Skip to content

Commit

Permalink
Fixes for the review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
chanakasameera committed Jan 10, 2022
1 parent ab7fd18 commit 7272db3
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 21 deletions.
Original file line number Diff line number Diff line change
@@ -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',
Expand All @@ -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',
Expand All @@ -38,34 +40,34 @@ 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)

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',
Expand All @@ -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)
Expand All @@ -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')
}
})
})
2 changes: 1 addition & 1 deletion packages/jellyfish-api-core/src/category/masternode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ export class Masternode {
* @return {Promise<boolean>} indicate that custom transaction was affected on chain
*/
async isAppliedCustomTransaction (transactionId: string, blockHeight: number): Promise<boolean> {
return await this.client.call('isappliedcustomtx', [transactionId, blockHeight], 'bignumber')
return await this.client.call('isappliedcustomtx', [transactionId, blockHeight], 'number')
}

/**
Expand Down

0 comments on commit 7272db3

Please sign in to comment.