Skip to content

Commit

Permalink
Added tests for new overloading functions
Browse files Browse the repository at this point in the history
  • Loading branch information
vekexasia committed Apr 17, 2018
1 parent c8d114c commit d46795e
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/library.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export class DposLedger {
*/
// tslint:disable-next-line max-line-length
public async getPubKey(account: LedgerAccount | Buffer, showOnLedger: boolean = false): Promise<{ publicKey: string, address: string }> {
const pathBuf = Buffer.isBuffer(account)? account : account.derivePath();
const pathBuf = Buffer.isBuffer(account) ? account : account.derivePath();
const resp = await this.exchange([
0x04,
showOnLedger ? 0x1 : 0x0,
Expand Down
39 changes: 39 additions & 0 deletions tests/unit/library.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,15 @@ describe('library', () => {
account.derivePath()
]);
});
it('should allow custom path32 derivation buffer', async () => {
await instance.getPubKey(account.derivePath());
expect(instanceExchangeStub.firstCall.args[0]).to.be.deep.eq([
0x04,
0x00,
account.derivePath().length / 4,
account.derivePath()
]);
});
it('should allow true in second param to show address', async () => {
await instance.getPubKey(account, true);
expect(instanceExchangeStub.calledOnce).is.true;
Expand Down Expand Up @@ -234,6 +243,21 @@ describe('library', () => {
buff
]);
});
it('should do the same as above ^^ for custom bip32 buffer', async () => {
const buff = Buffer.alloc(2);
await instance.signTX(account.derivePath(), buff, false);
expect(instanceExchangeStub.calledOnce).is.true;
const lengthBuff = Buffer.alloc(2);
lengthBuff.writeUInt16BE(2, 0);
expect(instanceExchangeStub.firstCall.args[0]).to.be.deep.eq([
0x05, // sign type
account.derivePath().length / 4,
account.derivePath(),
lengthBuff, // buffer length
0x00,
buff
]);
});
});

describe('signMSG', () => {
Expand Down Expand Up @@ -276,6 +300,21 @@ describe('library', () => {
buff,
]);
});
it('should do the same as above ^^ but with custom bip32 buffer', async () => {
const buff = Buffer.alloc(2);
await instance.signMSG(account.derivePath(), buff);
expect(instanceExchangeStub.calledOnce).is.true;
const lengthBuff = Buffer.alloc(2);
lengthBuff.writeUInt16BE(2, 0);
expect(instanceExchangeStub.firstCall.args[0]).to.be.deep.eq([
0x06, // sign type
account.derivePath().length / 4,
account.derivePath(),
lengthBuff, // buffer length
0x0,
buff,
]);
});
it('should call convert string to buffer', async () => {
await instance.signMSG(account, 'vekexasia rules');
expect(instanceExchangeStub.calledOnce).is.true;
Expand Down

0 comments on commit d46795e

Please sign in to comment.