2015-04-22 07:26:00 +00:00
|
|
|
var chai = require('chai');
|
|
|
|
var assert = chai.assert;
|
|
|
|
var SolidityEvent = require('../lib/web3/event');
|
|
|
|
|
2015-04-22 07:44:26 +00:00
|
|
|
var address = '0x1234567890123456789012345678901234567890';
|
|
|
|
var signature = '0xffff';
|
|
|
|
|
2015-04-22 07:26:00 +00:00
|
|
|
var tests = [{
|
|
|
|
abi: {
|
|
|
|
name: 'event1',
|
|
|
|
inputs: []
|
|
|
|
},
|
|
|
|
indexed: {},
|
|
|
|
options: {},
|
|
|
|
expected: {
|
2015-04-22 07:44:26 +00:00
|
|
|
address: address,
|
2015-04-22 07:26:00 +00:00
|
|
|
topics: [
|
2015-04-22 07:44:26 +00:00
|
|
|
signature
|
2015-04-22 07:26:00 +00:00
|
|
|
]
|
|
|
|
}
|
|
|
|
}, {
|
|
|
|
abi: {
|
|
|
|
name: 'event1',
|
|
|
|
inputs: [{
|
|
|
|
type: 'int',
|
|
|
|
name: 'a',
|
|
|
|
indexed: true
|
|
|
|
}]
|
|
|
|
},
|
|
|
|
indexed: {
|
|
|
|
a: 16
|
|
|
|
},
|
|
|
|
options: {},
|
|
|
|
expected: {
|
2015-04-22 07:44:26 +00:00
|
|
|
address: address,
|
2015-04-22 07:26:00 +00:00
|
|
|
topics: [
|
2015-04-22 07:44:26 +00:00
|
|
|
signature,
|
2015-04-22 07:26:00 +00: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
|
|
|
|
}]
|
|
|
|
},
|
|
|
|
indexed: {
|
|
|
|
b: 4
|
|
|
|
},
|
|
|
|
options: {},
|
|
|
|
expected: {
|
2015-04-22 07:44:26 +00:00
|
|
|
address: address,
|
2015-04-22 07:26:00 +00:00
|
|
|
topics: [
|
2015-04-22 07:44:26 +00:00
|
|
|
signature, // signature
|
2015-04-22 07:26:00 +00:00
|
|
|
null, // a
|
|
|
|
'0x0000000000000000000000000000000000000000000000000000000000000004', // b
|
|
|
|
null // d
|
|
|
|
]
|
|
|
|
}
|
2015-04-22 07:39:28 +00:00
|
|
|
}, {
|
|
|
|
abi: {
|
|
|
|
name: 'event1',
|
|
|
|
inputs: [{
|
|
|
|
type: 'int',
|
|
|
|
name: 'a',
|
|
|
|
indexed: true
|
|
|
|
}, {
|
|
|
|
type: 'int',
|
|
|
|
name: 'b',
|
|
|
|
indexed: true
|
|
|
|
}]
|
|
|
|
},
|
|
|
|
indexed: {
|
|
|
|
a: [16, 1],
|
|
|
|
b: 2
|
|
|
|
},
|
|
|
|
options: {},
|
|
|
|
expected: {
|
2015-04-22 07:44:26 +00:00
|
|
|
address: address,
|
2015-04-22 07:39:28 +00:00
|
|
|
topics: [
|
2015-04-22 07:44:26 +00:00
|
|
|
signature,
|
2015-04-22 07:39:28 +00:00
|
|
|
['0x0000000000000000000000000000000000000000000000000000000000000010', '0x0000000000000000000000000000000000000000000000000000000000000001'],
|
|
|
|
'0x0000000000000000000000000000000000000000000000000000000000000002'
|
|
|
|
]
|
|
|
|
}
|
|
|
|
}, {
|
|
|
|
abi: {
|
|
|
|
name: 'event1',
|
|
|
|
inputs: [{
|
|
|
|
type: 'int',
|
|
|
|
name: 'a',
|
|
|
|
indexed: true
|
|
|
|
}]
|
|
|
|
},
|
|
|
|
indexed: {
|
|
|
|
a: null
|
|
|
|
},
|
|
|
|
options: {},
|
|
|
|
expected: {
|
2015-04-22 07:44:26 +00:00
|
|
|
address: address,
|
2015-04-22 07:39:28 +00:00
|
|
|
topics: [
|
2015-04-22 07:44:26 +00:00
|
|
|
signature,
|
2015-04-22 07:39:28 +00:00
|
|
|
null
|
|
|
|
]
|
|
|
|
}
|
2015-04-22 08:12:39 +00:00
|
|
|
}, {
|
|
|
|
abi: {
|
|
|
|
name: 'event1',
|
|
|
|
inputs: [{
|
|
|
|
type: 'int',
|
|
|
|
name: 'a',
|
|
|
|
indexed: true
|
|
|
|
}]
|
|
|
|
},
|
|
|
|
indexed: {
|
|
|
|
a: 1
|
|
|
|
},
|
|
|
|
options: {
|
|
|
|
fromBlock: 4,
|
|
|
|
toBlock: 10
|
|
|
|
},
|
|
|
|
expected: {
|
|
|
|
address: address,
|
|
|
|
fromBlock: '0x4',
|
|
|
|
toBlock: '0xa',
|
|
|
|
topics: [
|
|
|
|
signature,
|
|
|
|
'0x0000000000000000000000000000000000000000000000000000000000000001'
|
|
|
|
]
|
|
|
|
}
|
2015-04-22 08:35:48 +00:00
|
|
|
}, {
|
|
|
|
abi: {
|
|
|
|
name: 'event1',
|
|
|
|
inputs: [{
|
|
|
|
type: 'int',
|
|
|
|
name: 'a',
|
|
|
|
indexed: true
|
|
|
|
}],
|
|
|
|
anonymous: true
|
|
|
|
},
|
|
|
|
indexed: {
|
|
|
|
a: 1
|
|
|
|
},
|
|
|
|
options: {},
|
|
|
|
expected: {
|
|
|
|
topics: [
|
|
|
|
'0x0000000000000000000000000000000000000000000000000000000000000001'
|
|
|
|
]
|
|
|
|
}
|
2015-04-22 08:59:09 +00:00
|
|
|
}, {
|
|
|
|
abi: {
|
|
|
|
name: 'event1',
|
|
|
|
inputs: [{
|
|
|
|
type: 'int',
|
|
|
|
name: 'a',
|
|
|
|
indexed: true
|
|
|
|
}, {
|
|
|
|
type: 'int',
|
|
|
|
name: 'b',
|
|
|
|
indexed: true
|
|
|
|
}],
|
|
|
|
anonymous: true
|
|
|
|
},
|
|
|
|
indexed: {
|
|
|
|
b: 1
|
|
|
|
},
|
|
|
|
options: {},
|
|
|
|
expected: {
|
|
|
|
topics: [
|
|
|
|
null,
|
|
|
|
'0x0000000000000000000000000000000000000000000000000000000000000001'
|
|
|
|
]
|
|
|
|
}
|
2015-04-22 07:26:00 +00:00
|
|
|
}];
|
|
|
|
|
|
|
|
describe('lib/web3/event', function () {
|
|
|
|
describe('encode', function () {
|
|
|
|
tests.forEach(function (test, index) {
|
|
|
|
it('test no: ' + index, function () {
|
2015-04-22 07:44:26 +00:00
|
|
|
var event = new SolidityEvent(test.abi, address);
|
2015-04-22 07:26:00 +00:00
|
|
|
event.signature = function () { // inject signature
|
2015-04-22 07:44:26 +00:00
|
|
|
return signature.slice(2);
|
2015-04-22 07:26:00 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
var result = event.encode(test.indexed, test.options);
|
|
|
|
assert.deepEqual(result, test.expected);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|