From 33cf687c7a013acdc7a5634fe6528a3e3a0e9d59 Mon Sep 17 00:00:00 2001 From: bowd Date: Sun, 18 Aug 2024 20:41:52 +0200 Subject: [PATCH] fix: set env vars during test initialization --- .env.ci | 3 --- foundry.toml | 2 ++ test/CeloChains.t.sol | 35 ++++++++++++++++++++++++++++++++--- test/ContractsLookup.t.sol | 6 ++++++ 4 files changed, 40 insertions(+), 6 deletions(-) delete mode 100644 .env.ci diff --git a/.env.ci b/.env.ci deleted file mode 100644 index 398db54..0000000 --- a/.env.ci +++ /dev/null @@ -1,3 +0,0 @@ -CELO_RPC_URL=https://forno.celo.org -BAKLAVA_RPC_URL=https://baklava-forno.celo-testnet.org -ALFAJORES_RPC_URL=https://alfajores-forno.celo-testnet.org diff --git a/foundry.toml b/foundry.toml index 786739c..f71c2e9 100644 --- a/foundry.toml +++ b/foundry.toml @@ -7,6 +7,8 @@ fs_permissions = [ { access = "read", path = "./broadcast/" }, ] +[profile.ci] + # See more config options https://github.com/foundry-rs/foundry/blob/master/crates/config/README.md#all-options [rpc_endpoints] celo = "${CELO_RPC_URL}" diff --git a/test/CeloChains.t.sol b/test/CeloChains.t.sol index b36afdd..f088440 100644 --- a/test/CeloChains.t.sol +++ b/test/CeloChains.t.sol @@ -8,6 +8,35 @@ import {CeloChains} from "src/CeloChains.sol"; import {CELO_ID, BAKLAVA_ID, ALFAJORES_ID} from "src/Constants.sol"; contract CeloChainsTest is Test { + address celoDeployerAddress; + address baklavaDeployerAddress; + address alfajoresDeployerAddress; + + constructor() Test() { + vm.setEnv("CELO_RPC_URL", "https://forno.celo.org"); + vm.setEnv( + "ALFAJORES_RPC_URL", + "https://alfajores-forno.celo-testnet.org" + ); + vm.setEnv("BAKLAVA_RPC_URL", "https://baklava-forno.celo-testnet.org"); + + uint256 celoDeployerPk; + uint256 baklavaDeployerPk; + uint256 alfajoresDeployerPk; + + (celoDeployerAddress, celoDeployerPk) = makeAddrAndKey("celoDeployer"); + (alfajoresDeployerAddress, alfajoresDeployerPk) = makeAddrAndKey( + "alfajoresDeployer" + ); + (baklavaDeployerAddress, baklavaDeployerPk) = makeAddrAndKey( + "baklavaDeployer" + ); + + vm.setEnv("celo_DEPLOYER_PK", vm.toString(celoDeployerPk)); + vm.setEnv("alfajores_DEPLOYER_PK", vm.toString(alfajoresDeployerPk)); + vm.setEnv("baklava_DEPLOYER_PK", vm.toString(baklavaDeployerPk)); + } + function test_getChainCelo() public { Chain memory chain = getChain(CELO_ID); assertEq(chain.chainAlias, "celo"); @@ -69,20 +98,20 @@ contract CeloChainsTest is Test { function test_deployerAddressCelo() public { fork(CELO_ID); address deployer = deployerAddress(); - assertEq(deployer, 0x7d8979781389885A30918aa6Ebb5B606c55845f2); + assertEq(deployer, celoDeployerAddress); } // Should read pk from .env and derive correct address function test_deployerAddressBaklava() public { fork(BAKLAVA_ID); address deployer = deployerAddress(); - assertEq(deployer, 0x83D8c67ADfFD01522C319476Fd14e85C431f2b63); + assertEq(deployer, baklavaDeployerAddress); } // Should read pk from .env and derive correct address function test_deployerAddressAlfajores() public { fork(ALFAJORES_ID); address deployer = deployerAddress(); - assertEq(deployer, 0xa43e5313e12B84aC737f335A7897668f235768A9); + assertEq(deployer, alfajoresDeployerAddress); } } diff --git a/test/ContractsLookup.t.sol b/test/ContractsLookup.t.sol index 00f8006..f2e6d94 100644 --- a/test/ContractsLookup.t.sol +++ b/test/ContractsLookup.t.sol @@ -30,6 +30,12 @@ abstract contract ContractsLookupTest is Test, ContractsLookup { return "/test/fixtures/dependencies.json"; } + constructor() Test() ContractsLookup() { + vm.setEnv("CELO_RPC_URL", "https://forno.celo.org"); + vm.setEnv("ALFAJORES_RPC_URL", "https://alfajores-forno.celo-testnet.org"); + vm.setEnv("BAKLAVA_RPC_URL", "https://baklava-forno.celo-testnet.org"); + } + address contract01Expected; address contract02Expected; address contract03Expected;