Skip to content

Commit

Permalink
Bump code coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
zajck committed Nov 10, 2023
1 parent 7d36468 commit db883cc
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
3 changes: 3 additions & 0 deletions contracts/mock/PriceDiscovery.sol
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,9 @@ contract PriceDiscovery {
}
}
}

// return half of the sent value back to the caller
payable(msg.sender).transfer(msg.value / 2);
}
}

Expand Down
38 changes: 38 additions & 0 deletions test/protocol/SequentialCommitHandlerTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -1329,6 +1329,44 @@ describe("IBosonSequentialCommitHandler", function () {
balancesBefore.originalSeller + expectedOriginalSellerChange
);
});

it(`protocol fee: ${fee.protocol / 100}%; royalties: ${
fee.royalties / 100
}% - non zero msg.value`, async function () {
await configHandler.setProtocolFeePercentage(fee.protocol);
await bosonVoucherClone.connect(assistant).setRoyaltyPercentage(fee.royalties);

const balancesBefore = await getBalances();

const sellerMsgValue = parseUnits("0.001", "ether");

// Sequential commit to offer
await sequentialCommitHandler
.connect(reseller)
.sequentialCommitToOffer(buyer2.address, exchangeId, priceDiscovery, {
gasPrice: 0,
value: sellerMsgValue,
});

const balancesAfter = await getBalances();

// Expected changes
const expectedBuyerChange = price2;
const reducedSecondaryPrice = (price2 * BigInt(10000 - fee.protocol - fee.royalties)) / 10000n;
const expectedSellerChange = reducedSecondaryPrice <= price ? reducedSecondaryPrice : price;
const expectedProtocolChange = price2 - expectedSellerChange;
const expectedOriginalSellerChange = 0n;

// Contract's balance should increase for minimal escrow amount
expect(balancesAfter.protocol).to.equal(balancesBefore.protocol + expectedProtocolChange);
expect(balancesAfter.seller).to.equal(
balancesBefore.seller + expectedSellerChange - sellerMsgValue / 2n
); // PriceDiscovery returns back half of the sent native value
expect(balancesAfter.newBuyer).to.equal(balancesBefore.newBuyer - expectedBuyerChange);
expect(balancesAfter.originalSeller).to.equal(
balancesBefore.originalSeller + expectedOriginalSellerChange
);
});
});
});
});
Expand Down

0 comments on commit db883cc

Please sign in to comment.