add unit tests for UInt31 and BIP32Path

This commit is contained in:
Vlad Stan 2020-09-02 10:08:31 +03:00
parent ec17b06bde
commit 0148d40f88

View file

@ -54,4 +54,41 @@ describe('types', () => {
});
});
});
describe('UInt31', () => {
const UINT31_MAX = Math.pow(2, 31) - 1;
it('return true for valid values', () => {
assert.strictEqual(types.UInt31(0), true);
assert.strictEqual(types.UInt31(1000), true);
assert.strictEqual(types.UInt31(UINT31_MAX), true);
});
it('return false for negative values', () => {
assert.strictEqual(types.UInt31(-1), false);
assert.strictEqual(types.UInt31(-UINT31_MAX), false);
});
it('return false for values > UINT31_MAX', () => {
assert.strictEqual(types.UInt31(UINT31_MAX + 1), false);
});
});
describe('BIP32Path', () => {
it('return true for valid paths', () => {
assert.strictEqual(types.BIP32Path("m/0'/0'"), true);
assert.strictEqual(types.BIP32Path("m/0'/0"), true);
assert.strictEqual(types.BIP32Path("m/0'/1'/2'/3/4'"), true);
});
it('return false for invalid paths', () => {
assert.strictEqual(types.BIP32Path('m'), false);
assert.strictEqual(types.BIP32Path("n/0'/0'"), false);
assert.strictEqual(types.BIP32Path("m/0'/x"), false);
});
it('return "BIP32 derivation path" for JSON.strigify()', () => {
const toJsonValue = JSON.stringify(types.BIP32Path);
assert.equal(toJsonValue, '"BIP32 derivation path"');
});
});
});