web3.js/test/soldity.formatters.formatInputInt.js
Leonid Gaiazov 557268d116 Fixed a bug where negative numbers were rounded up instead of rounding down (#507)
There was an issue in combination of `solidity.formatters.formatInputInt` and `utils.toTwosComplement` where the value was rounded *after* performing the toTwosComplement. This caused negative floats to round _UP_ instead of rounding _DOWN_. I'm not sure if this is a bug or intentional, but from reading the code it appears to be intended to be rounded down.

Added simple unit test to demonstrate the behavior
2016-11-11 11:38:03 +01:00

22 lines
960 B
JavaScript

var chai = require('chai');
var assert = chai.assert;
var formatters = require('../lib/solidity/formatters.js');
var SolidityParam = require('../lib/solidity/param');
var tests = [
{ input: 1, result: new SolidityParam('0000000000000000000000000000000000000000000000000000000000000001') },
{ input: 1.1, result: new SolidityParam('0000000000000000000000000000000000000000000000000000000000000001') },
{ input: -1.1, result: new SolidityParam('ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff') },
{ input: -1, result: new SolidityParam('ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff') }
];
describe('formatters', function () {
describe('inputAddressFormatter', function () {
tests.forEach(function(test){
it('should return the correct value', function () {
assert.deepEqual(formatters.formatInputInt(test.input), test.result);
});
});
});
});