Commit 3013627d authored by ben-chain's avatar ben-chain

start adding back

parent 69b705fd
......@@ -7,7 +7,7 @@
"build": "yarn run build:contracts",
"build:contracts": "buidler compile",
"test": "yarn run test:contracts",
"test:contracts": "buidler test \"test/contracts/OVM/execution/OVM_ExecutionManager/run.spec.ts\"",
"test:contracts": "buidler test \"test/contracts/OVM/execution/OVM_ExecutionManager/nuisance-gas.spec.ts\"",
"lint": "tslint --format stylish --project .",
"fix": "prettier --config prettier-config.json --write \"buidler.config.ts\" \"{src,test}/**/*.ts\""
},
......
/* Internal Imports */
import {
runExecutionManagerTest,
TestDefinition,
GAS_LIMIT,
NULL_BYTES32,
NON_NULL_BYTES32,
REVERT_FLAGS,
DUMMY_BYTECODE,
} from '../../../../helpers'
const globalContext = {
ovmCHAINID: 420
}
const transactionContext = {
ovmTIMESTAMP: 12341234,
ovmGASLIMIT: 45674567,
ovmTXGASLIMIT: 78907890,
ovmL1QUEUEORIGIN: 1,
ovmL1TXORIGIN: '0x1234123412341234123412341234123412341234'
}
const messageContext = {
ovmCALLER: '0x6789678967896789678967896789678967896789',
ovmADDRESS: '0x4567456745674567456745674567456745674567'
}
const test_ovmContextOpcodes: TestDefinition = {
name: 'unit tests for basic getter opcodes',
preState: {
ExecutionManager: {
globalContext,
transactionContext,
messageContext
},
},
parameters: [
{
name: 'gets ovmCALLER',
parameters: [
{
steps: [
{
functionName: 'ovmCALLER',
functionParams: [],
expectedReturnStatus: true,
expectedReturnValues: [messageContext.ovmCALLER]
}
],
},
],
},
{
name: 'gets ovmADDRESS',
parameters: [
{
steps: [
{
functionName: 'ovmADDRESS',
functionParams: [],
expectedReturnStatus: true,
expectedReturnValues: [messageContext.ovmADDRESS]
}
],
},
],
},
{
name: 'gets ovmTIMESTAMP',
parameters: [
{
steps: [
{
functionName: 'ovmTIMESTAMP',
functionParams: [],
expectedReturnStatus: true,
expectedReturnValues: [transactionContext.ovmTIMESTAMP]
}
],
},
],
},
{
name: 'gets ovmGASLIMIT',
parameters: [
{
steps: [
{
functionName: 'ovmGASLIMIT',
functionParams: [],
expectedReturnStatus: true,
expectedReturnValues: [transactionContext.ovmGASLIMIT]
}
],
},
],
},
{
name: 'gets ovmQUEUEORIGIN',
parameters: [
{
steps: [
{
functionName: 'ovmL1QUEUEORIGIN',
functionParams: [],
expectedReturnStatus: true,
expectedReturnValues: [transactionContext.ovmL1QUEUEORIGIN]
}
],
},
],
},
{
name: 'gets ovmL1TXORIGIN',
parameters: [
{
steps: [
{
functionName: 'ovmL1TXORIGIN',
functionParams: [],
expectedReturnStatus: true,
expectedReturnValues: [transactionContext.ovmL1TXORIGIN]
}
],
},
],
},
{
name: 'gets ovmCHAINID',
parameters: [
{
steps: [
{
functionName: 'ovmCHAINID',
functionParams: [],
expectedReturnStatus: true,
expectedReturnValues: [globalContext.ovmCHAINID]
}
],
},
],
},
],
}
runExecutionManagerTest(test_ovmContextOpcodes)
\ No newline at end of file
/* Internal Imports */
import {
ExecutionManagerTestRunner,
TestDefinition,
GAS_LIMIT,
NON_NULL_BYTES32,
REVERT_FLAGS,
VERIFIED_EMPTY_CONTRACT_HASH,
} from '../../../../helpers'
const DUMMY_REVERT_DATA =
'0xdeadbeef1e5420deadbeef1e5420deadbeef1e5420deadbeef1e5420deadbeef1e5420'
const test_nuisanceGas: TestDefinition = {
name: 'Basic tests for ovmCALL',
preState: {
ExecutionManager: {
ovmStateManager: '$OVM_STATE_MANAGER',
ovmSafetyChecker: '$OVM_SAFETY_CHECKER',
messageRecord: {
nuisanceGasLeft: 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),
},
},
},
},
subTests: [
{
name: 'Nuisance gas is consumed up to ovmCALL gas limit',
postState: {
ExecutionManager: {
messageRecord: {
nuisanceGasLeft: GAS_LIMIT / 2
}
}
},
parameters: [
{
name: 'ovmCALL => ovmCALL(evmINVALID)',
focus: true,
steps: [
{
functionName: 'ovmCALL',
functionParams: {
gasLimit: GAS_LIMIT / 2,
target: '$DUMMY_OVM_ADDRESS_1',
subSteps: [
{
functionName: 'ovmCALL',
functionParams: {
gasLimit: GAS_LIMIT,
target: '$DUMMY_OVM_ADDRESS_2',
subSteps: [
{
functionName: 'evmINVALID',
}
]
},
expectedReturnStatus: true,
expectedReturnValue: {
ovmSuccess: false,
returnData: '0x'
}
},
],
},
expectedReturnStatus: true,
},
],
}
]
}
],
parameters: [
{
name: 'ovmCALL(ADDRESS_1) => ovmSSTORE',
steps: [
{
functionName: 'ovmCALL',
functionParams: {
gasLimit: GAS_LIMIT,
target: '$DUMMY_OVM_ADDRESS_1',
subSteps: [
{
functionName: 'ovmSSTORE',
functionParams: {
key: NON_NULL_BYTES32,
value: NON_NULL_BYTES32,
},
expectedReturnStatus: true,
},
],
},
expectedReturnStatus: true,
},
],
},
{
name:
'ovmCALL(ADDRESS_1) => ovmSSTORE + ovmSLOAD, ovmCALL(ADDRESS_1) => ovmSLOAD',
steps: [
{
functionName: 'ovmCALL',
functionParams: {
gasLimit: GAS_LIMIT,
target: '$DUMMY_OVM_ADDRESS_1',
subSteps: [
{
functionName: 'ovmSSTORE',
functionParams: {
key: NON_NULL_BYTES32,
value: NON_NULL_BYTES32,
},
expectedReturnStatus: true,
},
{
functionName: 'ovmSLOAD',
functionParams: {
key: NON_NULL_BYTES32,
},
expectedReturnStatus: true,
expectedReturnValue: NON_NULL_BYTES32,
},
],
},
expectedReturnStatus: true,
},
{
functionName: 'ovmCALL',
functionParams: {
gasLimit: GAS_LIMIT,
target: '$DUMMY_OVM_ADDRESS_1',
subSteps: [
{
functionName: 'ovmSLOAD',
functionParams: {
key: NON_NULL_BYTES32,
},
expectedReturnStatus: true,
expectedReturnValue: NON_NULL_BYTES32,
},
],
},
expectedReturnStatus: true,
},
],
},
{
name:
'ovmCALL(ADDRESS_1) => ovmCALL(ADDRESS_2) => ovmADDRESS + ovmCALLER',
steps: [
{
functionName: 'ovmCALL',
functionParams: {
gasLimit: GAS_LIMIT,
target: '$DUMMY_OVM_ADDRESS_1',
subSteps: [
{
functionName: 'ovmCALL',
functionParams: {
gasLimit: GAS_LIMIT,
target: '$DUMMY_OVM_ADDRESS_2',
subSteps: [
{
functionName: 'ovmADDRESS',
expectedReturnValue: '$DUMMY_OVM_ADDRESS_2',
},
{
functionName: 'ovmCALLER',
expectedReturnValue: '$DUMMY_OVM_ADDRESS_1',
},
],
},
expectedReturnStatus: true,
},
],
},
expectedReturnStatus: true,
},
],
},
{
name: 'ovmCALL(ADDRESS_1) => ovmCALL(ADDRESS_3)',
steps: [
{
functionName: 'ovmCALL',
functionParams: {
gasLimit: GAS_LIMIT,
target: '$DUMMY_OVM_ADDRESS_1',
subSteps: [
{
functionName: 'ovmCALL',
functionParams: {
gasLimit: GAS_LIMIT,
target: '$DUMMY_OVM_ADDRESS_3',
calldata: '0x',
},
expectedReturnStatus: true,
},
],
},
expectedReturnStatus: true,
expectedReturnValue: '0x',
},
],
},
{
name: 'ovmCALL(ADDRESS_1) => INTENTIONAL_REVERT',
steps: [
{
functionName: 'ovmCALL',
functionParams: {
gasLimit: GAS_LIMIT,
target: '$DUMMY_OVM_ADDRESS_1',
subSteps: [
{
functionName: 'evmREVERT',
returnData: {
flag: REVERT_FLAGS.INTENTIONAL_REVERT,
data: DUMMY_REVERT_DATA,
},
},
],
},
expectedReturnStatus: false,
expectedReturnValue: DUMMY_REVERT_DATA,
},
],
},
{
name: 'ovmCALL(ADDRESS_1) => EXCEEDS_NUISANCE_GAS',
steps: [
{
functionName: 'ovmCALL',
functionParams: {
gasLimit: GAS_LIMIT,
target: '$DUMMY_OVM_ADDRESS_1',
subSteps: [
{
functionName: 'evmREVERT',
returnData: {
flag: REVERT_FLAGS.EXCEEDS_NUISANCE_GAS,
},
},
],
},
expectedReturnStatus: false,
expectedReturnValue: '0x',
},
],
},
],
}
const runner = new ExecutionManagerTestRunner()
runner.run(test_nuisanceGas)
\ No newline at end of file
......@@ -3,7 +3,7 @@ import { expect } from '../../setup'
/* External Imports */
import { ethers } from '@nomiclabs/buidler'
import { Contract, BigNumber, ContractFactory } from 'ethers'
import { cloneDeep } from 'lodash'
import { cloneDeep, merge } from 'lodash'
/* Internal Imports */
import {
......@@ -55,14 +55,8 @@ export class ExecutionManagerTestRunner {
test.subTests?.map((subTest) => {
this.run({
...subTest,
preState: {
...test.preState,
...subTest.preState,
},
postState: {
...test.postState,
...subTest.postState,
},
preState: merge(cloneDeep(test.preState), cloneDeep(subTest.preState)),
postState: merge(cloneDeep(test.postState), cloneDeep(subTest.postState))
})
})
......
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