Skip to content

BTT: OpenEditionERC721 #545

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 16 commits into from
Oct 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
// SPDX-License-Identifier: Apache-2.0
pragma solidity ^0.8.0;

import { OpenEditionERC721 } from "contracts/prebuilts/open-edition/OpenEditionERC721.sol";
import { TWProxy } from "contracts/infra/TWProxy.sol";

// Test imports
import "src/test/utils/BaseTest.sol";

contract OpenEditionERC721Harness is OpenEditionERC721 {
function beforeTokenTransfers(
address from,
address to,
uint256 startTokenId_,
uint256 quantity
) public {
_beforeTokenTransfers(from, to, startTokenId_, quantity);
}
}

contract OpenEditionERC721Test_beforeTokenTransfers is BaseTest {
OpenEditionERC721Harness public openEdition;

address private openEditionImpl;

function setUp() public override {
super.setUp();
openEditionImpl = address(new OpenEditionERC721Harness());
vm.prank(deployer);
openEdition = OpenEditionERC721Harness(
address(
new TWProxy(
openEditionImpl,
abi.encodeCall(
OpenEditionERC721.initialize,
(
deployer,
NAME,
SYMBOL,
CONTRACT_URI,
forwarders(),
saleRecipient,
royaltyRecipient,
royaltyBps
)
)
)
)
);
}

/*///////////////////////////////////////////////////////////////
Unit tests: misc
//////////////////////////////////////////////////////////////*/

function test_revert_transfersRestricted() public {
address from = address(0x1);
address to = address(0x2);
bytes32 role = keccak256("TRANSFER_ROLE");
vm.prank(deployer);
openEdition.revokeRole(role, address(0));

vm.expectRevert(bytes("!T"));
openEdition.beforeTokenTransfers(from, to, 0, 1);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
function _beforeTokenTransfers(
address from,
address to,
uint256 startTokenId_,
uint256 quantity
)
└── when address(0) does not have the transfer role
└── when from does not equal address(0)
└── when to does not equal address(0)
└── when from does not have the transfer role
└── when to does not have the transfer role
└── it should revert ✅
128 changes: 128 additions & 0 deletions src/test/open-edition/_canSetFunctions/_canSetFunctions.t.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
// SPDX-License-Identifier: Apache-2.0
pragma solidity ^0.8.0;

import { OpenEditionERC721 } from "contracts/prebuilts/open-edition/OpenEditionERC721.sol";
import { TWProxy } from "contracts/infra/TWProxy.sol";

// Test imports
import "src/test/utils/BaseTest.sol";

contract OpenEditionERC721Harness is OpenEditionERC721 {
function canSetPrimarySaleRecipient() external view returns (bool) {
return _canSetPrimarySaleRecipient();
}

function canSetOwner() external view returns (bool) {
return _canSetOwner();
}

/// @dev Checks whether royalty info can be set in the given execution context.
function canSetRoyaltyInfo() external view returns (bool) {
return _canSetRoyaltyInfo();
}

/// @dev Checks whether contract metadata can be set in the given execution context.
function canSetContractURI() external view returns (bool) {
return _canSetContractURI();
}

/// @dev Checks whether platform fee info can be set in the given execution context.
function canSetClaimConditions() external view returns (bool) {
return _canSetClaimConditions();
}

/// @dev Returns whether the shared metadata of tokens can be set in the given execution context.
function canSetSharedMetadata() external view virtual returns (bool) {
return _canSetSharedMetadata();
}
}

contract OpenEditionERC721Test_canSetFunctions is BaseTest {
OpenEditionERC721Harness public openEdition;

address private openEditionImpl;

function setUp() public override {
super.setUp();
openEditionImpl = address(new OpenEditionERC721Harness());
vm.prank(deployer);
openEdition = OpenEditionERC721Harness(
address(
new TWProxy(
openEditionImpl,
abi.encodeCall(
OpenEditionERC721.initialize,
(
deployer,
NAME,
SYMBOL,
CONTRACT_URI,
forwarders(),
saleRecipient,
royaltyRecipient,
royaltyBps
)
)
)
)
);
}

/*///////////////////////////////////////////////////////////////
Unit tests: misc
//////////////////////////////////////////////////////////////*/

function test_canSetPrimarySaleRecipient_returnTrue() public {
vm.prank(deployer);
assertTrue(openEdition.canSetPrimarySaleRecipient());
}

function test_canSetPrimarySaleRecipient_returnFalse() public {
assertFalse(openEdition.canSetPrimarySaleRecipient());
}

function test_canSetOwner_returnTrue() public {
vm.prank(deployer);
assertTrue(openEdition.canSetOwner());
}

function test_canSetOwner_returnFalse() public {
assertFalse(openEdition.canSetOwner());
}

function test_canSetRoyaltyInfo_returnTrue() public {
vm.prank(deployer);
assertTrue(openEdition.canSetRoyaltyInfo());
}

function test_canSetRoyaltyInfo_returnFalse() public {
assertFalse(openEdition.canSetRoyaltyInfo());
}

function test_canSetContractURI_returnTrue() public {
vm.prank(deployer);
assertTrue(openEdition.canSetContractURI());
}

function test_canSetContractURI_returnFalse() public {
assertFalse(openEdition.canSetContractURI());
}

function test_canSetClaimConditions_returnTrue() public {
vm.prank(deployer);
assertTrue(openEdition.canSetClaimConditions());
}

function test_canSetClaimConditions_returnFalse() public {
assertFalse(openEdition.canSetClaimConditions());
}

function test_canSetSharedMetadata_returnTrue() public {
vm.prank(deployer);
assertTrue(openEdition.canSetSharedMetadata());
}

function test_canSetSharedMetadata_returnFalse() public {
assertFalse(openEdition.canSetSharedMetadata());
}
}
39 changes: 39 additions & 0 deletions src/test/open-edition/_canSetFunctions/_canSetFunctions.tree
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
function _canSetPrimarySaleRecipient()
├── when _msgSender has DEFAULT_ADMIN_ROLE
│ └── it should return true ✅
└── when _msgSender does not have DEFAULT_ADMIN_ROLE
└── it should return false ✅

function _canSetOwner()
├── when _msgSender has DEFAULT_ADMIN_ROLE
│ └── it should return true ✅
└── when _msgSender does not have DEFAULT_ADMIN_ROLE
└── it should return false ✅


function _canSetRoyaltyInfo()
├── when _msgSender has DEFAULT_ADMIN_ROLE
│ └── it should return true ✅
└── when _msgSender does not have DEFAULT_ADMIN_ROLE
└── it should return false ✅


function _canSetContractURI()
├── when _msgSender has DEFAULT_ADMIN_ROLE
│ └── it should return true ✅
└── when _msgSender does not have DEFAULT_ADMIN_ROLE
└── it should return false ✅


function _canSetClaimConditions()
├── when _msgSender has DEFAULT_ADMIN_ROLE
│ └── it should return true ✅
└── when _msgSender does not have DEFAULT_ADMIN_ROLE
└── it should return false ✅


function _canSetSharedMetadata()
├── when _msgSender has minter role
│ └── it should return true ✅
└── when _msgSender does not have minter role
└── it should return false ✅
Loading