Skip to content

Commit

Permalink
test: Test indexer fetching from registry
Browse files Browse the repository at this point in the history
  • Loading branch information
morgsmccauley committed Aug 4, 2024
1 parent a82b24f commit b177fba
Showing 1 changed file with 78 additions and 0 deletions.
78 changes: 78 additions & 0 deletions coordinator/src/registry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -262,3 +262,81 @@ impl RegistryImpl {
anyhow::bail!("Invalid registry response")
}
}

#[cfg(test)]
mod tests {
use super::*;

use mockall::predicate::*;

#[tokio::test]
async fn parses_non_existant_config() {
let mut mock_json_rpc_client = JsonRpcClientWrapper::default();
mock_json_rpc_client
.expect_call::<RpcQueryRequest>()
.with(always())
.returning(|_| {
Ok(near_jsonrpc_client::methods::query::RpcQueryResponse {
kind: QueryResponseKind::CallResult(near_primitives::views::CallResult {
result: "null".as_bytes().to_vec(),
logs: vec![],
}),
block_height: Default::default(),
block_hash: Default::default(),
})
});

let registry = RegistryImpl::new("registry".parse().unwrap(), mock_json_rpc_client);

let config = registry
.fetch_indexer(&"account".parse().unwrap(), "function")
.await
.unwrap();

assert!(config.is_none());
}

#[tokio::test]
async fn parses_existing_config() {
let mut mock_json_rpc_client = JsonRpcClientWrapper::default();
mock_json_rpc_client
.expect_call::<RpcQueryRequest>()
.with(always())
.returning(|_| {
Ok(near_jsonrpc_client::methods::query::RpcQueryResponse {
kind: QueryResponseKind::CallResult(near_primitives::views::CallResult {
result: serde_json::json!({
"code": "code",
"schema": "schema",
"rule": {
"affected_account_id": "queryapi.dataplatform.near",
"kind": "ACTION_ANY",
"status": "SUCCESS"
},
"start_block": {
"HEIGHT": 0,
},
"updated_at_block_height": 0,
"created_at_block_height": 0,
"deleted_at_block_height": 0
})
.to_string()
.as_bytes()
.to_vec(),
logs: vec![],
}),
block_height: Default::default(),
block_hash: Default::default(),
})
});

let registry = RegistryImpl::new("registry".parse().unwrap(), mock_json_rpc_client);

let config = registry
.fetch_indexer(&"account".parse().unwrap(), "function")
.await
.unwrap();

assert!(config.is_some());
}
}

0 comments on commit b177fba

Please sign in to comment.