From b42612a856c95551400cde9be0e60ea5914167a1 Mon Sep 17 00:00:00 2001 From: youssefea Date: Sun, 17 Dec 2023 15:15:09 +0100 Subject: [PATCH] add libraries --- .../foundry-tests/lib/openzeppelin-contracts | 2 +- .../lib/superfluid-protocol-monorepo | 2 +- .../foundry-tests/src/AdSpotContract.sol | 20 +- .../foundry-tests/test/AdSpotContract.t.sol | 212 ++++++++++++++---- 4 files changed, 173 insertions(+), 63 deletions(-) diff --git a/projects/gda-advertisement-auction/foundry-tests/lib/openzeppelin-contracts b/projects/gda-advertisement-auction/foundry-tests/lib/openzeppelin-contracts index d155600..fd81a96 160000 --- a/projects/gda-advertisement-auction/foundry-tests/lib/openzeppelin-contracts +++ b/projects/gda-advertisement-auction/foundry-tests/lib/openzeppelin-contracts @@ -1 +1 @@ -Subproject commit d155600d554d28b583a8ab36dee0849215d48a20 +Subproject commit fd81a96f01cc42ef1c9a5399364968d0e07e9e90 diff --git a/projects/gda-advertisement-auction/foundry-tests/lib/superfluid-protocol-monorepo b/projects/gda-advertisement-auction/foundry-tests/lib/superfluid-protocol-monorepo index e5da4ec..b182e1d 160000 --- a/projects/gda-advertisement-auction/foundry-tests/lib/superfluid-protocol-monorepo +++ b/projects/gda-advertisement-auction/foundry-tests/lib/superfluid-protocol-monorepo @@ -1 +1 @@ -Subproject commit e5da4ec5bcd24d3230c9d1ae451999f062365075 +Subproject commit b182e1dac38615d40020947331937d34086aad6a diff --git a/projects/gda-advertisement-auction/foundry-tests/src/AdSpotContract.sol b/projects/gda-advertisement-auction/foundry-tests/src/AdSpotContract.sol index 997775e..5c6162d 100644 --- a/projects/gda-advertisement-auction/foundry-tests/src/AdSpotContract.sol +++ b/projects/gda-advertisement-auction/foundry-tests/src/AdSpotContract.sol @@ -81,14 +81,6 @@ contract AdSpotContract is SuperAppBaseFlow { // Getters // --------------------------------------------------------------------------------------------- - /** - * @dev Returns the last update timestamp. - */ - function getLastUpdate() public view returns (uint) { - return lastUpdate; - } - - /** * @dev Returns the address of the pool. */ @@ -196,10 +188,9 @@ contract AdSpotContract is SuperAppBaseFlow { if (highestBidder != address(0)) { newCtx = acceptedToken.deleteFlowWithCtx(highestBidder, address(this), ctx); uint128 halfShares = uint128(block.timestamp - lastUpdate) / 2; - if(pool.getUnits(owner)==1){ - pool.updateMemberUnits(owner, halfShares + pool.getUnits(owner)-1); - } - else{ + if (pool.getUnits(owner) == 1) { + pool.updateMemberUnits(owner, halfShares + pool.getUnits(owner) - 1); + } else { pool.updateMemberUnits(owner, halfShares + pool.getUnits(owner)); } pool.updateMemberUnits(highestBidder, halfShares + pool.getUnits(highestBidder)); @@ -240,7 +231,10 @@ contract AdSpotContract is SuperAppBaseFlow { newCtx = ctx; uint128 halfShares = uint128(block.timestamp - lastUpdate) / 2; ISuperfluidPool(poolAddress).updateMemberUnits(owner, halfShares + pool.getUnits(owner)); - ISuperfluidPool(poolAddress).updateMemberUnits(highestBidder,halfShares + pool.getUnits(highestBidder)); + ISuperfluidPool(poolAddress).updateMemberUnits( + highestBidder, + halfShares + pool.getUnits(highestBidder) + ); newCtx = acceptedToken.distributeFlowWithCtx(address(this), pool, senderFlowRate, newCtx); highestBidder = sender; highestFlowRate = senderFlowRate; diff --git a/projects/gda-advertisement-auction/foundry-tests/test/AdSpotContract.t.sol b/projects/gda-advertisement-auction/foundry-tests/test/AdSpotContract.t.sol index 362dec5..37a20f2 100644 --- a/projects/gda-advertisement-auction/foundry-tests/test/AdSpotContract.t.sol +++ b/projects/gda-advertisement-auction/foundry-tests/test/AdSpotContract.t.sol @@ -21,14 +21,13 @@ contract AdSpotContractTest is Test { uint256 mumbaiFork; string MUMBAI_RPC_URL = vm.envString("MUMBAI_RPC_URL"); - function setUp() public { mumbaiFork = vm.createSelectFork(MUMBAI_RPC_URL); - daix= ISuperToken(0x5D8B4C2554aeB7e86F387B4d6c00Ac33499Ed01f); + daix = ISuperToken(0x5D8B4C2554aeB7e86F387B4d6c00Ac33499Ed01f); adSpotContract = new AdSpotContract(daix); account1 = address(0x72343b915f335B2af76CA703cF7a550C8701d5CD); - account2= address(0x61fFC0072D66cE2bC3b8D7654BF68690b2d7fDc4); + account2 = address(0x61fFC0072D66cE2bC3b8D7654BF68690b2d7fDc4); vm.prank(account1); daix.transfer(address(adSpotContract), 1e18); vm.stopPrank(); @@ -37,9 +36,21 @@ contract AdSpotContractTest is Test { function testInitialSetup() public { vm.selectFork(mumbaiFork); assertEq(vm.activeFork(), mumbaiFork); - assertEq(address(adSpotContract.getAcceptedToken()), address(daix), "Accepted token should be daix"); - assertEq(adSpotContract.getOwner(), address(this), "Contract owner should be this contract"); - assertEq(adSpotContract.getHighestBidder(), address(0), "Initial highest bidder should be address 0"); + assertEq( + address(adSpotContract.getAcceptedToken()), + address(daix), + "Accepted token should be daix" + ); + assertEq( + adSpotContract.getOwner(), + address(this), + "Contract owner should be this contract" + ); + assertEq( + adSpotContract.getHighestBidder(), + address(0), + "Initial highest bidder should be address 0" + ); } function testFlowCreation() public { @@ -51,8 +62,16 @@ contract AdSpotContractTest is Test { vm.stopPrank(); // Verify that the highest bidder and flow rate are updated correctly - assertEq(adSpotContract.getHighestBidder(), account1, "Account1 should be the highest bidder"); - assertEq(adSpotContract.getHighestFlowRate(), flowRate, "Highest flow rate should match the set flow rate"); + assertEq( + adSpotContract.getHighestBidder(), + account1, + "Account1 should be the highest bidder" + ); + assertEq( + adSpotContract.getHighestFlowRate(), + flowRate, + "Highest flow rate should match the set flow rate" + ); } function testFlowUpdate() public { @@ -64,16 +83,27 @@ contract AdSpotContractTest is Test { vm.stopPrank(); // Verify that the highest bidder and flow rate are updated correctly - assertEq(adSpotContract.getHighestBidder(), account1, "Account1 should be the highest bidder"); - assertEq(adSpotContract.getHighestFlowRate(), flowRate, "Highest flow rate should match the set flow rate"); + assertEq( + adSpotContract.getHighestBidder(), + account1, + "Account1 should be the highest bidder" + ); + assertEq( + adSpotContract.getHighestFlowRate(), + flowRate, + "Highest flow rate should match the set flow rate" + ); vm.startPrank(account1); - daix.updateFlow(address(adSpotContract), 2*flowRate); + daix.updateFlow(address(adSpotContract), 2 * flowRate); vm.stopPrank(); // Verify that the flow rate is updated correctly - assertEq(adSpotContract.getHighestFlowRate(), 2*flowRate, "Highest flow rate should match the set flow rate"); - + assertEq( + adSpotContract.getHighestFlowRate(), + 2 * flowRate, + "Highest flow rate should match the set flow rate" + ); } function testFlowDeletion() public { @@ -85,17 +115,32 @@ contract AdSpotContractTest is Test { vm.stopPrank(); // Verify that the highest bidder and flow rate are updated correctly - assertEq(adSpotContract.getHighestBidder(), account1, "Account1 should be the highest bidder"); - assertEq(adSpotContract.getHighestFlowRate(), flowRate, "Highest flow rate should match the set flow rate"); + assertEq( + adSpotContract.getHighestBidder(), + account1, + "Account1 should be the highest bidder" + ); + assertEq( + adSpotContract.getHighestFlowRate(), + flowRate, + "Highest flow rate should match the set flow rate" + ); vm.startPrank(account1); daix.deleteFlow(account1, address(adSpotContract)); vm.stopPrank(); // Verify that the highest bidder and flow rate are updated correctly - assertEq(adSpotContract.getHighestBidder(), address(0), "Initial highest bidder should be address 0"); - assertEq(adSpotContract.getHighestFlowRate(), 0, "Highest flow rate should match the set flow rate"); - + assertEq( + adSpotContract.getHighestBidder(), + address(0), + "Initial highest bidder should be address 0" + ); + assertEq( + adSpotContract.getHighestFlowRate(), + 0, + "Highest flow rate should match the set flow rate" + ); } function testHigherBidd() public { @@ -107,18 +152,33 @@ contract AdSpotContractTest is Test { vm.stopPrank(); // Verify that the highest bidder and flow rate are updated correctly - assertEq(adSpotContract.getHighestBidder(), account1, "Account1 should be the highest bidder"); - assertEq(adSpotContract.getHighestFlowRate(), flowRate, "Highest flow rate should match the set flow rate"); + assertEq( + adSpotContract.getHighestBidder(), + account1, + "Account1 should be the highest bidder" + ); + assertEq( + adSpotContract.getHighestFlowRate(), + flowRate, + "Highest flow rate should match the set flow rate" + ); // Create a flow from account2 to the adSpotContract vm.startPrank(account2); - daix.createFlow(address(adSpotContract), flowRate+2); + daix.createFlow(address(adSpotContract), flowRate + 2); vm.stopPrank(); // Verify that the highest bidder and flow rate are updated correctly - assertEq(adSpotContract.getHighestBidder(), account2, "Account2 should be the highest bidder"); - assertEq(adSpotContract.getHighestFlowRate(), flowRate+2, "Highest flow rate should match the set flow rate"); - + assertEq( + adSpotContract.getHighestBidder(), + account2, + "Account2 should be the highest bidder" + ); + assertEq( + adSpotContract.getHighestFlowRate(), + flowRate + 2, + "Highest flow rate should match the set flow rate" + ); } function testNFTSetting() public { @@ -130,8 +190,16 @@ contract AdSpotContractTest is Test { vm.stopPrank(); // Verify that the highest bidder and flow rate are updated correctly - assertEq(adSpotContract.getHighestBidder(), account1, "Account1 should be the highest bidder"); - assertEq(adSpotContract.getHighestFlowRate(), flowRate, "Highest flow rate should match the set flow rate"); + assertEq( + adSpotContract.getHighestBidder(), + account1, + "Account1 should be the highest bidder" + ); + assertEq( + adSpotContract.getHighestFlowRate(), + flowRate, + "Highest flow rate should match the set flow rate" + ); // Set an NFT to showcase vm.startPrank(account1); @@ -139,9 +207,12 @@ contract AdSpotContractTest is Test { vm.stopPrank(); // Verify that the NFT address and token ID are updated correctly - assertEq(adSpotContract.getNftAddress(), address(this), "NFT address should be this contract"); + assertEq( + adSpotContract.getNftAddress(), + address(this), + "NFT address should be this contract" + ); assertEq(adSpotContract.getNftTokenId(), 1, "NFT token ID should be 1"); - } function testOwnerUnitsFirstTime() public { @@ -153,8 +224,16 @@ contract AdSpotContractTest is Test { vm.stopPrank(); // Verify that the highest bidder and flow rate are updated correctly - assertEq(adSpotContract.getHighestBidder(), account1, "Account1 should be the highest bidder"); - assertEq(adSpotContract.getHighestFlowRate(), flowRate, "Highest flow rate should match the set flow rate"); + assertEq( + adSpotContract.getHighestBidder(), + account1, + "Account1 should be the highest bidder" + ); + assertEq( + adSpotContract.getHighestFlowRate(), + flowRate, + "Highest flow rate should match the set flow rate" + ); // Verify that the owner's shares are updated correctly assertEq(adSpotContract.getOwnerShares(), 1, "Owner's shares should be 1e18"); @@ -169,23 +248,39 @@ contract AdSpotContractTest is Test { vm.stopPrank(); // Verify that the highest bidder and flow rate are updated correctly - assertEq(adSpotContract.getHighestBidder(), account1, "Account1 should be the highest bidder"); - assertEq(adSpotContract.getHighestFlowRate(), flowRate, "Highest flow rate should match the set flow rate"); + assertEq( + adSpotContract.getHighestBidder(), + account1, + "Account1 should be the highest bidder" + ); + assertEq( + adSpotContract.getHighestFlowRate(), + flowRate, + "Highest flow rate should match the set flow rate" + ); // Verify that the owner's shares are updated correctly assertEq(adSpotContract.getOwnerShares(), 1, "Owner's shares should be 1"); // Create a flow from account2 to the adSpotContract vm.startPrank(account2); - daix.createFlow(address(adSpotContract), flowRate+2); + daix.createFlow(address(adSpotContract), flowRate + 2); vm.stopPrank(); // Verify that the owner's shares are updated correctly - assertEq(adSpotContract.getOwnerShares(), adSpotContract.getTotalShares()/2, "Owner's shares should be half of total shares"); - assertEq(adSpotContract.getOwnerShares(), adSpotContract.getMemberShares(account1), "Owner's shares should be same as account1's shares"); + assertEq( + adSpotContract.getOwnerShares(), + adSpotContract.getTotalShares() / 2, + "Owner's shares should be half of total shares" + ); + assertEq( + adSpotContract.getOwnerShares(), + adSpotContract.getMemberShares(account1), + "Owner's shares should be same as account1's shares" + ); } - testAdvancedMembersUnits() public { + function testAdvancedMembersUnits() public { int96 flowRate = int96(1000); // example flow rate // Create a flow from account1 to the adSpotContract @@ -194,32 +289,53 @@ contract AdSpotContractTest is Test { vm.stopPrank(); // Verify that the highest bidder and flow rate are updated correctly - assertEq(adSpotContract.getHighestBidder(), account1, "Account1 should be the highest bidder"); - assertEq(adSpotContract.getHighestFlowRate(), flowRate, "Highest flow rate should match the set flow rate"); + assertEq( + adSpotContract.getHighestBidder(), + account1, + "Account1 should be the highest bidder" + ); + assertEq( + adSpotContract.getHighestFlowRate(), + flowRate, + "Highest flow rate should match the set flow rate" + ); // Verify that the owner's shares are updated correctly assertEq(adSpotContract.getOwnerShares(), 1, "Owner's shares should be 1"); // Create a flow from account2 to the adSpotContract vm.startPrank(account2); - daix.createFlow(address(adSpotContract), flowRate+2); + daix.createFlow(address(adSpotContract), flowRate + 2); vm.stopPrank(); // Verify that the owner's shares are updated correctly - assertEq(adSpotContract.getOwnerShares(), adSpotContract.getTotalShares()/2, "Owner's shares should be half of total shares"); - assertEq(adSpotContract.getOwnerShares(), adSpotContract.getMemberShares(account1), "Owner's shares should be same as account1's shares"); + assertEq( + adSpotContract.getOwnerShares(), + adSpotContract.getTotalShares() / 2, + "Owner's shares should be half of total shares" + ); + assertEq( + adSpotContract.getOwnerShares(), + adSpotContract.getMemberShares(account1), + "Owner's shares should be same as account1's shares" + ); // Create a flow from account2 to the adSpotContract vm.startPrank(account1); - daix.createFlow(address(adSpotContract), flowRate+2); + daix.createFlow(address(adSpotContract), flowRate + 4); vm.stopPrank(); // Verify that the owner's shares are updated correctly - assertEq(adSpotContract.getOwnerShares(), adSpotContract.getTotalShares()/3, "Owner's shares should be 1/3 of total shares"); - assertEq(adSpotContract.getOwnerShares(), adSpotContract.getMemberShares(account1), "Owner's shares should be same as account1's shares"); - assertEq(adSpotContract.getOwnerShares(), adSpotContract.getMemberShares(account2), "Owner's shares should be same as account2's shares"); - + assertEq( + adSpotContract.getOwnerShares(), + adSpotContract.getTotalShares() / 2, + "Owner's shares should be 1/3 of total shares" + ); + assertEq( + adSpotContract.getMemberShares(account1)+adSpotContract.getMemberShares(account2), + adSpotContract.getTotalShares() / 2, + "Owner's shares should be 1/3 of total shares" + ); } - - } + \ No newline at end of file