remix-project mirror
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
remix-project/test/solidity/storageDecoder.js

109 lines
4.3 KiB

8 years ago
'use strict'
var tape = require('tape')
var compiler = require('solc')
var stateDecoder = require('../../src/index').solidity.stateDecoder
tape('solidity', function (t) {
t.test('storage decoder', function (st) {
8 years ago
testIntStorage(st)
testByteStorage(st)
st.end()
8 years ago
})
})
8 years ago
function testIntStorage (st) {
var intStorage = require('./contracts/intStorage')
var output = compiler.compile(intStorage.contract, 0)
8 years ago
for (var storage of [intStorage.fullStorage, shrinkStorage(intStorage.fullStorage)]) {
var decoded = stateDecoder.solidityState(storage, output.sources, 'intStorage')
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'], '115792089237316195423570985008687907853269984665640564039457584007880697216513')
st.equal(decoded['ui'], '123545666')
st.equal(decoded['i8'], '-45')
st.equal(decoded['i16'], '-1234')
st.equal(decoded['i32'], '3455')
st.equal(decoded['i64'], '-35566')
st.equal(decoded['i128'], '-444444')
st.equal(decoded['i256'], '3434343')
st.equal(decoded['i'], '-32432423423')
st.equal(decoded['ishrink'], '2')
}
8 years ago
8 years ago
decoded = stateDecoder.solidityState({}, output.sources, 'intStorage')
st.equal(decoded['ui8'], '0')
st.equal(decoded['ui16'], '0')
st.equal(decoded['ui32'], '0')
st.equal(decoded['ui64'], '0')
st.equal(decoded['ui128'], '0')
st.equal(decoded['ui256'], '0')
st.equal(decoded['ui'], '0')
st.equal(decoded['i8'], '0')
st.equal(decoded['i16'], '0')
st.equal(decoded['i32'], '0')
st.equal(decoded['i64'], '0')
st.equal(decoded['i128'], '0')
st.equal(decoded['i256'], '0')
st.equal(decoded['i'], '0')
st.equal(decoded['ishrink'], '0')
}
function testByteStorage (st) {
var byteStorage = require('./contracts/byteStorage')
var output = compiler.compile(byteStorage.contract, 0)
var decoded = stateDecoder.solidityState(byteStorage.storage, output.sources, 'byteStorage')
st.equal(decoded['b1'], false)
st.equal(decoded['a1'], '0xfe350f199f244ac9a79038d254400b632a633225')
st.equal(decoded['b2'], true)
st.equal(decoded['dynb1'], '0x64796e616d69636279746573')
st.equal(decoded['stab'], '0x1')
st.equal(decoded['stab1'], '0x12')
st.equal(decoded['stab2'], '0x1579')
st.equal(decoded['stab3'], '0x359356')
st.equal(decoded['stab4'], '0x2375')
st.equal(decoded['stab5'], '0x2357645')
st.equal(decoded['stab6'], '0x324435')
st.equal(decoded['stab7'], '0x324324')
st.equal(decoded['stab8'], '0x324554645765')
st.equal(decoded['stab9'], '0x3434543')
st.equal(decoded['stab10'], '0x4543543654657')
st.equal(decoded['stab11'], '0x54354654')
st.equal(decoded['stab12'], '0x3')
st.equal(decoded['stab13'], '0x3243242345435')
st.equal(decoded['stab14'], '0x32454354354353')
st.equal(decoded['stab15'], '0x32454434435')
st.equal(decoded['stab16'], '0x3245435444')
st.equal(decoded['stab17'], '0x32454343243243245')
st.equal(decoded['stab18'], '0x324534325435435')
st.equal(decoded['stab19'], '0x324543435435435')
st.equal(decoded['stab20'], '0x32454543543AB35')
st.equal(decoded['stab21'], '0x32454432423435')
st.equal(decoded['stab22'], '0x324543AEF5')
st.equal(decoded['stab23'], '0x3245435FFF')
st.equal(decoded['stab24'], '0x3245435F')
st.equal(decoded['stab25'], '0x3245435F')
st.equal(decoded['stab26'], '0x3245435F')
st.equal(decoded['stab27'], '0x3245FFFFFFF')
st.equal(decoded['stab28'], '0x3241235')
st.equal(decoded['stab29'], '0x325213213')
st.equal(decoded['stab30'], '0x3245435232423')
st.equal(decoded['stab31'], '0x3245435123')
st.equal(decoded['stab32'], '0x324324423432543543AB')
st.equal(decoded['enumDec'], 'd')
st.equal(decoded['str1'], 'short')
st.equal(decoded['str2'], 'long__long__long__long__long__long__long__long__long__long__long__long__long__long__long__long__long__long__long__long__long__long__long__long__long__long__long__long__long__long__long__long__long__long__long__long__long__long__long__long__long__long__long__long__long__long__long__long')
}
function shrinkStorage (storage) {
var shrinkedStorage = {}
var regex = /0x(00)*(..)/
for (var key in storage) {
var value = storage[key]
shrinkedStorage[key.replace(regex, '0x$2')] = value.replace(regex, '0x$2')
}
return shrinkedStorage
}