Skip to content

Commit

Permalink
Increase unit test coverage: unit tests for Deposit (#741)
Browse files Browse the repository at this point in the history
#Refs: #714.
This PR adds unit tests for the `Deposit` functions.
  • Loading branch information
lukasz-zimnoch authored Nov 15, 2023
2 parents d29ee31 + fef5f8c commit a9ed10d
Show file tree
Hide file tree
Showing 6 changed files with 259 additions and 36 deletions.
4 changes: 3 additions & 1 deletion typescript/api-reference/classes/Deposit.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,8 @@ Handle to tBTC contracts.
**detectFunding**(): `Promise`\<[`BitcoinUtxo`](../README.md#bitcoinutxo)[]\>

Detects Bitcoin funding transactions transferring BTC to this deposit.
The list includes UTXOs from both the blockchain and the mempool, sorted by
age with the newest ones first. Mempool UTXOs are listed at the beginning.

#### Returns

Expand All @@ -114,7 +116,7 @@ Specific UTXOs targeting this deposit. Empty array in case

#### Defined in

[src/services/deposits/deposit.ts:84](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/services/deposits/deposit.ts#L84)
[src/services/deposits/deposit.ts:85](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/services/deposits/deposit.ts#L85)

___

Expand Down
22 changes: 12 additions & 10 deletions typescript/api-reference/interfaces/BitcoinClient.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ Broadcasts the given transaction over the network.

#### Defined in

[src/lib/bitcoin/client.ts:101](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/lib/bitcoin/client.ts#L101)
[src/lib/bitcoin/client.ts:103](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/lib/bitcoin/client.ts#L103)

___

Expand All @@ -51,6 +51,8 @@ ___
**findAllUnspentTransactionOutputs**(`address`): `Promise`\<[`BitcoinUtxo`](../README.md#bitcoinutxo)[]\>

Finds all unspent transaction outputs (UTXOs) for given Bitcoin address.
The list includes UTXOs from both the blockchain and the mempool, sorted by
age with the newest ones first. Mempool UTXOs are listed at the beginning.

#### Parameters

Expand All @@ -66,7 +68,7 @@ List of UTXOs.

#### Defined in

[src/lib/bitcoin/client.ts:21](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/lib/bitcoin/client.ts#L21)
[src/lib/bitcoin/client.ts:23](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/lib/bitcoin/client.ts#L23)

___

Expand All @@ -91,7 +93,7 @@ Concatenation of block headers in a hexadecimal format.

#### Defined in

[src/lib/bitcoin/client.ts:84](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/lib/bitcoin/client.ts#L84)
[src/lib/bitcoin/client.ts:86](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/lib/bitcoin/client.ts#L86)

___

Expand Down Expand Up @@ -133,7 +135,7 @@ Raw transaction.

#### Defined in

[src/lib/bitcoin/client.ts:47](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/lib/bitcoin/client.ts#L47)
[src/lib/bitcoin/client.ts:49](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/lib/bitcoin/client.ts#L49)

___

Expand All @@ -157,7 +159,7 @@ Transaction object.

#### Defined in

[src/lib/bitcoin/client.ts:40](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/lib/bitcoin/client.ts#L40)
[src/lib/bitcoin/client.ts:42](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/lib/bitcoin/client.ts#L42)

___

Expand All @@ -182,7 +184,7 @@ The number of confirmations.

#### Defined in

[src/lib/bitcoin/client.ts:55](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/lib/bitcoin/client.ts#L55)
[src/lib/bitcoin/client.ts:57](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/lib/bitcoin/client.ts#L57)

___

Expand All @@ -208,7 +210,7 @@ at the moment of request.

#### Defined in

[src/lib/bitcoin/client.ts:33](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/lib/bitcoin/client.ts#L33)
[src/lib/bitcoin/client.ts:35](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/lib/bitcoin/client.ts#L35)

___

Expand All @@ -233,7 +235,7 @@ Merkle branch.

#### Defined in

[src/lib/bitcoin/client.ts:92](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/lib/bitcoin/client.ts#L92)
[src/lib/bitcoin/client.ts:94](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/lib/bitcoin/client.ts#L94)

___

Expand Down Expand Up @@ -263,7 +265,7 @@ Array of confirmed transaction hashes related to the provided

#### Defined in

[src/lib/bitcoin/client.ts:69](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/lib/bitcoin/client.ts#L69)
[src/lib/bitcoin/client.ts:71](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/lib/bitcoin/client.ts#L71)

___

Expand All @@ -281,4 +283,4 @@ Height of the last mined block.

#### Defined in

[src/lib/bitcoin/client.ts:75](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/lib/bitcoin/client.ts#L75)
[src/lib/bitcoin/client.ts:77](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/lib/bitcoin/client.ts#L77)
2 changes: 2 additions & 0 deletions typescript/src/lib/bitcoin/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ export interface BitcoinClient {

/**
* Finds all unspent transaction outputs (UTXOs) for given Bitcoin address.
* The list includes UTXOs from both the blockchain and the mempool, sorted by
* age with the newest ones first. Mempool UTXOs are listed at the beginning.
* @param address - Bitcoin address UTXOs should be determined for.
* @returns List of UTXOs.
*/
Expand Down
6 changes: 3 additions & 3 deletions typescript/src/services/deposits/deposit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,11 @@ export class Deposit {

/**
* Detects Bitcoin funding transactions transferring BTC to this deposit.
* @return Specific UTXOs targeting this deposit. Empty array in case
* The list includes UTXOs from both the blockchain and the mempool, sorted by
* age with the newest ones first. Mempool UTXOs are listed at the beginning.
* @returns Specific UTXOs targeting this deposit. Empty array in case
* there are no UTXOs referring this deposit.
*/
// TODO: Cover with unit tests.
async detectFunding(): Promise<BitcoinUtxo[]> {
const utxos = await this.bitcoinClient.findAllUnspentTransactionOutputs(
await this.getBitcoinAddress()
Expand Down Expand Up @@ -110,7 +111,6 @@ export class Deposit {
* @throws Throws an error if the funding outpoint was already used to
* initiate minting (both modes).
*/
// TODO: Cover auto funding outpoint detection with unit tests.
async initiateMinting(fundingOutpoint?: BitcoinTxOutpoint): Promise<Hex> {
let resolvedFundingOutpoint: BitcoinTxOutpoint

Expand Down
Loading

0 comments on commit a9ed10d

Please sign in to comment.