Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added unit tests for HD.js #1123

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Added tests around isBase58, isRaw, from()
  • Loading branch information
haxwell committed Jan 12, 2023
commit 0af54bfbf4bc1b592165b14fa930065310d1fc16
67 changes: 67 additions & 0 deletions test/hd-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,73 @@ describe('HD', function() {
assert.strictEqual(key.toBase58('main'), master.toPublic().toBase58('main'));
});

it('should return a private key from fromRaw when private key data is supplied', () => {
const key = HD.fromRaw(master.toRaw(), 'main');
assert.strictEqual(key.toBase58('main'), master.toBase58('main'));
});

it('should return a public key from fromRaw when public key data is supplied', () => {
const key = HD.fromRaw(master.toPublic().toRaw(), 'main');
assert.strictEqual(key.toBase58('main'), master.toPublic().toBase58('main'));
});

it('should handle the private key case in HD.isBase58', () => {
assert.strictEqual(HD.isBase58(master.toBase58('main')), true);
});

it('should handle the public key case in HD.isBase58', () => {
assert.strictEqual(HD.isBase58(master.toPublic().toBase58('main')), true);
});

it('should handle the private key case in HD.isRaw', () => {
assert.strictEqual(HD.isRaw(master.toRaw()), true);
});

it('should handle the public key case in HD.isRaw', () => {
assert.strictEqual(HD.isRaw(master.toPublic().toRaw()), true);
});

it('should handle the private key case in HD.isHD', () => {
assert.strictEqual(HD.isHD(master), true);
});

it('should handle the public key case in HD.isHD', () => {
assert.strictEqual(HD.isHD(master.toPublic()), true);
});

it('should fail assertion when HD.from is called invalid data', () => {
assert.throws(() => {
HD.from('invalid', 'main');
}, Error);
});

it('should return the passed in parameter when HD.from is called with a valid HD object', () => {
const key = HD.from(master, 'main');
assert.strictEqual(key, master);
});

it('should return a key from HD.from when the passed in param isBase58', () => {
const key = HD.from(master.toBase58('main'), 'main');
assert.strictEqual(key.toBase58('main'), master.toBase58('main'));
});

it('should return a key from HD.from when the passed in param isRaw', () => {
const key = HD.from(master.toRaw(), 'main');
assert.strictEqual(key.toBase58('main'), master.toBase58('main'));
});

it('should return a key from HD.from when the passed in param is mnemonic options', () => {
const mne = new HD.Mnemonic();
const key = HD.from(mne, 'main');
assert.strictEqual(HD.isHD(key), true);
});

it('should throw an error from HD.from when passed in param is not Base58, Raw, Mnemonic, or HD', () => {
assert.throws(() => {
HD.from('bad options', 'main');
}, Error);
});

for (const vector of [vector1, vector2]) {
let master = null;

Expand Down