Skip to content

Commit

Permalink
Update staking unit tests
Browse files Browse the repository at this point in the history
Since the ERC4626 deposit function has different caller and receiver
roles, let's test them here. This will reflect the flow for tBTC minting
and staking in one transaction, where an external contract will call the
stake function in the name of the staker.
  • Loading branch information
r-czajkowski committed Dec 5, 2023
1 parent 4889a03 commit 9cac49c
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions core/test/Acre.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,23 +58,28 @@ describe("Acre", () => {
const expectedReceivedShares = amountToStake

let tx: ContractTransactionResponse
let tbtcHolder: HardhatEthersSigner
let receiver: HardhatEthersSigner

beforeEach(async () => {
tbtcHolder = staker1
receiver = staker2

await tbtc
.connect(staker1)
.connect(tbtcHolder)
.approve(await acre.getAddress(), amountToStake)

tx = await acre
.connect(staker1)
.stake(amountToStake, staker1.address, referral)
.connect(tbtcHolder)
.stake(amountToStake, receiver.address, referral)
})

it("should emit Deposit event", () => {
expect(tx).to.emit(acre, "Deposit").withArgs(
// Caller.
staker1.address,
tbtcHolder.address,
// Receiver.
staker1.address,
receiver.address,
// Staked tokens.
amountToStake,
// Received shares.
Expand All @@ -91,15 +96,15 @@ describe("Acre", () => {
it("should mint stBTC tokens", async () => {
await expect(tx).to.changeTokenBalances(
acre,
[staker1.address],
[receiver.address],
[expectedReceivedShares],
)
})

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

0 comments on commit 9cac49c

Please sign in to comment.