Skip to content

Commit

Permalink
init: integration tests (ethereum-optimism#344)
Browse files Browse the repository at this point in the history
Co-authored-by: Javed Khan <tuxcanfly@gmail.com>
  • Loading branch information
mslipper and tuxcanfly authored Apr 8, 2022
1 parent 493def3 commit 39fe50a
Show file tree
Hide file tree
Showing 21 changed files with 9,772 additions and 5 deletions.
39 changes: 39 additions & 0 deletions .github/workflows/devnet-ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
name: Devnet integration tests

on:
push:
branches:
- 'main'
- 'staging'
- 'feat/*'
pull_request:
workflow_dispatch:

jobs:
compose-devnet:
runs-on: ubuntu-latest
name: Run integration tests on devnet
steps:
- uses: actions/checkout@v2
with:
submodules: recursive

- uses: actions/setup-node@v2
with:
node-version: '14'
cache: 'yarn'

- run: |
curl -L -o /tmp/foundry.tgz https://github.com/gakonst/foundry/releases/download/nightly-9c2469488c6872e5d17198555f7d8e1a80173151/foundry_nightly_linux_amd64.tar.gz
tar -xzvf /tmp/foundry.tgz
mv forge /usr/local/bin
mv cast /usr/local/bin
name: Install forge
- run: cd packages/contracts && yarn install && yarn build
- run: cd packages/integration-tests && yarn install && yarn build:contracts

- run: make devnet-up
name: Bring up the stack

- run: sleep 10 && docker ps && make integration-tests
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,7 @@ bin

# vim swap files
*.sw*

integration-tests/cache/
integration-tests/artifacts/
**/*.env
19 changes: 18 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
COMPOSEFLAGS=-d
ITESTS_L2_HOST=http://localhost:9545

build: submodules opnode contracts
.PHONY: build

Expand Down Expand Up @@ -41,9 +44,23 @@ devnet-up:
L1_BLOCK_INFO_BYTECODE=$(shell cat ./packages/contracts/artifacts/contracts/L2/L1Block.sol/L1Block.json | jq .deployedBytecode) \
WITHDRAWER_BYTECODE=$(shell cat ./packages/contracts/artifacts/contracts/L2/Withdrawer.sol/Withdrawer.json | jq .deployedBytecode) \
GENESIS_TIMESTAMP=$(shell date +%s) \
BUILDKIT_PROGRESS=plain DOCKER_BUILDKIT=1 docker-compose up --build)
BUILDKIT_PROGRESS=plain DOCKER_BUILDKIT=1 docker-compose up --build $(COMPOSEFLAGS))
.PHONY: devnet-up

devnet-down:
@(cd ./ops && docker-compose down -v)
.PHONY: devnet-stop

integration-tests:
curl \
--fail \
--retry 10 \
--retry-delay 2 \
--retry-connrefused \
-X POST \
-H "Content-Type: application/json" \
--data '{"jsonrpc":"2.0","method":"eth_getBlockByNumber","params":["0x0", false],"id":1}' \
$(ITESTS_L2_HOST)

cd packages/integration-tests && yarn test
.PHONY: integration-tests
9 changes: 7 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ Note that you will need to specify the L2 chain ID manually if you use Metamask.

The devnet comes with a pre-funded account you can use as a faucet:

- Address: `0xde3829a23df1479438622a08a116e8eb3f620bb5`
- Private key: `bf7604d9d3a1c7748642b1b7b05c2bd219c9faa91458b370f85e5a40f3b03af7`
- Address: `0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266`
- Private key: `ac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80`

The faucet account exists on both L1 and L2. To deposit onto L2 from L1, you can use the `deposit` hardhat task.
Run the following from the `packags/contracts` directory:
Expand All @@ -53,6 +53,11 @@ L2_PROVIDER_URL=http://localhost:8546
PRIVATE_KEY=bf7604d9d3a1c7748642b1b7b05c2bd219c9faa91458b370f85e5a40f3b03af7
```
The batch submitter uses the account below to submit batches to L1:
- Address: `0xde3829a23df1479438622a08a116e8eb3f620bb5`
- Private key: `bf7604d9d3a1c7748642b1b7b05c2bd219c9faa91458b370f85e5a40f3b03af7`
## Contributing
### Basic Contributions
Expand Down
5 changes: 4 additions & 1 deletion ops/genesis-l1.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"nonce": "0x0",
"timestamp": "",
"extraData": "0x0000000000000000000000000000000000000000000000000000000000000000ca062b0fd91172d89bcd4bb084ac4e21972cc4670000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
"gasLimit": "0x47b760",
"gasLimit": "0xE4E1C0",
"difficulty": "0x1",
"mixHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
"coinbase": "0x0000000000000000000000000000000000000000",
Expand Down Expand Up @@ -796,6 +796,9 @@
"de3829a23df1479438622a08a116e8eb3f620bb5": {
"balance": "0x200000000000000000000000000000000000000000000000000000000000000"
},
"f39fd6e51aad88f6f4ce6ab8827279cfffb92266": {
"balance": "0x200000000000000000000000000000000000000000000000000000000000000"
},
"deaddeaddeaddeaddeaddeaddeaddeaddead0001": {
"code": "",
"balance": "0x0"
Expand Down
5 changes: 4 additions & 1 deletion ops/genesis-l2.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"nonce": "0x1234",
"timestamp": "",
"extraData": "0x",
"gasLimit": "0x4c4b40",
"gasLimit": "0xE4E1C0",
"difficulty": "0x1",
"mixHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
"coinbase": "0x0000000000000000000000000000000000000000",
Expand Down Expand Up @@ -794,6 +794,9 @@
"de3829a23df1479438622a08a116e8eb3f620bb5": {
"balance": "0x200000000000000000000000000000000000000000000000000000000000000"
},
"f39fd6e51aad88f6f4ce6ab8827279cfffb92266": {
"balance": "0x200000000000000000000000000000000000000000000000000000000000000"
},
"4200000000000000000000000000000000000014": {
"code": "",
"balance": "0x0"
Expand Down
2 changes: 2 additions & 0 deletions packages/integration-tests/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
artifacts
cache
15 changes: 15 additions & 0 deletions packages/integration-tests/contracts/Counter.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
pragma solidity ^0.8.10;

contract Counter {
uint256 public value = 0;

constructor() {}

function getValue() public view returns (uint256) {
return value;
}

function incValue() public {
value++;
}
}
72 changes: 72 additions & 0 deletions packages/integration-tests/contracts/ERC20.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.9;

contract ERC20 {
event Transfer(address indexed _from, address indexed _to, uint256 _value);
event Approval(address indexed _owner, address indexed _spender, uint256 _value);

uint256 constant private MAX_UINT256 = 2**256 - 1;
mapping (address => uint256) public balances;
mapping (address => mapping (address => uint256)) public allowed;
/*
NOTE:
The following variables are OPTIONAL vanities. One does not have to include them.
They allow one to customise the token contract & in no way influences the core functionality.
Some wallets/interfaces might not even bother to look at this information.
*/
string public name; //fancy name: eg OVM Coin
uint8 public decimals; //How many decimals to show.
string public symbol; //An identifier: eg OVM
uint256 public totalSupply;

constructor(
uint256 _initialAmount,
string memory _tokenName,
uint8 _decimalUnits,
string memory _tokenSymbol
) public {
balances[msg.sender] = _initialAmount; // Give the creator all initial tokens
totalSupply = _initialAmount; // Update total supply
name = _tokenName; // Set the name for display purposes
decimals = _decimalUnits; // Amount of decimals for display purposes
symbol = _tokenSymbol; // Set the symbol for display purposes
}

function transfer(address _to, uint256 _value) public returns (bool success) {
require(balances[msg.sender] >= _value, "insufficient balance");
balances[msg.sender] -= _value;
balances[_to] += _value;
emit Transfer(msg.sender, _to, _value);
return true;
}

function transferFrom(address _from, address _to, uint256 _value) public returns (bool success) {
uint256 allowance = allowed[_from][msg.sender];
require(balances[_from] >= _value && allowance >= _value, "bad allowance");
balances[_to] += _value;
balances[_from] -= _value;
if (allowance < MAX_UINT256) {
allowed[_from][msg.sender] -= _value;
}
emit Transfer(_from, _to, _value);
return true;
}

function balanceOf(address _owner) public view returns (uint256 balance) {
return balances[_owner];
}

function approve(address _spender, uint256 _value) public returns (bool success) {
allowed[msg.sender][_spender] = _value;
emit Approval(msg.sender, _spender, _value);
return true;
}

function allowance(address _owner, address _spender) public view returns (uint256 remaining) {
return allowed[_owner][_spender];
}

function destroy() public {
selfdestruct(payable(msg.sender));
}
}
27 changes: 27 additions & 0 deletions packages/integration-tests/contracts/MultiDepositor.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
pragma solidity 0.8.10;

interface DepositFeed {
function depositTransaction(
address _to,
uint256 _value,
uint256 _gasLimit,
bool _isCreation,
bytes memory _data
) external payable;
}

contract MultiDepositor {
DepositFeed df = DepositFeed(0xDeaDDEaDDeAdDeAdDEAdDEaddeAddEAdDEAd0001);

function deposit(address to) external payable {
for (uint i = 0; i < 3; i++) {
df.depositTransaction{ value: 1000000000 }(
to,
1000,
3000000,
false,
""
);
}
}
}
9 changes: 9 additions & 0 deletions packages/integration-tests/contracts/Reverter.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
pragma solidity 0.8.10;

contract Reverter {
string constant public revertMessage = "This is a simple reversion.";

function doRevert() public pure {
revert(revertMessage);
}
}
70 changes: 70 additions & 0 deletions packages/integration-tests/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
{
"private": true,
"name": "@eth-optimism/integration-tests",
"version": "0.5.9",
"description": "[Optimism] Integration tests",
"scripts": {
"lint": "yarn lint:fix && yarn lint:check",
"lint:fix": "yarn lint:check --fix",
"lint:check": "eslint . --max-warnings=0",
"build:contracts": "forge build --root . -c contracts -o artifacts",
"test": "ts-mocha --timeout 30000 test/**/*.spec.ts",
"test:actor": "IS_LIVE_NETWORK=true ts-node actor-tests/lib/runner.ts",
"test:integration:live": "NO_NETWORK=true IS_LIVE_NETWORK=true hardhat --network optimism test",
"clean": "rimraf cache artifacts",
"pre-commit": "lint-staged"
},
"keywords": [
"optimism",
"ethereum",
"integration",
"tests"
],
"homepage": "https://github.com/ethereum-optimism/optimism/tree/develop/packages/integration-tests#readme",
"license": "MIT",
"author": "Optimism PBC",
"repository": {
"type": "git",
"url": "https://github.com/ethereum-optimism/optimism.git"
},
"devDependencies": {
"@eth-optimism/contracts": "0.5.20",
"@eth-optimism/core-utils": "0.8.3",
"@eth-optimism/sdk": "1.0.4",
"@ethersproject/abstract-provider": "^5.5.1",
"@ethersproject/providers": "^5.5.3",
"@ethersproject/transactions": "^5.5.0",
"@types/chai": "^4.2.18",
"@types/chai-as-promised": "^7.1.4",
"@types/mocha": "^8.2.2",
"@types/rimraf": "^3.0.0",
"@typescript-eslint/eslint-plugin": "^4.26.0",
"@typescript-eslint/parser": "^4.26.0",
"async-mutex": "^0.3.2",
"babel-eslint": "^10.1.0",
"chai": "^4.3.4",
"chai-as-promised": "^7.1.1",
"commander": "^8.3.0",
"dotenv": "^10.0.0",
"envalid": "^7.1.0",
"eslint": "^7.27.0",
"eslint-config-prettier": "^8.3.0",
"eslint-plugin-import": "^2.23.4",
"eslint-plugin-jsdoc": "^35.1.2",
"eslint-plugin-prefer-arrow": "^1.2.3",
"eslint-plugin-prettier": "^3.4.0",
"eslint-plugin-react": "^7.24.0",
"eslint-plugin-unicorn": "^32.0.1",
"ethereum-waffle": "^3.3.0",
"ethers": "^5.5.4",
"mocha": "^8.4.0",
"node-fetch": "^2.6.7",
"prom-client": "^14.0.1",
"rimraf": "^3.0.2",
"ts-node": "^10.7.0",
"typescript": "^4.3.5"
},
"dependencies": {
"ts-mocha": "^9.0.2"
}
}
Loading

0 comments on commit 39fe50a

Please sign in to comment.