Skip to content

Commit 9f5f66d

Browse files
committed
tests: Fix running integration tests multiple times
When running integration tests multiple times, we need to make sure that we emit events only once, not once per run. Change the topic-filter test to do just that
1 parent 463ea47 commit 9f5f66d

3 files changed

Lines changed: 45 additions & 74 deletions

File tree

tests/src/contract.rs

Lines changed: 41 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use web3::{
99
api::{Eth, Namespace},
1010
contract::{tokens::Tokenize, Contract as Web3Contract, Options},
1111
transports::Http,
12-
types::{Address, Block, BlockId, BlockNumber, Bytes, TransactionReceipt, H256},
12+
types::{Address, Block, BlockId, BlockNumber, Bytes, TransactionReceipt, H256, U256},
1313
};
1414
// web3 version 0.18 does not expose this; once the graph crate updates to
1515
// version 0.19, we can use web3::signing::SecretKey from the graph crate
@@ -34,19 +34,19 @@ lazy_static! {
3434
},
3535
Contract {
3636
name: "LimitedContract".to_string(),
37-
address: Address::from_str("0xb7f8bc63bbcad18155201308c8f3540b07f84f5e").unwrap(),
37+
address: Address::from_str("0x0b306bf915c4d645ff596e518faf3f9669b97016").unwrap(),
3838
},
3939
Contract {
4040
name: "RevertingContract".to_string(),
41-
address: Address::from_str("0xa51c1fc2f0d1a1b8494ed1fe312d7c3a78ed91c0").unwrap(),
41+
address: Address::from_str("0x959922be3caee4b8cd9a407cc3ac1c251c2007b1").unwrap(),
4242
},
4343
Contract {
4444
name: "OverloadedContract".to_string(),
45-
address: Address::from_str("0x0dcd1bf9a1b36ce34237eeafef220932846bcd82").unwrap(),
45+
address: Address::from_str("0x9a9f2ccfde556a7e9ff0848998aa4a0cfd8863ae").unwrap(),
4646
},
4747
Contract {
4848
name: "DeclaredCallsContract".to_string(),
49-
address: Address::from_str("0x9a676e781a523b5d0c0e43731313a708cb607508").unwrap(),
49+
address: Address::from_str("0x68b1d87f95878fe05b998f19b66f4baba5de1aed").unwrap(),
5050
},
5151
]
5252
};
@@ -195,6 +195,42 @@ impl Contract {
195195
.await
196196
.unwrap();
197197
}
198+
// The topic-filter test needs some events emitted
199+
if contract.name == "SimpleContract" {
200+
status!("contracts", "Emitting anotherTrigger from SimpleContract");
201+
let args = &[
202+
(
203+
U256::from(1),
204+
U256::from(2),
205+
U256::from(3),
206+
"abc".to_string(),
207+
),
208+
(
209+
U256::from(1),
210+
U256::from(1),
211+
U256::from(1),
212+
"abc".to_string(),
213+
),
214+
(
215+
U256::from(4),
216+
U256::from(2),
217+
U256::from(3),
218+
"abc".to_string(),
219+
),
220+
(
221+
U256::from(4),
222+
U256::from(4),
223+
U256::from(3),
224+
"abc".to_string(),
225+
),
226+
];
227+
for arg in args {
228+
contract
229+
.call("emitAnotherTrigger", arg.clone())
230+
.await
231+
.unwrap();
232+
}
233+
}
198234
} else {
199235
status!(
200236
"contracts",

tests/tests/gnd_tests.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ async fn gnd_tests() -> anyhow::Result<()> {
104104
.enumerate()
105105
.map(|(index, case)| {
106106
let subgraph_name = format!("subgraph-{}", num_sources + index);
107-
case.check_health_and_test(&contracts, subgraph_name)
107+
case.check_health_and_test(subgraph_name)
108108
})
109109
.buffered(CONFIG.num_parallel_tests);
110110

tests/tests/integration_tests.rs

Lines changed: 3 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ use graph_tests::{error, status, CONFIG};
3232
use tokio::process::Child;
3333
use tokio::task::JoinError;
3434
use tokio::time::sleep;
35-
use web3::types::U256;
3635

3736
const SUBGRAPH_LAST_GRAFTING_BLOCK: i32 = 3;
3837

@@ -44,7 +43,6 @@ type TestFn = Box<
4443

4544
pub struct TestContext {
4645
pub subgraph: Subgraph,
47-
pub contracts: Vec<Contract>,
4846
}
4947

5048
pub enum TestStatus {
@@ -234,11 +232,7 @@ impl TestCase {
234232
Ok(subgraph_name)
235233
}
236234

237-
pub async fn check_health_and_test(
238-
self,
239-
contracts: &[Contract],
240-
subgraph_name: String,
241-
) -> TestResult {
235+
pub async fn check_health_and_test(self, subgraph_name: String) -> TestResult {
242236
status!(
243237
&self.name,
244238
"Waiting for subgraph ({}) to become ready",
@@ -264,7 +258,6 @@ impl TestCase {
264258

265259
let ctx = TestContext {
266260
subgraph: subgraph.clone(),
267-
contracts: contracts.to_vec(),
268261
};
269262

270263
status!(&self.name, "Starting test");
@@ -323,7 +316,7 @@ impl TestCase {
323316
}
324317
};
325318

326-
self.check_health_and_test(contracts, subgraph_name).await
319+
self.check_health_and_test(subgraph_name).await
327320
}
328321

329322
async fn prepare_multiple_sources(
@@ -671,63 +664,7 @@ async fn test_topic_filters(ctx: TestContext) -> anyhow::Result<()> {
671664
let subgraph = ctx.subgraph;
672665
assert!(subgraph.healthy);
673666

674-
let contract = ctx
675-
.contracts
676-
.iter()
677-
.find(|x| x.name == "SimpleContract")
678-
.unwrap();
679-
680-
contract
681-
.call(
682-
"emitAnotherTrigger",
683-
(
684-
U256::from(1),
685-
U256::from(2),
686-
U256::from(3),
687-
"abc".to_string(),
688-
),
689-
)
690-
.await
691-
.unwrap();
692-
693-
contract
694-
.call(
695-
"emitAnotherTrigger",
696-
(
697-
U256::from(1),
698-
U256::from(1),
699-
U256::from(1),
700-
"abc".to_string(),
701-
),
702-
)
703-
.await
704-
.unwrap();
705-
706-
contract
707-
.call(
708-
"emitAnotherTrigger",
709-
(
710-
U256::from(4),
711-
U256::from(2),
712-
U256::from(3),
713-
"abc".to_string(),
714-
),
715-
)
716-
.await
717-
.unwrap();
718-
719-
contract
720-
.call(
721-
"emitAnotherTrigger",
722-
(
723-
U256::from(4),
724-
U256::from(4),
725-
U256::from(3),
726-
"abc".to_string(),
727-
),
728-
)
729-
.await
730-
.unwrap();
667+
// Events we need are already emitted from Contract::deploy_all
731668

732669
let exp = json!({
733670
"anotherTriggerEntities": [
@@ -1211,8 +1148,6 @@ pub async fn test_multiple_subgraph_datasources(ctx: TestContext) -> anyhow::Res
12111148
let subgraph = ctx.subgraph;
12121149
assert!(subgraph.healthy);
12131150

1214-
println!("subgraph: {:?}", subgraph);
1215-
12161151
// Test querying data aggregated from multiple sources
12171152
let exp = json!({
12181153
"aggregatedDatas": [

0 commit comments

Comments
 (0)