-
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
6 changed files
with
355 additions
and
0 deletions.
There are no files selected for viewing
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
81 changes: 81 additions & 0 deletions
81
packages/jellyfish-api-core/__tests__/category/wallet/encryptWallet.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,81 @@ | ||
import { MasterNodeRegTestContainer, RegTestContainer } from '@defichain/testcontainers' | ||
import { ContainerAdapterClient } from '../../container_adapter_client' | ||
import { RpcApiError } from '@defichain/jellyfish-api-core' | ||
|
||
describe('Wallet on masternode', () => { | ||
const container = new MasterNodeRegTestContainer() | ||
const client = new ContainerAdapterClient(container) | ||
|
||
beforeAll(async () => { | ||
await container.start() | ||
}) | ||
|
||
afterAll(async () => { | ||
await container.stop() | ||
}) | ||
|
||
it('should throw error if passphrase for encryptWallet is empty', async () => { | ||
const promise = client.wallet.encryptWallet('') | ||
|
||
await expect(promise).rejects.toThrow(RpcApiError) | ||
await expect(promise).rejects.toThrow( | ||
"RpcApiError: 'passphrase can not be empty', code: -8, method: encryptwallet" | ||
) | ||
}) | ||
|
||
it('should encryptWallet with a given passphrase', async () => { | ||
const promise = await client.wallet.encryptWallet('yourpassphrase') | ||
|
||
expect(promise).toStrictEqual( | ||
'wallet encrypted; The keypool has been flushed and a new HD seed was generated (if you are using HD). You need to make a new backup.' | ||
) | ||
}) | ||
|
||
it('should throw error when encryptWallet is called again after encryption', async () => { | ||
const promise = client.wallet.encryptWallet('yourpassphrase') | ||
|
||
await expect(promise).rejects.toThrow(RpcApiError) | ||
await expect(promise).rejects.toThrow( | ||
"RpcApiError: 'Error: running with an encrypted wallet, but encryptwallet was called.', code: -15, method: encryptwallet" | ||
) | ||
}) | ||
}) | ||
|
||
describe('Wallet without masternode', () => { | ||
const container = new RegTestContainer() | ||
const client = new ContainerAdapterClient(container) | ||
|
||
beforeAll(async () => { | ||
await container.start() | ||
}) | ||
|
||
afterAll(async () => { | ||
await container.stop() | ||
}) | ||
|
||
it('should throw error if passphrase for wallet encryption is empty', async () => { | ||
const promise = client.wallet.encryptWallet('') | ||
|
||
await expect(promise).rejects.toThrow(RpcApiError) | ||
await expect(promise).rejects.toThrow( | ||
"RpcApiError: 'passphrase can not be empty', code: -8, method: encryptwallet" | ||
) | ||
}) | ||
|
||
it('should encryptWallet with a given passphrase', async () => { | ||
const promise = await client.wallet.encryptWallet('yourpassphrase') | ||
|
||
expect(promise).toStrictEqual( | ||
'wallet encrypted; The keypool has been flushed and a new HD seed was generated (if you are using HD). You need to make a new backup.' | ||
) | ||
}) | ||
|
||
it('should throw error when encryptWallet is called again after encryption', async () => { | ||
const promise = client.wallet.encryptWallet('yourpassphrase') | ||
|
||
await expect(promise).rejects.toThrow(RpcApiError) | ||
await expect(promise).rejects.toThrow( | ||
"RpcApiError: 'Error: running with an encrypted wallet, but encryptwallet was called.', code: -15, method: encryptwallet" | ||
) | ||
}) | ||
}) |
48 changes: 48 additions & 0 deletions
48
packages/jellyfish-api-core/__tests__/category/wallet/walletLock.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,48 @@ | ||
import { MasterNodeRegTestContainer } from '@defichain/testcontainers' | ||
import { ContainerAdapterClient } from '../../container_adapter_client' | ||
import { RpcApiError } from '@defichain/jellyfish-api-core' | ||
|
||
describe('Unencrypted wallet on masternode', () => { | ||
const container = new MasterNodeRegTestContainer() | ||
const client = new ContainerAdapterClient(container) | ||
|
||
beforeAll(async () => { | ||
await container.start() | ||
}) | ||
|
||
afterAll(async () => { | ||
await container.stop() | ||
}) | ||
|
||
it('should throw error when walletLock is called', async () => { | ||
const promise = client.wallet.walletLock() | ||
|
||
await expect(promise).rejects.toThrow(RpcApiError) | ||
await expect(promise).rejects.toThrow( | ||
"RpcApiError: 'Error: running with an unencrypted wallet, but walletlock was called.', code: -15, method: walletlock" | ||
) | ||
}) | ||
}) | ||
|
||
describe('Encrypted wallet on masternode', () => { | ||
const container = new MasterNodeRegTestContainer() | ||
const client = new ContainerAdapterClient(container) | ||
|
||
beforeAll(async () => { | ||
await container.start() | ||
await client.wallet.encryptWallet('password') | ||
await client.wallet.walletPassphrase('password', 10000) | ||
}) | ||
|
||
afterAll(async () => { | ||
await container.stop() | ||
}) | ||
|
||
it('should walletLock without failing', async () => { | ||
const method = client.wallet.importPrivKey(await client.wallet.dumpPrivKey(await client.wallet.getNewAddress())) | ||
const promise = client.wallet.walletLock() | ||
|
||
await expect(method).resolves.not.toThrow() | ||
await expect(promise).resolves.not.toThrow() | ||
}) | ||
}) |
72 changes: 72 additions & 0 deletions
72
packages/jellyfish-api-core/__tests__/category/wallet/walletPassphrase.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,72 @@ | ||
import { MasterNodeRegTestContainer } from '@defichain/testcontainers' | ||
import { ContainerAdapterClient } from '../../container_adapter_client' | ||
import { RpcApiError } from '@defichain/jellyfish-api-core' | ||
|
||
describe('Unencrypted wallet on masternode', () => { | ||
const container = new MasterNodeRegTestContainer() | ||
const client = new ContainerAdapterClient(container) | ||
|
||
beforeAll(async () => { | ||
await container.start() | ||
}) | ||
|
||
afterAll(async () => { | ||
await container.stop() | ||
}) | ||
|
||
it('should throw error when walletPassphrase is called', async () => { | ||
const promise = client.wallet.walletPassphrase('password', -100) | ||
|
||
await expect(promise).rejects.toThrow(RpcApiError) | ||
await expect(promise).rejects.toThrow( | ||
"RpcApiError: 'Error: running with an unencrypted wallet, but walletpassphrase was called.', code: -15, method: walletpassphrase" | ||
) | ||
}) | ||
}) | ||
|
||
describe('Encrypted wallet on masternode', () => { | ||
const container = new MasterNodeRegTestContainer() | ||
const client = new ContainerAdapterClient(container) | ||
|
||
beforeAll(async () => { | ||
await container.start() | ||
await client.wallet.encryptWallet('password') | ||
}) | ||
|
||
afterAll(async () => { | ||
await container.stop() | ||
}) | ||
|
||
it('should throw error when walletPassphrase is called with a negative timeout', async () => { | ||
const promise = client.wallet.walletPassphrase('password', -100) | ||
|
||
await expect(promise).rejects.toThrow(RpcApiError) | ||
await expect(promise).rejects.toThrow( | ||
"RpcApiError: 'Timeout cannot be negative.', code: -8, method: walletpassphrase" | ||
) | ||
}) | ||
|
||
it('should throw error when walletPassphrase is called without a passphrase', async () => { | ||
const promise = client.wallet.walletPassphrase('', 100) | ||
|
||
await expect(promise).rejects.toThrow(RpcApiError) | ||
await expect(promise).rejects.toThrow( | ||
"RpcApiError: 'passphrase can not be empty', code: -8, method: walletpassphrase" | ||
) | ||
}) | ||
|
||
it('should throw error when walletPassphrase is called with a wrong passphrase', async () => { | ||
const promise = client.wallet.walletPassphrase('incorrectpassword', 100) | ||
|
||
await expect(promise).rejects.toThrow(RpcApiError) | ||
await expect(promise).rejects.toThrow( | ||
"RpcApiError: 'Error: The wallet passphrase entered was incorrect.', code: -14, method: walletpassphrase" | ||
) | ||
}) | ||
|
||
it('should unlock wallet when walletPassphrase is called with the correct passphrase', async () => { | ||
const promise = client.wallet.walletPassphrase('password', 100) | ||
|
||
await expect(promise).resolves.not.toThrow() | ||
}) | ||
}) |
63 changes: 63 additions & 0 deletions
63
packages/jellyfish-api-core/__tests__/category/wallet/walletPassphraseChange.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,63 @@ | ||
import { MasterNodeRegTestContainer } from '@defichain/testcontainers' | ||
import { ContainerAdapterClient } from '../../container_adapter_client' | ||
import { RpcApiError } from '@defichain/jellyfish-api-core' | ||
|
||
describe('Unencrypted Wallet on masternode', () => { | ||
const container = new MasterNodeRegTestContainer() | ||
const client = new ContainerAdapterClient(container) | ||
|
||
beforeAll(async () => { | ||
await container.start() | ||
}) | ||
|
||
afterAll(async () => { | ||
await container.stop() | ||
}) | ||
|
||
it('should throw error when walletPassphraseChange is called', async () => { | ||
const promise = client.wallet.walletPassphraseChange('wrongpassword', 'newpassword') | ||
|
||
await expect(promise).rejects.toThrow(RpcApiError) | ||
await expect(promise).rejects.toThrow( | ||
"RpcApiError: 'Error: running with an unencrypted wallet, but walletpassphrasechange was called.', code: -15, method: walletpassphrasechange" | ||
) | ||
}) | ||
}) | ||
|
||
describe('Encrypted Wallet on masternode', () => { | ||
const container = new MasterNodeRegTestContainer() | ||
const client = new ContainerAdapterClient(container) | ||
|
||
beforeAll(async () => { | ||
await container.start() | ||
await client.wallet.encryptWallet('password') | ||
}) | ||
|
||
afterAll(async () => { | ||
await container.stop() | ||
}) | ||
|
||
it('should throw error when walletPassphraseChange is called with an incorrect passphrase', async () => { | ||
const promise = client.wallet.walletPassphraseChange('wrongpassword', 'newpassword') | ||
|
||
await expect(promise).rejects.toThrow(RpcApiError) | ||
await expect(promise).rejects.toThrow( | ||
"RpcApiError: 'Error: The wallet passphrase entered was incorrect.', code: -14, method: walletpassphrasechange" | ||
) | ||
}) | ||
|
||
it('should throw error when walletPassphraseChange is called with an empty passphrase', async () => { | ||
const promise = client.wallet.walletPassphraseChange('', 'newpassword') | ||
|
||
await expect(promise).rejects.toThrow(RpcApiError) | ||
await expect(promise).rejects.toThrow( | ||
"RpcApiError: 'passphrase can not be empty', code: -8, method: walletpassphrasechange" | ||
) | ||
}) | ||
|
||
it('should walletPassphraseChange when the correct old passphrase is provided', async () => { | ||
const promise = client.wallet.walletPassphraseChange('password', 'newpassword') | ||
|
||
await expect(promise).resolves.not.toThrow() | ||
}) | ||
}) |
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