Skip to content

Commit c2cdc32

Browse files
LeoPatOZ0xNeshi
andauthored
test: Add back testing mod file + refactors (#158)
Co-authored-by: Nenad <[email protected]>
1 parent c291996 commit c2cdc32

File tree

9 files changed

+279
-314
lines changed

9 files changed

+279
-314
lines changed

src/test_utils/mod.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1 @@
11
pub mod macros;
2-
pub mod types;
3-
4-
pub use types::LogMetadata;

src/test_utils/types.rs

Lines changed: 0 additions & 50 deletions
This file was deleted.

tests/common.rs

Lines changed: 1 addition & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,14 @@
55
use alloy::{
66
eips::BlockNumberOrTag,
77
network::Ethereum,
8-
primitives::U256,
98
providers::{Provider, ProviderBuilder, RootProvider},
109
sol,
1110
sol_types::SolEvent,
1211
};
1312
use alloy_node_bindings::{Anvil, AnvilInstance};
1413
use event_scanner::{
1514
EventFilter, EventScanner, EventScannerBuilder, Historic, LatestEvents, Live, Message,
16-
SyncFromBlock, SyncFromLatestEvents, test_utils::LogMetadata,
15+
SyncFromBlock, SyncFromLatestEvents,
1716
};
1817
use tokio_stream::wrappers::ReceiverStream;
1918

@@ -197,41 +196,3 @@ where
197196
let contract = TestCounter::deploy(provider).await?;
198197
Ok(contract)
199198
}
200-
201-
#[allow(dead_code)]
202-
pub(crate) trait TestCounterExt {
203-
async fn increase_and_get_meta(
204-
&self,
205-
) -> anyhow::Result<LogMetadata<TestCounter::CountIncreased>>;
206-
async fn decrease_and_get_meta(
207-
&self,
208-
) -> anyhow::Result<LogMetadata<TestCounter::CountDecreased>>;
209-
}
210-
211-
impl<P: Provider + Clone> TestCounterExt for TestCounter::TestCounterInstance<P> {
212-
async fn increase_and_get_meta(
213-
&self,
214-
) -> anyhow::Result<LogMetadata<TestCounter::CountIncreased>> {
215-
let receipt = self.increase().send().await?.get_receipt().await?;
216-
let tx_hash = receipt.transaction_hash;
217-
let new_count = receipt.decoded_log::<TestCounter::CountIncreased>().unwrap().data.newCount;
218-
Ok(LogMetadata {
219-
event: TestCounter::CountIncreased { newCount: U256::from(new_count) },
220-
address: *self.address(),
221-
tx_hash,
222-
})
223-
}
224-
225-
async fn decrease_and_get_meta(
226-
&self,
227-
) -> anyhow::Result<LogMetadata<TestCounter::CountDecreased>> {
228-
let receipt = self.decrease().send().await?.get_receipt().await?;
229-
let tx_hash = receipt.transaction_hash;
230-
let new_count = receipt.decoded_log::<TestCounter::CountDecreased>().unwrap().data.newCount;
231-
Ok(LogMetadata {
232-
event: TestCounter::CountDecreased { newCount: U256::from(new_count) },
233-
address: *self.address(),
234-
tx_hash,
235-
})
236-
}
237-
}

tests/historic/basic.rs

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
use alloy::eips::BlockNumberOrTag;
1+
use alloy::{eips::BlockNumberOrTag, primitives::U256};
22
use event_scanner::{assert_closed, assert_next};
33

4-
use crate::common::{TestCounterExt, setup_historic_scanner};
4+
use crate::common::{TestCounter, setup_historic_scanner};
55

66
#[tokio::test]
77
async fn processes_events_within_specified_historical_range() -> anyhow::Result<()> {
@@ -16,17 +16,24 @@ async fn processes_events_within_specified_historical_range() -> anyhow::Result<
1616
let scanner = setup.scanner;
1717
let mut stream = setup.stream;
1818

19-
let expected = &[
20-
contract.increase_and_get_meta().await?,
21-
contract.increase_and_get_meta().await?,
22-
contract.increase_and_get_meta().await?,
23-
contract.increase_and_get_meta().await?,
24-
contract.increase_and_get_meta().await?,
25-
];
19+
contract.increase().send().await?.watch().await?;
20+
contract.increase().send().await?.watch().await?;
21+
contract.increase().send().await?.watch().await?;
22+
contract.increase().send().await?.watch().await?;
23+
contract.increase().send().await?.watch().await?;
2624

2725
scanner.start().await?;
2826

29-
assert_next!(stream, expected);
27+
assert_next!(
28+
stream,
29+
&[
30+
TestCounter::CountIncreased { newCount: U256::from(1) },
31+
TestCounter::CountIncreased { newCount: U256::from(2) },
32+
TestCounter::CountIncreased { newCount: U256::from(3) },
33+
TestCounter::CountIncreased { newCount: U256::from(4) },
34+
TestCounter::CountIncreased { newCount: U256::from(5) },
35+
]
36+
);
3037
assert_closed!(stream);
3138

3239
Ok(())

0 commit comments

Comments
 (0)