-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
754 additions
and
639 deletions.
There are no files selected for viewing
606 changes: 0 additions & 606 deletions
606
packages/jellyfish-api-core/__tests__/category/account.test.ts
This file was deleted.
Oops, something went wrong.
132 changes: 132 additions & 0 deletions
132
packages/jellyfish-api-core/__tests__/category/account/accountHistoryCount.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,132 @@ | ||
import { MasterNodeRegTestContainer } from '@defichain/testcontainers' | ||
import { ContainerAdapterClient } from '../../container_adapter_client' | ||
import waitForExpect from 'wait-for-expect' | ||
import { AccountHistoryCountOptions, TxType } from '../../../src/category/account' | ||
|
||
describe('Account', () => { | ||
const container = new MasterNodeRegTestContainer() | ||
const client = new ContainerAdapterClient(container) | ||
|
||
beforeAll(async () => { | ||
await container.start() | ||
await container.waitForReady() | ||
await container.waitForWalletCoinbaseMaturity() | ||
await setup() | ||
}) | ||
|
||
afterAll(async () => { | ||
await container.stop() | ||
}) | ||
|
||
async function setup (): Promise<void> { | ||
const from = await container.call('getnewaddress') | ||
await createToken(from, 'DBTC', 200) | ||
|
||
const to = await accountToAccount('DBTC', 5, from) | ||
await accountToAccount('DBTC', 18, from, to) | ||
|
||
await createToken(from, 'DETH', 200) | ||
await accountToAccount('DETH', 46, from) | ||
} | ||
|
||
async function createToken (address: string, symbol: string, amount: number): Promise<void> { | ||
const metadata = { | ||
symbol, | ||
name: symbol, | ||
isDAT: true, | ||
mintable: true, | ||
tradeable: true, | ||
collateralAddress: address | ||
} | ||
await container.waitForWalletBalanceGTE(101) | ||
await container.call('createtoken', [metadata]) | ||
await container.generate(1) | ||
|
||
await container.call('minttokens', [`${amount.toString()}@${symbol}`]) | ||
await container.generate(1) | ||
} | ||
|
||
async function accountToAccount (symbol: string, amount: number, from: string, _to = ''): Promise<string> { | ||
const to = _to !== '' ? _to : await container.call('getnewaddress') | ||
|
||
await container.call('accounttoaccount', [from, { [to]: `${amount.toString()}@${symbol}` }]) | ||
|
||
return to | ||
} | ||
|
||
it('should get accountHistoryCount', async () => { | ||
await waitForExpect(async () => { | ||
const count = await client.account.historyCount() | ||
|
||
expect(typeof count).toBe('number') | ||
expect(count).toBeGreaterThanOrEqual(0) | ||
}) | ||
}) | ||
|
||
it('should get accountHistoryCount with owner as all', async () => { | ||
await waitForExpect(async () => { | ||
const count = await client.account.historyCount('all') | ||
|
||
expect(typeof count).toBe('number') | ||
expect(count).toBeGreaterThanOrEqual(0) | ||
}) | ||
}) | ||
|
||
it('should get accountHistoryCount with no_rewards option', async () => { | ||
await waitForExpect(async () => { | ||
const options: AccountHistoryCountOptions = { | ||
no_rewards: true | ||
} | ||
const count = await client.account.historyCount('mine', options) | ||
|
||
expect(typeof count).toBe('number') | ||
expect(count).toBeGreaterThanOrEqual(0) | ||
}) | ||
}) | ||
|
||
it('should get accountHistoryCount with token option', async () => { | ||
await waitForExpect(async () => { | ||
const options1: AccountHistoryCountOptions = { | ||
token: 'DBTC' | ||
} | ||
const options2: AccountHistoryCountOptions = { | ||
token: 'DETH' | ||
} | ||
const countWithDBTC = await client.account.historyCount('mine', options1) | ||
const countWithDETH = await client.account.historyCount('mine', options2) | ||
|
||
expect(typeof countWithDBTC).toBe('number') | ||
expect(typeof countWithDETH).toBe('number') | ||
expect(countWithDBTC).toStrictEqual(5) | ||
expect(countWithDETH).toStrictEqual(3) | ||
}) | ||
}) | ||
|
||
it('should get accountHistory with txtype option', async () => { | ||
await waitForExpect(async () => { | ||
const options: AccountHistoryCountOptions = { | ||
txtype: TxType.MINT_TOKEN | ||
} | ||
const count = await client.account.historyCount('mine', options) | ||
|
||
expect(typeof count).toBe('number') | ||
expect(count).toBeGreaterThanOrEqual(0) | ||
}) | ||
}) | ||
|
||
it('should get different count for different txtypes', async () => { | ||
await waitForExpect(async () => { | ||
const options1: AccountHistoryCountOptions = { | ||
txtype: TxType.MINT_TOKEN | ||
} | ||
const options2: AccountHistoryCountOptions = { | ||
txtype: TxType.POOL_SWAP | ||
|
||
} | ||
const count1 = await client.account.historyCount('mine', options1) | ||
const count2 = await client.account.historyCount('mine', options2) | ||
|
||
expect(count1 === count2).toStrictEqual(false) | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
91 changes: 91 additions & 0 deletions
91
packages/jellyfish-api-core/__tests__/category/account/getAccount.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
import { MasterNodeRegTestContainer } from '@defichain/testcontainers' | ||
import { ContainerAdapterClient } from '../../container_adapter_client' | ||
import waitForExpect from 'wait-for-expect' | ||
|
||
describe('Account', () => { | ||
const container = new MasterNodeRegTestContainer() | ||
const client = new ContainerAdapterClient(container) | ||
|
||
beforeAll(async () => { | ||
await container.start() | ||
await container.waitForReady() | ||
await container.waitForWalletCoinbaseMaturity() | ||
await container.waitForWalletBalanceGTE(100) | ||
await createToken(await container.getNewAddress(), 'DBTC', 200) | ||
}) | ||
|
||
afterAll(async () => { | ||
await container.stop() | ||
}) | ||
|
||
async function createToken (address: string, symbol: string, amount: number): Promise<void> { | ||
const metadata = { | ||
symbol, | ||
name: symbol, | ||
isDAT: true, | ||
mintable: true, | ||
tradeable: true, | ||
collateralAddress: address | ||
} | ||
await container.call('createtoken', [metadata]) | ||
await container.generate(1) | ||
|
||
await container.call('minttokens', [`${amount.toString()}@${symbol}`]) | ||
await container.generate(1) | ||
} | ||
|
||
it('should getAccount', async () => { | ||
const accounts = await client.account.listAccounts() | ||
|
||
const account = await client.account.getAccount(accounts[0].owner.addresses[0]) | ||
expect(account.length).toBeGreaterThan(0) | ||
for (let i = 0; i < account.length; i += 1) { | ||
expect(typeof account[i]).toStrictEqual('string') | ||
} | ||
}) | ||
|
||
it('should getAccount with pagination start and including_start', async () => { | ||
let accounts: any[] = [] | ||
let beforeAccountCount = 0 | ||
|
||
await waitForExpect(async () => { | ||
accounts = await client.account.listAccounts() | ||
expect(accounts.length).toBeGreaterThan(0) | ||
|
||
const account = await client.account.getAccount(accounts[0].owner.addresses[0]) | ||
beforeAccountCount = account.length | ||
}) | ||
|
||
const pagination = { | ||
start: beforeAccountCount, | ||
including_start: true | ||
} | ||
|
||
const account = await client.account.getAccount(accounts[0].owner.addresses[0], pagination) | ||
expect(account.length).toStrictEqual(1) | ||
|
||
for (let i = 0; i < account.length; i += 1) { | ||
expect(typeof account[i]).toStrictEqual('string') | ||
} | ||
}) | ||
|
||
it('should getAccount with pagination.limit', async () => { | ||
const accounts = await client.account.listAccounts() | ||
|
||
const pagination = { | ||
limit: 1 | ||
} | ||
const account = await client.account.getAccount(accounts[0].owner.addresses[0], pagination) | ||
expect(account.length).toStrictEqual(1) | ||
}) | ||
|
||
it('should getAccount with indexedAmount true', async () => { | ||
const accounts = await client.account.listAccounts() | ||
|
||
const account = await client.account.getAccount(accounts[0].owner.addresses[0], {}, { indexedAmounts: true }) | ||
expect(typeof account).toStrictEqual('object') | ||
for (const k in account) { | ||
expect(typeof account[k]).toStrictEqual('number') | ||
} | ||
}) | ||
}) |
Oops, something went wrong.