From d5b40d823e229dff1b4ae7fe51d2e536287dd135 Mon Sep 17 00:00:00 2001 From: Chanaka Sameera Date: Wed, 15 Jun 2022 23:33:50 +0530 Subject: [PATCH 1/7] Updated the listAccountHistory api with new pagination key amountFormat + test --- docs/node/CATEGORIES/08-account.md | 6 +++ .../account/listAccountHistory.test.ts | 46 ++++++++++++++++++- .../src/category/account.ts | 12 +++++ .../src/containers/DeFiDContainer.ts | 2 +- 4 files changed, 64 insertions(+), 2 deletions(-) diff --git a/docs/node/CATEGORIES/08-account.md b/docs/node/CATEGORIES/08-account.md index 8099dd7f85..95c0b60594 100644 --- a/docs/node/CATEGORIES/08-account.md +++ b/docs/node/CATEGORIES/08-account.md @@ -216,6 +216,11 @@ enum DfTxType { NONE = '0' } +export enum AmountFormat { + ID = 'id', + SYMBOL = 'symbol' +} + interface AccountHistory { owner: string blockHeight: number @@ -235,6 +240,7 @@ interface AccountHistoryOptions { txtype?: DfTxType limit?: number txn?: number + amountFormat?: AmountFormat } ``` diff --git a/packages/jellyfish-api-core/__tests__/category/account/listAccountHistory.test.ts b/packages/jellyfish-api-core/__tests__/category/account/listAccountHistory.test.ts index dc3c131781..85114991b1 100644 --- a/packages/jellyfish-api-core/__tests__/category/account/listAccountHistory.test.ts +++ b/packages/jellyfish-api-core/__tests__/category/account/listAccountHistory.test.ts @@ -1,7 +1,7 @@ import { MasterNodeRegTestContainer } from '@defichain/testcontainers' import { ContainerAdapterClient } from '../../container_adapter_client' import waitForExpect from 'wait-for-expect' -import { DfTxType, BalanceTransferPayload, AccountResult, AccountOwner } from '../../../src/category/account' +import { DfTxType, BalanceTransferPayload, AccountResult, AccountOwner, AmountFormat } from '../../../src/category/account' function createTokenForContainer (container: MasterNodeRegTestContainer) { return async (address: string, symbol: string, amount: number) => { @@ -303,6 +303,50 @@ describe('Account', () => { } }) }) + + it('should listAccountHistory with options amountFormat', async () => { + const options = { + token: 'DBTC' + } + await waitForExpect(async () => { + const accountHistories = await client.account.listAccountHistory('mine', options) + expect(accountHistories.length).toBeGreaterThan(0) + }) + + { // amountFormat should be id + const options = { + token: 'DBTC', + amountFormat: AmountFormat.ID + } + const accountHistories = await client.account.listAccountHistory('mine', options) + for (let i = 0; i < accountHistories.length; i += 1) { + const accountHistory = accountHistories[i] + expect(accountHistory.amounts.length).toBeGreaterThan(0) + for (let j = 0; j < accountHistory.amounts.length; j += 1) { + const amount = accountHistory.amounts[j] + const id = amount.split('@')[1] + expect(id).toStrictEqual('1') + } + } + } + + { // amountFormat should be symbol + const options = { + token: 'DBTC', + amountFormat: AmountFormat.SYMBOL + } + const accountHistories = await client.account.listAccountHistory('mine', options) + for (let i = 0; i < accountHistories.length; i += 1) { + const accountHistory = accountHistories[i] + expect(accountHistory.amounts.length).toBeGreaterThan(0) + for (let j = 0; j < accountHistory.amounts.length; j += 1) { + const amount = accountHistory.amounts[j] + const symbol = amount.split('@')[1] + expect(symbol).toStrictEqual('DBTC') + } + } + } + }) }) describe('listAccountHistory', () => { diff --git a/packages/jellyfish-api-core/src/category/account.ts b/packages/jellyfish-api-core/src/category/account.ts index 249aef54a1..b9f9fdb4ba 100644 --- a/packages/jellyfish-api-core/src/category/account.ts +++ b/packages/jellyfish-api-core/src/category/account.ts @@ -34,6 +34,16 @@ export enum DfTxType { FUTURE_SWAP_REFUND = 'w' } +/** + * Configure the format of amounts + * id - amount with the following 'id' -> @id + * symbol - amount with the following 'symbol' -> @symbol + */ +export enum AmountFormat { + ID = 'id', + SYMBOL = 'symbol' +} + export enum SelectionModeType { PIE = 'pie', CRUMBS = 'crumbs', @@ -292,6 +302,7 @@ export class Account { * @param {DfTxType} [options.txtype] Filter by transaction type. See DfTxType. * @param {number} [options.limit=100] Maximum number of records to return, 100 by default * @param {number} [options.txn] Order in block, unlimited by default + * @param {AmountFormat} [options.amountFormat] Set the return amount format, AmountFormat.SYMBOL by default * @return {Promise} */ async listAccountHistory ( @@ -511,6 +522,7 @@ export interface AccountHistoryOptions { txtype?: DfTxType limit?: number txn?: number + amountFormat?: AmountFormat } export interface AccountHistoryCountOptions { diff --git a/packages/testcontainers/src/containers/DeFiDContainer.ts b/packages/testcontainers/src/containers/DeFiDContainer.ts index f97310d11e..3b988b2dd0 100644 --- a/packages/testcontainers/src/containers/DeFiDContainer.ts +++ b/packages/testcontainers/src/containers/DeFiDContainer.ts @@ -35,7 +35,7 @@ export abstract class DeFiDContainer extends DockerContainer { if (process?.env?.DEFICHAIN_DOCKER_IMAGE !== undefined) { return process.env.DEFICHAIN_DOCKER_IMAGE } - return 'defi/defichain:master-27e9965ef' + return 'defi/defichain:HEAD-9d7117773' } public static readonly DefaultStartOptions = { From 9ec2df434b2c9c6a5b4db8d93ee2445418f32508 Mon Sep 17 00:00:00 2001 From: Chanaka Sameera Date: Thu, 16 Jun 2022 16:38:39 +0530 Subject: [PATCH 2/7] Added a test to check default symbol format --- .../account/listAccountHistory.test.ts | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/packages/jellyfish-api-core/__tests__/category/account/listAccountHistory.test.ts b/packages/jellyfish-api-core/__tests__/category/account/listAccountHistory.test.ts index 85114991b1..d923810032 100644 --- a/packages/jellyfish-api-core/__tests__/category/account/listAccountHistory.test.ts +++ b/packages/jellyfish-api-core/__tests__/category/account/listAccountHistory.test.ts @@ -346,6 +346,26 @@ describe('Account', () => { } } } + + { // amountFormat default should be symbol + const options = { + token: 'DFI' + } + await waitForExpect(async () => { + const accountHistories = await client.account.listAccountHistory('mine', options) + expect(accountHistories.length).toBeGreaterThan(0) + }) + const accountHistories = await client.account.listAccountHistory('mine', options) + for (let i = 0; i < accountHistories.length; i += 1) { + const accountHistory = accountHistories[i] + expect(accountHistory.amounts.length).toBeGreaterThan(0) + for (let j = 0; j < accountHistory.amounts.length; j += 1) { + const amount = accountHistory.amounts[j] + const symbol = amount.split('@')[1] + expect(symbol).toStrictEqual('DFI') + } + } + } }) }) From 4e5fe95027a7a955b9a26f44e371b6901dd7a921 Mon Sep 17 00:00:00 2001 From: Chanaka Sameera Date: Fri, 17 Jun 2022 00:10:49 +0530 Subject: [PATCH 3/7] Update docker images --- packages/testcontainers/src/containers/DeFiDContainer.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/testcontainers/src/containers/DeFiDContainer.ts b/packages/testcontainers/src/containers/DeFiDContainer.ts index 3b988b2dd0..c0bc40dd19 100644 --- a/packages/testcontainers/src/containers/DeFiDContainer.ts +++ b/packages/testcontainers/src/containers/DeFiDContainer.ts @@ -35,7 +35,7 @@ export abstract class DeFiDContainer extends DockerContainer { if (process?.env?.DEFICHAIN_DOCKER_IMAGE !== undefined) { return process.env.DEFICHAIN_DOCKER_IMAGE } - return 'defi/defichain:HEAD-9d7117773' + return 'defi/defichain:HEAD-d99220a3d' } public static readonly DefaultStartOptions = { From 2b1cb7da62d5191967dd84fbc831557168362398 Mon Sep 17 00:00:00 2001 From: Chanaka Sameera Date: Fri, 17 Jun 2022 12:48:55 +0530 Subject: [PATCH 4/7] Updated api and tests according to review --- docs/node/CATEGORIES/08-account.md | 2 +- .../category/account/listAccountHistory.test.ts | 15 +++------------ 2 files changed, 4 insertions(+), 13 deletions(-) diff --git a/docs/node/CATEGORIES/08-account.md b/docs/node/CATEGORIES/08-account.md index 95c0b60594..1ea81fd8e8 100644 --- a/docs/node/CATEGORIES/08-account.md +++ b/docs/node/CATEGORIES/08-account.md @@ -216,7 +216,7 @@ enum DfTxType { NONE = '0' } -export enum AmountFormat { +enum AmountFormat { ID = 'id', SYMBOL = 'symbol' } diff --git a/packages/jellyfish-api-core/__tests__/category/account/listAccountHistory.test.ts b/packages/jellyfish-api-core/__tests__/category/account/listAccountHistory.test.ts index d923810032..8fc84d1f73 100644 --- a/packages/jellyfish-api-core/__tests__/category/account/listAccountHistory.test.ts +++ b/packages/jellyfish-api-core/__tests__/category/account/listAccountHistory.test.ts @@ -305,20 +305,13 @@ describe('Account', () => { }) it('should listAccountHistory with options amountFormat', async () => { - const options = { - token: 'DBTC' - } - await waitForExpect(async () => { - const accountHistories = await client.account.listAccountHistory('mine', options) - expect(accountHistories.length).toBeGreaterThan(0) - }) - { // amountFormat should be id const options = { token: 'DBTC', amountFormat: AmountFormat.ID } const accountHistories = await client.account.listAccountHistory('mine', options) + expect(accountHistories.length).toBeGreaterThan(0) for (let i = 0; i < accountHistories.length; i += 1) { const accountHistory = accountHistories[i] expect(accountHistory.amounts.length).toBeGreaterThan(0) @@ -336,6 +329,7 @@ describe('Account', () => { amountFormat: AmountFormat.SYMBOL } const accountHistories = await client.account.listAccountHistory('mine', options) + expect(accountHistories.length).toBeGreaterThan(0) for (let i = 0; i < accountHistories.length; i += 1) { const accountHistory = accountHistories[i] expect(accountHistory.amounts.length).toBeGreaterThan(0) @@ -351,11 +345,8 @@ describe('Account', () => { const options = { token: 'DFI' } - await waitForExpect(async () => { - const accountHistories = await client.account.listAccountHistory('mine', options) - expect(accountHistories.length).toBeGreaterThan(0) - }) const accountHistories = await client.account.listAccountHistory('mine', options) + expect(accountHistories.length).toBeGreaterThan(0) for (let i = 0; i < accountHistories.length; i += 1) { const accountHistory = accountHistories[i] expect(accountHistory.amounts.length).toBeGreaterThan(0) From e227f8df3da1e5f4c9c88699a315f0a812bc041a Mon Sep 17 00:00:00 2001 From: Chanaka Sameera Date: Mon, 27 Jun 2022 09:38:22 +0200 Subject: [PATCH 5/7] Added latest master ain image --- packages/testcontainers/src/containers/DeFiDContainer.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/testcontainers/src/containers/DeFiDContainer.ts b/packages/testcontainers/src/containers/DeFiDContainer.ts index c0bc40dd19..020e6ef470 100644 --- a/packages/testcontainers/src/containers/DeFiDContainer.ts +++ b/packages/testcontainers/src/containers/DeFiDContainer.ts @@ -35,7 +35,7 @@ export abstract class DeFiDContainer extends DockerContainer { if (process?.env?.DEFICHAIN_DOCKER_IMAGE !== undefined) { return process.env.DEFICHAIN_DOCKER_IMAGE } - return 'defi/defichain:HEAD-d99220a3d' + return 'defi/defichain:master-735849f55' } public static readonly DefaultStartOptions = { From b65291c8b7fc13d6969f1c665b8504b0bacea254 Mon Sep 17 00:00:00 2001 From: Chanaka Sameera Date: Mon, 27 Jun 2022 12:37:11 +0200 Subject: [PATCH 6/7] Refactor amountFormat to format --- docs/node/CATEGORIES/08-account.md | 4 ++-- .../category/account/listAccountHistory.test.ts | 14 +++++++------- .../jellyfish-api-core/src/category/account.ts | 6 +++--- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/docs/node/CATEGORIES/08-account.md b/docs/node/CATEGORIES/08-account.md index 1ea81fd8e8..4d54539701 100644 --- a/docs/node/CATEGORIES/08-account.md +++ b/docs/node/CATEGORIES/08-account.md @@ -216,7 +216,7 @@ enum DfTxType { NONE = '0' } -enum AmountFormat { +enum Format { ID = 'id', SYMBOL = 'symbol' } @@ -240,7 +240,7 @@ interface AccountHistoryOptions { txtype?: DfTxType limit?: number txn?: number - amountFormat?: AmountFormat + format?: Format } ``` diff --git a/packages/jellyfish-api-core/__tests__/category/account/listAccountHistory.test.ts b/packages/jellyfish-api-core/__tests__/category/account/listAccountHistory.test.ts index 8fc84d1f73..faf9537bca 100644 --- a/packages/jellyfish-api-core/__tests__/category/account/listAccountHistory.test.ts +++ b/packages/jellyfish-api-core/__tests__/category/account/listAccountHistory.test.ts @@ -1,7 +1,7 @@ import { MasterNodeRegTestContainer } from '@defichain/testcontainers' import { ContainerAdapterClient } from '../../container_adapter_client' import waitForExpect from 'wait-for-expect' -import { DfTxType, BalanceTransferPayload, AccountResult, AccountOwner, AmountFormat } from '../../../src/category/account' +import { DfTxType, BalanceTransferPayload, AccountResult, AccountOwner, Format } from '../../../src/category/account' function createTokenForContainer (container: MasterNodeRegTestContainer) { return async (address: string, symbol: string, amount: number) => { @@ -304,11 +304,11 @@ describe('Account', () => { }) }) - it('should listAccountHistory with options amountFormat', async () => { - { // amountFormat should be id + it('should listAccountHistory with options format', async () => { + { // amount format should be id const options = { token: 'DBTC', - amountFormat: AmountFormat.ID + format: Format.ID } const accountHistories = await client.account.listAccountHistory('mine', options) expect(accountHistories.length).toBeGreaterThan(0) @@ -323,10 +323,10 @@ describe('Account', () => { } } - { // amountFormat should be symbol + { // amount format should be symbol const options = { token: 'DBTC', - amountFormat: AmountFormat.SYMBOL + format: Format.SYMBOL } const accountHistories = await client.account.listAccountHistory('mine', options) expect(accountHistories.length).toBeGreaterThan(0) @@ -341,7 +341,7 @@ describe('Account', () => { } } - { // amountFormat default should be symbol + { // amount format default should be symbol const options = { token: 'DFI' } diff --git a/packages/jellyfish-api-core/src/category/account.ts b/packages/jellyfish-api-core/src/category/account.ts index b9f9fdb4ba..7d61182ae0 100644 --- a/packages/jellyfish-api-core/src/category/account.ts +++ b/packages/jellyfish-api-core/src/category/account.ts @@ -39,7 +39,7 @@ export enum DfTxType { * id - amount with the following 'id' -> @id * symbol - amount with the following 'symbol' -> @symbol */ -export enum AmountFormat { +export enum Format { ID = 'id', SYMBOL = 'symbol' } @@ -302,7 +302,7 @@ export class Account { * @param {DfTxType} [options.txtype] Filter by transaction type. See DfTxType. * @param {number} [options.limit=100] Maximum number of records to return, 100 by default * @param {number} [options.txn] Order in block, unlimited by default - * @param {AmountFormat} [options.amountFormat] Set the return amount format, AmountFormat.SYMBOL by default + * @param {Format} [options.format] Set the return amount format, Format.SYMBOL by default * @return {Promise} */ async listAccountHistory ( @@ -522,7 +522,7 @@ export interface AccountHistoryOptions { txtype?: DfTxType limit?: number txn?: number - amountFormat?: AmountFormat + format?: Format } export interface AccountHistoryCountOptions { From 4a0eb5d40db83b2fae6a18d6d30046a0fbe1e24d Mon Sep 17 00:00:00 2001 From: Chanaka Sameera Date: Mon, 27 Jun 2022 15:47:38 +0200 Subject: [PATCH 7/7] Update with latest ain image --- packages/testcontainers/src/containers/DeFiDContainer.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/testcontainers/src/containers/DeFiDContainer.ts b/packages/testcontainers/src/containers/DeFiDContainer.ts index 020e6ef470..d2abdf93aa 100644 --- a/packages/testcontainers/src/containers/DeFiDContainer.ts +++ b/packages/testcontainers/src/containers/DeFiDContainer.ts @@ -35,7 +35,7 @@ export abstract class DeFiDContainer extends DockerContainer { if (process?.env?.DEFICHAIN_DOCKER_IMAGE !== undefined) { return process.env.DEFICHAIN_DOCKER_IMAGE } - return 'defi/defichain:master-735849f55' + return 'defi/defichain:HEAD-a8a2eafb5' } public static readonly DefaultStartOptions = {