Skip to content

Commit a7f5a55

Browse files
authored
GH-749: Update logic for contract existence tests (#384)
1 parent a50e526 commit a7f5a55

File tree

1 file changed

+19
-20
lines changed

1 file changed

+19
-20
lines changed

node/tests/contract_test.rs

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,7 @@ fn assert_contract_existence(
1414
chain: &Chain,
1515
expected_token_name: &str,
1616
expected_decimals: u32,
17-
) -> Result<(), ()> {
18-
eprintln!("Starting a new attempt with: '{}'", blockchain_service_url);
19-
17+
) -> Result<(), String> {
2018
let min_abi_json = r#"[{
2119
"constant": true,
2220
"inputs": [],
@@ -54,8 +52,7 @@ fn assert_contract_existence(
5452
{
5553
Ok(tn) => tn,
5654
Err(e) => {
57-
eprintln!("Token name query failed due to: {:?}", e);
58-
return Err(());
55+
return Err(format!("Token name query failed due to: {:?}", e));
5956
}
6057
};
6158
let decimals: u32 = match contract
@@ -64,8 +61,7 @@ fn assert_contract_existence(
6461
{
6562
Ok(dec) => dec,
6663
Err(e) => {
67-
eprintln!("Decimals query failed due to: {:?}", e);
68-
return Err(());
64+
return Err(format!("Decimals query failed due to: {:?}", e));
6965
}
7066
};
7167

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

9187
fn assert_contract<'a, F>(blockchain_urls: Vec<&'static str>, chain: &'a Chain, test_performer: F)
9288
where
93-
F: FnOnce(&'static str, &'a Chain) -> Result<(), ()> + Copy,
89+
F: FnOnce(&'static str, &'a Chain) -> Result<(), String> + Copy,
9490
{
95-
if !blockchain_urls
96-
.iter()
97-
.fold(false, |acc, url| match (acc, test_performer(url, chain)) {
98-
(true, _) => true,
99-
(false, Ok(_)) => true,
100-
(false, Err(_)) => false,
101-
})
102-
{
103-
panic!("Test failed on all blockchain services")
91+
for blockchain_url in blockchain_urls {
92+
eprintln!("Starting a new attempt with: '{}'", blockchain_url);
93+
match test_performer(blockchain_url, chain) {
94+
Ok(()) => {
95+
eprintln!("Attempt Successful!");
96+
return;
97+
}
98+
Err(e) => {
99+
eprintln!("Attempt Failed: {:?}", e);
100+
}
101+
}
104102
}
103+
104+
panic!("Test failed on all blockchain services");
105105
}
106106

107107
#[test]
@@ -144,7 +144,7 @@ fn assert_total_supply(
144144
blockchain_service_url: &str,
145145
chain: &Chain,
146146
expected_total_supply: u64,
147-
) -> Result<(), ()> {
147+
) -> Result<(), String> {
148148
let min_abi_json = r#"[{
149149
"constant": true,
150150
"inputs": [],
@@ -169,8 +169,7 @@ fn assert_total_supply(
169169
{
170170
Ok(ts) => ts,
171171
Err(e) => {
172-
eprintln!("Total supply query failed due to: {:?}", e);
173-
return Err(());
172+
return Err(format!("Total supply query failed due to: {:?}", e));
174173
}
175174
};
176175
assert_eq!(

0 commit comments

Comments
 (0)