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

Commit

Permalink
Merge pull request #360 from rajivshah3/fix/add-checksum
Browse files Browse the repository at this point in the history
Retain original behavior of addChecksum
  • Loading branch information
chrisdukakis authored Feb 22, 2019
2 parents afe95db + 5a98f0d commit eb27c18
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
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

0 comments on commit eb27c18

Please sign in to comment.