Commit a7760482 authored by ben-chain's avatar ben-chain

linting

parent a56125c2
import { usePlugin, BuidlerConfig } from '@nomiclabs/buidler/config' import { usePlugin, BuidlerConfig } from '@nomiclabs/buidler/config'
import { DEFAULT_ACCOUNTS_BUIDLER, RUN_OVM_TEST_GAS } from './test/helpers/constants' import {
DEFAULT_ACCOUNTS_BUIDLER,
RUN_OVM_TEST_GAS,
} from './test/helpers/constants'
usePlugin('@nomiclabs/buidler-ethers') usePlugin('@nomiclabs/buidler-ethers')
usePlugin('@nomiclabs/buidler-waffle') usePlugin('@nomiclabs/buidler-waffle')
......
/* Internal Imports */ /* Internal Imports */
import { import {
ExecutionManagerTestRunner, ExecutionManagerTestRunner,
TestDefinition, TestDefinition,
NON_NULL_BYTES32, NON_NULL_BYTES32,
OVM_TX_GAS_LIMIT OVM_TX_GAS_LIMIT,
} from '../../../../helpers' } from '../../../../helpers'
const globalContext = { const globalContext = {
ovmCHAINID: 420 ovmCHAINID: 420,
} }
const transactionContext = { const transactionContext = {
ovmTIMESTAMP: 12341234, ovmTIMESTAMP: 12341234,
ovmNUMBER: 13371337, ovmNUMBER: 13371337,
ovmGASLIMIT: 45674567, ovmGASLIMIT: 45674567,
ovmTXGASLIMIT: 78907890, ovmTXGASLIMIT: 78907890,
ovmL1QUEUEORIGIN: 1, ovmL1QUEUEORIGIN: 1,
ovmL1TXORIGIN: '0x1234123412341234123412341234123412341234' ovmL1TXORIGIN: '0x1234123412341234123412341234123412341234',
} }
const messageContext = { const messageContext = {
ovmCALLER: '0x6789678967896789678967896789678967896789', ovmCALLER: '0x6789678967896789678967896789678967896789',
ovmADDRESS: '0x4567456745674567456745674567456745674567' ovmADDRESS: '0x4567456745674567456745674567456745674567',
} }
const test_contextOpcodes: TestDefinition = { const test_contextOpcodes: TestDefinition = {
name: 'unit tests for basic getter opcodes', name: 'unit tests for basic getter opcodes',
preState: { preState: {
ExecutionManager: { ExecutionManager: {
ovmStateManager: '$OVM_STATE_MANAGER', ovmStateManager: '$OVM_STATE_MANAGER',
ovmSafetyChecker: '$OVM_SAFETY_CHECKER', ovmSafetyChecker: '$OVM_SAFETY_CHECKER',
messageRecord: { messageRecord: {
nuisanceGasLeft: OVM_TX_GAS_LIMIT, nuisanceGasLeft: OVM_TX_GAS_LIMIT,
},
globalContext,
transactionContext,
messageContext
},
StateManager: {
owner: '$OVM_EXECUTION_MANAGER',
accounts: {
$DUMMY_OVM_ADDRESS_1: {
codeHash: NON_NULL_BYTES32,
ethAddress: '$OVM_CALL_HELPER',
},
},
}, },
globalContext,
transactionContext,
messageContext,
}, },
parameters: [ StateManager: {
// TODO: re-enable when we can unwrap tests' ovmCALL owner: '$OVM_EXECUTION_MANAGER',
// { accounts: {
// name: 'gets ovmCALLER', $DUMMY_OVM_ADDRESS_1: {
// steps: [ codeHash: NON_NULL_BYTES32,
// { ethAddress: '$OVM_CALL_HELPER',
// functionName: 'ovmCALLER', },
// expectedReturnValue: messageContext.ovmCALLER
// }
// ],
// },
// {
// name: 'gets ovmADDRESS',
// steps: [
// {
// functionName: 'ovmADDRESS',
// expectedReturnValue: messageContext.ovmADDRESS
// }
// ],
// },
{
name: 'gets ovmTIMESTAMP',
steps: [
{
functionName: 'ovmTIMESTAMP',
expectedReturnValue: transactionContext.ovmTIMESTAMP
}
],
},
{
name: 'gets ovmNUMBER',
steps: [
{
functionName: 'ovmNUMBER',
expectedReturnValue: transactionContext.ovmNUMBER
}
],
},
{
name: 'gets ovmGASLIMIT',
steps: [
{
functionName: 'ovmGASLIMIT',
expectedReturnValue: transactionContext.ovmGASLIMIT
}
],
},
{
name: 'gets ovmL1QUEUEORIGIN',
steps: [
{
functionName: 'ovmL1QUEUEORIGIN',
expectedReturnValue: transactionContext.ovmL1QUEUEORIGIN
}
],
},
{
name: 'gets ovmL1TXORIGIN',
steps: [
{
functionName: 'ovmL1TXORIGIN',
expectedReturnValue: transactionContext.ovmL1TXORIGIN
}
],
}, },
{ },
name: 'gets ovmCHAINID', },
steps: [ parameters: [
{ // TODO: re-enable when we can unwrap tests' ovmCALL
functionName: 'ovmCHAINID', // {
expectedReturnValue: globalContext.ovmCHAINID // name: 'gets ovmCALLER',
} // steps: [
], // {
}, // functionName: 'ovmCALLER',
], // expectedReturnValue: messageContext.ovmCALLER
} // }
// ],
const runner = new ExecutionManagerTestRunner() // },
runner.run(test_contextOpcodes) // {
\ No newline at end of file // name: 'gets ovmADDRESS',
// steps: [
// {
// functionName: 'ovmADDRESS',
// expectedReturnValue: messageContext.ovmADDRESS
// }
// ],
// },
{
name: 'gets ovmTIMESTAMP',
steps: [
{
functionName: 'ovmTIMESTAMP',
expectedReturnValue: transactionContext.ovmTIMESTAMP,
},
],
},
{
name: 'gets ovmNUMBER',
steps: [
{
functionName: 'ovmNUMBER',
expectedReturnValue: transactionContext.ovmNUMBER,
},
],
},
{
name: 'gets ovmGASLIMIT',
steps: [
{
functionName: 'ovmGASLIMIT',
expectedReturnValue: transactionContext.ovmGASLIMIT,
},
],
},
{
name: 'gets ovmL1QUEUEORIGIN',
steps: [
{
functionName: 'ovmL1QUEUEORIGIN',
expectedReturnValue: transactionContext.ovmL1QUEUEORIGIN,
},
],
},
{
name: 'gets ovmL1TXORIGIN',
steps: [
{
functionName: 'ovmL1TXORIGIN',
expectedReturnValue: transactionContext.ovmL1TXORIGIN,
},
],
},
{
name: 'gets ovmCHAINID',
steps: [
{
functionName: 'ovmCHAINID',
expectedReturnValue: globalContext.ovmCHAINID,
},
],
},
],
}
const runner = new ExecutionManagerTestRunner()
runner.run(test_contextOpcodes)
/* Internal Imports */ /* Internal Imports */
import { import {
ExecutionManagerTestRunner, ExecutionManagerTestRunner,
TestDefinition, TestDefinition,
OVM_TX_GAS_LIMIT, OVM_TX_GAS_LIMIT,
NON_NULL_BYTES32, NON_NULL_BYTES32,
REVERT_FLAGS, REVERT_FLAGS,
VERIFIED_EMPTY_CONTRACT_HASH, VERIFIED_EMPTY_CONTRACT_HASH,
NUISANCE_GAS_COSTS, NUISANCE_GAS_COSTS,
Helper_TestRunner_BYTELEN, Helper_TestRunner_BYTELEN,
ZERO_ADDRESS ZERO_ADDRESS,
} from '../../../../helpers' } from '../../../../helpers'
const DUMMY_REVERT_DATA = const DUMMY_REVERT_DATA =
'0xdeadbeef1e5420deadbeef1e5420deadbeef1e5420deadbeef1e5420deadbeef1e5420' '0xdeadbeef1e5420deadbeef1e5420deadbeef1e5420deadbeef1e5420deadbeef1e5420'
const CREATED_CONTRACT_1 = '0x2bda4a99d5be88609d23b1e4ab5d1d34fb1c2feb' const CREATED_CONTRACT_1 = '0x2bda4a99d5be88609d23b1e4ab5d1d34fb1c2feb'
const FRESH_CALL_NUISANCE_GAS_COST = Helper_TestRunner_BYTELEN * NUISANCE_GAS_COSTS.NUISANCE_GAS_PER_CONTRACT_BYTE + NUISANCE_GAS_COSTS.MIN_NUISANCE_GAS_PER_CONTRACT const FRESH_CALL_NUISANCE_GAS_COST =
Helper_TestRunner_BYTELEN *
console.log(`first call cost: ${FRESH_CALL_NUISANCE_GAS_COST}`) NUISANCE_GAS_COSTS.NUISANCE_GAS_PER_CONTRACT_BYTE +
NUISANCE_GAS_COSTS.MIN_NUISANCE_GAS_PER_CONTRACT
const test_nuisanceGas: TestDefinition = { const test_nuisanceGas: TestDefinition = {
name: 'Basic tests for nuisance gas', name: 'Basic tests for nuisance gas',
preState: { preState: {
ExecutionManager: { ExecutionManager: {
ovmStateManager: '$OVM_STATE_MANAGER', ovmStateManager: '$OVM_STATE_MANAGER',
ovmSafetyChecker: '$OVM_SAFETY_CHECKER', ovmSafetyChecker: '$OVM_SAFETY_CHECKER',
messageRecord: { messageRecord: {
nuisanceGasLeft: OVM_TX_GAS_LIMIT, nuisanceGasLeft: OVM_TX_GAS_LIMIT,
},
},
StateManager: {
owner: '$OVM_EXECUTION_MANAGER',
accounts: {
$DUMMY_OVM_ADDRESS_1: {
codeHash: NON_NULL_BYTES32,
ethAddress: '$OVM_CALL_HELPER',
},
$DUMMY_OVM_ADDRESS_2: {
codeHash: NON_NULL_BYTES32,
ethAddress: '$OVM_CALL_HELPER',
},
$DUMMY_OVM_ADDRESS_3: {
codeHash: VERIFIED_EMPTY_CONTRACT_HASH,
ethAddress: '0x' + '00'.repeat(20),
},
[CREATED_CONTRACT_1]: {
codeHash: VERIFIED_EMPTY_CONTRACT_HASH,
ethAddress: '0x' + '00'.repeat(20),
}, },
}, },
StateManager: { },
owner: '$OVM_EXECUTION_MANAGER', },
accounts: { subTests: [
$DUMMY_OVM_ADDRESS_1: { {
codeHash: NON_NULL_BYTES32, name:
ethAddress: '$OVM_CALL_HELPER', 'ovmCALL consumes nuisance gas of CODESIZE * NUISANCE_GAS_PER_CONTRACT_BYTE',
}, postState: {
$DUMMY_OVM_ADDRESS_2: { ExecutionManager: {
codeHash: NON_NULL_BYTES32, messageRecord: {
ethAddress: '$OVM_CALL_HELPER', nuisanceGasLeft: OVM_TX_GAS_LIMIT - FRESH_CALL_NUISANCE_GAS_COST,
},
$DUMMY_OVM_ADDRESS_3: {
codeHash: VERIFIED_EMPTY_CONTRACT_HASH,
ethAddress: '0x' + '00'.repeat(20),
},
[CREATED_CONTRACT_1]: {
codeHash: VERIFIED_EMPTY_CONTRACT_HASH,
ethAddress: '0x' + '00'.repeat(20),
}, },
}, },
}, },
parameters: [
{
name: 'single ovmCALL',
steps: [
// do a non-nuisance-gas-consuming opcode (test runner auto-wraps in ovmCALL)
{
functionName: 'ovmADDRESS',
expectedReturnValue: '$DUMMY_OVM_ADDRESS_1',
},
],
},
{
name: 'nested ovmCALL, same address',
steps: [
{
functionName: 'ovmCALL',
functionParams: {
gasLimit: OVM_TX_GAS_LIMIT,
target: '$DUMMY_OVM_ADDRESS_1',
subSteps: [],
},
expectedReturnStatus: true,
},
],
},
],
}, },
subTests: [ {
name:
'ovmCALL consumes nuisance gas of CODESIZE * NUISANCE_GAS_PER_CONTRACT_BYTE twice for two unique ovmCALLS',
postState: {
ExecutionManager: {
messageRecord: {
nuisanceGasLeft:
OVM_TX_GAS_LIMIT - 2 * FRESH_CALL_NUISANCE_GAS_COST,
},
},
},
parameters: [
{ {
name: 'ovmCALL consumes nuisance gas of CODESIZE * NUISANCE_GAS_PER_CONTRACT_BYTE', name: 'directly nested ovmCALL',
postState: { steps: [
ExecutionManager: { {
messageRecord: { functionName: 'ovmCALL',
nuisanceGasLeft: OVM_TX_GAS_LIMIT - FRESH_CALL_NUISANCE_GAS_COST functionParams: {
} gasLimit: OVM_TX_GAS_LIMIT,
} target: '$DUMMY_OVM_ADDRESS_2',
subSteps: [],
},
expectedReturnStatus: true,
}, },
parameters: [ ],
{
name: 'single ovmCALL',
steps: [
// do a non-nuisance-gas-consuming opcode (test runner auto-wraps in ovmCALL)
{
functionName: 'ovmADDRESS',
expectedReturnValue: "$DUMMY_OVM_ADDRESS_1",
},
],
},
{
name: 'nested ovmCALL, same address',
steps: [
{
functionName: 'ovmCALL',
functionParams: {
gasLimit: OVM_TX_GAS_LIMIT,
target: "$DUMMY_OVM_ADDRESS_1",
subSteps: []
},
expectedReturnStatus: true
},
],
}
]
}, },
{ {
name: 'ovmCALL consumes nuisance gas of CODESIZE * NUISANCE_GAS_PER_CONTRACT_BYTE twice for two unique ovmCALLS', name: 'with a call to previously called contract too',
postState: { steps: [
ExecutionManager: { {
messageRecord: { functionName: 'ovmCALL',
nuisanceGasLeft: OVM_TX_GAS_LIMIT - 2 * FRESH_CALL_NUISANCE_GAS_COST functionParams: {
} gasLimit: OVM_TX_GAS_LIMIT,
} target: '$DUMMY_OVM_ADDRESS_2',
subSteps: [
{
functionName: 'ovmCALL',
functionParams: {
gasLimit: OVM_TX_GAS_LIMIT,
target: '$DUMMY_OVM_ADDRESS_1',
subSteps: [],
},
expectedReturnStatus: true,
},
],
},
expectedReturnStatus: true,
}, },
parameters: [ ],
{
name: 'directly nested ovmCALL',
steps: [
{
functionName: 'ovmCALL',
functionParams: {
gasLimit: OVM_TX_GAS_LIMIT,
target: "$DUMMY_OVM_ADDRESS_2",
subSteps: []
},
expectedReturnStatus: true
},
],
},
{
name: 'with a call to previously called contract too',
steps: [
{
functionName: 'ovmCALL',
functionParams: {
gasLimit: OVM_TX_GAS_LIMIT,
target: "$DUMMY_OVM_ADDRESS_2",
subSteps: [
{
functionName: 'ovmCALL',
functionParams: {
gasLimit: OVM_TX_GAS_LIMIT,
target: '$DUMMY_OVM_ADDRESS_1',
subSteps: []
},
expectedReturnStatus: true
}
]
},
expectedReturnStatus: true
},
],
}
]
}, },
],
},
{
name:
'ovmCALL consumes all allotted nuisance gas if code contract throws unknown exception',
postState: {
ExecutionManager: {
messageRecord: {
nuisanceGasLeft:
OVM_TX_GAS_LIMIT -
FRESH_CALL_NUISANCE_GAS_COST -
OVM_TX_GAS_LIMIT / 2,
},
},
},
parameters: [
{ {
name: 'ovmCALL consumes all allotted nuisance gas if code contract throws unknown exception', name: 'give 1/2 gas to evmINVALID',
postState: { steps: [
ExecutionManager: { {
messageRecord: { functionName: 'ovmCALL',
nuisanceGasLeft: OVM_TX_GAS_LIMIT - FRESH_CALL_NUISANCE_GAS_COST - OVM_TX_GAS_LIMIT / 2 functionParams: {
} gasLimit: OVM_TX_GAS_LIMIT / 2,
} target: '$DUMMY_OVM_ADDRESS_1',
subSteps: [
{
functionName: 'evmINVALID',
},
],
},
expectedReturnStatus: true,
expectedReturnValue: {
ovmSuccess: false,
returnData: '0x',
},
}, },
parameters: [ ],
{
name: 'give 1/2 gas to evmINVALID',
steps: [
{
functionName: 'ovmCALL',
functionParams: {
gasLimit: OVM_TX_GAS_LIMIT / 2,
target: "$DUMMY_OVM_ADDRESS_1",
subSteps: [
{
functionName: 'evmINVALID'
}
]
},
expectedReturnStatus: true,
expectedReturnValue: {
ovmSuccess: false,
returnData: '0x'
}
},
],
},
]
}, },
],
},
{
name:
'ovmCREATE consumes all allotted nuisance gas if creation code throws data-less exception',
postState: {
ExecutionManager: {
messageRecord: {
// note: this is slightly higher than the "idealized" value which would be:
// OVM_TX_GAS_LIMIT / 2 - 2 * ( Helper_TestRunner_BYTELEN * NUISANCE_GAS_PER_CONTRACT_BYTE )
// This is because there is natural gas consumption between the ovmCALL(GAS/2) and ovmCREATE, which allots nuisance gas via _getNuisanceGasLimit.
// This means that the ovmCREATE exception, DOES consumes all nuisance gas allotted, but that allotment
// is less than the full OVM_TX_GAS_LIMIT / 2 which is alloted to the parent ovmCALL.
nuisanceGasLeft: 4603714,
},
},
},
parameters: [
{ {
name: 'ovmCREATE consumes all allotted nuisance gas if creation code throws data-less exception', name: 'give 1/2 gas to ovmCALL => ovmCREATE, evmINVALID',
postState: { steps: [
ExecutionManager: { {
messageRecord: { functionName: 'ovmCALL',
// note: this is slightly higher than the "idealized" value which would be: functionParams: {
// OVM_TX_GAS_LIMIT / 2 - 2 * ( Helper_TestRunner_BYTELEN * NUISANCE_GAS_PER_CONTRACT_BYTE ) target: '$DUMMY_OVM_ADDRESS_1',
// This is because there is natural gas consumption between the ovmCALL(GAS/2) and ovmCREATE, which allots nuisance gas via _getNuisanceGasLimit. gasLimit: OVM_TX_GAS_LIMIT / 2,
// This means that the ovmCREATE exception, DOES consumes all nuisance gas allotted, but that allotment subSteps: [
// is less than the full OVM_TX_GAS_LIMIT / 2 which is alloted to the parent ovmCALL. {
nuisanceGasLeft: 4603714 functionName: 'ovmCREATE',
} functionParams: {
} subSteps: [
{
functionName: 'evmINVALID',
},
],
},
expectedReturnStatus: true,
expectedReturnValue: ZERO_ADDRESS,
},
],
},
expectedReturnStatus: true,
}, },
parameters: [ ],
{ },
name: 'give 1/2 gas to ovmCALL => ovmCREATE, evmINVALID', ],
steps: [ },
{ ],
functionName: 'ovmCALL', }
functionParams: {
target: '$DUMMY_OVM_ADDRESS_1', const runner = new ExecutionManagerTestRunner()
gasLimit: OVM_TX_GAS_LIMIT / 2, runner.run(test_nuisanceGas)
subSteps: [
{
functionName: 'ovmCREATE',
functionParams: {
subSteps: [
{
functionName: 'evmINVALID'
}
]
},
expectedReturnStatus: true,
expectedReturnValue: ZERO_ADDRESS
},
]
},
expectedReturnStatus: true,
}
],
}
]
}
],
}
const runner = new ExecutionManagerTestRunner()
runner.run(test_nuisanceGas)
\ No newline at end of file
...@@ -186,7 +186,11 @@ const test_ovmSTATICCALL: TestDefinition = { ...@@ -186,7 +186,11 @@ const test_ovmSTATICCALL: TestDefinition = {
[ [
{ {
functionName: 'ovmSTATICCALL', functionName: 'ovmSTATICCALL',
functionParams: [OVM_TX_GAS_LIMIT, '$DUMMY_OVM_ADDRESS_2', []], functionParams: [
OVM_TX_GAS_LIMIT,
'$DUMMY_OVM_ADDRESS_2',
[],
],
expectedReturnStatus: true, expectedReturnStatus: true,
expectedReturnValues: [], expectedReturnValues: [],
}, },
...@@ -226,7 +230,12 @@ const test_ovmSTATICCALL: TestDefinition = { ...@@ -226,7 +230,12 @@ const test_ovmSTATICCALL: TestDefinition = {
functionParams: [ functionParams: [
OVM_TX_GAS_LIMIT / 2, OVM_TX_GAS_LIMIT / 2,
'$DUMMY_OVM_ADDRESS_2', '$DUMMY_OVM_ADDRESS_2',
[REVERT_FLAGS.STATIC_VIOLATION, '0x', OVM_TX_GAS_LIMIT / 2, 0], [
REVERT_FLAGS.STATIC_VIOLATION,
'0x',
OVM_TX_GAS_LIMIT / 2,
0,
],
], ],
expectedReturnStatus: true, expectedReturnStatus: true,
expectedReturnValues: [false, '0x'], expectedReturnValues: [false, '0x'],
...@@ -257,7 +266,12 @@ const test_ovmSTATICCALL: TestDefinition = { ...@@ -257,7 +266,12 @@ const test_ovmSTATICCALL: TestDefinition = {
functionParams: [ functionParams: [
OVM_TX_GAS_LIMIT / 2, OVM_TX_GAS_LIMIT / 2,
'$DUMMY_OVM_ADDRESS_2', '$DUMMY_OVM_ADDRESS_2',
[REVERT_FLAGS.STATIC_VIOLATION, '0x', OVM_TX_GAS_LIMIT / 2, 0], [
REVERT_FLAGS.STATIC_VIOLATION,
'0x',
OVM_TX_GAS_LIMIT / 2,
0,
],
], ],
expectedReturnStatus: true, expectedReturnStatus: true,
expectedReturnValues: [false, '0x'], expectedReturnValues: [false, '0x'],
......
...@@ -21,7 +21,7 @@ export const decodeRevertData = (revertData: string): any => { ...@@ -21,7 +21,7 @@ export const decodeRevertData = (revertData: string): any => {
['uint256', 'uint256', 'uint256', 'bytes'], ['uint256', 'uint256', 'uint256', 'bytes'],
revertData revertData
) )
console.log(`flag is: ${decoded[0].toNumber()}`)
return ( return (
'[revertFlag:' + '[revertFlag:' +
Object.keys(REVERT_FLAGS)[decoded[0]] + Object.keys(REVERT_FLAGS)[decoded[0]] +
......
...@@ -32,5 +32,5 @@ export const NUISANCE_GAS_COSTS = { ...@@ -32,5 +32,5 @@ export const NUISANCE_GAS_COSTS = {
MIN_GAS_FOR_INVALID_STATE_ACCESS: 30000, MIN_GAS_FOR_INVALID_STATE_ACCESS: 30000,
} }
// TODO: get this exported/imported somehow in a way that we can do math on it. unfortunately using require('.....artifacts/contract.json') is erroring... // TODO: get this exported/imported somehow in a way that we can do math on it. unfortunately using require('.....artifacts/contract.json') is erroring...
export const Helper_TestRunner_BYTELEN = 3654 export const Helper_TestRunner_BYTELEN = 3654
\ No newline at end of file
...@@ -29,7 +29,11 @@ import { ...@@ -29,7 +29,11 @@ import {
} from './test.types' } from './test.types'
import { encodeRevertData } from '../codec' import { encodeRevertData } from '../codec'
import { getModifiableStorageFactory } from '../storage/contract-storage' import { getModifiableStorageFactory } from '../storage/contract-storage'
import { OVM_TX_GAS_LIMIT, RUN_OVM_TEST_GAS, NON_NULL_BYTES32 } from '../constants' import {
OVM_TX_GAS_LIMIT,
RUN_OVM_TEST_GAS,
NON_NULL_BYTES32,
} from '../constants'
export class ExecutionManagerTestRunner { export class ExecutionManagerTestRunner {
private snapshot: string private snapshot: string
...@@ -55,8 +59,14 @@ export class ExecutionManagerTestRunner { ...@@ -55,8 +59,14 @@ export class ExecutionManagerTestRunner {
test.subTests?.map((subTest) => { test.subTests?.map((subTest) => {
this.run({ this.run({
...subTest, ...subTest,
preState: merge(cloneDeep(test.preState), cloneDeep(subTest.preState)), preState: merge(
postState: merge(cloneDeep(test.postState), cloneDeep(subTest.postState)) cloneDeep(test.preState),
cloneDeep(subTest.preState)
),
postState: merge(
cloneDeep(test.postState),
cloneDeep(subTest.postState)
),
}) })
}) })
...@@ -123,13 +133,11 @@ export class ExecutionManagerTestRunner { ...@@ -123,13 +133,11 @@ export class ExecutionManagerTestRunner {
} }
private async initContracts() { private async initContracts() {
console.log('initcontracts')
if (this.snapshot) { if (this.snapshot) {
await ethers.provider.send('evm_revert', [this.snapshot]) await ethers.provider.send('evm_revert', [this.snapshot])
this.snapshot = await ethers.provider.send('evm_snapshot', []) this.snapshot = await ethers.provider.send('evm_snapshot', [])
return return
} }
console.log('no snapshot')
this.contracts.OVM_SafetyChecker = await ( this.contracts.OVM_SafetyChecker = await (
await ethers.getContractFactory('OVM_SafetyChecker') await ethers.getContractFactory('OVM_SafetyChecker')
...@@ -204,7 +212,9 @@ export class ExecutionManagerTestRunner { ...@@ -204,7 +212,9 @@ export class ExecutionManagerTestRunner {
functionName: 'ovmCALL', functionName: 'ovmCALL',
functionParams: { functionParams: {
gasLimit: OVM_TX_GAS_LIMIT, gasLimit: OVM_TX_GAS_LIMIT,
target: ExecutionManagerTestRunner.getDummyAddress("$DUMMY_OVM_ADDRESS_1"), target: ExecutionManagerTestRunner.getDummyAddress(
'$DUMMY_OVM_ADDRESS_1'
),
subSteps: step.functionParams.subSteps, subSteps: step.functionParams.subSteps,
}, },
expectedReturnStatus: true, expectedReturnStatus: true,
...@@ -224,17 +234,17 @@ export class ExecutionManagerTestRunner { ...@@ -224,17 +234,17 @@ export class ExecutionManagerTestRunner {
data: calldata, data: calldata,
}, },
this.contracts.OVM_StateManager.address, this.contracts.OVM_StateManager.address,
{ gasLimit: RUN_OVM_TEST_GAS} { gasLimit: RUN_OVM_TEST_GAS }
) )
} else { } else {
await this.contracts.OVM_ExecutionManager.ovmCALL( await this.contracts.OVM_ExecutionManager.ovmCALL(
OVM_TX_GAS_LIMIT, OVM_TX_GAS_LIMIT,
ExecutionManagerTestRunner.getDummyAddress("$DUMMY_OVM_ADDRESS_1"), ExecutionManagerTestRunner.getDummyAddress('$DUMMY_OVM_ADDRESS_1'),
this.contracts.Helper_TestRunner.interface.encodeFunctionData( this.contracts.Helper_TestRunner.interface.encodeFunctionData(
'runSingleTestStep', 'runSingleTestStep',
[this.parseTestStep(step)] [this.parseTestStep(step)]
), ),
{ gasLimit: RUN_OVM_TEST_GAS} { gasLimit: RUN_OVM_TEST_GAS }
) )
} }
} }
...@@ -336,13 +346,19 @@ export class ExecutionManagerTestRunner { ...@@ -336,13 +346,19 @@ export class ExecutionManagerTestRunner {
if (isTestStep_CALL(step)) { if (isTestStep_CALL(step)) {
if (step.expectedReturnValue === '0x00') { if (step.expectedReturnValue === '0x00') {
return step.expectedReturnValue return step.expectedReturnValue
} else if (typeof step.expectedReturnValue === 'string' || step.expectedReturnValue === undefined) { } else if (
typeof step.expectedReturnValue === 'string' ||
step.expectedReturnValue === undefined
) {
returnData = [ returnData = [
step.expectedReturnStatus, step.expectedReturnStatus,
step.expectedReturnValue || '0x', step.expectedReturnValue || '0x',
] ]
} else { } else {
returnData = [step.expectedReturnValue.ovmSuccess, step.expectedReturnValue.returnData] returnData = [
step.expectedReturnValue.ovmSuccess,
step.expectedReturnValue.returnData,
]
} }
} else if (BigNumber.isBigNumber(step.expectedReturnValue)) { } else if (BigNumber.isBigNumber(step.expectedReturnValue)) {
returnData = [step.expectedReturnValue.toHexString()] returnData = [step.expectedReturnValue.toHexString()]
......
...@@ -94,7 +94,10 @@ export interface TestStep_CALL { ...@@ -94,7 +94,10 @@ export interface TestStep_CALL {
subSteps?: TestStep[] subSteps?: TestStep[]
} }
expectedReturnStatus: boolean expectedReturnStatus: boolean
expectedReturnValue?: string | RevertFlagError | {ovmSuccess: boolean, returnData: string} expectedReturnValue?:
| string
| RevertFlagError
| { ovmSuccess: boolean; returnData: string }
} }
interface TestStep_CREATE { interface TestStep_CREATE {
...@@ -176,7 +179,7 @@ export const isTestStep_Context = ( ...@@ -176,7 +179,7 @@ export const isTestStep_Context = (
'ovmTIMESTAMP', 'ovmTIMESTAMP',
'ovmGASLIMIT', 'ovmGASLIMIT',
'ovmCHAINID', 'ovmCHAINID',
'ovmL1QUEUEORIGIN' 'ovmL1QUEUEORIGIN',
].includes(step.functionName) ].includes(step.functionName)
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment