parent
074e2ee57e
commit
e5a0f2c056
@ -0,0 +1,24 @@ |
||||
'use strict' |
||||
|
||||
module.exports = { |
||||
contract: ` |
||||
contract intLocal { |
||||
function set () { |
||||
uint8 ui8 = 130; |
||||
uint16 ui16 = 456; |
||||
uint32 ui32 = 4356; |
||||
uint64 ui64 = 3543543543; |
||||
uint128 ui128 = 234567; |
||||
uint256 ui256 = 115792089237316195423570985008687907853269984665640564039457584007880697216513; |
||||
uint ui = 123545666; |
||||
int8 i8 = -45; |
||||
int16 i16 = -1234; |
||||
int32 i32 = 3455; |
||||
int64 i64 = -35566; |
||||
int128 i128 = -444444; |
||||
int256 i256 = 3434343; |
||||
int i = -32432423423; |
||||
int32 ishrink = 2;
|
||||
} |
||||
} |
||||
`}
|
@ -0,0 +1,92 @@ |
||||
'use strict' |
||||
var tape = require('tape') |
||||
var compiler = require('solc') |
||||
var intLocal = require('./contracts/intLocal') |
||||
var TraceManager = require('../../src/trace/traceManager') |
||||
var CodeManager = require('../../src/code/codeManager') |
||||
var VM = require('ethereumjs-vm') |
||||
var Tx = require('ethereumjs-tx') |
||||
var Block = require('ethereumjs-block') |
||||
var BN = require('ethereumjs-util').BN |
||||
var utileth = require('ethereumjs-util') |
||||
var Web3Providers = require('../../src/web3Provider/web3Providers') |
||||
var traceHelper = require('../../src/helpers/traceHelper') |
||||
var util = require('../../src/helpers/global') |
||||
var LocalDecoder = require('../../src/solidity/localDecoder') |
||||
|
||||
tape('solidity', function (t) { |
||||
t.test('storage decoder', function (st) { |
||||
var privateKey = new Buffer('dae9801649ba2d95a21e688b56f77905e5667c44ce868ec83f82e838712a2c7a', 'hex') |
||||
var address = utileth.privateToAddress(privateKey) |
||||
var vm = initVM(st, address) |
||||
var output = compiler.compile(intLocal.contract, 0) |
||||
|
||||
sendTx(vm, {nonce: 0, privateKey: privateKey}, null, 0, output.contracts['intLocal'].bytecode, function (error, txHash) { |
||||
if (error) { |
||||
st.fail(error) |
||||
} else { |
||||
util.web3.getTransaction(txHash, function (error, tx) { |
||||
if (error) { |
||||
st.fail(error) |
||||
} else { |
||||
tx.to = traceHelper.contractCreationToken('0') |
||||
var traceManager = new TraceManager() |
||||
var codeManager = new CodeManager(traceManager) |
||||
var locals = new LocalDecoder(output, codeManager, traceManager.traceAnalyser.event) |
||||
traceManager.resolveTrace(tx, function (error, result) { |
||||
if (error) { |
||||
st.fail(error) |
||||
} else { |
||||
console.log(locals) |
||||
} |
||||
}) |
||||
} |
||||
}) |
||||
} |
||||
}) |
||||
}) |
||||
}) |
||||
|
||||
function initVM (st, address) { |
||||
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 { |
||||
util.web3 = obj |
||||
st.end() |
||||
} |
||||
}) |
||||
return vm |
||||
} |
||||
|
||||
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())) |
||||
}) |
||||
} |
Loading…
Reference in new issue