-
Notifications
You must be signed in to change notification settings - Fork 0
/
Lock.ts
65 lines (52 loc) · 2.03 KB
/
Lock.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import { expect } from 'chai'
import { ethers } from 'hardhat'
describe('Lock', function () {
it('should work with on chain listeners', async () => {
const Lock = await ethers.getContractFactory('Lock')
const lock = await Lock.deploy()
const requestsToMake = 20
let received = 0
lock.on(lock.filters.TestEvent(), (event) => {
console.log('Received', event.transactionHash)
received++
})
await new Promise((res) => setTimeout(res, 5_000)) // Wait until the listener is registered
for (let i = 0; i < requestsToMake; i++) {
const tx = await lock.emitEvent()
console.log('Created', tx.hash)
}
await new Promise((res) => setTimeout(res, 5_000)) // Should be more then enough time for all events to be processed
expect(received).to.equal(requestsToMake)
})
it('should work with getLogs', async () => {
const Lock = await ethers.getContractFactory('Lock')
const lock = await Lock.deploy()
const requestsToMake = 20
for (let i = 0; i < requestsToMake; i++) {
const tx = await lock.emitEvent()
console.log('Created', tx.hash)
}
await new Promise((res) => setTimeout(res, 5_000)) // Should be more then enough time for all events to be processed
const events = await lock.provider.getLogs(lock.filters.TestEvent())
console.log(
'Received',
events.map((e) => e.transactionHash),
)
expect(events.length).to.equal(requestsToMake)
})
it('should work with queryFilter', async () => {
const Lock = await ethers.getContractFactory('Lock')
const lock = await Lock.deploy()
const requestsToMake = 20
for (let i = 0; i < requestsToMake; i++) {
const tx = await lock.emitEvent()
}
await new Promise((res) => setTimeout(res, 5_000)) // Should be more then enough time for all events to be processed
const events = await lock.queryFilter(lock.filters.TestEvent())
console.log(
'Received',
events.map((e) => e.transactionHash),
)
expect(events.length).to.equal(requestsToMake)
})
})