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

Commit

Permalink
Merge pull request #535 from LiskHQ/502-get_transaction_bytes_refactor
Browse files Browse the repository at this point in the history
Fix amount bug getTransactionBytes - Closes #544
  • Loading branch information
Tobias Schwarz committed Feb 8, 2018
2 parents efe0a6a + 06c92c5 commit 3122e4d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 deletions.
7 changes: 5 additions & 2 deletions src/transactions/utils/getTransactionBytes.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
* Removal or modification of this copyright notice is prohibited.
*
*/
import bignum from 'browserify-bignum';
import cryptoModule from '../../crypto';

export const isValidValue = value => ![undefined, false, NaN].includes(value);
Expand Down Expand Up @@ -173,8 +174,10 @@ const getTransactionBytes = transaction => {
)
: Buffer.alloc(BYTESIZES.RECIPIENT_ID);

const transactionAmount = Buffer.alloc(BYTESIZES.AMOUNT);
transactionAmount.writeInt32LE(transaction.amount, 0, BYTESIZES.AMOUNT);
const transactionAmount = bignum(transaction.amount).toBuffer({
endian: 'little',
size: BYTESIZES.AMOUNT,
});

const transactionAssetData = getAssetBytes(transaction);

Expand Down
15 changes: 7 additions & 8 deletions test/transactions/utils/getTransactionBytes.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ const defaultSenderPublicKey =
const defaultSenderId = '18160565574430594874L';
const defaultSenderSecondPublicKey =
'0401c8ac9f29ded9e1e4d5b6b43051cb25b22f27c7b7b35092161e851946f82f';
const defaultAmount = 1000;
const defaultAmount = (3 + 2 ** 62).toString();
const defaultNoAmount = 0;
const defaultTimestamp = 141738;
const defaultTransactionId = '13987348420913138422';
Expand Down Expand Up @@ -65,7 +65,7 @@ describe('#getTransactionBytes', () => {

it('should return Buffer of type 0 (transfer LSK) transaction', () => {
const expectedBuffer = Buffer.from(
'00aa2902005d036a858ce89f844491762eb89e2bfbd50a4a0a0da658e4b2628b25b117ae0900cebcaa8d34153de803000000000000618a54975212ead93df8c881655c625544bce8ed7ccdfe6f08a42eecfb1adebd051307be5014bb051617baf7815d50f62129e70918190361e5d4dd4796541b0a',
'00aa2902005d036a858ce89f844491762eb89e2bfbd50a4a0a0da658e4b2628b25b117ae0900cebcaa8d34153d6000000000000040618a54975212ead93df8c881655c625544bce8ed7ccdfe6f08a42eecfb1adebd051307be5014bb051617baf7815d50f62129e70918190361e5d4dd4796541b0a',
'hex',
);
const transactionBytes = getTransactionBytes(defaultTransaction);
Expand All @@ -76,7 +76,7 @@ describe('#getTransactionBytes', () => {
it('should return Buffer of type 0 (transfer LSK) with data', () => {
defaultTransaction.asset.data = 'Hello Lisk! Some data in here!...';
const expectedBuffer = Buffer.from(
'00aa2902005d036a858ce89f844491762eb89e2bfbd50a4a0a0da658e4b2628b25b117ae0900cebcaa8d34153de80300000000000048656c6c6f204c69736b2120536f6d65206461746120696e2068657265212e2e2e618a54975212ead93df8c881655c625544bce8ed7ccdfe6f08a42eecfb1adebd051307be5014bb051617baf7815d50f62129e70918190361e5d4dd4796541b0a',
'00aa2902005d036a858ce89f844491762eb89e2bfbd50a4a0a0da658e4b2628b25b117ae0900cebcaa8d34153d600000000000004048656c6c6f204c69736b2120536f6d65206461746120696e2068657265212e2e2e618a54975212ead93df8c881655c625544bce8ed7ccdfe6f08a42eecfb1adebd051307be5014bb051617baf7815d50f62129e70918190361e5d4dd4796541b0a',
'hex',
);
const transactionBytes = getTransactionBytes(defaultTransaction);
Expand All @@ -97,11 +97,10 @@ describe('#getTransactionBytes', () => {
it('should return Buffer of transaction with second signature', () => {
defaultTransaction.signSignature = defaultSecondSignature;
const expectedBuffer = Buffer.from(
'00aa2902005d036a858ce89f844491762eb89e2bfbd50a4a0a0da658e4b2628b25b117ae0900cebcaa8d34153de803000000000000618a54975212ead93df8c881655c625544bce8ed7ccdfe6f08a42eecfb1adebd051307be5014bb051617baf7815d50f62129e70918190361e5d4dd4796541b0ab00c4ad1988bca245d74435660a278bfe6bf2f5efa8bda96d927fabf8b4f6fcfdcb2953f6abacaa119d6880987a55dea0e6354bc8366052b45fa23145522020f',
'00aa2902005d036a858ce89f844491762eb89e2bfbd50a4a0a0da658e4b2628b25b117ae0900cebcaa8d34153d6000000000000040618a54975212ead93df8c881655c625544bce8ed7ccdfe6f08a42eecfb1adebd051307be5014bb051617baf7815d50f62129e70918190361e5d4dd4796541b0ab00c4ad1988bca245d74435660a278bfe6bf2f5efa8bda96d927fabf8b4f6fcfdcb2953f6abacaa119d6880987a55dea0e6354bc8366052b45fa23145522020f',
'hex',
);
const transactionBytes = getTransactionBytes(defaultTransaction);

return transactionBytes.should.be.eql(expectedBuffer);
});

Expand Down Expand Up @@ -132,7 +131,7 @@ describe('#getTransactionBytes', () => {
it('should return Buffer of type 0 (transfer LSK) with additional properties', () => {
defaultTransaction.skip = false;
const expectedBuffer = Buffer.from(
'00aa2902005d036a858ce89f844491762eb89e2bfbd50a4a0a0da658e4b2628b25b117ae0900cebcaa8d34153de803000000000000618a54975212ead93df8c881655c625544bce8ed7ccdfe6f08a42eecfb1adebd051307be5014bb051617baf7815d50f62129e70918190361e5d4dd4796541b0a',
'00aa2902005d036a858ce89f844491762eb89e2bfbd50a4a0a0da658e4b2628b25b117ae0900cebcaa8d34153d6000000000000040618a54975212ead93df8c881655c625544bce8ed7ccdfe6f08a42eecfb1adebd051307be5014bb051617baf7815d50f62129e70918190361e5d4dd4796541b0a',
'hex',
);
const transactionBytes = getTransactionBytes(defaultTransaction);
Expand Down Expand Up @@ -339,7 +338,7 @@ describe('#getTransactionBytes', () => {

it('should return Buffer of type 6 (dapp inTransfer) transaction', () => {
const expectedBuffer = Buffer.from(
'06aa2902005d036a858ce89f844491762eb89e2bfbd50a4a0a0da658e4b2628b25b117ae090000000000000000e80300000000000031323334323133618a54975212ead93df8c881655c625544bce8ed7ccdfe6f08a42eecfb1adebd051307be5014bb051617baf7815d50f62129e70918190361e5d4dd4796541b0a',
'06aa2902005d036a858ce89f844491762eb89e2bfbd50a4a0a0da658e4b2628b25b117ae090000000000000000600000000000004031323334323133618a54975212ead93df8c881655c625544bce8ed7ccdfe6f08a42eecfb1adebd051307be5014bb051617baf7815d50f62129e70918190361e5d4dd4796541b0a',
'hex',
);
const transactionBytes = getTransactionBytes(inTransferTransction);
Expand Down Expand Up @@ -368,7 +367,7 @@ describe('#getTransactionBytes', () => {

it('should return Buffer of type 7 (dapp outTransfer) transaction', () => {
const expectedBuffer = Buffer.from(
'07aa2902005d036a858ce89f844491762eb89e2bfbd50a4a0a0da658e4b2628b25b117ae0900cebcaa8d34153de803000000000000313233343231333133393837333438343230393133313338343232618a54975212ead93df8c881655c625544bce8ed7ccdfe6f08a42eecfb1adebd051307be5014bb051617baf7815d50f62129e70918190361e5d4dd4796541b0a',
'07aa2902005d036a858ce89f844491762eb89e2bfbd50a4a0a0da658e4b2628b25b117ae0900cebcaa8d34153d6000000000000040313233343231333133393837333438343230393133313338343232618a54975212ead93df8c881655c625544bce8ed7ccdfe6f08a42eecfb1adebd051307be5014bb051617baf7815d50f62129e70918190361e5d4dd4796541b0a',
'hex',
);
const transactionBytes = getTransactionBytes(outTransferTransaction);
Expand Down

0 comments on commit 3122e4d

Please sign in to comment.