Skip to content

Commit 33bb865

Browse files
committed
add test for fork deploy and read from process.env when using deploy scripts
1 parent 8a85eb4 commit 33bb865

14 files changed

+93
-54
lines changed

.github/workflows/bindings.yml

+14-3
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ concurrency:
1010

1111
jobs:
1212
verify-bindings:
13-
runs-on: ubuntu-latest
13+
runs-on: macos-latest
1414
steps:
1515
- uses: actions/checkout@v4
1616
with:
@@ -23,11 +23,10 @@ jobs:
2323
go-version: "1.21.3"
2424

2525
- name: Setup Foundry
26-
uses: foundry-rs/foundry-toolchain@v1
26+
uses: foundry-rs/foundry-toolchain@v1.2.0
2727

2828
- name: Install Bun
2929
uses: oven-sh/setup-bun@v2
30-
3130
- name: Install ABIGen
3231
run: |
3332
go install github.com/ethereum/go-ethereum/cmd/[email protected]
@@ -44,3 +43,15 @@ jobs:
4443
echo -e "Changes in Generated Bindings:\n$changes"
4544
exit 1
4645
fi
46+
- name: Upload ts bindings artifact on error
47+
if: failure()
48+
uses: actions/upload-artifact@v2
49+
with:
50+
name: ts-bindings
51+
path: ./src/evm/contracts/
52+
- name: Upload go bindings artifact on error
53+
if: failure()
54+
uses: actions/upload-artifact@v2
55+
with:
56+
name: go-bindings
57+
path: ./bindings/

.github/workflows/foundry.yml

+14
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,17 @@ jobs:
2626

2727
- name: Tests
2828
run: forge test --no-match-contract DispatcherDeployTest
29+
30+
- name: Fork Deploy Test
31+
run: npm run build && npx
32+
env:
33+
MODULE_ROOT_PATH: "./"
34+
RPC_URL: ${{ secrets.FORK_RPC_URL }}
35+
CHAIN_NAME: fork-test-ci
36+
DUMMY_DEPLOYER_PRIVATE_KEY: ${{ secrets.DUMMY_DEPLOYER_PRIVATE_KEY }}
37+
DAPP_PRIVATE_KEY_1: ${{ secrets.DAPP_PRIVATE_KEY_1 }}
38+
DAPP_PRIVATE_KEY_2: ${{ secrets.DAPP_PRIVATE_KEY_2 }}
39+
DAPP_PRIVATE_KEY_3: ${{ secrets.DAPP_PRIVATE_KEY_3 }}
40+
PolymerL2OutputOracleProxyAddress: 0xB901B810B30f4d8D179FA5e4dFA73B6EC81f2dB0
41+
L2OutputOracleProxyAddress: 0xB901B810B30f4d8D179FA5e4dFA73B6EC81f2dB0
42+
L1BlockAddress: 0x4200000000000000000000000000000000000015

README.md

+5-5
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ This file is read in-order, so each entry in this file should be in-order, where
5050
### Deploying via Command Line
5151
This npm package exposes two commands - one to deploy new contacts (which automatically creates persisted deployment files), and one to send transactions to contracts from persisted artifact files. The following steps are needed to deploy contracts via the command line:
5252

53-
1. Ensure that your deployer account and constructor arguments are configured. This can either be done through adding contract spec yaml files located in the specs/ from the root of where this npm module is installed from (requires adding a `specs/evm.accounts.yaml` file and either a `specs/contracts.spec.yaml` or `specs/upgrade.spec.yaml`), or by setting the KEY_POLYMER, RPC_URL, DEPLOYMENT_CHAIN_ID, CHAIN_NAME environment variables. For examples of contract and account spec files, see the `/specs` folder in this repo.
53+
1. Ensure that your deployer account and constructor arguments are configured. This can either be done through adding contract spec yaml files located in the specs/ from the root of where this npm module is installed from (requires adding a `specs/evm.accounts.yaml` file and either a `specs/contracts.spec.yaml` or `specs/upgrade.spec.yaml`), or by setting the KEY_DEPLOYER, RPC_URL, DEPLOYMENT_CHAIN_ID, CHAIN_NAME environment variables. For examples of contract and account spec files, see the `/specs` folder in this repo.
5454
2. Pass in optional command arguments:
5555
- RPC_URL - the rpc url to submit deploy txs to, can be a local fork as well
5656
- ACCOUNTS_SPECS_PATH - the path to the accounts spec file
@@ -89,8 +89,8 @@ const accountConfig = {
8989
name: "local",
9090
registry: [
9191
{
92-
name: "KEY_POLYMER",
93-
privateKey: process.env.KEY_POLYMER
92+
name: "KEY_DEPLOYER",
93+
privateKey: process.env.KEY_DEPLOYER
9494
},
9595
],
9696
};
@@ -138,8 +138,8 @@ const accountConfig = {
138138
name: "local",
139139
registry: [
140140
{
141-
name: "KEY_POLYMER",
142-
privateKey: process.env.KEY_POLYMER,
141+
name: "KEY_DEPLOYER",
142+
privateKey: process.env.KEY_DEPLOYER,
143143
},
144144
],
145145
};

bun.lockb

-168 Bytes
Binary file not shown.

specs/contracts.setup.spec.yaml

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
# args: args to make the function call with, need to be compatible with the signature
1111
- name: DispatcherClientSetup-Connection-0
1212
description: 'Setup client for dispatcher contracts'
13-
deployer: 'KEY_POLYMER'
13+
deployer: 'KEY_DEPLOYER'
1414
signature: "setClientForConnection(string,address)"
1515
address: '{{DispatcherProxy}}'
1616
factoryName: "Dispatcher"
@@ -20,7 +20,7 @@
2020

2121
- name: DispatcherClientSetup-Connection-1
2222
description: 'Setup client for dispatcher contracts'
23-
deployer: 'KEY_POLYMER'
23+
deployer: 'KEY_DEPLOYER'
2424
signature: "setClientForConnection(string,address)"
2525
address: '{{DispatcherProxy}}'
2626
factoryName: "Dispatcher"

specs/contracts.spec.yaml

+8-8
Original file line numberDiff line numberDiff line change
@@ -20,17 +20,17 @@
2020
- name: LightClient
2121
description: 'DummyLightClient'
2222
factoryName: 'DummyLightClient'
23-
deployer: 'KEY_POLYMER'
23+
deployer: 'KEY_DEPLOYER'
2424

2525
- name: Ibc
2626
description: 'IBC library'
2727
factoryName: 'Ibc'
28-
deployer: 'KEY_POLYMER'
28+
deployer: 'KEY_DEPLOYER'
2929

3030
- name: IbcUtils
3131
description: 'IBC utils library'
3232
factoryName: 'IbcUtils'
33-
deployer: 'KEY_POLYMER'
33+
deployer: 'KEY_DEPLOYER'
3434

3535
- name: Dispatcher
3636
description: 'IBC Core contract'
@@ -40,12 +40,12 @@
4040
address: '{{Ibc}}'
4141
- name: 'contracts/libs/IbcUtils.sol:IbcUtils'
4242
address: '{{IbcUtils}}'
43-
deployer: 'KEY_POLYMER'
43+
deployer: 'KEY_DEPLOYER'
4444

4545
- name: FeeVault
4646
description: 'FeeVault'
4747
factoryName: 'FeeVault'
48-
deployer: 'KEY_POLYMER'
48+
deployer: 'KEY_DEPLOYER'
4949

5050
- name: DispatcherProxy
5151
description: 'Dispatcher proxy contract'
@@ -58,20 +58,20 @@
5858
args:
5959
- 'polyibc.{{chain.chainName}}.'
6060
- '{{FeeVault}}'
61-
deployer: 'KEY_POLYMER'
61+
deployer: 'KEY_DEPLOYER'
6262

6363
- name: UC
6464
description: 'Universal Chanel IBC-middleware contract'
6565
factoryName: 'UniversalChannelHandler'
66-
deployer: 'KEY_POLYMER'
66+
deployer: 'KEY_DEPLOYER'
6767
libraries:
6868
- name: 'contracts/libs/IbcUtils.sol:IbcUtils'
6969
address: '{{IbcUtils}}'
7070

7171
- name: UCProxy
7272
description: 'Universal Chanel IBC-middleware proxy'
7373
factoryName: 'ERC1967Proxy'
74-
deployer: 'KEY_POLYMER'
74+
deployer: 'KEY_DEPLOYER'
7575
deployArgs:
7676
- '{{UC}}'
7777
- '$INITARGS'

specs/evm.accounts.yaml

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
# These accounts are derived from a test mnemonic by Anvil/Hardhat and used for testing purposes only.
2-
- name: 'KEY_POLYMER'
3-
privateKey: '{{DEPLOYER_PRIVATE_KEY}}'
4-
2+
- name: 'KEY_DEPLOYER'
3+
privateKey: '{{ DUMMY_DEPLOYER_PRIVATE_KEY }}'
54

65
# Dapp accounts
76
- name: 'KEY_DAPP1'
87
privateKey: '{{ DAPP_PRIVATE_KEY_1 }}'
98
- name: 'KEY_DAPP2'
109
privateKey: '{{ DAPP_PRIVATE_KEY_2 }}'
1110
- name: 'KEY_DAPP3'
12-
privateKey: '{{ DAPP_PRIVATE_KEY_2 }}'
11+
privateKey: '{{ DAPP_PRIVATE_KEY_3 }}'

specs/update.spec.yaml

+30-14
Original file line numberDiff line numberDiff line change
@@ -35,20 +35,36 @@
3535
# signature: signature of method to call for this tx
3636
# args: args to make the function call with, need to be compatible with the signature
3737

38-
- name: LightClient
38+
- name: OptimisticProofVerifier
39+
description: 'OptimisticProofVerifier'
40+
factoryName: 'OptimisticProofVerifier'
41+
deployer: 'KEY_DEPLOYER'
42+
deployArgs:
43+
- '{{PolymerL2OutputOracleProxyAddress}}'
44+
45+
- name: OptimisticLightClient
46+
description: 'OptimisticLightClient'
47+
factoryName: 'OptimisticLightClient'
48+
deployer: 'KEY_DEPLOYER'
49+
deployArgs:
50+
- 0
51+
- '{{OptimisticProofVerifier}}'
52+
- '{{L1BlockAddress}}'
53+
54+
- name: DummyLightClient
3955
description: 'DummyLightClient'
4056
factoryName: 'DummyLightClient'
41-
deployer: 'KEY_POLYMER'
57+
deployer: 'KEY_DEPLOYER'
4258

4359
- name: Ibc
4460
description: 'IBC library'
4561
factoryName: 'Ibc'
46-
deployer: 'KEY_POLYMER'
62+
deployer: 'KEY_DEPLOYER'
4763

4864
- name: IbcUtils
4965
description: 'IBC utils library'
5066
factoryName: 'IbcUtils'
51-
deployer: 'KEY_POLYMER'
67+
deployer: 'KEY_DEPLOYER'
5268

5369
- name: Dispatcher
5470
description: 'IBC Core contract'
@@ -58,12 +74,12 @@
5874
address: '{{Ibc}}'
5975
- name: 'contracts/libs/IbcUtils.sol:IbcUtils'
6076
address: '{{IbcUtils}}'
61-
deployer: 'KEY_POLYMER'
77+
deployer: 'KEY_DEPLOYER'
6278

6379
- name: FeeVault
6480
description: 'FeeVault'
6581
factoryName: 'FeeVault'
66-
deployer: 'KEY_POLYMER'
82+
deployer: 'KEY_DEPLOYER'
6783

6884
- name: DispatcherProxy
6985
description: 'Dispatcher proxy contract'
@@ -76,20 +92,20 @@
7692
args:
7793
- 'polyibc.{{chain.chainName}}.'
7894
- '{{FeeVault}}'
79-
deployer: 'KEY_POLYMER'
95+
deployer: 'KEY_DEPLOYER'
8096

8197
- name: UC
8298
description: 'Universal Chanel IBC-middleware contract'
8399
factoryName: 'UniversalChannelHandler'
84-
deployer: 'KEY_POLYMER'
100+
deployer: 'KEY_DEPLOYER'
85101
libraries:
86102
- name: 'contracts/libs/IbcUtils.sol:IbcUtils'
87103
address: '{{IbcUtils}}'
88104

89105
- name: UCProxy
90106
description: 'Universal Chanel IBC-middleware proxy'
91107
factoryName: 'ERC1967Proxy'
92-
deployer: 'KEY_POLYMER'
108+
deployer: 'KEY_DEPLOYER'
93109
deployArgs:
94110
- '{{UC}}'
95111
- '$INITARGS'
@@ -115,7 +131,7 @@
115131
# Contract Setup below
116132
- name: DispatcherUpgrade
117133
description: 'UUPS Upgrade for dispatcher contract implementation'
118-
deployer: 'KEY_POLYMER'
134+
deployer: 'KEY_DEPLOYER'
119135
signature: "upgradeTo(address)"
120136
address: '{{DispatcherProxy}}'
121137
factoryName: "Dispatcher"
@@ -124,7 +140,7 @@
124140

125141
- name: DispatcherUpgrade
126142
description: 'UUPS Upgrade for dispatcher contract implementation'
127-
deployer: 'KEY_POLYMER'
143+
deployer: 'KEY_DEPLOYER'
128144
signature: "upgradeTo(address)"
129145
address: '{{DispatcherProxy}}'
130146
factoryName: "Dispatcher"
@@ -133,7 +149,7 @@
133149

134150
- name: UCH Upgrade
135151
description: 'Upgrade for uch contract'
136-
deployer: 'KEY_POLYMER'
152+
deployer: 'KEY_DEPLOYER'
137153
signature: "upgradeTo(address)"
138154
address: '{{ UCProxy }}'
139155
factoryName: "UC"
@@ -142,7 +158,7 @@
142158

143159
- name: DispatcherClientSetup-Connection-0
144160
description: 'Setup client for dispatcher contracts'
145-
deployer: 'KEY_POLYMER'
161+
deployer: 'KEY_DEPLOYER'
146162
signature: "setClientForConnection(string,address)"
147163
address: '{{DispatcherProxy}}'
148164
factoryName: "Dispatcher"
@@ -152,7 +168,7 @@
152168

153169
- name: DispatcherClientSetup-Connection-1
154170
description: 'Setup client for dispatcher contracts'
155-
deployer: 'KEY_POLYMER'
171+
deployer: 'KEY_DEPLOYER'
156172
signature: "setClientForConnection(string,address)"
157173
address: '{{DispatcherProxy}}'
158174
factoryName: "Dispatcher"

specs/upgrade.spec.yaml

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919
- name: DispatcherUpgrade
2020
description: 'UUPS Upgrade for dispatcher contract implementation'
21-
deployer: 'KEY_POLYMER'
21+
deployer: 'KEY_DEPLOYER'
2222
signature: "upgradeTo(address)"
2323
address: '{{DispatcherProxy}}'
2424
factoryName: "Dispatcher"
@@ -27,7 +27,7 @@
2727

2828
- name: UCH Upgrade
2929
description: 'Upgrade for uch contract'
30-
deployer: 'KEY_POLYMER'
30+
deployer: 'KEY_DEPLOYER'
3131
signature: "upgradeTo(address)"
3232
address: '{{ UCProxy }}'
3333
factoryName: "UC"

src/deploy.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ export async function deployToChain(
187187
}
188188

189189
// @ts-ignore
190-
const env: StringToStringMap = { chain };
190+
const env: StringToStringMap = {...process.env , chain , };
191191
if (!forceDeployNewContracts) {
192192
// Only read from existing contract files if we want to deploy new ones
193193
await readDeploymentFilesIntoEnv(env, chain);

src/scripts/fork-deployment-test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@ const main = async () => {
4444
env = await readDeploymentFilesIntoEnv(env, chain); // Read deployment files from non-forked chain to get live addresses
4545

4646
$.env = {
47-
...env,
4847
...process.env,
48+
...env,
4949
};
5050

5151
await $`cd ${MODULE_ROOT_PATH} && forge test --match-contract DispatcherDeployTest --fork-url ${anvilUrl} -vvvv `.pipe(

src/updateContract.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ export async function updateContractsForChain(
4141

4242
// @ts-ignore
4343
let env = await readDeploymentFilesIntoEnv({}, chain); // Read from existing deployment files first, then overwrite with explicitly given contract addresses
44-
env = { chain, ...existingContractAddresses, ...env };
44+
env = {...process.env, chain, ...existingContractAddresses, ...env };
4545
if (!forceDeployNewContracts) {
4646
// Only read from existing contract files if we want to deploy new ones
4747
await readDeploymentFilesIntoEnv(env, chain);

test/Fork/Dispatcher.deploy.t.sol

+4-5
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ struct ChainAddresses {
4242
IUniversalChannelHandler uch;
4343
ILightClient dummyLightClient;
4444
ILightClient optimisticLightClient;
45-
bytes32 ownerKey; // Owner Address of dispatcher
45+
address owner; // Owner Address of dispatcher
4646
}
4747

4848
contract DispatcherDeployTest is ChannelHandShakeUpgradeUtil, UpgradeTestUtils {
@@ -57,17 +57,16 @@ contract DispatcherDeployTest is ChannelHandShakeUpgradeUtil, UpgradeTestUtils {
5757
IUniversalChannelHandler(vm.envAddress("UCProxy")),
5858
ILightClient(vm.envAddress("DummyLightClient")),
5959
ILightClient(vm.envAddress("OptimisticLightClient")),
60-
vm.envBytes32("OWNER_KEY")
60+
vm.envAddress("OwnerAddress")
6161
);
6262

6363
opLightClient = addresses.optimisticLightClient; // Need to set this so that when we call load_proof, it loads
6464
// the proof to the right address
6565

66-
address owner = vm.addr(uint256(addresses.ownerKey));
6766
mars = Mars(payable(targetMarsAddress));
6867

6968
dispatcherProxy = addresses.dispatcherProxy;
70-
vm.prank(owner);
69+
vm.prank(addresses.owner);
7170

7271
// For now, we need to change the portPrefix to that of the one which was used to generate the proof. We also
7372
// have to set that for the connectionHop to light client mapping.
@@ -80,7 +79,7 @@ contract DispatcherDeployTest is ChannelHandShakeUpgradeUtil, UpgradeTestUtils {
8079
connectionHops0 = ["connection-0", "connection-3"];
8180
connectionHops1 = ["connection-2", "connection-1"];
8281

83-
vm.startPrank(owner); // Only sender should have permission
82+
vm.startPrank(addresses.owner); // Only sender should have permission
8483
dispatcherProxy.setClientForConnection("connection-0", opLightClient);
8584

8685
dispatcherProxy.setClientForConnection("connection-2", opLightClient);

0 commit comments

Comments
 (0)