diff --git a/libs/remix-simulator/src/methods/transactions.ts b/libs/remix-simulator/src/methods/transactions.ts index 9afa156df0..90bcc88600 100644 --- a/libs/remix-simulator/src/methods/transactions.ts +++ b/libs/remix-simulator/src/methods/transactions.ts @@ -25,6 +25,7 @@ export class Transactions { txRunnerVMInstance txRunnerInstance TX_INDEX = '0x0' // currently there's always only 1 tx per block, so the transaction index will always be 0x0 + comingCallId constructor (vmContext) { this.vmContext = vmContext @@ -73,7 +74,8 @@ export class Transactions { eth_getExecutionResultFromSimulator: this.eth_getExecutionResultFromSimulator.bind(this), eth_getHHLogsForTx: this.eth_getHHLogsForTx.bind(this), eth_getHashFromTagBySimulator: this.eth_getHashFromTagBySimulator.bind(this), - eth_callBySimulator: this.eth_callBySimulator.bind(this) + eth_callBySimulator: this.eth_callBySimulator.bind(this), + eth_registerCallId: this.eth_registerCallId.bind(this) } } @@ -195,6 +197,11 @@ export class Transactions { }) } + eth_registerCallId (payload, cb) { + this.comingCallId = payload.params[0] + cb() + } + eth_call (payload, cb) { // from might be lowercased address (web3) if (payload.params && payload.params.length > 0 && payload.params[0].from) { @@ -221,7 +228,12 @@ export class Transactions { returnValue: returnValue } // calls are not supposed to return a transaction hash. we do this for keeping track of it and allowing debugging calls. - this.tags[tag] = result.transactionHash + // either the tag is specified as a timestamp in a tx or the caller should call registerCallId before calling the call. + if (tag) this.tags[tag] = result.transactionHash + else if (this.comingCallId) { + this.tags[this.comingCallId] = result.transactionHash + this.comingCallId = null + } this.vmContext.trackExecResult(hash, execResult) return cb(null, returnValue) } diff --git a/libs/remix-simulator/src/provider.ts b/libs/remix-simulator/src/provider.ts index ac28e68b67..8317444203 100644 --- a/libs/remix-simulator/src/provider.ts +++ b/libs/remix-simulator/src/provider.ts @@ -168,4 +168,11 @@ class Web3TestPlugin extends Web3PluginBase { params: [payload] }) } + + public registerCallId(id) { + return this.requestManager.send({ + method: 'eth_registerCallId', + params: [id] + }) + } } diff --git a/libs/remix-tests/src/testRunner.ts b/libs/remix-tests/src/testRunner.ts index b243d386f8..a382e7de53 100644 --- a/libs/remix-tests/src/testRunner.ts +++ b/libs/remix-tests/src/testRunner.ts @@ -250,7 +250,7 @@ export function runTest (testName: string, testObject: any, contractDetails: Com if (func.constant) { sendParams = {} const tagTimestamp = 'remix_tests_tag' + Date.now() - sendParams.timestamp = tagTimestamp + if (web3.testPlugin && web3.testPlugin.registerCallId) web3.testPlugin.registerCallId(tagTimestamp) method.call(sendParams).then(async (result) => { const time = (Date.now() - startTime) / 1000.0 let tagTxHash