Commit 872e7a2d authored by Kelvin Fichter's avatar Kelvin Fichter Committed by GitHub

dev: Apply linting to all test files (#275)

* Apply linting to all test files

* Lint new stuff from master

* Minor tweak to avoid a bug
parent e97edd27
/* External Imports */ /* External Imports */
import { Signer, Contract, ContractFactory } from 'ethers' import { Contract } from 'ethers'
/* Internal Imports */ /* Internal Imports */
import { RollupDeployConfig, makeContractDeployConfig } from './config' import { RollupDeployConfig, makeContractDeployConfig } from './config'
......
...@@ -9,7 +9,7 @@ async function mineBlock(provider: any, timestamp: number): Promise<void> { ...@@ -9,7 +9,7 @@ async function mineBlock(provider: any, timestamp: number): Promise<void> {
describe('BondManager', () => { describe('BondManager', () => {
const provider = waffle.provider const provider = waffle.provider
let wallets = provider.getWallets() const wallets = provider.getWallets()
let bondManager: Contract let bondManager: Contract
let token: Contract let token: Contract
...@@ -117,7 +117,7 @@ describe('BondManager', () => { ...@@ -117,7 +117,7 @@ describe('BondManager', () => {
const timestamp = withdrawalTimestamp + ONE_WEEK const timestamp = withdrawalTimestamp + ONE_WEEK
await mineBlock(deployer.provider, timestamp) await mineBlock(deployer.provider, timestamp)
const balanceBefore = await token.balanceOf(sender) balanceBefore = await token.balanceOf(sender)
await bondManager.finalizeWithdrawal() await bondManager.finalizeWithdrawal()
const bond = await bondManager.bonds(sender) const bond = await bondManager.bonds(sender)
expect(bond.state).to.eq(State.NOT_COLLATERALIZED) expect(bond.state).to.eq(State.NOT_COLLATERALIZED)
...@@ -333,12 +333,12 @@ describe('BondManager', () => { ...@@ -333,12 +333,12 @@ describe('BondManager', () => {
describe('same publisher commits fraud multiple times', async () => { describe('same publisher commits fraud multiple times', async () => {
let timestamp: number let timestamp: number
let root1 = const root1 =
'0x0000000000000000000000000000000000000000000000000000000000000000' '0x0000000000000000000000000000000000000000000000000000000000000000'
let ts1 = 100 const ts1 = 100
let root2 = const root2 =
'0x0000000000000000000000000000000000000000000000000000000000000001' '0x0000000000000000000000000000000000000000000000000000000000000001'
let ts2 = 110 const ts2 = 110
beforeEach(async () => { beforeEach(async () => {
await fraudVerifier.finalize(root2, sender, ts2) await fraudVerifier.finalize(root2, sender, ts2)
......
...@@ -4,16 +4,16 @@ import { expect } from '../../../setup' ...@@ -4,16 +4,16 @@ import { expect } from '../../../setup'
import { ethers, waffle } from 'hardhat' import { ethers, waffle } from 'hardhat'
import { ContractFactory, Contract, Wallet } from 'ethers' import { ContractFactory, Contract, Wallet } from 'ethers'
import { MockContract, smockit } from '@eth-optimism/smock' import { MockContract, smockit } from '@eth-optimism/smock'
import { NON_ZERO_ADDRESS, ZERO_ADDRESS } from '../../../helpers/constants'
/* Internal Imports */
import { NON_ZERO_ADDRESS } from '../../../helpers/constants'
import { import {
serializeNativeTransaction, serializeNativeTransaction,
signNativeTransaction, signNativeTransaction,
DEFAULT_EIP155_TX, DEFAULT_EIP155_TX,
serializeEthSignTransaction, serializeEthSignTransaction,
signEthSignMessage, signEthSignMessage,
EIP155Transaction,
} from '../../../helpers' } from '../../../helpers'
import { defaultAbiCoder } from 'ethers/lib/utils'
const callPrecompile = async ( const callPrecompile = async (
Helper_PrecompileCaller: Contract, Helper_PrecompileCaller: Contract,
......
...@@ -4,15 +4,9 @@ import { expect } from '../../../setup' ...@@ -4,15 +4,9 @@ import { expect } from '../../../setup'
import { ethers, waffle } from 'hardhat' import { ethers, waffle } from 'hardhat'
import { ContractFactory, Contract, Wallet } from 'ethers' import { ContractFactory, Contract, Wallet } from 'ethers'
import { MockContract, smockit } from '@eth-optimism/smock' import { MockContract, smockit } from '@eth-optimism/smock'
import { NON_ZERO_ADDRESS } from '../../../helpers/constants'
import { AbiCoder, keccak256 } from 'ethers/lib/utils' /* Internal Imports */
import { import { remove0x } from '../../../helpers'
DEFAULT_EIP155_TX,
remove0x,
serializeNativeTransaction,
signNativeTransaction,
} from '../../../helpers'
import { getContractInterface } from '../../../../src'
const callPrecompile = async ( const callPrecompile = async (
Helper_PrecompileCaller: Contract, Helper_PrecompileCaller: Contract,
......
...@@ -2,13 +2,8 @@ import { expect } from '../../../../setup' ...@@ -2,13 +2,8 @@ import { expect } from '../../../../setup'
/* External Imports */ /* External Imports */
import { ethers } from 'hardhat' import { ethers } from 'hardhat'
import { Signer, ContractFactory, Contract, BigNumber } from 'ethers' import { Signer, ContractFactory, Contract } from 'ethers'
import { import { smockit, MockContract, smoddit } from '@eth-optimism/smock'
smockit,
MockContract,
smoddit,
ModifiableContract,
} from '@eth-optimism/smock'
/* Internal Imports */ /* Internal Imports */
import { NON_ZERO_ADDRESS, ZERO_ADDRESS } from '../../../../helpers' import { NON_ZERO_ADDRESS, ZERO_ADDRESS } from '../../../../helpers'
...@@ -28,7 +23,6 @@ describe('OVM_L1ERC20Gateway', () => { ...@@ -28,7 +23,6 @@ describe('OVM_L1ERC20Gateway', () => {
let Mock__OVM_L2DepositedERC20: MockContract let Mock__OVM_L2DepositedERC20: MockContract
let Factory__L1ERC20: ContractFactory let Factory__L1ERC20: ContractFactory
let L1ERC20: Contract let L1ERC20: Contract
const initialSupply = 1_000
before(async () => { before(async () => {
;[alice, bob] = await ethers.getSigners() ;[alice, bob] = await ethers.getSigners()
...@@ -145,7 +139,6 @@ describe('OVM_L1ERC20Gateway', () => { ...@@ -145,7 +139,6 @@ describe('OVM_L1ERC20Gateway', () => {
const INITIAL_DEPOSITER_BALANCE = 100_000 const INITIAL_DEPOSITER_BALANCE = 100_000
let depositer: string let depositer: string
const depositAmount = 1_000 const depositAmount = 1_000
let L1ERC20: Contract
beforeEach(async () => { beforeEach(async () => {
// Deploy the L1 ERC20 token, Alice will receive the full initialSupply // Deploy the L1 ERC20 token, Alice will receive the full initialSupply
......
...@@ -2,13 +2,8 @@ import { expect } from '../../../../setup' ...@@ -2,13 +2,8 @@ import { expect } from '../../../../setup'
/* External Imports */ /* External Imports */
import { ethers } from 'hardhat' import { ethers } from 'hardhat'
import { Signer, ContractFactory, Contract, BigNumber, providers } from 'ethers' import { Signer, Contract } from 'ethers'
import { import { smockit, MockContract } from '@eth-optimism/smock'
smockit,
MockContract,
smoddit,
ModifiableContract,
} from '@eth-optimism/smock'
/* Internal Imports */ /* Internal Imports */
import { import {
......
...@@ -2,7 +2,7 @@ import { expect } from '../../../../setup' ...@@ -2,7 +2,7 @@ import { expect } from '../../../../setup'
/* External Imports */ /* External Imports */
import { ethers } from 'hardhat' import { ethers } from 'hardhat'
import { Signer, ContractFactory, Contract, BigNumber } from 'ethers' import { Signer, ContractFactory, Contract } from 'ethers'
import { import {
smockit, smockit,
MockContract, MockContract,
...@@ -13,8 +13,6 @@ import { ...@@ -13,8 +13,6 @@ import {
/* Internal Imports */ /* Internal Imports */
import { NON_ZERO_ADDRESS, ZERO_ADDRESS } from '../../../../helpers' import { NON_ZERO_ADDRESS, ZERO_ADDRESS } from '../../../../helpers'
const decimals = 1
const ERR_INVALID_MESSENGER = 'OVM_XCHAIN: messenger contract unauthenticated' const ERR_INVALID_MESSENGER = 'OVM_XCHAIN: messenger contract unauthenticated'
const ERR_INVALID_X_DOMAIN_MSG_SENDER = const ERR_INVALID_X_DOMAIN_MSG_SENDER =
'OVM_XCHAIN: wrong sender of cross-domain message' 'OVM_XCHAIN: wrong sender of cross-domain message'
...@@ -50,11 +48,7 @@ describe('OVM_L2DepositedERC20', () => { ...@@ -50,11 +48,7 @@ describe('OVM_L2DepositedERC20', () => {
// Deploy the contract under test // Deploy the contract under test
OVM_L2DepositedERC20 = await ( OVM_L2DepositedERC20 = await (
await ethers.getContractFactory('OVM_L2DepositedERC20') await ethers.getContractFactory('OVM_L2DepositedERC20')
).deploy( ).deploy(Mock__OVM_L2CrossDomainMessenger.address, 'ovmWETH', 'oWETH')
Mock__OVM_L2CrossDomainMessenger.address,
'ovmWETH',
'oWETH'
)
// initialize the L2 Gateway with the L1G ateway addrss // initialize the L2 Gateway with the L1G ateway addrss
await OVM_L2DepositedERC20.init(MOCK_L1GATEWAY_ADDRESS) await OVM_L2DepositedERC20.init(MOCK_L1GATEWAY_ADDRESS)
...@@ -116,11 +110,7 @@ describe('OVM_L2DepositedERC20', () => { ...@@ -116,11 +110,7 @@ describe('OVM_L2DepositedERC20', () => {
// Deploy a smodded gateway so we can give some balances to withdraw // Deploy a smodded gateway so we can give some balances to withdraw
SmoddedL2Gateway = await ( SmoddedL2Gateway = await (
await smoddit('OVM_L2DepositedERC20', alice) await smoddit('OVM_L2DepositedERC20', alice)
).deploy( ).deploy(Mock__OVM_L2CrossDomainMessenger.address, 'ovmWETH', 'oWETH')
Mock__OVM_L2CrossDomainMessenger.address,
'ovmWETH',
'oWETH'
)
await SmoddedL2Gateway.init(MOCK_L1GATEWAY_ADDRESS) await SmoddedL2Gateway.init(MOCK_L1GATEWAY_ADDRESS)
// Populate the initial state with a total supply and some money in alice's balance // Populate the initial state with a total supply and some money in alice's balance
......
...@@ -10,7 +10,6 @@ import { ...@@ -10,7 +10,6 @@ import {
makeAddressManager, makeAddressManager,
setProxyTarget, setProxyTarget,
NON_NULL_BYTES32, NON_NULL_BYTES32,
ZERO_ADDRESS,
NON_ZERO_ADDRESS, NON_ZERO_ADDRESS,
NULL_BYTES32, NULL_BYTES32,
DUMMY_BATCH_HEADERS, DUMMY_BATCH_HEADERS,
...@@ -232,7 +231,7 @@ describe('OVM_L1CrossDomainMessenger', () => { ...@@ -232,7 +231,7 @@ describe('OVM_L1CrossDomainMessenger', () => {
true true
) )
const proof = { const proof1 = {
stateRoot: NULL_BYTES32, stateRoot: NULL_BYTES32,
stateRootBatchHeader: DUMMY_BATCH_HEADERS[0], stateRootBatchHeader: DUMMY_BATCH_HEADERS[0],
stateRootProof: DUMMY_BATCH_PROOFS[0], stateRootProof: DUMMY_BATCH_PROOFS[0],
...@@ -246,7 +245,7 @@ describe('OVM_L1CrossDomainMessenger', () => { ...@@ -246,7 +245,7 @@ describe('OVM_L1CrossDomainMessenger', () => {
sender, sender,
message, message,
0, 0,
proof proof1
) )
).to.be.revertedWith('Provided message could not be verified.') ).to.be.revertedWith('Provided message could not be verified.')
}) })
...@@ -256,7 +255,7 @@ describe('OVM_L1CrossDomainMessenger', () => { ...@@ -256,7 +255,7 @@ describe('OVM_L1CrossDomainMessenger', () => {
false false
) )
const proof = { const proof1 = {
stateRoot: NULL_BYTES32, stateRoot: NULL_BYTES32,
stateRootBatchHeader: DUMMY_BATCH_HEADERS[0], stateRootBatchHeader: DUMMY_BATCH_HEADERS[0],
stateRootProof: DUMMY_BATCH_PROOFS[0], stateRootProof: DUMMY_BATCH_PROOFS[0],
...@@ -270,7 +269,7 @@ describe('OVM_L1CrossDomainMessenger', () => { ...@@ -270,7 +269,7 @@ describe('OVM_L1CrossDomainMessenger', () => {
sender, sender,
message, message,
0, 0,
proof proof1
) )
).to.be.revertedWith('Provided message could not be verified.') ).to.be.revertedWith('Provided message could not be verified.')
}) })
......
...@@ -14,7 +14,6 @@ import { ...@@ -14,7 +14,6 @@ import {
DUMMY_BATCH_PROOFS, DUMMY_BATCH_PROOFS,
toHexString, toHexString,
} from '../../../../helpers' } from '../../../../helpers'
import { sign } from 'crypto'
describe('OVM_L1MultiMessageRelayer', () => { describe('OVM_L1MultiMessageRelayer', () => {
let signer: Signer let signer: Signer
...@@ -54,7 +53,7 @@ describe('OVM_L1MultiMessageRelayer', () => { ...@@ -54,7 +53,7 @@ describe('OVM_L1MultiMessageRelayer', () => {
) )
// define a dummy proof to satisfy the abi // define a dummy proof to satisfy the abi
let dummyProof = { const dummyProof = {
stateRoot: NON_NULL_BYTES32, stateRoot: NON_NULL_BYTES32,
stateRootBatchHeader: DUMMY_BATCH_HEADERS[0], stateRootBatchHeader: DUMMY_BATCH_HEADERS[0],
stateRootProof: DUMMY_BATCH_PROOFS[0], stateRootProof: DUMMY_BATCH_PROOFS[0],
...@@ -63,27 +62,30 @@ describe('OVM_L1MultiMessageRelayer', () => { ...@@ -63,27 +62,30 @@ describe('OVM_L1MultiMessageRelayer', () => {
} }
// create a few dummy messages to relay // create a few dummy messages to relay
let m1 = { const m1 = {
target: '0x1100000000000000000000000000000000000000', target: '0x1100000000000000000000000000000000000000',
message: NON_NULL_BYTES32, message: NON_NULL_BYTES32,
sender: '0x2200000000000000000000000000000000000000', sender: '0x2200000000000000000000000000000000000000',
messageNonce: 1, messageNonce: 1,
proof: dummyProof, proof: dummyProof,
} }
let m2 = {
const m2 = {
target: '0x1100000000000000000000000000000000000000', target: '0x1100000000000000000000000000000000000000',
message: NON_NULL_BYTES32, message: NON_NULL_BYTES32,
sender: '0x2200000000000000000000000000000000000000', sender: '0x2200000000000000000000000000000000000000',
messageNonce: 2, messageNonce: 2,
proof: dummyProof, proof: dummyProof,
} }
let m3 = {
const m3 = {
target: '0x1100000000000000000000000000000000000000', target: '0x1100000000000000000000000000000000000000',
message: NON_NULL_BYTES32, message: NON_NULL_BYTES32,
sender: '0x2200000000000000000000000000000000000000', sender: '0x2200000000000000000000000000000000000000',
messageNonce: 2, messageNonce: 2,
proof: dummyProof, proof: dummyProof,
} }
messages = [m1, m2, m3] messages = [m1, m2, m3]
}) })
......
...@@ -2,7 +2,7 @@ import { expect } from '../../../setup' ...@@ -2,7 +2,7 @@ import { expect } from '../../../setup'
/* External Imports */ /* External Imports */
import { ethers } from 'hardhat' import { ethers } from 'hardhat'
import { Signer, ContractFactory, Contract, BigNumber, providers } from 'ethers' import { Signer, ContractFactory, Contract, BigNumber } from 'ethers'
import { TransactionResponse } from '@ethersproject/abstract-provider' import { TransactionResponse } from '@ethersproject/abstract-provider'
import { smockit, MockContract } from '@eth-optimism/smock' import { smockit, MockContract } from '@eth-optimism/smock'
import _ from 'lodash' import _ from 'lodash'
...@@ -245,7 +245,6 @@ describe('OVM_CanonicalTransactionChain', () => { ...@@ -245,7 +245,6 @@ describe('OVM_CanonicalTransactionChain', () => {
describe('enqueue', () => { describe('enqueue', () => {
const target = NON_ZERO_ADDRESS const target = NON_ZERO_ADDRESS
const gasLimit = 500_000 const gasLimit = 500_000
const data = '0x' + '12'.repeat(1234)
it('should revert when trying to input more data than the max data size', async () => { it('should revert when trying to input more data than the max data size', async () => {
const MAX_ROLLUP_TX_SIZE = await OVM_CanonicalTransactionChain.MAX_ROLLUP_TX_SIZE() const MAX_ROLLUP_TX_SIZE = await OVM_CanonicalTransactionChain.MAX_ROLLUP_TX_SIZE()
...@@ -270,15 +269,17 @@ describe('OVM_CanonicalTransactionChain', () => { ...@@ -270,15 +269,17 @@ describe('OVM_CanonicalTransactionChain', () => {
it('should revert if gas limit parameter is not at least MIN_ROLLUP_TX_GAS', async () => { it('should revert if gas limit parameter is not at least MIN_ROLLUP_TX_GAS', async () => {
const MIN_ROLLUP_TX_GAS = await OVM_CanonicalTransactionChain.MIN_ROLLUP_TX_GAS() const MIN_ROLLUP_TX_GAS = await OVM_CanonicalTransactionChain.MIN_ROLLUP_TX_GAS()
const gasLimit = MIN_ROLLUP_TX_GAS / 2 const customGasLimit = MIN_ROLLUP_TX_GAS / 2
const data = '0x' + '12'.repeat(1234)
await expect( await expect(
OVM_CanonicalTransactionChain.enqueue(target, gasLimit, data) OVM_CanonicalTransactionChain.enqueue(target, customGasLimit, data)
).to.be.revertedWith('Transaction gas limit too low to enqueue.') ).to.be.revertedWith('Transaction gas limit too low to enqueue.')
}) })
it('should revert if transaction gas limit does not cover rollup burn', async () => { it('should revert if transaction gas limit does not cover rollup burn', async () => {
const L2_GAS_DISCOUNT_DIVISOR = await OVM_CanonicalTransactionChain.L2_GAS_DISCOUNT_DIVISOR() const L2_GAS_DISCOUNT_DIVISOR = await OVM_CanonicalTransactionChain.L2_GAS_DISCOUNT_DIVISOR()
const data = '0x' + '12'.repeat(1234)
await expect( await expect(
OVM_CanonicalTransactionChain.enqueue(target, gasLimit, data, { OVM_CanonicalTransactionChain.enqueue(target, gasLimit, data, {
...@@ -290,6 +291,8 @@ describe('OVM_CanonicalTransactionChain', () => { ...@@ -290,6 +291,8 @@ describe('OVM_CanonicalTransactionChain', () => {
describe('with valid input parameters', () => { describe('with valid input parameters', () => {
it('should emit a TransactionEnqueued event', async () => { it('should emit a TransactionEnqueued event', async () => {
const timestamp = (await getEthTime(ethers.provider)) + 100 const timestamp = (await getEthTime(ethers.provider)) + 100
const data = '0x' + '12'.repeat(1234)
await setEthTime(ethers.provider, timestamp) await setEthTime(ethers.provider, timestamp)
await expect( await expect(
...@@ -298,6 +301,8 @@ describe('OVM_CanonicalTransactionChain', () => { ...@@ -298,6 +301,8 @@ describe('OVM_CanonicalTransactionChain', () => {
}) })
describe('when enqueing multiple times', () => { describe('when enqueing multiple times', () => {
const data = '0x' + '12'.repeat(1234)
for (const size of ELEMENT_TEST_SIZES) { for (const size of ELEMENT_TEST_SIZES) {
it(`should be able to enqueue ${size} elements`, async () => { it(`should be able to enqueue ${size} elements`, async () => {
for (let i = 0; i < size; i++) { for (let i = 0; i < size; i++) {
...@@ -675,8 +680,8 @@ describe('OVM_CanonicalTransactionChain', () => { ...@@ -675,8 +680,8 @@ describe('OVM_CanonicalTransactionChain', () => {
{ {
numSequencedTransactions: 1, numSequencedTransactions: 1,
numSubsequentQueueTransactions: 0, numSubsequentQueueTransactions: 0,
timestamp: timestamp, timestamp,
blockNumber: blockNumber, blockNumber,
}, },
], ],
transactions: [data], transactions: [data],
...@@ -1005,7 +1010,7 @@ describe('OVM_CanonicalTransactionChain', () => { ...@@ -1005,7 +1010,7 @@ describe('OVM_CanonicalTransactionChain', () => {
{ {
numSequencedTransactions: 1, numSequencedTransactions: 1,
numSubsequentQueueTransactions: 0, numSubsequentQueueTransactions: 0,
timestamp: timestamp, timestamp,
blockNumber, blockNumber,
}, },
], ],
...@@ -1029,8 +1034,8 @@ describe('OVM_CanonicalTransactionChain', () => { ...@@ -1029,8 +1034,8 @@ describe('OVM_CanonicalTransactionChain', () => {
{ {
numSequencedTransactions: 1, numSequencedTransactions: 1,
numSubsequentQueueTransactions: 0, numSubsequentQueueTransactions: 0,
timestamp: timestamp, timestamp,
blockNumber: blockNumber, blockNumber,
}, },
], ],
shouldStartAtElement: 0, shouldStartAtElement: 0,
...@@ -1043,8 +1048,8 @@ describe('OVM_CanonicalTransactionChain', () => { ...@@ -1043,8 +1048,8 @@ describe('OVM_CanonicalTransactionChain', () => {
}) })
describe('adding multiple sequencer transactions with multiple pending queue elements', () => { describe('adding multiple sequencer transactions with multiple pending queue elements', () => {
const numQueuedTransactions = 10 const numQueuedTransactions = 10
let queueElements = [] const queueElements = []
let validContexts = [] const validContexts = []
beforeEach(async () => { beforeEach(async () => {
for (let i = 0; i < numQueuedTransactions; i++) { for (let i = 0; i < numQueuedTransactions; i++) {
await OVM_CanonicalTransactionChain.enqueue( await OVM_CanonicalTransactionChain.enqueue(
...@@ -1075,7 +1080,7 @@ describe('OVM_CanonicalTransactionChain', () => { ...@@ -1075,7 +1080,7 @@ describe('OVM_CanonicalTransactionChain', () => {
}) })
it('reverts if wrong timestamp in middle', async () => { it('reverts if wrong timestamp in middle', async () => {
let invalidTimestampContexts = [...validContexts] const invalidTimestampContexts = [...validContexts]
// put a bigger timestamp early // put a bigger timestamp early
invalidTimestampContexts[6].timestamp = invalidTimestampContexts[6].timestamp =
invalidTimestampContexts[8].timestamp invalidTimestampContexts[8].timestamp
...@@ -1093,7 +1098,7 @@ describe('OVM_CanonicalTransactionChain', () => { ...@@ -1093,7 +1098,7 @@ describe('OVM_CanonicalTransactionChain', () => {
}) })
it('reverts if wrong block number in the middle', async () => { it('reverts if wrong block number in the middle', async () => {
let invalidBlockNumberContexts = [...validContexts] const invalidBlockNumberContexts = [...validContexts]
// put a bigger block number early // put a bigger block number early
invalidBlockNumberContexts[6].blockNumber = invalidBlockNumberContexts[6].blockNumber =
invalidBlockNumberContexts[8].blockNumber invalidBlockNumberContexts[8].blockNumber
...@@ -1415,8 +1420,8 @@ describe('OVM_CanonicalTransactionChain', () => { ...@@ -1415,8 +1420,8 @@ describe('OVM_CanonicalTransactionChain', () => {
{ {
numSequencedTransactions: size, numSequencedTransactions: size,
numSubsequentQueueTransactions: 0, numSubsequentQueueTransactions: 0,
timestamp: timestamp, timestamp,
blockNumber: blockNumber, blockNumber,
}, },
] ]
...@@ -1466,7 +1471,7 @@ describe('OVM_CanonicalTransactionChain', () => { ...@@ -1466,7 +1471,7 @@ describe('OVM_CanonicalTransactionChain', () => {
return { return {
numSequencedTransactions: 1, numSequencedTransactions: 1,
numSubsequentQueueTransactions: 1, numSubsequentQueueTransactions: 1,
timestamp: timestamp, timestamp,
blockNumber: Math.max(blockNumber, 0), blockNumber: Math.max(blockNumber, 0),
} }
}) })
...@@ -1506,7 +1511,7 @@ describe('OVM_CanonicalTransactionChain', () => { ...@@ -1506,7 +1511,7 @@ describe('OVM_CanonicalTransactionChain', () => {
return { return {
numSequencedTransactions: size / spacing, numSequencedTransactions: size / spacing,
numSubsequentQueueTransactions: 1, numSubsequentQueueTransactions: 1,
timestamp: timestamp, timestamp,
blockNumber: Math.max(blockNumber, 0), blockNumber: Math.max(blockNumber, 0),
} }
}) })
...@@ -1552,7 +1557,7 @@ describe('OVM_CanonicalTransactionChain', () => { ...@@ -1552,7 +1557,7 @@ describe('OVM_CanonicalTransactionChain', () => {
{ {
numSequencedTransactions: size, numSequencedTransactions: size,
numSubsequentQueueTransactions: 0, numSubsequentQueueTransactions: 0,
timestamp: timestamp, timestamp,
blockNumber: Math.max(blockNumber, 0), blockNumber: Math.max(blockNumber, 0),
}, },
] ]
......
...@@ -15,7 +15,6 @@ import { ...@@ -15,7 +15,6 @@ import {
NULL_BYTES32, NULL_BYTES32,
increaseEthTime, increaseEthTime,
} from '../../../helpers' } from '../../../helpers'
import { keccak256, defaultAbiCoder } from 'ethers/lib/utils'
describe('OVM_StateCommitmentChain', () => { describe('OVM_StateCommitmentChain', () => {
let sequencer: Signer let sequencer: Signer
...@@ -205,7 +204,7 @@ describe('OVM_StateCommitmentChain', () => { ...@@ -205,7 +204,7 @@ describe('OVM_StateCommitmentChain', () => {
batch.length batch.length
) )
await OVM_StateCommitmentChain.appendStateBatch(batch, 0) await OVM_StateCommitmentChain.appendStateBatch(batch, 0)
batchHeader.extraData = defaultAbiCoder.encode( batchHeader.extraData = ethers.utils.defaultAbiCoder.encode(
['uint256', 'address'], ['uint256', 'address'],
[await getEthTime(ethers.provider), await sequencer.getAddress()] [await getEthTime(ethers.provider), await sequencer.getAddress()]
) )
......
...@@ -6,7 +6,6 @@ import { ethers } from 'hardhat' ...@@ -6,7 +6,6 @@ import { ethers } from 'hardhat'
import { Contract, ContractFactory, Signer } from 'ethers' import { Contract, ContractFactory, Signer } from 'ethers'
import { smockit, MockContract } from '@eth-optimism/smock' import { smockit, MockContract } from '@eth-optimism/smock'
/* Internal Imports */ /* Internal Imports */
import { import {
makeAddressManager, makeAddressManager,
...@@ -28,17 +27,17 @@ const DUMMY_GLOBALCONTEXT = { ...@@ -28,17 +27,17 @@ const DUMMY_GLOBALCONTEXT = {
const QUEUE_ORIGIN = { const QUEUE_ORIGIN = {
SEQUENCER_QUEUE: 0, SEQUENCER_QUEUE: 0,
L1TOL2_QUEUE: 1 L1TOL2_QUEUE: 1,
} }
let DUMMY_TRANSACTION = { const DUMMY_TRANSACTION = {
timestamp: 111111111111, timestamp: 111111111111,
blockNumber: 20, blockNumber: 20,
l1QueueOrigin: QUEUE_ORIGIN.SEQUENCER_QUEUE, l1QueueOrigin: QUEUE_ORIGIN.SEQUENCER_QUEUE,
l1TxOrigin: NON_ZERO_ADDRESS, l1TxOrigin: NON_ZERO_ADDRESS,
entrypoint: NON_ZERO_ADDRESS, // update this below entrypoint: NON_ZERO_ADDRESS, // update this below
gasLimit: 10_000_000, gasLimit: 10_000_000,
data: 0 data: 0,
} }
describe('OVM_ExecutionManager gas consumption', () => { describe('OVM_ExecutionManager gas consumption', () => {
...@@ -56,26 +55,32 @@ describe('OVM_ExecutionManager gas consumption', () => { ...@@ -56,26 +55,32 @@ describe('OVM_ExecutionManager gas consumption', () => {
Factory__OVM_ExecutionManager = await ethers.getContractFactory( Factory__OVM_ExecutionManager = await ethers.getContractFactory(
'OVM_ExecutionManager' 'OVM_ExecutionManager'
) )
// Deploy a simple contract that just returns successfully with no data // Deploy a simple contract that just returns successfully with no data
targetContractAddress = await deployContractCode('60206001f3', wallet, 10_000_000) targetContractAddress = await deployContractCode(
'60206001f3',
wallet,
10_000_000
)
DUMMY_TRANSACTION.entrypoint = targetContractAddress DUMMY_TRANSACTION.entrypoint = targetContractAddress
AddressManager = await makeAddressManager() AddressManager = await makeAddressManager()
// deploy the state manager and mock it for the state transitioner // deploy the state manager and mock it for the state transitioner
MOCK__STATE_MANAGER = await smockit( MOCK__STATE_MANAGER = await smockit(
await ( await (await ethers.getContractFactory('OVM_StateManager')).deploy(
await ethers.getContractFactory('OVM_StateManager') NON_ZERO_ADDRESS
).deploy(NON_ZERO_ADDRESS) )
) )
// Setup the SM to satisfy all the checks executed during EM.run() // Setup the SM to satisfy all the checks executed during EM.run()
MOCK__STATE_MANAGER.smocked.isAuthenticated.will.return.with(true) MOCK__STATE_MANAGER.smocked.isAuthenticated.will.return.with(true)
MOCK__STATE_MANAGER.smocked.getAccountEthAddress.will.return.with(targetContractAddress) MOCK__STATE_MANAGER.smocked.getAccountEthAddress.will.return.with(
targetContractAddress
)
MOCK__STATE_MANAGER.smocked.hasAccount.will.return.with(true) MOCK__STATE_MANAGER.smocked.hasAccount.will.return.with(true)
MOCK__STATE_MANAGER.smocked.testAndSetAccountLoaded.will.return.with(true) MOCK__STATE_MANAGER.smocked.testAndSetAccountLoaded.will.return.with(true)
await AddressManager.setAddress( await AddressManager.setAddress(
'OVM_StateManagerFactory', 'OVM_StateManagerFactory',
MOCK__STATE_MANAGER.address MOCK__STATE_MANAGER.address
...@@ -85,7 +90,6 @@ describe('OVM_ExecutionManager gas consumption', () => { ...@@ -85,7 +90,6 @@ describe('OVM_ExecutionManager gas consumption', () => {
await gasMeasurement.init(wallet) await gasMeasurement.init(wallet)
}) })
let OVM_ExecutionManager: Contract let OVM_ExecutionManager: Contract
beforeEach(async () => { beforeEach(async () => {
OVM_ExecutionManager = ( OVM_ExecutionManager = (
...@@ -99,17 +103,18 @@ describe('OVM_ExecutionManager gas consumption', () => { ...@@ -99,17 +103,18 @@ describe('OVM_ExecutionManager gas consumption', () => {
describe('Measure cost of a very simple contract', async () => { describe('Measure cost of a very simple contract', async () => {
it('Gas cost of run', async () => { it('Gas cost of run', async () => {
let gasCost = await gasMeasurement.getGasCost( const gasCost = await gasMeasurement.getGasCost(
OVM_ExecutionManager, 'run', OVM_ExecutionManager,
'run',
[DUMMY_TRANSACTION, MOCK__STATE_MANAGER.address] [DUMMY_TRANSACTION, MOCK__STATE_MANAGER.address]
) )
console.log(`calculated gas cost of ${gasCost}`) console.log(`calculated gas cost of ${gasCost}`)
let benchmark:number = 226_516 const benchmark: number = 226_516
expect(gasCost).to.be.lte(benchmark) expect(gasCost).to.be.lte(benchmark)
expect(gasCost).to.be.gte( expect(gasCost).to.be.gte(
benchmark - 1_000, benchmark - 1_000,
"Gas cost has significantly decreased, consider updating the benchmark to reflect the change" 'Gas cost has significantly decreased, consider updating the benchmark to reflect the change'
) )
}) })
}) })
......
...@@ -4,16 +4,12 @@ import { ...@@ -4,16 +4,12 @@ import {
TestDefinition, TestDefinition,
OVM_TX_GAS_LIMIT, OVM_TX_GAS_LIMIT,
NON_NULL_BYTES32, NON_NULL_BYTES32,
REVERT_FLAGS,
VERIFIED_EMPTY_CONTRACT_HASH, VERIFIED_EMPTY_CONTRACT_HASH,
NUISANCE_GAS_COSTS, NUISANCE_GAS_COSTS,
Helper_TestRunner_BYTELEN, Helper_TestRunner_BYTELEN,
ZERO_ADDRESS, ZERO_ADDRESS,
} from '../../../../helpers' } from '../../../../helpers'
const DUMMY_REVERT_DATA =
'0xdeadbeef1e5420deadbeef1e5420deadbeef1e5420deadbeef1e5420deadbeef1e5420'
const CREATED_CONTRACT_1 = '0x2bda4a99d5be88609d23b1e4ab5d1d34fb1c2feb' const CREATED_CONTRACT_1 = '0x2bda4a99d5be88609d23b1e4ab5d1d34fb1c2feb'
const FRESH_CALL_NUISANCE_GAS_COST = const FRESH_CALL_NUISANCE_GAS_COST =
......
...@@ -4,7 +4,6 @@ import { ...@@ -4,7 +4,6 @@ import {
TestDefinition, TestDefinition,
OVM_TX_GAS_LIMIT, OVM_TX_GAS_LIMIT,
NON_NULL_BYTES32, NON_NULL_BYTES32,
REVERT_FLAGS,
VERIFIED_EMPTY_CONTRACT_HASH, VERIFIED_EMPTY_CONTRACT_HASH,
} from '../../../../helpers' } from '../../../../helpers'
......
...@@ -3,9 +3,7 @@ import { ...@@ -3,9 +3,7 @@ import {
ExecutionManagerTestRunner, ExecutionManagerTestRunner,
TestDefinition, TestDefinition,
OVM_TX_GAS_LIMIT, OVM_TX_GAS_LIMIT,
NULL_BYTES32,
NON_NULL_BYTES32, NON_NULL_BYTES32,
REVERT_FLAGS,
DUMMY_BYTECODE, DUMMY_BYTECODE,
VERIFIED_EMPTY_CONTRACT_HASH, VERIFIED_EMPTY_CONTRACT_HASH,
} from '../../../../helpers' } from '../../../../helpers'
......
import { expect } from '../../../setup' import '../../../setup'
/* External Imports */ /* External Imports */
import { ethers } from 'hardhat' import { ethers } from 'hardhat'
import { Contract, ContractFactory, Signer, BigNumber } from 'ethers' import { Contract, ContractFactory, Signer } from 'ethers'
import _ from 'lodash' import _ from 'lodash'
/* Internal Imports */ /* Internal Imports */
...@@ -29,7 +29,6 @@ describe('OVM_StateManager gas consumption', () => { ...@@ -29,7 +29,6 @@ describe('OVM_StateManager gas consumption', () => {
}) })
let Factory__OVM_StateManager: ContractFactory let Factory__OVM_StateManager: ContractFactory
let Helper_GasMeasurer: Contract
let gasMeasurement: GasMeasurement let gasMeasurement: GasMeasurement
before(async () => { before(async () => {
Factory__OVM_StateManager = await ethers.getContractFactory( Factory__OVM_StateManager = await ethers.getContractFactory(
...@@ -39,14 +38,15 @@ describe('OVM_StateManager gas consumption', () => { ...@@ -39,14 +38,15 @@ describe('OVM_StateManager gas consumption', () => {
await gasMeasurement.init(owner) await gasMeasurement.init(owner)
}) })
let OVM_StateManager: Contract let OVM_StateManager: Contract
beforeEach(async () => { beforeEach(async () => {
OVM_StateManager = ( OVM_StateManager = (
await Factory__OVM_StateManager.deploy(await owner.getAddress()) await Factory__OVM_StateManager.deploy(await owner.getAddress())
).connect(owner) ).connect(owner)
await OVM_StateManager.setExecutionManager(gasMeasurement.GasMeasurementContract.address) await OVM_StateManager.setExecutionManager(
gasMeasurement.GasMeasurementContract.address
)
}) })
const measure = ( const measure = (
...@@ -58,7 +58,11 @@ describe('OVM_StateManager gas consumption', () => { ...@@ -58,7 +58,11 @@ describe('OVM_StateManager gas consumption', () => {
) => { ) => {
it('measured consumption!', async () => { it('measured consumption!', async () => {
await doFirst() await doFirst()
let gasCost = await gasMeasurement.getGasCost(OVM_StateManager, methodName, methodArgs) const gasCost = await gasMeasurement.getGasCost(
OVM_StateManager,
methodName,
methodArgs
)
console.log(` calculated gas cost of ${gasCost}`) console.log(` calculated gas cost of ${gasCost}`)
}) })
} }
...@@ -378,8 +382,8 @@ describe('OVM_StateManager gas consumption', () => { ...@@ -378,8 +382,8 @@ describe('OVM_StateManager gas consumption', () => {
describe('putContractStorage', () => { describe('putContractStorage', () => {
const relevantValues = [DUMMY_VALUE_1, DUMMY_VALUE_2, STORAGE_XOR_VALUE] const relevantValues = [DUMMY_VALUE_1, DUMMY_VALUE_2, STORAGE_XOR_VALUE]
for (let preValue of relevantValues) { for (const preValue of relevantValues) {
for (let postValue of relevantValues) { for (const postValue of relevantValues) {
describe(`when overwriting ${preValue} with ${postValue}`, () => { describe(`when overwriting ${preValue} with ${postValue}`, () => {
measure( measure(
'putContractStorage', 'putContractStorage',
......
...@@ -4,12 +4,9 @@ import { expect } from '../../../setup' ...@@ -4,12 +4,9 @@ import { expect } from '../../../setup'
import { ethers, waffle } from 'hardhat' import { ethers, waffle } from 'hardhat'
import { ContractFactory, Contract, Wallet } from 'ethers' import { ContractFactory, Contract, Wallet } from 'ethers'
import { MockContract, smockit } from '@eth-optimism/smock' import { MockContract, smockit } from '@eth-optimism/smock'
import {
encodeSequencerCalldata, /* Internal Imports */
DEFAULT_EIP155_TX, import { ZERO_ADDRESS, remove0x } from '../../../helpers'
ZERO_ADDRESS,
remove0x,
} from '../../../helpers'
const callPrecompile = async ( const callPrecompile = async (
Helper_PrecompileCaller: Contract, Helper_PrecompileCaller: Contract,
......
...@@ -3,20 +3,18 @@ import { expect } from '../../../setup' ...@@ -3,20 +3,18 @@ import { expect } from '../../../setup'
/* External Imports */ /* External Imports */
import { waffle, ethers } from 'hardhat' import { waffle, ethers } from 'hardhat'
import { ContractFactory, Wallet, Contract } from 'ethers' import { ContractFactory, Wallet, Contract } from 'ethers'
import { zeroPad } from '@ethersproject/bytes' import { smockit, MockContract } from '@eth-optimism/smock'
/* Internal Imports */
import { getContractInterface } from '../../../../src' import { getContractInterface } from '../../../../src'
import { import {
encodeSequencerCalldata, encodeSequencerCalldata,
EIP155Transaction,
signNativeTransaction, signNativeTransaction,
signEthSignMessage, signEthSignMessage,
DEFAULT_EIP155_TX, DEFAULT_EIP155_TX,
serializeNativeTransaction, serializeNativeTransaction,
serializeEthSignTransaction, serializeEthSignTransaction,
ZERO_ADDRESS,
} from '../../../helpers' } from '../../../helpers'
import { smockit, MockContract } from '@eth-optimism/smock'
import { create } from 'lodash'
describe('OVM_SequencerEntrypoint', () => { describe('OVM_SequencerEntrypoint', () => {
let wallet: Wallet let wallet: Wallet
......
...@@ -412,7 +412,7 @@ describe('OVM_FraudVerifier', () => { ...@@ -412,7 +412,7 @@ describe('OVM_FraudVerifier', () => {
describe('multiple fraud proofs for the same pre-execution state', () => { describe('multiple fraud proofs for the same pre-execution state', () => {
let state2: any let state2: any
let DUMMY_HASH_2 = hashTransaction(DUMMY_OVM_TRANSACTIONS[1]) const DUMMY_HASH_2 = hashTransaction(DUMMY_OVM_TRANSACTIONS[1])
beforeEach(async () => { beforeEach(async () => {
state2 = await smockit( state2 = await smockit(
await ethers.getContractFactory('OVM_StateTransitioner') await ethers.getContractFactory('OVM_StateTransitioner')
......
...@@ -3,7 +3,7 @@ import { expect } from '../../../setup' ...@@ -3,7 +3,7 @@ import { expect } from '../../../setup'
/* External Imports */ /* External Imports */
import { ethers } from 'hardhat' import { ethers } from 'hardhat'
import { BigNumber, Contract, ContractFactory } from 'ethers' import { BigNumber, Contract } from 'ethers'
import * as rlp from 'rlp' import * as rlp from 'rlp'
/* Internal Imports */ /* Internal Imports */
...@@ -24,7 +24,6 @@ import { ...@@ -24,7 +24,6 @@ import {
smoddit, smoddit,
ModifiableContractFactory, ModifiableContractFactory,
} from '@eth-optimism/smock' } from '@eth-optimism/smock'
import { keccak256 } from 'ethers/lib/utils'
describe('OVM_StateTransitioner', () => { describe('OVM_StateTransitioner', () => {
let AddressManager: Contract let AddressManager: Contract
...@@ -92,7 +91,7 @@ describe('OVM_StateTransitioner', () => { ...@@ -92,7 +91,7 @@ describe('OVM_StateTransitioner', () => {
}) })
describe('proveContractState', () => { describe('proveContractState', () => {
let ovmContractAddress = NON_ZERO_ADDRESS const ovmContractAddress = NON_ZERO_ADDRESS
let ethContractAddress = ZERO_ADDRESS let ethContractAddress = ZERO_ADDRESS
let account: any let account: any
beforeEach(() => { beforeEach(() => {
...@@ -109,7 +108,7 @@ describe('OVM_StateTransitioner', () => { ...@@ -109,7 +108,7 @@ describe('OVM_StateTransitioner', () => {
describe('when provided a valid code hash', () => { describe('when provided a valid code hash', () => {
beforeEach(async () => { beforeEach(async () => {
ethContractAddress = OVM_StateTransitioner.address ethContractAddress = OVM_StateTransitioner.address
account.codeHash = keccak256( account.codeHash = ethers.utils.keccak256(
await ethers.provider.getCode(OVM_StateTransitioner.address) await ethers.provider.getCode(OVM_StateTransitioner.address)
) )
}) })
...@@ -207,9 +206,9 @@ describe('OVM_StateTransitioner', () => { ...@@ -207,9 +206,9 @@ describe('OVM_StateTransitioner', () => {
}) })
describe('when provided an invalid slot inclusion proof', () => { describe('when provided an invalid slot inclusion proof', () => {
let key = keccak256('0x1234') const key = ethers.utils.keccak256('0x1234')
let val = keccak256('0x5678') const val = ethers.utils.keccak256('0x5678')
let proof = '0x' const proof = '0x'
beforeEach(async () => { beforeEach(async () => {
const generator = await TrieTestGenerator.fromNodes({ const generator = await TrieTestGenerator.fromNodes({
nodes: [ nodes: [
...@@ -236,8 +235,8 @@ describe('OVM_StateTransitioner', () => { ...@@ -236,8 +235,8 @@ describe('OVM_StateTransitioner', () => {
}) })
describe('when provided a valid slot inclusion proof', () => { describe('when provided a valid slot inclusion proof', () => {
let key = keccak256('0x1234') const key = ethers.utils.keccak256('0x1234')
let val = keccak256('0x5678') const val = ethers.utils.keccak256('0x5678')
let proof: string let proof: string
beforeEach(async () => { beforeEach(async () => {
const generator = await TrieTestGenerator.fromNodes({ const generator = await TrieTestGenerator.fromNodes({
...@@ -329,7 +328,7 @@ describe('OVM_StateTransitioner', () => { ...@@ -329,7 +328,7 @@ describe('OVM_StateTransitioner', () => {
}) })
}) })
let ovmContractAddress = NON_ZERO_ADDRESS const ovmContractAddress = NON_ZERO_ADDRESS
let account: any let account: any
beforeEach(() => { beforeEach(() => {
account = { account = {
...@@ -414,11 +413,11 @@ describe('OVM_StateTransitioner', () => { ...@@ -414,11 +413,11 @@ describe('OVM_StateTransitioner', () => {
}) })
}) })
let ovmContractAddress = NON_ZERO_ADDRESS const ovmContractAddress = NON_ZERO_ADDRESS
let account: any let account: any
let key = keccak256('0x1234') const key = ethers.utils.keccak256('0x1234')
let val = keccak256('0x5678') const val = ethers.utils.keccak256('0x5678')
let newVal = keccak256('0x4321') const newVal = ethers.utils.keccak256('0x4321')
beforeEach(() => { beforeEach(() => {
account = { account = {
nonce: 0, nonce: 0,
...@@ -460,9 +459,7 @@ describe('OVM_StateTransitioner', () => { ...@@ -460,9 +459,7 @@ describe('OVM_StateTransitioner', () => {
}) })
describe('with a valid proof', () => { describe('with a valid proof', () => {
let accountTrieProof: string
let storageTrieProof: string let storageTrieProof: string
let postStateRoot: string
beforeEach(async () => { beforeEach(async () => {
const storageGenerator = await TrieTestGenerator.fromNodes({ const storageGenerator = await TrieTestGenerator.fromNodes({
nodes: [ nodes: [
...@@ -505,11 +502,8 @@ describe('OVM_StateTransitioner', () => { ...@@ -505,11 +502,8 @@ describe('OVM_StateTransitioner', () => {
isFresh: false, isFresh: false,
}) })
accountTrieProof = test.accountTrieWitness
storageTrieProof = storageTest.proof storageTrieProof = storageTest.proof
postStateRoot = test.newAccountTrieRoot
OVM_StateTransitioner.smodify.put({ OVM_StateTransitioner.smodify.put({
postStateRoot: test.accountTrieRoot, postStateRoot: test.accountTrieRoot,
}) })
......
...@@ -2,7 +2,7 @@ import { expect } from '../../../setup' ...@@ -2,7 +2,7 @@ import { expect } from '../../../setup'
/* External Imports */ /* External Imports */
import { ethers } from 'hardhat' import { ethers } from 'hardhat'
import { ContractFactory, Contract, BigNumber } from 'ethers' import { ContractFactory, Contract } from 'ethers'
/* Internal Imports */ /* Internal Imports */
import { import {
......
/* tslint:disable:no-empty */ /* tslint:disable:no-empty */
import { expect } from '../../../setup' import '../../../setup'
/* Internal Imports */ /* Internal Imports */
import { Lib_OVMCodec_TEST_JSON } from '../../../data' import { Lib_OVMCodec_TEST_JSON } from '../../../data'
import { runJsonTest, toHexString } from '../../../helpers' import { runJsonTest } from '../../../helpers'
describe.skip('Lib_OVMCodec', () => { describe.skip('Lib_OVMCodec', () => {
describe('JSON tests', () => { describe('JSON tests', () => {
......
/* External Imports */
import * as rlp from 'rlp'
/* Internal Imports */ /* Internal Imports */
import { Lib_RLPReader_TEST_JSON } from '../../../data' import { Lib_RLPReader_TEST_JSON } from '../../../data'
import { runJsonTest, toHexString } from '../../../helpers' import { runJsonTest } from '../../../helpers'
describe('Lib_RLPReader', () => { describe('Lib_RLPReader', () => {
describe('JSON tests', () => { describe('JSON tests', () => {
......
...@@ -122,7 +122,7 @@ describe('Lib_MerkleTrie', () => { ...@@ -122,7 +122,7 @@ describe('Lib_MerkleTrie', () => {
}) })
it(`should revert when the first proof element is not the root node`, async () => { it(`should revert when the first proof element is not the root node`, async () => {
const test = await generator.makeInclusionProofTest(0) const test = await generator.makeInclusionProofTest(0)
let decodedProof = rlp.decode(test.proof) const decodedProof = rlp.decode(test.proof)
decodedProof[0].write('abcd', 8) // change the 1st element (root) of the proof decodedProof[0].write('abcd', 8) // change the 1st element (root) of the proof
const badProof = rlp.encode(decodedProof as rlp.Input) const badProof = rlp.encode(decodedProof as rlp.Input)
await expect( await expect(
...@@ -156,7 +156,7 @@ describe('Lib_MerkleTrie', () => { ...@@ -156,7 +156,7 @@ describe('Lib_MerkleTrie', () => {
it(`should revert on an incorrect proof node prefix`, async () => { it(`should revert on an incorrect proof node prefix`, async () => {
const test = await generator.makeInclusionProofTest(0) const test = await generator.makeInclusionProofTest(0)
let decodedProof = rlp.decode(test.proof) const decodedProof = rlp.decode(test.proof)
decodedProof[0].write('a', 3) // change the prefix decodedProof[0].write('a', 3) // change the prefix
test.root = ethers.utils.keccak256(toHexString(decodedProof[0])) test.root = ethers.utils.keccak256(toHexString(decodedProof[0]))
const badProof = rlp.encode(decodedProof as rlp.Input) const badProof = rlp.encode(decodedProof as rlp.Input)
......
/* External Imports */ /* External Imports */
import { ethers } from 'hardhat' import { ethers } from 'hardhat'
import { zeroPad } from '@ethersproject/bytes'
import { Wallet } from 'ethers' import { Wallet } from 'ethers'
import {
remove0x, /* Internal Imports */
numberToHexString, import { remove0x, hexStrToBuf } from '../'
hexStrToBuf,
makeAddressManager,
} from '../'
import { ZERO_ADDRESS } from '../constants' import { ZERO_ADDRESS } from '../constants'
export interface EIP155Transaction { export interface EIP155Transaction {
...@@ -44,12 +40,12 @@ export const getSignedComponents = (signed: string): any[] => { ...@@ -44,12 +40,12 @@ export const getSignedComponents = (signed: string): any[] => {
} }
export const encodeCompactTransaction = (transaction: any): string => { export const encodeCompactTransaction = (transaction: any): string => {
const nonce = zeroPad(transaction.nonce, 3) const nonce = ethers.utils.zeroPad(transaction.nonce, 3)
const gasLimit = zeroPad(transaction.gasLimit, 3) const gasLimit = ethers.utils.zeroPad(transaction.gasLimit, 3)
if (transaction.gasPrice % 1000000 !== 0) if (transaction.gasPrice % 1000000 !== 0)
throw Error('gas price must be a multiple of 1000000') throw Error('gas price must be a multiple of 1000000')
const compressedGasPrice: any = transaction.gasPrice / 1000000 const compressedGasPrice: any = transaction.gasPrice / 1000000
const gasPrice = zeroPad(compressedGasPrice, 3) const gasPrice = ethers.utils.zeroPad(compressedGasPrice, 3)
const to = !transaction.to.length const to = !transaction.to.length
? hexStrToBuf(ZERO_ADDRESS) ? hexStrToBuf(ZERO_ADDRESS)
: hexStrToBuf(transaction.to) : hexStrToBuf(transaction.to)
...@@ -96,15 +92,14 @@ export const signEthSignMessage = async ( ...@@ -96,15 +92,14 @@ export const signEthSignMessage = async (
const transactionSignature = await wallet.signMessage(transactionHashBytes) const transactionSignature = await wallet.signMessage(transactionHashBytes)
const messageHash = ethers.utils.hashMessage(transactionHashBytes) const messageHash = ethers.utils.hashMessage(transactionHashBytes)
let [v, r, s] = getRawSignedComponents(transactionSignature).map( const [v, r, s] = getRawSignedComponents(transactionSignature).map(
(component) => { (component) => {
return remove0x(component) return remove0x(component)
} }
) )
v = '0' + (parseInt(v, 16) - 27)
return { return {
messageHash, messageHash,
v, v: '0' + (parseInt(v, 16) - 27),
r, r,
s, s,
} }
...@@ -118,13 +113,14 @@ export const signNativeTransaction = async ( ...@@ -118,13 +113,14 @@ export const signNativeTransaction = async (
const transactionSignature = await wallet.signTransaction(transaction) const transactionSignature = await wallet.signTransaction(transaction)
const messageHash = ethers.utils.keccak256(serializedTransaction) const messageHash = ethers.utils.keccak256(serializedTransaction)
let [v, r, s] = getSignedComponents(transactionSignature).map((component) => { const [v, r, s] = getSignedComponents(transactionSignature).map(
return remove0x(component) (component) => {
}) return remove0x(component)
v = '0' + (parseInt(v, 16) - transaction.chainId * 2 - 8 - 27) }
)
return { return {
messageHash, messageHash,
v, v: '0' + (parseInt(v, 16) - transaction.chainId * 2 - 8 - 27),
r, r,
s, s,
} }
......
...@@ -4,7 +4,7 @@ import { Contract, Signer } from 'ethers' ...@@ -4,7 +4,7 @@ import { Contract, Signer } from 'ethers'
export class GasMeasurement { export class GasMeasurement {
GasMeasurementContract: Contract GasMeasurementContract: Contract
public async init(wallet: Signer){ public async init(wallet: Signer) {
this.GasMeasurementContract = await ( this.GasMeasurementContract = await (
await (await ethers.getContractFactory('Helper_GasMeasurer')).deploy() await (await ethers.getContractFactory('Helper_GasMeasurer')).deploy()
).connect(wallet) ).connect(wallet)
...@@ -14,8 +14,7 @@ export class GasMeasurement { ...@@ -14,8 +14,7 @@ export class GasMeasurement {
targetContract: Contract, targetContract: Contract,
methodName: string, methodName: string,
methodArgs: Array<any> = [] methodArgs: Array<any> = []
): Promise<number> ): Promise<number> {
{
const gasCost: number = await this.GasMeasurementContract.callStatic.measureCallGas( const gasCost: number = await this.GasMeasurementContract.callStatic.measureCallGas(
targetContract.address, targetContract.address,
targetContract.interface.encodeFunctionData(methodName, methodArgs) targetContract.interface.encodeFunctionData(methodName, methodArgs)
......
...@@ -83,6 +83,7 @@ export class ExecutionManagerTestRunner { ...@@ -83,6 +83,7 @@ export class ExecutionManagerTestRunner {
} }
public run(test: TestDefinition) { public run(test: TestDefinition) {
// tslint:disable-next-line:ban-comma-operator
;(test.preState = merge( ;(test.preState = merge(
cloneDeep(this.defaultPreState), cloneDeep(this.defaultPreState),
cloneDeep(test.preState) cloneDeep(test.preState)
...@@ -255,7 +256,7 @@ export class ExecutionManagerTestRunner { ...@@ -255,7 +256,7 @@ export class ExecutionManagerTestRunner {
return this.contracts.OVM_SafetyChecker.address return this.contracts.OVM_SafetyChecker.address
} else if (kv === '$OVM_CALL_HELPER') { } else if (kv === '$OVM_CALL_HELPER') {
return this.contracts.Helper_TestRunner.address return this.contracts.Helper_TestRunner.address
} else if (kv == '$OVM_DEPLOYER_WHITELIST') { } else if (kv === '$OVM_DEPLOYER_WHITELIST') {
return this.contracts.OVM_DeployerWhitelist.address return this.contracts.OVM_DeployerWhitelist.address
} else if (kv.startsWith('$DUMMY_OVM_ADDRESS_')) { } else if (kv.startsWith('$DUMMY_OVM_ADDRESS_')) {
return ExecutionManagerTestRunner.getDummyAddress(kv) return ExecutionManagerTestRunner.getDummyAddress(kv)
......
import { Signer } from 'ethers' import { Signer } from 'ethers'
import { toHexString } from '../../../src/utils' import { toHexString } from '../../../src/utils'
export const deployContractCode = async (code: string, signer: Signer, gasLimit: number): Promise<string> => { export const deployContractCode = async (
code: string,
signer: Signer,
gasLimit: number
): Promise<string> => {
// "Magic" prefix to be prepended to the contract code. Contains a series of opcodes that will // "Magic" prefix to be prepended to the contract code. Contains a series of opcodes that will
// copy the given code into memory and return it, thereby storing at the contract address. // copy the given code into memory and return it, thereby storing at the contract address.
const prefix = '0x600D380380600D6000396000f3' const prefix = '0x600D380380600D6000396000f3'
......
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
"target": "es2017", "target": "es2017",
"declaration": true, "declaration": true,
"noImplicitAny": false, "noImplicitAny": false,
"noUnusedLocals": true,
"removeComments": true, "removeComments": true,
"noLib": false, "noLib": false,
"emitDecoratorMetadata": true, "emitDecoratorMetadata": true,
......
...@@ -32,8 +32,7 @@ ...@@ -32,8 +32,7 @@
"linterOptions": { "linterOptions": {
"exclude": [ "exclude": [
"**/node_modules/**/*", "**/node_modules/**/*",
"bin/**/*", "bin/**/*"
"test/**/*"
] ]
} }
} }
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