From 7081f8513cce39976d077ae1b65759ff22ec1786 Mon Sep 17 00:00:00 2001 From: Yash Date: Sat, 28 Oct 2023 03:23:08 +0530 Subject: [PATCH] test setContractURI --- .../set-contract-uri/setContractURI.t.sol | 85 +++++++++++++++++++ .../set-contract-uri/setContractURI.tree | 8 ++ 2 files changed, 93 insertions(+) create mode 100644 src/test/split-BTT/set-contract-uri/setContractURI.t.sol create mode 100644 src/test/split-BTT/set-contract-uri/setContractURI.tree diff --git a/src/test/split-BTT/set-contract-uri/setContractURI.t.sol b/src/test/split-BTT/set-contract-uri/setContractURI.t.sol new file mode 100644 index 000000000..4a9da18b4 --- /dev/null +++ b/src/test/split-BTT/set-contract-uri/setContractURI.t.sol @@ -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); + } +} diff --git a/src/test/split-BTT/set-contract-uri/setContractURI.tree b/src/test/split-BTT/set-contract-uri/setContractURI.tree new file mode 100644 index 000000000..8fc480b19 --- /dev/null +++ b/src/test/split-BTT/set-contract-uri/setContractURI.tree @@ -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` ✅ \ No newline at end of file