From 61f46e99de357199824c6bb1d32b034ccba4f09c Mon Sep 17 00:00:00 2001 From: Fuxing Loh <4266087+fuxingloh@users.noreply.github.com> Date: Mon, 17 May 2021 13:23:56 +0800 Subject: [PATCH] `@defichain/testing` createToken to return id number (#234) * createToken to return id number * Update token.test.ts --- packages/testing/__tests__/token.test.ts | 3 ++- packages/testing/src/token.ts | 11 ++++++----- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/packages/testing/__tests__/token.test.ts b/packages/testing/__tests__/token.test.ts index 925d52f764..19aa655d3c 100644 --- a/packages/testing/__tests__/token.test.ts +++ b/packages/testing/__tests__/token.test.ts @@ -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') diff --git a/packages/testing/src/token.ts b/packages/testing/src/token.ts index 1ce80a166d..42eafad1a6 100644 --- a/packages/testing/src/token.ts +++ b/packages/testing/src/token.ts @@ -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 @@ -13,13 +13,13 @@ import { utxosToAccount } from './account' * @param {boolean} [options.mintable=true] * @param {boolean} [options.tradeable=true] * @param {string} [options.collateralAddress] - * @return {Promise} + * @return {Promise} id of the created token */ export async function createToken ( container: MasterNodeRegTestContainer, symbol: string, options?: CreateTokenOptions -): Promise { +): Promise { const metadata = { symbol, name: options?.name ?? symbol, @@ -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]) } /**