From 48dd22bab717cf18f21b7ad2862ba4bda0c27cf6 Mon Sep 17 00:00:00 2001 From: Dilshan Madushanka Date: Mon, 17 Oct 2022 11:56:13 +0530 Subject: [PATCH] feat(jellyfish-api-core): add masternode clearMempool RPC (#1801) What this PR does / why we need it: /kind feature Which issue(s) does this PR fixes?: Fixes part of https://github.com/JellyfishSDK/jellyfish/issues/48 - Implements `clearmempool` type for RPC. --- docs/node/CATEGORIES/11-masternode.md | 9 ++++++ .../category/masternode/clearMempool.test.ts | 30 +++++++++++++++++++ .../src/category/masternode.ts | 8 +++++ 3 files changed, 47 insertions(+) create mode 100644 packages/jellyfish-api-core/__tests__/category/masternode/clearMempool.test.ts diff --git a/docs/node/CATEGORIES/11-masternode.md b/docs/node/CATEGORIES/11-masternode.md index 309c104dda..feda9551a0 100644 --- a/docs/node/CATEGORIES/11-masternode.md +++ b/docs/node/CATEGORIES/11-masternode.md @@ -269,3 +269,12 @@ interface MasternodeResult { [id: string]: T } ``` + +## clearMempool +Clears the memory pool and returns a list of the removed transaction ids. + +```ts title="client.masternode.clearMempool" +interface masternode { + clearMempool (): Promise +} +``` diff --git a/packages/jellyfish-api-core/__tests__/category/masternode/clearMempool.test.ts b/packages/jellyfish-api-core/__tests__/category/masternode/clearMempool.test.ts new file mode 100644 index 0000000000..56de251a69 --- /dev/null +++ b/packages/jellyfish-api-core/__tests__/category/masternode/clearMempool.test.ts @@ -0,0 +1,30 @@ +import { MasterNodeRegTestContainer } from '@defichain/testcontainers' +import { Testing } from '@defichain/jellyfish-testing' + +describe('clear mempool', () => { + const container = new MasterNodeRegTestContainer() + const testing = Testing.create(container) + + beforeAll(async () => { + await testing.container.start() + await testing.container.waitForWalletCoinbaseMaturity() + }) + + afterAll(async () => { + await testing.container.stop() + }) + + it('should clear mempool and return the removed transaction ids', async () => { + const createdTxId = await testing.rpc.wallet.sendToAddress('mwsZw8nF7pKxWH8eoKL9tPxTpaFkz7QeLU', 0.003) + + const txIdsInMempoolBefore = await testing.rpc.blockchain.getRawMempool(false) + expect(txIdsInMempoolBefore.length).toStrictEqual(1) + + const removedTxIds = await testing.rpc.masternode.clearMempool() + + expect(removedTxIds).toContain(createdTxId) + + const txIdsInMempoolAfter = await testing.rpc.blockchain.getRawMempool(false) + expect(txIdsInMempoolAfter.length).toStrictEqual(0) + }) +}) diff --git a/packages/jellyfish-api-core/src/category/masternode.ts b/packages/jellyfish-api-core/src/category/masternode.ts index 449a650cf5..b9bdd9d615 100644 --- a/packages/jellyfish-api-core/src/category/masternode.ts +++ b/packages/jellyfish-api-core/src/category/masternode.ts @@ -240,6 +240,14 @@ export class Masternode { async listAnchors (): Promise> { return await this.client.call('listanchors', [], 'number') } + + /** + * Clears the memory pool and returns a list of the removed transaction ids. + * @return {Promise} Array of removed transaction ids + */ + async clearMempool (): Promise { + return await this.client.call('clearmempool', [], 'number') + } } export interface UTXO {