Skip to content

Commit

Permalink
Add a test for checking for overflow when cancelling an order which o…
Browse files Browse the repository at this point in the history
…verflows uint72
  • Loading branch information
0xSamWitch committed Oct 10, 2024
1 parent 911eb37 commit d4bef18
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions test/SamWitchOrderBook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1569,6 +1569,35 @@ describe("SamWitchOrderBook", function () {
expect(await brush.balanceOf(orderBook)).to.eq(0);
expect(await erc1155.balanceOf(owner, tokenId)).to.eq(initialQuantity);
});

it("Cancelling when the overall (price * quantity) order amount exceeds a uint72 (checks for overflow)", async function () {
const {orderBook, owner, tokenId, erc1155, brush, initialBrush, initialQuantity} =
await loadFixture(deployContractsFixture);

const quantity = 10n;
const extraBrush = ethers.parseEther("1700") * quantity;
await brush.mint(owner.address, extraBrush);
await brush.approve(orderBook, extraBrush);

// Set up order books
const price = ethers.parseEther("1700");
await orderBook.limitOrders([
{
side: OrderSide.Buy,
tokenId,
price,
quantity,
},
]);

// Cancel buy, should not revert and return the brush
const orderId = 1;
await orderBook.cancelOrders([orderId], [{side: OrderSide.Buy, tokenId, price}]);

expect(await brush.balanceOf(owner)).to.eq(BigInt(initialBrush) + extraBrush);
expect(await brush.balanceOf(orderBook)).to.eq(0);
expect(await erc1155.balanceOf(owner, tokenId)).to.eq(initialQuantity);
});
});

it("Consume a segment and whole price level with a tombstone offset, and check it works as expected when re-added to the tree", async function () {
Expand Down

0 comments on commit d4bef18

Please sign in to comment.