From 798a934256a522c7578e49ceb9a5722640dce5d4 Mon Sep 17 00:00:00 2001 From: Vegard Bakke Date: Sat, 30 Dec 2017 07:30:44 +0100 Subject: [PATCH] Minor changes --- src/trytes.js | 17 +++++++++++++++++ test/tests.js | 12 +++++++----- 2 files changed, 24 insertions(+), 5 deletions(-) diff --git a/src/trytes.js b/src/trytes.js index fa178c9..707571a 100644 --- a/src/trytes.js +++ b/src/trytes.js @@ -134,6 +134,14 @@ function _shiftTrytes(fromArray, sizeFrom, sizeTo) { } +/** + * Convert a tryte string (9+A-Z), to an array of tryte3 values (0-26) + * + * @param {*} tryte3Str a tryte string, e.g. "KB0Z" + * + * @returns Array of tryte3 valules, e.g. [11, 2, 0, 26] + * + */ function convertTryte3CharsToValues(tryte3Str) { let tryte3Values = new Array(tryte3Str.length); for (let i = 0; i < tryte3Str.length; i++) { @@ -144,6 +152,15 @@ function convertTryte3CharsToValues(tryte3Str) { } return tryte3Values; } + +/** + * Convert an array of tryte3 values (0-26) to a tryte string (9+A-Z) + * + * @param {*} tryte3Values Array of tryte3 valules, e.g. [11, 2, 0, 26] + * + * @returns a tryte string, e.g. "KB0Z" + * + */ function convertTryte3ValuesToChars(tryte3Values) { let tryte3Str = ""; let value = 0; diff --git a/test/tests.js b/test/tests.js index 1e74df3..09ff218 100644 --- a/test/tests.js +++ b/test/tests.js @@ -1,8 +1,6 @@ var chai = require('chai'); var assert = chai.assert; -var Trytes = require('../src/trytes.js'); - -Trytes.decodeTryteStringFromBytes('KB'); +var Trytes = require('../index.js'); describe('Various lengths of Z trytes', function () { @@ -13,12 +11,14 @@ describe('Various lengths of Z trytes', function () { var trytes = str.substr(0, i); var bytes = Trytes.encodeTryteStringAsBytes(trytes); var reverted = Trytes.decodeTryteStringFromBytes(bytes); - //console.log('Converted '+trytes+'-'+reverted+', via '+bytes.toString()); + console.log('Converted '+trytes+'-'+reverted+', via '+bytes.toString()); assert.equal(trytes, reverted); } }); }); + + describe('Various length of 9 trytes', function () { it('should convert tryte strings of 0 to 6, to byte and back', function () { @@ -27,12 +27,14 @@ describe('Various length of 9 trytes', function () { var trytes = str.substr(0, i); var bytes = Trytes.encodeTryteStringAsBytes(trytes); var reverted = Trytes.decodeTryteStringFromBytes(bytes); - //console.log('Converted '+trytes+'-'+reverted+', via '+bytes.toString()); + console.log('Converted '+trytes+'-'+reverted+', via '+bytes.toString()); assert.equal(trytes, reverted); } }); }); + + describe('Encode and decode seeds and addresses', function () { let testTrytes = [ '',