Skip to content

Commit

Permalink
Unit test covering the case when manager is not set and addGuardian
Browse files Browse the repository at this point in the history
… is called
  • Loading branch information
lukasz-zimnoch committed Feb 21, 2024
1 parent 743e9c7 commit 6b0a76a
Showing 1 changed file with 54 additions and 40 deletions.
94 changes: 54 additions & 40 deletions solidity/test/bridge/RedemptionWatchtower.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -172,65 +172,79 @@ describe("RedemptionWatchtower", () => {
})

describe("addGuardian", () => {
before(async () => {
await createSnapshot()

await redemptionWatchtower.connect(governance).enableWatchtower(
redemptionWatchtowerManager.address,
guardians.map((g) => g.address)
)
})

after(async () => {
await restoreSnapshot()
})

context("when called not by the watchtower manager", () => {
context("when watchtower manager is not set", () => {
// At this point, the watchtower manager is not set as `enableWatchtower`
// has not been called yet.
it("should revert", async () => {
await expect(
redemptionWatchtower
.connect(governance) // governance has not such a power
.connect(thirdParty)
.addGuardian(thirdParty.address)
).to.be.revertedWith("Caller is not watchtower manager")
})
})

context("when called by the watchtower manager", () => {
context("when guardian already exists", () => {
context("when watchtower manager is set", () => {
before(async () => {
await createSnapshot()

await redemptionWatchtower.connect(governance).enableWatchtower(
redemptionWatchtowerManager.address,
guardians.map((g) => g.address)
)
})

after(async () => {
await restoreSnapshot()
})

context("when called not by the watchtower manager", () => {
it("should revert", async () => {
await expect(
redemptionWatchtower
.connect(redemptionWatchtowerManager)
.addGuardian(guardians[0].address)
).to.be.revertedWith("Guardian already exists")
.connect(governance) // governance has not such a power
.addGuardian(thirdParty.address)
).to.be.revertedWith("Caller is not watchtower manager")
})
})

context("when guardian does not exist", () => {
let tx: ContractTransaction
context("when called by the watchtower manager", () => {
context("when guardian already exists", () => {
it("should revert", async () => {
await expect(
redemptionWatchtower
.connect(redemptionWatchtowerManager)
.addGuardian(guardians[0].address)
).to.be.revertedWith("Guardian already exists")
})
})

before(async () => {
await createSnapshot()
context("when guardian does not exist", () => {
let tx: ContractTransaction

tx = await redemptionWatchtower
.connect(redemptionWatchtowerManager)
.addGuardian(thirdParty.address)
})
before(async () => {
await createSnapshot()

after(async () => {
await restoreSnapshot()
})
tx = await redemptionWatchtower
.connect(redemptionWatchtowerManager)
.addGuardian(thirdParty.address)
})

it("should add the guardian properly", async () => {
// eslint-disable-next-line @typescript-eslint/no-unused-expressions
expect(await redemptionWatchtower.isGuardian(thirdParty.address)).to
.be.true
})
after(async () => {
await restoreSnapshot()
})

it("should emit GuardianAdded event", async () => {
await expect(tx)
.to.emit(redemptionWatchtower, "GuardianAdded")
.withArgs(thirdParty.address)
it("should add the guardian properly", async () => {
// eslint-disable-next-line @typescript-eslint/no-unused-expressions
expect(await redemptionWatchtower.isGuardian(thirdParty.address)).to
.be.true
})

it("should emit GuardianAdded event", async () => {
await expect(tx)
.to.emit(redemptionWatchtower, "GuardianAdded")
.withArgs(thirdParty.address)
})
})
})
})
Expand Down

0 comments on commit 6b0a76a

Please sign in to comment.