-
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
1 parent
2f3ab75
commit 4fb3b90
Showing
3 changed files
with
213 additions
and
78 deletions.
There are no files selected for viewing
92 changes: 92 additions & 0 deletions
92
packages/jellyfish-api-core/__tests__/category/account/accountToUtxos.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,92 @@ | ||
import { MasterNodeRegTestContainer } from '@defichain/testcontainers' | ||
import { ContainerAdapterClient } from '../../container_adapter_client' | ||
import { BalanceTransferPayload } from '../../../src/category/account' | ||
import { RpcApiError } from '../../../src' | ||
|
||
describe('Account with DBTC', () => { | ||
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() | ||
}) | ||
|
||
let from: string | ||
|
||
async function setup (): Promise<void> { | ||
from = await container.call('getnewaddress') | ||
await createToken(from, 'DBTC') | ||
} | ||
|
||
async function createToken (address: string, symbol: string): 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('utxostoaccount', [{ [address]: '100@0' }]) | ||
await container.generate(1) | ||
} | ||
|
||
it('should accountToUtxos', async () => { | ||
const balanceBefore = await container.call('getbalance') | ||
|
||
const payload: BalanceTransferPayload = {} | ||
// NOTE(jingyi2811): Only support sending DFI from account to Utxos. | ||
payload[await container.getNewAddress()] = '5@DFI' | ||
payload[await container.getNewAddress()] = '5@DFI' | ||
|
||
const data = await client.account.accountToUtxos(from, payload) | ||
await container.generate(1) | ||
|
||
expect(typeof data).toStrictEqual('string') | ||
expect(data.length).toStrictEqual(64) | ||
|
||
const balanceAfter = await container.call('getbalance') | ||
expect(balanceAfter).toBeGreaterThan(balanceBefore) | ||
}) | ||
|
||
it('should not accountToUtxos for token', async () => { | ||
const payload: BalanceTransferPayload = {} | ||
payload[await container.getNewAddress()] = '5@DBTC' | ||
|
||
const promise = client.account.accountToUtxos(from, payload) | ||
|
||
await expect(promise).rejects.toThrow(RpcApiError) | ||
await expect(promise).rejects.toThrow('RpcApiError: \'Test AccountToUtxosTx execution failed:\nonly available for DFI transactions\', code: -32600, method: accounttoutxos') | ||
}) | ||
|
||
it('should accountToUtxos with utxos', async () => { | ||
const balanceBefore = await container.call('getbalance') | ||
|
||
const { txid, vout } = await container.fundAddress(from, 10) | ||
|
||
const payload: BalanceTransferPayload = {} | ||
// NOTE(jingyi2811): Only support sending DFI from account to Utxos. | ||
payload[await container.getNewAddress()] = '5@DFI' | ||
payload[await container.getNewAddress()] = '5@DFI' | ||
|
||
const data = await client.account.accountToUtxos(from, payload, { utxos: [{ txid, vout }] }) | ||
await container.generate(1) | ||
|
||
expect(typeof data).toStrictEqual('string') | ||
expect(data.length).toStrictEqual(64) | ||
|
||
const balanceAfter = await container.call('getbalance') | ||
expect(balanceAfter).toBeGreaterThan(balanceBefore) | ||
}) | ||
}) |
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
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