Skip to content

Commit

Permalink
Implemented getUnconfirmBalance and incomplete tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
aikchun committed Jun 8, 2021
1 parent 257722e commit ee98eae
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { MasterNodeRegTestContainer } from '@defichain/testcontainers'
import { ContainerAdapterClient } from '../../container_adapter_client'

describe('Balance on masternode', () => {
const container = new MasterNodeRegTestContainer()
const client = new ContainerAdapterClient(container)

beforeAll(async () => {
await container.start()
await container.waitForReady()
await container.waitForWalletCoinbaseMaturity()
})

afterAll(async () => {
await container.stop()
})

it('should getUnconfirmedBalance', async () => {
const address = 'mwsZw8nF7pKxWH8eoKL9tPxTpaFkz7QeLU'
const unconfirmedbalance = await client.wallet.getUnconfirmedBalance()

expect(unconfirmedbalance.toNumber()).toStrictEqual(0)
await client.wallet.sendToAddress(address, 35)

await container.generate(1)

const newUnconfirmedBalance = await client.wallet.getUnconfirmedBalance()

expect(newUnconfirmedBalance.toNumber()).toStrictEqual(0)
})
})
10 changes: 10 additions & 0 deletions packages/jellyfish-api-core/src/category/wallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,16 @@ export class Wallet {
return await this.client.call('getbalance', ['*', minimumConfirmation, includeWatchOnly], 'bignumber')
}

/**
* Identical to getBalance to get untrusted pending balance
*
* @param {boolean} withTokens
* @return Promise<BigNumber>
*/
async getUnconfirmedBalance (withTokens: boolean = false): Promise<BigNumber> {
return await this.client.call('getunconfirmedbalance', [withTokens], 'bignumber')
}

/**
* Get list of UTXOs in wallet.
*
Expand Down
11 changes: 11 additions & 0 deletions website/docs/jellyfish/api/wallet.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,17 @@ interface wallet {
}
```

## getUnconfirmedBalance

Identical to getBalance to get untrusted pending balance
- `withTokens` to include token balances, default is false for backward compatibility

```ts title="client.wallet.getUnconfirmedBalance()"
interface wallet {
getUnconfirmedBalance(withTokens = false): Promise<number>
}
```

## listUnspent

Get list of UTXOs in wallet.
Expand Down

0 comments on commit ee98eae

Please sign in to comment.