From 22edfec5f506100fc7006a9472044c14fa9e118e Mon Sep 17 00:00:00 2001 From: Adam Stox Date: Mon, 17 Apr 2023 16:17:10 -0400 Subject: [PATCH 01/13] WIP: Add some tests for deterministic deploys --- test/token/factory.sol | 98 +++++++++++++++++++++++++++++------------- 1 file changed, 68 insertions(+), 30 deletions(-) diff --git a/test/token/factory.sol b/test/token/factory.sol index 1803e433..240c2a1e 100644 --- a/test/token/factory.sol +++ b/test/token/factory.sol @@ -3,6 +3,7 @@ pragma solidity ^0.8.18; pragma abicoder v2; import {TrancheTokenFactory, MemberlistFactory} from "src/token/factory.sol"; +import {RestrictedToken} from "src/token/restricted.sol"; import "forge-std/Test.sol"; contract FactoryTest is Test { @@ -15,34 +16,71 @@ contract FactoryTest is Test { function setUp() public {} - // function testTokenAddressShouldBeDeterministic( - // address sender, - // uint64 chainId, - // string memory name, - // string memory symbol - // ) public { - // TrancheTokenFactory tokenFactory = new TrancheTokenFactory{ salt: SALT }(); - - // if (isFirstRun) { - // tokenFactoryAddress = address(tokenFactory); - // } else { - // assertEq(address(tokenFactory), tokenFactoryAddress); - // } - - // vm.prank(sender); - // vm.chainId(uint256(chainId)); - - // uint64 fixedPoolId = 1; - // bytes16 fixedTrancheId = "1"; - // uint8 fixedDecimals = 18; - - // address token = tokenFactory.newTrancheToken(fixedPoolId, fixedTrancheId, name, symbol, fixedDecimals); - - // if (isFirstRun) { - // tokenAddress = address(tokenFactory); - // isFirstRun = false; - // } else { - // assertEq(token, tokenAddress); - // } - // } + function testTokenAddressShouldBeDeterministic1( + address sender, + uint64 chainId, + string memory name, + string memory symbol + ) public { + TrancheTokenFactory tokenFactory = new TrancheTokenFactory{ salt: SALT }(); + + if (isFirstRun) { + tokenFactoryAddress = address(tokenFactory); + } else { + assertEq(address(tokenFactory), tokenFactoryAddress); + } + + vm.prank(sender); + vm.chainId(uint256(chainId)); + + uint64 fixedPoolId = 1; + bytes16 fixedTrancheId = "1"; + uint8 fixedDecimals = 18; + + address token = tokenFactory.newTrancheToken(fixedPoolId, fixedTrancheId, name, symbol, fixedDecimals); + + if (isFirstRun) { + tokenAddress = address(tokenFactory); + isFirstRun = false; + } else { + assertEq(token, tokenAddress); + } + } + + function testTokenFactoryAddressShouldBeDeterministic() public { + address predictedAddress = address(uint160(uint(keccak256(abi.encodePacked( + bytes1(0xff), + address(this), + SALT, + keccak256(abi.encodePacked( + type(TrancheTokenFactory).creationCode + )) + ))))); + TrancheTokenFactory tokenFactory = new TrancheTokenFactory{ salt: SALT }(); + assertEq(address(tokenFactory), predictedAddress); + } + + function testTrancheTokenAddressShouldBeDeterministic() public { + uint64 fixedPoolId = 1; + bytes16 fixedTrancheId = "1"; + string memory name = "Test Tranche Token"; + string memory symbol = "TEST"; + uint8 fixedDecimals = 18; + + TrancheTokenFactory tokenFactory = new TrancheTokenFactory{ salt: SALT }(); + + address token = tokenFactory.newTrancheToken(fixedPoolId, fixedTrancheId, name, symbol, fixedDecimals); + + address predictedAddress = address(uint160(uint(keccak256(abi.encodePacked( + bytes1(0xff), + address(this), + SALT, + keccak256(abi.encodePacked( + type(RestrictedToken).creationCode, + abi.encode(fixedPoolId, fixedTrancheId, name, symbol, fixedDecimals) + )) + ))))); + + assertEq(token, predictedAddress); + } } From f877b2741151cc4e30639d176a32669202fbcaea Mon Sep 17 00:00:00 2001 From: Adam Stox Date: Tue, 18 Apr 2023 17:01:20 -0400 Subject: [PATCH 02/13] fix tranche token test --- test/token/factory.sol | 94 +++++++++++++++++++++++------------------- 1 file changed, 52 insertions(+), 42 deletions(-) diff --git a/test/token/factory.sol b/test/token/factory.sol index 240c2a1e..bd9d75be 100644 --- a/test/token/factory.sol +++ b/test/token/factory.sol @@ -16,36 +16,36 @@ contract FactoryTest is Test { function setUp() public {} - function testTokenAddressShouldBeDeterministic1( - address sender, - uint64 chainId, - string memory name, - string memory symbol - ) public { - TrancheTokenFactory tokenFactory = new TrancheTokenFactory{ salt: SALT }(); - - if (isFirstRun) { - tokenFactoryAddress = address(tokenFactory); - } else { - assertEq(address(tokenFactory), tokenFactoryAddress); - } - - vm.prank(sender); - vm.chainId(uint256(chainId)); - - uint64 fixedPoolId = 1; - bytes16 fixedTrancheId = "1"; - uint8 fixedDecimals = 18; - - address token = tokenFactory.newTrancheToken(fixedPoolId, fixedTrancheId, name, symbol, fixedDecimals); - - if (isFirstRun) { - tokenAddress = address(tokenFactory); - isFirstRun = false; - } else { - assertEq(token, tokenAddress); - } - } + // function testTokenAddressShouldBeDeterministic1( + // address sender, + // uint64 chainId, + // string memory name, + // string memory symbol + // ) public { + // TrancheTokenFactory tokenFactory = new TrancheTokenFactory{ salt: SALT }(); + + // if (isFirstRun) { + // tokenFactoryAddress = address(tokenFactory); + // } else { + // assertEq(address(tokenFactory), tokenFactoryAddress); + // } + + // vm.prank(sender); + // vm.chainId(uint256(chainId)); + + // uint64 fixedPoolId = 1; + // bytes16 fixedTrancheId = "1"; + // uint8 fixedDecimals = 18; + + // address token = tokenFactory.newTrancheToken(fixedPoolId, fixedTrancheId, name, symbol, fixedDecimals); + + // if (isFirstRun) { + // tokenAddress = address(tokenFactory); + // isFirstRun = false; + // } else { + // assertEq(token, tokenAddress); + // } + // } function testTokenFactoryAddressShouldBeDeterministic() public { address predictedAddress = address(uint160(uint(keccak256(abi.encodePacked( @@ -60,27 +60,37 @@ contract FactoryTest is Test { assertEq(address(tokenFactory), predictedAddress); } - function testTrancheTokenAddressShouldBeDeterministic() public { - uint64 fixedPoolId = 1; - bytes16 fixedTrancheId = "1"; - string memory name = "Test Tranche Token"; - string memory symbol = "TEST"; - uint8 fixedDecimals = 18; - + function testTrancheTokenAddressShouldBeDeterministic(uint64 poolId, bytes16 trancheId, string memory name, string memory symbol, uint8 decimals) public { TrancheTokenFactory tokenFactory = new TrancheTokenFactory{ salt: SALT }(); - address token = tokenFactory.newTrancheToken(fixedPoolId, fixedTrancheId, name, symbol, fixedDecimals); + bytes32 salt = keccak256(abi.encodePacked(poolId, trancheId)); + address predictedAddress = address(uint160(uint(keccak256(abi.encodePacked( + bytes1(0xff), + address(tokenFactory), + salt, + keccak256(abi.encodePacked( + type(RestrictedToken).creationCode, + abi.encode(decimals) + )) + ))))); + + address token = tokenFactory.newTrancheToken(poolId, trancheId, name, symbol, decimals); + assertEq(address(token), predictedAddress); + } + + function testDeployingDeterministicAddressTwice() public { address predictedAddress = address(uint160(uint(keccak256(abi.encodePacked( bytes1(0xff), address(this), SALT, keccak256(abi.encodePacked( - type(RestrictedToken).creationCode, - abi.encode(fixedPoolId, fixedTrancheId, name, symbol, fixedDecimals) + type(TrancheTokenFactory).creationCode )) ))))); - - assertEq(token, predictedAddress); + TrancheTokenFactory tokenFactory1 = new TrancheTokenFactory{ salt: SALT }(); + TrancheTokenFactory tokenFactory2 = new TrancheTokenFactory{ salt: SALT }(); + assertEq(address(tokenFactory1), predictedAddress); + assertEq(address(tokenFactory2), predictedAddress); } } From 2fe2222bb2dbb3c451a4e6d47baa9479768b60a8 Mon Sep 17 00:00:00 2001 From: Adam Stox Date: Tue, 18 Apr 2023 17:03:09 -0400 Subject: [PATCH 03/13] rename token test files to .t.sol --- test/token/{factory.sol => factory.t.sol} | 0 test/token/{restricted.sol => restricted.t.sol} | 0 2 files changed, 0 insertions(+), 0 deletions(-) rename test/token/{factory.sol => factory.t.sol} (100%) rename test/token/{restricted.sol => restricted.t.sol} (100%) diff --git a/test/token/factory.sol b/test/token/factory.t.sol similarity index 100% rename from test/token/factory.sol rename to test/token/factory.t.sol diff --git a/test/token/restricted.sol b/test/token/restricted.t.sol similarity index 100% rename from test/token/restricted.sol rename to test/token/restricted.t.sol From 9866224d466c927cd5d45091ad735c365bbb6660 Mon Sep 17 00:00:00 2001 From: Adam Stox Date: Fri, 21 Apr 2023 14:53:04 -0400 Subject: [PATCH 04/13] cross-chain test passing --- .env.example | 4 ++- test/token/factory.t.sol | 59 ++++++++++++++++------------------------ 2 files changed, 26 insertions(+), 37 deletions(-) diff --git a/.env.example b/.env.example index 80a258a0..a87e1c39 100644 --- a/.env.example +++ b/.env.example @@ -1,3 +1,5 @@ -RPC_URL= +CENTRIFUGE_CHAIN_ORIGIN= +MAINNET_RPC_URL= +POLYGON_RPC_URL= PRIVATE_KEY= ETHERSCAN_KEY= \ No newline at end of file diff --git a/test/token/factory.t.sol b/test/token/factory.t.sol index bd9d75be..a7b2a22f 100644 --- a/test/token/factory.t.sol +++ b/test/token/factory.t.sol @@ -10,42 +10,29 @@ contract FactoryTest is Test { // address(0)[0:20] + keccak("Centrifuge")[21:32] bytes32 SALT = 0x000000000000000000000000000000000000000075eb27011b69f002dc094d05; - bool isFirstRun = false; - address tokenFactoryAddress; - address tokenAddress; - function setUp() public {} - // function testTokenAddressShouldBeDeterministic1( - // address sender, - // uint64 chainId, - // string memory name, - // string memory symbol - // ) public { - // TrancheTokenFactory tokenFactory = new TrancheTokenFactory{ salt: SALT }(); - - // if (isFirstRun) { - // tokenFactoryAddress = address(tokenFactory); - // } else { - // assertEq(address(tokenFactory), tokenFactoryAddress); - // } - - // vm.prank(sender); - // vm.chainId(uint256(chainId)); - - // uint64 fixedPoolId = 1; - // bytes16 fixedTrancheId = "1"; - // uint8 fixedDecimals = 18; - - // address token = tokenFactory.newTrancheToken(fixedPoolId, fixedTrancheId, name, symbol, fixedDecimals); + function testTokenFactoryAddressIsDeterministicAcrossChains( + address sender, + string memory name, + string memory symbol, + uint64 poolId, + bytes16 trancheId, + uint8 decimals + ) public { + uint256 mainnetFork = vm.createFork(vm.envString("MAINNET_RPC_URL")); + uint256 polygonFork = vm.createFork(vm.envString("POLYGON_RPC_URL")); + vm.selectFork(mainnetFork); + TrancheTokenFactory tokenFactory1 = new TrancheTokenFactory{ salt: SALT }(); + address token1 = tokenFactory1.newTrancheToken(poolId, trancheId, name, symbol, decimals); - // if (isFirstRun) { - // tokenAddress = address(tokenFactory); - // isFirstRun = false; - // } else { - // assertEq(token, tokenAddress); - // } - // } + vm.selectFork(polygonFork); + TrancheTokenFactory tokenFactory2 = new TrancheTokenFactory{ salt: SALT }(); + assertEq(address(tokenFactory1), address(tokenFactory2)); + vm.prank(sender); + address token2 = tokenFactory2.newTrancheToken(poolId, trancheId, name, symbol, decimals); + assertEq(address(token1), address(token2)); + } function testTokenFactoryAddressShouldBeDeterministic() public { address predictedAddress = address(uint160(uint(keccak256(abi.encodePacked( @@ -79,7 +66,7 @@ contract FactoryTest is Test { assertEq(address(token), predictedAddress); } - function testDeployingDeterministicAddressTwice() public { + function testDeployingDeterministicAddressTwiceReverts() public { address predictedAddress = address(uint160(uint(keccak256(abi.encodePacked( bytes1(0xff), address(this), @@ -89,8 +76,8 @@ contract FactoryTest is Test { )) ))))); TrancheTokenFactory tokenFactory1 = new TrancheTokenFactory{ salt: SALT }(); - TrancheTokenFactory tokenFactory2 = new TrancheTokenFactory{ salt: SALT }(); assertEq(address(tokenFactory1), predictedAddress); - assertEq(address(tokenFactory2), predictedAddress); + vm.expectRevert(); + TrancheTokenFactory tokenFactory2 = new TrancheTokenFactory{ salt: SALT }(); } } From 93ae313cadc9c1cd1e6534051b9099975210ff38 Mon Sep 17 00:00:00 2001 From: Adam Stox Date: Fri, 21 Apr 2023 15:27:45 -0400 Subject: [PATCH 05/13] Add memberlist tests --- .env.example | 6 ++--- test/token/factory.t.sol | 57 +++++++++++++++++++++++++++++++++------- 2 files changed, 50 insertions(+), 13 deletions(-) diff --git a/.env.example b/.env.example index a87e1c39..7b5a8788 100644 --- a/.env.example +++ b/.env.example @@ -1,5 +1,5 @@ -CENTRIFUGE_CHAIN_ORIGIN= -MAINNET_RPC_URL= -POLYGON_RPC_URL= +CENTRIFUGE_CHAIN_ORIGIN=0x7369626cef070000000000000000000000000000 +MAINNET_RPC_URL=https://mainnet.infura.io/v3/... +POLYGON_RPC_URL=https://polygon-mainnet.infura.io/v3/... PRIVATE_KEY= ETHERSCAN_KEY= \ No newline at end of file diff --git a/test/token/factory.t.sol b/test/token/factory.t.sol index a7b2a22f..83f06c16 100644 --- a/test/token/factory.t.sol +++ b/test/token/factory.t.sol @@ -9,10 +9,15 @@ import "forge-std/Test.sol"; contract FactoryTest is Test { // address(0)[0:20] + keccak("Centrifuge")[21:32] bytes32 SALT = 0x000000000000000000000000000000000000000075eb27011b69f002dc094d05; + uint256 mainnetFork; + uint256 polygonFork; - function setUp() public {} + function setUp() public { + mainnetFork = vm.createFork(vm.envString("MAINNET_RPC_URL")); + polygonFork = vm.createFork(vm.envString("POLYGON_RPC_URL")); + } - function testTokenFactoryAddressIsDeterministicAcrossChains( + function testTokenFactoryIsDeterministicAcrossChains( address sender, string memory name, string memory symbol, @@ -20,8 +25,6 @@ contract FactoryTest is Test { bytes16 trancheId, uint8 decimals ) public { - uint256 mainnetFork = vm.createFork(vm.envString("MAINNET_RPC_URL")); - uint256 polygonFork = vm.createFork(vm.envString("POLYGON_RPC_URL")); vm.selectFork(mainnetFork); TrancheTokenFactory tokenFactory1 = new TrancheTokenFactory{ salt: SALT }(); address token1 = tokenFactory1.newTrancheToken(poolId, trancheId, name, symbol, decimals); @@ -34,7 +37,7 @@ contract FactoryTest is Test { assertEq(address(token1), address(token2)); } - function testTokenFactoryAddressShouldBeDeterministic() public { + function testTokenFactoryShouldBeDeterministic() public { address predictedAddress = address(uint160(uint(keccak256(abi.encodePacked( bytes1(0xff), address(this), @@ -47,7 +50,7 @@ contract FactoryTest is Test { assertEq(address(tokenFactory), predictedAddress); } - function testTrancheTokenAddressShouldBeDeterministic(uint64 poolId, bytes16 trancheId, string memory name, string memory symbol, uint8 decimals) public { + function testTrancheTokenShouldBeDeterministic(uint64 poolId, bytes16 trancheId, string memory name, string memory symbol, uint8 decimals) public { TrancheTokenFactory tokenFactory = new TrancheTokenFactory{ salt: SALT }(); bytes32 salt = keccak256(abi.encodePacked(poolId, trancheId)); @@ -66,7 +69,7 @@ contract FactoryTest is Test { assertEq(address(token), predictedAddress); } - function testDeployingDeterministicAddressTwiceReverts() public { + function testDeployingDeterministicAddressTwiceReverts(uint64 poolId, bytes16 trancheId, string memory name, string memory symbol, uint8 decimals) public { address predictedAddress = address(uint160(uint(keccak256(abi.encodePacked( bytes1(0xff), address(this), @@ -75,9 +78,43 @@ contract FactoryTest is Test { type(TrancheTokenFactory).creationCode )) ))))); - TrancheTokenFactory tokenFactory1 = new TrancheTokenFactory{ salt: SALT }(); - assertEq(address(tokenFactory1), predictedAddress); + TrancheTokenFactory tokenFactory = new TrancheTokenFactory{ salt: SALT }(); + assertEq(address(tokenFactory), predictedAddress); + address token1 = tokenFactory.newTrancheToken(poolId, trancheId, name, symbol, decimals); vm.expectRevert(); - TrancheTokenFactory tokenFactory2 = new TrancheTokenFactory{ salt: SALT }(); + address token2 = tokenFactory.newTrancheToken(poolId, trancheId, name, symbol, decimals); + + } + + function testMemberlistFactoryIsDeterministicAcrossChains( + address sender, + uint64 poolId, + bytes16 trancheId, + uint256 threshold + ) public { + vm.selectFork(mainnetFork); + MemberlistFactory memberlistFactory1 = new MemberlistFactory{ salt: SALT }(); + address memberlist1 = memberlistFactory1.newMemberlist(); + + vm.selectFork(polygonFork); + MemberlistFactory memberlistFactory2 = new MemberlistFactory{ salt: SALT }(); + assertEq(address(memberlistFactory1), address(memberlistFactory2)); + vm.prank(sender); + address memberlist2 = memberlistFactory2.newMemberlist(); + assertEq(address(memberlist1), address(memberlist2)); + } + + function testMemberlistShouldBeDeterministic() public { + address predictedAddress = address(uint160(uint(keccak256(abi.encodePacked( + bytes1(0xff), + address(this), + SALT, + keccak256(abi.encodePacked( + type(MemberlistFactory).creationCode + )) + ))))); + MemberlistFactory memberlistFactory = new MemberlistFactory{ salt: SALT }(); + assertEq(address(memberlistFactory), predictedAddress); + } } From 4bb0c4008c30f128975e31f361b43afa429a5edb Mon Sep 17 00:00:00 2001 From: Jeroen Offerijns Date: Sun, 23 Apr 2023 09:59:30 +0200 Subject: [PATCH 06/13] Add env vars --- .github/workflows/pull-request.yml | 5 ++++- .github/workflows/push-to-main.yml | 5 ++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/.github/workflows/pull-request.yml b/.github/workflows/pull-request.yml index a3bfa541..64b42475 100644 --- a/.github/workflows/pull-request.yml +++ b/.github/workflows/pull-request.yml @@ -34,7 +34,10 @@ jobs: id: test env: - FOUNDRY_PROFILE: pull_request + FOUNDRY_PROFILE: push_to_main + CENTRIFUGE_CHAIN_ORIGIN: 0x7369626cef070000000000000000000000000000 + MAINNET_RPC_URL: {{ secret.MAINNET_RPC_URL }} + POLYGON_RPC_URL: {{ secret.POLYGON_RPC_URL }} lint: name: fmt diff --git a/.github/workflows/push-to-main.yml b/.github/workflows/push-to-main.yml index 0a97bedc..99b31e9d 100644 --- a/.github/workflows/push-to-main.yml +++ b/.github/workflows/push-to-main.yml @@ -36,4 +36,7 @@ jobs: forge test -vvv id: test env: - FOUNDRY_PROFILE: push_to_main \ No newline at end of file + FOUNDRY_PROFILE: push_to_main + CENTRIFUGE_CHAIN_ORIGIN: 0x7369626cef070000000000000000000000000000 + MAINNET_RPC_URL: {{ secret.MAINNET_RPC_URL }} + POLYGON_RPC_URL: {{ secret.POLYGON_RPC_URL }} From 569a0bbaee366c92990258ee86aaaf7ef87a11ab Mon Sep 17 00:00:00 2001 From: Jeroen Offerijns Date: Sun, 23 Apr 2023 10:00:45 +0200 Subject: [PATCH 07/13] Fix formatting --- .github/workflows/pull-request.yml | 2 +- .github/workflows/push-to-main.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/pull-request.yml b/.github/workflows/pull-request.yml index 64b42475..55917201 100644 --- a/.github/workflows/pull-request.yml +++ b/.github/workflows/pull-request.yml @@ -35,7 +35,7 @@ jobs: env: FOUNDRY_PROFILE: push_to_main - CENTRIFUGE_CHAIN_ORIGIN: 0x7369626cef070000000000000000000000000000 + CENTRIFUGE_CHAIN_ORIGIN: "0x7369626cef070000000000000000000000000000" MAINNET_RPC_URL: {{ secret.MAINNET_RPC_URL }} POLYGON_RPC_URL: {{ secret.POLYGON_RPC_URL }} diff --git a/.github/workflows/push-to-main.yml b/.github/workflows/push-to-main.yml index 99b31e9d..ff16962b 100644 --- a/.github/workflows/push-to-main.yml +++ b/.github/workflows/push-to-main.yml @@ -37,6 +37,6 @@ jobs: id: test env: FOUNDRY_PROFILE: push_to_main - CENTRIFUGE_CHAIN_ORIGIN: 0x7369626cef070000000000000000000000000000 + CENTRIFUGE_CHAIN_ORIGIN: "0x7369626cef070000000000000000000000000000" MAINNET_RPC_URL: {{ secret.MAINNET_RPC_URL }} POLYGON_RPC_URL: {{ secret.POLYGON_RPC_URL }} From 99f431918e905858e7d601a2cbcdc2fc5544e9c6 Mon Sep 17 00:00:00 2001 From: Jeroen Offerijns Date: Sun, 23 Apr 2023 10:02:42 +0200 Subject: [PATCH 08/13] Change to secret --- .github/workflows/pull-request.yml | 2 +- .github/workflows/push-to-main.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/pull-request.yml b/.github/workflows/pull-request.yml index 55917201..f4de76e3 100644 --- a/.github/workflows/pull-request.yml +++ b/.github/workflows/pull-request.yml @@ -35,7 +35,7 @@ jobs: env: FOUNDRY_PROFILE: push_to_main - CENTRIFUGE_CHAIN_ORIGIN: "0x7369626cef070000000000000000000000000000" + CENTRIFUGE_CHAIN_ORIGIN: {{ secret.CENTRIFUGE_CHAIN_ORIGIN }} MAINNET_RPC_URL: {{ secret.MAINNET_RPC_URL }} POLYGON_RPC_URL: {{ secret.POLYGON_RPC_URL }} diff --git a/.github/workflows/push-to-main.yml b/.github/workflows/push-to-main.yml index ff16962b..01355ad9 100644 --- a/.github/workflows/push-to-main.yml +++ b/.github/workflows/push-to-main.yml @@ -37,6 +37,6 @@ jobs: id: test env: FOUNDRY_PROFILE: push_to_main - CENTRIFUGE_CHAIN_ORIGIN: "0x7369626cef070000000000000000000000000000" + CENTRIFUGE_CHAIN_ORIGIN: {{ secret.CENTRIFUGE_CHAIN_ORIGIN }} MAINNET_RPC_URL: {{ secret.MAINNET_RPC_URL }} POLYGON_RPC_URL: {{ secret.POLYGON_RPC_URL }} From 037b6d6dd3c821509416d0ef3192fd97694c9ac8 Mon Sep 17 00:00:00 2001 From: Jeroen Offerijns Date: Sun, 23 Apr 2023 10:05:02 +0200 Subject: [PATCH 09/13] Fix syntax --- .github/workflows/pull-request.yml | 6 +++--- .github/workflows/push-to-main.yml | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/.github/workflows/pull-request.yml b/.github/workflows/pull-request.yml index f4de76e3..61011443 100644 --- a/.github/workflows/pull-request.yml +++ b/.github/workflows/pull-request.yml @@ -35,9 +35,9 @@ jobs: env: FOUNDRY_PROFILE: push_to_main - CENTRIFUGE_CHAIN_ORIGIN: {{ secret.CENTRIFUGE_CHAIN_ORIGIN }} - MAINNET_RPC_URL: {{ secret.MAINNET_RPC_URL }} - POLYGON_RPC_URL: {{ secret.POLYGON_RPC_URL }} + CENTRIFUGE_CHAIN_ORIGIN: ${{ secrets.CENTRIFUGE_CHAIN_ORIGIN }} + MAINNET_RPC_URL: ${{ secrets.MAINNET_RPC_URL }} + POLYGON_RPC_URL: ${{ secrets.POLYGON_RPC_URL }} lint: name: fmt diff --git a/.github/workflows/push-to-main.yml b/.github/workflows/push-to-main.yml index 01355ad9..422119f0 100644 --- a/.github/workflows/push-to-main.yml +++ b/.github/workflows/push-to-main.yml @@ -37,6 +37,6 @@ jobs: id: test env: FOUNDRY_PROFILE: push_to_main - CENTRIFUGE_CHAIN_ORIGIN: {{ secret.CENTRIFUGE_CHAIN_ORIGIN }} - MAINNET_RPC_URL: {{ secret.MAINNET_RPC_URL }} - POLYGON_RPC_URL: {{ secret.POLYGON_RPC_URL }} + CENTRIFUGE_CHAIN_ORIGIN: ${{ secrets.CENTRIFUGE_CHAIN_ORIGIN }} + MAINNET_RPC_URL: ${{ secrets.MAINNET_RPC_URL }} + POLYGON_RPC_URL: ${{ secrets.POLYGON_RPC_URL }} From 697bf65889f7b96a514ab49e6587799743da9b66 Mon Sep 17 00:00:00 2001 From: Jeroen Offerijns Date: Sun, 23 Apr 2023 10:07:39 +0200 Subject: [PATCH 10/13] Assume destination address is not 0x0 --- test/Connector.t.sol | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/test/Connector.t.sol b/test/Connector.t.sol index dc8bc422..ccbeadca 100644 --- a/test/Connector.t.sol +++ b/test/Connector.t.sol @@ -373,7 +373,7 @@ contract ConnectorTest is Test { address destinationAddress, uint128 amount ) public { - vm.assume(validUntil > block.timestamp + 7 days); + vm.assume(validUntil > block.timestamp + 7 days && destinationAddress != address(0)); connector.addPool(poolId, currency, decimals); connector.addTranche(poolId, trancheId, tokenName, tokenSymbol, price); bridgedConnector.deployTranche(poolId, trancheId); @@ -397,6 +397,7 @@ contract ConnectorTest is Test { address destinationAddress, uint128 amount ) public { + vm.assume(destinationAddress != address(0)); connector.addPool(poolId, currency, decimals); connector.addTranche(poolId, trancheId, tokenName, tokenSymbol, price); bridgedConnector.deployTranche(poolId, trancheId); From 9d5e29438e8446745f0bc0cb7f76c12d817a86fa Mon Sep 17 00:00:00 2001 From: Jeroen Offerijns Date: Sun, 23 Apr 2023 10:07:59 +0200 Subject: [PATCH 11/13] Format --- test/token/factory.t.sol | 107 +++++++++++++++++++++++++-------------- 1 file changed, 70 insertions(+), 37 deletions(-) diff --git a/test/token/factory.t.sol b/test/token/factory.t.sol index 83f06c16..e8bd8eac 100644 --- a/test/token/factory.t.sol +++ b/test/token/factory.t.sol @@ -38,52 +38,80 @@ contract FactoryTest is Test { } function testTokenFactoryShouldBeDeterministic() public { - address predictedAddress = address(uint160(uint(keccak256(abi.encodePacked( - bytes1(0xff), - address(this), - SALT, - keccak256(abi.encodePacked( - type(TrancheTokenFactory).creationCode - )) - ))))); + address predictedAddress = address( + uint160( + uint256( + keccak256( + abi.encodePacked( + bytes1(0xff), + address(this), + SALT, + keccak256(abi.encodePacked(type(TrancheTokenFactory).creationCode)) + ) + ) + ) + ) + ); TrancheTokenFactory tokenFactory = new TrancheTokenFactory{ salt: SALT }(); assertEq(address(tokenFactory), predictedAddress); } - function testTrancheTokenShouldBeDeterministic(uint64 poolId, bytes16 trancheId, string memory name, string memory symbol, uint8 decimals) public { + function testTrancheTokenShouldBeDeterministic( + uint64 poolId, + bytes16 trancheId, + string memory name, + string memory symbol, + uint8 decimals + ) public { TrancheTokenFactory tokenFactory = new TrancheTokenFactory{ salt: SALT }(); bytes32 salt = keccak256(abi.encodePacked(poolId, trancheId)); - address predictedAddress = address(uint160(uint(keccak256(abi.encodePacked( - bytes1(0xff), - address(tokenFactory), - salt, - keccak256(abi.encodePacked( - type(RestrictedToken).creationCode, - abi.encode(decimals) - )) - ))))); + address predictedAddress = address( + uint160( + uint256( + keccak256( + abi.encodePacked( + bytes1(0xff), + address(tokenFactory), + salt, + keccak256(abi.encodePacked(type(RestrictedToken).creationCode, abi.encode(decimals))) + ) + ) + ) + ) + ); address token = tokenFactory.newTrancheToken(poolId, trancheId, name, symbol, decimals); assertEq(address(token), predictedAddress); } - function testDeployingDeterministicAddressTwiceReverts(uint64 poolId, bytes16 trancheId, string memory name, string memory symbol, uint8 decimals) public { - address predictedAddress = address(uint160(uint(keccak256(abi.encodePacked( - bytes1(0xff), - address(this), - SALT, - keccak256(abi.encodePacked( - type(TrancheTokenFactory).creationCode - )) - ))))); + function testDeployingDeterministicAddressTwiceReverts( + uint64 poolId, + bytes16 trancheId, + string memory name, + string memory symbol, + uint8 decimals + ) public { + address predictedAddress = address( + uint160( + uint256( + keccak256( + abi.encodePacked( + bytes1(0xff), + address(this), + SALT, + keccak256(abi.encodePacked(type(TrancheTokenFactory).creationCode)) + ) + ) + ) + ) + ); TrancheTokenFactory tokenFactory = new TrancheTokenFactory{ salt: SALT }(); assertEq(address(tokenFactory), predictedAddress); address token1 = tokenFactory.newTrancheToken(poolId, trancheId, name, symbol, decimals); vm.expectRevert(); address token2 = tokenFactory.newTrancheToken(poolId, trancheId, name, symbol, decimals); - } function testMemberlistFactoryIsDeterministicAcrossChains( @@ -105,16 +133,21 @@ contract FactoryTest is Test { } function testMemberlistShouldBeDeterministic() public { - address predictedAddress = address(uint160(uint(keccak256(abi.encodePacked( - bytes1(0xff), - address(this), - SALT, - keccak256(abi.encodePacked( - type(MemberlistFactory).creationCode - )) - ))))); + address predictedAddress = address( + uint160( + uint256( + keccak256( + abi.encodePacked( + bytes1(0xff), + address(this), + SALT, + keccak256(abi.encodePacked(type(MemberlistFactory).creationCode)) + ) + ) + ) + ) + ); MemberlistFactory memberlistFactory = new MemberlistFactory{ salt: SALT }(); assertEq(address(memberlistFactory), predictedAddress); - } } From a8929b6a2415d0576f12a19ef9b10af45bef40f2 Mon Sep 17 00:00:00 2001 From: Jeroen Offerijns Date: Sun, 23 Apr 2023 11:06:03 +0200 Subject: [PATCH 12/13] Update test/Connector.t.sol Co-authored-by: Nuno Alexandre --- test/Connector.t.sol | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/test/Connector.t.sol b/test/Connector.t.sol index ccbeadca..c49908d5 100644 --- a/test/Connector.t.sol +++ b/test/Connector.t.sol @@ -373,7 +373,8 @@ contract ConnectorTest is Test { address destinationAddress, uint128 amount ) public { - vm.assume(validUntil > block.timestamp + 7 days && destinationAddress != address(0)); + vm.assume(validUntil > block.timestamp + 7 days); + vm.assume(destinationAddress != address(0))); connector.addPool(poolId, currency, decimals); connector.addTranche(poolId, trancheId, tokenName, tokenSymbol, price); bridgedConnector.deployTranche(poolId, trancheId); From 8cb16adea5d1271f3c595272b113ae3e7ec333cb Mon Sep 17 00:00:00 2001 From: Jeroen Offerijns Date: Sun, 23 Apr 2023 11:07:15 +0200 Subject: [PATCH 13/13] Fix typo --- test/Connector.t.sol | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/Connector.t.sol b/test/Connector.t.sol index c49908d5..b8a815e9 100644 --- a/test/Connector.t.sol +++ b/test/Connector.t.sol @@ -374,7 +374,7 @@ contract ConnectorTest is Test { uint128 amount ) public { vm.assume(validUntil > block.timestamp + 7 days); - vm.assume(destinationAddress != address(0))); + vm.assume(destinationAddress != address(0)); connector.addPool(poolId, currency, decimals); connector.addTranche(poolId, trancheId, tokenName, tokenSymbol, price); bridgedConnector.deployTranche(poolId, trancheId);