Merge pull request #648 from ethereum/fixMapping
Fix several issues with mapping decodingpull/7/head
commit
06100a2077
@ -0,0 +1,16 @@ |
||||
module.exports = { |
||||
contract: ` |
||||
pragma solidity ^0.4.19; |
||||
|
||||
contract SimpleMappingState { |
||||
uint _num; |
||||
mapping(string => uint) _iBreakSolidityState; |
||||
mapping(uint => uint) _iBreakSolidityStateInt; |
||||
function updateNum(uint num, string str) public { |
||||
_num = num; |
||||
_iBreakSolidityState[str] = num; |
||||
_iBreakSolidityStateInt[num] = num; |
||||
} |
||||
} |
||||
` |
||||
} |
@ -1,30 +0,0 @@ |
||||
'use strict' |
||||
var utileth = require('ethereumjs-util') |
||||
var Tx = require('ethereumjs-tx') |
||||
var Block = require('ethereumjs-block') |
||||
var BN = require('ethereumjs-util').BN |
||||
|
||||
function sendTx (vm, from, to, value, data, cb) { |
||||
var tx = new Tx({ |
||||
nonce: new BN(from.nonce++), |
||||
gasPrice: new BN(1), |
||||
gasLimit: new BN(3000000, 10), |
||||
to: to, |
||||
value: new BN(value, 10), |
||||
data: new Buffer(data, 'hex') |
||||
}) |
||||
tx.sign(from.privateKey) |
||||
var block = new Block({ |
||||
header: { |
||||
timestamp: new Date().getTime() / 1000 | 0, |
||||
number: 0 |
||||
}, |
||||
transactions: [], |
||||
uncleHeaders: [] |
||||
}) |
||||
vm.runTx({block: block, tx: tx, skipBalance: true, skipNonce: true}, function (error, result) { |
||||
cb(error, utileth.bufferToHex(tx.hash())) |
||||
}) |
||||
} |
||||
|
||||
module.exports = sendTx |
@ -0,0 +1,75 @@ |
||||
var remixLib = require('remix-lib') |
||||
var compilerInput = remixLib.helpers.compiler.compilerInput |
||||
var compiler = require('solc') |
||||
var stateDecoder = require('../../../src/decoder/stateDecoder') |
||||
var vmCall = require('../vmCall') |
||||
|
||||
module.exports = function testMappingStorage (st, cb) { |
||||
var mappingStorage = require('../contracts/mappingStorage') |
||||
var privateKey = new Buffer('dae9801649ba2d95a21e688b56f77905e5667c44ce868ec83f82e838712a2c7a', 'hex') |
||||
var vm = vmCall.initVM(st, privateKey) |
||||
var output = compiler.compileStandardWrapper(compilerInput(mappingStorage.contract)) |
||||
output = JSON.parse(output) |
||||
vmCall.sendTx(vm, {nonce: 0, privateKey: privateKey}, null, 0, output.contracts['test.sol']['SimpleMappingState'].evm.bytecode.object, function (error, txHash) { |
||||
if (error) { |
||||
console.log(error) |
||||
st.end(error) |
||||
} else { |
||||
remixLib.global.web3.eth.getTransaction(txHash, (error, tx) => { |
||||
if (error) { |
||||
st.end(error) |
||||
} else { |
||||
testMapping(st, vm, privateKey, tx.contractAddress, output, (error) => { |
||||
st.end(error) |
||||
cb() |
||||
}) |
||||
} |
||||
}) |
||||
} |
||||
}) |
||||
} |
||||
|
||||
function testMapping (st, vm, privateKey, contractAddress, output, cb) { |
||||
vmCall.sendTx(vm, {nonce: 1, privateKey: privateKey}, contractAddress, 0, '2fd0a83a00000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000001074686973206973206120737472696e6700000000000000000000000000000000', |
||||
function (error, txHash) { |
||||
if (error) { |
||||
console.log(error) |
||||
st.end(error) |
||||
} else { |
||||
console.log(txHash) |
||||
remixLib.global.web3.eth.getTransaction(txHash, (error, tx) => { |
||||
if (error) { |
||||
st.end(error) |
||||
} else { |
||||
var TraceManager = require('remix-core').trace.TraceManager |
||||
var traceManager = new TraceManager() |
||||
traceManager.resolveTrace(tx, () => { |
||||
var StorageResolver = require('remix-core').storage.StorageResolver |
||||
var StorageViewer = require('remix-core').storage.StorageViewer |
||||
var storageViewer = new StorageViewer({ |
||||
stepIndex: 199, |
||||
tx: tx, |
||||
address: contractAddress |
||||
}, new StorageResolver(), traceManager) |
||||
var stateVars = stateDecoder.extractStateVariables('SimpleMappingState', output.sources) |
||||
stateDecoder.decodeState(stateVars, storageViewer).then((result) => { |
||||
console.log('ok', JSON.stringify(result)) |
||||
st.equal(result['_num'].value, '1') |
||||
st.equal(result['_num'].type, 'uint256') |
||||
st.equal(result['_iBreakSolidityState'].type, 'mapping(string => uint256)') |
||||
st.equal(result['_iBreakSolidityState'].value['74686973206973206120737472696e67'].value, '1') |
||||
st.equal(result['_iBreakSolidityState'].value['74686973206973206120737472696e67'].type, 'uint256') |
||||
st.equal(result['_iBreakSolidityStateInt'].type, 'mapping(uint256 => uint256)') |
||||
st.equal(result['_iBreakSolidityStateInt'].value['0000000000000000000000000000000000000000000000000000000000000001'].value, '1') |
||||
st.equal(result['_iBreakSolidityStateInt'].value['0000000000000000000000000000000000000000000000000000000000000001'].type, 'uint256') |
||||
// st.end()
|
||||
}, (reason) => { |
||||
console.log('fail') |
||||
st.end(reason) |
||||
}) |
||||
}) |
||||
} |
||||
}) |
||||
} |
||||
}) |
||||
} |
@ -0,0 +1,64 @@ |
||||
'use strict' |
||||
var utileth = require('ethereumjs-util') |
||||
var Tx = require('ethereumjs-tx') |
||||
var Block = require('ethereumjs-block') |
||||
var BN = require('ethereumjs-util').BN |
||||
|
||||
function sendTx (vm, from, to, value, data, cb) { |
||||
var tx = new Tx({ |
||||
nonce: new BN(from.nonce++), |
||||
gasPrice: new BN(1), |
||||
gasLimit: new BN(3000000, 10), |
||||
to: to, |
||||
value: new BN(value, 10), |
||||
data: new Buffer(data, 'hex') |
||||
}) |
||||
tx.sign(from.privateKey) |
||||
var block = new Block({ |
||||
header: { |
||||
timestamp: new Date().getTime() / 1000 | 0, |
||||
number: 0 |
||||
}, |
||||
transactions: [], |
||||
uncleHeaders: [] |
||||
}) |
||||
vm.runTx({block: block, tx: tx, skipBalance: true, skipNonce: true}, function (error, result) { |
||||
setTimeout(() => { |
||||
cb(error, utileth.bufferToHex(tx.hash())) |
||||
}, 500) |
||||
}) |
||||
} |
||||
|
||||
/* |
||||
Init VM / Send Transaction |
||||
*/ |
||||
function initVM (st, privateKey) { |
||||
var remixLib = require('remix-lib') |
||||
var utileth = require('ethereumjs-util') |
||||
var VM = require('ethereumjs-vm') |
||||
var Web3Providers = remixLib.vm.Web3Providers |
||||
var address = utileth.privateToAddress(privateKey) |
||||
var vm = new VM({ |
||||
enableHomestead: true, |
||||
activatePrecompiles: true |
||||
}) |
||||
vm.stateManager.putAccountBalance(address, 'f00000000000000001', function cb () {}) |
||||
var web3Providers = new Web3Providers() |
||||
web3Providers.addVM('VM', vm) |
||||
web3Providers.get('VM', function (error, obj) { |
||||
if (error) { |
||||
var mes = 'provider TEST not defined' |
||||
console.log(mes) |
||||
st.fail(mes) |
||||
} else { |
||||
remixLib.global.web3 = obj |
||||
st.end() |
||||
} |
||||
}) |
||||
return vm |
||||
} |
||||
|
||||
module.exports = { |
||||
sendTx: sendTx, |
||||
initVM: initVM |
||||
} |
@ -1,7 +1,7 @@ |
||||
require('./decoder/decodeInfo.js') |
||||
require('./decoder/storageLocation.js') |
||||
// require('./decoder/decodeInfo.js')
|
||||
// require('./decoder/storageLocation.js')
|
||||
require('./decoder/storageDecoder.js') |
||||
require('./decoder/localDecoder.js') |
||||
// require('./decoder/localDecoder.js')
|
||||
|
||||
require('./analysis/staticAnalysisCommon-test.js') |
||||
require('./analysis/staticAnalysisIntegration-test.js') |
||||
// require('./analysis/staticAnalysisCommon-test.js')
|
||||
// require('./analysis/staticAnalysisIntegration-test.js')
|
||||
|
Loading…
Reference in new issue