Skip to content

Commit

Permalink
test(withdrawal): cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
tamtamchik committed Mar 5, 2024
1 parent 43866bb commit 31696b7
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 28 deletions.
2 changes: 1 addition & 1 deletion test/0.8.9/WithdrawalQueue.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -694,7 +694,7 @@ describe("WithdrawalQueue.sol", () => {
queue.connect(owner).claimWithdrawalsTo(
requests,
hints.map((h) => h.valueOf()),
stranger.address,
stranger,
),
)
.to.emit(queue, "WithdrawalClaimed")
Expand Down
4 changes: 2 additions & 2 deletions test/0.8.9/WithdrawalQueueBase.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -618,14 +618,14 @@ describe("WithdrawalQueueBase.sol", () => {
await queue.prefinalize([1], shareRate(1n));
await queue.exposedFinalize(1, ether("1.00"), shareRate(1n));

const balanceBefore = await provider.getBalance(stranger.address);
const balanceBefore = await provider.getBalance(stranger);
const lockedBefore = await queue.getLockedEtherAmount();

await expect(queue.exposedClaim(1, 1, stranger))
.to.emit(queue, "WithdrawalClaimed")
.withArgs(1, owner.address, stranger.address, shares(1n));

const balanceAfter = await provider.getBalance(stranger.address);
const balanceAfter = await provider.getBalance(stranger);
const lockedAfter = await queue.getLockedEtherAmount();

expect(balanceAfter - balanceBefore).to.equal(ether("1.00"));
Expand Down
44 changes: 19 additions & 25 deletions test/0.8.9/WithdrawalQueueERC721.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -468,36 +468,36 @@ describe("WithdrawalQueueERC721.sol", () => {
});

it("Returns correct spender for approved token", async () => {
await queue.connect(user).approve(stranger.address, 1);
await queue.connect(user).approve(stranger, 1);

expect(await queue.getApproved(1)).to.equal(stranger.address);
});
});

context("setApprovalForAll", () => {
it("Reverts if operator is the caller", async () => {
await expect(queue.connect(user).setApprovalForAll(user.address, true)).to.be.revertedWithCustomError(
await expect(queue.connect(user).setApprovalForAll(user, true)).to.be.revertedWithCustomError(
queue,
"ApproveToCaller",
);
});

it("Approves operator for all tokens", async () => {
await expect(queue.connect(user).setApprovalForAll(stranger.address, true))
await expect(queue.connect(user).setApprovalForAll(stranger, true))
.to.emit(queue, "ApprovalForAll")
.withArgs(user.address, stranger.address, true);
});
});

context("isApprovedForAll", () => {
it("Returns false for non-operator", async () => {
expect(await queue.isApprovedForAll(user.address, stranger.address)).to.equal(false);
expect(await queue.isApprovedForAll(user, stranger)).to.equal(false);
});

it("Returns true for operator", async () => {
await queue.connect(user).setApprovalForAll(stranger.address, true);
await queue.connect(user).setApprovalForAll(stranger, true);

expect(await queue.isApprovedForAll(user.address, stranger.address)).to.equal(true);
expect(await queue.isApprovedForAll(user, stranger)).to.equal(true);
});
});

Expand All @@ -514,9 +514,7 @@ describe("WithdrawalQueueERC721.sol", () => {
});

it("Works as safeTransferFrom(address,address,uint256,bytes)", async () => {
await expect(
queue.connect(user)["safeTransferFrom(address,address,uint256)"](user.address, stranger.address, 1),
)
await expect(queue.connect(user)["safeTransferFrom(address,address,uint256)"](user, stranger, 1))
.to.emit(queue, "Transfer")
.withArgs(user.address, stranger.address, 1);
});
Expand Down Expand Up @@ -545,9 +543,7 @@ describe("WithdrawalQueueERC721.sol", () => {

it("Transfers token to user", async () => {
await expect(
queue
.connect(user)
["safeTransferFrom(address,address,uint256,bytes)"](user.address, stranger.address, 1, new Uint8Array()),
queue.connect(user)["safeTransferFrom(address,address,uint256,bytes)"](user, stranger, 1, new Uint8Array()),
)
.to.emit(queue, "Transfer")
.withArgs(user.address, stranger.address, 1);
Expand All @@ -557,9 +553,7 @@ describe("WithdrawalQueueERC721.sol", () => {
await expect(
queue
.connect(user)
[
"safeTransferFrom(address,address,uint256,bytes)"
](user.address, receiverContractAddress, 1, new Uint8Array()),
["safeTransferFrom(address,address,uint256,bytes)"](user, receiverContractAddress, 1, new Uint8Array()),
)
.revertedWithCustomError(queue, "TransferToNonIERC721Receiver")
.withArgs(receiverContractAddress);
Expand All @@ -573,7 +567,7 @@ describe("WithdrawalQueueERC721.sol", () => {
.connect(user)
[
"safeTransferFrom(address,address,uint256,bytes)"
](user.address, erc721ReceiverContractAddress, 1, new Uint8Array()),
](user, erc721ReceiverContractAddress, 1, new Uint8Array()),
).revertedWith("ERC721_NOT_ACCEPT_TOKENS");
});

Expand All @@ -586,7 +580,7 @@ describe("WithdrawalQueueERC721.sol", () => {
.connect(user)
[
"safeTransferFrom(address,address,uint256,bytes)"
](user.address, erc721ReceiverContractAddress, 1, new Uint8Array()),
](user, erc721ReceiverContractAddress, 1, new Uint8Array()),
)
.revertedWithCustomError(queue, "TransferToNonIERC721Receiver")
.withArgs(erc721ReceiverContractAddress);
Expand All @@ -601,7 +595,7 @@ describe("WithdrawalQueueERC721.sol", () => {
.connect(user)
[
"safeTransferFrom(address,address,uint256,bytes)"
](user.address, erc721ReceiverContractAddress, 1, new Uint8Array()),
](user, erc721ReceiverContractAddress, 1, new Uint8Array()),
)
.to.emit(queue, "Transfer")
.withArgs(user.address, erc721ReceiverContractAddress, 1);
Expand All @@ -620,27 +614,27 @@ describe("WithdrawalQueueERC721.sol", () => {
});

it("Reverts if transfer to zero address", async () => {
await expect(queue.connect(user).transferFrom(user.address, ZeroAddress, 1)).to.be.revertedWithCustomError(
await expect(queue.connect(user).transferFrom(user, ZeroAddress, 1)).to.be.revertedWithCustomError(
queue,
"TransferToZeroAddress",
);
});

it("Reverts if transfer to self", async () => {
await expect(queue.connect(user).transferFrom(user.address, user.address, 1)).to.be.revertedWithCustomError(
await expect(queue.connect(user).transferFrom(user, user, 1)).to.be.revertedWithCustomError(
queue,
"TransferToThemselves",
);
});

it("Reverts if request id is 0", async () => {
await expect(queue.connect(user).transferFrom(user.address, stranger.address, 0))
await expect(queue.connect(user).transferFrom(user, stranger, 0))
.to.be.revertedWithCustomError(queue, "InvalidRequestId")
.withArgs(0);
});

it("Reverts if request id is out of bounds", async () => {
await expect(queue.connect(user).transferFrom(user.address, stranger.address, 10))
await expect(queue.connect(user).transferFrom(user, stranger, 10))
.to.be.revertedWithCustomError(queue, "InvalidRequestId")
.withArgs(10);
});
Expand All @@ -652,19 +646,19 @@ describe("WithdrawalQueueERC721.sol", () => {
await queue.connect(finalizer).finalize(1, shareRate(300n), { value: ether("25.00") });
await queue.connect(user).claimWithdrawal(1);

await expect(queue.connect(user).transferFrom(user.address, stranger.address, 1))
await expect(queue.connect(user).transferFrom(user, stranger, 1))
.to.be.revertedWithCustomError(queue, "RequestAlreadyClaimed")
.withArgs(1);
});

it("Reverts if transfer from incorrect owner", async () => {
await expect(queue.connect(stranger).transferFrom(stranger.address, user.address, 1))
await expect(queue.connect(stranger).transferFrom(stranger, user, 1))
.to.be.revertedWithCustomError(queue, "TransferFromIncorrectOwner")
.withArgs(stranger.address, user.address);
});

it("Reverts if not owner and not approved for all", async () => {
await expect(queue.connect(stranger).transferFrom(user.address, stranger.address, 1))
await expect(queue.connect(stranger).transferFrom(user, stranger, 1))
.to.be.revertedWithCustomError(queue, "NotOwnerOrApproved")
.withArgs(stranger.address);
});
Expand Down

0 comments on commit 31696b7

Please sign in to comment.