Skip to content

Commit

Permalink
fix: set env vars during test initialization
Browse files Browse the repository at this point in the history
  • Loading branch information
bowd committed Aug 18, 2024
1 parent 42d8334 commit 33cf687
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 6 deletions.
3 changes: 0 additions & 3 deletions .env.ci

This file was deleted.

2 changes: 2 additions & 0 deletions foundry.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
Expand Down
35 changes: 32 additions & 3 deletions test/CeloChains.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -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);
}
}
6 changes: 6 additions & 0 deletions test/ContractsLookup.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 33cf687

Please sign in to comment.