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

Add data field option to type 0 transaction creator - Closes#606 #632

Closed
Show file tree
Hide file tree
Changes from all commits
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
5 changes: 5 additions & 0 deletions docs/transaction.md
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,11 @@ ARGUMENTS
ADDRESS Address of the recipient.

OPTIONS
-d, --data=data
Optional UTF8 encoded data (maximum of 64 bytes) to include in the transaction asset.
Examples:
- --data=customInformation

-j, --[no-]json
Prints output in JSON format. You can change the default behaviour in your config.json file.

Expand Down
23 changes: 21 additions & 2 deletions src/commands/transaction/create/transfer.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,22 @@ import BaseCommand from '../../../base';
import commonFlags from '../../../utils/flags';
import getInputsFromSources from '../../../utils/input';

const processInputs = (amount, address) => ({ passphrase, secondPassphrase }) =>
const dataFlag = {
char: 'd',
description: `Optional UTF8 encoded data (maximum of 64 bytes) to include in the transaction asset.
Examples:
- --data=customInformation
`,
};

const processInputs = (amount, address, data) => ({
passphrase,
secondPassphrase,
}) =>
elements.transaction.transfer({
recipientId: address,
amount,
data,
passphrase,
secondPassphrase,
});
Expand All @@ -35,14 +47,20 @@ export default class TransferCommand extends BaseCommand {
passphrase: passphraseSource,
'second-passphrase': secondPassphraseSource,
'no-signature': noSignature,
data: dataString,
},
} = this.parse(TransferCommand);

elements.transaction.utils.validateAddress(address);
const normalizedAmount = elements.transaction.utils.convertLSKToBeddows(
amount,
);
const processFunction = processInputs(normalizedAmount, address);

const processFunction = processInputs(
normalizedAmount,
address,
dataString,
);

if (noSignature) {
const result = processFunction({
Expand Down Expand Up @@ -87,6 +105,7 @@ TransferCommand.flags = {
passphrase: flagParser.string(commonFlags.passphrase),
'second-passphrase': flagParser.string(commonFlags.secondPassphrase),
'no-signature': flagParser.boolean(commonFlags.noSignature),
data: flagParser.string(dataFlag),
};

TransferCommand.description = `
Expand Down
36 changes: 32 additions & 4 deletions test/commands/transaction/create/transfer.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,35 @@ describe('transaction:create:transfer', () => {
describe('transaction:create:transfer amount address', () => {
setupTest()
.command(['transaction:create:transfer', defaultAmount, defaultAddress])
.it('should create an tranfer transaction', () => {
.it('should create a transfer transaction', () => {
expect(transactionUtilStub.validateAddress).to.be.calledWithExactly(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"tranfer" --> "transfer"

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Haha, good catch, these were old test and these wrong articles caught my eye but I missed out this one 😅

defaultAddress,
);
expect(transactionUtilStub.convertLSKToBeddows).to.be.calledWithExactly(
defaultAmount,
);
expect(getInputsFromSources.default).to.be.calledWithExactly({
passphrase: {
source: undefined,
repeatPrompt: true,
},
secondPassphrase: null,
});
return expect(printMethodStub).to.be.calledWithExactly(
defaultTransaction,
);
});
});

describe('transaction:create:transfer amount address --data=xxx', () => {
setupTest()
.command([
'transaction:create:transfer',
defaultAmount,
defaultAddress,
'--data=Testing lisk transaction data.',
])
.it('should create a transfer transaction', () => {
expect(transactionUtilStub.validateAddress).to.be.calledWithExactly(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above.

defaultAddress,
);
Expand Down Expand Up @@ -109,7 +137,7 @@ describe('transaction:create:transfer', () => {
defaultAddress,
'--no-signature',
])
.it('should create an tranfer transaction without signature', () => {
.it('should create a transfer transaction without signature', () => {
expect(transactionUtilStub.validateAddress).to.be.calledWithExactly(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above.

defaultAddress,
);
Expand All @@ -131,7 +159,7 @@ describe('transaction:create:transfer', () => {
defaultAddress,
'--passphrase=pass:123',
])
.it('should create an tranfer transaction', () => {
.it('should create a transfer transaction', () => {
expect(transactionUtilStub.validateAddress).to.be.calledWithExactly(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above.

defaultAddress,
);
Expand Down Expand Up @@ -160,7 +188,7 @@ describe('transaction:create:transfer', () => {
'--passphrase=pass:123',
'--second-passphrase=pass:456',
])
.it('should create an tranfer transaction', () => {
.it('should create a transfer transaction', () => {
expect(transactionUtilStub.validateAddress).to.be.calledWithExactly(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above.

defaultAddress,
);
Expand Down