Skip to content

Commit 16704f5

Browse files
committed
test: newFilter
1 parent 89892a7 commit 16704f5

File tree

3 files changed

+51
-0
lines changed

3 files changed

+51
-0
lines changed

client/src/tests.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff 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
}

client/src/tests/eth/newFilter.sol

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
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+
}

client/src/tests/eth/newFilter.ts

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
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+
});

0 commit comments

Comments
 (0)