Skip to content

Commit

Permalink
Fix for failing unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
tomaszslabon committed Aug 23, 2021
1 parent 3530f39 commit 90da984
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 28 deletions.
36 changes: 10 additions & 26 deletions test/Auction.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const {
pastEvents,
increaseTime,
impersonateAccount,
isCodeAt,
} = require("./helpers/contract-test-helpers")

const { BigNumber } = ethers
Expand Down Expand Up @@ -275,17 +276,15 @@ describe("Auction", () => {
})

context("when the auction was fully paid off and is closed", () => {
it("should revert on taking offer again", async () => {
it("should destroy the auction", async () => {
// Increase time 1h -> 3600sec
await increaseTime(3600)

// take the entire auction
await auction.connect(bidder1).takeOffer(auctionAmountDesired)

// another bidder is trying to take offer on a closed auction
await expect(
auction.connect(bidder2).takeOffer(BigNumber.from(1))
).to.be.revertedWith("Address: call to non-contract")
// the auction contract address should not store code anymore
expect(await isCodeAt(auction.address)).to.be.false
})
})

Expand Down Expand Up @@ -523,7 +522,7 @@ describe("Auction", () => {
)

context("when the auction was fully paid off in partial offers", () => {
it("should revert on taking another offer", async () => {
it("should destroy the auction", async () => {
// Auction amount desired: 1 * 10^18
// Increase time 1h -> 3600sec
await increaseTime(3600)
Expand All @@ -538,9 +537,7 @@ describe("Auction", () => {
.amountOutstanding()
await auction.connect(bidder2).takeOffer(amountOutstanding)

await expect(
auction.connect(bidder2).takeOffer(BigNumber.from(1))
).to.be.revertedWith("Address: call to non-contract")
expect(await isCodeAt(auction.address)).to.be.false
})
})
})
Expand All @@ -558,21 +555,21 @@ describe("Auction", () => {
})

context("when the auction is open and there are no fills", () => {
it("should early close the auction", async () => {
it("should destroy the auction", async () => {
await auction.connect(auctioneerSigner).earlyClose()

expect(await auction.isOpen()).to.be.false
expect(await isCodeAt(auction.address)).to.be.false
})
})

context("when the auction is open and there are partial fills", () => {
it("should early close the auction", async () => {
it("should destroy the auction", async () => {
const partialOfferAmount = auctionAmountDesired.div(BigNumber.from("2"))
await auction.connect(bidder1).takeOffer(partialOfferAmount)

await auction.connect(auctioneerSigner).earlyClose()

expect(await auction.isOpen()).to.be.false
expect(await isCodeAt(auction.address)).to.be.false
})
})

Expand All @@ -583,19 +580,6 @@ describe("Auction", () => {
)
})
})

context("when the auction is closed", () => {
it("should revert", async () => {
// close the auction by taking the whole amount
await auction.connect(bidder1).takeOffer(auctionAmountDesired)

// Will be reverted due to onlyAuctioneer modifier violation as
// Auction storage has been destroyed by harikari and current
// auctioneer is a zero address.
await expect(auction.connect(auctioneerSigner).earlyClose()).to.be
.reverted
})
})
})

describe("amountTransferred", () => {
Expand Down
5 changes: 3 additions & 2 deletions test/Auctioneer.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const {
to1e18,
pastEvents,
increaseTime,
isCodeAt,
} = require("./helpers/contract-test-helpers")

const auctionLength = 86400 // 24h in sec
Expand Down Expand Up @@ -264,10 +265,10 @@ describe("Auctioneer", () => {
})

context("when the auction is still open", () => {
it("should close the auction", async () => {
it("should destroy the auction", async () => {
await auctioneer.connect(bidder).publicEarlyCloseAuction(auctionAddress)

expect(await auction.isOpen()).to.be.false
expect(await isCodeAt(auctionAddress)).to.be.false
})

it("should emit the auction closed event", async () => {
Expand Down
8 changes: 8 additions & 0 deletions test/helpers/contract-test-helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,12 +78,20 @@ async function resetFork(blockNumber) {
})
}

// This function checks whether the given address stores contract code. It
// can be used to determine whether a contract stored at the given address has
// self destructed.
async function isCodeAt(address) {
return (await ethers.provider.getCode(address)) != ethers.utils.hexlify("0x")
}

module.exports.to1ePrecision = to1ePrecision
module.exports.to1e18 = to1e18
module.exports.pastEvents = pastEvents
module.exports.lastBlockTime = lastBlockTime
module.exports.increaseTime = increaseTime
module.exports.impersonateAccount = impersonateAccount
module.exports.resetFork = resetFork
module.exports.isCodeAt = isCodeAt

module.exports.ZERO_ADDRESS = "0x0000000000000000000000000000000000000000"

0 comments on commit 90da984

Please sign in to comment.