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 9712e80 commit 1b3488e
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 8 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 @@ -642,8 +642,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 @@ -672,7 +673,7 @@ describe("IBosonExchangeHandler", function () {
await exchangeHandler.connect(buyer).commitToOffer(await buyer.getAddress(), 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
18 changes: 13 additions & 5 deletions test/protocol/MetaTransactionsHandlerTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -3484,9 +3484,12 @@ 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
buyerAvailableFunds = FundsList.fromStruct(await fundsHandler.getAvailableFunds(buyerId));
buyerAvailableFunds = FundsList.fromStruct(await fundsHandler.getAvailableFunds(buyerId, availableFundsAddresses));
buyerBalanceBefore = await mockToken.balanceOf(await buyer.getAddress());

// Chain state should match the expected available funds before the withdrawal
Expand Down Expand Up @@ -3533,12 +3536,13 @@ describe("IBosonMetaTransactionsHandler", function () {
.withArgs(await buyer.getAddress(), await deployer.getAddress(), message.functionName, nonce);

// Read on chain state
buyerAvailableFunds = FundsList.fromStruct(await fundsHandler.getAvailableFunds(buyerId));
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(await mockToken.getAddress(), "Foreign20", "0"),
new Funds(ZeroAddress, "Native currency", (BigInt(buyerPayoff) / 2n).toString()),
]);
expect(buyerAvailableFunds).to.eql(
Expand Down Expand Up @@ -3597,12 +3601,16 @@ describe("IBosonMetaTransactionsHandler", function () {
.withArgs(await buyer.getAddress(), await deployer.getAddress(), message.functionName, nonce);

// Read on chain state
buyerAvailableFunds = FundsList.fromStruct(await fundsHandler.getAvailableFunds(buyerId));
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 1b3488e

Please sign in to comment.