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

linting

parent a56125c2
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-waffle')
......
/* Internal Imports */
import {
ExecutionManagerTestRunner,
TestDefinition,
NON_NULL_BYTES32,
OVM_TX_GAS_LIMIT
} from '../../../../helpers'
ExecutionManagerTestRunner,
TestDefinition,
NON_NULL_BYTES32,
OVM_TX_GAS_LIMIT,
} from '../../../../helpers'
const globalContext = {
ovmCHAINID: 420
}
const globalContext = {
ovmCHAINID: 420,
}
const transactionContext = {
ovmTIMESTAMP: 12341234,
ovmNUMBER: 13371337,
ovmGASLIMIT: 45674567,
ovmTXGASLIMIT: 78907890,
ovmL1QUEUEORIGIN: 1,
ovmL1TXORIGIN: '0x1234123412341234123412341234123412341234'
}
const transactionContext = {
ovmTIMESTAMP: 12341234,
ovmNUMBER: 13371337,
ovmGASLIMIT: 45674567,
ovmTXGASLIMIT: 78907890,
ovmL1QUEUEORIGIN: 1,
ovmL1TXORIGIN: '0x1234123412341234123412341234123412341234',
}
const messageContext = {
ovmCALLER: '0x6789678967896789678967896789678967896789',
ovmADDRESS: '0x4567456745674567456745674567456745674567'
}
const test_contextOpcodes: TestDefinition = {
name: 'unit tests for basic getter opcodes',
preState: {
ExecutionManager: {
ovmStateManager: '$OVM_STATE_MANAGER',
ovmSafetyChecker: '$OVM_SAFETY_CHECKER',
messageRecord: {
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',
},
},
const messageContext = {
ovmCALLER: '0x6789678967896789678967896789678967896789',
ovmADDRESS: '0x4567456745674567456745674567456745674567',
}
const test_contextOpcodes: TestDefinition = {
name: 'unit tests for basic getter opcodes',
preState: {
ExecutionManager: {
ovmStateManager: '$OVM_STATE_MANAGER',
ovmSafetyChecker: '$OVM_SAFETY_CHECKER',
messageRecord: {
nuisanceGasLeft: OVM_TX_GAS_LIMIT,
},
globalContext,
transactionContext,
messageContext,
},
parameters: [
// TODO: re-enable when we can unwrap tests' ovmCALL
// {
// name: 'gets ovmCALLER',
// steps: [
// {
// 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
}
],
StateManager: {
owner: '$OVM_EXECUTION_MANAGER',
accounts: {
$DUMMY_OVM_ADDRESS_1: {
codeHash: NON_NULL_BYTES32,
ethAddress: '$OVM_CALL_HELPER',
},
},
{
name: 'gets ovmCHAINID',
steps: [
{
functionName: 'ovmCHAINID',
expectedReturnValue: globalContext.ovmCHAINID
}
],
},
],
}
const runner = new ExecutionManagerTestRunner()
runner.run(test_contextOpcodes)
\ No newline at end of file
},
},
parameters: [
// TODO: re-enable when we can unwrap tests' ovmCALL
// {
// name: 'gets ovmCALLER',
// steps: [
// {
// 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: [
{
functionName: 'ovmCHAINID',
expectedReturnValue: globalContext.ovmCHAINID,
},
],
},
],
}
const runner = new ExecutionManagerTestRunner()
runner.run(test_contextOpcodes)
......@@ -186,7 +186,11 @@ const test_ovmSTATICCALL: TestDefinition = {
[
{
functionName: 'ovmSTATICCALL',
functionParams: [OVM_TX_GAS_LIMIT, '$DUMMY_OVM_ADDRESS_2', []],
functionParams: [
OVM_TX_GAS_LIMIT,
'$DUMMY_OVM_ADDRESS_2',
[],
],
expectedReturnStatus: true,
expectedReturnValues: [],
},
......@@ -226,7 +230,12 @@ const test_ovmSTATICCALL: TestDefinition = {
functionParams: [
OVM_TX_GAS_LIMIT / 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,
expectedReturnValues: [false, '0x'],
......@@ -257,7 +266,12 @@ const test_ovmSTATICCALL: TestDefinition = {
functionParams: [
OVM_TX_GAS_LIMIT / 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,
expectedReturnValues: [false, '0x'],
......
......@@ -21,7 +21,7 @@ export const decodeRevertData = (revertData: string): any => {
['uint256', 'uint256', 'uint256', 'bytes'],
revertData
)
console.log(`flag is: ${decoded[0].toNumber()}`)
return (
'[revertFlag:' +
Object.keys(REVERT_FLAGS)[decoded[0]] +
......
......@@ -32,5 +32,5 @@ export const NUISANCE_GAS_COSTS = {
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...
export const Helper_TestRunner_BYTELEN = 3654
\ No newline at end of file
// 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
......@@ -29,7 +29,11 @@ import {
} from './test.types'
import { encodeRevertData } from '../codec'
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 {
private snapshot: string
......@@ -55,8 +59,14 @@ export class ExecutionManagerTestRunner {
test.subTests?.map((subTest) => {
this.run({
...subTest,
preState: merge(cloneDeep(test.preState), cloneDeep(subTest.preState)),
postState: merge(cloneDeep(test.postState), cloneDeep(subTest.postState))
preState: merge(
cloneDeep(test.preState),
cloneDeep(subTest.preState)
),
postState: merge(
cloneDeep(test.postState),
cloneDeep(subTest.postState)
),
})
})
......@@ -123,13 +133,11 @@ export class ExecutionManagerTestRunner {
}
private async initContracts() {
console.log('initcontracts')
if (this.snapshot) {
await ethers.provider.send('evm_revert', [this.snapshot])
this.snapshot = await ethers.provider.send('evm_snapshot', [])
return
}
console.log('no snapshot')
this.contracts.OVM_SafetyChecker = await (
await ethers.getContractFactory('OVM_SafetyChecker')
......@@ -204,7 +212,9 @@ export class ExecutionManagerTestRunner {
functionName: 'ovmCALL',
functionParams: {
gasLimit: OVM_TX_GAS_LIMIT,
target: ExecutionManagerTestRunner.getDummyAddress("$DUMMY_OVM_ADDRESS_1"),
target: ExecutionManagerTestRunner.getDummyAddress(
'$DUMMY_OVM_ADDRESS_1'
),
subSteps: step.functionParams.subSteps,
},
expectedReturnStatus: true,
......@@ -224,17 +234,17 @@ export class ExecutionManagerTestRunner {
data: calldata,
},
this.contracts.OVM_StateManager.address,
{ gasLimit: RUN_OVM_TEST_GAS}
{ gasLimit: RUN_OVM_TEST_GAS }
)
} else {
await this.contracts.OVM_ExecutionManager.ovmCALL(
OVM_TX_GAS_LIMIT,
ExecutionManagerTestRunner.getDummyAddress("$DUMMY_OVM_ADDRESS_1"),
ExecutionManagerTestRunner.getDummyAddress('$DUMMY_OVM_ADDRESS_1'),
this.contracts.Helper_TestRunner.interface.encodeFunctionData(
'runSingleTestStep',
[this.parseTestStep(step)]
),
{ gasLimit: RUN_OVM_TEST_GAS}
{ gasLimit: RUN_OVM_TEST_GAS }
)
}
}
......@@ -336,13 +346,19 @@ export class ExecutionManagerTestRunner {
if (isTestStep_CALL(step)) {
if (step.expectedReturnValue === '0x00') {
return step.expectedReturnValue
} else if (typeof step.expectedReturnValue === 'string' || step.expectedReturnValue === undefined) {
} else if (
typeof step.expectedReturnValue === 'string' ||
step.expectedReturnValue === undefined
) {
returnData = [
step.expectedReturnStatus,
step.expectedReturnValue || '0x',
]
} else {
returnData = [step.expectedReturnValue.ovmSuccess, step.expectedReturnValue.returnData]
returnData = [
step.expectedReturnValue.ovmSuccess,
step.expectedReturnValue.returnData,
]
}
} else if (BigNumber.isBigNumber(step.expectedReturnValue)) {
returnData = [step.expectedReturnValue.toHexString()]
......
......@@ -94,7 +94,10 @@ export interface TestStep_CALL {
subSteps?: TestStep[]
}
expectedReturnStatus: boolean
expectedReturnValue?: string | RevertFlagError | {ovmSuccess: boolean, returnData: string}
expectedReturnValue?:
| string
| RevertFlagError
| { ovmSuccess: boolean; returnData: string }
}
interface TestStep_CREATE {
......@@ -176,7 +179,7 @@ export const isTestStep_Context = (
'ovmTIMESTAMP',
'ovmGASLIMIT',
'ovmCHAINID',
'ovmL1QUEUEORIGIN'
'ovmL1QUEUEORIGIN',
].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