Skip to content

Commit

Permalink
Extract repeated tx code to beforeEach blocks
Browse files Browse the repository at this point in the history
We can define the transactions execution in beforeEach blocks, as we do
in other tests.
  • Loading branch information
nkuba committed Sep 23, 2021
1 parent 5624f29 commit 0ef7ee3
Showing 1 changed file with 12 additions and 32 deletions.
44 changes: 12 additions & 32 deletions test/token/ERC20WithPermit.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,9 +137,15 @@ describe("ERC20WithPermit", () => {
context("when the sender transfers part of their tokens", () => {
const amount = to1e18(60)

it("should transfer the requested amount", async () => {
await token.connect(initialHolder).transfer(recipient.address, amount)
let tx

beforeEach(async () => {
tx = await token
.connect(initialHolder)
.transfer(recipient.address, amount)
})

it("should transfer the requested amount", async () => {
expect(await token.balanceOf(initialHolder.address)).to.equal(
initialHolderBalance.sub(amount)
)
Expand All @@ -148,10 +154,6 @@ describe("ERC20WithPermit", () => {
})

it("should emit a transfer event", async () => {
const tx = await token
.connect(initialHolder)
.transfer(recipient.address, amount)

await expect(tx)
.to.emit(token, "Transfer")
.withArgs(initialHolder.address, recipient.address, amount)
Expand Down Expand Up @@ -365,15 +367,17 @@ describe("ERC20WithPermit", () => {
context("when the sender transfers all balance", () => {
const amount = initialHolderBalance

it("should transfer the requested amount", async () => {
await token
beforeEach(async () => {
tx = await token
.connect(anotherAccount)
.transferFrom(
initialHolder.address,
recipient.address,
amount
)
})

it("should transfer the requested amount", async () => {
expect(await token.balanceOf(initialHolder.address)).to.equal(0)

expect(await token.balanceOf(recipient.address)).to.equal(
Expand All @@ -382,14 +386,6 @@ describe("ERC20WithPermit", () => {
})

it("should decrease the spender allowance", async () => {
await token
.connect(anotherAccount)
.transferFrom(
initialHolder.address,
recipient.address,
amount
)

expect(
await token.allowance(
initialHolder.address,
Expand All @@ -399,28 +395,12 @@ describe("ERC20WithPermit", () => {
})

it("should emit a transfer event", async () => {
const tx = await token
.connect(anotherAccount)
.transferFrom(
initialHolder.address,
recipient.address,
amount
)

await expect(tx)
.to.emit(token, "Transfer")
.withArgs(initialHolder.address, recipient.address, amount)
})

it("should emit an approval event", async () => {
const tx = await token
.connect(anotherAccount)
.transferFrom(
initialHolder.address,
recipient.address,
amount
)

await expect(tx)
.to.emit(token, "Approval")
.withArgs(
Expand Down

0 comments on commit 0ef7ee3

Please sign in to comment.