From e24d28c8c3e1b0974e214aee88a2649555fd4716 Mon Sep 17 00:00:00 2001 From: yann300 Date: Thu, 24 Nov 2016 11:34:03 +0100 Subject: [PATCH] fix int, uint --- src/solidity/types/Int.js | 2 +- src/solidity/types/Uint.js | 2 +- src/solidity/types/util.js | 6 ++++-- test/solidity/contracts/intStorage.js | 20 ++++---------------- test/solidity/storageDecoder.js | 6 ++++-- 5 files changed, 14 insertions(+), 22 deletions(-) diff --git a/src/solidity/types/Int.js b/src/solidity/types/Int.js index 7872c8bc1d..feee4f0fc8 100644 --- a/src/solidity/types/Int.js +++ b/src/solidity/types/Int.js @@ -8,7 +8,7 @@ function Int (storageBytes) { } Int.prototype.decodeFromStorage = function (location, storageContent) { - return util.decodeInt(location, storageContent, this.storageBytes) + return util.decodeInt(location, storageContent, this.storageBytes, true) } module.exports = Int diff --git a/src/solidity/types/Uint.js b/src/solidity/types/Uint.js index f4c8599cff..4993258d2d 100644 --- a/src/solidity/types/Uint.js +++ b/src/solidity/types/Uint.js @@ -10,7 +10,7 @@ function Uint (storageBytes) { } Uint.prototype.decodeFromStorage = function (location, storageContent) { - return util.decodeInt(location, storageContent, this.storageBytes) + return util.decodeInt(location, storageContent, this.storageBytes, false) } module.exports = Uint diff --git a/src/solidity/types/util.js b/src/solidity/types/util.js index be57fe621c..13636121a4 100644 --- a/src/solidity/types/util.js +++ b/src/solidity/types/util.js @@ -8,14 +8,16 @@ module.exports = { decodeInt: decodeInt } -function decodeInt (location, storageContent, byteLength) { +function decodeInt (location, storageContent, byteLength, signed) { var slotvalue = extractSlotValue(location.slot, storageContent) if (slotvalue === null) { return '0' } var value = extractHexByteSlice(slotvalue, byteLength, location.offset) var bigNumber = new BN(value, 16) - bigNumber = bigNumber.fromTwos(8 * byteLength) + if (signed) { + bigNumber = bigNumber.fromTwos(8 * byteLength) + } return bigNumber.toString(10) } diff --git a/test/solidity/contracts/intStorage.js b/test/solidity/contracts/intStorage.js index 318be44015..ec2ed7719e 100644 --- a/test/solidity/contracts/intStorage.js +++ b/test/solidity/contracts/intStorage.js @@ -3,12 +3,12 @@ module.exports = { contract: ` contract intStorage { - uint8 ui8 = 123; + uint8 ui8 = 130; uint16 ui16 = 456; uint32 ui32 = 4356; uint64 ui64 = 3543543543; uint128 ui128 = 234567; - uint256 ui256 = 234566666656; + uint256 public ui256 = 115792089237316195423570985008687907853269984665640564039457584007880697216513; uint ui = 123545666; int8 i8 = -45; int16 i16 = -1234; @@ -18,27 +18,15 @@ module.exports = { int256 i256 = 3434343; int i = -32432423423; int32 ishrink = 2; - - function intStorage () { - } } `, fullStorage: { - '0x0000000000000000000000000000000000000000000000000000000000000000': '0x000000000000000000000000000003944700000000d3362ef70000110401c87b', - '0x0000000000000000000000000000000000000000000000000000000000000001': '0x000000000000000000000000000000000000000000000000000000369d4349a0', + '0x0000000000000000000000000000000000000000000000000000000000000000': '0x000000000000000000000000000003944700000000d3362ef70000110401c882', + '0x0000000000000000000000000000000000000000000000000000000000000001': '0xfffffffffffffffffffffffffffffffffffffffffffffffffffffff872e07e01', '0x0000000000000000000000000000000000000000000000000000000000000002': '0x00000000000000000000000000000000000000000000000000000000075d2842', '0x0000000000000000000000000000000000000000000000000000000000000003': '0x00fffffffffffffffffffffffffff937e4ffffffffffff751200000d7ffb2ed3', '0x0000000000000000000000000000000000000000000000000000000000000004': '0x0000000000000000000000000000000000000000000000000000000000346767', '0x0000000000000000000000000000000000000000000000000000000000000005': '0xfffffffffffffffffffffffffffffffffffffffffffffffffffffff872e07e01', '0x0000000000000000000000000000000000000000000000000000000000000006': '0x0000000000000000000000000000000000000000000000000000000000000002' - }, - shrinkedStorage: { - '0x00': '0x03944700000000d3362ef70000110401c87b', - '0x01': '0x369d4349a0', - '0x02': '0x075d2842', - '0x03': '0xfffffffffffffffffffffffffff937e4ffffffffffff751200000d7ffb2ed3', - '0x04': '0x346767', - '0x05': '0xfffffffffffffffffffffffffffffffffffffffffffffffffffffff872e07e01', - '0x06': '0x02' } } diff --git a/test/solidity/storageDecoder.js b/test/solidity/storageDecoder.js index b3f8d143ee..e770c3442f 100644 --- a/test/solidity/storageDecoder.js +++ b/test/solidity/storageDecoder.js @@ -13,12 +13,12 @@ function testIntStorage (st) { var intStorage = require('./contracts/intStorage') var output = compiler.compile(intStorage.contract, 0) var decoded = stateDecoder.solidityState(intStorage.fullStorage, output.sources, 'intStorage') - st.equal(decoded['ui8'], '123') + st.equal(decoded['ui8'], '130') st.equal(decoded['ui16'], '456') st.equal(decoded['ui32'], '4356') st.equal(decoded['ui64'], '3543543543') st.equal(decoded['ui128'], '234567') - st.equal(decoded['ui256'], '234566666656') + st.equal(decoded['ui256'], '115792089237316195423570985008687907853269984665640564039457584007880697216513') st.equal(decoded['ui'], '123545666') st.equal(decoded['i8'], '-45') st.equal(decoded['i16'], '-1234') @@ -29,6 +29,7 @@ function testIntStorage (st) { st.equal(decoded['i'], '-32432423423') st.equal(decoded['ishrink'], '2') +/* decoded = stateDecoder.solidityState(intStorage.shrinkedStorage, output.sources, 'intStorage') st.equal(decoded['ui8'], '123') st.equal(decoded['ui16'], '456') @@ -45,6 +46,7 @@ function testIntStorage (st) { st.equal(decoded['i256'], '3434343') st.equal(decoded['i'], '-32432423423') st.equal(decoded['ishrink'], '2') + */ decoded = stateDecoder.solidityState({}, output.sources, 'intStorage') st.equal(decoded['ui8'], '0')