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