Commit 954e87cd authored by Kelvin Fichter's avatar Kelvin Fichter

Restored old tests

parent 528f57f7
import { expect } from '../../../../../setup'
/* External Imports */
import { ethers } from '@nomiclabs/buidler'
import { Contract, ContractFactory } from 'ethers'
describe('OVM_ExecutionManager:opcodes:creation', () => {
describe('ovmCREATE', () => {
})
describe('ovmCREATE2', () => {
})
})
import { expect } from '../../../../../setup'
/* External Imports */
import { ethers } from '@nomiclabs/buidler'
import { Contract, ContractFactory } from 'ethers'
/* Internal Imports */
import { getProxyManager, encodeRevertData, REVERT_FLAGS } from '../../../../../helpers'
describe('OVM_ExecutionManager:opcodes:halting', () => {
let Proxy_Manager: Contract
before(async () => {
Proxy_Manager = await getProxyManager()
})
let Factory__OVM_ExecutionManager: ContractFactory
before(async () => {
Factory__OVM_ExecutionManager = await ethers.getContractFactory(
'OVM_ExecutionManager'
)
})
let OVM_ExecutionManager: Contract
beforeEach(async () => {
OVM_ExecutionManager = await Factory__OVM_ExecutionManager.deploy(
Proxy_Manager.address
)
})
let Helper_RevertDataViewer: Contract
beforeEach(async () => {
const Factory__Helper_RevertDataViewer = await ethers.getContractFactory(
'Helper_RevertDataViewer'
)
Helper_RevertDataViewer = await Factory__Helper_RevertDataViewer.deploy(OVM_ExecutionManager.address)
})
describe('ovmREVERT', () => {
it('should revert with the provided data prefixed by the intentional revert flag', async () => {
const revertdata = '12345678'.repeat(10)
const calldata = OVM_ExecutionManager.interface.encodeFunctionData(
'ovmREVERT',
['0x' + revertdata]
)
await Helper_RevertDataViewer.fallback({
data: calldata
})
expect(
await Helper_RevertDataViewer.revertdata()
).to.equal(encodeRevertData(
REVERT_FLAGS.INTENTIONAL_REVERT,
'0x' + revertdata
))
})
it('should revert with the intentional revert flag if no data is provided', async () => {
const calldata = OVM_ExecutionManager.interface.encodeFunctionData(
'ovmREVERT',
['0x']
)
await Helper_RevertDataViewer.fallback({
data: calldata
})
expect(
await Helper_RevertDataViewer.revertdata()
).to.equal(encodeRevertData(
REVERT_FLAGS.INTENTIONAL_REVERT
))
})
})
})
import { expect } from '../../../../../setup'
/* External Imports */
import { ethers } from '@nomiclabs/buidler'
import { Contract, ContractFactory } from 'ethers'
/* Internal Imports */
import { getProxyManager, MockContract, getMockContract, DUMMY_ACCOUNTS, setProxyTarget, ZERO_ADDRESS, fromHexString, toHexString, makeHexString, NULL_BYTES32, DUMMY_BYTES32, encodeRevertData, REVERT_FLAGS, NON_ZERO_ADDRESS } from '../../../../../helpers'
describe('OVM_ExecutionManager:opcodes:storage', () => {
let Proxy_Manager: Contract
before(async () => {
Proxy_Manager = await getProxyManager()
})
let Mock__OVM_StateManager: MockContract
before(async () => {
Mock__OVM_StateManager = await getMockContract('OVM_StateManager')
await setProxyTarget(
Proxy_Manager,
'OVM_StateManager',
Mock__OVM_StateManager
)
})
let Factory__OVM_ExecutionManager: ContractFactory
before(async () => {
Factory__OVM_ExecutionManager = await ethers.getContractFactory(
'OVM_ExecutionManager'
)
})
let OVM_ExecutionManager: Contract
beforeEach(async () => {
OVM_ExecutionManager = await Factory__OVM_ExecutionManager.deploy(
Proxy_Manager.address
)
})
let Helper_RevertDataViewer: Contract
beforeEach(async () => {
const Factory__Helper_RevertDataViewer = await ethers.getContractFactory(
'Helper_RevertDataViewer'
)
Helper_RevertDataViewer = await Factory__Helper_RevertDataViewer.deploy(
OVM_ExecutionManager.address
)
})
const DUMMY_SLOT_KEY = DUMMY_BYTES32[0]
const DUMMY_SLOT_VALUE = DUMMY_BYTES32[1]
describe('ovmSLOAD', () => {
before(() => {
Mock__OVM_StateManager.setReturnValues('getContractStorage', () => {
return [
DUMMY_SLOT_VALUE
]
})
})
describe('when the OVM_StateManager has the corresponding storage slot', () => {
before(() => {
Mock__OVM_StateManager.setReturnValues('hasContractStorage', [true])
})
describe('when the OVM_StateManager has already loaded the storage slot', () => {
before(() => {
Mock__OVM_StateManager.setReturnValues('testAndSetContractStorageLoaded', [true])
})
it('should return the value of the storage slot', async () => {
expect(
await OVM_ExecutionManager.callStatic.ovmSLOAD(
DUMMY_SLOT_KEY
)
).to.equal(DUMMY_SLOT_VALUE)
})
})
describe('when the OVM_StateManager has not already loaded the storage slot', () => {
before(() => {
Mock__OVM_StateManager.setReturnValues('testAndSetContractStorageLoaded', [false])
})
it('should revert with the EXCEEDS_NUISANCE_GAS flag', async () => {
const calldata = OVM_ExecutionManager.interface.encodeFunctionData(
'ovmSLOAD',
[
DUMMY_SLOT_KEY
]
)
await Helper_RevertDataViewer.fallback({
data: calldata
})
expect(
await Helper_RevertDataViewer.revertdata()
).to.equal(encodeRevertData(
REVERT_FLAGS.EXCEEDS_NUISANCE_GAS
))
})
})
})
describe('when the OVM_StateManager does not have the corresponding storage slot', () => {
before(() => {
Mock__OVM_StateManager.setReturnValues('hasContractStorage', [false])
})
it('should revert with the INVALID_STATE_ACCESS flag', async () => {
const calldata = OVM_ExecutionManager.interface.encodeFunctionData(
'ovmSLOAD',
[
DUMMY_SLOT_KEY
]
)
await Helper_RevertDataViewer.fallback({
data: calldata
})
expect(
await Helper_RevertDataViewer.revertdata()
).to.equal(encodeRevertData(
REVERT_FLAGS.INVALID_STATE_ACCESS
))
})
})
})
describe('ovmSSTORE', () => {
describe('when the OVM_StateManager has already changed the storage slot', () => {
before(() => {
Mock__OVM_StateManager.setReturnValues('testAndSetContractStorageChanged', [true])
})
it('should modify the storage slot value', async () => {
await expect(
OVM_ExecutionManager.ovmSSTORE(
DUMMY_SLOT_KEY,
DUMMY_SLOT_VALUE
)
).to.not.be.reverted
expect(
Mock__OVM_StateManager.getCallData('putContractStorage', 0)
).to.deep.equal(
[
ZERO_ADDRESS,
DUMMY_SLOT_KEY,
DUMMY_SLOT_VALUE
]
)
})
})
describe('when the OVM_StateManager has not already changed the storage slot', () => {
before(() => {
Mock__OVM_StateManager.setReturnValues('testAndSetContractStorageChanged', [false])
})
it('should revert with the EXCEEDS_NUISANCE_GAS flag', async () => {
const calldata = OVM_ExecutionManager.interface.encodeFunctionData(
'ovmSSTORE',
[
DUMMY_SLOT_KEY,
DUMMY_SLOT_VALUE
]
)
await Helper_RevertDataViewer.fallback({
data: calldata
})
expect(
await Helper_RevertDataViewer.revertdata()
).to.equal(encodeRevertData(
REVERT_FLAGS.EXCEEDS_NUISANCE_GAS
))
})
})
})
})
import { expect } from '../../../setup'
/* External Imports */
import { ethers } from '@nomiclabs/buidler'
import { Contract, ContractFactory } from 'ethers'
/* Internal Imports */
import {
DUMMY_ACCOUNTS,
DUMMY_BYTES32,
toOVMAccount
} from '../../../helpers'
describe('OVM_StateManager', () => {
let Factory__OVM_StateManager: ContractFactory
before(async () => {
Factory__OVM_StateManager = await ethers.getContractFactory(
'OVM_StateManager'
)
})
let OVM_StateManager: Contract
beforeEach(async () => {
OVM_StateManager = await Factory__OVM_StateManager.deploy()
})
describe('putAccount', () => {
it('should be able to store an OVM account', async () => {
await expect(
OVM_StateManager.putAccount(
DUMMY_ACCOUNTS[0].address,
DUMMY_ACCOUNTS[0].data
)
).to.not.be.reverted
})
it('should be able to overwrite an OVM account', async () => {
await OVM_StateManager.putAccount(
DUMMY_ACCOUNTS[0].address,
DUMMY_ACCOUNTS[0].data
)
await expect(
OVM_StateManager.putAccount(
DUMMY_ACCOUNTS[0].address,
DUMMY_ACCOUNTS[1].data
)
).to.not.be.reverted
})
})
describe('getAccount', () => {
it('should be able to retrieve an OVM account', async () => {
await OVM_StateManager.putAccount(
DUMMY_ACCOUNTS[0].address,
DUMMY_ACCOUNTS[0].data
)
expect(
toOVMAccount(
await OVM_StateManager.callStatic.getAccount(DUMMY_ACCOUNTS[0].address)
)
).to.deep.equal(DUMMY_ACCOUNTS[0].data)
})
it('should be able to retrieve an overwritten OVM account', async () => {
await OVM_StateManager.putAccount(
DUMMY_ACCOUNTS[0].address,
DUMMY_ACCOUNTS[0].data
)
await OVM_StateManager.putAccount(
DUMMY_ACCOUNTS[0].address,
DUMMY_ACCOUNTS[1].data
)
expect(
toOVMAccount(
await OVM_StateManager.callStatic.getAccount(DUMMY_ACCOUNTS[0].address)
)
).to.deep.equal(DUMMY_ACCOUNTS[1].data)
})
})
describe('hasAccount', () => {
it('should return true if an account exists', async () => {
await OVM_StateManager.putAccount(
DUMMY_ACCOUNTS[0].address,
DUMMY_ACCOUNTS[0].data
)
expect(
await OVM_StateManager.callStatic.hasAccount(DUMMY_ACCOUNTS[0].address)
).to.equal(true)
})
it('should return false if the account does not exist', async () => {
expect(
await OVM_StateManager.callStatic.hasAccount(DUMMY_ACCOUNTS[0].address)
).to.equal(false)
})
})
describe('putContractStorage', () => {
it('should be able to insert a storage slot for a given contract', async () => {
await expect(
OVM_StateManager.putContractStorage(
DUMMY_ACCOUNTS[0].address,
DUMMY_BYTES32[0],
DUMMY_BYTES32[1],
)
).to.not.be.reverted
})
it('should be able to overwrite a storage slot for a given contract', async () => {
await OVM_StateManager.putContractStorage(
DUMMY_ACCOUNTS[0].address,
DUMMY_BYTES32[0],
DUMMY_BYTES32[1],
)
await expect(
OVM_StateManager.putContractStorage(
DUMMY_ACCOUNTS[0].address,
DUMMY_BYTES32[0],
DUMMY_BYTES32[2],
)
).to.not.be.reverted
})
})
describe('getContractStorage', () => {
it('should be able to retrieve a storage slot for a given contract', async () => {
await OVM_StateManager.putContractStorage(
DUMMY_ACCOUNTS[0].address,
DUMMY_BYTES32[0],
DUMMY_BYTES32[1],
)
expect(
await OVM_StateManager.callStatic.getContractStorage(
DUMMY_ACCOUNTS[0].address,
DUMMY_BYTES32[0]
)
).to.equal(DUMMY_BYTES32[1])
})
it('should be able to retrieve an overwritten storage slot for a given contract', async () => {
await OVM_StateManager.putContractStorage(
DUMMY_ACCOUNTS[0].address,
DUMMY_BYTES32[0],
DUMMY_BYTES32[1],
)
await OVM_StateManager.putContractStorage(
DUMMY_ACCOUNTS[0].address,
DUMMY_BYTES32[0],
DUMMY_BYTES32[2],
)
expect(
await OVM_StateManager.callStatic.getContractStorage(
DUMMY_ACCOUNTS[0].address,
DUMMY_BYTES32[0]
)
).to.equal(DUMMY_BYTES32[2])
})
})
})
import { expect } from '../../setup'
/* External Imports */
import { ethers } from '@nomiclabs/buidler'
import { Contract, ContractFactory } from 'ethers'
describe('Proxy_Forwarder', () => {
describe('fallback', () => {
})
})
import { expect } from '../../setup'
/* External Imports */
import { ethers } from '@nomiclabs/buidler'
import { Contract, ContractFactory } from 'ethers'
describe('Proxy_Manager', () => {
describe('setProxy', () => {
})
describe('getProxy', () => {
})
describe('hasProxy', () => {
})
describe('isProxy', () => {
})
describe('setTarget', () => {
})
describe('getTarget', () => {
})
describe('hasTarget', () => {
})
describe('isTarget', () => {
})
})
import { expect } from '../../setup'
/* External Imports */
import { ethers } from '@nomiclabs/buidler'
import { Contract, ContractFactory } from 'ethers'
describe('Proxy_Resolver', () => {
describe('resolve', () => {
})
})
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