From 0bfe075161b18b6a04397975d9eece778e4db10d Mon Sep 17 00:00:00 2001 From: Ana Julia Date: Wed, 5 Jul 2023 20:43:05 -0300 Subject: [PATCH] Remediate tests on MetaTx and ExchangeHandler --- test/integration/seaport/utils.js | 2 +- test/protocol/ExchangeHandlerTest.js | 5 ++-- test/protocol/MetaTransactionsHandlerTest.js | 31 +++++++++++++------- 3 files changed, 24 insertions(+), 14 deletions(-) diff --git a/test/integration/seaport/utils.js b/test/integration/seaport/utils.js index 19fcfc268..dbae9e415 100644 --- a/test/integration/seaport/utils.js +++ b/test/integration/seaport/utils.js @@ -2,7 +2,7 @@ const { BigNumber, constants, utils } = require("ethers"); const getOfferOrConsiderationItem = function ( itemType = 0, - token = constants.AddressZero, + token = ZeroAddress, identifierOrCriteria = 0, startAmount = 1, endAmount = 1, diff --git a/test/protocol/ExchangeHandlerTest.js b/test/protocol/ExchangeHandlerTest.js index 177083b35..e4eedab81 100644 --- a/test/protocol/ExchangeHandlerTest.js +++ b/test/protocol/ExchangeHandlerTest.js @@ -600,8 +600,9 @@ describe("IBosonExchangeHandler", function () { }); it("Should not decrement seller funds if offer price and sellerDeposit is 0", async function () { + let availableFundsAddresses = [ZeroAddress]; // Seller funds before - const sellersFundsBefore = FundsList.fromStruct(await fundsHandler.getAvailableFunds(seller.id)); + const sellersFundsBefore = FundsList.fromStruct(await fundsHandler.getAvailableFunds(seller.id, availableFundsAddresses)); // Set protocolFee to zero so we don't get the error AGENT_FEE_AMOUNT_TOO_HIGH let protocolFeePercentage = "0"; @@ -630,7 +631,7 @@ describe("IBosonExchangeHandler", function () { await exchangeHandler.connect(buyer).commitToOffer(buyer.address, offerId); // Seller funds after - const sellerFundsAfter = FundsList.fromStruct(await fundsHandler.getAvailableFunds(seller.id)); + const sellerFundsAfter = FundsList.fromStruct(await fundsHandler.getAvailableFunds(seller.id, availableFundsAddresses)); expect(sellerFundsAfter.toString()).to.equal( sellersFundsBefore.toString(), "Seller funds should not be decremented" diff --git a/test/protocol/MetaTransactionsHandlerTest.js b/test/protocol/MetaTransactionsHandlerTest.js index 9287b79e2..4c4314a14 100644 --- a/test/protocol/MetaTransactionsHandlerTest.js +++ b/test/protocol/MetaTransactionsHandlerTest.js @@ -3387,10 +3387,18 @@ describe("IBosonMetaTransactionsHandler", function () { }); context("Should emit MetaTransactionExecuted event and update state", async () => { + let availableFundsAddresses; beforeEach(async function () { + availableFundsAddresses = [await mockToken.getAddress(), ZeroAddress]; + // Read on chain state +<<<<<<< HEAD buyerAvailableFunds = FundsList.fromStruct(await fundsHandler.getAvailableFunds(buyerId)); buyerBalanceBefore = await mockToken.balanceOf(buyer.address); +======= + buyerAvailableFunds = FundsList.fromStruct(await fundsHandler.getAvailableFunds(buyerId, availableFundsAddresses)); + buyerBalanceBefore = await mockToken.balanceOf(await buyer.getAddress()); +>>>>>>> 1b3488e6 (Remediate tests on MetaTx and ExchangeHandler) // Chain state should match the expected available funds before the withdrawal expectedBuyerAvailableFunds = new FundsList([ @@ -3436,17 +3444,14 @@ describe("IBosonMetaTransactionsHandler", function () { .withArgs(buyer.address, deployer.address, message.functionName, nonce); // Read on chain state - buyerAvailableFunds = FundsList.fromStruct(await fundsHandler.getAvailableFunds(buyerId)); - buyerBalanceAfter = await mockToken.balanceOf(buyer.address); + buyerAvailableFunds = FundsList.fromStruct(await fundsHandler.getAvailableFunds(buyerId, availableFundsAddresses)); + buyerBalanceAfter = await mockToken.balanceOf(await buyer.getAddress()); // Chain state should match the expected available funds after the withdrawal // Since all tokens are withdrawn, token should be removed from the list expectedBuyerAvailableFunds = new FundsList([ - new Funds( - ethers.constants.AddressZero, - "Native currency", - ethers.BigNumber.from(buyerPayoff).div("2").toString() - ), + new Funds(await mockToken.getAddress(), "Foreign20", "0"), + new Funds(ZeroAddress, "Native currency", (BigInt(buyerPayoff) / 2n).toString()), ]); expect(buyerAvailableFunds).to.eql( expectedBuyerAvailableFunds, @@ -3504,12 +3509,16 @@ describe("IBosonMetaTransactionsHandler", function () { .withArgs(buyer.address, deployer.address, message.functionName, nonce); // Read on chain state - buyerAvailableFunds = FundsList.fromStruct(await fundsHandler.getAvailableFunds(buyerId)); - buyerBalanceAfter = await mockToken.balanceOf(buyer.address); + buyerAvailableFunds = FundsList.fromStruct(await fundsHandler.getAvailableFunds(buyerId, availableFundsAddresses)); + buyerBalanceAfter = await mockToken.balanceOf(await buyer.getAddress()); // Chain state should match the expected available funds after the withdrawal - // Since all tokens are withdrawn, funds list should be empty. - expectedBuyerAvailableFunds = new FundsList([]); + // Since all tokens are withdrawn, values should be zero + const emptyFundsList = new FundsList([ + new Funds(await mockToken.getAddress(), "Foreign20", "0"), + new Funds(ZeroAddress, "Native currency", "0"), + ]); + expectedBuyerAvailableFunds = emptyFundsList; expect(buyerAvailableFunds).to.eql( expectedBuyerAvailableFunds, "Buyer available funds mismatch after withdrawal"