Skip to content

Commit 8eaa50f

Browse files
committed
Merge remote-tracking branch 'template/main' into update-from-template
2 parents 6f40634 + 3b432ae commit 8eaa50f

File tree

19 files changed

+174
-121
lines changed

19 files changed

+174
-121
lines changed

.gas-snapshot

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
UpgradeArbOSVersionAtTimestampActionTest:test_1() (gas: 165)
1+
UpgradeArbOSVersionAtTimestampActionTest:test_1() (gas: 165)

.github/workflows/test.yml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,3 +84,16 @@ jobs:
8484

8585
- run: yarn minimal-install
8686
- run: yarn test:storage
87+
88+
test-unused-errors:
89+
name: Test Unused Errors
90+
runs-on: ubuntu-latest
91+
steps:
92+
- name: Checkout
93+
uses: actions/checkout@v4
94+
95+
- name: Execute check
96+
uses: OffchainLabs/actions/check-unused-errors@main
97+
with:
98+
directory: './contracts'
99+
exceptions_file: './test/unused-errors/exceptions.txt'

audit-ci.jsonc

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,16 @@
1-
{}
1+
{
2+
"$schema": "https://github.com/IBM/audit-ci/raw/main/docs/schema.json",
3+
"low": true,
4+
"allowlist": [
5+
// ws affected by a DoS when handling a request with many HTTP headers
6+
"GHSA-3h5v-q93c-6h6q",
7+
// follow-redirects' Proxy-Authorization header kept across hosts
8+
"GHSA-cxjh-pqwp-8mfp",
9+
// Undici's Proxy-Authorization header not cleared on cross-origin redirect for dispatch, request, stream, pipeline
10+
"GHSA-m4v8-wqvr-p9f7",
11+
// Undici's fetch with integrity option is too lax when algorithm is specified but hash value is in incorrect
12+
"GHSA-9qxr-qj54-h672",
13+
// Uncontrolled resource consumption in braces
14+
"GHSA-grv7-fg5c-xmjg"
15+
]
16+
}

foundry.toml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,19 @@ solc_version = '0.8.16'
88
optimizer_runs = 2000
99
fs_permissions = [{ access = "read", path = "node_modules/@arbitrum/"}, { access = "read", path = "node_modules/@openzeppelin/"},{ access = "read-write", path = "./scripts/foundry"}]
1010
script = 'scripts'
11+
12+
[fmt]
13+
line_length = 120
14+
tab_width = 4
15+
bracket_spacing = false
16+
int_types = "long"
17+
multiline_func_header = "attributes_first"
18+
quote_style = "double"
19+
number_underscore = "preserve"
20+
hex_underscore = "remove"
21+
single_line_statement_blocks = "preserve"
22+
override_spacing = false
23+
wrap_comments = false
24+
ignore = []
25+
contract_new_lines = false
26+
sort_imports = false

hardhat.config.ts

Lines changed: 19 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -3,41 +3,37 @@ import '@nomicfoundation/hardhat-toolbox'
33
import '@nomicfoundation/hardhat-foundry'
44
import dotenv from 'dotenv'
55
dotenv.config()
6+
import 'hardhat-contract-sizer'
67

7-
import { SolidityUserConfig } from 'hardhat/types'
8+
import { SolcUserConfig } from 'hardhat/types'
89
import toml from 'toml'
910
import fs from 'fs'
1011

1112
const config: HardhatUserConfig = {
12-
solidity: getSolidityConfigFromFoundryToml(
13-
process.env.FOUNDRY_PROFILE || 'default'
14-
),
13+
solidity: {
14+
...getSolidityConfigFromFoundryToml(process.env.FOUNDRY_PROFILE),
15+
// overrides here
16+
// overrides: {
17+
// 'contracts/MyContract.sol': {
18+
// version: '0.8.0',
19+
// settings: {
20+
// optimizer: {
21+
// enabled: false,
22+
// },
23+
// },
24+
// },
25+
// },
26+
},
1527
networks: {
1628
fork: {
1729
url: process.env.FORK_URL || 'http://localhost:8545',
1830
},
19-
arb1: {
20-
url: 'https://arb1.arbitrum.io/rpc',
21-
},
22-
mainnet: {
23-
url: 'https://mainnet.infura.io/v3/' + process.env['INFURA_KEY'],
24-
},
25-
sepolia: {
26-
url: 'https://sepolia.infura.io/v3/' + process.env['INFURA_KEY'],
27-
},
28-
arbSepolia: {
29-
url: 'https://sepolia-rollup.arbitrum.io/rpc',
30-
},
31-
nova: {
32-
url: 'https://nova.arbitrum.io/rpc',
33-
},
34-
holesky: {
35-
url: 'https://1rpc.io/holesky',
36-
},
3731
},
3832
}
3933

40-
function getSolidityConfigFromFoundryToml(profile: string): SolidityUserConfig {
34+
function getSolidityConfigFromFoundryToml(
35+
profile: string | undefined
36+
): SolcUserConfig {
4137
const data = toml.parse(fs.readFileSync('foundry.toml', 'utf-8'))
4238

4339
const defaultConfig = data.profile['default']

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
"license": "Apache 2.0",
66
"scripts": {
77
"prepare": "forge install && cd lib/arbitrum-sdk && yarn",
8-
"minimal-publish": "./scripts/publish.bash",
98
"minimal-install": "yarn --ignore-scripts && forge install",
9+
"minimal-publish": "./scripts/template/publish.bash",
1010
"audit:ci": "audit-ci --config ./audit-ci.jsonc",
1111
"upload-all-selectors": "forge build && find ./out -name \"*.json\" -exec cast upload-signature {} +",
1212
"format": "cat .prettierignore .gitignore > .pignore && prettier --ignore-path .pignore \"**/*.{js,ts,json}\" --write && rm .pignore && forge fmt",
@@ -16,7 +16,7 @@
1616
"test:unit": "./test/unit/test-unit.bash",
1717
"test:fork": "./test/fork/test-fork.bash",
1818
"test:e2e": "./test/e2e/test-e2e.bash",
19-
"test:sizes": "forge build --sizes",
19+
"test:sizes": "STRICT=true yarn hardhat size-contracts",
2020
"test:gas-check": "forge snapshot --check --tolerance 1 --match-path \"test/unit/**/*.t.sol\"",
2121
"test:sigs": "./test/signatures/test-sigs.bash",
2222
"test:storage": "./test/storage/test-storage.bash",
@@ -52,6 +52,7 @@
5252
"ethers": "^6.4.0",
5353
"ethers-v5": "npm:ethers@^5.7.2",
5454
"hardhat": "^2.19.5",
55+
"hardhat-contract-sizer": "^2.10.0",
5556
"hardhat-gas-reporter": "^1.0.8",
5657
"prettier": "^3.2.5",
5758
"solidity-coverage": "^0.8.0",

scripts/prepublish.ts renamed to scripts/template/prepublish.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import * as fs from 'fs'
2-
import hardhatConfig from '../hardhat.config'
2+
import hardhatConfig from '../../hardhat.config'
33

44
/*
55
Generates a minimal package.json and hardhat.config.js for publishing to npm
File renamed without changes.

scripts/publish.bash renamed to scripts/template/publish.bash

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
# prepublish
1010
# must run with hardhat to generate hardhat.config.js
11-
yarn hardhat run scripts/prepublish.ts
11+
yarn hardhat run scripts/template/prepublish.ts
1212

1313
if [ $? -ne 0 ]; then
1414
echo "Prepublish failed"

scripts/template/util.ts

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import { JsonRpcProvider, Provider, Wallet } from 'ethers'
2+
import { ethers as ethersv5 } from 'ethers-v5'
3+
4+
export type Unwrap<T> = T extends Promise<infer U> ? U : T
5+
6+
export function getEnv(name: string): string {
7+
const value = process.env[name] || ''
8+
if (value === '') {
9+
throw new Error(`Environment variable ${name} is not defined`)
10+
}
11+
return value
12+
}
13+
14+
export class DoubleProvider extends JsonRpcProvider {
15+
public readonly v5: ethersv5.providers.JsonRpcProvider
16+
constructor(public readonly url: string) {
17+
super(url)
18+
this.v5 = new ethersv5.providers.JsonRpcProvider(url)
19+
}
20+
}
21+
22+
export class DoubleWallet extends Wallet {
23+
public readonly provider!: Provider
24+
public readonly v5: ethersv5.Wallet & {
25+
provider: ethersv5.providers.JsonRpcProvider
26+
}
27+
28+
constructor(
29+
privateKey: string,
30+
public readonly doubleProvider: DoubleProvider
31+
) {
32+
super(privateKey, doubleProvider)
33+
this.v5 = new ethersv5.Wallet(
34+
privateKey,
35+
doubleProvider.v5
36+
) as ethersv5.Wallet & { provider: ethersv5.providers.JsonRpcProvider }
37+
}
38+
}

test/e2e/test-e2e.bash

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,12 @@ else
1212
export ORBIT_TEST=1
1313
fi
1414

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

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

23-
yarn hardhat compile
19+
yarn build
2420

2521
yarn mocha test/e2e/ --timeout 30000000 --bail
22+
23+
exit $?

test/e2e/testSetup.ts

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,27 @@
1-
import { JsonRpcProvider, Wallet } from 'ethers'
21
import { testSetup as sdkTestSetup } from '../../lib/arbitrum-sdk/scripts/testSetup'
32
import { L1Network, L2Network, getL1Network } from '../../lib/arbitrum-sdk/src'
4-
import { getEnv } from '../util/util'
3+
import {
4+
DoubleProvider,
5+
DoubleWallet,
6+
getEnv,
7+
} from '../../scripts/template/util'
58

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

811
type BaseTestSetup = {
912
l1Network: L1Network
1013
l2Network: L2Network
11-
l1Signer: Wallet
12-
l2Signer: Wallet
13-
l1Provider: JsonRpcProvider
14-
l2Provider: JsonRpcProvider
14+
l1Signer: DoubleWallet
15+
l2Signer: DoubleWallet
16+
l1Provider: DoubleProvider
17+
l2Provider: DoubleProvider
1518
}
1619

1720
export type OrbitTestSetup = BaseTestSetup & {
1821
isTestingOrbit: true
1922
l3Network: L2Network
20-
l3Provider: JsonRpcProvider
21-
l3Signer: Wallet
23+
l3Provider: DoubleProvider
24+
l3Signer: DoubleWallet
2225
}
2326

2427
export type NonOrbitTestSetup = BaseTestSetup & {
@@ -28,16 +31,16 @@ export type NonOrbitTestSetup = BaseTestSetup & {
2831
export type TestSetup = OrbitTestSetup | NonOrbitTestSetup
2932

3033
export async function testSetup(): Promise<TestSetup> {
31-
const l1Provider = new JsonRpcProvider(getEnv('LOCAL_L1_URL'))
32-
const l2Provider = new JsonRpcProvider(getEnv('LOCAL_L2_URL'))
33-
const l1Signer = new Wallet(getEnv('LOCAL_L1_KEY'), l1Provider)
34-
const l2Signer = new Wallet(getEnv('LOCAL_L2_KEY'), l2Provider)
34+
const l1Provider = new DoubleProvider(getEnv('LOCAL_L1_URL'))
35+
const l2Provider = new DoubleProvider(getEnv('LOCAL_L2_URL'))
36+
const l1Signer = new DoubleWallet(getEnv('LOCAL_L1_KEY'), l1Provider)
37+
const l2Signer = new DoubleWallet(getEnv('LOCAL_L2_KEY'), l2Provider)
3538

3639
const setup = await sdkTestSetup()
3740

3841
if (isTestingOrbit) {
39-
const l3Provider = new JsonRpcProvider(getEnv('LOCAL_L3_URL'))
40-
const l3Signer = new Wallet(getEnv('LOCAL_L3_KEY'), l3Provider)
42+
const l3Provider = new DoubleProvider(getEnv('LOCAL_L3_URL'))
43+
const l3Signer = new DoubleWallet(getEnv('LOCAL_L3_KEY'), l3Provider)
4144

4245
const l1Network = await getL1Network(
4346
(setup.l1Network as L2Network).partnerChainID

test/fork/test-fork.bash

Lines changed: 6 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,10 @@
11
#!/bin/bash
22

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

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

8-
chains=$(ls -d ./test/fork/*/ 2>/dev/null)
9-
10-
if [ -z "$chains" ]; then
11-
echo "No directories found in ./test/fork/"
12-
exit 0
13-
fi
14-
15-
for dir in $chains; do
16-
dirName=$(basename "$dir")
17-
forkUrlName="${dirName^^}_FORK_URL"
18-
forkUrl="${!forkUrlName}"
19-
20-
if [ -z "$forkUrl" ]; then
21-
echo "No value found for $forkUrlName"
22-
exit 1
23-
fi
24-
25-
code=0
26-
27-
hardhatFiles=$(find "$dir" -name "*.test.ts")
28-
if [ -z "$hardhatFiles" ]; then
29-
echo "No .test.ts files found in $dir"
30-
else
31-
echo "Running hardhat tests against \$$forkUrlName ..."
32-
FORK_URL=$forkUrl yarn run hardhat test $hardhatFiles --network fork
33-
CODE=$?
34-
fi
35-
[ "$code" -ne 0 ] && exit $code
36-
37-
foundryFiles=$(find "$dir" -name "*.t.sol")
38-
if [ -z "$foundryFiles" ]; then
39-
echo "No .t.sol files found in $dir"
40-
else
41-
echo "Running foundry tests against \$$forkUrlName ..."
42-
forge test --fork-url $forkUrl --match-path "$dir**/*.t.sol"
43-
code=$?
44-
fi
45-
[ "$code" -ne 0 ] && exit $code
46-
done
47-
48-
exit 0
9+
# run foundry tests if there are any
10+
test $(find test/fork -name '*.t.sol' | wc -l) -eq 0 || forge test --match-path 'test/fork/**/*.t.sol'

test/mocks/SampleMock.sol

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// SPDX-License-Identifier: MIT
2+
pragma solidity ^0.8.16;
3+
4+
contract SampleMock {
5+
function arbOSVersion() external pure returns (uint256) {
6+
return 1;
7+
}
8+
}

test/unit/test-unit.bash

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,10 @@
11
#!/bin/bash
22

3-
shopt -s globstar
3+
# early exit on failure
4+
set -e
45

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

7-
hardhatFiles=$(ls ./test/unit/**/*.test.ts 2>/dev/null)
8-
if [ -n "$hardhatFiles" ]; then
9-
yarn run hardhat test $hardhatFiles
10-
code=$?
11-
fi
12-
13-
[ "$code" -ne 0 ] && exit $code
14-
15-
foundryFiles=$(ls ./test/unit/**/*.t.sol 2>/dev/null)
16-
if [ -n "$foundryFiles" ]; then
17-
forge test --match-path "test/unit/*.t.sol"
18-
code=$?
19-
fi
20-
21-
exit $code
9+
# run foundry tests if there are any
10+
test $(find test/unit -name '*.t.sol' | wc -l) -eq 0 || forge test --match-path 'test/unit/**/*.t.sol'

test/unused-errors/exceptions.txt

Whitespace-only changes.

test/util/forge-inspect.bash

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

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

5-
contracts=$(./scripts/print-contracts.bash)
5+
contracts=$(./scripts/template/print-contracts.bash)
66
if [[ $? != "0" ]]; then
77
echo "Failed to get contracts"
88
exit 1

test/util/util.ts

Lines changed: 0 additions & 9 deletions
This file was deleted.

0 commit comments

Comments
 (0)