Skip to content

Commit

Permalink
Used Bitcoin client instances from SDK
Browse files Browse the repository at this point in the history
  • Loading branch information
tomaszslabon committed Nov 14, 2023
1 parent 40e46b4 commit 3c4fd74
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 20 deletions.
46 changes: 29 additions & 17 deletions system-tests/test/deposit-redemption.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ describe("System Test - Deposit and redemption", () => {
let bank: Contract
let relay: Contract

let electrumClient: ElectrumClient
let depositorSdk: TBTC
let maintainerSdk: TBTC
let walletTx: WalletTx
Expand Down Expand Up @@ -96,7 +95,7 @@ describe("System Test - Deposit and redemption", () => {
maintainer
)

electrumClient = ElectrumClient.fromUrl(
const electrumClient = ElectrumClient.fromUrl(
electrumUrl,
undefined,
ELECTRUM_RETRIES,
Expand Down Expand Up @@ -157,7 +156,7 @@ describe("System Test - Deposit and redemption", () => {
`)

const depositorUtxos =
await electrumClient.findAllUnspentTransactionOutputs(
await depositorSdk.bitcoinClient.findAllUnspentTransactionOutputs(
depositorBitcoinAddress
)

Expand All @@ -166,7 +165,7 @@ describe("System Test - Deposit and redemption", () => {
depositorUtxos,
depositTxFee,
systemTestsContext.depositorBitcoinKeyPair.wif,
electrumClient
depositorSdk.bitcoinClient
))

console.log(`
Expand All @@ -178,9 +177,10 @@ describe("System Test - Deposit and redemption", () => {
// Since the reveal deposit logic does not perform SPV proof, we
// can reveal the deposit transaction immediately without waiting
// for confirmations.
const rawDepositTransaction = await electrumClient.getRawTransaction(
depositUtxo.transactionHash
)
const rawDepositTransaction =
await depositorSdk.bitcoinClient.getRawTransaction(
depositUtxo.transactionHash
)
const depositRawTxVectors = extractBitcoinRawTxVectors(
rawDepositTransaction
)
Expand All @@ -199,8 +199,11 @@ describe("System Test - Deposit and redemption", () => {

it("should broadcast the deposit transaction on the Bitcoin network", async () => {
expect(
(await electrumClient.getRawTransaction(depositUtxo.transactionHash))
.transactionHex.length
(
await maintainerSdk.bitcoinClient.getRawTransaction(
depositUtxo.transactionHash
)
).transactionHex.length
).to.be.greaterThan(0)
})

Expand Down Expand Up @@ -231,13 +234,13 @@ describe("System Test - Deposit and redemption", () => {
// transaction to have an enough number of confirmations. This is
// because the bridge performs the SPV proof of that transaction.
await waitTransactionConfirmed(
electrumClient,
maintainerSdk.bitcoinClient,
sweepUtxo.transactionHash
)

await fakeRelayDifficulty(
relay,
electrumClient,
maintainerSdk.bitcoinClient,
sweepUtxo.transactionHash
)

Expand All @@ -262,8 +265,11 @@ describe("System Test - Deposit and redemption", () => {

it("should broadcast the sweep transaction on the Bitcoin network", async () => {
expect(
(await electrumClient.getRawTransaction(sweepUtxo.transactionHash))
.transactionHex.length
(
await maintainerSdk.bitcoinClient.getRawTransaction(
sweepUtxo.transactionHash
)
).transactionHex.length
).to.be.greaterThan(0)
})

Expand Down Expand Up @@ -373,11 +379,14 @@ describe("System Test - Deposit and redemption", () => {
`- Transaction hash: ${redemptionTxHash}`
)

await waitTransactionConfirmed(electrumClient, redemptionTxHash)
await waitTransactionConfirmed(
maintainerSdk.bitcoinClient,
redemptionTxHash
)

await fakeRelayDifficulty(
relay,
electrumClient,
maintainerSdk.bitcoinClient,
redemptionTxHash
)

Expand All @@ -393,8 +402,11 @@ describe("System Test - Deposit and redemption", () => {

it("should broadcast the redemption transaction on the Bitcoin network", async () => {
expect(
(await electrumClient.getRawTransaction(redemptionTxHash))
.transactionHex.length
(
await maintainerSdk.bitcoinClient.getRawTransaction(
redemptionTxHash
)
).transactionHex.length
).to.be.greaterThan(0)
})

Expand Down
6 changes: 3 additions & 3 deletions system-tests/test/utils/bitcoin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import wifLib from "wif"
import { ec as EllipticCurve } from "elliptic"
import { assembleBitcoinSpvProof, Hex } from "@keep-network/tbtc-v2.ts"

import type { BitcoinTxHash, ElectrumClient } from "@keep-network/tbtc-v2.ts"
import type { BitcoinTxHash, BitcoinClient } from "@keep-network/tbtc-v2.ts"
import type { Contract } from "ethers"

/**
Expand Down Expand Up @@ -75,7 +75,7 @@ export function keyPairFromWif(wif: string): KeyPair {
* @returns Empty promise.
*/
export async function waitTransactionConfirmed(
bitcoinClient: ElectrumClient,
bitcoinClient: BitcoinClient,
transactionHash: BitcoinTxHash,
requiredConfirmations: number = defaultTxProofDifficultyFactor,
sleep = 30000
Expand Down Expand Up @@ -126,7 +126,7 @@ export async function waitTransactionConfirmed(
*/
export async function fakeRelayDifficulty(
relay: Contract,
bitcoinClient: ElectrumClient,
bitcoinClient: BitcoinClient,
transactionHash: BitcoinTxHash,
headerChainLength: number = defaultTxProofDifficultyFactor
): Promise<void> {
Expand Down

0 comments on commit 3c4fd74

Please sign in to comment.