|
| 1 | +const chai = require("chai") |
| 2 | +const expect = chai.expect |
| 3 | + |
| 4 | +const { ZERO_ADDRESS } = require("./helpers/contract-test-helpers") |
| 5 | + |
| 6 | +describe("SignerBondsEscrow", () => { |
| 7 | + let governance |
| 8 | + let riskManager |
| 9 | + let signerBondsEscrow |
| 10 | + |
| 11 | + beforeEach(async () => { |
| 12 | + governance = await ethers.getSigner(0) |
| 13 | + riskManager = await ethers.getSigner(1) |
| 14 | + |
| 15 | + const SignerBondsEscrow = await ethers.getContractFactory( |
| 16 | + "SignerBondsEscrow" |
| 17 | + ) |
| 18 | + signerBondsEscrow = await SignerBondsEscrow.deploy() |
| 19 | + await signerBondsEscrow.deployed() |
| 20 | + }) |
| 21 | + |
| 22 | + describe("swapSignerBonds", () => { |
| 23 | + let tx |
| 24 | + |
| 25 | + beforeEach(async () => { |
| 26 | + tx = await signerBondsEscrow |
| 27 | + .connect(riskManager) |
| 28 | + .swapSignerBonds({ value: ethers.utils.parseEther("10") }) |
| 29 | + }) |
| 30 | + |
| 31 | + it("should add the processed signer bonds to the contract balance", async () => { |
| 32 | + await expect(tx).to.changeEtherBalance( |
| 33 | + signerBondsEscrow, |
| 34 | + ethers.utils.parseEther("10") |
| 35 | + ) |
| 36 | + }) |
| 37 | + }) |
| 38 | + |
| 39 | + describe("withdraw", () => { |
| 40 | + context( |
| 41 | + "when the caller is the governance, target address is non-zero, " + |
| 42 | + "and there are available funds", |
| 43 | + () => { |
| 44 | + let tx |
| 45 | + |
| 46 | + beforeEach(async () => { |
| 47 | + await signerBondsEscrow |
| 48 | + .connect(riskManager) |
| 49 | + .swapSignerBonds({ value: ethers.utils.parseEther("10") }) |
| 50 | + |
| 51 | + tx = await signerBondsEscrow |
| 52 | + .connect(governance) |
| 53 | + .withdraw(riskManager.address) |
| 54 | + }) |
| 55 | + |
| 56 | + it("transfer all funds to the target account", async () => { |
| 57 | + await expect(tx).to.changeEtherBalance( |
| 58 | + signerBondsEscrow, |
| 59 | + ethers.utils.parseEther("10").mul(-1) |
| 60 | + ) |
| 61 | + await expect(tx).to.changeEtherBalance( |
| 62 | + riskManager, |
| 63 | + ethers.utils.parseEther("10") |
| 64 | + ) |
| 65 | + }) |
| 66 | + } |
| 67 | + ) |
| 68 | + |
| 69 | + context("when the caller is not the governance", () => { |
| 70 | + it("should revert", async () => { |
| 71 | + await expect( |
| 72 | + signerBondsEscrow.connect(riskManager).withdraw(riskManager.address) |
| 73 | + ).to.be.revertedWith("Ownable: caller is not the owner") |
| 74 | + }) |
| 75 | + }) |
| 76 | + |
| 77 | + context("when the target address is zero", () => { |
| 78 | + it("should revert", async () => { |
| 79 | + await expect( |
| 80 | + signerBondsEscrow.connect(governance).withdraw(ZERO_ADDRESS) |
| 81 | + ).to.be.revertedWith("Invalid recipient address") |
| 82 | + }) |
| 83 | + }) |
| 84 | + |
| 85 | + context("when there are no available funds", () => { |
| 86 | + it("should not transfer any funds", async () => { |
| 87 | + const tx = await signerBondsEscrow |
| 88 | + .connect(governance) |
| 89 | + .withdraw(riskManager.address) |
| 90 | + await expect(tx).to.changeEtherBalance(signerBondsEscrow, 0) |
| 91 | + await expect(tx).to.changeEtherBalance(riskManager, 0) |
| 92 | + }) |
| 93 | + }) |
| 94 | + }) |
| 95 | +}) |
0 commit comments