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

add context opcode tests

parent c236b1d4
...@@ -487,6 +487,8 @@ contract OVM_ExecutionManager is iOVM_ExecutionManager { ...@@ -487,6 +487,8 @@ contract OVM_ExecutionManager is iOVM_ExecutionManager {
bytes memory _returndata bytes memory _returndata
) )
{ {
console.log("ovmCALL to");
console.logAddress(_address);
// CALL updates the CALLER and ADDRESS. // CALL updates the CALLER and ADDRESS.
MessageContext memory nextMessageContext = messageContext; MessageContext memory nextMessageContext = messageContext;
nextMessageContext.ovmCALLER = nextMessageContext.ovmADDRESS; nextMessageContext.ovmCALLER = nextMessageContext.ovmADDRESS;
...@@ -1678,6 +1680,8 @@ contract OVM_ExecutionManager is iOVM_ExecutionManager { ...@@ -1678,6 +1680,8 @@ contract OVM_ExecutionManager is iOVM_ExecutionManager {
) )
internal internal
{ {
console.log("setting number to:");
console.log(_transaction.number);
transactionContext.ovmTIMESTAMP = _transaction.timestamp; transactionContext.ovmTIMESTAMP = _transaction.timestamp;
transactionContext.ovmNUMBER = _transaction.number; transactionContext.ovmNUMBER = _transaction.number;
transactionContext.ovmTXGASLIMIT = _transaction.gasLimit; transactionContext.ovmTXGASLIMIT = _transaction.gasLimit;
......
...@@ -46,11 +46,11 @@ interface iOVM_ExecutionManager { ...@@ -46,11 +46,11 @@ interface iOVM_ExecutionManager {
} }
struct TransactionContext { struct TransactionContext {
Lib_OVMCodec.QueueOrigin ovmL1QUEUEORIGIN;
uint256 ovmTIMESTAMP; uint256 ovmTIMESTAMP;
uint256 ovmNUMBER; uint256 ovmNUMBER;
uint256 ovmGASLIMIT; uint256 ovmGASLIMIT;
uint256 ovmTXGASLIMIT; uint256 ovmTXGASLIMIT;
Lib_OVMCodec.QueueOrigin ovmL1QUEUEORIGIN;
address ovmL1TXORIGIN; address ovmL1TXORIGIN;
} }
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
"build": "yarn run build:contracts", "build": "yarn run build:contracts",
"build:contracts": "buidler compile", "build:contracts": "buidler compile",
"test": "yarn run test:contracts", "test": "yarn run test:contracts",
"test:contracts": "buidler test \"test/contracts/OVM/execution/OVM_ExecutionManager/nuisance-gas.spec.ts\"", "test:contracts": "buidler test \"test/contracts/OVM/execution/OVM_ExecutionManager/context-opcodes.spec.ts\"",
"lint": "tslint --format stylish --project .", "lint": "tslint --format stylish --project .",
"fix": "prettier --config prettier-config.json --write \"buidler.config.ts\" \"{src,test}/**/*.ts\"" "fix": "prettier --config prettier-config.json --write \"buidler.config.ts\" \"{src,test}/**/*.ts\""
}, },
......
/* Internal Imports */ /* Internal Imports */
import { import {
runExecutionManagerTest, ExecutionManagerTestRunner,
TestDefinition, TestDefinition,
OVM_TX_GAS_LIMIT,
NULL_BYTES32,
NON_NULL_BYTES32, NON_NULL_BYTES32,
REVERT_FLAGS, OVM_TX_GAS_LIMIT
DUMMY_BYTECODE,
} from '../../../../helpers' } from '../../../../helpers'
const globalContext = { const globalContext = {
...@@ -15,6 +12,7 @@ import { ...@@ -15,6 +12,7 @@ import {
const transactionContext = { const transactionContext = {
ovmTIMESTAMP: 12341234, ovmTIMESTAMP: 12341234,
ovmNUMBER: 13371337,
ovmGASLIMIT: 45674567, ovmGASLIMIT: 45674567,
ovmTXGASLIMIT: 78907890, ovmTXGASLIMIT: 78907890,
ovmL1QUEUEORIGIN: 1, ovmL1QUEUEORIGIN: 1,
...@@ -26,123 +24,105 @@ import { ...@@ -26,123 +24,105 @@ import {
ovmADDRESS: '0x4567456745674567456745674567456745674567' ovmADDRESS: '0x4567456745674567456745674567456745674567'
} }
const test_ovmContextOpcodes: 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',
ovmSafetyChecker: '$OVM_SAFETY_CHECKER',
messageRecord: {
nuisanceGasLeft: OVM_TX_GAS_LIMIT,
},
globalContext, globalContext,
transactionContext, transactionContext,
messageContext messageContext
},
StateManager: {
owner: '$OVM_EXECUTION_MANAGER',
accounts: {
$DUMMY_OVM_ADDRESS_1: {
codeHash: NON_NULL_BYTES32,
ethAddress: '$OVM_CALL_HELPER',
},
},
}, },
}, },
parameters: [ 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 ovmCALLER', name: 'gets ovmTIMESTAMP',
parameters: [
{
steps: [
{
functionName: 'ovmCALLER',
functionParams: [],
expectedReturnStatus: true,
expectedReturnValues: [messageContext.ovmCALLER]
}
],
},
],
},
{
name: 'gets ovmADDRESS',
parameters: [
{
steps: [ steps: [
{ {
functionName: 'ovmADDRESS', functionName: 'ovmTIMESTAMP',
functionParams: [], expectedReturnValue: transactionContext.ovmTIMESTAMP
expectedReturnStatus: true,
expectedReturnValues: [messageContext.ovmADDRESS]
} }
], ],
},
],
}, },
{ {
name: 'gets ovmTIMESTAMP', name: 'gets ovmNUMBER',
parameters: [
{
steps: [ steps: [
{ {
functionName: 'ovmTIMESTAMP', functionName: 'ovmNUMBER',
functionParams: [], expectedReturnValue: transactionContext.ovmNUMBER
expectedReturnStatus: true,
expectedReturnValues: [transactionContext.ovmTIMESTAMP]
} }
], ],
},
],
}, },
{ {
name: 'gets ovmGASLIMIT', name: 'gets ovmGASLIMIT',
parameters: [
{
steps: [ steps: [
{ {
functionName: 'ovmGASLIMIT', functionName: 'ovmGASLIMIT',
functionParams: [], expectedReturnValue: transactionContext.ovmGASLIMIT
expectedReturnStatus: true,
expectedReturnValues: [transactionContext.ovmGASLIMIT]
} }
], ],
},
],
}, },
{ {
name: 'gets ovmQUEUEORIGIN', name: 'gets ovmL1QUEUEORIGIN',
parameters: [
{
steps: [ steps: [
{ {
functionName: 'ovmL1QUEUEORIGIN', functionName: 'ovmL1QUEUEORIGIN',
functionParams: [], expectedReturnValue: transactionContext.ovmL1QUEUEORIGIN
expectedReturnStatus: true,
expectedReturnValues: [transactionContext.ovmL1QUEUEORIGIN]
} }
], ],
},
],
}, },
{ {
name: 'gets ovmL1TXORIGIN', name: 'gets ovmL1TXORIGIN',
parameters: [
{
steps: [ steps: [
{ {
functionName: 'ovmL1TXORIGIN', functionName: 'ovmL1TXORIGIN',
functionParams: [], expectedReturnValue: transactionContext.ovmL1TXORIGIN
expectedReturnStatus: true,
expectedReturnValues: [transactionContext.ovmL1TXORIGIN]
} }
], ],
},
],
}, },
{ {
name: 'gets ovmCHAINID', name: 'gets ovmCHAINID',
parameters: [ steps: [
{ {
steps: [
{
functionName: 'ovmCHAINID', functionName: 'ovmCHAINID',
functionParams: [], expectedReturnValue: globalContext.ovmCHAINID
expectedReturnStatus: true,
expectedReturnValues: [globalContext.ovmCHAINID]
} }
], ],
}, },
],
},
], ],
} }
runExecutionManagerTest(test_ovmContextOpcodes) const runner = new ExecutionManagerTestRunner()
runner.run(test_contextOpcodes)
\ No newline at end of file \ No newline at end of file
...@@ -3,8 +3,10 @@ import { BigNumber } from 'ethers' ...@@ -3,8 +3,10 @@ import { BigNumber } from 'ethers'
export type ContextOpcode = export type ContextOpcode =
| 'ovmCALLER' | 'ovmCALLER'
| 'ovmNUMBER'
| 'ovmADDRESS' | 'ovmADDRESS'
| 'ovmORIGIN' | 'ovmL1TXORIGIN'
| 'ovmL1QUEUEORIGIN'
| 'ovmTIMESTAMP' | 'ovmTIMESTAMP'
| 'ovmGASLIMIT' | 'ovmGASLIMIT'
| 'ovmCHAINID' | 'ovmCHAINID'
...@@ -170,10 +172,11 @@ export const isTestStep_Context = ( ...@@ -170,10 +172,11 @@ export const isTestStep_Context = (
return [ return [
'ovmCALLER', 'ovmCALLER',
'ovmADDRESS', 'ovmADDRESS',
'ovmORIGIN', 'ovmL1TXORIGIN',
'ovmTIMESTAMP', 'ovmTIMESTAMP',
'ovmGASLIMIT', 'ovmGASLIMIT',
'ovmCHAINID', 'ovmCHAINID',
'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