From 51dd601a384b594aaa5a57e9bd489ea985c5ef0a Mon Sep 17 00:00:00 2001 From: Ben Sparks <52714090+BenSparksCode@users.noreply.github.com> Date: Thu, 1 Dec 2022 15:32:38 +0200 Subject: [PATCH] feat: Added more collect tests --- test/foundry/CollectingTest.t.sol | 34 +++++++++---------------------- test/foundry/base/BaseTest.t.sol | 9 ++++++++ 2 files changed, 19 insertions(+), 24 deletions(-) diff --git a/test/foundry/CollectingTest.t.sol b/test/foundry/CollectingTest.t.sol index 299194a..2fb8c6a 100644 --- a/test/foundry/CollectingTest.t.sol +++ b/test/foundry/CollectingTest.t.sol @@ -212,36 +212,22 @@ contract CollectingTest_WithSig is CollectingTest_Base { _mockCollectWithSig({delegatedSigner: address(0), signerPrivKey: profileOwnerKey}); } - function testCannotCollectWithSigIfNonceWasIncrementedWithAnotherAction() public { - // TODO clean up - address delegatedSigner = address(0); - uint256 signerPrivKey = profileOwnerKey; - + function testCannotCollectIfNonceWasIncrementedWithAnotherAction() public { assertEq(_getSigNonce(profileOwner), nonce, 'Wrong nonce before posting'); - // cancel with permitForAll + uint256 expectedCollectId = _getCollectCount(firstProfileId, mockCollectData.pubId) + 1; - // bytes32 collectDigest = _getCollectTypedDataHash( - // mockCollectData.profileId, - // mockCollectData.pubId, - // mockCollectData.data, - // nonce, - // deadline - // ); + uint256 nftId = _mockCollectWithSig({ + delegatedSigner: address(0), + signerPrivKey: profileOwnerKey + }); - // hub.permitForAll(); + assertEq(nftId, expectedCollectId, 'Wrong collectId'); - // _collectWithSig( - // _buildCollectWithSigData( - // delegatedSigner, - // mockCollectData, - // _getSigStruct(signerPrivKey, collectDigest, deadline) - // ) - // ); + assertTrue(_getSigNonce(profileOwner) != nonce, 'Wrong nonce after collecting'); - // // TODO fix - // vm.expectRevert(Errors.SignatureInvalid.selector); - // _mockCollectWithSig({delegatedSigner: address(0), signerPrivKey: otherSignerKey}); + vm.expectRevert(Errors.SignatureInvalid.selector); + _mockCollectWithSig({delegatedSigner: address(0), signerPrivKey: profileOwnerKey}); } // SCENARIOS diff --git a/test/foundry/base/BaseTest.t.sol b/test/foundry/base/BaseTest.t.sol index 464114b..f050ba9 100644 --- a/test/foundry/base/BaseTest.t.sol +++ b/test/foundry/base/BaseTest.t.sol @@ -393,4 +393,13 @@ contract BaseTest is TestSetup { function _getPubCount(uint256 profileId) internal view returns (uint256) { return hub.getPubCount(profileId); } + + function _getCollectCount(uint256 profileId, uint256 pubId) internal view returns (uint256) { + address collectNft = hub.getCollectNFT(profileId, pubId); + if (collectNft == address(0)) { + return 0; + } else { + return CollectNFT(collectNft).totalSupply(); + } + } }