-
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
3 changed files
with
85 additions
and
80 deletions.
There are no files selected for viewing
37 changes: 37 additions & 0 deletions
37
packages/jellyfish-api-core/__tests__/category/wallet/dumpPrivKey.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,37 @@ | ||
import { MasterNodeRegTestContainer } from '@defichain/testcontainers' | ||
import { ContainerAdapterClient } from '../../container_adapter_client' | ||
import waitForExpect from 'wait-for-expect' | ||
|
||
describe('DumpPrivKey', () => { | ||
const container = new MasterNodeRegTestContainer() | ||
const client = new ContainerAdapterClient(container) | ||
|
||
beforeAll(async () => { | ||
await container.start() | ||
await container.waitForReady() | ||
await container.waitForWalletCoinbaseMaturity() | ||
await container.waitForWalletBalanceGTE(101) | ||
}) | ||
|
||
afterAll(async () => { | ||
await container.stop() | ||
}) | ||
|
||
it('should reveal private key of given address', async () => { | ||
await waitForExpect(async () => { | ||
const address = 'mwsZw8nF7pKxWH8eoKL9tPxTpaFkz7QeLU' | ||
const privateKey = await client.wallet.dumpPrivKey(address) | ||
|
||
expect(typeof privateKey).toStrictEqual('string') | ||
expect(privateKey).toStrictEqual('cRiRQ9cHmy5evDqNDdEV8f6zfbK6epi9Fpz4CRZsmLEmkwy54dWz') | ||
}) | ||
}) | ||
|
||
it('should throw and error when invalid DFI address is provided', async () => { | ||
await waitForExpect(async () => { | ||
const invalidAddress = 'invalidAddress' | ||
|
||
await expect(client.wallet.dumpPrivKey(invalidAddress)).rejects.toThrow('Invalid Defi address') | ||
}) | ||
}) | ||
}) |
45 changes: 45 additions & 0 deletions
45
packages/jellyfish-api-core/__tests__/category/wallet/importPrivkey.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,45 @@ | ||
import { MasterNodeRegTestContainer } from '@defichain/testcontainers' | ||
import { ContainerAdapterClient } from '../../container_adapter_client' | ||
|
||
describe('ImportPrivKey', () => { | ||
const container = new MasterNodeRegTestContainer() | ||
const client = new ContainerAdapterClient(container) | ||
|
||
beforeAll(async () => { | ||
await container.start() | ||
await container.waitForReady() | ||
await container.waitForWalletCoinbaseMaturity() | ||
}) | ||
|
||
afterAll(async () => { | ||
await container.stop() | ||
}) | ||
|
||
it('should should import private key without failing ', async () => { | ||
const privatekey = await client.wallet.dumpPrivKey(await client.wallet.getNewAddress()) | ||
const promise = client.wallet.importPrivKey(privatekey) | ||
|
||
await expect(promise).resolves.not.toThrow() | ||
}) | ||
|
||
it('should import private key with rescan set to false', async () => { | ||
const privateKey = await client.wallet.dumpPrivKey(await client.wallet.getNewAddress()) | ||
const promise = client.wallet.importPrivKey(privateKey, '', false) | ||
|
||
await expect(promise).resolves.not.toThrow() | ||
}) | ||
|
||
it('should import private key with label passed', async () => { | ||
const privateKey = await client.wallet.dumpPrivKey(await client.wallet.getNewAddress('testing')) | ||
const promise = client.wallet.importPrivKey(privateKey, 'testing') | ||
|
||
await expect(promise).resolves.not.toThrow() | ||
}) | ||
|
||
it('should fail and throw an error with invalid private key', async () => { | ||
const privateKey = 'invalidPrivateKey' | ||
const promise = client.wallet.importPrivKey(privateKey) | ||
|
||
await expect(promise).rejects.toThrow('Invalid private key encoding') | ||
}) | ||
}) |
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