Skip to content

Commit

Permalink
Remediate tests on MetaTx and ExchangeHandler
Browse files Browse the repository at this point in the history
  • Loading branch information
anajuliabit committed Jul 5, 2023
1 parent 8d28bf6 commit 0bfe075
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 14 deletions.
2 changes: 1 addition & 1 deletion test/integration/seaport/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
5 changes: 3 additions & 2 deletions test/protocol/ExchangeHandlerTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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"
Expand Down
31 changes: 20 additions & 11 deletions test/protocol/MetaTransactionsHandlerTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -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([
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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"
Expand Down

0 comments on commit 0bfe075

Please sign in to comment.