diff --git a/src/Connector.sol b/src/Connector.sol index 3f25914a..deb21b31 100644 --- a/src/Connector.sol +++ b/src/Connector.sol @@ -5,6 +5,7 @@ pragma abicoder v2; import { RestrictedTokenFactoryLike, MemberlistFactoryLike } from "./token/factory.sol"; import { RestrictedTokenLike } from "./token/restricted.sol"; import { MemberlistLike } from "./token/memberlist.sol"; +// TODO: remove dependency on Messages.sol import { ConnectorMessages } from "src/Messages.sol"; interface RouterLike { @@ -104,10 +105,9 @@ contract CentrifugeConnector { } function deployTranche(uint64 poolId, bytes16 trancheId) public { - Pool storage pool = pools[poolId]; - require(pool.createdAt > 0, "CentrifugeConnector/invalid-pool"); - Tranche storage tranche = tranches[poolId][trancheId]; + require(tranche.lastPriceUpdate > 0, "CentrifugeConnector/invalid-pool-or-tranche"); + address token = tokenFactory.newRestrictedToken(tranche.tokenName, tranche.tokenSymbol); tranche.token = token; diff --git a/test/Connector.t.sol b/test/Connector.t.sol index 848324e4..e1e2f387 100644 --- a/test/Connector.t.sol +++ b/test/Connector.t.sol @@ -96,6 +96,34 @@ contract ConnectorTest is Test { homeConnector.addTranche(poolId, trancheId, tokenName, tokenSymbol, price); } + function testDeployingWrongTrancheFails(uint64 poolId, string memory tokenName, string memory tokenSymbol, bytes16 trancheId, bytes16 wrongTrancheId, uint128 price) public { + vm.assume(trancheId != wrongTrancheId); + // 0. Add Pool + homeConnector.addPool(poolId); + (uint64 actualPoolId,) = bridgedConnector.pools(poolId); + assertEq(uint256(actualPoolId), uint256(poolId)); + + // 1. Add the tranche + homeConnector.addTranche(poolId, trancheId, tokenName, tokenSymbol, price); + // 2. Then deploy the tranche + vm.expectRevert(bytes("CentrifugeConnector/invalid-pool-or-tranche")); + bridgedConnector.deployTranche(poolId, wrongTrancheId); + } + + function testDeployingTrancheOnNonExistantPoolFails(uint64 poolId, uint64 wrongPoolId, string memory tokenName, string memory tokenSymbol, bytes16 trancheId, uint128 price) public { + vm.assume(poolId != wrongPoolId); + // 0. Add Pool + homeConnector.addPool(poolId); + (uint64 actualPoolId,) = bridgedConnector.pools(poolId); + assertEq(uint256(actualPoolId), uint256(poolId)); + + // 1. Add the tranche + homeConnector.addTranche(poolId, trancheId, tokenName, tokenSymbol, price); + // 2. Then deploy the tranche + vm.expectRevert(bytes("CentrifugeConnector/invalid-pool-or-tranche")); + bridgedConnector.deployTranche(wrongPoolId, trancheId); + } + function testUpdatingMemberWorks(uint64 poolId, bytes16 trancheId, address user, uint64 validUntil) public { vm.assume(validUntil >= safeAdd(block.timestamp, new Memberlist().minimumDelay())); vm.assume(user != address(0));