Skip to content

Commit

Permalink
Merge remote-tracking branch 'template/main' into update-from-template
Browse files Browse the repository at this point in the history
  • Loading branch information
godzillaba committed Jan 14, 2025
2 parents 6f40634 + 3b432ae commit 8eaa50f
Show file tree
Hide file tree
Showing 19 changed files with 174 additions and 121 deletions.
2 changes: 1 addition & 1 deletion .gas-snapshot
Original file line number Diff line number Diff line change
@@ -1 +1 @@
UpgradeArbOSVersionAtTimestampActionTest:test_1() (gas: 165)
UpgradeArbOSVersionAtTimestampActionTest:test_1() (gas: 165)
13 changes: 13 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -84,3 +84,16 @@ jobs:

- run: yarn minimal-install
- run: yarn test:storage

test-unused-errors:
name: Test Unused Errors
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Execute check
uses: OffchainLabs/actions/check-unused-errors@main
with:
directory: './contracts'
exceptions_file: './test/unused-errors/exceptions.txt'
17 changes: 16 additions & 1 deletion audit-ci.jsonc
Original file line number Diff line number Diff line change
@@ -1 +1,16 @@
{}
{
"$schema": "https://github.com/IBM/audit-ci/raw/main/docs/schema.json",
"low": true,
"allowlist": [
// ws affected by a DoS when handling a request with many HTTP headers
"GHSA-3h5v-q93c-6h6q",
// follow-redirects' Proxy-Authorization header kept across hosts
"GHSA-cxjh-pqwp-8mfp",
// Undici's Proxy-Authorization header not cleared on cross-origin redirect for dispatch, request, stream, pipeline
"GHSA-m4v8-wqvr-p9f7",
// Undici's fetch with integrity option is too lax when algorithm is specified but hash value is in incorrect
"GHSA-9qxr-qj54-h672",
// Uncontrolled resource consumption in braces
"GHSA-grv7-fg5c-xmjg"
]
}
16 changes: 16 additions & 0 deletions foundry.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,19 @@ solc_version = '0.8.16'
optimizer_runs = 2000
fs_permissions = [{ access = "read", path = "node_modules/@arbitrum/"}, { access = "read", path = "node_modules/@openzeppelin/"},{ access = "read-write", path = "./scripts/foundry"}]
script = 'scripts'

[fmt]
line_length = 120
tab_width = 4
bracket_spacing = false
int_types = "long"
multiline_func_header = "attributes_first"
quote_style = "double"
number_underscore = "preserve"
hex_underscore = "remove"
single_line_statement_blocks = "preserve"
override_spacing = false
wrap_comments = false
ignore = []
contract_new_lines = false
sort_imports = false
42 changes: 19 additions & 23 deletions hardhat.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,41 +3,37 @@ import '@nomicfoundation/hardhat-toolbox'
import '@nomicfoundation/hardhat-foundry'
import dotenv from 'dotenv'
dotenv.config()
import 'hardhat-contract-sizer'

import { SolidityUserConfig } from 'hardhat/types'
import { SolcUserConfig } from 'hardhat/types'
import toml from 'toml'
import fs from 'fs'

const config: HardhatUserConfig = {
solidity: getSolidityConfigFromFoundryToml(
process.env.FOUNDRY_PROFILE || 'default'
),
solidity: {
...getSolidityConfigFromFoundryToml(process.env.FOUNDRY_PROFILE),
// overrides here
// overrides: {
// 'contracts/MyContract.sol': {
// version: '0.8.0',
// settings: {
// optimizer: {
// enabled: false,
// },
// },
// },
// },
},
networks: {
fork: {
url: process.env.FORK_URL || 'http://localhost:8545',
},
arb1: {
url: 'https://arb1.arbitrum.io/rpc',
},
mainnet: {
url: 'https://mainnet.infura.io/v3/' + process.env['INFURA_KEY'],
},
sepolia: {
url: 'https://sepolia.infura.io/v3/' + process.env['INFURA_KEY'],
},
arbSepolia: {
url: 'https://sepolia-rollup.arbitrum.io/rpc',
},
nova: {
url: 'https://nova.arbitrum.io/rpc',
},
holesky: {
url: 'https://1rpc.io/holesky',
},
},
}

function getSolidityConfigFromFoundryToml(profile: string): SolidityUserConfig {
function getSolidityConfigFromFoundryToml(
profile: string | undefined
): SolcUserConfig {
const data = toml.parse(fs.readFileSync('foundry.toml', 'utf-8'))

const defaultConfig = data.profile['default']
Expand Down
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
"license": "Apache 2.0",
"scripts": {
"prepare": "forge install && cd lib/arbitrum-sdk && yarn",
"minimal-publish": "./scripts/publish.bash",
"minimal-install": "yarn --ignore-scripts && forge install",
"minimal-publish": "./scripts/template/publish.bash",
"audit:ci": "audit-ci --config ./audit-ci.jsonc",
"upload-all-selectors": "forge build && find ./out -name \"*.json\" -exec cast upload-signature {} +",
"format": "cat .prettierignore .gitignore > .pignore && prettier --ignore-path .pignore \"**/*.{js,ts,json}\" --write && rm .pignore && forge fmt",
Expand All @@ -16,7 +16,7 @@
"test:unit": "./test/unit/test-unit.bash",
"test:fork": "./test/fork/test-fork.bash",
"test:e2e": "./test/e2e/test-e2e.bash",
"test:sizes": "forge build --sizes",
"test:sizes": "STRICT=true yarn hardhat size-contracts",
"test:gas-check": "forge snapshot --check --tolerance 1 --match-path \"test/unit/**/*.t.sol\"",
"test:sigs": "./test/signatures/test-sigs.bash",
"test:storage": "./test/storage/test-storage.bash",
Expand Down Expand Up @@ -52,6 +52,7 @@
"ethers": "^6.4.0",
"ethers-v5": "npm:ethers@^5.7.2",
"hardhat": "^2.19.5",
"hardhat-contract-sizer": "^2.10.0",
"hardhat-gas-reporter": "^1.0.8",
"prettier": "^3.2.5",
"solidity-coverage": "^0.8.0",
Expand Down
2 changes: 1 addition & 1 deletion scripts/prepublish.ts → scripts/template/prepublish.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as fs from 'fs'
import hardhatConfig from '../hardhat.config'
import hardhatConfig from '../../hardhat.config'

/*
Generates a minimal package.json and hardhat.config.js for publishing to npm
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion scripts/publish.bash → scripts/template/publish.bash
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

# prepublish
# must run with hardhat to generate hardhat.config.js
yarn hardhat run scripts/prepublish.ts
yarn hardhat run scripts/template/prepublish.ts

if [ $? -ne 0 ]; then
echo "Prepublish failed"
Expand Down
38 changes: 38 additions & 0 deletions scripts/template/util.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import { JsonRpcProvider, Provider, Wallet } from 'ethers'
import { ethers as ethersv5 } from 'ethers-v5'

export type Unwrap<T> = T extends Promise<infer U> ? U : T

export function getEnv(name: string): string {
const value = process.env[name] || ''
if (value === '') {
throw new Error(`Environment variable ${name} is not defined`)
}
return value
}

export class DoubleProvider extends JsonRpcProvider {
public readonly v5: ethersv5.providers.JsonRpcProvider
constructor(public readonly url: string) {
super(url)
this.v5 = new ethersv5.providers.JsonRpcProvider(url)
}
}

export class DoubleWallet extends Wallet {
public readonly provider!: Provider
public readonly v5: ethersv5.Wallet & {
provider: ethersv5.providers.JsonRpcProvider
}

constructor(
privateKey: string,
public readonly doubleProvider: DoubleProvider
) {
super(privateKey, doubleProvider)
this.v5 = new ethersv5.Wallet(
privateKey,
doubleProvider.v5
) as ethersv5.Wallet & { provider: ethersv5.providers.JsonRpcProvider }
}
}
12 changes: 5 additions & 7 deletions test/e2e/test-e2e.bash
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,12 @@ else
export ORBIT_TEST=1
fi

cd lib/arbitrum-sdk && yarn gen:network && cd -
set -e

# if the above command fails, exit
if [ $? -ne 0 ]; then
echo "Failed to generate network"
exit 1
fi
cd lib/arbitrum-sdk && yarn gen:network && cd -

yarn hardhat compile
yarn build

yarn mocha test/e2e/ --timeout 30000000 --bail

exit $?
31 changes: 17 additions & 14 deletions test/e2e/testSetup.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,27 @@
import { JsonRpcProvider, Wallet } from 'ethers'
import { testSetup as sdkTestSetup } from '../../lib/arbitrum-sdk/scripts/testSetup'
import { L1Network, L2Network, getL1Network } from '../../lib/arbitrum-sdk/src'
import { getEnv } from '../util/util'
import {
DoubleProvider,
DoubleWallet,
getEnv,
} from '../../scripts/template/util'

export const isTestingOrbit = process.env.ORBIT_TEST === '1'

type BaseTestSetup = {
l1Network: L1Network
l2Network: L2Network
l1Signer: Wallet
l2Signer: Wallet
l1Provider: JsonRpcProvider
l2Provider: JsonRpcProvider
l1Signer: DoubleWallet
l2Signer: DoubleWallet
l1Provider: DoubleProvider
l2Provider: DoubleProvider
}

export type OrbitTestSetup = BaseTestSetup & {
isTestingOrbit: true
l3Network: L2Network
l3Provider: JsonRpcProvider
l3Signer: Wallet
l3Provider: DoubleProvider
l3Signer: DoubleWallet
}

export type NonOrbitTestSetup = BaseTestSetup & {
Expand All @@ -28,16 +31,16 @@ export type NonOrbitTestSetup = BaseTestSetup & {
export type TestSetup = OrbitTestSetup | NonOrbitTestSetup

export async function testSetup(): Promise<TestSetup> {
const l1Provider = new JsonRpcProvider(getEnv('LOCAL_L1_URL'))
const l2Provider = new JsonRpcProvider(getEnv('LOCAL_L2_URL'))
const l1Signer = new Wallet(getEnv('LOCAL_L1_KEY'), l1Provider)
const l2Signer = new Wallet(getEnv('LOCAL_L2_KEY'), l2Provider)
const l1Provider = new DoubleProvider(getEnv('LOCAL_L1_URL'))
const l2Provider = new DoubleProvider(getEnv('LOCAL_L2_URL'))
const l1Signer = new DoubleWallet(getEnv('LOCAL_L1_KEY'), l1Provider)
const l2Signer = new DoubleWallet(getEnv('LOCAL_L2_KEY'), l2Provider)

const setup = await sdkTestSetup()

if (isTestingOrbit) {
const l3Provider = new JsonRpcProvider(getEnv('LOCAL_L3_URL'))
const l3Signer = new Wallet(getEnv('LOCAL_L3_KEY'), l3Provider)
const l3Provider = new DoubleProvider(getEnv('LOCAL_L3_URL'))
const l3Signer = new DoubleWallet(getEnv('LOCAL_L3_KEY'), l3Provider)

const l1Network = await getL1Network(
(setup.l1Network as L2Network).partnerChainID
Expand Down
50 changes: 6 additions & 44 deletions test/fork/test-fork.bash
Original file line number Diff line number Diff line change
@@ -1,48 +1,10 @@
#!/bin/bash

# run fork tests, tests in fork/<chain_name>/ will be run against <CHAIN_NAME>_FORK_URL
# if there is a chain dir without a corresponding env var, the script will fail
# early exit on failure
set -e

shopt -s globstar
# run hardhat tests if there are any
test $(find test/fork -name '*.test.ts' | wc -l) -eq 0 || yarn hardhat test $(find test/fork -name '*.test.ts')

chains=$(ls -d ./test/fork/*/ 2>/dev/null)

if [ -z "$chains" ]; then
echo "No directories found in ./test/fork/"
exit 0
fi

for dir in $chains; do
dirName=$(basename "$dir")
forkUrlName="${dirName^^}_FORK_URL"
forkUrl="${!forkUrlName}"

if [ -z "$forkUrl" ]; then
echo "No value found for $forkUrlName"
exit 1
fi

code=0

hardhatFiles=$(find "$dir" -name "*.test.ts")
if [ -z "$hardhatFiles" ]; then
echo "No .test.ts files found in $dir"
else
echo "Running hardhat tests against \$$forkUrlName ..."
FORK_URL=$forkUrl yarn run hardhat test $hardhatFiles --network fork
CODE=$?
fi
[ "$code" -ne 0 ] && exit $code

foundryFiles=$(find "$dir" -name "*.t.sol")
if [ -z "$foundryFiles" ]; then
echo "No .t.sol files found in $dir"
else
echo "Running foundry tests against \$$forkUrlName ..."
forge test --fork-url $forkUrl --match-path "$dir**/*.t.sol"
code=$?
fi
[ "$code" -ne 0 ] && exit $code
done

exit 0
# run foundry tests if there are any
test $(find test/fork -name '*.t.sol' | wc -l) -eq 0 || forge test --match-path 'test/fork/**/*.t.sol'
8 changes: 8 additions & 0 deletions test/mocks/SampleMock.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.16;

contract SampleMock {
function arbOSVersion() external pure returns (uint256) {
return 1;
}
}
23 changes: 6 additions & 17 deletions test/unit/test-unit.bash
Original file line number Diff line number Diff line change
@@ -1,21 +1,10 @@
#!/bin/bash

shopt -s globstar
# early exit on failure
set -e

code=0
# run hardhat tests if there are any
test $(find test/unit -name '*.test.ts' | wc -l) -eq 0 || yarn hardhat test $(find test/unit -name '*.test.ts')

hardhatFiles=$(ls ./test/unit/**/*.test.ts 2>/dev/null)
if [ -n "$hardhatFiles" ]; then
yarn run hardhat test $hardhatFiles
code=$?
fi

[ "$code" -ne 0 ] && exit $code

foundryFiles=$(ls ./test/unit/**/*.t.sol 2>/dev/null)
if [ -n "$foundryFiles" ]; then
forge test --match-path "test/unit/*.t.sol"
code=$?
fi

exit $code
# run foundry tests if there are any
test $(find test/unit -name '*.t.sol' | wc -l) -eq 0 || forge test --match-path 'test/unit/**/*.t.sol'
Empty file.
2 changes: 1 addition & 1 deletion test/util/forge-inspect.bash
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

# usage: ./test/util/forge-inspect.bash <outputDir> <inspectType>

contracts=$(./scripts/print-contracts.bash)
contracts=$(./scripts/template/print-contracts.bash)
if [[ $? != "0" ]]; then
echo "Failed to get contracts"
exit 1
Expand Down
9 changes: 0 additions & 9 deletions test/util/util.ts

This file was deleted.

Loading

0 comments on commit 8eaa50f

Please sign in to comment.