Skip to content

Commit

Permalink
Rplace some .address calls with just the signer in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
0xSamWitch committed Aug 6, 2024
1 parent a5b629b commit 8a4553c
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 17 deletions.
1 change: 1 addition & 0 deletions contracts/interfaces/ISamWitchOrderBook.sol
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ interface ISamWitchOrderBook is IERC1155Receiver {
uint80 amount;
}

// A helper type for a view function to return orders
struct Order {
address maker;
uint24 quantity;
Expand Down
33 changes: 16 additions & 17 deletions test/SamWitchOrderBook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ describe("SamWitchOrderBook", function () {
)) as unknown as SamWitchOrderBook;

const initialBrush = 1000000;
await brush.mint(owner.address, initialBrush);
await brush.mint(owner, initialBrush);
await brush.approve(orderBook, initialBrush);

await brush.connect(alice).mint(alice.address, initialBrush);
await brush.connect(alice).mint(alice, initialBrush);
await brush.connect(alice).approve(orderBook, initialBrush);

const initialQuantity = 100;
Expand Down Expand Up @@ -260,8 +260,7 @@ describe("SamWitchOrderBook", function () {
});

it("Check total cost, selling", async function () {
const {orderBook, erc1155, brush, owner, alice, dev, royaltyRecipient, tokenId, initialBrush} =
await loadFixture(deployContractsFixture);
const {orderBook, alice, tokenId} = await loadFixture(deployContractsFixture);

// Set up order book
const price = 100;
Expand Down Expand Up @@ -336,15 +335,15 @@ describe("SamWitchOrderBook", function () {
)
.to.emit(orderBook, "OrdersMatched")
.withArgs(alice.address, [orderId], [numToBuy]);
expect(await erc1155.balanceOf(alice.address, tokenId)).to.equal(initialQuantity + numToBuy);
expect(await erc1155.balanceOf(alice, tokenId)).to.equal(initialQuantity + numToBuy);

await orderBook.connect(alice).marketOrder({
side: OrderSide.Buy,
tokenId,
totalCost: (price + 1) * (quantity - numToBuy),
quantity: quantity - numToBuy,
}); // Buy the rest
expect(await erc1155.balanceOf(alice.address, tokenId)).to.equal(initialQuantity + quantity);
expect(await erc1155.balanceOf(alice, tokenId)).to.equal(initialQuantity + quantity);

// There's nothing left on the sell side, this adds to the buy order side
await expect(
Expand Down Expand Up @@ -433,15 +432,15 @@ describe("SamWitchOrderBook", function () {
.to.emit(orderBook, "OrdersMatched")
.withArgs(alice.address, [orderId], [numToSell]);

expect(await erc1155.balanceOf(alice.address, tokenId)).to.equal(initialQuantity - numToSell);
expect(await erc1155.balanceOf(alice, tokenId)).to.equal(initialQuantity - numToSell);

await orderBook.connect(alice).marketOrder({
side: OrderSide.Sell,
tokenId,
totalCost: price * (quantity - numToSell),
quantity: quantity - numToSell,
}); // Buy the rest
expect(await erc1155.balanceOf(alice.address, tokenId)).to.equal(initialQuantity - quantity);
expect(await erc1155.balanceOf(alice, tokenId)).to.equal(initialQuantity - quantity);

// There's nothing left on the sell side
await expect(
Expand Down Expand Up @@ -544,7 +543,7 @@ describe("SamWitchOrderBook", function () {
)
.to.emit(orderBook, "OrdersMatched")
.withArgs(alice.address, [orderId], [numToBuy]);
expect(await erc1155.balanceOf(alice.address, tokenId)).to.equal(initialQuantity + numToBuy);
expect(await erc1155.balanceOf(alice, tokenId)).to.equal(initialQuantity + numToBuy);

await orderBook.connect(alice).limitOrders([
{
Expand All @@ -554,7 +553,7 @@ describe("SamWitchOrderBook", function () {
quantity: quantity - numToBuy,
},
]); // Buy the rest
expect(await erc1155.balanceOf(alice.address, tokenId)).to.equal(initialQuantity + quantity);
expect(await erc1155.balanceOf(alice, tokenId)).to.equal(initialQuantity + quantity);

// There's nothing left on the sell side, this adds to the buy order side
await orderBook.connect(alice).limitOrders([
Expand Down Expand Up @@ -648,7 +647,7 @@ describe("SamWitchOrderBook", function () {
.to.emit(orderBook, "OrdersMatched")
.withArgs(alice.address, [orderId], [numToSell]);

expect(await erc1155.balanceOf(alice.address, tokenId)).to.equal(initialQuantity - numToSell);
expect(await erc1155.balanceOf(alice, tokenId)).to.equal(initialQuantity - numToSell);

await orderBook.connect(alice).limitOrders([
{
Expand All @@ -658,7 +657,7 @@ describe("SamWitchOrderBook", function () {
quantity: quantity - numToSell,
},
]); // Buy the rest
expect(await erc1155.balanceOf(alice.address, tokenId)).to.equal(initialQuantity - quantity);
expect(await erc1155.balanceOf(alice, tokenId)).to.equal(initialQuantity - quantity);

// There's nothing left on the sell side, this adds to the buy order side
await orderBook.connect(alice).limitOrders([
Expand Down Expand Up @@ -938,7 +937,7 @@ describe("SamWitchOrderBook", function () {
// Check you get the brush back
expect(await brush.balanceOf(owner)).to.eq(initialBrush);
expect(await brush.balanceOf(orderBook)).to.eq(0);
expect(await erc1155.balanceOf(owner.address, tokenId)).to.eq(initialQuantity);
expect(await erc1155.balanceOf(owner, tokenId)).to.eq(initialQuantity);

expect(await orderBook.getHighestBid(tokenId)).to.equal(0);
expect(await orderBook.getLowestAsk(tokenId)).to.equal(0);
Expand Down Expand Up @@ -1199,7 +1198,7 @@ describe("SamWitchOrderBook", function () {
).to.be.revertedWithCustomError(orderBook, "OrderNotFoundInTree");

expect(await brush.balanceOf(owner)).to.eq(initialBrush);
expect(await erc1155.balanceOf(owner.address, tokenId)).to.eq(initialQuantity);
expect(await erc1155.balanceOf(owner, tokenId)).to.eq(initialQuantity);

expect(await orderBook.getHighestBid(tokenId)).to.equal(0);
expect(await orderBook.getLowestAsk(tokenId)).to.equal(0);
Expand Down Expand Up @@ -1424,7 +1423,7 @@ describe("SamWitchOrderBook", function () {
await orderBook.setTokenIdInfos([tokenId], [{tick: 0, minQuantity: 20}]);
// Cancel should work
const orderId = 1;
const preBalance = await brush.balanceOf(owner.address);
const preBalance = await brush.balanceOf(owner);
await orderBook.cancelOrders([orderId], [{side: OrderSide.Buy, tokenId, price}]);

// Selling should no longer work
Expand All @@ -1440,7 +1439,7 @@ describe("SamWitchOrderBook", function () {
)
.to.be.revertedWithCustomError(orderBook, "TokenDoesntExist")
.withArgs(tokenId);
expect(await brush.balanceOf(owner.address)).to.eq(preBalance + BigInt(price * (quantity - 1)));
expect(await brush.balanceOf(owner)).to.eq(preBalance + BigInt(price * (quantity - 1)));
});

// Fixes: https://ftmscan.com/tx/0x69dd308e7a096ebd035bd3a3f18c2a9b116faee78ea4e0ccda06c3cfede0950b
Expand Down Expand Up @@ -1470,7 +1469,7 @@ describe("SamWitchOrderBook", function () {

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

Expand Down

0 comments on commit 8a4553c

Please sign in to comment.