Skip to content

Commit

Permalink
@defichain/testing createToken to return id number (#234)
Browse files Browse the repository at this point in the history
* createToken to return id number

* Update token.test.ts
  • Loading branch information
fuxingloh authored May 17, 2021
1 parent dc80d46 commit 61f46e9
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
3 changes: 2 additions & 1 deletion packages/testing/__tests__/token.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ describe('utils', () => {
tokensLengthBefore = Object.keys(tokens).length
})

await createToken(container, 'DDD')
const tokenId = await createToken(container, 'DDD')
expect(tokenId).toBeGreaterThan(0)

await waitForExpect(async () => {
const tokens = await container.call('listtokens')
Expand Down
11 changes: 6 additions & 5 deletions packages/testing/src/token.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { getNewAddress } from './wallet'
import { utxosToAccount } from './account'

/**
* Create a new token
* Create a new token and return id of token
*
* @param {MasterNodeRegTestContainer} container
* @param {string} symbol
Expand All @@ -13,13 +13,13 @@ import { utxosToAccount } from './account'
* @param {boolean} [options.mintable=true]
* @param {boolean} [options.tradeable=true]
* @param {string} [options.collateralAddress]
* @return {Promise<string>}
* @return {Promise<number>} id of the created token
*/
export async function createToken (
container: MasterNodeRegTestContainer,
symbol: string,
options?: CreateTokenOptions
): Promise<string> {
): Promise<number> {
const metadata = {
symbol,
name: options?.name ?? symbol,
Expand All @@ -30,10 +30,11 @@ export async function createToken (
}

await container.waitForWalletBalanceGTE(101) // token creation fee
const hashed = await container.call('createtoken', [metadata])
await container.call('createtoken', [metadata])
await container.generate(1)

return hashed
const result = await container.call('gettoken', [symbol])
return Number.parseInt(Object.keys(result)[0])
}

/**
Expand Down

0 comments on commit 61f46e9

Please sign in to comment.