This repository was archived by the owner on Mar 5, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5.1k
Expand file tree
/
Copy pathe2e.contract.events.js
More file actions
74 lines (61 loc) · 2.02 KB
/
e2e.contract.events.js
File metadata and controls
74 lines (61 loc) · 2.02 KB
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
66
67
68
69
70
71
72
73
var assert = require('assert');
var Basic = require('./sources/Basic');
var utils = require('./helpers/test.utils');
var Web3 = utils.getWeb3();
describe('contract.events [ @E2E ]', function() {
// `getPastEvents` not working with Geth instamine over websockets.
if (process.env.GETH_INSTAMINE) return;
var web3;
var accounts;
var basic;
var instance;
var basicOptions = {
data: Basic.bytecode,
gasPrice: '1',
gas: 4000000
};
before(async function(){
var port = utils.getWebsocketPort();
web3 = new Web3('ws://localhost:' + port);
accounts = await web3.eth.getAccounts();
basic = new web3.eth.Contract(Basic.abi, basicOptions);
instance = await basic.deploy().send({from: accounts[0]});
})
it('contract.getPastEvents', async function(){
await instance
.methods
.firesEvent(accounts[0], 1)
.send({from: accounts[0]});
await instance
.methods
.firesEvent(accounts[0], 2)
.send({from: accounts[0]});
const events = await instance.getPastEvents({
fromBlock: 0,
toBlock: 'latest'
});
assert.equal(events.length, 2);
assert.equal(events[0].event, 'BasicEvent');
assert.equal(events[1].event, 'BasicEvent');
assert.notEqual(events[0].id, events[1].id);
});
it('contract.events.<eventName>', function(){
return new Promise(async resolve => {
instance
.events
.BasicEvent({
fromBlock: 0,
toBlock: 'latest'
})
.on('data', function(event) {
assert.equal(event.event, 'BasicEvent');
this.removeAllListeners();
resolve();
});
await instance
.methods
.firesEvent(accounts[0], 1)
.send({from: accounts[0]});
});
});
});