Skip to content

Commit

Permalink
update explorer tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Kirill-K-1 committed Jul 16, 2024
1 parent ed9ad6e commit 3e02d2f
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 21 deletions.
73 changes: 52 additions & 21 deletions user-verifier/src/explorer_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,27 +99,58 @@ impl ExplorerClient {

#[cfg(test)]
mod tests {
use assert_matches::assert_matches;
use chrono::Utc;
use ethereum_types::Address;

use super::{ExplorerClient, ExplorerConfig};

#[tokio::test]
async fn test_find_first_transaction_before() {
let client = ExplorerClient::new(ExplorerConfig {
url: "https://explorer-v2-api.ambrosus.io/v2/addresses/".to_owned(),
timeout: std::time::Duration::from_secs(10),
})
.unwrap();
use super::*;

#[test]
fn test_de_response() {
let response = r#"{
"data": [{
"blockHash": "0x5256c76ad7a3809eaff33cacabf4d2747bb4a60e73cee32f50407f950f7af782",
"blockNumber": 31632033,
"from": "",
"to": "0xaeE13A8db3e216A364255EFEbA171ce329100876",
"gasCost": {
"wei": "0",
"ether": 0
},
"gasPrice": "0",
"gasSent": 0,
"gasUsed": 0,
"hash": "0x0f71f742aafc559fc6618a0ed3d2a640fab851f786bfe2143463a6f5571e798a",
"input": "-",
"logs": [],
"nonce": 0,
"status": "SUCCESS",
"timestamp": 1721135640,
"transactionIndex": -1,
"type": "TokenTransfer",
"parent": null,
"hasInners": false,
"value": {
"wei": "8339991955835962979526",
"ether": 8339.99195583596,
"symbol": ""
},
"token": {
"address": "0x8d4439F8AC1e5CCF37F9ACb527E59720E0ccA3E3",
"name": "",
"symbol": "",
"decimals": 18,
"totalSupply": 0
}
}],
"pagination": {
"totalCount": 2,
"pageCount": 2,
"perPage": 1,
"next": 2,
"hasNext": true,
"current": 1,
"previous": 1,
"hasPrevious": false
}
}"#;

let wallet = Address::from(
<[u8; 20]>::try_from(hex::decode("aeE13A8db3e216A364255EFEbA171ce329100876").unwrap())
.unwrap(),
);
let tx = client
.find_first_transaction_before(wallet, Utc::now())
.await;
assert_matches!(tx, Ok(Some(_)));
serde_json::from_str::<ResponsePaged<Vec<Transaction>>>(response).unwrap();
}
}
1 change: 1 addition & 0 deletions user-verifier/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
mod error;

pub mod explorer_client;
pub mod rpc_node_client;
pub mod server_nodes_manager;
pub mod signer;
Expand Down
28 changes: 28 additions & 0 deletions user-verifier/tests/test_explorer_client.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#![cfg(feature = "enable-integration-tests")]
use assert_matches::assert_matches;
use chrono::Utc;
use ethereum_types::Address;

use airdao_gov_user_verifier::explorer_client::{ExplorerClient, ExplorerConfig};

#[tokio::test]
async fn test_find_first_transaction_before() -> Result<(), anyhow::Error> {
let client = ExplorerClient::new(ExplorerConfig {
url: "https://explorer-v2-api.ambrosus.io/v2/addresses/".to_owned(),
timeout: std::time::Duration::from_secs(10),
})?;

let wallet = Address::from(
<[u8; 20]>::try_from(hex::decode("aeE13A8db3e216A364255EFEbA171ce329100876")?).map_err(
|failed_data| {
anyhow::format_err!("Failed to deserialize Address from: {failed_data:?}")
},
)?,
);
let tx = client
.find_first_transaction_before(wallet, Utc::now())
.await;
assert_matches!(tx, Ok(Some(_)));

Ok(())
}

0 comments on commit 3e02d2f

Please sign in to comment.