Skip to content

Commit

Permalink
Add TODO and more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
AStox committed Feb 8, 2023
1 parent 54dd4bb commit 695f1f0
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/Connector.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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;

Expand Down
28 changes: 28 additions & 0 deletions test/Connector.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down

0 comments on commit 695f1f0

Please sign in to comment.