mirror of https://github.com/status-im/web3.js.git
tests for decoding event logs
This commit is contained in:
parent
7c16dbf7e4
commit
3d3db61e2e
|
@ -2135,8 +2135,10 @@ SolidityEvent.prototype.decode = function (data) {
|
|||
};
|
||||
|
||||
data.data = data.data || '';
|
||||
data.topics = data.topics || [];
|
||||
|
||||
var indexedData = data.topics.slice(1).map(function (topics) { return topics.slice(2); }).join("");
|
||||
var argTopics = this._anonymous ? data.topics : data.topics.slice(1);
|
||||
var indexedData = argTopics.map(function (topics) { return topics.slice(2); }).join("");
|
||||
var indexedParams = coder.decodeParams(this.types(true), indexedData);
|
||||
|
||||
var notIndexedData = data.data.slice(2);
|
||||
|
|
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
|
@ -2135,8 +2135,10 @@ SolidityEvent.prototype.decode = function (data) {
|
|||
};
|
||||
|
||||
data.data = data.data || '';
|
||||
data.topics = data.topics || [];
|
||||
|
||||
var indexedData = data.topics.slice(1).map(function (topics) { return topics.slice(2); }).join("");
|
||||
var argTopics = this._anonymous ? data.topics : data.topics.slice(1);
|
||||
var indexedData = argTopics.map(function (topics) { return topics.slice(2); }).join("");
|
||||
var indexedParams = coder.decodeParams(this.types(true), indexedData);
|
||||
|
||||
var notIndexedData = data.data.slice(2);
|
||||
|
|
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
|
@ -146,8 +146,10 @@ SolidityEvent.prototype.decode = function (data) {
|
|||
};
|
||||
|
||||
data.data = data.data || '';
|
||||
data.topics = data.topics || [];
|
||||
|
||||
var indexedData = data.topics.slice(1).map(function (topics) { return topics.slice(2); }).join("");
|
||||
var argTopics = this._anonymous ? data.topics : data.topics.slice(1);
|
||||
var indexedData = argTopics.map(function (topics) { return topics.slice(2); }).join("");
|
||||
var indexedParams = coder.decodeParams(this.types(true), indexedData);
|
||||
|
||||
var notIndexedData = data.data.slice(2);
|
||||
|
|
|
@ -0,0 +1,180 @@
|
|||
var chai = require('chai');
|
||||
var assert = chai.assert;
|
||||
var BigNumber = require('bignumber.js');
|
||||
var SolidityEvent = require('../lib/web3/event');
|
||||
|
||||
var name = 'event1';
|
||||
var address = '0x1234567890123456789012345678901234567890';
|
||||
|
||||
var tests = [{
|
||||
abi: {
|
||||
name: name,
|
||||
inputs: []
|
||||
},
|
||||
data: {
|
||||
logIndex: '0x1',
|
||||
transactionIndex: '0x10',
|
||||
transactionHash: '0x1234567890',
|
||||
address: address,
|
||||
blockHash: '0x1234567890',
|
||||
blockNumber: '0x1'
|
||||
},
|
||||
expected: {
|
||||
event: name,
|
||||
args: {},
|
||||
logIndex: 1,
|
||||
transactionIndex: 16,
|
||||
transactionHash: '0x1234567890',
|
||||
address: address,
|
||||
blockHash: '0x1234567890',
|
||||
blockNumber: 1
|
||||
}
|
||||
}, {
|
||||
abi: {
|
||||
name: name,
|
||||
inputs: [{
|
||||
name: 'a',
|
||||
type: 'int',
|
||||
indexed: false
|
||||
}]
|
||||
},
|
||||
data: {
|
||||
logIndex: '0x1',
|
||||
transactionIndex: '0x10',
|
||||
transactionHash: '0x1234567890',
|
||||
address: address,
|
||||
blockHash: '0x1234567890',
|
||||
blockNumber: '0x1',
|
||||
data: '0x0000000000000000000000000000000000000000000000000000000000000001'
|
||||
},
|
||||
expected: {
|
||||
event: name,
|
||||
args: {
|
||||
a: new BigNumber(1)
|
||||
},
|
||||
logIndex: 1,
|
||||
transactionIndex: 16,
|
||||
transactionHash: '0x1234567890',
|
||||
address: address,
|
||||
blockHash: '0x1234567890',
|
||||
blockNumber: 1
|
||||
}
|
||||
}, {
|
||||
abi: {
|
||||
name: name,
|
||||
inputs: [{
|
||||
name: 'a',
|
||||
type: 'int',
|
||||
indexed: false
|
||||
}, {
|
||||
name: 'b',
|
||||
type: 'int',
|
||||
indexed: true
|
||||
}, {
|
||||
name: 'c',
|
||||
type: 'int',
|
||||
indexed: false
|
||||
}, {
|
||||
name: 'd',
|
||||
type: 'int',
|
||||
indexed: true
|
||||
}]
|
||||
},
|
||||
data: {
|
||||
logIndex: '0x1',
|
||||
transactionIndex: '0x10',
|
||||
transactionHash: '0x1234567890',
|
||||
address: address,
|
||||
blockHash: '0x1234567890',
|
||||
blockNumber: '0x1',
|
||||
data: '0x' +
|
||||
'0000000000000000000000000000000000000000000000000000000000000001' +
|
||||
'0000000000000000000000000000000000000000000000000000000000000004',
|
||||
topics: [
|
||||
address,
|
||||
'0x000000000000000000000000000000000000000000000000000000000000000a',
|
||||
'0x0000000000000000000000000000000000000000000000000000000000000010'
|
||||
]
|
||||
},
|
||||
expected: {
|
||||
event: name,
|
||||
args: {
|
||||
a: new BigNumber(1),
|
||||
b: new BigNumber(10),
|
||||
c: new BigNumber(4),
|
||||
d: new BigNumber(16)
|
||||
},
|
||||
logIndex: 1,
|
||||
transactionIndex: 16,
|
||||
transactionHash: '0x1234567890',
|
||||
address: address,
|
||||
blockHash: '0x1234567890',
|
||||
blockNumber: 1
|
||||
}
|
||||
}, {
|
||||
abi: {
|
||||
name: name,
|
||||
anonymous: true,
|
||||
inputs: [{
|
||||
name: 'a',
|
||||
type: 'int',
|
||||
indexed: false
|
||||
}, {
|
||||
name: 'b',
|
||||
type: 'int',
|
||||
indexed: true
|
||||
}, {
|
||||
name: 'c',
|
||||
type: 'int',
|
||||
indexed: false
|
||||
}, {
|
||||
name: 'd',
|
||||
type: 'int',
|
||||
indexed: true
|
||||
}]
|
||||
},
|
||||
data: {
|
||||
logIndex: '0x1',
|
||||
transactionIndex: '0x10',
|
||||
transactionHash: '0x1234567890',
|
||||
address: address,
|
||||
blockHash: '0x1234567890',
|
||||
blockNumber: '0x1',
|
||||
data: '0x' +
|
||||
'0000000000000000000000000000000000000000000000000000000000000001' +
|
||||
'0000000000000000000000000000000000000000000000000000000000000004',
|
||||
topics: [
|
||||
'0x000000000000000000000000000000000000000000000000000000000000000a',
|
||||
'0x0000000000000000000000000000000000000000000000000000000000000010'
|
||||
]
|
||||
},
|
||||
expected: {
|
||||
event: name,
|
||||
args: {
|
||||
a: new BigNumber(1),
|
||||
b: new BigNumber(10),
|
||||
c: new BigNumber(4),
|
||||
d: new BigNumber(16)
|
||||
},
|
||||
logIndex: 1,
|
||||
transactionIndex: 16,
|
||||
transactionHash: '0x1234567890',
|
||||
address: address,
|
||||
blockHash: '0x1234567890',
|
||||
blockNumber: 1
|
||||
}
|
||||
}];
|
||||
|
||||
describe('lib/web3/event', function () {
|
||||
describe('decode', function () {
|
||||
tests.forEach(function (test, index) {
|
||||
it('test no: ' + index, function () {
|
||||
var event = new SolidityEvent(test.abi, address);
|
||||
|
||||
var result = event.decode(test.data);
|
||||
assert.deepEqual(result, test.expected);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
Loading…
Reference in New Issue