Commit 64b5e336 authored by James Kim's avatar James Kim

fix comments

parent 9884fb31
...@@ -40,6 +40,9 @@ contract Optimist_Initializer is Test { ...@@ -40,6 +40,9 @@ contract Optimist_Initializer is Test {
address internal bob; address internal bob;
address internal sally; address internal sally;
/**
* @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[]
...@@ -61,6 +64,9 @@ contract Optimist_Initializer is Test { ...@@ -61,6 +64,9 @@ contract Optimist_Initializer is Test {
attestationStation.attest(attestationData); attestationStation.attest(attestationData);
} }
/**
* @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[]
...@@ -81,6 +87,9 @@ contract Optimist_Initializer is Test { ...@@ -81,6 +87,9 @@ contract Optimist_Initializer is Test {
assertTrue(optimist.isOnAllowList(_about)); assertTrue(optimist.isOnAllowList(_about));
} }
/**
* @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[]
...@@ -101,6 +110,9 @@ contract Optimist_Initializer is Test { ...@@ -101,6 +110,9 @@ contract Optimist_Initializer is Test {
assertTrue(optimist.isOnAllowList(_about)); assertTrue(optimist.isOnAllowList(_about));
} }
/**
* @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);
...@@ -162,6 +174,7 @@ contract Optimist_Initializer is Test { ...@@ -162,6 +174,7 @@ contract Optimist_Initializer is Test {
optimistInviter.initialize("OptimistInviter"); optimistInviter.initialize("OptimistInviter");
// Initialize the helper which helps sign EIP-712 signatures
optimistInviterHelper = new OptimistInviterHelper(optimistInviter, "OptimistInviter"); optimistInviterHelper = new OptimistInviterHelper(optimistInviter, "OptimistInviter");
optimistAllowlist = new OptimistAllowlist({ optimistAllowlist = new OptimistAllowlist({
...@@ -181,7 +194,7 @@ contract Optimist_Initializer is Test { ...@@ -181,7 +194,7 @@ contract Optimist_Initializer is Test {
} }
/** /**
* @notice Returns address as uint256 * @notice Returns address as uint256.
*/ */
function _getTokenId(address _owner) internal pure returns (uint256) { function _getTokenId(address _owner) internal pure returns (uint256) {
return uint256(uint160(address(_owner))); return uint256(uint160(address(_owner)));
...@@ -197,12 +210,12 @@ contract OptimistTest is Optimist_Initializer { ...@@ -197,12 +210,12 @@ contract OptimistTest is Optimist_Initializer {
// expect attestationStation to be set // expect attestationStation to be set
assertEq(address(optimist.ATTESTATION_STATION()), address(attestationStation)); assertEq(address(optimist.ATTESTATION_STATION()), address(attestationStation));
assertEq(optimist.BASE_URI_ATTESTOR(), carol_baseURIAttestor); assertEq(optimist.BASE_URI_ATTESTOR(), carol_baseURIAttestor);
assertEq(optimist.version(), "1.0.0"); assertEq(optimist.version(), "1.1.0");
} }
/** /**
* @notice Bob should be able to mint an NFT if he is allowlisted * @notice Bob should be able to mint an NFT if he is allowlisted
* by the allowlistAttestor and has a balance of 0 * by the allowlistAttestor and has a balance of 0.
*/ */
function test_mint_afterAllowlistAttestation_succeeds() external { function test_mint_afterAllowlistAttestation_succeeds() external {
// bob should start with 0 balance // bob should start with 0 balance
...@@ -230,7 +243,7 @@ contract OptimistTest is Optimist_Initializer { ...@@ -230,7 +243,7 @@ contract OptimistTest is Optimist_Initializer {
/** /**
* @notice Bob should be able to mint an NFT if he claimed an invite through OptimistInviter * @notice Bob should be able to mint an NFT if he claimed an invite through OptimistInviter
* and has a balance of 0 * and has a balance of 0.
*/ */
function test_mint_afterInviteClaimed_succeeds() external { function test_mint_afterInviteClaimed_succeeds() external {
// bob should start with 0 balance // bob should start with 0 balance
...@@ -257,8 +270,8 @@ contract OptimistTest is Optimist_Initializer { ...@@ -257,8 +270,8 @@ contract OptimistTest is Optimist_Initializer {
} }
/** /**
* @notice Bob should be able to mint an NFT if he claimed an invite through OptimistInviter * @notice Bob should be able to mint an NFT if he has an attestation from Coinbase Quest
* and has a balance of 0 * attestor and has a balance of 0.
*/ */
function test_mint_afterCoinbaseQuestAttestation_succeeds() external { function test_mint_afterCoinbaseQuestAttestation_succeeds() external {
// bob should start with 0 balance // bob should start with 0 balance
...@@ -285,7 +298,40 @@ contract OptimistTest is Optimist_Initializer { ...@@ -285,7 +298,40 @@ contract OptimistTest is Optimist_Initializer {
} }
/** /**
* @notice Sally should be able to mint a token on behalf of bob * @notice Multiple valid attestations should allow Bob to mint.
*/
function test_mint_afterMultipleAttestations_succeeds() external {
// bob should start with 0 balance
assertEq(optimist.balanceOf(bob), 0);
// bob receives attestation from Coinbase Quest attestor
attestCoinbaseQuest(bob);
// allowlist bob
attestAllowlist(bob);
// bob claims an invite
inviteAndClaim(bob);
assertTrue(optimistAllowlist.isAllowedToMint(bob));
// Check that the OptimistAllowlist is checked
bytes memory data = abi.encodeWithSelector(optimistAllowlist.isAllowedToMint.selector, bob);
vm.expectCall(address(optimistAllowlist), data);
// mint an NFT and expect mint transfer event to be emitted
vm.expectEmit(true, true, true, true);
emit Transfer(address(0), bob, _getTokenId(bob));
vm.prank(bob);
optimist.mint(bob);
// expect the NFT to be owned by bob
assertEq(optimist.ownerOf(_getTokenId(bob)), bob);
assertEq(optimist.balanceOf(bob), 1);
}
/**
* @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(); bytes32 allowlistAttestationKey = optimistAllowlist.OPTIMIST_CAN_MINT_ATTESTATION_KEY();
...@@ -313,7 +359,7 @@ contract OptimistTest is Optimist_Initializer { ...@@ -313,7 +359,7 @@ contract OptimistTest is Optimist_Initializer {
} }
/** /**
* @notice Bob should not be able to mint an NFT if he is not allowlisted * @notice Bob should not be able to mint an NFT if he is not allowlisted.
*/ */
function test_mint_forNonAllowlistedClaimer_reverts() external { function test_mint_forNonAllowlistedClaimer_reverts() external {
vm.prank(bob); vm.prank(bob);
...@@ -322,7 +368,7 @@ contract OptimistTest is Optimist_Initializer { ...@@ -322,7 +368,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);
...@@ -340,7 +386,7 @@ contract OptimistTest is Optimist_Initializer { ...@@ -340,7 +386,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);
...@@ -359,7 +405,7 @@ contract OptimistTest is Optimist_Initializer { ...@@ -359,7 +405,7 @@ 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); attestAllowlist(bob);
...@@ -379,7 +425,7 @@ contract OptimistTest is Optimist_Initializer { ...@@ -379,7 +425,7 @@ contract OptimistTest is Optimist_Initializer {
} }
/** /**
* @notice Should return a boolean of if the address is allowlisted * @notice Should return a boolean of if the address is allowlisted.
*/ */
function test_isOnAllowlist_returnsTrueForAllowlistedAddresses_succeeds() external { function test_isOnAllowlist_returnsTrueForAllowlistedAddresses_succeeds() external {
attestAllowlist(bob); attestAllowlist(bob);
...@@ -407,7 +453,7 @@ contract OptimistTest is Optimist_Initializer { ...@@ -407,7 +453,7 @@ contract OptimistTest is Optimist_Initializer {
} }
/** /**
* @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 // allowlist bob
...@@ -422,7 +468,7 @@ contract OptimistTest is Optimist_Initializer { ...@@ -422,7 +468,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); attestAllowlist(bob);
...@@ -447,7 +493,7 @@ contract OptimistTest is Optimist_Initializer { ...@@ -447,7 +493,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); attestAllowlist(bob);
...@@ -465,7 +511,7 @@ contract OptimistTest is Optimist_Initializer { ...@@ -465,7 +511,7 @@ contract OptimistTest is Optimist_Initializer {
} }
/** /**
* @notice It should be able to burn token * @notice It should be able to burn token.
*/ */
function test_burn_byOwner_succeeds() external { function test_burn_byOwner_succeeds() external {
attestAllowlist(bob); attestAllowlist(bob);
...@@ -483,7 +529,7 @@ contract OptimistTest is Optimist_Initializer { ...@@ -483,7 +529,7 @@ contract OptimistTest is Optimist_Initializer {
} }
/** /**
* @notice setApprovalForAll should revert as sbt * @notice setApprovalForAll should revert since Optimist is a SBT.
*/ */
function test_setApprovalForAll_reverts() external { function test_setApprovalForAll_reverts() external {
attestAllowlist(bob); attestAllowlist(bob);
...@@ -505,7 +551,7 @@ contract OptimistTest is Optimist_Initializer { ...@@ -505,7 +551,7 @@ contract OptimistTest is Optimist_Initializer {
} }
/** /**
* @notice should support erc721 interface * @notice should 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;
......
...@@ -37,7 +37,7 @@ contract Optimist is ERC721BurnableUpgradeable, Semver { ...@@ -37,7 +37,7 @@ contract Optimist is ERC721BurnableUpgradeable, Semver {
OptimistAllowlist public immutable OPTIMIST_ALLOWLIST; OptimistAllowlist public immutable OPTIMIST_ALLOWLIST;
/** /**
* @custom:semver 1.0.0 * @custom:semver 1.1.0
* @param _name Token name. * @param _name Token name.
* @param _symbol Token symbol. * @param _symbol Token symbol.
* @param _baseURIAttestor Address of the baseURI attestor. * @param _baseURIAttestor Address of the baseURI attestor.
...@@ -50,7 +50,7 @@ contract Optimist is ERC721BurnableUpgradeable, Semver { ...@@ -50,7 +50,7 @@ contract Optimist is ERC721BurnableUpgradeable, Semver {
address _baseURIAttestor, address _baseURIAttestor,
AttestationStation _attestationStation, AttestationStation _attestationStation,
OptimistAllowlist _optimistAllowlist OptimistAllowlist _optimistAllowlist
) Semver(1, 0, 0) { ) Semver(1, 1, 0) {
BASE_URI_ATTESTOR = _baseURIAttestor; BASE_URI_ATTESTOR = _baseURIAttestor;
ATTESTATION_STATION = _attestationStation; ATTESTATION_STATION = _attestationStation;
OPTIMIST_ALLOWLIST = _optimistAllowlist; OPTIMIST_ALLOWLIST = _optimistAllowlist;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment