Skip to content

Commit

Permalink
fixed filters encoding null
Browse files Browse the repository at this point in the history
  • Loading branch information
debris committed Apr 22, 2015
1 parent 4482d5b commit 5f2eb33
Show file tree
Hide file tree
Showing 11 changed files with 98 additions and 55 deletions.
26 changes: 12 additions & 14 deletions dist/web3-light.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions dist/web3-light.js.map

Large diffs are not rendered by default.

5 changes: 3 additions & 2 deletions dist/web3-light.min.js

Large diffs are not rendered by default.

26 changes: 12 additions & 14 deletions dist/web3.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions dist/web3.js.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions dist/web3.min.js

Large diffs are not rendered by default.

3 changes: 0 additions & 3 deletions lib/utils/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -214,9 +214,6 @@ var fromDecimal = function (value) {
var toHex = function (val) {
/*jshint maxcomplexity:7 */

if(val === null || typeof val === 'undefined')
return val;

if (isBoolean(val))
return fromDecimal(+val);

Expand Down
19 changes: 10 additions & 9 deletions lib/web3/event.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,15 +98,16 @@ SolidityEvent.prototype.encode = function (indexed, options) {
return i.indexed === true;
}).map(function (i) {
var value = indexed[i.name];
if (value !== undefined) {
if (utils.isArray(value)) {
return value.map(function (v) {
return '0x' + coder.encodeParam(i.type, v);
});
}
return '0x' + coder.encodeParam(i.type, value);
}
return null;
if (value === undefined || value === null) {
return null;
}

if (utils.isArray(value)) {
return value.map(function (v) {
return '0x' + coder.encodeParam(i.type, v);
});
}
return '0x' + coder.encodeParam(i.type, value);
});

options.topics = options.topics.concat(indexedTopics);
Expand Down
2 changes: 1 addition & 1 deletion lib/web3/filter.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ var getOptions = function (options) {
// make sure topics, get converted to hex
options.topics = options.topics || [];
options.topics = options.topics.map(function(topic) {
if (topic === null) {
if (topic === null || topic === undefined) {
return null;
} else if (utils.isArray(topic)) {
topic = topic.map(utils.toHex);
Expand Down
51 changes: 50 additions & 1 deletion test/event.encode.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,56 @@ var tests = [{
null // d
]
}

}, {
abi: {
name: 'event1',
inputs: [{
type: 'int',
name: 'a',
indexed: true
}, {
type: 'int',
name: 'b',
indexed: true
}]
},
address: '0x1234567890123456789012345678901234567890',
signature: 'ffff',
indexed: {
a: [16, 1],
b: 2
},
options: {},
expected: {
address: '0x1234567890123456789012345678901234567890',
topics: [
'0xffff',
['0x0000000000000000000000000000000000000000000000000000000000000010', '0x0000000000000000000000000000000000000000000000000000000000000001'],
'0x0000000000000000000000000000000000000000000000000000000000000002'
]
}
}, {
abi: {
name: 'event1',
inputs: [{
type: 'int',
name: 'a',
indexed: true
}]
},
address: '0x1234567890123456789012345678901234567890',
signature: 'ffff',
indexed: {
a: null
},
options: {},
expected: {
address: '0x1234567890123456789012345678901234567890',
topics: [
'0xffff',
null
]
}
}];

describe('lib/web3/event', function () {
Expand Down
1 change: 0 additions & 1 deletion test/utils.toHex.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ var BigNumber = require('bignumber.js');
var assert = chai.assert;

var tests = [
{ value: null, expected: null },
{ value: 1, expected: '0x1' },
{ value: '1', expected: '0x1' },
{ value: '0x1', expected: '0x1'},
Expand Down

0 comments on commit 5f2eb33

Please sign in to comment.