From 20d69dad56bffdfa83d282491818f9baa8e21da8 Mon Sep 17 00:00:00 2001 From: Fuxing Loh <4266087+fuxingloh@users.noreply.github.com> Date: Fri, 2 Dec 2022 09:29:36 +0800 Subject: [PATCH] chore(apps/whale-api): add create update resign masternode indexer scenario (#1895) #### What this PR does / why we need it: As per the title, adds a new create, update and finally resign masternode indexing scenario. --- .../model/dftx/resign.masternode.spec.ts | 81 ++++++++++++++++++- package-lock.json | 6 ++ 2 files changed, 86 insertions(+), 1 deletion(-) diff --git a/apps/whale-api/src/module.indexer/model/dftx/resign.masternode.spec.ts b/apps/whale-api/src/module.indexer/model/dftx/resign.masternode.spec.ts index 1aef1cc5a5..b10537fda1 100644 --- a/apps/whale-api/src/module.indexer/model/dftx/resign.masternode.spec.ts +++ b/apps/whale-api/src/module.indexer/model/dftx/resign.masternode.spec.ts @@ -1,4 +1,10 @@ -import { createTestingApp, DelayedEunosPayaTestContainer, invalidateFromHeight, stopTestingApp, waitForIndexedHeight } from '../../../e2e.module' +import { + createTestingApp, + DelayedEunosPayaTestContainer, + invalidateFromHeight, + stopTestingApp, + waitForIndexedHeight +} from '../../../e2e.module' import { NestFastifyApplication } from '@nestjs/platform-fastify' import { JsonRpcClient } from '@defichain/jellyfish-api-jsonrpc' import { MasternodeMapper } from '../../../module.model/masternode' @@ -123,3 +129,76 @@ describe('invalidate', () => { } }) }) + +describe('updated masternode', () => { + const container = new DelayedEunosPayaTestContainer() + let app: NestFastifyApplication + let client: JsonRpcClient + let mapper: MasternodeMapper + + beforeAll(async () => { + await container.start() + await container.waitForWalletCoinbaseMaturity() + + app = await createTestingApp(container) + mapper = app.get(MasternodeMapper) + client = new JsonRpcClient(await container.getCachedRpcUrl()) + + await client.masternode.setGov({ + ATTRIBUTES: { + 'v0/params/feature/mn-setowneraddress': 'true' + } + }) + await container.generate(1) + }) + + afterAll(async () => { + await stopTestingApp(container, app) + }) + + it('should resign masternode and invalidate', async () => { + await container.generate(1) + + const ownerAddress = await client.wallet.getNewAddress() + const masternodeId = await client.masternode.createMasternode(ownerAddress) + + await container.generate(1) + const height = await client.blockchain.getBlockCount() + await container.generate(20) + await waitForIndexedHeight(app, height) + + const masternode = await mapper.get(masternodeId) + expect(masternode).not.toBeUndefined() + + await client.masternode.updateMasternode(masternodeId, { + ownerAddress: await client.wallet.getNewAddress() + }) + await container.generate(50) + + const resignTx = await client.masternode.resignMasternode(masternodeId) + await container.generate(1) + const resignHeight = await client.blockchain.getBlockCount() + + { + await container.generate(1) + await waitForIndexedHeight(app, resignHeight) + + const resignedMasternode = await mapper.get(masternodeId) + expect(resignedMasternode).toStrictEqual(expect.objectContaining({ + resignHeight: resignHeight, + resignTx: resignTx + })) + } + + { + await invalidateFromHeight(app, container, resignHeight) + await container.generate(2) + await waitForIndexedHeight(app, resignHeight) + + const invalidatedMasternode = await mapper.get(masternodeId) + expect(invalidatedMasternode).toStrictEqual(expect.objectContaining({ + resignHeight: -1 + })) + } + }) +}) diff --git a/package-lock.json b/package-lock.json index d3b5af83b3..c15bb2fae5 100644 --- a/package-lock.json +++ b/package-lock.json @@ -25943,6 +25943,8 @@ "version": "0.0.0", "license": "MIT", "dependencies": { + "@defichain/jellyfish-transaction": "^0.0.0", + "@defichain/jellyfish-wallet": "^0.0.0", "bip32": "^2.0.6", "bip39": "^3.0.4", "create-hmac": "^1.1.7" @@ -27905,6 +27907,8 @@ "@defichain/jellyfish-wallet-mnemonic": { "version": "file:packages/jellyfish-wallet-mnemonic", "requires": { + "@defichain/jellyfish-transaction": "^0.0.0", + "@defichain/jellyfish-wallet": "^0.0.0", "@types/create-hmac": "1.1.0", "bip32": "^2.0.6", "bip39": "^3.0.4", @@ -36059,6 +36063,8 @@ "@defichain/jellyfish-wallet-mnemonic": { "version": "file:packages/jellyfish-wallet-mnemonic", "requires": { + "@defichain/jellyfish-transaction": "^0.0.0", + "@defichain/jellyfish-wallet": "^0.0.0", "@types/create-hmac": "1.1.0", "bip32": "^2.0.6", "bip39": "^3.0.4",