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 30, 2024
1 parent 24550b8 commit 94355b4
Show file tree
Hide file tree
Showing 15 changed files with 107 additions and 59 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/[email protected]
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/
23 changes: 23 additions & 0 deletions .github/workflows/foundry.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,32 @@ jobs:

- name: Install Foundry
uses: foundry-rs/foundry-toolchain@v1

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

- name: Generate Bindings
run: |
bun install --frozen-lockfile
bun run build
- name: Check contract sizes
run: forge build --sizes --deny-warnings

- name: Tests
run: forge test --no-match-contract DispatcherDeployTest
- name: set Owner Address
run: echo "OwnerAddress=$(cast wallet address ${{ secrets.DUMMY_DEPLOYER_PRIVATE_KEY }})" >> $GITHUB_ENV
- name: Fork Deploy Test
run: npx vibc-core-deploy-test
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.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@open-ibc/vibc-core-smart-contracts",
"version": "2.1.12",
"version": "2.1.13",
"main": "dist/index.js",
"bin": {
"verify-vibc-core-smart-contracts": "./dist/scripts/verify-contract-script.js",
Expand Down
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 }}'
52 changes: 34 additions & 18 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,20 +158,20 @@

- name: DispatcherClientSetup-Connection-0
description: 'Setup client for dispatcher contracts'
deployer: 'KEY_POLYMER'
deployer: 'KEY_DEPLOYER'
signature: "setClientForConnection(string,address)"
address: '{{DispatcherProxy}}'
factoryName: "Dispatcher"
args:
- 'connection-0'
- '{{LightClient}}'
- 'connection-1'
- '{{DummyLightClient}}'

- name: DispatcherClientSetup-Connection-1
description: 'Setup client for dispatcher contracts'
deployer: 'KEY_POLYMER'
deployer: 'KEY_DEPLOYER'
signature: "setClientForConnection(string,address)"
address: '{{DispatcherProxy}}'
factoryName: "Dispatcher"
args:
- 'connection-2'
- '{{LightClient}}'
- 'connection-3'
- '{{DummyLightClient}}'
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
Loading

0 comments on commit 94355b4

Please sign in to comment.