Skip to content
This repository has been archived by the owner on Apr 15, 2019. It is now read-only.

Commit

Permalink
✅ Add verify message test functions
Browse files Browse the repository at this point in the history
  • Loading branch information
tosch110 committed Jan 26, 2018
1 parent bdb04cf commit 2f89872
Show file tree
Hide file tree
Showing 5 changed files with 99 additions and 5 deletions.
4 changes: 2 additions & 2 deletions test/steps/api/3_then.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,12 @@ export function itShouldBroadcastTheSignature() {

export function itShouldNotBroadcastTheTransaction() {
const { liskAPIInstance } = this.test.ctx;
return liskAPIInstance.broadcastSignedTransaction.should.not.be.called();
return liskAPIInstance.broadcastTransaction.should.not.be.called();
}

export function itShouldBroadcastTheTransaction() {
const { liskAPIInstance, transaction } = this.test.ctx;
return liskAPIInstance.broadcastSignedTransaction.should.be.calledWithExactly(
return liskAPIInstance.broadcastTransaction.should.be.calledWithExactly(
JSON.parse(transaction),
);
}
Expand Down
24 changes: 21 additions & 3 deletions test/steps/crypto/1_given.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,16 @@ import cryptoInstance from '../../../src/utils/cryptoModule';
import * as inputUtils from '../../../src/utils/input/utils';
import { getFirstQuotedString, getQuotedStrings } from '../utils';

export function aMessageWithAPublicKeyAndASignature() {
const [message, publicKey, signature] = getQuotedStrings(
this.test.parent.title,
);

this.test.ctx.message = message;
this.test.ctx.publicKey = publicKey;
this.test.ctx.signature = signature;
}

export function theMessageUnderThePassphraseHasSignature() {
const signature = getFirstQuotedString(this.test.parent.title);
this.test.ctx.signature = signature;
Expand All @@ -40,17 +50,25 @@ export function aCryptoInstanceHasBeenInitialised() {
'getKeys',
'getAddressFromPublicKey',
'signMessage',
'verifyMessage',
].forEach(methodName => cryptoInstance[methodName].returns(cryptoResult));

this.test.ctx.cryptoResult = cryptoResult;
this.test.ctx.cryptoInstance = cryptoInstance;
}

export function aSenderPublicKey() {
const senderPublicKey = getFirstQuotedString(this.test.parent.title);
this.test.ctx.senderPublicKey = senderPublicKey;
export function aSignature() {
const signature = getFirstQuotedString(this.test.parent.title);
this.test.ctx.signature = signature;
}

export function aPublicKey() {
const publicKey = getFirstQuotedString(this.test.parent.title);
this.test.ctx.publicKey = publicKey;
}

export const aSenderPublicKey = aPublicKey;

export function aNonce() {
const nonce = getFirstQuotedString(this.test.parent.title);
this.test.ctx.nonce = nonce;
Expand Down
28 changes: 28 additions & 0 deletions test/steps/crypto/2_when.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,34 @@
import lisk from 'lisk-js';
import { DEFAULT_ERROR_MESSAGE } from '../utils';

export function anErrorOccursAttemptingToVerifyTheMessageUsingThePublicKeyAndTheSignature() {
const { cryptoInstance, publicKey, message, signature } = this.test.ctx;

lisk.crypto.verifyMessageWithPublicKey.throws(
new TypeError(DEFAULT_ERROR_MESSAGE),
);

this.test.ctx.errorMessage = DEFAULT_ERROR_MESSAGE;
this.test.ctx.returnValue = cryptoInstance.verifyMessage({
publicKey,
signature,
message,
});
}

export function noErrorOccursAttemptingToVerifyTheMessageUsingThePublicKeyAndTheSignature() {
const { cryptoInstance, message, publicKey, signature } = this.test.ctx;
const verifyReturnMessage = true;

lisk.crypto.verifyMessageWithPublicKey.returns(verifyReturnMessage);

this.test.ctx.returnValue = cryptoInstance.verifyMessage({
publicKey,
signature,
message,
});
}

export function noErrorOccursAttemptingToSignTheMessageUsingThePassphrase() {
const { cryptoInstance, message, passphrase, signature } = this.test.ctx;

Expand Down
20 changes: 20 additions & 0 deletions test/steps/crypto/3_then.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,26 @@ import lisk from 'lisk-js';
import cryptoInstance from '../../../src/utils/cryptoModule';
import { getFirstQuotedString } from '../utils';

export function theVerifiedMessageShouldBeReturned() {
const { returnValue } = this.test.ctx;
const verified = { verified: true };
return returnValue.should.eql(verified);
}

export function liskJSCryptoShouldBeUsedToVerifyTheMessage() {
const { message, publicKey, signature } = this.test.ctx;
return lisk.crypto.verifyMessageWithPublicKey.should.be.calledWithExactly({
publicKey,
signature,
message,
});
}

export function itShouldResolveToTheResultOfVerifyingTheMessage() {
const { returnValue, cryptoResult } = this.test.ctx;
return returnValue.should.be.fulfilledWith(cryptoResult);
}

export function itShouldSignTheMessageWithThePassphrase() {
const { message, passphrase } = this.test.ctx;
return cryptoInstance.signMessage.should.be.calledWithExactly({
Expand Down
28 changes: 28 additions & 0 deletions test/steps/vorpal/2_when.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,34 @@ import { wrapActionCreator, createCommand } from '../../../src/utils/helpers';
import execFile from '../../../src/execFile';
import { getFirstQuotedString } from '../utils';

export function theActionIsCalledWithTheOptionsThePublicKeyTheSignatureAndTheMessage() {
const { action, options, publicKey, signature, message } = this.test.ctx;
const returnValue = action({ options, publicKey, signature, message });
this.test.ctx.returnValue = returnValue;
return returnValue.catch(e => e);
}

export function theActionIsCalledWithTheOptionsTheMessageThePublicKeyAndTheSignature() {
const { action, options, publicKey, signature, message } = this.test.ctx;
const returnValue = action({ options, publicKey, signature, message });
this.test.ctx.returnValue = returnValue;
return returnValue.catch(e => e);
}

export function theActionIsCalledWithTheOptionsThePublicKeyAndTheSignature() {
const { action, options, publicKey, signature } = this.test.ctx;
const returnValue = action({ options, publicKey, signature });
this.test.ctx.returnValue = returnValue;
return returnValue.catch(e => e);
}

export function theActionIsCalledWithTheOptionsAndThePublicKey() {
const { action, options, publicKey } = this.test.ctx;
const returnValue = action({ options, publicKey });
this.test.ctx.returnValue = returnValue;
return returnValue.catch(e => e);
}

export function theActionIsCalledWithTheSignatureAndTheStringifiedErrorObjectViaVorpalStdIn() {
const { action, signature, errorObject } = this.test.ctx;
const returnValue = action({
Expand Down

0 comments on commit 2f89872

Please sign in to comment.