Skip to content

Commit

Permalink
Merge PR #1030 from 'RajWorking/test-coverage'
Browse files Browse the repository at this point in the history
  • Loading branch information
pinheadmz committed Sep 6, 2021
2 parents e14a95a + a2ea585 commit cf7da94
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions test/wallet-http-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ let txFee = 0;

const coinValue = 50000;
const witnessOptions = [true, false];
const wallets = ['primary'];

for (const witnessOpt of witnessOptions) {
describe(`Wallet HTTP - witness: ${witnessOpt}`, function() {
Expand All @@ -71,11 +72,17 @@ for (const witnessOpt of witnessOptions) {

it('should create wallet', async () => {
const info = await wclient.createWallet(name, {witness: witnessOpt});
wallets.push(name);
assert.strictEqual(info.id, name);
wallet = wclient.wallet(name, info.token);
await wallet.open();
});

it('should list wallets', async () => {
const info = await wclient.getWallets();
assert.deepEqual(info, wallets);
});

it('should get wallet info', async () => {
const info = await wallet.getInfo();
assert.strictEqual(info.id, name);
Expand All @@ -85,12 +92,49 @@ for (const witnessOpt of witnessOptions) {
addr = Address.fromString(str, node.network);
});

it('should change passphrase', async () => {
await wallet.setPassphrase('initial');

// Incorrect Passphrase should not work
await assert.rejects(async () => {
await wallet.unlock('badpass');
}, {
name: 'Error',
message: 'Could not decrypt.'
});

// Correct Passphrase should work
const masterO1 = await wclient.getMaster(name);
assert.equal(masterO1.encrypted, true);
await wallet.unlock('initial');
const masterO2 = await wclient.getMaster(name);
assert.equal(masterO2.encrypted, false);

await wallet.setPassphrase('newpass', 'initial');

// Old Passphrase should not work
await assert.rejects(async () => {
await wallet.unlock('initial');
}, {
name: 'Error',
message: 'Could not decrypt.'
});

// New Passphrase should work
const masterN1 = await wclient.getMaster(name);
assert.equal(masterN1.encrypted, true);
await wallet.unlock('newpass', 15000);
const masterN2 = await wclient.getMaster(name);
assert.equal(masterN2.encrypted, false);
});

it('should enable seed phrase recovery', async () => {
const options = {
passphrase: 'PASSPHRASE',
mnemonic: 'zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo wrong'
};
const walletName = `test_seed-${witnessOpt}`;
wallets.push(walletName);

const testwallet = await wclient.createWallet(walletName, options);
assert.strictEqual(testwallet.master.encrypted, false);
Expand Down

0 comments on commit cf7da94

Please sign in to comment.