-
Notifications
You must be signed in to change notification settings - Fork 5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add function compareBlockNumbers(a, b) No tests yet; BigNumber values not presently included * Fix format of fn declaration & add to exports * Finish fixing format of fn declaration * refactor exisiting pr * update changelog * more tests * more tests * move to web3-utils * fix if clause Co-authored-by: wbt <[email protected]> Co-authored-by: Frankie <[email protected]>
- Loading branch information
1 parent
9edd908
commit f33e5d5
Showing
3 changed files
with
119 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
const chai = require('chai'); | ||
const assert = chai.assert; | ||
const BN = require('bn.js'); | ||
const formatters = require('../packages/web3-utils/src/index.js'); | ||
|
||
const pending = "pending"; | ||
const latest = "latest"; | ||
const genesis = "genesis"; | ||
const earliest = "earliest"; | ||
|
||
const tests = [ | ||
// Base cases for numbers | ||
{ input: {a: 1, b: 1}, result: 0 }, | ||
{ input: {a: 1, b: 2}, result: -1 }, | ||
{ input: {a: 2, b: 1}, result: 1 }, | ||
// Base cases for BN | ||
{ input: {a: new BN(1), b: new BN(1)}, result: 0 }, | ||
{ input: {a: new BN(1), b: new BN(2)}, result: -1 }, | ||
{ input: {a: new BN(2), b: new BN(1)}, result: 1 }, | ||
// Base cases for numbers vs BN | ||
{ input: {a: new BN(1), b: 1}, result: 0 }, | ||
{ input: {a: new BN(1), b: 2}, result: -1 }, | ||
{ input: {a: new BN(2), b: 1}, result: 1 }, | ||
// Base cases for strings (sanity) | ||
{ input: {a: genesis, b: earliest}, result: 0 }, | ||
{ input: {a: genesis, b: 0}, result: 0 }, | ||
{ input: {a: earliest, b: 0}, result: 0 }, | ||
{ input: {a: latest, b: latest}, result: 0 }, | ||
{ input: {a: pending, b: pending}, result: 0 }, | ||
// Complex Strings | ||
// Genesis | ||
{ input: {a: earliest, b: 2}, result: -1 }, | ||
{ input: {a: earliest, b: new BN(2)}, result: -1 }, | ||
{ input: {a: earliest, b: latest}, result: -1 }, | ||
{ input: {a: earliest, b: pending}, result: -1 }, | ||
{ input: {a: genesis, b: 2}, result: -1 }, | ||
{ input: {a: genesis, b: new BN(2)}, result: -1 }, | ||
{ input: {a: genesis, b: latest}, result: -1 }, | ||
{ input: {a: genesis, b: pending}, result: -1 }, | ||
// latest | ||
{ input: {a: latest, b: 0}, result: 1 }, | ||
{ input: {a: latest, b: new BN(1)}, result: 1 }, | ||
{ input: {a: latest, b: pending}, result: -1 }, | ||
// pending | ||
{ input: {a: pending, b: 0}, result: 1 }, | ||
{ input: {a: pending, b: new BN(1)}, result: 1 }, | ||
]; | ||
|
||
describe('formatters', function () { | ||
describe('compare blocknumbers', function () { | ||
tests.forEach(function(test){ | ||
it('should return the correct value', function () { | ||
assert.deepEqual(formatters.compareBlockNumbers(test.input.a, test.input.b), test.result); | ||
}); | ||
}); | ||
}); | ||
|
||
}); |