Skip to content

Commit

Permalink
GH-749: Update logic for contract existence tests (#384)
Browse files Browse the repository at this point in the history
  • Loading branch information
utkarshg6 committed Feb 19, 2024
1 parent a50e526 commit a7f5a55
Showing 1 changed file with 19 additions and 20 deletions.
39 changes: 19 additions & 20 deletions node/tests/contract_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,7 @@ fn assert_contract_existence(
chain: &Chain,
expected_token_name: &str,
expected_decimals: u32,
) -> Result<(), ()> {
eprintln!("Starting a new attempt with: '{}'", blockchain_service_url);

) -> Result<(), String> {
let min_abi_json = r#"[{
"constant": true,
"inputs": [],
Expand Down Expand Up @@ -54,8 +52,7 @@ fn assert_contract_existence(
{
Ok(tn) => tn,
Err(e) => {
eprintln!("Token name query failed due to: {:?}", e);
return Err(());
return Err(format!("Token name query failed due to: {:?}", e));
}
};
let decimals: u32 = match contract
Expand All @@ -64,8 +61,7 @@ fn assert_contract_existence(
{
Ok(dec) => dec,
Err(e) => {
eprintln!("Decimals query failed due to: {:?}", e);
return Err(());
return Err(format!("Decimals query failed due to: {:?}", e));
}
};

Expand All @@ -90,18 +86,22 @@ fn create_contract_interface(transport: Http, chain: &Chain, min_abi_json: &str)

fn assert_contract<'a, F>(blockchain_urls: Vec<&'static str>, chain: &'a Chain, test_performer: F)
where
F: FnOnce(&'static str, &'a Chain) -> Result<(), ()> + Copy,
F: FnOnce(&'static str, &'a Chain) -> Result<(), String> + Copy,
{
if !blockchain_urls
.iter()
.fold(false, |acc, url| match (acc, test_performer(url, chain)) {
(true, _) => true,
(false, Ok(_)) => true,
(false, Err(_)) => false,
})
{
panic!("Test failed on all blockchain services")
for blockchain_url in blockchain_urls {
eprintln!("Starting a new attempt with: '{}'", blockchain_url);
match test_performer(blockchain_url, chain) {
Ok(()) => {
eprintln!("Attempt Successful!");
return;
}
Err(e) => {
eprintln!("Attempt Failed: {:?}", e);
}
}
}

panic!("Test failed on all blockchain services");
}

#[test]
Expand Down Expand Up @@ -144,7 +144,7 @@ fn assert_total_supply(
blockchain_service_url: &str,
chain: &Chain,
expected_total_supply: u64,
) -> Result<(), ()> {
) -> Result<(), String> {
let min_abi_json = r#"[{
"constant": true,
"inputs": [],
Expand All @@ -169,8 +169,7 @@ fn assert_total_supply(
{
Ok(ts) => ts,
Err(e) => {
eprintln!("Total supply query failed due to: {:?}", e);
return Err(());
return Err(format!("Total supply query failed due to: {:?}", e));
}
};
assert_eq!(
Expand Down

0 comments on commit a7f5a55

Please sign in to comment.