Skip to content

Commit

Permalink
Add unit tests for deposit function
Browse files Browse the repository at this point in the history
We overridden `deposit` function and now it takes into account the
minimum deposit amount parameter - here we add unit test for this
function to cover a cases where the deposit amount is less than minimum
and equal to the minimum amount. We indirectly cover this check's test
in `stake` tests but we want to add an explicit `deposit` function test
that covers it as well.
  • Loading branch information
r-czajkowski committed Dec 28, 2023
1 parent 54bcf17 commit 0f8b830
Showing 1 changed file with 66 additions and 0 deletions.
66 changes: 66 additions & 0 deletions core/test/Acre.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -885,4 +885,70 @@ describe("Acre", () => {
})
})
})

describe("deposit", () => {
let amountToDeposit: bigint
let minimumDepositAmount: bigint

beforeEach(async () => {
minimumDepositAmount = await acre.minimumDepositAmount()
})

context("when the deposit amount is less than minimum", () => {
beforeEach(() => {
amountToDeposit = minimumDepositAmount - 1n
})

it("should revert", async () => {
await expect(acre.deposit(amountToDeposit, staker1.address))
.to.be.revertedWithCustomError(acre, "DepositAmountLessThanMin")
.withArgs(amountToDeposit, minimumDepositAmount)
})
})

context(
"when the deposit amount is equal to the minimum deposit amount",
() => {
let tx: ContractTransactionResponse
let expectedReceivedShares: bigint

beforeEach(async () => {
amountToDeposit = minimumDepositAmount
expectedReceivedShares = amountToDeposit

await tbtc.approve(await acre.getAddress(), amountToDeposit)
tx = await acre.deposit(amountToDeposit, staker1.address)
})

it("should emit Deposit event", () => {
expect(tx).to.emit(acre, "Deposit").withArgs(
// Caller.
staker1.address,
// Receiver.
staker1.address,
// Staked tokens.
amountToDeposit,
// Received shares.
expectedReceivedShares,
)
})

it("should mint stBTC tokens", async () => {
await expect(tx).to.changeTokenBalances(
acre,
[staker1.address],
[expectedReceivedShares],
)
})

it("should transfer tBTC tokens", async () => {
await expect(tx).to.changeTokenBalances(
tbtc,
[staker1.address, acre],
[-amountToDeposit, amountToDeposit],
)
})
},
)
})
})

0 comments on commit 0f8b830

Please sign in to comment.