Skip to content

Commit

Permalink
Allow 0 fromBlock, toBlock values (#3089)
Browse files Browse the repository at this point in the history
* Allow 0 fromBlock, toBlock values
  • Loading branch information
cgewecke authored and nivida committed Oct 8, 2019
1 parent c1db2ca commit c51c3b9
Show file tree
Hide file tree
Showing 3 changed files with 111 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ Released with 1.0.0-beta.37 code base.

### Fixed

- Fix allow `0` as a valid `fromBlock` or `toBlock` filter param (#1100)
- Fix randomHex returning inconsistent string lengths (#1490)
- Fix make isBN minification safe (#1777)
- Fix incorrect references to BigNumber in utils.fromWei and utils.toWei error messages (#2468)
Expand Down
4 changes: 2 additions & 2 deletions packages/web3-core-helpers/src/formatters.js
Original file line number Diff line number Diff line change
Expand Up @@ -279,10 +279,10 @@ var inputLogFormatter = function(options) {
return utils.fromUtf8(value);
};

if (options.fromBlock)
if (options.fromBlock || options.fromBlock === 0)
options.fromBlock = inputBlockNumberFormatter(options.fromBlock);

if (options.toBlock)
if (options.toBlock || options.toBlock === 0)
options.toBlock = inputBlockNumberFormatter(options.toBlock);


Expand Down
108 changes: 108 additions & 0 deletions test/formatters.inputLogFormatter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
var chai = require('chai');
var assert = chai.assert;
var formatters = require('../packages/web3-core-helpers/src/formatters.js');

describe('InputLogFormatterTest', function() {

it('call inputLogFormatter with a valid log', function() {
var log = {
fromBlock: 'earliest',
toBlock: 'latest',
topics: ['0x0'],
address: '0x03C9A938fF7f54090d0d99e2c6f80380510Ea078'
};

assert.deepEqual(formatters.inputLogFormatter(log), {
fromBlock: 'earliest',
toBlock: 'latest',
topics: ['0x0'],
address: '0x03c9a938ff7f54090d0d99e2c6f80380510ea078'
});
});

it('call inputLogFormatter with numerical from/to blocks', function() {
var log = {
fromBlock: 1,
toBlock: 2,
topics: ['0x0'],
address: '0x03C9A938fF7f54090d0d99e2c6f80380510Ea078'
};

assert.deepEqual(formatters.inputLogFormatter(log), {
fromBlock: '0x1',
toBlock: '0x2',
topics: ['0x0'],
address: '0x03c9a938ff7f54090d0d99e2c6f80380510ea078'
});
});

it('call inputLogFormatter with zero valued from/to blocks', function() {
var log = {
fromBlock: 0,
toBlock: 0,
topics: ['0x0'],
address: '0x03C9A938fF7f54090d0d99e2c6f80380510Ea078'
};

assert.deepEqual(formatters.inputLogFormatter(log), {
fromBlock: '0x0',
toBlock: '0x0',
topics: ['0x0'],
address: '0x03c9a938ff7f54090d0d99e2c6f80380510ea078'
});
});

it('call inputLogFormatter with a array of addresses in the log', function() {
var log = {
fromBlock: 'earliest',
toBlock: 'latest',
topics: ['0x0'],
address: [
'0x03C9A938fF7f54090d0d99e2c6f80380510Ea078',
'0x03C9A938fF7f54090d0d99e2c6f80380510Ea078'
]
};

assert.deepEqual(formatters.inputLogFormatter(log), {
fromBlock: 'earliest',
toBlock: 'latest',
topics: ['0x0'],
address: [
'0x03c9a938ff7f54090d0d99e2c6f80380510ea078',
'0x03c9a938ff7f54090d0d99e2c6f80380510ea078'
]
});
});

it('call inputLogFormatter with an topic item of null', function() {
var log = {
fromBlock: 'earliest',
toBlock: 'latest',
topics: [null],
address: '0x03C9A938fF7f54090d0d99e2c6f80380510Ea078'
};

assert.deepEqual(formatters.inputLogFormatter(log), {
fromBlock: 'earliest',
toBlock: 'latest',
topics: [null],
address: '0x03c9a938ff7f54090d0d99e2c6f80380510ea078'
});
});

it('call inputLogFormatter with an topic item that does not start with "0x"', function() {
var log = {
fromBlock: 'earliest',
toBlock: 'latest',
topics: ['00'],
address: '0x03C9A938fF7f54090d0d99e2c6f80380510Ea078'
};

assert.deepEqual(formatters.inputLogFormatter(log), {
fromBlock: 'earliest',
toBlock: 'latest',
topics: ['0x3030'],
address: '0x03c9a938ff7f54090d0d99e2c6f80380510ea078'
});
});
});

0 comments on commit c51c3b9

Please sign in to comment.