Skip to content

Commit

Permalink
Some minor fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
jingyi2811 committed Apr 27, 2021
1 parent b063fff commit 003e4aa
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 33 deletions.
46 changes: 16 additions & 30 deletions packages/jellyfish-api-core/__tests__/category/blockchain.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,18 @@ describe('masternode', () => {
await container.stop()
})

/**
* Wait for block hash to reach a certain height
*/
async function waitForBlockHash (height: number): Promise<string> {
await waitForExpect(async () => {
const info = await client.blockchain.getBlockchainInfo()
expect(info.blocks).toBeGreaterThan(height)
})

return await client.blockchain.getBlockHash(height)
}

describe('getBlockchainInfo', () => {
it('should getBlockchainInfo', async () => {
await waitForExpect(async () => {
Expand All @@ -83,23 +95,10 @@ describe('masternode', () => {
})

describe('getBlock', () => {
/**
* Wait for block hash to reach a certain height
*/
async function waitForBlockHash (height: number): Promise<string> {
await waitForExpect(async () => {
const info = await client.blockchain.getBlockchainInfo()
expect(info.blocks).toBeGreaterThan(height)
})

return await client.blockchain.getBlockHash(height)
}

it('should getBlock with verbosity 0 and return just a string that is serialized, hex-encoded data for block', async () => {
const blockHash = await waitForBlockHash(1)
const hash: string = await client.blockchain.getBlock(blockHash, 0)

expect(hash).not.toBeNull()
expect(typeof hash).toBe('string')
})

it('should getBlock with verbosity 1 and return block with tx as hex', async () => {
Expand Down Expand Up @@ -158,19 +157,6 @@ describe('masternode', () => {
})

describe('getBlockHeader', () => {
/**
* Wait for block hash to reach a certain height
*/

async function waitForBlockHash (height: number): Promise<string> {
await waitForExpect(async () => {
const info = await client.blockchain.getBlockchainInfo()
expect(info.blocks).toBeGreaterThan(height)
})

return await client.blockchain.getBlockHash(height)
}

it('should getBlockHeader with verbosity true and return block with tx as hex', async () => {
const blockHash = await waitForBlockHash(1)
const blockHeader: BlockHeader = await client.blockchain.getBlockHeader(blockHash, true)
Expand All @@ -196,10 +182,10 @@ describe('masternode', () => {
expect(blockHeader.nextblockhash.length).toBe(64)
})

it('should getBlockHeader with verbosity false and return just a string that is serialized, hex-encoded data for block', async () => {
it('should getBlockHeader with verbosity false and return a string that is serialized, hex-encoded data for block header', async () => {
const blockHash = await waitForBlockHash(1)
const hash: string = await client.blockchain.getBlockHeader(blockHash, false)
expect(hash).not.toBeNull()
expect(typeof hash).toBe('string')
})
})

Expand All @@ -211,7 +197,7 @@ describe('masternode', () => {
})

const blockHash: string = await client.blockchain.getBlockHash(1)
expect(blockHash).not.toBeNull()
expect(typeof blockHash).toBe('string')
expect(blockHash.length).toBe(64)
})
})
Expand Down
4 changes: 2 additions & 2 deletions packages/jellyfish-api-core/src/category/blockchain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ export class Blockchain {

/**
* Get block header data with particular header hash.
* Returns an Object with information about block header.
* Returns an Object with information for block header.
*
* @param {string} hash of the block
* @param {boolean} verbosity true
Expand All @@ -85,7 +85,7 @@ export class Blockchain {

/**
* Get block header data with particular header hash.
* Returns an Object with information about block header.
* Returns a string that is serialized, hex-encoded data for block header.
*
* @param {string} hash of the block
* @param {boolean} verbosity false
Expand Down
1 change: 0 additions & 1 deletion website/docs/jellyfish/api/blockchain.md
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,6 @@ Get block header data with particular header hash.
interface blockchain {
getBlockHeader (hash: string, verbosity: true): Promise<BlockHeader>
getBlockHeader (hash: string, verbosity: false): Promise<string>

}

interface BlockHeader {
Expand Down

0 comments on commit 003e4aa

Please sign in to comment.