File tree Expand file tree Collapse file tree 3 files changed +51
-0
lines changed
Expand file tree Collapse file tree 3 files changed +51
-0
lines changed Original file line number Diff line number Diff line change @@ -25,6 +25,7 @@ export async function run(
2525 await import ( "./tests/eth/blockNumber" ) ;
2626 await import ( "./tests/eth/getBalance" ) ;
2727 await import ( "./tests/eth/getTransactionByHash" ) ;
28+ await import ( "./tests/eth/newFilter" ) ;
2829
2930 mocha . run ( ) ;
3031}
Original file line number Diff line number Diff line change 1+ // SPDX-License-Identifier: MIT
2+
3+ pragma solidity ^ 0.8.19 ;
4+
5+ contract Emit {
6+ event Log (uint256 indexed arg0 );
7+
8+ function logSomething (uint256 arg0 ) external {
9+ emit Log (arg0);
10+ }
11+ }
Original file line number Diff line number Diff line change 1+ import { blockchain , wallet } from "../../tests" ;
2+ import newFilter from "./newFilter.sol" ;
3+ import assert from "assert" ;
4+ import { ethers } from "ethers" ;
5+
6+ describe ( "newFilter" , ( ) => {
7+ let contract : ethers . Contract ;
8+
9+ before ( async ( ) => {
10+ if ( ! blockchain || ! wallet ) {
11+ throw "not ready" ;
12+ }
13+ const deployer = ( await blockchain . listAccounts ( ) ) [ 0 ] ;
14+ const factory = ethers . ContractFactory . fromSolidity (
15+ newFilter . Emit ,
16+ deployer
17+ ) ;
18+
19+ contract = await factory . deploy ( ) ;
20+ await blockchain . send ( "evm_mine" , [ { blocks : 1 } ] ) ;
21+ await contract . deploymentTransaction ( ) ?. wait ( 1 ) ;
22+ } ) ;
23+
24+ it ( "returns events matching filter" , async ( ) => {
25+ if ( ! blockchain || ! wallet ) {
26+ throw "not ready" ;
27+ }
28+ const eventPromise = new Promise ( ( resolve ) =>
29+ contract . once ( "Log" , ( args ) => {
30+ resolve ( args ) ;
31+ } )
32+ ) ;
33+ const call = await contract . logSomething ( 1234n ) ;
34+ await blockchain . send ( "evm_mine" , [ { blocks : 1 } ] ) ;
35+ await call . wait ( 1 ) ;
36+ const actual = await eventPromise ;
37+ assert . equal ( actual , 1234n ) ;
38+ } ) ;
39+ } ) ;
You can’t perform that action at this time.
0 commit comments