From ab7fd18793841d0593677e94ca7c86aa17ec8cfc Mon Sep 17 00:00:00 2001 From: Chanaka Sameera Date: Mon, 10 Jan 2022 06:40:57 +0530 Subject: [PATCH 1/5] Added isAppliedCustomTransaction RPC and Test --- docs/node/CATEGORIES/11-masternode.md | 10 ++ .../isAppliedCustomTransaction.test.ts | 93 +++++++++++++++++++ .../src/category/masternode.ts | 11 +++ 3 files changed, 114 insertions(+) create mode 100644 packages/jellyfish-api-core/__tests__/category/masternode/isAppliedCustomTransaction.test.ts diff --git a/docs/node/CATEGORIES/11-masternode.md b/docs/node/CATEGORIES/11-masternode.md index 340f62e365..4bc8e53582 100644 --- a/docs/node/CATEGORIES/11-masternode.md +++ b/docs/node/CATEGORIES/11-masternode.md @@ -206,6 +206,16 @@ interface masternode { } ``` +## isAppliedCustomTransaction + +Checks that custom transaction was affected on chain + +```ts title="client.masternode.isAppliedCustomTransaction()" +interface masternode { + isAppliedCustomTransaction (transactionId: string, blockHeight: number): Promise +} +``` + ## getAnchorTeams Returns the auth and confirm anchor masternode teams at current or specified height diff --git a/packages/jellyfish-api-core/__tests__/category/masternode/isAppliedCustomTransaction.test.ts b/packages/jellyfish-api-core/__tests__/category/masternode/isAppliedCustomTransaction.test.ts new file mode 100644 index 0000000000..85d15bd8af --- /dev/null +++ b/packages/jellyfish-api-core/__tests__/category/masternode/isAppliedCustomTransaction.test.ts @@ -0,0 +1,93 @@ +import { MasterNodeRegTestContainer } from '@defichain/testcontainers' +import { ContainerAdapterClient } from '../../container_adapter_client' + +describe('Masternode', () => { + const container = new MasterNodeRegTestContainer() + const client = new ContainerAdapterClient(container) + + beforeAll(async () => { + await container.start() + await container.waitForWalletCoinbaseMaturity() + }) + + afterAll(async () => { + await container.stop() + }) + + it('should be passed while using valid id and height', async () => { + const goldAddress = await container.getNewAddress('', 'legacy') + const goldMetadata = { + symbol: 'GOLD', + name: 'shiny gold', + isDAT: false, + mintable: true, + tradeable: true, + collateralAddress: goldAddress + } + const goldTokenId = await client.token.createToken(goldMetadata) + await container.generate(1) + const goldHeight = await client.blockchain.getBlockCount() + + const silverAddress = await container.getNewAddress('', 'legacy') + const silverMetadata = { + symbol: 'SILVER', + name: 'just silver', + isDAT: false, + mintable: true, + tradeable: true, + collateralAddress: silverAddress + } + const silverTokenId = await client.token.createToken(silverMetadata) + await container.generate(1) + const silverHeight = await client.blockchain.getBlockCount() + + const cupperAddress = await container.getNewAddress('', 'legacy') + const cupperMetadata = { + symbol: 'CUPPER', + name: 'just cupper', + isDAT: false, + mintable: true, + tradeable: true, + collateralAddress: cupperAddress + } + const cupperTokenId = await client.token.createToken(cupperMetadata) + await container.generate(1) + const cupperHeight = await client.blockchain.getBlockCount() + + const goldResult = await client.masternode.isAppliedCustomTransaction(goldTokenId, goldHeight) + expect(goldResult).toStrictEqual(true) + + const silverResult = await client.masternode.isAppliedCustomTransaction(silverTokenId, silverHeight) + expect(silverResult).toStrictEqual(true) + + const cupperResult = await client.masternode.isAppliedCustomTransaction(cupperTokenId, cupperHeight) + expect(cupperResult).toStrictEqual(true) + }) + + it('should be failed while using invalid height', async () => { + const brassAddress = await container.getNewAddress('', 'legacy') + const brassMetadata = { + symbol: 'BRASS', + name: 'shiny brass', + isDAT: false, + mintable: true, + tradeable: true, + collateralAddress: brassAddress + } + const brassTokenId = await client.token.createToken(brassMetadata) + await container.generate(1) + const brassHeight = await client.blockchain.getBlockCount() + + const brassResult = await client.masternode.isAppliedCustomTransaction(brassTokenId, brassHeight + 1) + expect(brassResult).toStrictEqual(false) + }) + + it('should be failed while using invalid id', async () => { + const blockHeight = await client.blockchain.getBlockCount() + + const result = await client.masternode.isAppliedCustomTransaction('b2bb09ffe9f9b292f13d23bafa1225ef26d0b9906da7af194c5738b63839b235', blockHeight) + expect(result).toStrictEqual(false) + + await expect(client.masternode.isAppliedCustomTransaction('z2bb09ffe9f9b292f13d23bafa1225ef26d0b9906da7af194c5738b63839b235', blockHeight)).rejects.toThrow() + }) +}) diff --git a/packages/jellyfish-api-core/src/category/masternode.ts b/packages/jellyfish-api-core/src/category/masternode.ts index c197471f3c..ec33198297 100644 --- a/packages/jellyfish-api-core/src/category/masternode.ts +++ b/packages/jellyfish-api-core/src/category/masternode.ts @@ -198,6 +198,17 @@ export class Masternode { return await this.client.call('listgovs', [], 'bignumber') } + /** + * Checks that custom transaction was affected on chain + * + * @param {string} transactionId transaction hash + * @param {number} blockHeight height of block which contain transaction + * @return {Promise} indicate that custom transaction was affected on chain + */ + async isAppliedCustomTransaction (transactionId: string, blockHeight: number): Promise { + return await this.client.call('isappliedcustomtx', [transactionId, blockHeight], 'bignumber') + } + /** * Returns the auth and confirm anchor masternode teams at current or specified height * From 7272db3226945594b2f347198df1a244ce06065c Mon Sep 17 00:00:00 2001 From: Chanaka Sameera Date: Mon, 10 Jan 2022 16:16:21 +0530 Subject: [PATCH 2/5] Fixes for the review comments --- .../isAppliedCustomTransaction.test.ts | 56 ++++++++++++------- .../src/category/masternode.ts | 2 +- 2 files changed, 37 insertions(+), 21 deletions(-) diff --git a/packages/jellyfish-api-core/__tests__/category/masternode/isAppliedCustomTransaction.test.ts b/packages/jellyfish-api-core/__tests__/category/masternode/isAppliedCustomTransaction.test.ts index 85d15bd8af..f4bb9f3ef7 100644 --- a/packages/jellyfish-api-core/__tests__/category/masternode/isAppliedCustomTransaction.test.ts +++ b/packages/jellyfish-api-core/__tests__/category/masternode/isAppliedCustomTransaction.test.ts @@ -1,21 +1,23 @@ +import { Testing } from '@defichain/jellyfish-testing' import { MasterNodeRegTestContainer } from '@defichain/testcontainers' import { ContainerAdapterClient } from '../../container_adapter_client' describe('Masternode', () => { const container = new MasterNodeRegTestContainer() + const testing = Testing.create(container) const client = new ContainerAdapterClient(container) beforeAll(async () => { - await container.start() - await container.waitForWalletCoinbaseMaturity() + await testing.container.start() + await testing.container.waitForWalletCoinbaseMaturity() }) afterAll(async () => { - await container.stop() + await testing.container.stop() }) it('should be passed while using valid id and height', async () => { - const goldAddress = await container.getNewAddress('', 'legacy') + const goldAddress = await testing.container.getNewAddress('', 'legacy') const goldMetadata = { symbol: 'GOLD', name: 'shiny gold', @@ -25,10 +27,10 @@ describe('Masternode', () => { collateralAddress: goldAddress } const goldTokenId = await client.token.createToken(goldMetadata) - await container.generate(1) + await testing.container.generate(1) const goldHeight = await client.blockchain.getBlockCount() - const silverAddress = await container.getNewAddress('', 'legacy') + const silverAddress = await testing.container.getNewAddress('', 'legacy') const silverMetadata = { symbol: 'SILVER', name: 'just silver', @@ -38,21 +40,21 @@ describe('Masternode', () => { collateralAddress: silverAddress } const silverTokenId = await client.token.createToken(silverMetadata) - await container.generate(1) + await testing.container.generate(1) const silverHeight = await client.blockchain.getBlockCount() - const cupperAddress = await container.getNewAddress('', 'legacy') - const cupperMetadata = { - symbol: 'CUPPER', - name: 'just cupper', + const copperAddress = await testing.container.getNewAddress('', 'legacy') + const copperMetadata = { + symbol: 'COPPER', + name: 'just copper', isDAT: false, mintable: true, tradeable: true, - collateralAddress: cupperAddress + collateralAddress: copperAddress } - const cupperTokenId = await client.token.createToken(cupperMetadata) - await container.generate(1) - const cupperHeight = await client.blockchain.getBlockCount() + const copperTokenId = await client.token.createToken(copperMetadata) + await testing.container.generate(1) + const copperHeight = await client.blockchain.getBlockCount() const goldResult = await client.masternode.isAppliedCustomTransaction(goldTokenId, goldHeight) expect(goldResult).toStrictEqual(true) @@ -60,12 +62,12 @@ describe('Masternode', () => { const silverResult = await client.masternode.isAppliedCustomTransaction(silverTokenId, silverHeight) expect(silverResult).toStrictEqual(true) - const cupperResult = await client.masternode.isAppliedCustomTransaction(cupperTokenId, cupperHeight) - expect(cupperResult).toStrictEqual(true) + const copperResult = await client.masternode.isAppliedCustomTransaction(copperTokenId, copperHeight) + expect(copperResult).toStrictEqual(true) }) it('should be failed while using invalid height', async () => { - const brassAddress = await container.getNewAddress('', 'legacy') + const brassAddress = await testing.container.getNewAddress('', 'legacy') const brassMetadata = { symbol: 'BRASS', name: 'shiny brass', @@ -75,7 +77,7 @@ describe('Masternode', () => { collateralAddress: brassAddress } const brassTokenId = await client.token.createToken(brassMetadata) - await container.generate(1) + await testing.container.generate(1) const brassHeight = await client.blockchain.getBlockCount() const brassResult = await client.masternode.isAppliedCustomTransaction(brassTokenId, brassHeight + 1) @@ -88,6 +90,20 @@ describe('Masternode', () => { const result = await client.masternode.isAppliedCustomTransaction('b2bb09ffe9f9b292f13d23bafa1225ef26d0b9906da7af194c5738b63839b235', blockHeight) expect(result).toStrictEqual(false) - await expect(client.masternode.isAppliedCustomTransaction('z2bb09ffe9f9b292f13d23bafa1225ef26d0b9906da7af194c5738b63839b235', blockHeight)).rejects.toThrow() + // Hex hash id with 63 chars + try { + await client.masternode.isAppliedCustomTransaction('2bb09ffe9f9b292f13d23bafa1225ef26d0b9906da7af194c5738b63839b235', blockHeight) + throw new Error('It should not reach here') + } catch (error: any) { + expect(error.message).toContain('must be of length 64') + } + + // Invalid hash id with a non hex char + try { + await client.masternode.isAppliedCustomTransaction('b2bb09ffe9f9b292f13d23bafa1225ef26d0b9906da7af194c5738b63839b23z', blockHeight) + throw new Error('It should not reach here') + } catch (error: any) { + expect(error.message).toContain('must be hexadecimal string') + } }) }) diff --git a/packages/jellyfish-api-core/src/category/masternode.ts b/packages/jellyfish-api-core/src/category/masternode.ts index ec33198297..e685cc8c23 100644 --- a/packages/jellyfish-api-core/src/category/masternode.ts +++ b/packages/jellyfish-api-core/src/category/masternode.ts @@ -206,7 +206,7 @@ export class Masternode { * @return {Promise} indicate that custom transaction was affected on chain */ async isAppliedCustomTransaction (transactionId: string, blockHeight: number): Promise { - return await this.client.call('isappliedcustomtx', [transactionId, blockHeight], 'bignumber') + return await this.client.call('isappliedcustomtx', [transactionId, blockHeight], 'number') } /** From 3472e0fd2ccf077a16e122e6b246e35c32c97766 Mon Sep 17 00:00:00 2001 From: Chanaka Sameera Date: Tue, 11 Jan 2022 09:52:56 +0530 Subject: [PATCH 3/5] Fixes for the review comment - now testing.rpc client is used --- .../isAppliedCustomTransaction.test.ts | 29 +++++++++---------- 1 file changed, 14 insertions(+), 15 deletions(-) diff --git a/packages/jellyfish-api-core/__tests__/category/masternode/isAppliedCustomTransaction.test.ts b/packages/jellyfish-api-core/__tests__/category/masternode/isAppliedCustomTransaction.test.ts index f4bb9f3ef7..702a6f927b 100644 --- a/packages/jellyfish-api-core/__tests__/category/masternode/isAppliedCustomTransaction.test.ts +++ b/packages/jellyfish-api-core/__tests__/category/masternode/isAppliedCustomTransaction.test.ts @@ -1,23 +1,22 @@ import { Testing } from '@defichain/jellyfish-testing' import { MasterNodeRegTestContainer } from '@defichain/testcontainers' -import { ContainerAdapterClient } from '../../container_adapter_client' describe('Masternode', () => { - const container = new MasterNodeRegTestContainer() - const testing = Testing.create(container) - const client = new ContainerAdapterClient(container) + const testing = Testing.create(new MasterNodeRegTestContainer()) + const container = testing.container + const client = testing.rpc beforeAll(async () => { - await testing.container.start() - await testing.container.waitForWalletCoinbaseMaturity() + await container.start() + await container.waitForWalletCoinbaseMaturity() }) afterAll(async () => { - await testing.container.stop() + await container.stop() }) it('should be passed while using valid id and height', async () => { - const goldAddress = await testing.container.getNewAddress('', 'legacy') + const goldAddress = await container.getNewAddress('', 'legacy') const goldMetadata = { symbol: 'GOLD', name: 'shiny gold', @@ -27,10 +26,10 @@ describe('Masternode', () => { collateralAddress: goldAddress } const goldTokenId = await client.token.createToken(goldMetadata) - await testing.container.generate(1) + await container.generate(1) const goldHeight = await client.blockchain.getBlockCount() - const silverAddress = await testing.container.getNewAddress('', 'legacy') + const silverAddress = await container.getNewAddress('', 'legacy') const silverMetadata = { symbol: 'SILVER', name: 'just silver', @@ -40,10 +39,10 @@ describe('Masternode', () => { collateralAddress: silverAddress } const silverTokenId = await client.token.createToken(silverMetadata) - await testing.container.generate(1) + await container.generate(1) const silverHeight = await client.blockchain.getBlockCount() - const copperAddress = await testing.container.getNewAddress('', 'legacy') + const copperAddress = await container.getNewAddress('', 'legacy') const copperMetadata = { symbol: 'COPPER', name: 'just copper', @@ -53,7 +52,7 @@ describe('Masternode', () => { collateralAddress: copperAddress } const copperTokenId = await client.token.createToken(copperMetadata) - await testing.container.generate(1) + await container.generate(1) const copperHeight = await client.blockchain.getBlockCount() const goldResult = await client.masternode.isAppliedCustomTransaction(goldTokenId, goldHeight) @@ -67,7 +66,7 @@ describe('Masternode', () => { }) it('should be failed while using invalid height', async () => { - const brassAddress = await testing.container.getNewAddress('', 'legacy') + const brassAddress = await container.getNewAddress('', 'legacy') const brassMetadata = { symbol: 'BRASS', name: 'shiny brass', @@ -77,7 +76,7 @@ describe('Masternode', () => { collateralAddress: brassAddress } const brassTokenId = await client.token.createToken(brassMetadata) - await testing.container.generate(1) + await container.generate(1) const brassHeight = await client.blockchain.getBlockCount() const brassResult = await client.masternode.isAppliedCustomTransaction(brassTokenId, brassHeight + 1) From 0037db79a08f7e4a80660c62676ab011fd697716 Mon Sep 17 00:00:00 2001 From: Chanaka Sameera Date: Wed, 12 Jan 2022 12:33:46 +0530 Subject: [PATCH 4/5] Review update --- .../isAppliedCustomTransaction.test.ts | 56 +++++++++---------- 1 file changed, 27 insertions(+), 29 deletions(-) diff --git a/packages/jellyfish-api-core/__tests__/category/masternode/isAppliedCustomTransaction.test.ts b/packages/jellyfish-api-core/__tests__/category/masternode/isAppliedCustomTransaction.test.ts index 702a6f927b..2aafb4cff5 100644 --- a/packages/jellyfish-api-core/__tests__/category/masternode/isAppliedCustomTransaction.test.ts +++ b/packages/jellyfish-api-core/__tests__/category/masternode/isAppliedCustomTransaction.test.ts @@ -3,20 +3,18 @@ import { MasterNodeRegTestContainer } from '@defichain/testcontainers' describe('Masternode', () => { const testing = Testing.create(new MasterNodeRegTestContainer()) - const container = testing.container - const client = testing.rpc beforeAll(async () => { - await container.start() - await container.waitForWalletCoinbaseMaturity() + await testing.container.start() + await testing.container.waitForWalletCoinbaseMaturity() }) afterAll(async () => { - await container.stop() + await testing.container.stop() }) it('should be passed while using valid id and height', async () => { - const goldAddress = await container.getNewAddress('', 'legacy') + const goldAddress = await testing.container.getNewAddress('', 'legacy') const goldMetadata = { symbol: 'GOLD', name: 'shiny gold', @@ -25,11 +23,11 @@ describe('Masternode', () => { tradeable: true, collateralAddress: goldAddress } - const goldTokenId = await client.token.createToken(goldMetadata) - await container.generate(1) - const goldHeight = await client.blockchain.getBlockCount() + const goldTokenId = await testing.rpc.token.createToken(goldMetadata) + await testing.container.generate(1) + const goldHeight = await testing.rpc.blockchain.getBlockCount() - const silverAddress = await container.getNewAddress('', 'legacy') + const silverAddress = await testing.container.getNewAddress('', 'legacy') const silverMetadata = { symbol: 'SILVER', name: 'just silver', @@ -38,11 +36,11 @@ describe('Masternode', () => { tradeable: true, collateralAddress: silverAddress } - const silverTokenId = await client.token.createToken(silverMetadata) - await container.generate(1) - const silverHeight = await client.blockchain.getBlockCount() + const silverTokenId = await testing.rpc.token.createToken(silverMetadata) + await testing.container.generate(1) + const silverHeight = await testing.rpc.blockchain.getBlockCount() - const copperAddress = await container.getNewAddress('', 'legacy') + const copperAddress = await testing.container.getNewAddress('', 'legacy') const copperMetadata = { symbol: 'COPPER', name: 'just copper', @@ -51,22 +49,22 @@ describe('Masternode', () => { tradeable: true, collateralAddress: copperAddress } - const copperTokenId = await client.token.createToken(copperMetadata) - await container.generate(1) - const copperHeight = await client.blockchain.getBlockCount() + const copperTokenId = await testing.rpc.token.createToken(copperMetadata) + await testing.container.generate(1) + const copperHeight = await testing.rpc.blockchain.getBlockCount() - const goldResult = await client.masternode.isAppliedCustomTransaction(goldTokenId, goldHeight) + const goldResult = await testing.rpc.masternode.isAppliedCustomTransaction(goldTokenId, goldHeight) expect(goldResult).toStrictEqual(true) - const silverResult = await client.masternode.isAppliedCustomTransaction(silverTokenId, silverHeight) + const silverResult = await testing.rpc.masternode.isAppliedCustomTransaction(silverTokenId, silverHeight) expect(silverResult).toStrictEqual(true) - const copperResult = await client.masternode.isAppliedCustomTransaction(copperTokenId, copperHeight) + const copperResult = await testing.rpc.masternode.isAppliedCustomTransaction(copperTokenId, copperHeight) expect(copperResult).toStrictEqual(true) }) it('should be failed while using invalid height', async () => { - const brassAddress = await container.getNewAddress('', 'legacy') + const brassAddress = await testing.container.getNewAddress('', 'legacy') const brassMetadata = { symbol: 'BRASS', name: 'shiny brass', @@ -75,23 +73,23 @@ describe('Masternode', () => { tradeable: true, collateralAddress: brassAddress } - const brassTokenId = await client.token.createToken(brassMetadata) - await container.generate(1) - const brassHeight = await client.blockchain.getBlockCount() + const brassTokenId = await testing.rpc.token.createToken(brassMetadata) + await testing.container.generate(1) + const brassHeight = await testing.rpc.blockchain.getBlockCount() - const brassResult = await client.masternode.isAppliedCustomTransaction(brassTokenId, brassHeight + 1) + const brassResult = await testing.rpc.masternode.isAppliedCustomTransaction(brassTokenId, brassHeight + 1) expect(brassResult).toStrictEqual(false) }) it('should be failed while using invalid id', async () => { - const blockHeight = await client.blockchain.getBlockCount() + const blockHeight = await testing.rpc.blockchain.getBlockCount() - const result = await client.masternode.isAppliedCustomTransaction('b2bb09ffe9f9b292f13d23bafa1225ef26d0b9906da7af194c5738b63839b235', blockHeight) + const result = await testing.rpc.masternode.isAppliedCustomTransaction('b2bb09ffe9f9b292f13d23bafa1225ef26d0b9906da7af194c5738b63839b235', blockHeight) expect(result).toStrictEqual(false) // Hex hash id with 63 chars try { - await client.masternode.isAppliedCustomTransaction('2bb09ffe9f9b292f13d23bafa1225ef26d0b9906da7af194c5738b63839b235', blockHeight) + await testing.rpc.masternode.isAppliedCustomTransaction('2bb09ffe9f9b292f13d23bafa1225ef26d0b9906da7af194c5738b63839b235', blockHeight) throw new Error('It should not reach here') } catch (error: any) { expect(error.message).toContain('must be of length 64') @@ -99,7 +97,7 @@ describe('Masternode', () => { // Invalid hash id with a non hex char try { - await client.masternode.isAppliedCustomTransaction('b2bb09ffe9f9b292f13d23bafa1225ef26d0b9906da7af194c5738b63839b23z', blockHeight) + await testing.rpc.masternode.isAppliedCustomTransaction('b2bb09ffe9f9b292f13d23bafa1225ef26d0b9906da7af194c5738b63839b23z', blockHeight) throw new Error('It should not reach here') } catch (error: any) { expect(error.message).toContain('must be hexadecimal string') From bf27cd83e32e0494e57b4e9ca3d47e60faee1772 Mon Sep 17 00:00:00 2001 From: Chanaka Sameera Date: Thu, 13 Jan 2022 17:55:56 +0530 Subject: [PATCH 5/5] Just test case update for exception handling --- .../isAppliedCustomTransaction.test.ts | 27 ++++++++----------- 1 file changed, 11 insertions(+), 16 deletions(-) diff --git a/packages/jellyfish-api-core/__tests__/category/masternode/isAppliedCustomTransaction.test.ts b/packages/jellyfish-api-core/__tests__/category/masternode/isAppliedCustomTransaction.test.ts index 2aafb4cff5..f346954767 100644 --- a/packages/jellyfish-api-core/__tests__/category/masternode/isAppliedCustomTransaction.test.ts +++ b/packages/jellyfish-api-core/__tests__/category/masternode/isAppliedCustomTransaction.test.ts @@ -1,5 +1,6 @@ import { Testing } from '@defichain/jellyfish-testing' import { MasterNodeRegTestContainer } from '@defichain/testcontainers' +import { RpcApiError } from '@defichain/jellyfish-api-core' describe('Masternode', () => { const testing = Testing.create(new MasterNodeRegTestContainer()) @@ -24,7 +25,7 @@ describe('Masternode', () => { collateralAddress: goldAddress } const goldTokenId = await testing.rpc.token.createToken(goldMetadata) - await testing.container.generate(1) + await testing.generate(1) const goldHeight = await testing.rpc.blockchain.getBlockCount() const silverAddress = await testing.container.getNewAddress('', 'legacy') @@ -37,7 +38,7 @@ describe('Masternode', () => { collateralAddress: silverAddress } const silverTokenId = await testing.rpc.token.createToken(silverMetadata) - await testing.container.generate(1) + await testing.generate(1) const silverHeight = await testing.rpc.blockchain.getBlockCount() const copperAddress = await testing.container.getNewAddress('', 'legacy') @@ -50,7 +51,7 @@ describe('Masternode', () => { collateralAddress: copperAddress } const copperTokenId = await testing.rpc.token.createToken(copperMetadata) - await testing.container.generate(1) + await testing.generate(1) const copperHeight = await testing.rpc.blockchain.getBlockCount() const goldResult = await testing.rpc.masternode.isAppliedCustomTransaction(goldTokenId, goldHeight) @@ -74,7 +75,7 @@ describe('Masternode', () => { collateralAddress: brassAddress } const brassTokenId = await testing.rpc.token.createToken(brassMetadata) - await testing.container.generate(1) + await testing.generate(1) const brassHeight = await testing.rpc.blockchain.getBlockCount() const brassResult = await testing.rpc.masternode.isAppliedCustomTransaction(brassTokenId, brassHeight + 1) @@ -88,19 +89,13 @@ describe('Masternode', () => { expect(result).toStrictEqual(false) // Hex hash id with 63 chars - try { - await testing.rpc.masternode.isAppliedCustomTransaction('2bb09ffe9f9b292f13d23bafa1225ef26d0b9906da7af194c5738b63839b235', blockHeight) - throw new Error('It should not reach here') - } catch (error: any) { - expect(error.message).toContain('must be of length 64') - } + let promise = testing.rpc.masternode.isAppliedCustomTransaction('2bb09ffe9f9b292f13d23bafa1225ef26d0b9906da7af194c5738b63839b235', blockHeight) + await expect(promise).rejects.toThrow(RpcApiError) + await expect(promise).rejects.toThrow('txid must be of length 64') // Invalid hash id with a non hex char - try { - await testing.rpc.masternode.isAppliedCustomTransaction('b2bb09ffe9f9b292f13d23bafa1225ef26d0b9906da7af194c5738b63839b23z', blockHeight) - throw new Error('It should not reach here') - } catch (error: any) { - expect(error.message).toContain('must be hexadecimal string') - } + promise = testing.rpc.masternode.isAppliedCustomTransaction('b2bb09ffe9f9b292f13d23bafa1225ef26d0b9906da7af194c5738b63839b23z', blockHeight) + await expect(promise).rejects.toThrow(RpcApiError) + await expect(promise).rejects.toThrow('txid must be hexadecimal string') }) })