From c802e5b5be83eaf882908b599cff9a9f048e225c Mon Sep 17 00:00:00 2001 From: Kodemon Date: Thu, 6 Jan 2022 07:08:09 +0000 Subject: [PATCH 1/5] add list wallets rpc --- docs/node/CATEGORIES/05-wallet.md | 12 ++++++ .../category/wallet/listWallets.test.ts | 38 +++++++++++++++++++ .../jellyfish-api-core/src/category/wallet.ts | 10 +++++ 3 files changed, 60 insertions(+) create mode 100644 packages/jellyfish-api-core/__tests__/category/wallet/listWallets.test.ts diff --git a/docs/node/CATEGORIES/05-wallet.md b/docs/node/CATEGORIES/05-wallet.md index c4650ffb4f..aac6cd276d 100644 --- a/docs/node/CATEGORIES/05-wallet.md +++ b/docs/node/CATEGORIES/05-wallet.md @@ -385,3 +385,15 @@ interface wallet { importPrivKey (privkey: string, label: string = "", rescan: boolean = true): Promise } ``` + +## listWallets + +Returns a list of currently loaded wallets. + +For full information on the wallet, use [getWalletInfo](#getwalletinfo) + +```ts title="client.wallet.listWallets()" +interface wallet { + listWallets (): Promise +} +``` \ No newline at end of file diff --git a/packages/jellyfish-api-core/__tests__/category/wallet/listWallets.test.ts b/packages/jellyfish-api-core/__tests__/category/wallet/listWallets.test.ts new file mode 100644 index 0000000000..dc60a69a2a --- /dev/null +++ b/packages/jellyfish-api-core/__tests__/category/wallet/listWallets.test.ts @@ -0,0 +1,38 @@ +import { MasterNodeRegTestContainer, RegTestContainer } from '@defichain/testcontainers' +import { ContainerAdapterClient } from '../../container_adapter_client' + +describe('Wallet without masternode', () => { + const container = new RegTestContainer() + const client = new ContainerAdapterClient(container) + + beforeAll(async () => { + await container.start() + await client.wallet.createWallet('test') + }) + + afterAll(async () => { + await container.stop() + }) + + it('should listWallets', async () => { + await expect(client.wallet.listWallets()).resolves.toEqual(['', 'test']) + }) +}) + +describe('Wallet with masternode', () => { + const container = new MasterNodeRegTestContainer() + const client = new ContainerAdapterClient(container) + + beforeAll(async () => { + await container.start() + await client.wallet.createWallet('test') + }) + + afterAll(async () => { + await container.stop() + }) + + it('should listWallets', async () => { + await expect(client.wallet.listWallets()).resolves.toEqual(['', 'test']) + }) +}) diff --git a/packages/jellyfish-api-core/src/category/wallet.ts b/packages/jellyfish-api-core/src/category/wallet.ts index 74f04a6889..021c1da2ac 100644 --- a/packages/jellyfish-api-core/src/category/wallet.ts +++ b/packages/jellyfish-api-core/src/category/wallet.ts @@ -314,6 +314,16 @@ export class Wallet { async getTransaction (txid: string, includeWatchOnly: boolean = true): Promise { return await this.client.call('gettransaction', [txid, includeWatchOnly], { amount: 'bignumber' }) } + + /** + * Returns a list of currently loaded wallets. + * For full information on the wallet, use 'getwalletinfo' + * + * @return {Promise} + */ + async listWallets (): Promise { + return await this.client.call('listwallets', [], 'number') + } } export interface UTXO { From add7b3a1e30f1795588895d3676198082f7a35ba Mon Sep 17 00:00:00 2001 From: Kodemon Date: Wed, 12 Jan 2022 02:39:32 +0000 Subject: [PATCH 2/5] use testing package for container creation --- .../__tests__/category/wallet/listWallets.test.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/jellyfish-api-core/__tests__/category/wallet/listWallets.test.ts b/packages/jellyfish-api-core/__tests__/category/wallet/listWallets.test.ts index dc60a69a2a..af8e52e27e 100644 --- a/packages/jellyfish-api-core/__tests__/category/wallet/listWallets.test.ts +++ b/packages/jellyfish-api-core/__tests__/category/wallet/listWallets.test.ts @@ -1,3 +1,4 @@ +import { Testing } from '@defichain/jellyfish-testing' import { MasterNodeRegTestContainer, RegTestContainer } from '@defichain/testcontainers' import { ContainerAdapterClient } from '../../container_adapter_client' @@ -20,12 +21,11 @@ describe('Wallet without masternode', () => { }) describe('Wallet with masternode', () => { - const container = new MasterNodeRegTestContainer() - const client = new ContainerAdapterClient(container) + const { container, rpc: { wallet } } = Testing.create(new MasterNodeRegTestContainer()) beforeAll(async () => { await container.start() - await client.wallet.createWallet('test') + await wallet.createWallet('test') }) afterAll(async () => { @@ -33,6 +33,6 @@ describe('Wallet with masternode', () => { }) it('should listWallets', async () => { - await expect(client.wallet.listWallets()).resolves.toEqual(['', 'test']) + await expect(wallet.listWallets()).resolves.toEqual(['', 'test']) }) }) From e997a38080c9d3054a37e3409a11656b06aa885c Mon Sep 17 00:00:00 2001 From: Christoffer Date: Sat, 19 Feb 2022 02:40:12 +0900 Subject: [PATCH 3/5] tweak value assignment as per suggestion Co-authored-by: Fuxing Loh <4266087+fuxingloh@users.noreply.github.com> --- .../__tests__/category/wallet/listWallets.test.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/jellyfish-api-core/__tests__/category/wallet/listWallets.test.ts b/packages/jellyfish-api-core/__tests__/category/wallet/listWallets.test.ts index af8e52e27e..f1931fe796 100644 --- a/packages/jellyfish-api-core/__tests__/category/wallet/listWallets.test.ts +++ b/packages/jellyfish-api-core/__tests__/category/wallet/listWallets.test.ts @@ -16,7 +16,8 @@ describe('Wallet without masternode', () => { }) it('should listWallets', async () => { - await expect(client.wallet.listWallets()).resolves.toEqual(['', 'test']) + const wallets = await client.wallet.listWallets() + expect(wallets).toStrictEqual(['', 'test']) }) }) From 8e6b9e196ee39cbf6b3fe16c921f4c98c1978d04 Mon Sep 17 00:00:00 2001 From: Kodemon Date: Mon, 21 Feb 2022 04:32:47 +0000 Subject: [PATCH 4/5] split wallets generation and expect test --- .../__tests__/category/wallet/listWallets.test.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/jellyfish-api-core/__tests__/category/wallet/listWallets.test.ts b/packages/jellyfish-api-core/__tests__/category/wallet/listWallets.test.ts index f1931fe796..f70885efe6 100644 --- a/packages/jellyfish-api-core/__tests__/category/wallet/listWallets.test.ts +++ b/packages/jellyfish-api-core/__tests__/category/wallet/listWallets.test.ts @@ -34,6 +34,7 @@ describe('Wallet with masternode', () => { }) it('should listWallets', async () => { - await expect(wallet.listWallets()).resolves.toEqual(['', 'test']) + const wallets = await wallet.listWallets() + expect(wallets).toEqual(['', 'test']) }) }) From 24bc79d9b283ba5ea68395dea72a2f96caad8f8c Mon Sep 17 00:00:00 2001 From: Kodemon Date: Mon, 21 Feb 2022 07:37:09 +0000 Subject: [PATCH 5/5] further update tests based on feedback --- .../__tests__/category/wallet/listWallets.test.ts | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/packages/jellyfish-api-core/__tests__/category/wallet/listWallets.test.ts b/packages/jellyfish-api-core/__tests__/category/wallet/listWallets.test.ts index f70885efe6..ecfe5ecc34 100644 --- a/packages/jellyfish-api-core/__tests__/category/wallet/listWallets.test.ts +++ b/packages/jellyfish-api-core/__tests__/category/wallet/listWallets.test.ts @@ -22,19 +22,20 @@ describe('Wallet without masternode', () => { }) describe('Wallet with masternode', () => { - const { container, rpc: { wallet } } = Testing.create(new MasterNodeRegTestContainer()) + const master = new MasterNodeRegTestContainer() + const testing = Testing.create(master) beforeAll(async () => { - await container.start() - await wallet.createWallet('test') + await testing.container.start() + await testing.rpc.wallet.createWallet('test') }) afterAll(async () => { - await container.stop() + await testing.container.stop() }) it('should listWallets', async () => { - const wallets = await wallet.listWallets() + const wallets = await testing.rpc.wallet.listWallets() expect(wallets).toEqual(['', 'test']) }) })