web3.js/test/event.encode.js

249 lines
5.0 KiB
JavaScript
Raw Normal View History

2015-04-22 09:26:00 +02:00
var chai = require('chai');
var assert = chai.assert;
var Eth = require('../packages/web3-eth');
2015-10-15 14:46:47 +08:00
2015-04-22 09:26:00 +02:00
2015-04-22 09:44:26 +02:00
var address = '0x1234567890123456789012345678901234567890';
var signature = '0xffff';
2015-04-22 09:26:00 +02:00
var tests = [{
abi: {
name: 'event1',
inputs: [],
signature: signature
2015-04-22 09:26:00 +02:00
},
options: {},
expected: {
2015-04-22 09:44:26 +02:00
address: address,
2015-04-22 09:26:00 +02:00
topics: [
2015-04-22 09:44:26 +02:00
signature
2015-04-22 09:26:00 +02:00
]
}
}, {
abi: {
name: 'event1',
inputs: [{
type: 'int',
name: 'a',
indexed: true
}],
signature: signature
2015-04-22 09:26:00 +02:00
},
options: {
filter: {
a: 16
},
2015-04-22 09:26:00 +02:00
},
expected: {
2015-04-22 09:44:26 +02:00
address: address,
2015-04-22 09:26:00 +02:00
topics: [
2015-04-22 09:44:26 +02:00
signature,
2015-04-22 09:26:00 +02:00
'0x0000000000000000000000000000000000000000000000000000000000000010'
]
}
},{
abi: {
name: 'event1',
inputs: [{
type: 'int',
name: 'a',
indexed: true
}, {
type: 'int',
name: 'b',
indexed: true
}, {
type: 'int',
name: 'c',
indexed: false
}, {
type: 'int',
name: 'd',
indexed: true
}],
signature: signature
2015-04-22 09:26:00 +02:00
},
options: {
filter: {
b: 4
}
2015-04-22 09:26:00 +02:00
},
expected: {
2015-04-22 09:44:26 +02:00
address: address,
2015-04-22 09:26:00 +02:00
topics: [
2015-04-22 09:44:26 +02:00
signature, // signature
2015-04-22 09:26:00 +02:00
null, // a
'0x0000000000000000000000000000000000000000000000000000000000000004', // b
null // d
]
}
2015-04-22 09:39:28 +02:00
}, {
abi: {
name: 'event1',
inputs: [{
type: 'int',
name: 'a',
indexed: true
}, {
type: 'int',
name: 'b',
indexed: true
}],
signature: signature
2015-04-22 09:39:28 +02:00
},
options: {
filter: {
a: [16, 1],
b: 2
}
2015-04-22 09:39:28 +02:00
},
expected: {
2015-04-22 09:44:26 +02:00
address: address,
2015-04-22 09:39:28 +02:00
topics: [
2015-04-22 09:44:26 +02:00
signature,
2015-04-22 09:39:28 +02:00
['0x0000000000000000000000000000000000000000000000000000000000000010', '0x0000000000000000000000000000000000000000000000000000000000000001'],
'0x0000000000000000000000000000000000000000000000000000000000000002'
]
}
}, {
abi: {
name: 'event1',
inputs: [{
type: 'int',
name: 'a',
indexed: true
}],
signature: signature
2015-04-22 09:39:28 +02:00
},
options: {
filter: {
a: null
}
2015-04-22 09:39:28 +02:00
},
expected: {
2015-04-22 09:44:26 +02:00
address: address,
2015-04-22 09:39:28 +02:00
topics: [
2015-04-22 09:44:26 +02:00
signature,
2015-04-22 09:39:28 +02:00
null
]
}
2015-04-22 10:12:39 +02:00
}, {
2015-04-28 17:01:37 +02:00
abi: {
name: 'event1',
inputs: [{
type: 'int',
name: 'a',
indexed: true
}],
signature: signature
2015-04-28 17:01:37 +02:00
},
options: {
filter: {
a: 1
},
2015-04-28 17:01:37 +02:00
fromBlock: 'latest',
toBlock: 'pending'
},
expected: {
address: address,
fromBlock: 'latest',
toBlock: 'pending',
topics: [
signature,
'0x0000000000000000000000000000000000000000000000000000000000000001'
]
}
},
{
2015-04-22 10:12:39 +02:00
abi: {
name: 'event1',
inputs: [{
type: 'int',
name: 'a',
indexed: true
}],
signature: signature
2015-04-22 10:12:39 +02:00
},
options: {
filter: {
a: 1
},
2015-04-22 10:12:39 +02:00
fromBlock: 4,
toBlock: 10
},
expected: {
address: address,
fromBlock: '0x4',
toBlock: '0xa',
topics: [
signature,
'0x0000000000000000000000000000000000000000000000000000000000000001'
]
}
}, {
abi: {
name: 'event1',
inputs: [{
type: 'int',
name: 'a',
indexed: true
}],
anonymous: true,
signature: signature
},
options: {
filter: {
a: 1
}
},
expected: {
2015-07-09 12:05:19 +02:00
address: address,
topics: [
'0x0000000000000000000000000000000000000000000000000000000000000001'
]
}
2015-04-22 10:59:09 +02:00
}, {
abi: {
name: 'event1',
inputs: [{
type: 'int',
name: 'a',
indexed: true
}, {
type: 'int',
name: 'b',
indexed: true
}],
anonymous: true,
signature: signature
2015-04-22 10:59:09 +02:00
},
options: {
filter: {
b: 1
}
2015-04-22 10:59:09 +02:00
},
expected: {
2015-07-09 12:05:19 +02:00
address: address,
2015-04-22 10:59:09 +02:00
topics: [
null,
'0x0000000000000000000000000000000000000000000000000000000000000001'
]
}
2015-04-22 09:26:00 +02:00
}];
describe('lib/web3/event', function () {
describe('encode', function () {
tests.forEach(function (test, index) {
it('test no: ' + index, function () {
var eth = new Eth();
var contract = new eth.Contract([test.abi], address);
2015-04-22 09:26:00 +02:00
var result = contract._encodeEventABI(test.abi, test.options);
2015-04-22 09:26:00 +02:00
assert.deepEqual(result, test.expected);
});
});
});
});