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