Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
207cbe8
Moved all OVM files and deleted the package
smartcontracts Jun 24, 2020
358ea4c
Started cleaning contracts
smartcontracts Jun 24, 2020
922536a
Quick contract cleanup
smartcontracts Jun 24, 2020
073448a
Added cleaned contracts
smartcontracts Jun 25, 2020
64b7000
Fixed merge conflicts
smartcontracts Jun 25, 2020
ba1d7bc
Fixed package.json
smartcontracts Jun 25, 2020
16b9374
Removed /ovm requirements
smartcontracts Jun 25, 2020
30e6b2e
Fixed circular dependencies
smartcontracts Jun 25, 2020
3e1801b
Fixed various linting errors
smartcontracts Jun 25, 2020
fc409d8
Fixed yet another ganache-core issue
smartcontracts Jun 25, 2020
41bc77c
Fixed bug causing tests to fail
smartcontracts Jun 26, 2020
3baed52
Fixed bug causing tests to fail
smartcontracts Jun 26, 2020
64c7f01
Merged master
smartcontracts Jun 26, 2020
78ce1bc
Merge branch 'master' of github.com:ethereum-optimism/optimism-monore…
smartcontracts Jun 26, 2020
4593033
Added older RLPEncode file again
smartcontracts Jun 26, 2020
5840831
Renamed rollup-contracts => contracts
smartcontracts Jun 26, 2020
45e94f4
Transitioned contracts to use buidler
smartcontracts Jun 30, 2020
470fbe1
Linted and added better export method
smartcontracts Jun 30, 2020
a2b9b85
Fixed a typo
smartcontracts Jun 30, 2020
9b94f0d
Merged master
smartcontracts Jul 1, 2020
2e3fa36
Removed unused imports
smartcontracts Jul 1, 2020
ef6a154
Removed unused variables
smartcontracts Jul 1, 2020
a0c695c
Started reworking test helpers
smartcontracts Jul 1, 2020
5af729c
Clean up test helpers
smartcontracts Jul 2, 2020
0259ab4
Fixed linting errors
smartcontracts Jul 2, 2020
4519577
Support globs in solcover
smartcontracts Jul 6, 2020
5d0c209
Merged master and linted
smartcontracts Jul 6, 2020
753a147
Merge remote-tracking branch 'origin/master' into YAS-467/contracts/c…
smartcontracts Jul 9, 2020
7cc641c
Removed ganache typings entirely
smartcontracts Jul 9, 2020
df9336d
Fixed missing import
smartcontracts Jul 9, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"release:alpha": "yarn clean && yarn build && lerna version prerelease --yes && lerna publish from-package --yes --force-publish --dist-tag=alpha -m \"chore(@ethereum-optimism) publish %s release\"",
"release:beta": "yarn clean && yarn build && lerna version prerelease --yes && lerna publish from-package --yes --force-publish --dist-tag=beta -m \"chore(@ethereum-optimism) publish %s release\"",
"patch": "yarn run patch:ganache && yarn run patch:waffle",
"patch:ganache": "sed -ie 's!import { Provider as Web3Provider } from \"web3/providers\";!import { AbstractProvider as Web3Provider } from \"web3-core\";!' node_modules/ganache-core/typings/index.d.ts",
"patch:ganache": "rm node_modules/ganache-core/typings/index.d.ts ||:",
"patch:waffle": "sed -ie 's!Ganache.GanacheOpts!any!g' node_modules/ethereum-waffle/dist/waffle.d.ts"
},
"repository": "git+https://github.com/ethereum-optimism/optimism-monorepo.git",
Expand Down
5 changes: 5 additions & 0 deletions packages/contracts/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
.coverage_artifacts/
.coverage_cache/
.coverage_contracts/
coverage/
coverage.json
69 changes: 69 additions & 0 deletions packages/contracts/.solcover.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
/**
* SolCover configuration management:
*
* SolCover unfortunately doesn't provide us with the ability to exclusively
* generate coverage reports for a given file. Although we can use the
* `--testfiles`` parameter to limit tests to a particular glob, SolCover will
* still try to generate coverage reports for anything not covered within the
* `skipFiles` option exported below. `skipFiles` additionally does not parse
* globs, creating a mismatch between it and the `--testfiles` option.
*
* To address the above issues, we take the following steps:
* 1. Parse the `--testfiles` option from our command-line arguments.
* 2. Use the `--testfiles` option to find the list of contracts to be tested.
* 3. Find *all* contracts and exclude the results of (2).
* 4. Add the result of (3) to `skipFiles`.
*
* NOTE: The above will *only* work if contract test files follow the
* `<ContractName>.spec.ts` convention. Our function will fail to find the
* correct contracts otherwise.
*/

const path = require('path')
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

General explainer for this file: solcover only gives us the option to skip specific contracts during the instrumentation phase (so we can't explicitly list out the contracts we do want). solcover also doesn't allow us to use globs. This file pulls out the testfiles argument from the coverage script inside package.json and automatically determines the corresponding contract. It then skips all contracts except the corresponding contract.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could consider putting this explainer in as a comment in the file

const glob = require('glob')
const ArgumentParser = require('argparse').ArgumentParser

const parser = new ArgumentParser()
parser.addArgument(
['--testfiles'],
)

/**
* Given a glob, finds all files to skip.
* @param skipFiles Path or glob of files to skip.
* @returns Paths to files to skip.
*/
const parseSkipFiles = (skipFiles) => {
return skipFiles.reduce((files, contract) => {
return files.concat(glob.sync(contract))
}, []).map((contract) => {
return contract.replace('contracts/', '')
})
}

/**
* Given a glob, finds all contracts to skip that are *not* the given files.
* @param includeFiles Path or glob of files not to skip.
* @returns Paths to files to skip.
*/
const parseIncludeFiles = (includeFiles) => {
const allFiles = parseSkipFiles(['contracts/**/*.sol'])
const includedFiles = parseSkipFiles(includeFiles)
return allFiles.filter((file) => {
return !includedFiles.includes(file)
})
}

/**
* Parses command-line arguments and picks out the correct contracts to skip.
*/
const parseTestFiles = () => {
const args = parser.parseKnownArgs()[0]
const testFileName = path.basename(args.testfiles)
const contractFileName = testFileName.split('.')[0] + '.sol'
return parseIncludeFiles(['contracts/**/' + contractFileName])
}

module.exports = {
skipFiles: parseTestFiles()
}
11 changes: 9 additions & 2 deletions packages/contracts/buidler.config.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,24 @@
import * as path from 'path'
import { usePlugin, BuidlerConfig } from '@nomiclabs/buidler/config'

import { DEFAULT_ACCOUNTS_BUIDLER } from './test/test-helpers/constants'
import {
DEFAULT_ACCOUNTS_BUIDLER,
GAS_LIMIT,
} from './test/test-helpers/constants'

usePlugin('@nomiclabs/buidler-ethers')
usePlugin('@nomiclabs/buidler-waffle')
usePlugin('solidity-coverage')

import './plugins/hijack-compiler'

const config: BuidlerConfig = {
networks: {
buidlerevm: {
accounts: DEFAULT_ACCOUNTS_BUIDLER,
blockGasLimit: GAS_LIMIT * 2,
},
coverage: {
url: 'http://localhost:8555',
},
},
}
Expand Down
10 changes: 9 additions & 1 deletion packages/contracts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
"nohoist": [
"**/@nomiclabs",
"**/@nomiclabs/**",
"**/solidity-coverage",
"**/solidity-coverage/**",
"**/typescript",
"**/typescript/**",
"**/ts-node",
Expand All @@ -22,6 +24,8 @@
"all": "yarn clean && yarn build && yarn test && yarn fix && yarn lint",
"test": "yarn run test:contracts",
"test:contracts": "buidler test --show-stack-traces",
"coverage": "yarn run coverage:contracts",
"coverage:contracts": "buidler coverage --network coverage --show-stack-traces --testfiles \"test/contracts/**/*.spec.ts\"",
"build": "yarn run build:contracts && yarn run build:typescript",
"build:contracts": "buidler compile",
"build:typescript": "tsc -p .",
Expand Down Expand Up @@ -52,5 +56,9 @@
"seedrandom": "^3.0.5",
"ts-node": "^8.10.2",
"typescript": "^3.9.5"
},
"devDependencies": {
"glob": "^7.1.6",
"solidity-coverage": "^0.7.9"
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,14 @@ import '../../setup'
/* External Imports */
import { ethers } from '@nomiclabs/buidler'
import { getLogger, sleep, TestUtils } from '@eth-optimism/core-utils'
import { Signer, ContractFactory } from 'ethers'
import { Contract, Signer, ContractFactory } from 'ethers'

/* Internal Imports */
import { TxChainBatch, TxQueueBatch } from '../../test-helpers/rl-helpers'
import { makeRandomBatchOfSize } from '../../test-helpers'
import {
makeRandomBatchOfSize,
TxQueueBatch,
TxChainBatch,
} from '../../test-helpers'

/* Logging */
const log = getLogger('canonical-tx-chain', true)
Expand All @@ -32,10 +35,10 @@ describe('CanonicalTransactionChain', () => {
] = await ethers.getSigners()
})

let canonicalTxChain
let rollupMerkleUtils
let l1ToL2Queue
let safetyQueue
let canonicalTxChain: Contract
let rollupMerkleUtils: Contract
let l1ToL2Queue: Contract
let safetyQueue: Contract

const appendSequencerBatch = async (batch: string[]): Promise<number> => {
const timestamp = Math.floor(Date.now() / 1000)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,13 @@ import { getLogger, TestUtils } from '@eth-optimism/core-utils'
import { Contract, Signer, ContractFactory } from 'ethers'

/* Internal Imports */
import { StateChainBatch, TxChainBatch } from '../../test-helpers/rl-helpers'
import { StateChainBatch, TxChainBatch } from '../../test-helpers'

/* Logging */
const log = getLogger('batch-submitter', true)

/* Tests */
describe('SequencerBatchSubmitter', () => {
const provider = ethers.provider
const DEFAULT_STATE_BATCH = ['0x1234', '0x5678']
const DEFAULT_TX_BATCH = ['0xabcd', '0xef12']
const FORCE_INCLUSION_PERIOD = 600
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ import { getLogger, sleep, TestUtils } from '@eth-optimism/core-utils'
import { Contract, Signer, ContractFactory } from 'ethers'

/* Internal Imports */
import { StateChainBatch } from '../../test-helpers/rl-helpers'
import { makeRandomBatchOfSize } from '../../test-helpers'
import { makeRandomBatchOfSize, StateChainBatch } from '../../test-helpers'

/* Logging */
const log = getLogger('state-commitment-chain', true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,7 @@ import { add0x, getLogger } from '@eth-optimism/core-utils'
import { Contract, Signer, ContractFactory } from 'ethers'

/* Internal Imports */
import {
DEFAULT_OPCODE_WHITELIST_MASK,
GAS_LIMIT,
DEFAULT_ETHNODE_GAS_LIMIT,
} from '../../test-helpers/core-helpers'
import { DEFAULT_OPCODE_WHITELIST_MASK, GAS_LIMIT } from '../../test-helpers'

/* Logging */
const log = getLogger('l2-execution-manager-calls', true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import '../../setup'

/* External Imports */
import { ethers } from '@nomiclabs/buidler'
import { getLogger, TestUtils } from '@eth-optimism/core-utils'
import { getLogger } from '@eth-optimism/core-utils'
import { Contract, ContractFactory, Signer } from 'ethers'

/* Logging */
Expand All @@ -20,7 +20,7 @@ describe('PartialStateManager', () => {
PartialStateManager = await ethers.getContractFactory('PartialStateManager')
})

let partialStateManager
let partialStateManager: Contract
beforeEach(async () => {
partialStateManager = await PartialStateManager.deploy(
await wallet.getAddress(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import '../../setup'

/* External Imports */
import { ethers } from '@nomiclabs/buidler'
import { getLogger, TestUtils } from '@eth-optimism/core-utils'
import { getLogger } from '@eth-optimism/core-utils'
import { Contract, ContractFactory, Signer } from 'ethers'

/* Logging */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,12 @@ import { fromPairs } from 'lodash'

/* Internal Imports */
import {
Address,
GAS_LIMIT,
DEFAULT_OPCODE_WHITELIST_MASK,
DEFAULT_ETHNODE_GAS_LIMIT,
} from '../../../test-helpers/core-helpers'
import {
Address,
manuallyDeployOvmContract,
addressToBytes32Address,
didCreateSucceed,
gasLimit,
encodeMethodId,
encodeRawArguments,
} from '../../../test-helpers'
Expand Down Expand Up @@ -450,7 +446,7 @@ describe('Execution Manager -- Call opcodes', () => {
const receipt = await wallet.sendTransaction({
to: executionManager.address,
data: add0x(data),
gasLimit,
gasLimit: GAS_LIMIT,
})

return receipt.hash
Expand All @@ -477,7 +473,7 @@ describe('Execution Manager -- Call opcodes', () => {
return executionManager.provider.call({
to: executionManager.address,
data,
gasLimit,
gasLimit: GAS_LIMIT,
})
}
})
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,9 @@ import { Contract, ContractFactory, Signer } from 'ethers'

/* Internal Imports */
import {
Address,
GAS_LIMIT,
DEFAULT_OPCODE_WHITELIST_MASK,
DEFAULT_ETHNODE_GAS_LIMIT,
} from '../../../test-helpers/core-helpers'
import {
Address,
manuallyDeployOvmContract,
executeOVMCall,
addressToBytes32Address,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,13 @@ import { fromPairs } from 'lodash'

/* Internal Imports */
import {
Address,
GAS_LIMIT,
DEFAULT_OPCODE_WHITELIST_MASK,
DEFAULT_ETHNODE_GAS_LIMIT,
} from '../../../test-helpers/core-helpers'
import {
Address,
manuallyDeployOvmContract,
addressToBytes32Address,
encodeRawArguments,
encodeMethodId,
gasLimit,
} from '../../../test-helpers'

/* Logging */
Expand Down Expand Up @@ -229,7 +225,7 @@ describe('Execution Manager -- Context opcodes', () => {
return executionManager.provider.call({
to: executionManager.address,
data,
gasLimit,
gasLimit: GAS_LIMIT,
})
}
})
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,6 @@ import { fromPairs } from 'lodash'
import {
DEFAULT_OPCODE_WHITELIST_MASK,
GAS_LIMIT,
DEFAULT_ETHNODE_GAS_LIMIT,
} from '../../../test-helpers/core-helpers'
import {
gasLimit,
executeOVMCall,
encodeMethodId,
encodeRawArguments,
Expand All @@ -31,11 +27,6 @@ const methodIds = fromPairs(

/* Tests */
describe('ExecutionManager -- Create opcodes', () => {
let wallet: Signer
before(async () => {
;[wallet] = await ethers.getSigners()
})

let ExecutionManager: ContractFactory
let SimpleStorage: ContractFactory
let InvalidOpcodes: ContractFactory
Expand Down Expand Up @@ -91,7 +82,7 @@ describe('ExecutionManager -- Create opcodes', () => {
const result = await executionManager.provider.call({
to: safetyCheckedExecutionManager.address,
data,
gasLimit,
gasLimit: GAS_LIMIT,
})

log.debug(`Result: [${result}]`)
Expand All @@ -112,7 +103,7 @@ describe('ExecutionManager -- Create opcodes', () => {
const result = await executionManager.provider.call({
to: executionManager.address,
data,
gasLimit,
gasLimit: GAS_LIMIT,
})

log.debug(`Result: [${result}]`)
Expand All @@ -131,7 +122,7 @@ describe('ExecutionManager -- Create opcodes', () => {
const result = await executionManager.provider.call({
to: safetyCheckedExecutionManager.address,
data,
gasLimit,
gasLimit: GAS_LIMIT,
})

log.debug(`Result: [${result}]`)
Expand Down
Loading