-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(jellyfish-api-core): add masternode isAppliedCustomTransaction R…
…PC (#957) * Added isAppliedCustomTransaction RPC and Test * Fixes for the review comments * Fixes for the review comment - now testing.rpc client is used * Review update * Just test case update for exception handling
- Loading branch information
1 parent
8928e40
commit ddc6b7f
Showing
3 changed files
with
122 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
101 changes: 101 additions & 0 deletions
101
packages/jellyfish-api-core/__tests__/category/masternode/isAppliedCustomTransaction.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
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()) | ||
|
||
beforeAll(async () => { | ||
await testing.container.start() | ||
await testing.container.waitForWalletCoinbaseMaturity() | ||
}) | ||
|
||
afterAll(async () => { | ||
await testing.container.stop() | ||
}) | ||
|
||
it('should be passed while using valid id and height', async () => { | ||
const goldAddress = await testing.container.getNewAddress('', 'legacy') | ||
const goldMetadata = { | ||
symbol: 'GOLD', | ||
name: 'shiny gold', | ||
isDAT: false, | ||
mintable: true, | ||
tradeable: true, | ||
collateralAddress: goldAddress | ||
} | ||
const goldTokenId = await testing.rpc.token.createToken(goldMetadata) | ||
await testing.generate(1) | ||
const goldHeight = await testing.rpc.blockchain.getBlockCount() | ||
|
||
const silverAddress = await testing.container.getNewAddress('', 'legacy') | ||
const silverMetadata = { | ||
symbol: 'SILVER', | ||
name: 'just silver', | ||
isDAT: false, | ||
mintable: true, | ||
tradeable: true, | ||
collateralAddress: silverAddress | ||
} | ||
const silverTokenId = await testing.rpc.token.createToken(silverMetadata) | ||
await testing.generate(1) | ||
const silverHeight = await testing.rpc.blockchain.getBlockCount() | ||
|
||
const copperAddress = await testing.container.getNewAddress('', 'legacy') | ||
const copperMetadata = { | ||
symbol: 'COPPER', | ||
name: 'just copper', | ||
isDAT: false, | ||
mintable: true, | ||
tradeable: true, | ||
collateralAddress: copperAddress | ||
} | ||
const copperTokenId = await testing.rpc.token.createToken(copperMetadata) | ||
await testing.generate(1) | ||
const copperHeight = await testing.rpc.blockchain.getBlockCount() | ||
|
||
const goldResult = await testing.rpc.masternode.isAppliedCustomTransaction(goldTokenId, goldHeight) | ||
expect(goldResult).toStrictEqual(true) | ||
|
||
const silverResult = await testing.rpc.masternode.isAppliedCustomTransaction(silverTokenId, silverHeight) | ||
expect(silverResult).toStrictEqual(true) | ||
|
||
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 testing.container.getNewAddress('', 'legacy') | ||
const brassMetadata = { | ||
symbol: 'BRASS', | ||
name: 'shiny brass', | ||
isDAT: false, | ||
mintable: true, | ||
tradeable: true, | ||
collateralAddress: brassAddress | ||
} | ||
const brassTokenId = await testing.rpc.token.createToken(brassMetadata) | ||
await testing.generate(1) | ||
const brassHeight = await testing.rpc.blockchain.getBlockCount() | ||
|
||
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 testing.rpc.blockchain.getBlockCount() | ||
|
||
const result = await testing.rpc.masternode.isAppliedCustomTransaction('b2bb09ffe9f9b292f13d23bafa1225ef26d0b9906da7af194c5738b63839b235', blockHeight) | ||
expect(result).toStrictEqual(false) | ||
|
||
// Hex hash id with 63 chars | ||
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 | ||
promise = testing.rpc.masternode.isAppliedCustomTransaction('b2bb09ffe9f9b292f13d23bafa1225ef26d0b9906da7af194c5738b63839b23z', blockHeight) | ||
await expect(promise).rejects.toThrow(RpcApiError) | ||
await expect(promise).rejects.toThrow('txid must be hexadecimal string') | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters