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)
...@@ -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