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

test passing, snapshot logic worked

parent 4fc1a473
......@@ -834,6 +834,8 @@ contract OVM_ExecutionManager is iOVM_ExecutionManager {
bytes memory _returndata
)
{
console.log("_callContract with nuisance gas:");
console.log(messageRecord.nuisanceGasLeft);
return _handleExternalInteraction(
_nextMessageContext,
_gasLimit,
......@@ -1126,6 +1128,7 @@ contract OVM_ExecutionManager is iOVM_ExecutionManager {
)
internal
{
console.log("checking account load");
// See `_checkContractStorageLoad` for more information.
if (gasleft() < MIN_GAS_FOR_INVALID_STATE_ACCESS) {
_revertWithFlag(RevertFlag.OUT_OF_GAS);
......@@ -1145,10 +1148,14 @@ contract OVM_ExecutionManager is iOVM_ExecutionManager {
// If we hadn't already loaded the account, then we'll need to charge "nuisance gas" based
// on the size of the contract code.
if (_wasAccountAlreadyLoaded == false) {
console.log("was not already loaded");
_useNuisanceGas(
Lib_EthUtils.getCodeSize(_getAccountEthAddress(_address)) * NUISANCE_GAS_PER_CONTRACT_BYTE
);
console.log("got code size:");
console.log(Lib_EthUtils.getCodeSize(_getAccountEthAddress(_address)));
}
console.log("was already loaded");
}
/**
......@@ -1414,6 +1421,8 @@ contract OVM_ExecutionManager is iOVM_ExecutionManager {
)
internal
{
console.log("using nuisance gas of amount:");
console.log(_amount);
// Essentially the same as a standard OUT_OF_GAS, except we also retain a record of the gas
// refund to be given at the end of the transaction.
if (messageRecord.nuisanceGasLeft < _amount) {
......
......@@ -12,6 +12,8 @@ import {
const DUMMY_REVERT_DATA =
'0xdeadbeef1e5420deadbeef1e5420deadbeef1e5420deadbeef1e5420deadbeef1e5420'
console.log('cost multiplied:', Helper_TestRunner_BYTELEN * NUISANCE_GAS_COSTS.NUISANCE_GAS_PER_CONTRACT_BYTE, 'bytelenL:',Helper_TestRunner_BYTELEN )
const test_nuisanceGas: TestDefinition = {
name: 'Basic tests for nuisance gas',
......@@ -47,7 +49,7 @@ import {
postState: {
ExecutionManager: {
messageRecord: {
nuisanceGasLeft: OVM_TX_GAS_LIMIT / 2
nuisanceGasLeft: OVM_TX_GAS_LIMIT - Helper_TestRunner_BYTELEN * NUISANCE_GAS_COSTS.NUISANCE_GAS_PER_CONTRACT_BYTE
}
}
},
......@@ -56,10 +58,64 @@ import {
name: 'single ovmCALL',
focus: true,
steps: [
// do a non-nuisance gas consuming opcode (test auto-wraps in ovmCALL)
// do a non-nuisance-gas-consuming opcode (test runner auto-wraps in ovmCALL)
{
functionName: 'ovmADDRESS',
expectedReturnValue: "$DUMMY_OVM_ADDRESS_1"
expectedReturnValue: "$DUMMY_OVM_ADDRESS_1",
},
],
}
]
},
{
name: 'ovmCALL only consumes nuisance gas of CODESIZE * NUISANCE_GAS_PER_CONTRACT_BYTE for same contract called twice',
postState: {
ExecutionManager: {
messageRecord: {
nuisanceGasLeft: OVM_TX_GAS_LIMIT - Helper_TestRunner_BYTELEN * NUISANCE_GAS_COSTS.NUISANCE_GAS_PER_CONTRACT_BYTE
}
}
},
parameters: [
{
name: 'nested ovmCALL',
focus: true,
steps: [
{
functionName: 'ovmCALL',
functionParams: {
gasLimit: OVM_TX_GAS_LIMIT,
target: "$DUMMY_OVM_ADDRESS_1",
subSteps: []
},
expectedReturnStatus: true
},
],
}
]
},
{
name: 'ovmCALL only consumes nuisance gas of CODESIZE * NUISANCE_GAS_PER_CONTRACT_BYTE twice for two separate ovmCALLS',
postState: {
ExecutionManager: {
messageRecord: {
nuisanceGasLeft: OVM_TX_GAS_LIMIT - 2 * ( Helper_TestRunner_BYTELEN * NUISANCE_GAS_COSTS.NUISANCE_GAS_PER_CONTRACT_BYTE )
}
}
},
parameters: [
{
name: 'nested ovmCALL',
// focus: true,
steps: [
{
functionName: 'ovmCALL',
functionParams: {
gasLimit: OVM_TX_GAS_LIMIT,
target: "$DUMMY_OVM_ADDRESS_2",
subSteps: []
},
expectedReturnStatus: true
},
],
}
......
......@@ -32,4 +32,4 @@ export const NUISANCE_GAS_COSTS = {
}
// 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 = 3686
\ No newline at end of file
export const Helper_TestRunner_BYTELEN = 3654
\ No newline at end of file
......@@ -123,10 +123,13 @@ 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')
......@@ -201,7 +204,7 @@ export class ExecutionManagerTestRunner {
functionName: 'ovmCALL',
functionParams: {
gasLimit: OVM_TX_GAS_LIMIT,
target: this.contracts.Helper_TestRunner.address,
target: ExecutionManagerTestRunner.getDummyAddress("$DUMMY_OVM_ADDRESS_1"),
subSteps: step.functionParams.subSteps,
},
expectedReturnStatus: true,
......@@ -226,7 +229,7 @@ export class ExecutionManagerTestRunner {
} else {
await this.contracts.OVM_ExecutionManager.ovmCALL(
OVM_TX_GAS_LIMIT,
this.contracts.Helper_TestRunner.address,
ExecutionManagerTestRunner.getDummyAddress("$DUMMY_OVM_ADDRESS_1"),
this.contracts.Helper_TestRunner.interface.encodeFunctionData(
'runSingleTestStep',
[this.parseTestStep(step)]
......
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