Skip to content
This repository was archived by the owner on Sep 6, 2024. It is now read-only.

Retain original behavior of addChecksum #360

Merged
merged 1 commit into from
Feb 22, 2019
Merged
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
4 changes: 2 additions & 2 deletions lib/utils/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ var convertUnits = function(value, fromUnit, toUnit) {
throw new Error("Invalid unit provided");
}

var valueBn = new BigNumber(value);
var valueBn = new BigNumber(value);

if(valueBn.dp() > unitMap[fromUnit].dp) {
throw new Error("Input value exceeded max fromUnit precision.");
Expand Down Expand Up @@ -110,7 +110,7 @@ var addChecksum = function (inputValue, checksumLength, isAddress) {
var fallbackLength = isTrytes ? 9 : 27;
var length = checksumLength || fallbackLength;

return value.concat(checksum.slice(0, length));
return value.concat(checksum.slice(-length));
};

var result = input.map(withChecksum);
Expand Down
12 changes: 6 additions & 6 deletions test/utils/utils.checksum.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ describe('utils.checksum', function () {
var checksumLength = 3;

validAddressData.forEach(function (data) {
expect(Utils.addChecksum(data.address, checksumLength)).to.equal(data.address + data.checksum.slice(0, checksumLength));
expect(Utils.addChecksum(data.address, checksumLength)).to.equal(data.address + data.checksum.slice(-checksumLength));
});
});
});
Expand Down Expand Up @@ -103,7 +103,7 @@ describe('utils.checksum', function () {

expect(actualAddressesWithChecksum).to.eql(expectedAddressesWithChecksum);
});

it('should have correct checksum length', function () {
var checksumLength = 4;

Expand All @@ -115,7 +115,7 @@ describe('utils.checksum', function () {
);

var expectedAddressesWithChecksum = validAddressData.map(function (data) {
return data.address + data.checksum.slice(0, checksumLength);
return data.address + data.checksum.slice(-checksumLength);
});

expect(actualAddressesWithChecksum).to.eql(expectedAddressesWithChecksum);
Expand Down Expand Up @@ -176,11 +176,11 @@ describe('utils.checksum', function () {

addressData.forEach(function (data) {
var addressTritsWithChecksum = Utils.addChecksum(data.address, tritsChecksumLength);
expect(addressTritsWithChecksum).to.eql(data.address.concat(data.checksum.slice(0, tritsChecksumLength)));
expect(addressTritsWithChecksum).to.eql(data.address.concat(data.checksum.slice(-tritsChecksumLength)));

// Also assert on trytes
expect(Converter.trytes(addressTritsWithChecksum)).to.equal(
Converter.trytes(data.address).concat(Converter.trytes(data.checksum).slice(0, trytesChecksumLength))
Converter.trytes(data.address).concat(Converter.trytes(data.checksum).slice(-trytesChecksumLength))
);
});
});
Expand Down Expand Up @@ -253,7 +253,7 @@ describe('utils.checksum', function () {
tritsChecksumLength
);
var expectedTritArray = addressData.map(function (data) {
return data.address.concat(data.checksum.slice(0, tritsChecksumLength));
return data.address.concat(data.checksum.slice(-tritsChecksumLength));
});

expect(actualTritArray).to.eql(expectedTritArray);
Expand Down