Skip to content

Commit

Permalink
test setContractURI
Browse files Browse the repository at this point in the history
  • Loading branch information
kumaryash90 committed Oct 27, 2023
1 parent cb78667 commit 7081f85
Show file tree
Hide file tree
Showing 2 changed files with 93 additions and 0 deletions.
85 changes: 85 additions & 0 deletions src/test/split-BTT/set-contract-uri/setContractURI.t.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
// SPDX-License-Identifier: Apache-2.0
pragma solidity ^0.8.11;

import "../../utils/BaseTest.sol";

import { TWProxy } from "contracts/infra/TWProxy.sol";

contract MySplit is Split {}

contract SplitTest_SetContractURI is BaseTest {
address payable public implementation;
address payable public proxy;

address[] public payees;
uint256[] public shares;

address internal caller;
string internal _contractURI;

MySplit internal splitContract;

function setUp() public override {
super.setUp();

// Deploy implementation.
implementation = payable(address(new MySplit()));

// create 5 payees and shares
for (uint160 i = 0; i < 5; i++) {
payees.push(getActor(i + 100));
shares.push(i + 100);
}

caller = getActor(1);

// Deploy proxy pointing to implementaion.
vm.prank(deployer);
proxy = payable(
address(
new TWProxy(
implementation,
abi.encodeCall(Split.initialize, (deployer, CONTRACT_URI, forwarders(), payees, shares))
)
)
);

splitContract = MySplit(proxy);
_contractURI = "ipfs://contracturi";
}

function test_setContractURI_callerNotAuthorized() public {
vm.prank(address(caller));
vm.expectRevert(
abi.encodePacked(
"AccessControl: account ",
TWStrings.toHexString(uint160(caller), 20),
" is missing role ",
TWStrings.toHexString(uint256(0), 32)
)
);
splitContract.setContractURI(_contractURI);
}

modifier whenCallerAuthorized() {
vm.prank(deployer);
splitContract.grantRole(bytes32(0x00), caller);
_;
}

function test_setContractURI_empty() public whenCallerAuthorized {
vm.prank(address(caller));
splitContract.setContractURI("");

// get contract uri
assertEq(splitContract.contractURI(), "");
}

function test_setContractURI_notEmpty() public whenCallerAuthorized {
vm.prank(address(caller));
splitContract.setContractURI(_contractURI);

// get contract uri
assertEq(splitContract.contractURI(), _contractURI);
}
}
8 changes: 8 additions & 0 deletions src/test/split-BTT/set-contract-uri/setContractURI.tree
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
setContractURI(string calldata _uri)
├── when caller not authorized
│ └── it should revert ✅
└── when caller is authorized
└── when `uri` is empty
│ └── it should update contract URI to empty string ✅
└── when `uri` is not empty
└── it should update contract URI to `_uri` ✅

0 comments on commit 7081f85

Please sign in to comment.