From 40a8f83630acbe140709efbbfe88f4ea1574d584 Mon Sep 17 00:00:00 2001 From: yann300 Date: Wed, 19 May 2021 21:58:29 +0200 Subject: [PATCH] ensure calldata locals are propery tested --- .../test/decoder/contracts/calldata.ts | 5 +- libs/remix-debug/test/decoder/localDecoder.ts | 2 +- .../test/decoder/localsTests/calldata.ts | 94 +++---------------- 3 files changed, 15 insertions(+), 86 deletions(-) diff --git a/libs/remix-debug/test/decoder/contracts/calldata.ts b/libs/remix-debug/test/decoder/contracts/calldata.ts index 75b3694429..62d3df3ea4 100644 --- a/libs/remix-debug/test/decoder/contracts/calldata.ts +++ b/libs/remix-debug/test/decoder/contracts/calldata.ts @@ -2,12 +2,13 @@ module.exports = { contract: ` -contract calldataLocal { + pragma experimental ABIEncoderV2; + contract calldataLocal { constructor () public { } function level11(uint8[1] calldata foo, string[2][1] calldata boo) public { - + uint p = 45; } } `} diff --git a/libs/remix-debug/test/decoder/localDecoder.ts b/libs/remix-debug/test/decoder/localDecoder.ts index 1c647a6875..2a8f4f8997 100644 --- a/libs/remix-debug/test/decoder/localDecoder.ts +++ b/libs/remix-debug/test/decoder/localDecoder.ts @@ -37,7 +37,7 @@ async function test (st, vm, privateKey) { output = compiler.compile(compilerInput(calldataLocal.contract)) output = JSON.parse(output) - await calldataLocalTest(st, vm, privateKey, output.contracts['test.sol']['structArrayLocal'].evm.bytecode.object, output) + await calldataLocalTest(st, vm, privateKey, output.contracts['test.sol']['calldataLocal'].evm.bytecode.object, output) st.end() } diff --git a/libs/remix-debug/test/decoder/localsTests/calldata.ts b/libs/remix-debug/test/decoder/localsTests/calldata.ts index 98c55cf74b..8f7d3b5fa8 100644 --- a/libs/remix-debug/test/decoder/localsTests/calldata.ts +++ b/libs/remix-debug/test/decoder/localsTests/calldata.ts @@ -1,9 +1,9 @@ 'use strict' +import deepequal from 'deep-equal' import { sendTx } from '../vmCall' import { TraceManager } from '../../../src/trace/traceManager' import { CodeManager } from '../../../src/code/codeManager' -import { contractCreationToken } from '../../../src/trace/traceHelper' import { SolidityProxy } from '../../../src/solidity-decoder/solidityProxy' import { InternalCallTree } from '../../../src/solidity-decoder/internalCallTree' import { EventManager } from '../../../src/eventManager' @@ -13,8 +13,9 @@ module.exports = async function (st, vm, privateKey, contractBytecode, compilati let txHash try { let data = await sendTx(vm, { nonce: 0, privateKey: privateKey }, null, 0, contractBytecode) - const to = (data as any).result.contractAddress - data = await sendTx(vm, { nonce: 0, privateKey: privateKey }, to, 0, '0xa372a595000000000000000000000000000000000000000000000000000000000000000900000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000800000000000000000000000000000000000000000000000000000000000000006746573742031000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000067465737420320000000000000000000000000000000000000000000000000000') // call to level11 + const to = (data as any).result.createdAddress.toString() + // call to level11 + data = await sendTx(vm, { nonce: 1, privateKey: privateKey }, to, 0, 'a372a595000000000000000000000000000000000000000000000000000000000000000300000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000800000000000000000000000000000000000000000000000000000000000000001520000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000015400000000000000000000000000000000000000000000000000000000000000') txHash = (data as any).hash } catch (e) { return st.fail(e) @@ -24,7 +25,6 @@ module.exports = async function (st, vm, privateKey, contractBytecode, compilati if (error) { return st.fail(error) } - tx.to = contractCreationToken('0') var traceManager = new TraceManager({ web3: vm.web3 }) var codeManager = new CodeManager(traceManager) codeManager.clear() @@ -39,95 +39,23 @@ module.exports = async function (st, vm, privateKey, contractBytecode, compilati st.fail(reason) }) callTree.event.register('callTreeReady', (scopes, scopeStarts) => { - try { - let functions1 = callTree.retrieveFunctionsStack(102) - let functions2 = callTree.retrieveFunctionsStack(115) - let functions3 = callTree.retrieveFunctionsStack(13) - - st.equals(functions1.length, 1) - st.equals(functions2.length, 2) - st.equals(functions3.length, 0) - - st.equals(Object.keys(functions1[0])[0], 'functionDefinition') - st.equals(Object.keys(functions1[0])[1], 'inputs') - st.equals(functions1[0].inputs[0], 'foo') - st.equals(Object.keys(functions2[0])[0], 'functionDefinition') - st.equals(Object.keys(functions2[0])[1], 'inputs') - st.equals(Object.keys(functions2[1])[0], 'functionDefinition') - st.equals(Object.keys(functions2[1])[1], 'inputs') - st.equals(functions2[0].inputs[0], 'asd') - st.equals(functions2[1].inputs[0], 'foo') - - st.equals(functions1[0].functionDefinition.name, 'level11') - st.equals(functions2[0].functionDefinition.name, 'level12') - st.equals(functions2[1].functionDefinition.name, 'level11') - - st.equals(scopeStarts[0], '') - st.equals(scopeStarts[13], '1') - st.equals(scopeStarts[102], '2') - st.equals(scopeStarts[115], '2.1') - st.equals(scopeStarts[136], '3') - st.equals(scopeStarts[153], '4') - st.equals(scopeStarts[166], '4.1') - st.equals(scopes[''].locals['ui8'].type.typeName, 'uint8') - st.equals(scopes[''].locals['ui16'].type.typeName, 'uint16') - st.equals(scopes[''].locals['ui32'].type.typeName, 'uint32') - st.equals(scopes[''].locals['ui64'].type.typeName, 'uint64') - st.equals(scopes[''].locals['ui128'].type.typeName, 'uint128') - st.equals(scopes[''].locals['ui256'].type.typeName, 'uint256') - st.equals(scopes[''].locals['ui'].type.typeName, 'uint256') - st.equals(scopes[''].locals['i8'].type.typeName, 'int8') - st.equals(scopes[''].locals['i16'].type.typeName, 'int16') - st.equals(scopes[''].locals['i32'].type.typeName, 'int32') - st.equals(scopes[''].locals['i64'].type.typeName, 'int64') - st.equals(scopes[''].locals['i128'].type.typeName, 'int128') - st.equals(scopes[''].locals['i256'].type.typeName, 'int256') - st.equals(scopes[''].locals['i'].type.typeName, 'int256') - st.equals(scopes[''].locals['ishrink'].type.typeName, 'int32') - st.equals(scopes['2'].locals['ui8'].type.typeName, 'uint8') - st.equals(scopes['2.1'].locals['ui81'].type.typeName, 'uint8') - st.equals(scopes['3'].locals['ui81'].type.typeName, 'uint8') - st.equals(scopes['4'].locals['ui8'].type.typeName, 'uint8') - st.equals(scopes['4.1'].locals['ui81'].type.typeName, 'uint8') - } catch (e) { - st.fail(e.message) - } - - helper.decodeLocals(st, 95, traceManager, callTree, function (locals) { - st.equals(Object.keys(locals).length, 16) - st.equals(locals['ui8'].value, '130') - st.equals(locals['ui16'].value, '456') - st.equals(locals['ui32'].value, '4356') - st.equals(locals['ui64'].value, '3543543543') - st.equals(locals['ui128'].value, '234567') - st.equals(locals['ui256'].value, '115792089237316195423570985008687907853269984665640564039457584007880697216513') - st.equals(locals['ui'].value, '123545666') - st.equals(locals['i8'].value, '-45') - st.equals(locals['i16'].value, '-1234') - st.equals(locals['i32'].value, '3455') - st.equals(locals['i64'].value, '-35566') - st.equals(locals['i128'].value, '-444444') - st.equals(locals['i256'].value, '3434343') - st.equals(locals['i'].value, '-32432423423') - st.equals(locals['ishrink'].value, '2') - }) - - helper.decodeLocals(st, 106, traceManager, callTree, function (locals) { + helper.decodeLocals(st, 140, traceManager, callTree, function (locals) { try { - st.equals(locals['ui8'].value, '123') - st.equals(Object.keys(locals).length, 2) + const expected = {"p":{"value":"45","type":"uint256"},"foo":{"length":"1","value":[{"value":"3","type":"uint8"}],"type":"uint8[1]"},"boo":{"length":"1","value":[{"length":"2","value":[{"value":"R","type":"string"},{"value":"T","type":"string"}],"type":"string[2]"}],"type":"string[2][1]"}} + st.deepEqual(locals, expected) } catch (e) { st.fail(e.message) } resolve({}) }) }) + + traceManager.resolveTrace(tx).then(() => { debuggerEvent.trigger('newTraceLoaded', [traceManager.trace]) }).catch((error) => { st.fail(error) }) }) - }) -} - + }) +} \ No newline at end of file