Skip to content

Commit

Permalink
add test for fork deploy and read from process.env when using deploy …
Browse files Browse the repository at this point in the history
…scripts
  • Loading branch information
RnkSngh committed Jul 29, 2024
1 parent 8a85eb4 commit 33bb865
Show file tree
Hide file tree
Showing 14 changed files with 93 additions and 54 deletions.
17 changes: 14 additions & 3 deletions .github/workflows/bindings.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ concurrency:

jobs:
verify-bindings:
runs-on: ubuntu-latest
runs-on: macos-latest
steps:
- uses: actions/checkout@v4
with:
Expand All @@ -23,11 +23,10 @@ jobs:
go-version: "1.21.3"

- name: Setup Foundry
uses: foundry-rs/foundry-toolchain@v1
uses: foundry-rs/foundry-toolchain@v1.2.0

- name: Install Bun
uses: oven-sh/setup-bun@v2

- name: Install ABIGen
run: |
go install github.com/ethereum/go-ethereum/cmd/abigen@v1.13.5
Expand All @@ -44,3 +43,15 @@ jobs:
echo -e "Changes in Generated Bindings:\n$changes"
exit 1
fi
- name: Upload ts bindings artifact on error
if: failure()
uses: actions/upload-artifact@v2
with:
name: ts-bindings
path: ./src/evm/contracts/
- name: Upload go bindings artifact on error
if: failure()
uses: actions/upload-artifact@v2
with:
name: go-bindings
path: ./bindings/
14 changes: 14 additions & 0 deletions .github/workflows/foundry.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,17 @@ jobs:

- name: Tests
run: forge test --no-match-contract DispatcherDeployTest

- name: Fork Deploy Test
run: npm run build && npx
env:
MODULE_ROOT_PATH: "./"
RPC_URL: ${{ secrets.FORK_RPC_URL }}
CHAIN_NAME: fork-test-ci
DUMMY_DEPLOYER_PRIVATE_KEY: ${{ secrets.DUMMY_DEPLOYER_PRIVATE_KEY }}
DAPP_PRIVATE_KEY_1: ${{ secrets.DAPP_PRIVATE_KEY_1 }}
DAPP_PRIVATE_KEY_2: ${{ secrets.DAPP_PRIVATE_KEY_2 }}
DAPP_PRIVATE_KEY_3: ${{ secrets.DAPP_PRIVATE_KEY_3 }}
PolymerL2OutputOracleProxyAddress: 0xB901B810B30f4d8D179FA5e4dFA73B6EC81f2dB0
L2OutputOracleProxyAddress: 0xB901B810B30f4d8D179FA5e4dFA73B6EC81f2dB0
L1BlockAddress: 0x4200000000000000000000000000000000000015
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ This file is read in-order, so each entry in this file should be in-order, where
### Deploying via Command Line
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:

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.
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.
2. Pass in optional command arguments:
- RPC_URL - the rpc url to submit deploy txs to, can be a local fork as well
- ACCOUNTS_SPECS_PATH - the path to the accounts spec file
Expand Down Expand Up @@ -89,8 +89,8 @@ const accountConfig = {
name: "local",
registry: [
{
name: "KEY_POLYMER",
privateKey: process.env.KEY_POLYMER
name: "KEY_DEPLOYER",
privateKey: process.env.KEY_DEPLOYER
},
],
};
Expand Down Expand Up @@ -138,8 +138,8 @@ const accountConfig = {
name: "local",
registry: [
{
name: "KEY_POLYMER",
privateKey: process.env.KEY_POLYMER,
name: "KEY_DEPLOYER",
privateKey: process.env.KEY_DEPLOYER,
},
],
};
Expand Down
Binary file modified bun.lockb
Binary file not shown.
4 changes: 2 additions & 2 deletions specs/contracts.setup.spec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
# args: args to make the function call with, need to be compatible with the signature
- name: DispatcherClientSetup-Connection-0
description: 'Setup client for dispatcher contracts'
deployer: 'KEY_POLYMER'
deployer: 'KEY_DEPLOYER'
signature: "setClientForConnection(string,address)"
address: '{{DispatcherProxy}}'
factoryName: "Dispatcher"
Expand All @@ -20,7 +20,7 @@

- name: DispatcherClientSetup-Connection-1
description: 'Setup client for dispatcher contracts'
deployer: 'KEY_POLYMER'
deployer: 'KEY_DEPLOYER'
signature: "setClientForConnection(string,address)"
address: '{{DispatcherProxy}}'
factoryName: "Dispatcher"
Expand Down
16 changes: 8 additions & 8 deletions specs/contracts.spec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,17 @@
- name: LightClient
description: 'DummyLightClient'
factoryName: 'DummyLightClient'
deployer: 'KEY_POLYMER'
deployer: 'KEY_DEPLOYER'

- name: Ibc
description: 'IBC library'
factoryName: 'Ibc'
deployer: 'KEY_POLYMER'
deployer: 'KEY_DEPLOYER'

- name: IbcUtils
description: 'IBC utils library'
factoryName: 'IbcUtils'
deployer: 'KEY_POLYMER'
deployer: 'KEY_DEPLOYER'

- name: Dispatcher
description: 'IBC Core contract'
Expand All @@ -40,12 +40,12 @@
address: '{{Ibc}}'
- name: 'contracts/libs/IbcUtils.sol:IbcUtils'
address: '{{IbcUtils}}'
deployer: 'KEY_POLYMER'
deployer: 'KEY_DEPLOYER'

- name: FeeVault
description: 'FeeVault'
factoryName: 'FeeVault'
deployer: 'KEY_POLYMER'
deployer: 'KEY_DEPLOYER'

- name: DispatcherProxy
description: 'Dispatcher proxy contract'
Expand All @@ -58,20 +58,20 @@
args:
- 'polyibc.{{chain.chainName}}.'
- '{{FeeVault}}'
deployer: 'KEY_POLYMER'
deployer: 'KEY_DEPLOYER'

- name: UC
description: 'Universal Chanel IBC-middleware contract'
factoryName: 'UniversalChannelHandler'
deployer: 'KEY_POLYMER'
deployer: 'KEY_DEPLOYER'
libraries:
- name: 'contracts/libs/IbcUtils.sol:IbcUtils'
address: '{{IbcUtils}}'

- name: UCProxy
description: 'Universal Chanel IBC-middleware proxy'
factoryName: 'ERC1967Proxy'
deployer: 'KEY_POLYMER'
deployer: 'KEY_DEPLOYER'
deployArgs:
- '{{UC}}'
- '$INITARGS'
Expand Down
7 changes: 3 additions & 4 deletions specs/evm.accounts.yaml
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
# These accounts are derived from a test mnemonic by Anvil/Hardhat and used for testing purposes only.
- name: 'KEY_POLYMER'
privateKey: '{{DEPLOYER_PRIVATE_KEY}}'

- name: 'KEY_DEPLOYER'
privateKey: '{{ DUMMY_DEPLOYER_PRIVATE_KEY }}'

# Dapp accounts
- name: 'KEY_DAPP1'
privateKey: '{{ DAPP_PRIVATE_KEY_1 }}'
- name: 'KEY_DAPP2'
privateKey: '{{ DAPP_PRIVATE_KEY_2 }}'
- name: 'KEY_DAPP3'
privateKey: '{{ DAPP_PRIVATE_KEY_2 }}'
privateKey: '{{ DAPP_PRIVATE_KEY_3 }}'
44 changes: 30 additions & 14 deletions specs/update.spec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -35,20 +35,36 @@
# signature: signature of method to call for this tx
# args: args to make the function call with, need to be compatible with the signature

- name: LightClient
- name: OptimisticProofVerifier
description: 'OptimisticProofVerifier'
factoryName: 'OptimisticProofVerifier'
deployer: 'KEY_DEPLOYER'
deployArgs:
- '{{PolymerL2OutputOracleProxyAddress}}'

- name: OptimisticLightClient
description: 'OptimisticLightClient'
factoryName: 'OptimisticLightClient'
deployer: 'KEY_DEPLOYER'
deployArgs:
- 0
- '{{OptimisticProofVerifier}}'
- '{{L1BlockAddress}}'

- name: DummyLightClient
description: 'DummyLightClient'
factoryName: 'DummyLightClient'
deployer: 'KEY_POLYMER'
deployer: 'KEY_DEPLOYER'

- name: Ibc
description: 'IBC library'
factoryName: 'Ibc'
deployer: 'KEY_POLYMER'
deployer: 'KEY_DEPLOYER'

- name: IbcUtils
description: 'IBC utils library'
factoryName: 'IbcUtils'
deployer: 'KEY_POLYMER'
deployer: 'KEY_DEPLOYER'

- name: Dispatcher
description: 'IBC Core contract'
Expand All @@ -58,12 +74,12 @@
address: '{{Ibc}}'
- name: 'contracts/libs/IbcUtils.sol:IbcUtils'
address: '{{IbcUtils}}'
deployer: 'KEY_POLYMER'
deployer: 'KEY_DEPLOYER'

- name: FeeVault
description: 'FeeVault'
factoryName: 'FeeVault'
deployer: 'KEY_POLYMER'
deployer: 'KEY_DEPLOYER'

- name: DispatcherProxy
description: 'Dispatcher proxy contract'
Expand All @@ -76,20 +92,20 @@
args:
- 'polyibc.{{chain.chainName}}.'
- '{{FeeVault}}'
deployer: 'KEY_POLYMER'
deployer: 'KEY_DEPLOYER'

- name: UC
description: 'Universal Chanel IBC-middleware contract'
factoryName: 'UniversalChannelHandler'
deployer: 'KEY_POLYMER'
deployer: 'KEY_DEPLOYER'
libraries:
- name: 'contracts/libs/IbcUtils.sol:IbcUtils'
address: '{{IbcUtils}}'

- name: UCProxy
description: 'Universal Chanel IBC-middleware proxy'
factoryName: 'ERC1967Proxy'
deployer: 'KEY_POLYMER'
deployer: 'KEY_DEPLOYER'
deployArgs:
- '{{UC}}'
- '$INITARGS'
Expand All @@ -115,7 +131,7 @@
# Contract Setup below
- name: DispatcherUpgrade
description: 'UUPS Upgrade for dispatcher contract implementation'
deployer: 'KEY_POLYMER'
deployer: 'KEY_DEPLOYER'
signature: "upgradeTo(address)"
address: '{{DispatcherProxy}}'
factoryName: "Dispatcher"
Expand All @@ -124,7 +140,7 @@

- name: DispatcherUpgrade
description: 'UUPS Upgrade for dispatcher contract implementation'
deployer: 'KEY_POLYMER'
deployer: 'KEY_DEPLOYER'
signature: "upgradeTo(address)"
address: '{{DispatcherProxy}}'
factoryName: "Dispatcher"
Expand All @@ -133,7 +149,7 @@

- name: UCH Upgrade
description: 'Upgrade for uch contract'
deployer: 'KEY_POLYMER'
deployer: 'KEY_DEPLOYER'
signature: "upgradeTo(address)"
address: '{{ UCProxy }}'
factoryName: "UC"
Expand All @@ -142,7 +158,7 @@

- name: DispatcherClientSetup-Connection-0
description: 'Setup client for dispatcher contracts'
deployer: 'KEY_POLYMER'
deployer: 'KEY_DEPLOYER'
signature: "setClientForConnection(string,address)"
address: '{{DispatcherProxy}}'
factoryName: "Dispatcher"
Expand All @@ -152,7 +168,7 @@

- name: DispatcherClientSetup-Connection-1
description: 'Setup client for dispatcher contracts'
deployer: 'KEY_POLYMER'
deployer: 'KEY_DEPLOYER'
signature: "setClientForConnection(string,address)"
address: '{{DispatcherProxy}}'
factoryName: "Dispatcher"
Expand Down
4 changes: 2 additions & 2 deletions specs/upgrade.spec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

- name: DispatcherUpgrade
description: 'UUPS Upgrade for dispatcher contract implementation'
deployer: 'KEY_POLYMER'
deployer: 'KEY_DEPLOYER'
signature: "upgradeTo(address)"
address: '{{DispatcherProxy}}'
factoryName: "Dispatcher"
Expand All @@ -27,7 +27,7 @@

- name: UCH Upgrade
description: 'Upgrade for uch contract'
deployer: 'KEY_POLYMER'
deployer: 'KEY_DEPLOYER'
signature: "upgradeTo(address)"
address: '{{ UCProxy }}'
factoryName: "UC"
Expand Down
2 changes: 1 addition & 1 deletion src/deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ export async function deployToChain(
}

// @ts-ignore
const env: StringToStringMap = { chain };
const env: StringToStringMap = {...process.env , chain , };
if (!forceDeployNewContracts) {
// Only read from existing contract files if we want to deploy new ones
await readDeploymentFilesIntoEnv(env, chain);
Expand Down
2 changes: 1 addition & 1 deletion src/scripts/fork-deployment-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ const main = async () => {
env = await readDeploymentFilesIntoEnv(env, chain); // Read deployment files from non-forked chain to get live addresses

$.env = {
...env,
...process.env,
...env,
};

await $`cd ${MODULE_ROOT_PATH} && forge test --match-contract DispatcherDeployTest --fork-url ${anvilUrl} -vvvv `.pipe(
Expand Down
2 changes: 1 addition & 1 deletion src/updateContract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export async function updateContractsForChain(

// @ts-ignore
let env = await readDeploymentFilesIntoEnv({}, chain); // Read from existing deployment files first, then overwrite with explicitly given contract addresses
env = { chain, ...existingContractAddresses, ...env };
env = {...process.env, chain, ...existingContractAddresses, ...env };
if (!forceDeployNewContracts) {
// Only read from existing contract files if we want to deploy new ones
await readDeploymentFilesIntoEnv(env, chain);
Expand Down
9 changes: 4 additions & 5 deletions test/Fork/Dispatcher.deploy.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ struct ChainAddresses {
IUniversalChannelHandler uch;
ILightClient dummyLightClient;
ILightClient optimisticLightClient;
bytes32 ownerKey; // Owner Address of dispatcher
address owner; // Owner Address of dispatcher
}

contract DispatcherDeployTest is ChannelHandShakeUpgradeUtil, UpgradeTestUtils {
Expand All @@ -57,17 +57,16 @@ contract DispatcherDeployTest is ChannelHandShakeUpgradeUtil, UpgradeTestUtils {
IUniversalChannelHandler(vm.envAddress("UCProxy")),
ILightClient(vm.envAddress("DummyLightClient")),
ILightClient(vm.envAddress("OptimisticLightClient")),
vm.envBytes32("OWNER_KEY")
vm.envAddress("OwnerAddress")
);

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

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

dispatcherProxy = addresses.dispatcherProxy;
vm.prank(owner);
vm.prank(addresses.owner);

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

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

dispatcherProxy.setClientForConnection("connection-2", opLightClient);
Expand Down
Loading

0 comments on commit 33bb865

Please sign in to comment.