Skip to content

Commit 912e2be

Browse files
authored
Merge pull request #442 from threshold-network/tbtc-tests
Tbtc tests Adds tests for TBTC class in `threshold-ts` lib. Also resolves other tests that might have not worked because of some tBTCv2-ts libs.
2 parents 6c3ceb7 + 2c10f49 commit 912e2be

File tree

9 files changed

+816
-9
lines changed

9 files changed

+816
-9
lines changed

.env.test

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
REACT_APP_SUPPORTED_CHAIN_ID=1337
2+
REACT_APP_MULTICALL_ADDRESS=0x086813525A7dC7dafFf015Cdf03896Fd276eab60

src/hooks/__tests__/useFetchTvl.test.tsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,11 @@ describe("Test `useFetchTvl` hook", () => {
4040
usdConversion: 2,
4141
} as any
4242

43+
const tbtcv2Context = {
44+
contract: {} as any,
45+
usdConversion: 2,
46+
} as any
47+
4348
const tContext = {
4449
contract: {} as any,
4550
usdConversion: 3,
@@ -61,6 +66,7 @@ describe("Test `useFetchTvl` hook", () => {
6166
value={{
6267
[Token.Keep]: keepContext,
6368
[Token.TBTC]: tbtcContext,
69+
[Token.TBTCV2]: tbtcv2Context,
6470
[Token.T]: tContext,
6571
[Token.Nu]: nuContext,
6672
}}

src/setupTests.js

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,46 @@
44
// learn more: https://github.com/testing-library/jest-dom
55
import "@testing-library/jest-dom"
66

7-
jest.mock("@keep-network/tbtc-v2.ts/dist/src", () => ({}))
7+
jest.mock("@keep-network/tbtc-v2.ts/dist/src/deposit", () => ({
8+
calculateDepositAddress: jest.fn(),
9+
calculateDepositRefundLocktime: jest.fn(),
10+
DepositScriptParameters: jest.fn(),
11+
revealDeposit: jest.fn(),
12+
getRevealedDeposit: jest.fn(),
13+
}))
14+
15+
jest.mock("@keep-network/tbtc-v2.ts/dist/src/bitcoin", () => ({
16+
decodeBitcoinAddress: jest.fn(),
17+
TransactionHash: {
18+
from: jest.fn().mockReturnValue({
19+
reverse: jest
20+
.fn()
21+
.mockReturnValue(
22+
"reversed_9eb901fc68f0d9bcaf575f23783b7d30ac5dd8d95f3c83dceaa13dce17de816a"
23+
),
24+
toString: jest
25+
.fn()
26+
.mockReturnValue(
27+
"9eb901fc68f0d9bcaf575f23783b7d30ac5dd8d95f3c83dceaa13dce17de816a"
28+
),
29+
}),
30+
reverse: jest
31+
.fn()
32+
.mockReturnValue(
33+
"reversed_9eb901fc68f0d9bcaf575f23783b7d30ac5dd8d95f3c83dceaa13dce17de816a"
34+
),
35+
toString: jest
36+
.fn()
37+
.mockReturnValue(
38+
"9eb901fc68f0d9bcaf575f23783b7d30ac5dd8d95f3c83dceaa13dce17de816a"
39+
),
40+
},
41+
computeHash160: jest.fn(),
42+
}))
43+
44+
jest.mock("@keep-network/tbtc-v2.ts/dist/src", () => ({
45+
EthereumBridge: jest.fn(),
46+
ElectrumClient: jest.fn(),
47+
}))
48+
49+
jest.mock("crypto-js")

src/tbtc/mock-bitcoin-client.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ const testnetTransaction: RawTransaction = {
3131
"f68e65aa2727cd4208b5012102ee067a0273f2e3ba88d23140a24fdb290f27bbcd0f94" +
3232
"117a9c65be3911c5c04e00000000",
3333
}
34-
const testnetUTXO: UnspentTransactionOutput & RawTransaction = {
34+
export const testnetUTXO: UnspentTransactionOutput & RawTransaction = {
3535
transactionHash: testnetTransactionHash,
3636
outputIndex: 1,
3737
value: BigNumber.from(3933200),

src/threshold-ts/applications/__tests__/application.test.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,7 @@ describe("Application test", () => {
201201
currentBlockTimestamp +
202202
remainingAuthorizationDecreaseDelay -
203203
authorizationDecreaseDelay
204+
const operator = "0xeCbEb9B6Aa18dD3B57ECD061490ae5029c05EC91"
204205
const testCases = [
205206
{
206207
remainingAuthorizationDecreaseDelay: MAX_UINT64,
@@ -243,17 +244,22 @@ describe("Application test", () => {
243244
const authParameters = {
244245
authorizationDecreaseDelay,
245246
}
247+
246248
const multicallResult = [
247249
authorizedStake,
248250
pendingAuthorizationDecrease,
249251
remainingAuthorizationDecreaseDelay,
250252
currentBlockTimestamp,
251253
authParameters,
254+
[operator],
252255
]
253256

254257
const multicallSpy = jest
255258
.spyOn(mockMulticall, "aggregate")
256259
.mockResolvedValue(multicallResult)
260+
const isOperatorInPoolSpy = jest
261+
.spyOn(mockAppContract, "isOperatorInPool")
262+
.mockResolvedValue(false)
257263

258264
const result = await application.getStakingProviderAppInfo(
259265
stakingProvider
@@ -284,11 +290,20 @@ describe("Application test", () => {
284290
address: application.address,
285291
method: "authorizationParameters",
286292
},
293+
{
294+
interface: application.contract.interface,
295+
address: application.address,
296+
method: "stakingProviderToOperator",
297+
args: [stakingProvider],
298+
},
287299
])
300+
expect(isOperatorInPoolSpy).toHaveBeenCalledWith(operator)
288301
expect(result).toEqual({
289302
authorizedStake,
290303
pendingAuthorizationDecrease,
291304
remainingAuthorizationDecreaseDelay,
305+
isOperatorInPool: false,
306+
operator,
292307
...expectedValue,
293308
})
294309
}

0 commit comments

Comments
 (0)