Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
N
nebula
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
exchain
nebula
Commits
c6cd3881
Commit
c6cd3881
authored
Mar 31, 2023
by
James Kim
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
use mock calls
parent
64b5e336
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
61 additions
and
70 deletions
+61
-70
Optimist.t.sol
...ontracts-periphery/contracts/foundry-tests/Optimist.t.sol
+61
-70
No files found.
packages/contracts-periphery/contracts/foundry-tests/Optimist.t.sol
View file @
c6cd3881
...
@@ -43,7 +43,7 @@ contract Optimist_Initializer is Test {
...
@@ -43,7 +43,7 @@ contract Optimist_Initializer is Test {
/**
/**
* @notice BaseURI attestor sets the baseURI of the Optimist NFT.
* @notice BaseURI attestor sets the baseURI of the Optimist NFT.
*/
*/
function attestBaseURI(string memory _baseUri) internal {
function
_
attestBaseURI(string memory _baseUri) internal {
bytes32 baseURIAttestationKey = optimist.BASE_URI_ATTESTATION_KEY();
bytes32 baseURIAttestationKey = optimist.BASE_URI_ATTESTATION_KEY();
AttestationStation.AttestationData[]
AttestationStation.AttestationData[]
memory attestationData = new AttestationStation.AttestationData[](1);
memory attestationData = new AttestationStation.AttestationData[](1);
...
@@ -67,7 +67,7 @@ contract Optimist_Initializer is Test {
...
@@ -67,7 +67,7 @@ contract Optimist_Initializer is Test {
/**
/**
* @notice Allowlist attestor creates an attestation for an address.
* @notice Allowlist attestor creates an attestation for an address.
*/
*/
function attestAllowlist(address _about) internal {
function
_
attestAllowlist(address _about) internal {
bytes32 attestationKey = optimistAllowlist.OPTIMIST_CAN_MINT_ATTESTATION_KEY();
bytes32 attestationKey = optimistAllowlist.OPTIMIST_CAN_MINT_ATTESTATION_KEY();
AttestationStation.AttestationData[]
AttestationStation.AttestationData[]
memory attestationData = new AttestationStation.AttestationData[](1);
memory attestationData = new AttestationStation.AttestationData[](1);
...
@@ -90,7 +90,7 @@ contract Optimist_Initializer is Test {
...
@@ -90,7 +90,7 @@ contract Optimist_Initializer is Test {
/**
/**
* @notice Coinbase Quest attestor creates an attestation for an address.
* @notice Coinbase Quest attestor creates an attestation for an address.
*/
*/
function attestCoinbaseQuest(address _about) internal {
function
_
attestCoinbaseQuest(address _about) internal {
bytes32 attestationKey = optimistAllowlist.COINBASE_QUEST_ELIGIBLE_ATTESTATION_KEY();
bytes32 attestationKey = optimistAllowlist.COINBASE_QUEST_ELIGIBLE_ATTESTATION_KEY();
AttestationStation.AttestationData[]
AttestationStation.AttestationData[]
memory attestationData = new AttestationStation.AttestationData[](1);
memory attestationData = new AttestationStation.AttestationData[](1);
...
@@ -113,7 +113,7 @@ contract Optimist_Initializer is Test {
...
@@ -113,7 +113,7 @@ contract Optimist_Initializer is Test {
/**
/**
* @notice Issues invite, then claims it using the claimer's address.
* @notice Issues invite, then claims it using the claimer's address.
*/
*/
function inviteAndClaim(address _about) internal {
function
_
inviteAndClaim(address _about) internal {
uint256 inviterPrivateKey = 0xbeefbeef;
uint256 inviterPrivateKey = 0xbeefbeef;
address inviter = vm.addr(inviterPrivateKey);
address inviter = vm.addr(inviterPrivateKey);
...
@@ -152,6 +152,24 @@ contract Optimist_Initializer is Test {
...
@@ -152,6 +152,24 @@ contract Optimist_Initializer is Test {
assertTrue(optimist.isOnAllowList(_about));
assertTrue(optimist.isOnAllowList(_about));
}
}
/**
* @notice Mocks the allowlistAttestor to always return true for a given address.
*/
function _mockAllowlistTrueFor(address _claimer) internal {
vm.mockCall(
address(optimistAllowlist),
abi.encodeWithSelector(OptimistAllowlist.isAllowedToMint.selector, _claimer),
abi.encode(true)
);
}
/**
* @notice Returns address as uint256.
*/
function _getTokenId(address _owner) internal pure returns (uint256) {
return uint256(uint160(address(_owner)));
}
function setUp() public {
function setUp() public {
carol_baseURIAttestor = makeAddr("carol_baseURIAttestor");
carol_baseURIAttestor = makeAddr("carol_baseURIAttestor");
alice_allowlistAttestor = makeAddr("alice_allowlistAttestor");
alice_allowlistAttestor = makeAddr("alice_allowlistAttestor");
...
@@ -192,13 +210,6 @@ contract Optimist_Initializer is Test {
...
@@ -192,13 +210,6 @@ contract Optimist_Initializer is Test {
_optimistAllowlist: optimistAllowlist
_optimistAllowlist: optimistAllowlist
});
});
}
}
/**
* @notice Returns address as uint256.
*/
function _getTokenId(address _owner) internal pure returns (uint256) {
return uint256(uint160(address(_owner)));
}
}
}
contract OptimistTest is Optimist_Initializer {
contract OptimistTest is Optimist_Initializer {
...
@@ -222,7 +233,7 @@ contract OptimistTest is Optimist_Initializer {
...
@@ -222,7 +233,7 @@ contract OptimistTest is Optimist_Initializer {
assertEq(optimist.balanceOf(bob), 0);
assertEq(optimist.balanceOf(bob), 0);
// allowlist bob
// allowlist bob
attestAllowlist(bob);
_
attestAllowlist(bob);
assertTrue(optimistAllowlist.isAllowedToMint(bob));
assertTrue(optimistAllowlist.isAllowedToMint(bob));
...
@@ -250,7 +261,7 @@ contract OptimistTest is Optimist_Initializer {
...
@@ -250,7 +261,7 @@ contract OptimistTest is Optimist_Initializer {
assertEq(optimist.balanceOf(bob), 0);
assertEq(optimist.balanceOf(bob), 0);
// bob claims an invite
// bob claims an invite
inviteAndClaim(bob);
_
inviteAndClaim(bob);
assertTrue(optimistAllowlist.isAllowedToMint(bob));
assertTrue(optimistAllowlist.isAllowedToMint(bob));
...
@@ -278,7 +289,7 @@ contract OptimistTest is Optimist_Initializer {
...
@@ -278,7 +289,7 @@ contract OptimistTest is Optimist_Initializer {
assertEq(optimist.balanceOf(bob), 0);
assertEq(optimist.balanceOf(bob), 0);
// bob receives attestation from Coinbase Quest attestor
// bob receives attestation from Coinbase Quest attestor
attestCoinbaseQuest(bob);
_
attestCoinbaseQuest(bob);
assertTrue(optimistAllowlist.isAllowedToMint(bob));
assertTrue(optimistAllowlist.isAllowedToMint(bob));
...
@@ -305,13 +316,13 @@ contract OptimistTest is Optimist_Initializer {
...
@@ -305,13 +316,13 @@ contract OptimistTest is Optimist_Initializer {
assertEq(optimist.balanceOf(bob), 0);
assertEq(optimist.balanceOf(bob), 0);
// bob receives attestation from Coinbase Quest attestor
// bob receives attestation from Coinbase Quest attestor
attestCoinbaseQuest(bob);
_
attestCoinbaseQuest(bob);
// allowlist bob
// allowlist bob
attestAllowlist(bob);
_
attestAllowlist(bob);
// bob claims an invite
// bob claims an invite
inviteAndClaim(bob);
_
inviteAndClaim(bob);
assertTrue(optimistAllowlist.isAllowedToMint(bob));
assertTrue(optimistAllowlist.isAllowedToMint(bob));
...
@@ -334,20 +345,10 @@ contract OptimistTest is Optimist_Initializer {
...
@@ -334,20 +345,10 @@ contract OptimistTest is Optimist_Initializer {
* @notice Sally should be able to mint a token on behalf of bob.
* @notice Sally should be able to mint a token on behalf of bob.
*/
*/
function test_mint_secondaryMinter_succeeds() external {
function test_mint_secondaryMinter_succeeds() external {
bytes32 allowlistAttestationKey = optimistAllowlist.OPTIMIST_CAN_MINT_ATTESTATION_KEY();
_mockAllowlistTrueFor(bob);
attestAllowlist(bob);
bytes memory data = abi.encodeWithSelector(
attestationStation.attestations.selector,
alice_allowlistAttestor,
bob,
allowlistAttestationKey
);
vm.expectCall(address(attestationStation), data);
uint256 tokenId = uint256(uint160(bob));
vm.expectEmit(true, true, true, true);
vm.expectEmit(true, true, true, true);
emit Transfer(address(0), bob,
tokenId
);
emit Transfer(address(0), bob,
_getTokenId(bob)
);
// mint as sally instead of bob
// mint as sally instead of bob
vm.prank(sally);
vm.prank(sally);
...
@@ -371,7 +372,7 @@ contract OptimistTest is Optimist_Initializer {
...
@@ -371,7 +372,7 @@ contract OptimistTest is Optimist_Initializer {
* @notice Bob's tx should revert if he already minted.
* @notice Bob's tx should revert if he already minted.
*/
*/
function test_mint_forAlreadyMintedClaimer_reverts() external {
function test_mint_forAlreadyMintedClaimer_reverts() external {
attestAllowlist(bob);
_
attestAllowlist(bob);
// mint initial nft with bob
// mint initial nft with bob
vm.prank(bob);
vm.prank(bob);
...
@@ -389,7 +390,7 @@ contract OptimistTest is Optimist_Initializer {
...
@@ -389,7 +390,7 @@ contract OptimistTest is Optimist_Initializer {
* @notice The baseURI should be set by attestation station by the baseURIAttestor.
* @notice The baseURI should be set by attestation station by the baseURIAttestor.
*/
*/
function test_baseURI_returnsCorrectBaseURI_succeeds() external {
function test_baseURI_returnsCorrectBaseURI_succeeds() external {
attestBaseURI(base_uri);
_
attestBaseURI(base_uri);
bytes memory data = abi.encodeWithSelector(
bytes memory data = abi.encodeWithSelector(
attestationStation.attestations.selector,
attestationStation.attestations.selector,
...
@@ -408,11 +409,11 @@ contract OptimistTest is Optimist_Initializer {
...
@@ -408,11 +409,11 @@ contract OptimistTest is Optimist_Initializer {
* @notice The tokenURI should return the token uri for a minted token.
* @notice The tokenURI should return the token uri for a minted token.
*/
*/
function test_tokenURI_returnsCorrectTokenURI_succeeds() external {
function test_tokenURI_returnsCorrectTokenURI_succeeds() external {
attestAllowlist(bob);
// we are using true but it can be any non empty value
// we are using true but it can be any non empty value
attestBaseURI(base_uri);
_
attestBaseURI(base_uri);
// mint an NFT
// mint an NFT
_mockAllowlistTrueFor(bob);
vm.prank(bob);
vm.prank(bob);
optimist.mint(bob);
optimist.mint(bob);
...
@@ -424,43 +425,14 @@ contract OptimistTest is Optimist_Initializer {
...
@@ -424,43 +425,14 @@ contract OptimistTest is Optimist_Initializer {
);
);
}
}
/**
* @notice Should return a boolean of if the address is allowlisted.
*/
function test_isOnAllowlist_returnsTrueForAllowlistedAddresses_succeeds() external {
attestAllowlist(bob);
bytes32 allowlistAttestationKey = optimistAllowlist.OPTIMIST_CAN_MINT_ATTESTATION_KEY();
bytes memory data = abi.encodeWithSelector(
attestationStation.attestations.selector,
alice_allowlistAttestor,
bob,
allowlistAttestationKey
);
vm.expectCall(address(attestationStation), data);
// assert bob is allowlisted
assertEq(optimist.isOnAllowList(bob), true);
data = abi.encodeWithSelector(
attestationStation.attestations.selector,
alice_allowlistAttestor,
sally,
allowlistAttestationKey
);
vm.expectCall(address(attestationStation), data);
// assert sally is not allowlisted
assertEq(optimist.isOnAllowList(sally), false);
}
/**
/**
* @notice Should return the token id of the owner.
* @notice Should return the token id of the owner.
*/
*/
function test_tokenIdOfAddress_returnsOwnerID_succeeds() external {
function test_tokenIdOfAddress_returnsOwnerID_succeeds() external {
// allowlist bob
uint256 willTokenId = 1024;
uint256 willTokenId = 1024;
address will = address(1024);
address will = address(1024);
attestAllowlist
(will);
_mockAllowlistTrueFor
(will);
optimist.mint(will);
optimist.mint(will);
...
@@ -471,7 +443,7 @@ contract OptimistTest is Optimist_Initializer {
...
@@ -471,7 +443,7 @@ contract OptimistTest is Optimist_Initializer {
* @notice It should revert if anybody attemps token transfer.
* @notice It should revert if anybody attemps token transfer.
*/
*/
function test_transferFrom_reverts() external {
function test_transferFrom_reverts() external {
attestAllowlist
(bob);
_mockAllowlistTrueFor
(bob);
// mint as bob
// mint as bob
vm.prank(bob);
vm.prank(bob);
...
@@ -496,7 +468,7 @@ contract OptimistTest is Optimist_Initializer {
...
@@ -496,7 +468,7 @@ contract OptimistTest is Optimist_Initializer {
* @notice It should revert if anybody attemps approve.
* @notice It should revert if anybody attemps approve.
*/
*/
function test_approve_reverts() external {
function test_approve_reverts() external {
attestAllowlist
(bob);
_mockAllowlistTrueFor
(bob);
// mint as bob
// mint as bob
vm.prank(bob);
vm.prank(bob);
...
@@ -511,10 +483,10 @@ contract OptimistTest is Optimist_Initializer {
...
@@ -511,10 +483,10 @@ contract OptimistTest is Optimist_Initializer {
}
}
/**
/**
* @notice
It
should be able to burn token.
* @notice
Only Owner
should be able to burn token.
*/
*/
function test_burn_byOwner_succeeds() external {
function test_burn_byOwner_succeeds() external {
attestAllowlist
(bob);
_mockAllowlistTrueFor
(bob);
// mint as bob
// mint as bob
vm.prank(bob);
vm.prank(bob);
...
@@ -528,11 +500,30 @@ contract OptimistTest is Optimist_Initializer {
...
@@ -528,11 +500,30 @@ contract OptimistTest is Optimist_Initializer {
assertEq(optimist.balanceOf(bob), 0);
assertEq(optimist.balanceOf(bob), 0);
}
}
/**
* @notice Non-owner attempting to burn token should revert.
*/
function test_burn_byNonOwner_reverts() external {
_mockAllowlistTrueFor(bob);
// mint as bob
vm.prank(bob);
optimist.mint(bob);
vm.expectRevert("ERC721: caller is not token owner nor approved");
// burn as Sally
vm.prank(sally);
optimist.burn(_getTokenId(bob));
// expect bob to have still have the token
assertEq(optimist.balanceOf(bob), 1);
}
/**
/**
* @notice setApprovalForAll should revert since Optimist is a SBT.
* @notice setApprovalForAll should revert since Optimist is a SBT.
*/
*/
function test_setApprovalForAll_reverts() external {
function test_setApprovalForAll_reverts() external {
attestAllowlist
(bob);
_mockAllowlistTrueFor
(bob);
// mint as bob
// mint as bob
vm.prank(bob);
vm.prank(bob);
...
@@ -551,11 +542,11 @@ contract OptimistTest is Optimist_Initializer {
...
@@ -551,11 +542,11 @@ contract OptimistTest is Optimist_Initializer {
}
}
/**
/**
* @notice
s
hould support ERC-721 interface.
* @notice
S
hould support ERC-721 interface.
*/
*/
function test_supportsInterface_returnsCorrectInterfaceForERC721_succeeds() external {
function test_supportsInterface_returnsCorrectInterfaceForERC721_succeeds() external {
bytes4 iface721 = type(IERC721).interfaceId;
bytes4 iface721 = type(IERC721).interfaceId;
// check that it supports
erc
721 interface
// check that it supports
ERC-
721 interface
assertEq(optimist.supportsInterface(iface721), true);
assertEq(optimist.supportsInterface(iface721), true);
}
}
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment