Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Read the min amount of BTC deposit from the SDK #303

Merged
merged 21 commits into from
Apr 16, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
0f3a8e4
Read the min amount of BTC deposit from the SDK
kkosiorowska Mar 7, 2024
836a300
Use a `bigint` type in `StakeDetails` and validation
kkosiorowska Mar 7, 2024
904ddcf
Merge branch 'main' of github.com:thesis/acre into min-amount-btc
kkosiorowska Apr 9, 2024
3766428
Rename from `minDepositAmount` to `minStakeAmount`
kkosiorowska Apr 9, 2024
45d58fd
Move `useFetchBTCBalance` to `useFetchSdkData`
kkosiorowska Apr 9, 2024
88f96d8
Create a hook for min stake amount
kkosiorowska Apr 9, 2024
d7884f8
Add `fromSatoshi` and `toSatoshi` to utils function
kkosiorowska Apr 9, 2024
4244f92
Add min stake amount to the staking module
kkosiorowska Apr 9, 2024
49b4306
Read the min amount of BTC deposit from the SDK
kkosiorowska Apr 9, 2024
243a507
Add tests for `minStake` from BitcoinDepositor contract
kkosiorowska Apr 10, 2024
e5c3f3a
Use bigint type for the token balance in the form
kkosiorowska Apr 10, 2024
3265221
Merge branch 'main' of github.com:thesis/acre into min-amount-btc
kkosiorowska Apr 10, 2024
1f55b26
Remove unnecessary conversion to `bigint`
kkosiorowska Apr 10, 2024
d920ad3
Remove unnecessary check condition for bigint
kkosiorowska Apr 10, 2024
7e0c787
Fix issues after merge
kkosiorowska Apr 10, 2024
679374c
Use `useMinStakeAmount` instead of a simple selector
kkosiorowska Apr 12, 2024
7ff5b12
Merge branch 'main' of github.com:thesis/acre into min-amount-btc
kkosiorowska Apr 12, 2024
4734e21
Remove unneeded function declaration after merge
kkosiorowska Apr 12, 2024
f50a49d
Rename stake to deposit for minimum amount
kkosiorowska Apr 12, 2024
b0a0167
Rename from `useFetchSdkData` to `useInitDataFromSdk`
kkosiorowska Apr 12, 2024
b836867
Merge branch 'main' of github.com:thesis/acre into min-amount-btc
kkosiorowska Apr 15, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add tests for minStake from BitcoinDepositor contract
  • Loading branch information
kkosiorowska committed Apr 10, 2024
commit 243a507244de167be8e111dc9fb91ef490eea743
10 changes: 10 additions & 0 deletions sdk/test/lib/ethereum/tbtc-depositor.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,12 @@ describe("BitcoinDepositor", () => {
const vaultAddress = EthereumAddress.from(
ethers.Wallet.createRandom().address,
)
const minStakeAmount = BigInt(0.015 * 1e18)

const mockedContractInstance = {
tbtcVault: jest.fn().mockImplementation(() => vaultAddress.identifierHex),
initializeStake: jest.fn(),
minStake: jest.fn().mockImplementation(() => minStakeAmount),
}
let depositor: EthereumBitcoinDepositor
let depositorAddress: EthereumAddress
Expand Down Expand Up @@ -241,4 +243,12 @@ describe("BitcoinDepositor", () => {
},
)
})

describe("minStake", () => {
it("should return minimum stake amount", async () => {
const result = await depositor.minStake()

expect(result).toEqual(minStakeAmount)
})
})
})
27 changes: 27 additions & 0 deletions sdk/test/modules/staking.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
import { MockAcreContracts } from "../utils/mock-acre-contracts"
import { MockMessageSigner } from "../utils/mock-message-signer"
import { MockTBTC } from "../utils/mock-tbtc"
import * as satoshiConverterUtils from "../../src/lib/utils/satoshi-converter"

const stakingModuleData: {
initializeStake: {
Expand Down Expand Up @@ -395,4 +396,30 @@ describe("Staking", () => {
expect(result).toEqual(expectedResult)
})
})

describe("minStakeAmount", () => {
describe("should return minimum stake amount", () => {
const spyOnToSatoshi = jest.spyOn(satoshiConverterUtils, "toSatoshi")
const mockedResult = BigInt(0.015 * 1e18)
// The returned result should be in satoshi precision
const expectedResult = BigInt(0.015 * 1e8)
let result: bigint

beforeAll(async () => {
contracts.bitcoinDepositor.minStake = jest
.fn()
.mockResolvedValue(mockedResult)
result = await staking.minStakeAmount()
})

it("should convert value to 1e8 satoshi precision", () => {
expect(spyOnToSatoshi).toHaveBeenCalledWith(mockedResult)
expect(spyOnToSatoshi).toHaveReturnedWith(expectedResult)
})

it(`should return ${expectedResult}`, () => {
expect(result).toBe(expectedResult)
})
})
})
})