diff --git a/npm-shrinkwrap.json b/npm-shrinkwrap.json index 47b07abf..20e33ec6 100644 --- a/npm-shrinkwrap.json +++ b/npm-shrinkwrap.json @@ -22,6 +22,11 @@ "version": "2.0.7", "resolved": "https://registry.npmjs.org/bignumber.js/-/bignumber.js-2.0.7.tgz" }, + "bn.js": { + "version": "3.1.1", + "from": "bn.js@*", + "resolved": "https://registry.npmjs.org/bn.js/-/bn.js-3.1.1.tgz" + }, "es6-promisify": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/es6-promisify/-/es6-promisify-2.0.0.tgz", diff --git a/package.json b/package.json index a7b7a507..78a29dfe 100644 --- a/package.json +++ b/package.json @@ -18,15 +18,16 @@ "async": "~0.9.0", "babel-runtime": "^5.5.4", "bignumber.js": "^2.0.3", + "bn.js": "^3.1.1", "es6-promisify": "^2.0.0", "extend": "~1.2.1", "https-proxy-agent": "^1.0.0", "is-my-json-valid": "^2.12.0", "lodash": "^3.1.0", "lru-cache": "~2.5.0", - "ripple-lib-transactionparser": "^0.5.0", "ripple-address-codec": "^1.6.0", "ripple-keypairs": "^0.7.3", + "ripple-lib-transactionparser": "^0.5.0", "ripple-wallet-generator": "^1.0.3", "sjcl-extended": "ripple/sjcl-extended#1.0.3", "ws": "~0.7.1" diff --git a/scripts/verify_ledger_json.js b/scripts/verify_ledger_json.js index a2139b25..c61e0f36 100755 --- a/scripts/verify_ledger_json.js +++ b/scripts/verify_ledger_json.js @@ -2,12 +2,13 @@ 'use strict'; var fs = require('fs'); -var Amount = require('../dist/npm').Amount; -var Ledger = require('../dist/npm').Ledger; +var ripple = require('../dist/npm')._DEPRECATED; +var Amount = ripple.Amount; +var Ledger = ripple.Ledger; function parse_options(from, flags) { - var argv = from.slice(), - opts_ = {argv: argv}; + var argv = from.slice(); + var opts_ = {argv: argv}; flags.forEach(function(f) { // Do we have the flag? diff --git a/src/core/base.js b/src/core/base.js index 4f6f8099..bab273ed 100644 --- a/src/core/base.js +++ b/src/core/base.js @@ -1,6 +1,6 @@ 'use strict'; -const sjcl = require('./utils').sjcl; +const BN = require('bn.js'); const extend = require('extend'); const {encode, decode} = require('ripple-address-codec'); @@ -44,11 +44,11 @@ Base.encode_check = function(version, input, alphabet) { }; // --> input : String -// <-- NaN || sjcl.bn +// <-- NaN || BN Base.decode_check = function(version, input, alphabet) { try { const decoded = decode(input, {version, alphabet}); - return sjcl.bn.fromBits(sjcl.codec.bytes.toBits(decoded)); + return new BN(decoded); } catch (e) { return NaN; } diff --git a/src/core/ledger.js b/src/core/ledger.js index a9e25c31..9c6e6a05 100644 --- a/src/core/ledger.js +++ b/src/core/ledger.js @@ -1,19 +1,18 @@ -/* eslint-disable valid-jsdoc */ 'use strict'; -var Transaction = require('./transaction').Transaction; -var SHAMap = require('./shamap').SHAMap; -var SHAMapTreeNode = require('./shamap').SHAMapTreeNode; -var SerializedObject = require('./serializedobject').SerializedObject; -var stypes = require('./serializedtypes'); -var UInt160 = require('./uint160').UInt160; -var Currency = require('./currency').Currency; +const Transaction = require('./transaction').Transaction; +const SHAMap = require('./shamap').SHAMap; +const SHAMapTreeNode = require('./shamap').SHAMapTreeNode; +const SerializedObject = require('./serializedobject').SerializedObject; +const stypes = require('./serializedtypes'); +const UInt160 = require('./uint160').UInt160; +const Currency = require('./currency').Currency; function Ledger() { this.ledger_json = {}; } Ledger.from_json = function(v) { - var ledger = new Ledger(); + const ledger = new Ledger(); ledger.parse_json(v); return ledger; }; @@ -23,14 +22,13 @@ Ledger.space = require('./ledgerspaces'); /** * Generate the key for an AccountRoot entry. * - * @param {String|UInt160} account Ripple Account + * @param {String|UInt160} accountArg - Ripple Account * @return {UInt256} */ Ledger.calcAccountRootEntryHash = -Ledger.prototype.calcAccountRootEntryHash = function(account) { - account = UInt160.from_json(account); - - var index = new SerializedObject(); +Ledger.prototype.calcAccountRootEntryHash = function(accountArg) { + const account = UInt160.from_json(accountArg); + const index = new SerializedObject(); index.append([0, Ledger.space.account.charCodeAt(0)]); index.append(account.to_bytes()); @@ -41,17 +39,15 @@ Ledger.prototype.calcAccountRootEntryHash = function(account) { /** * Generate the key for an Offer entry. * - * @param {String|UInt160} account Ripple Account - * @param {Number} sequence Sequence number of the OfferCreate transaction + * @param {String|UInt160} accountArg - Ripple Account + * @param {Number} sequence - Sequence number of the OfferCreate transaction * that instantiated this offer. * @return {UInt256} */ Ledger.calcOfferEntryHash = -Ledger.prototype.calcOfferEntryHash = function(account, sequence) { - account = UInt160.from_json(account); - sequence = parseInt(sequence, 10); - - var index = new SerializedObject(); +Ledger.prototype.calcOfferEntryHash = function(accountArg, sequence) { + const account = UInt160.from_json(accountArg); + const index = new SerializedObject(); index.append([0, Ledger.space.offer.charCodeAt(0)]); index.append(account.to_bytes()); @@ -65,17 +61,17 @@ Ledger.prototype.calcOfferEntryHash = function(account, sequence) { * * The ordering of the two account parameters does not matter. * - * @param {String|UInt160} account1 First Ripple Account - * @param {String|UInt160} account2 Second Ripple Account - * @param {String|Currency} currency The currency code + * @param {String|UInt160} _account1 - First Ripple Account + * @param {String|UInt160} _account2 - Second Ripple Account + * @param {String|Currency} _currency - The currency code * @return {UInt256} */ Ledger.calcRippleStateEntryHash = Ledger.prototype.calcRippleStateEntryHash = function( - account1, account2, currency) { - currency = Currency.from_json(currency); - account1 = UInt160.from_json(account1); - account2 = UInt160.from_json(account2); + _account1, _account2, _currency) { + const currency = Currency.from_json(_currency); + const account1 = UInt160.from_json(_account1); + const account2 = UInt160.from_json(_account2); if (!account1.is_valid()) { throw new Error('Invalid first account'); @@ -87,18 +83,14 @@ Ledger.prototype.calcRippleStateEntryHash = function( throw new Error('Invalid currency'); } - // The lower ID has to come first - if (account1.to_bn().greaterEquals(account2.to_bn())) { - var tmp = account2; - account2 = account1; - account1 = tmp; - } - - var index = new SerializedObject(); + const swap = account1.greater_than(account2); + const lowAccount = swap ? account2 : account1; + const highAccount = swap ? account1 : account2; + const index = new SerializedObject(); index.append([0, Ledger.space.rippleState.charCodeAt(0)]); - index.append(account1.to_bytes()); - index.append(account2.to_bytes()); + index.append(lowAccount.to_bytes()); + index.append(highAccount.to_bytes()); index.append(currency.to_bytes()); return index.hash(); @@ -109,13 +101,13 @@ Ledger.prototype.parse_json = function(v) { }; Ledger.prototype.calc_tx_hash = function() { - var tx_map = new SHAMap(); + const tx_map = new SHAMap(); this.ledger_json.transactions.forEach(function(tx_json) { - var tx = Transaction.from_json(tx_json); - var meta = SerializedObject.from_json(tx_json.metaData); + const tx = Transaction.from_json(tx_json); + const meta = SerializedObject.from_json(tx_json.metaData); - var data = new SerializedObject(); + const data = new SerializedObject(); stypes.VariableLength.serialize(data, tx.serialize().to_hex()); stypes.VariableLength.serialize(data, meta.to_hex()); tx_map.add_item(tx.hash(), data, SHAMapTreeNode.TYPE_TRANSACTION_MD); @@ -125,22 +117,23 @@ Ledger.prototype.calc_tx_hash = function() { }; /** -* @param options .sanity_test {Boolean} -* @return hash of shamap +* @param {Object} options - object * -* If `true`, will serialize each accountState item to binary and then back to -* json before finally serializing for hashing. This is mostly to expose any -* issues with ripple-lib's binary <--> json codecs. +* @param {Boolean} [options.sanity_test=false] - If `true`, will serialize each +* accountState item to binary and then back to json before finally +* serializing for hashing. This is mostly to expose any issues with +* ripple-lib's binary <--> json codecs. * +* @return {UInt256} - hash of shamap */ Ledger.prototype.calc_account_hash = function(options) { - var account_map = new SHAMap(); - var erred; + const account_map = new SHAMap(); + let erred; this.ledger_json.accountState.forEach(function(le) { - var data = SerializedObject.from_json(le); + let data = SerializedObject.from_json(le); - var json; + let json; if (options && options.sanity_test) { try { json = data.to_json(); diff --git a/src/core/seed.js b/src/core/seed.js index 33c00630..d6f01414 100644 --- a/src/core/seed.js +++ b/src/core/seed.js @@ -7,6 +7,7 @@ const {KeyPair, KeyType} = require('ripple-keypairs'); const codec = require('ripple-address-codec'); const extend = require('extend'); +const BN = require('bn.js'); const utils = require('./utils'); const sjcl = utils.sjcl; @@ -54,7 +55,7 @@ Seed.prototype.parse_base58 = function(j) { } else { try { const {bytes, type} = codec.decodeSeed(j); - this._value = sjcl.bn.fromBits(sjcl.codec.bytes.toBits(bytes)); + this._value = new BN(bytes); this._type = type; } catch (e) { this._value = NaN; diff --git a/src/core/serializedobject.js b/src/core/serializedobject.js index fb94b492..f68cd111 100644 --- a/src/core/serializedobject.js +++ b/src/core/serializedobject.js @@ -1,8 +1,8 @@ 'use strict'; -const _ = require('lodash'); const assert = require('assert'); const extend = require('extend'); +const BN = require('bn.js'); const binformat = require('./binformat'); const stypes = require('./serializedtypes'); const utils = require('./utils'); @@ -28,13 +28,9 @@ Object.keys(binformat.ter).forEach(function(key) { TRANSACTION_RESULTS[binformat.ter[key]] = key; }); -function normalize_sjcl_bn_hex(string) { - const hex = string.slice(2); // remove '0x' prefix - // now strip leading zeros - const i = _.findIndex(hex, function(c) { - return c !== '0'; - }); - return i >= 0 ? hex.slice(i) : '0'; +function fieldType(fieldName) { + const fieldDef = binformat.fieldsInverseMap[fieldName]; + return binformat.types[fieldDef[0]]; } function SerializedObject(buf) { @@ -231,12 +227,12 @@ SerializedObject.prototype.to_json = function() { return output; }; -SerializedObject.jsonify_structure = function(structure, field_name) { +SerializedObject.jsonify_structure = function(structure, fieldName) { let output; switch (typeof structure) { case 'number': - switch (field_name) { + switch (fieldName) { case 'LedgerEntryType': output = LEDGER_ENTRY_TYPES[structure]; break; @@ -257,11 +253,10 @@ SerializedObject.jsonify_structure = function(structure, field_name) { if (typeof structure.to_json === 'function') { output = structure.to_json(); - } else if (structure instanceof sjcl.bn) { - output = ('0000000000000000' + - normalize_sjcl_bn_hex(structure.toString()) - .toUpperCase() - ).slice(-16); + } else if (structure instanceof BN) { + // We assume that any BN is a UInt64 field + assert.equal(fieldType(fieldName), 'Int64'); + output = utils.arrayToHex(structure.toArray('bn', 8)); } else { // new Array or Object output = new structure.constructor(); diff --git a/src/core/serializedtypes.js b/src/core/serializedtypes.js index dd6f3f4e..ed01d0e8 100644 --- a/src/core/serializedtypes.js +++ b/src/core/serializedtypes.js @@ -10,13 +10,13 @@ const assert = require('assert'); const extend = require('extend'); +const BN = require('bn.js'); const GlobalBigNumber = require('bignumber.js'); const Amount = require('./amount').Amount; const Currency = require('./currency').Currency; const binformat = require('./binformat'); const utils = require('./utils'); const sjcl = utils.sjcl; -const SJCL_BN = sjcl.bn; const UInt128 = require('./uint128').UInt128; const UInt160 = require('./uint160').UInt160; @@ -44,8 +44,7 @@ function isHexInt64String(val) { return isString(val) && /^[0-9A-F]{0,16}$/i.test(val); } -function serializeBits(so, bits, noLength) { - const byteData = sjcl.codec.bytes.fromBits(bits); +function serializeBytes(so, byteData, noLength) { if (!noLength) { SerializedType.serialize_varint(so, byteData.length); } @@ -53,18 +52,7 @@ function serializeBits(so, bits, noLength) { } function serializeHex(so, hexData, noLength) { - serializeBits(so, sjcl.codec.hex.toBits(hexData), noLength); -} - -/** - * parses bytes as hex - * - * @param {Array} byte_array bytes - * @return {String} hex string - */ -function convertByteArrayToHex(byte_array) { - return sjcl.codec.hex.fromBits(sjcl.codec.bytes.toBits(byte_array)) - .toUpperCase(); + serializeBytes(so, utils.hexToArray(hexData), noLength); } function convertHexToString(hexString) { @@ -308,25 +296,27 @@ const STInt64 = exports.Int64 = new SerializedType({ if (value < 0) { throw new Error('Negative value for unsigned Int64 is invalid.'); } - bigNumObject = new SJCL_BN(value, 10); + bigNumObject = new BN(value, 10); } else if (isString(value)) { if (!isHexInt64String(value)) { throw new Error('Not a valid hex Int64.'); } - bigNumObject = new SJCL_BN(value, 16); - } else if (value instanceof SJCL_BN) { - if (!value.greaterEquals(0)) { + bigNumObject = new BN(value, 16); + } else if (value instanceof BN) { + if (value.cmpn(0) < 0) { throw new Error('Negative value for unsigned Int64 is invalid.'); } bigNumObject = value; } else { - throw new Error('Invalid type for Int64'); + throw new Error('Invalid type for Int64: ' + (typeof value) + ' value'); } - serializeBits(so, bigNumObject.toBits(64), true); // noLength = true + // `'be'` means big endian, and the following arg is the byte length, which + // it will pad with 0s to if not enough bytes, or throw if over + serializeBytes(so, bigNumObject.toArray('be', 8), /* noLength= */true); }, parse: function(so) { const bytes = so.read(8); - return SJCL_BN.fromBits(sjcl.codec.bytes.toBits(bytes)); + return new BN(bytes); } }); @@ -338,7 +328,7 @@ const STHash128 = exports.Hash128 = new SerializedType({ if (!hash.is_valid()) { throw new Error('Invalid Hash128'); } - serializeBits(so, hash.to_bits(), true); // noLength = true + serializeBytes(so, hash.to_bytes(), true); // noLength = true }, parse: function(so) { return UInt128.from_bytes(so.read(16)); @@ -353,7 +343,7 @@ const STHash256 = exports.Hash256 = new SerializedType({ if (!hash.is_valid()) { throw new Error('Invalid Hash256'); } - serializeBits(so, hash.to_bits(), true); // noLength = true + serializeBytes(so, hash.to_bytes(), true); // noLength = true }, parse: function(so) { return UInt256.from_bytes(so.read(32)); @@ -368,7 +358,7 @@ const STHash160 = exports.Hash160 = new SerializedType({ if (!hash.is_valid()) { throw new Error('Invalid Hash160'); } - serializeBits(so, hash.to_bits(), true); // noLength = true + serializeBytes(so, hash.to_bytes(), true); // noLength = true }, parse: function(so) { return UInt160.from_bytes(so.read(20)); @@ -582,7 +572,7 @@ const STVL = exports.VariableLength = exports.VL = new SerializedType({ }, parse: function(so) { const len = this.parse_varint(so); - return convertByteArrayToHex(so.read(len)); + return utils.arrayToHex(so.read(len)); } }); @@ -594,7 +584,7 @@ const STAccount = exports.Account = new SerializedType({ if (!account.is_valid()) { throw new Error('Invalid account!'); } - serializeBits(so, account.to_bits()); + serializeBytes(so, account.to_bytes()); }, parse: function(so) { const len = this.parse_varint(so); @@ -807,27 +797,27 @@ exports.STMemo = new SerializedType({ if (parsedType !== 'unformatted_memo') { output.parsed_memo_type = parsedType; } - /*eslint-disable no-empty*/ + /* eslint-disable no-empty */ } catch (e) { // empty // we don't know what's in the binary, apparently it's not a UTF-8 // string // this is fine, we won't add the parsed_memo_type field } - /*eslint-enable no-empty*/ + /* eslint-enable no-empty */ } if (output.MemoFormat !== undefined) { try { output.parsed_memo_format = convertHexToString(output.MemoFormat); - /*eslint-disable no-empty*/ + /* eslint-disable no-empty */ } catch (e) { // empty // we don't know what's in the binary, apparently it's not a UTF-8 // string // this is fine, we won't add the parsed_memo_format field } - /*eslint-enable no-empty*/ + /* eslint-enable no-empty */ } if (output.MemoData !== undefined) { @@ -842,7 +832,7 @@ exports.STMemo = new SerializedType({ // otherwise see if we can parse text output.parsed_memo_data = convertHexToString(output.MemoData); } - /*eslint-disable no-empty*/ + /* eslint-disable no-empty */ } catch(e) { // empty // we'll fail in case the content does not match what the MemoFormat @@ -850,7 +840,7 @@ exports.STMemo = new SerializedType({ // this is fine, we won't add the parsed_memo_data, the user has to // parse themselves } - /*eslint-enable no-empty*/ + /* eslint-enable no-empty */ } so.read(1); diff --git a/src/core/uint.js b/src/core/uint.js index 291c9954..ebddd5d6 100644 --- a/src/core/uint.js +++ b/src/core/uint.js @@ -1,10 +1,12 @@ 'use strict'; -/*eslint new-cap: 1*/ +/* eslint new-cap: 1 */ const assert = require('assert'); const lodash = require('lodash'); const utils = require('./utils'); +const BN = require('bn.js'); + const sjcl = utils.sjcl; // @@ -14,7 +16,7 @@ const sjcl = utils.sjcl; // function UInt() { - // Internal form: NaN or sjcl.bn + // Internal form: NaN or BN this._value = NaN; } @@ -108,16 +110,33 @@ UInt.prototype.copyTo = function(d) { return d; }; -UInt.prototype.equals = function(d) { - return this.is_valid() && d.is_valid() && this._value.equals(d._value); +UInt.prototype.equals = function(o) { + return this.is_valid() && + o.is_valid() && + // This throws but the expression will short circuit + this.cmp(o) === 0; +}; + +UInt.prototype.cmp = function(o) { + assert(this.is_valid() && o.is_valid()); + return this._value.cmp(o._value); +}; + +UInt.prototype.greater_than = function(o) { + return this.cmp(o) > 0; +}; + +UInt.prototype.less_than = function(o) { + return this.cmp(o) < 0; }; UInt.prototype.is_valid = function() { - return this._value instanceof sjcl.bn; + return this._value instanceof BN; }; UInt.prototype.is_zero = function() { - return this.is_valid() && this._value.equals(new sjcl.bn(0)); + // cmpn means cmp with N)umber + return this.is_valid() && this._value.cmpn(0) === 0; }; /** @@ -150,14 +169,14 @@ UInt.prototype.parse_generic = function(j) { case subclass.STR_ZERO: case subclass.ACCOUNT_ZERO: case subclass.HEX_ZERO: - this._value = new sjcl.bn(0); + this._value = new BN(0); break; case '1': case subclass.STR_ONE: case subclass.ACCOUNT_ONE: case subclass.HEX_ONE: - this._value = new sjcl.bn(1); + this._value = new BN(1); break; default: @@ -165,7 +184,7 @@ UInt.prototype.parse_generic = function(j) { switch (j.length) { case subclass.width: const hex = utils.arrayToHex(utils.stringToArray(j)); - this._value = new sjcl.bn(hex, 16); + this._value = new BN(hex, 16); break; case subclass.width * 2: // Assume hex, check char set @@ -187,7 +206,7 @@ UInt.prototype.parse_generic = function(j) { UInt.prototype.parse_hex = function(j) { if (new RegExp(`^[0-9A-Fa-f]{${this.constructor.width * 2}}$`).test(j)) { - this._value = new sjcl.bn(j, 16); + this._value = new BN(j, 16); } else { this._value = NaN; } @@ -199,9 +218,8 @@ UInt.prototype.parse_hex = function(j) { UInt.prototype.parse_bits = function(j) { if (sjcl.bitArray.bitLength(j) === this.constructor.width * 8) { - this._value = sjcl.bn.fromBits(j); - // let bytes = sjcl.codec.bytes.fromBits(j); - // this.parse_bytes(bytes); + const bytes = sjcl.codec.bytes.fromBits(j); + this.parse_bytes(bytes); } else { this._value = NaN; } @@ -211,11 +229,9 @@ UInt.prototype.parse_bits = function(j) { return this; }; - UInt.prototype.parse_bytes = function(j) { if (Array.isArray(j) && j.length === this.constructor.width) { - const bits = sjcl.codec.bytes.toBits(j); - this._value = sjcl.bn.fromBits(bits); + this._value = new BN(j); } else { this._value = NaN; } @@ -225,26 +241,13 @@ UInt.prototype.parse_bytes = function(j) { return this; }; - UInt.prototype.parse_json = UInt.prototype.parse_hex; -UInt.prototype.parse_bn = function(j) { - if ((j instanceof sjcl.bn) && j.bitLength() <= this.constructor.width * 8) { - this._value = new sjcl.bn(j); - } else { - this._value = NaN; - } - - this._update(); - - return this; -}; - UInt.prototype.parse_number = function(j) { this._value = NaN; if (typeof j === 'number' && isFinite(j) && j >= 0) { - this._value = new sjcl.bn(j); + this._value = new BN(j); } this._update(); @@ -258,7 +261,7 @@ UInt.prototype.to_bytes = function() { return null; } - return sjcl.codec.bytes.fromBits(this.to_bits()); + return this._value.toArray('be', this.constructor.width); }; UInt.prototype.to_hex = function() { @@ -266,27 +269,18 @@ UInt.prototype.to_hex = function() { return null; } - return sjcl.codec.hex.fromBits(this.to_bits()).toUpperCase(); + return utils.arrayToHex(this.to_bytes()); }; UInt.prototype.to_json = UInt.prototype.to_hex; +// Convert from internal form. UInt.prototype.to_bits = function() { if (!this.is_valid()) { return null; } - return this._value.toBits(this.constructor.width * 8); -}; - -UInt.prototype.to_bn = function() { - if (!this.is_valid()) { - return null; - } - - const bits = this.to_bits(); - - return sjcl.bn.fromBits(bits); + return sjcl.codec.bytes.toBits(this.to_bytes()); }; exports.UInt = UInt; diff --git a/src/core/utils.js b/src/core/utils.js index 6341a6c3..a9441a0b 100644 --- a/src/core/utils.js +++ b/src/core/utils.js @@ -77,7 +77,7 @@ function hexToArray(h) { function arrayToHex(a) { return a.map(function(byteValue) { - const hex = byteValue.toString(16); + const hex = byteValue.toString(16).toUpperCase(); return hex.length > 1 ? hex : '0' + hex; }).join(''); } diff --git a/test/base-test.js b/test/base-test.js index c5789622..43efb264 100644 --- a/test/base-test.js +++ b/test/base-test.js @@ -31,11 +31,11 @@ describe('Base', function() { describe('decode_check', function() { it('rrrrrrrrrrrrrrrrrrrrrhoLvTp', function() { const decoded = Base.decode_check(0, 'rrrrrrrrrrrrrrrrrrrrrhoLvTp'); - assert(decoded.equals(0)); + assert(decoded.cmpn(0) === 0); }); it('rrrrrrrrrrrrrrrrrrrrBZbvji', function() { const decoded = Base.decode_check(0, 'rrrrrrrrrrrrrrrrrrrrBZbvji'); - assert(decoded.equals(1)); + assert(decoded.cmpn(1) === 0); }); }); describe('decode-encode identity', function() { diff --git a/test/serializedtypes-test.js b/test/serializedtypes-test.js index 34a93d2f..ae1039bb 100644 --- a/test/serializedtypes-test.js +++ b/test/serializedtypes-test.js @@ -1,67 +1,67 @@ -/*eslint-disable max-len */ +/* eslint-disable max-len */ 'use strict'; -var assert = require('assert'); -var BigNumber = require('bignumber.js'); -var SerializedObject = require('ripple-lib').SerializedObject; -var types = require('ripple-lib').types; -var Amount = require('ripple-lib').Amount; -var sjcl = require('ripple-lib').sjcl; +const assert = require('assert'); +const BN = require('bn.js'); +const BigNumber = require('bignumber.js'); +const SerializedObject = require('ripple-lib').SerializedObject; +const types = require('ripple-lib').types; +const Amount = require('ripple-lib').Amount; describe('Serialized types', function() { describe('Int8', function() { it('Serialize 0', function() { - var so = new SerializedObject(); + const so = new SerializedObject(); types.Int8.serialize(so, 0); assert.strictEqual(so.to_hex(), '00'); }); it('Serialize 123', function() { - var so = new SerializedObject(); + const so = new SerializedObject(); types.Int8.serialize(so, 123); assert.strictEqual(so.to_hex(), '7B'); }); it('Serialize 255', function() { - var so = new SerializedObject(); + const so = new SerializedObject(); types.Int8.serialize(so, 255); assert.strictEqual(so.to_hex(), 'FF'); }); it('Fail to serialize 256', function() { - var so = new SerializedObject(); + const so = new SerializedObject(); assert.throws(function() { types.Int8.serialize(so, 256); }); }); it('Fail to serialize -1', function() { - var so = new SerializedObject(); + const so = new SerializedObject(); assert.throws(function() { types.Int8.serialize(so, -1); }); }); it('Serialize 5.5 (should floor)', function() { - var so = new SerializedObject(); + const so = new SerializedObject(); types.Int8.serialize(so, 5.5); assert.strictEqual(so.to_hex(), '05'); }); it('Serialize 255.9 (should floor)', function() { - var so = new SerializedObject(); + const so = new SerializedObject(); types.Int8.serialize(so, 255.9); assert.strictEqual(so.to_hex(), 'FF'); }); it('Fail to serialize null', function() { - var so = new SerializedObject(); + const so = new SerializedObject(); assert.throws(function() { types.Int8.serialize(so, null); }); }); it('Fail to serialize "bla"', function() { - var so = new SerializedObject(); + const so = new SerializedObject(); assert.throws(function() { types.Int8.serialize(so, 'bla'); }); }); it('Fail to serialize {}', function() { - var so = new SerializedObject(); + const so = new SerializedObject(); assert.throws(function() { types.Int8.serialize(so, {}); }); @@ -70,66 +70,66 @@ describe('Serialized types', function() { describe('Int16', function() { it('Serialize 0', function() { - var so = new SerializedObject(); + const so = new SerializedObject(); types.Int16.serialize(so, 0); assert.strictEqual(so.to_hex(), '0000'); }); it('Serialize 123', function() { - var so = new SerializedObject(); + const so = new SerializedObject(); types.Int16.serialize(so, 123); assert.strictEqual(so.to_hex(), '007B'); }); it('Serialize 255', function() { - var so = new SerializedObject(); + const so = new SerializedObject(); types.Int16.serialize(so, 255); assert.strictEqual(so.to_hex(), '00FF'); }); it('Serialize 256', function() { - var so = new SerializedObject(); + const so = new SerializedObject(); types.Int16.serialize(so, 256); assert.strictEqual(so.to_hex(), '0100'); }); it('Serialize 65535', function() { - var so = new SerializedObject(); + const so = new SerializedObject(); types.Int16.serialize(so, 65535); assert.strictEqual(so.to_hex(), 'FFFF'); }); it('Fail to serialize 65536', function() { - var so = new SerializedObject(); + const so = new SerializedObject(); assert.throws(function() { types.Int8.serialize(so, 65536); }); }); it('Fail to serialize -1', function() { - var so = new SerializedObject(); + const so = new SerializedObject(); assert.throws(function() { types.Int16.serialize(so, -1); }); }); it('Serialize 123.5 (should floor)', function() { - var so = new SerializedObject(); + const so = new SerializedObject(); types.Int16.serialize(so, 123.5); assert.strictEqual(so.to_hex(), '007B'); }); it('Serialize 65535.5 (should floor)', function() { - var so = new SerializedObject(); + const so = new SerializedObject(); types.Int16.serialize(so, 65535.5); assert.strictEqual(so.to_hex(), 'FFFF'); }); it('Fail to serialize null', function() { - var so = new SerializedObject(); + const so = new SerializedObject(); assert.throws(function() { types.Int16.serialize(so, null); }); }); it('Fail to serialize "bla"', function() { - var so = new SerializedObject(); + const so = new SerializedObject(); assert.throws(function() { types.Int16.serialize(so, 'bla'); }); }); it('Fail to serialize {}', function() { - var so = new SerializedObject(); + const so = new SerializedObject(); assert.throws(function() { types.Int16.serialize(so, {}); }); @@ -138,363 +138,362 @@ describe('Serialized types', function() { describe('Int32', function() { it('Serialize 0', function() { - var so = new SerializedObject(); + const so = new SerializedObject(); types.Int32.serialize(so, 0); assert.strictEqual(so.to_hex(), '00000000'); }); it('Serialize 123', function() { - var so = new SerializedObject(); + const so = new SerializedObject(); types.Int32.serialize(so, 123); assert.strictEqual(so.to_hex(), '0000007B'); }); it('Serialize 255', function() { - var so = new SerializedObject(); + const so = new SerializedObject(); types.Int32.serialize(so, 255); assert.strictEqual(so.to_hex(), '000000FF'); }); it('Serialize 256', function() { - var so = new SerializedObject(); + const so = new SerializedObject(); types.Int32.serialize(so, 256); assert.strictEqual(so.to_hex(), '00000100'); }); it('Serialize 0xF0F0F0F0', function() { - var so = new SerializedObject(); + const so = new SerializedObject(); types.Int32.serialize(so, 0xF0F0F0F0); assert.strictEqual(so.to_hex(), 'F0F0F0F0'); }); it('Serialize 0xFFFFFFFF', function() { - var so = new SerializedObject(); + const so = new SerializedObject(); types.Int32.serialize(so, 0xFFFFFFFF); assert.strictEqual(so.to_hex(), 'FFFFFFFF'); }); it('Fail to serialize 0x100000000', function() { - var so = new SerializedObject(); + const so = new SerializedObject(); assert.throws(function() { types.Int8.serialize(so, 0x100000000); }); }); it('Fail to serialize -1', function() { - var so = new SerializedObject(); + const so = new SerializedObject(); assert.throws(function() { types.Int32.serialize(so, -1); }); }); it('Serialize 123.5 (should floor)', function() { - var so = new SerializedObject(); + const so = new SerializedObject(); types.Int32.serialize(so, 123.5); assert.strictEqual(so.to_hex(), '0000007B'); }); it('Serialize 4294967295.5 (should floor)', function() { - var so = new SerializedObject(); + const so = new SerializedObject(); types.Int32.serialize(so, 4294967295.5); assert.strictEqual(so.to_hex(), 'FFFFFFFF'); }); it('Fail to serialize null', function() { - var so = new SerializedObject(); + const so = new SerializedObject(); assert.throws(function() { types.Int32.serialize(so, null); }); }); it('Fail to serialize "bla"', function() { - var so = new SerializedObject(); + const so = new SerializedObject(); assert.throws(function() { types.Int32.serialize(so, 'bla'); }); }); it('Fail to serialize {}', function() { - var so = new SerializedObject(); + const so = new SerializedObject(); assert.throws(function() { types.Int32.serialize(so, {}); }); }); it('Parse 0', function() { - var val = '00000000'; - var so = new SerializedObject(val); - var num = types.Int32.parse(so); + const val = '00000000'; + const so = new SerializedObject(val); + const num = types.Int32.parse(so); assert.strictEqual(num, parseInt(val, 16)); }); it('Parse 1', function() { - var val = '00000001'; - var so = new SerializedObject(val); - var num = types.Int32.parse(so); + const val = '00000001'; + const so = new SerializedObject(val); + const num = types.Int32.parse(so); assert.strictEqual(num, parseInt(val, 16)); }); it('Parse UINT32_MAX', function() { - var val = 'FFFFFFFF'; - var so = new SerializedObject(val); - var num = types.Int32.parse(so); + const val = 'FFFFFFFF'; + const so = new SerializedObject(val); + const num = types.Int32.parse(so); assert.strictEqual(num, parseInt(val, 16)); }); }); describe('Int64', function() { it('Serialize 0', function() { - var so = new SerializedObject(); + const so = new SerializedObject(); types.Int64.serialize(so, 0); assert.strictEqual(so.to_hex(), '0000000000000000'); }); it('Serialize 123', function() { - var so = new SerializedObject(); + const so = new SerializedObject(); types.Int64.serialize(so, 123); assert.strictEqual(so.to_hex(), '000000000000007B'); }); it('Serialize 255', function() { - var so = new SerializedObject(); + const so = new SerializedObject(); types.Int64.serialize(so, 255); assert.strictEqual(so.to_hex(), '00000000000000FF'); }); it('Serialize 256', function() { - var so = new SerializedObject(); + const so = new SerializedObject(); types.Int64.serialize(so, 256); assert.strictEqual(so.to_hex(), '0000000000000100'); }); it('Serialize 0xF0F0F0F0', function() { - var so = new SerializedObject(); + const so = new SerializedObject(); types.Int64.serialize(so, 0xF0F0F0F0); assert.strictEqual(so.to_hex(), '00000000F0F0F0F0'); }); it('Serialize 0xFFFFFFFF', function() { - var so = new SerializedObject(); + const so = new SerializedObject(); types.Int64.serialize(so, 0xFFFFFFFF); assert.strictEqual(so.to_hex(), '00000000FFFFFFFF'); }); it('Serialize 0x100000000', function() { - var so = new SerializedObject(); + const so = new SerializedObject(); types.Int64.serialize(so, 0x100000000); assert.strictEqual(so.to_hex(), '0000000100000000'); }); it('Fail to serialize 0x100000000', function() { - var so = new SerializedObject(); + const so = new SerializedObject(); assert.throws(function() { types.Int8.serialize(so, 0x100000000); }); }); it('Fail to serialize -1', function() { - var so = new SerializedObject(); + const so = new SerializedObject(); assert.throws(function() { types.Int64.serialize(so, -1); }); }); it('Serialize 123.5 (should floor)', function() { - var so = new SerializedObject(); + const so = new SerializedObject(); types.Int64.serialize(so, 123.5); assert.strictEqual(so.to_hex(), '000000000000007B'); }); it('Serialize 4294967295.5 (should floor)', function() { - var so = new SerializedObject(); + const so = new SerializedObject(); types.Int64.serialize(so, 4294967295.5); assert.strictEqual(so.to_hex(), '00000000FFFFFFFF'); }); it('Does not get confused when the high bit is set', function() { - var so = new SerializedObject(); + const so = new SerializedObject(); types.Int64.serialize(so, '8B2386F26F8E232B'); assert.strictEqual(so.to_hex(), '8B2386F26F8E232B'); - so = new SerializedObject('8B2386F26F8E232B'); - var num = types.Int64.parse(so); + const so2 = new SerializedObject('8B2386F26F8E232B'); + const num = types.Int64.parse(so2); // We get a positive number - assert.strictEqual(num.toString(), '0x8b2386f26f8e232b'); + assert.strictEqual(num.toString(16), '8b2386f26f8e232b'); }); it('Serialize "0123456789ABCDEF"', function() { - var so = new SerializedObject(); + const so = new SerializedObject(); types.Int64.serialize(so, '0123456789ABCDEF'); assert.strictEqual(so.to_hex(), '0123456789ABCDEF'); }); it('Serialize "F0E1D2C3B4A59687"', function() { - var so = new SerializedObject(); + const so = new SerializedObject(); types.Int64.serialize(so, 'F0E1D2C3B4A59687'); assert.strictEqual(so.to_hex(), 'F0E1D2C3B4A59687'); }); it('Serialize bn("FFEEDDCCBBAA9988")', function() { - var so = new SerializedObject(); - var BN = sjcl.bn; + const so = new SerializedObject(); types.Int64.serialize(so, new BN('FFEEDDCCBBAA9988', 16)); assert.strictEqual(so.to_hex(), 'FFEEDDCCBBAA9988'); }); it('Fail to serialize BigNumber("-1")', function() { - var so = new SerializedObject(); + const so = new SerializedObject(); assert.throws(function() { types.Int64.serialize(so, new BigNumber('-1', 10)); }); }); it('Fail to serialize "10000000000000000"', function() { - var so = new SerializedObject(); + const so = new SerializedObject(); assert.throws(function() { types.Int64.serialize(so, '10000000000000000'); }); }); it('Fail to serialize "110000000000000000"', function() { - var so = new SerializedObject(); + const so = new SerializedObject(); assert.throws(function() { types.Int64.serialize(so, '110000000000000000'); }); }); it('Fail to serialize null', function() { - var so = new SerializedObject(); + const so = new SerializedObject(); assert.throws(function() { types.Int64.serialize(so, null); }); }); it('Fail to serialize "bla"', function() { - var so = new SerializedObject(); + const so = new SerializedObject(); assert.throws(function() { types.Int64.serialize(so, 'bla'); }); }); it('Fail to serialize {}', function() { - var so = new SerializedObject(); + const so = new SerializedObject(); assert.throws(function() { types.Int64.serialize(so, {}); }); }); it('Parse "0123456789ABCDEF"', function() { - var so = new SerializedObject('0123456789ABCDEF'); - var num = types.Int64.parse(so); - assert.strictEqual(num.toString(), '0x123456789abcdef'); + const so = new SerializedObject('0123456789ABCDEF'); + const num = types.Int64.parse(so); + assert.strictEqual(num.toString(16), '123456789abcdef'); }); }); describe('Hash128', function() { it('Serialize 0', function() { - var so = new SerializedObject(); + const so = new SerializedObject(); types.Hash128.serialize(so, '00000000000000000000000000000000'); assert.strictEqual(so.to_hex(), '00000000000000000000000000000000'); }); it('Serialize 102030405060708090A0B0C0D0E0F000', function() { - var so = new SerializedObject(); + const so = new SerializedObject(); types.Hash128.serialize(so, '102030405060708090A0B0C0D0E0F000'); assert.strictEqual(so.to_hex(), '102030405060708090A0B0C0D0E0F000'); }); it('Serialize HASH128_MAX', function() { - var so = new SerializedObject(); + const so = new SerializedObject(); types.Hash128.serialize(so, 'FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF'); assert.strictEqual(so.to_hex(), 'FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF'); }); it('Parse 0', function() { - var val = '00000000000000000000000000000000'; - var so = new SerializedObject(val); - var num = types.Hash128.parse(so); + const val = '00000000000000000000000000000000'; + const so = new SerializedObject(val); + const num = types.Hash128.parse(so); assert.strictEqual(num.to_hex(), val); }); it('Parse 1', function() { - var val = '00000000000000000000000000000001'; - var so = new SerializedObject(val); - var num = types.Hash128.parse(so); + const val = '00000000000000000000000000000001'; + const so = new SerializedObject(val); + const num = types.Hash128.parse(so); assert.strictEqual(num.to_hex(), val); }); it('Parse HASH128_MAX', function() { - var val = 'FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF'; - var so = new SerializedObject(val); - var num = types.Hash128.parse(so); + const val = 'FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF'; + const so = new SerializedObject(val); + const num = types.Hash128.parse(so); assert.strictEqual(num.to_hex(), val); }); }); describe('Hash160', function() { it('Serialize 0', function() { - var hex = '0000000000000000000000000000000000000000'; - var base58 = 'rrrrrrrrrrrrrrrrrrrrrhoLvTp'; - var so = new SerializedObject(); + const hex = '0000000000000000000000000000000000000000'; + const base58 = 'rrrrrrrrrrrrrrrrrrrrrhoLvTp'; + const so = new SerializedObject(); types.Hash160.serialize(so, base58); assert.strictEqual(so.to_hex(), hex); - so = new SerializedObject(); - types.Hash160.serialize(so, hex); - assert.strictEqual(so.to_hex(), hex); + const so2 = new SerializedObject(); + types.Hash160.serialize(so2, hex); + assert.strictEqual(so2.to_hex(), hex); }); it('Serialize 1', function() { - var hex = '0000000000000000000000000000000000000001'; - var base58 = 'rrrrrrrrrrrrrrrrrrrrBZbvji'; - var so = new SerializedObject(); + const hex = '0000000000000000000000000000000000000001'; + const base58 = 'rrrrrrrrrrrrrrrrrrrrBZbvji'; + const so = new SerializedObject(); types.Hash160.serialize(so, base58); assert.strictEqual(so.to_hex(), hex); - so = new SerializedObject(); - types.Hash160.serialize(so, hex); - assert.strictEqual(so.to_hex(), hex); + const so2 = new SerializedObject(); + types.Hash160.serialize(so2, hex); + assert.strictEqual(so2.to_hex(), hex); }); it('Serialize FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF', function() { - var hex = 'FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF'; - var base58 = 'rQLbzfJH5BT1FS9apRLKV3G8dWEA5njaQi'; - var so = new SerializedObject(); + const hex = 'FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF'; + const base58 = 'rQLbzfJH5BT1FS9apRLKV3G8dWEA5njaQi'; + const so = new SerializedObject(); types.Hash160.serialize(so, base58); assert.strictEqual(so.to_hex(), hex); - so = new SerializedObject(); - types.Hash160.serialize(so, hex); - assert.strictEqual(so.to_hex(), hex); + const so2 = new SerializedObject(); + types.Hash160.serialize(so2, hex); + assert.strictEqual(so2.to_hex(), hex); }); it('Parse 0', function() { - var val = '0000000000000000000000000000000000000000'; - var so = new SerializedObject(val); - var num = types.Hash160.parse(so); + const val = '0000000000000000000000000000000000000000'; + const so = new SerializedObject(val); + const num = types.Hash160.parse(so); assert.strictEqual(num.to_hex(), val); }); it('Parse 1', function() { - var val = '0000000000000000000000000000000000000001'; - var so = new SerializedObject(val); - var num = types.Hash160.parse(so); + const val = '0000000000000000000000000000000000000001'; + const so = new SerializedObject(val); + const num = types.Hash160.parse(so); assert.strictEqual(num.to_hex(), val); }); it('Parse HASH160_MAX', function() { - var val = 'FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF'; - var so = new SerializedObject(val); - var num = types.Hash160.parse(so); + const val = 'FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF'; + const so = new SerializedObject(val); + const num = types.Hash160.parse(so); assert.strictEqual(num.to_hex(), val); }); it('Parse 0 as JSON', function() { // Hash160 should be returned as hex in JSON, unlike // addresses. - var val = '0000000000000000000000000000000000000000'; - var so = new SerializedObject(val); - var num = types.Hash160.parse(so); + const val = '0000000000000000000000000000000000000000'; + const so = new SerializedObject(val); + const num = types.Hash160.parse(so); assert.strictEqual(num.to_json(), val); }); }); describe('Hash256', function() { it('Serialize 0', function() { - var so = new SerializedObject(); + const so = new SerializedObject(); types.Hash256.serialize(so, '0000000000000000000000000000000000000000000000000000000000000000'); assert.strictEqual(so.to_hex(), '0000000000000000000000000000000000000000000000000000000000000000'); }); it('Serialize 1', function() { - var so = new SerializedObject(); + const so = new SerializedObject(); types.Hash256.serialize(so, '0000000000000000000000000000000000000000000000000000000000000001'); assert.strictEqual(so.to_hex(), '0000000000000000000000000000000000000000000000000000000000000001'); }); it('Serialize HASH256_MAX', function() { - var so = new SerializedObject(); + const so = new SerializedObject(); types.Hash256.serialize(so, 'FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF'); assert.strictEqual(so.to_hex(), 'FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF'); }); it('Parse 0', function() { - var val = '0000000000000000000000000000000000000000000000000000000000000000'; - var so = new SerializedObject(val); - var num = types.Hash256.parse(so); + const val = '0000000000000000000000000000000000000000000000000000000000000000'; + const so = new SerializedObject(val); + const num = types.Hash256.parse(so); assert.strictEqual(num.to_hex(), val); }); it('Parse 1', function() { - var val = '0000000000000000000000000000000000000000000000000000000000000000'; - var so = new SerializedObject(val); - var num = types.Hash256.parse(so); + const val = '0000000000000000000000000000000000000000000000000000000000000000'; + const so = new SerializedObject(val); + const num = types.Hash256.parse(so); assert.strictEqual(num.to_hex(), val); }); it('Parse HASH256_MAX', function() { - var val = 'FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF'; - var so = new SerializedObject(val); - var num = types.Hash256.parse(so); + const val = 'FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF'; + const so = new SerializedObject(val); + const num = types.Hash256.parse(so); assert.strictEqual(num.to_hex(), val); }); }); describe('Quality', function() { it('Serialize 1/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh', function() { - var so = new SerializedObject(); + const so = new SerializedObject(); types.Quality.serialize(so, '1/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh'); assert.strictEqual(so.to_hex(), '55038D7EA4C68000'); }); it('Serialize 87654321.12345678/EUR/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh', function() { - var so = new SerializedObject(); + const so = new SerializedObject(); types.Quality.serialize(so, '87654321.12345678/EUR/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh'); assert.strictEqual(so.to_hex(), '5C1F241D335BF24E'); }); @@ -502,56 +501,56 @@ describe('Serialized types', function() { describe('Amount', function() { it('Serialize 0 XRP', function() { - var so = new SerializedObject(); + const so = new SerializedObject(); types.Amount.serialize(so, '0'); assert.strictEqual(so.to_hex(), '4000000000000000'); }); it('Serialize 1 XRP', function() { - var so = new SerializedObject(); + const so = new SerializedObject(); types.Amount.serialize(so, '1'); assert.strictEqual(so.to_hex(), '4000000000000001'); }); it('Serialize -1 XRP', function() { - var so = new SerializedObject(); + const so = new SerializedObject(); types.Amount.serialize(so, '-1'); assert.strictEqual(so.to_hex(), '0000000000000001'); }); it('Serialize 213 XRP', function() { - var so = new SerializedObject(); + const so = new SerializedObject(); types.Amount.serialize(so, '213'); assert.strictEqual(so.to_hex(), '40000000000000D5'); }); it('Serialize 270544960 XRP', function() { - var so = new SerializedObject(); + const so = new SerializedObject(); types.Amount.serialize(so, '270544960'); assert.strictEqual(so.to_hex(), '4000000010203040'); }); it('Serialize 1161981756646125568 XRP', function() { - var so = new SerializedObject(); + const so = new SerializedObject(); assert.throws(function() { - var amt = Amount.from_json('1161981756646125696'); + const amt = Amount.from_json('1161981756646125696'); types.Amount.serialize(so, amt); }); }); it('Serialize 1/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh', function() { - var so = new SerializedObject(); + const so = new SerializedObject(); types.Amount.serialize(so, '1/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh'); assert.strictEqual(so.to_hex(), 'D4838D7EA4C680000000000000000000000000005553440000000000B5F762798A53D543A014CAF8B297CFF8F2F937E8'); }); it('Serialize 87654321.12345678/EUR/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh', function() { - var so = new SerializedObject(); + const so = new SerializedObject(); types.Amount.serialize(so, '87654321.12345678/EUR/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh'); assert.strictEqual(so.to_hex(), 'D65F241D335BF24E0000000000000000000000004555520000000000B5F762798A53D543A014CAF8B297CFF8F2F937E8'); }); it('Serialize -1/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh', function() { - var so = new SerializedObject(); + const so = new SerializedObject(); types.Amount.serialize(so, '-1/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh'); assert.strictEqual(so.to_hex(), '94838D7EA4C680000000000000000000000000005553440000000000B5F762798A53D543A014CAF8B297CFF8F2F937E8'); }); it('Serialize 15/XRP/rM1oqKtfh1zgjdAgbFmaRm3btfGBX25xVo', function() { // This actually appears in the ledger, so we need to be able to serialize // Transaction #A2AD66C93C7B7277CD5AEB718A4E82D88C7099129948BC66A394EE38B34657A9 - var so = new SerializedObject(); + const so = new SerializedObject(); types.Amount.serialize(so, { value: '1000', currency: 'XRP', @@ -561,7 +560,7 @@ describe('Serialized types', function() { }); // Test support for 20-byte hex raw currency codes it('Serialize 15/015841551A748AD23FEFFFFFFFEA028000000000/1', function() { - var so = new SerializedObject(); + const so = new SerializedObject(); types.Amount.serialize(so, { value: '1000', currency: '015841551A748AD23FEFFFFFFFEA028000000000', @@ -570,113 +569,113 @@ describe('Serialized types', function() { assert.strictEqual(so.to_hex(), 'D5438D7EA4C68000015841551A748AD23FEFFFFFFFEA028000000000E4FE687C90257D3D2D694C8531CDEECBE84F3367'); }); it('Serialize max_value/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh', function() { - var so = new SerializedObject(); + const so = new SerializedObject(); types.Amount.serialize(so, Amount.max_value + '/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh'); assert.strictEqual(so.to_hex(), 'EC6386F26FC0FFFF0000000000000000000000005553440000000000B5F762798A53D543A014CAF8B297CFF8F2F937E8'); }); it('Parse 1 XRP', function() { - var so = new SerializedObject('4000000000000001'); + const so = new SerializedObject('4000000000000001'); assert.strictEqual(types.Amount.parse(so).to_json(), '1'); }); it('Parse -1 XRP', function() { - var so = new SerializedObject('0000000000000001'); + const so = new SerializedObject('0000000000000001'); assert.strictEqual(types.Amount.parse(so).to_json(), '-1'); }); it('Parse 213 XRP', function() { - var so = new SerializedObject('40000000000000D5'); + const so = new SerializedObject('40000000000000D5'); assert.strictEqual(types.Amount.parse(so).to_json(), '213'); }); it('Parse 270544960 XRP', function() { - var so = new SerializedObject('4000000010203040'); + const so = new SerializedObject('4000000010203040'); assert.strictEqual(types.Amount.parse(so).to_json(), '270544960'); }); it('Parse 1161981756646125568 XRP', function() { assert.throws(function() { // hex(1161981756646125568) = 1020304050607000 - var so = new SerializedObject('1020304050607000'); + const so = new SerializedObject('1020304050607000'); types.Amount.parse(so).to_json(); }); }); it('Parse 1/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh', function() { - var so = new SerializedObject('D4838D7EA4C680000000000000000000000000005553440000000000B5F762798A53D543A014CAF8B297CFF8F2F937E8'); + const so = new SerializedObject('D4838D7EA4C680000000000000000000000000005553440000000000B5F762798A53D543A014CAF8B297CFF8F2F937E8'); assert.strictEqual(types.Amount.parse(so).to_text_full(), '1/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh'); }); it('Parse 87654321.12345678/EUR/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh', function() { - var so = new SerializedObject('D65F241D335BF24E0000000000000000000000004555520000000000B5F762798A53D543A014CAF8B297CFF8F2F937E8'); + const so = new SerializedObject('D65F241D335BF24E0000000000000000000000004555520000000000B5F762798A53D543A014CAF8B297CFF8F2F937E8'); assert.strictEqual(types.Amount.parse(so).to_text_full(), '87654321.12345678/EUR/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh'); }); it('Parse -1/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh', function() { - var so = new SerializedObject('94838D7EA4C680000000000000000000000000005553440000000000B5F762798A53D543A014CAF8B297CFF8F2F937E8'); + const so = new SerializedObject('94838D7EA4C680000000000000000000000000005553440000000000B5F762798A53D543A014CAF8B297CFF8F2F937E8'); assert.strictEqual(types.Amount.parse(so).to_text_full(), '-1/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh'); }); it('Parse max_value/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh', function() { - var so = new SerializedObject('EC6386F26FC0FFFF0000000000000000000000005553440000000000B5F762798A53D543A014CAF8B297CFF8F2F937E8'); + const so = new SerializedObject('EC6386F26FC0FFFF0000000000000000000000005553440000000000B5F762798A53D543A014CAF8B297CFF8F2F937E8'); assert.strictEqual(types.Amount.parse(so).to_text_full(), Amount.max_value + '/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh'); }); }); describe('Account', function() { it('Serialize 0', function() { - var hex = '0000000000000000000000000000000000000000'; - var base58 = 'rrrrrrrrrrrrrrrrrrrrrhoLvTp'; - var so = new SerializedObject(); + const hex = '0000000000000000000000000000000000000000'; + const base58 = 'rrrrrrrrrrrrrrrrrrrrrhoLvTp'; + const so = new SerializedObject(); types.Account.serialize(so, base58); assert.strictEqual(so.to_hex(), '14' + hex); - so = new SerializedObject(); - types.Account.serialize(so, hex); - assert.strictEqual(so.to_hex(), '14' + hex); + const so2 = new SerializedObject(); + types.Account.serialize(so2, hex); + assert.strictEqual(so2.to_hex(), '14' + hex); }); it('Serialize 1', function() { - var hex = '0000000000000000000000000000000000000001'; - var base58 = 'rrrrrrrrrrrrrrrrrrrrBZbvji'; - var so = new SerializedObject(); + const hex = '0000000000000000000000000000000000000001'; + const base58 = 'rrrrrrrrrrrrrrrrrrrrBZbvji'; + const so = new SerializedObject(); types.Account.serialize(so, base58); assert.strictEqual(so.to_hex(), '14' + hex); - so = new SerializedObject(); - types.Account.serialize(so, hex); - assert.strictEqual(so.to_hex(), '14' + hex); + const so2 = new SerializedObject(); + types.Account.serialize(so2, hex); + assert.strictEqual(so2.to_hex(), '14' + hex); }); it('Serialize FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF', function() { - var hex = 'FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF'; - var base58 = 'rQLbzfJH5BT1FS9apRLKV3G8dWEA5njaQi'; - var so = new SerializedObject(); + const hex = 'FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF'; + const base58 = 'rQLbzfJH5BT1FS9apRLKV3G8dWEA5njaQi'; + const so = new SerializedObject(); types.Account.serialize(so, base58); assert.strictEqual(so.to_hex(), '14' + hex); - so = new SerializedObject(); - types.Account.serialize(so, hex); - assert.strictEqual(so.to_hex(), '14' + hex); + const so2 = new SerializedObject(); + types.Account.serialize(so2, hex); + assert.strictEqual(so2.to_hex(), '14' + hex); }); it('Parse 0', function() { - var val = '140000000000000000000000000000000000000000'; - var so = new SerializedObject(val); - var num = types.Account.parse(so); + const val = '140000000000000000000000000000000000000000'; + const so = new SerializedObject(val); + const num = types.Account.parse(so); assert.strictEqual(num.to_json(), 'rrrrrrrrrrrrrrrrrrrrrhoLvTp'); }); it('Parse 1', function() { - var val = '140000000000000000000000000000000000000001'; - var so = new SerializedObject(val); - var num = types.Account.parse(so); + const val = '140000000000000000000000000000000000000001'; + const so = new SerializedObject(val); + const num = types.Account.parse(so); assert.strictEqual(num.to_json(), 'rrrrrrrrrrrrrrrrrrrrBZbvji'); }); it('Parse HASH160_MAX', function() { - var val = '14FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF'; - var so = new SerializedObject(val); - var num = types.Account.parse(so); + const val = '14FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF'; + const so = new SerializedObject(val); + const num = types.Account.parse(so); assert.strictEqual(num.to_json(), 'rQLbzfJH5BT1FS9apRLKV3G8dWEA5njaQi'); }); }); describe('PathSet', function() { it('Serialize single empty path [[]]', function() { - var so = new SerializedObject(); + const so = new SerializedObject(); types.PathSet.serialize(so, [[]]); assert.strictEqual(so.to_hex(), '00'); }); it('Serialize [[e],[e,e]]', function() { - var so = new SerializedObject(); + const so = new SerializedObject(); types.PathSet.serialize(so, [[{ account: 123, currency: 'USD', @@ -695,8 +694,8 @@ describe('Serialized types', function() { assert.strictEqual(so.to_hex(), '31000000000000000000000000000000000000007B00000000000000000000000055534400000000000000000000000000000000000000000000000315FF31000000000000000000000000000000000000007B000000000000000000000000425443000000000000000000000000000000000000000000000003153100000000000000000000000000000000000003DB0000000000000000000000004555520000000000000000000000000000000000000000000000014100'); // TODO: Check this independently }); it('Serialize path through XRP', function() { - var hex = '31000000000000000000000000000000000000007B00000000000000000000000055534400000000000000000000000000000000000000000000000315FF1000000000000000000000000000000000000000003100000000000000000000000000000000000003DB0000000000000000000000004555520000000000000000000000000000000000000000000000014100'; - var json = [ + const hex = '31000000000000000000000000000000000000007B00000000000000000000000055534400000000000000000000000000000000000000000000000315FF1000000000000000000000000000000000000000003100000000000000000000000000000000000003DB0000000000000000000000004555520000000000000000000000000000000000000000000000014100'; + const json = [ [{ account: 'rrrrrrrrrrrrrrrrrrrrNxV3Xza', currency: 'USD', @@ -711,7 +710,7 @@ describe('Serialized types', function() { }] ]; - var result_json = [ + const result_json = [ [{ account: 'rrrrrrrrrrrrrrrrrrrrNxV3Xza', currency: 'USD', @@ -732,17 +731,17 @@ describe('Serialized types', function() { }] ]; - var so = new SerializedObject(); + const so = new SerializedObject(); types.PathSet.serialize(so, json); assert.strictEqual(so.to_hex(), hex); - so = new SerializedObject(hex); - var parsed_path = SerializedObject.jsonify_structure(types.PathSet.parse(so)); + const so2 = new SerializedObject(hex); + const parsed_path = SerializedObject.jsonify_structure(types.PathSet.parse(so2)); assert.deepEqual(parsed_path, result_json); }); it('Serialize path through XRP IOUs', function() { - var hex = '31000000000000000000000000000000000000007B00000000000000000000000055534400000000000000000000000000000000000000000000000315FF1000000000000000000000000058525000000000003100000000000000000000000000000000000003DB0000000000000000000000004555520000000000000000000000000000000000000000000000014100'; - var json = [ + const hex = '31000000000000000000000000000000000000007B00000000000000000000000055534400000000000000000000000000000000000000000000000315FF1000000000000000000000000058525000000000003100000000000000000000000000000000000003DB0000000000000000000000004555520000000000000000000000000000000000000000000000014100'; + const json = [ [{ account: 'rrrrrrrrrrrrrrrrrrrrNxV3Xza', currency: 'USD', @@ -758,7 +757,7 @@ describe('Serialized types', function() { }] ]; - var result_json = [ + const result_json = [ [{ account: 'rrrrrrrrrrrrrrrrrrrrNxV3Xza', currency: 'USD', @@ -780,12 +779,12 @@ describe('Serialized types', function() { }] ]; - var so = new SerializedObject(); + const so = new SerializedObject(); types.PathSet.serialize(so, json); assert.strictEqual(so.to_hex(), hex); - so = new SerializedObject(hex); - var parsed_path = SerializedObject.jsonify_structure(types.PathSet.parse(so)); + const so2 = new SerializedObject(hex); + const parsed_path = SerializedObject.jsonify_structure(types.PathSet.parse(so2)); assert.deepEqual(parsed_path, result_json); }); it('Serialize path through XRP IOUs (realistic example)', function() { @@ -794,8 +793,8 @@ describe('Serialized types', function() { // Note that XRP IOUs are no longer allowed, so this functionality is // for historic transactions only. - var hex = '31585E1F3BD02A15D6185F8BB9B57CC60DEDDB37C10000000000000000000000004254430000000000585E1F3BD02A15D6185F8BB9B57CC60DEDDB37C131E4FE687C90257D3D2D694C8531CDEECBE84F33670000000000000000000000004254430000000000E4FE687C90257D3D2D694C8531CDEECBE84F3367310A20B3C85F482532A9578DBB3950B85CA06594D100000000000000000000000042544300000000000A20B3C85F482532A9578DBB3950B85CA06594D13000000000000000000000000055534400000000000A20B3C85F482532A9578DBB3950B85CA06594D1FF31585E1F3BD02A15D6185F8BB9B57CC60DEDDB37C10000000000000000000000004254430000000000585E1F3BD02A15D6185F8BB9B57CC60DEDDB37C131E4FE687C90257D3D2D694C8531CDEECBE84F33670000000000000000000000004254430000000000E4FE687C90257D3D2D694C8531CDEECBE84F33673115036E2D3F5437A83E5AC3CAEE34FF2C21DEB618000000000000000000000000425443000000000015036E2D3F5437A83E5AC3CAEE34FF2C21DEB6183000000000000000000000000055534400000000000A20B3C85F482532A9578DBB3950B85CA06594D1FF31585E1F3BD02A15D6185F8BB9B57CC60DEDDB37C10000000000000000000000004254430000000000585E1F3BD02A15D6185F8BB9B57CC60DEDDB37C13157180C769B66D942EE69E6DCC940CA48D82337AD000000000000000000000000425443000000000057180C769B66D942EE69E6DCC940CA48D82337AD1000000000000000000000000058525000000000003000000000000000000000000055534400000000000A20B3C85F482532A9578DBB3950B85CA06594D100'; - var json = [ + const hex = '31585E1F3BD02A15D6185F8BB9B57CC60DEDDB37C10000000000000000000000004254430000000000585E1F3BD02A15D6185F8BB9B57CC60DEDDB37C131E4FE687C90257D3D2D694C8531CDEECBE84F33670000000000000000000000004254430000000000E4FE687C90257D3D2D694C8531CDEECBE84F3367310A20B3C85F482532A9578DBB3950B85CA06594D100000000000000000000000042544300000000000A20B3C85F482532A9578DBB3950B85CA06594D13000000000000000000000000055534400000000000A20B3C85F482532A9578DBB3950B85CA06594D1FF31585E1F3BD02A15D6185F8BB9B57CC60DEDDB37C10000000000000000000000004254430000000000585E1F3BD02A15D6185F8BB9B57CC60DEDDB37C131E4FE687C90257D3D2D694C8531CDEECBE84F33670000000000000000000000004254430000000000E4FE687C90257D3D2D694C8531CDEECBE84F33673115036E2D3F5437A83E5AC3CAEE34FF2C21DEB618000000000000000000000000425443000000000015036E2D3F5437A83E5AC3CAEE34FF2C21DEB6183000000000000000000000000055534400000000000A20B3C85F482532A9578DBB3950B85CA06594D1FF31585E1F3BD02A15D6185F8BB9B57CC60DEDDB37C10000000000000000000000004254430000000000585E1F3BD02A15D6185F8BB9B57CC60DEDDB37C13157180C769B66D942EE69E6DCC940CA48D82337AD000000000000000000000000425443000000000057180C769B66D942EE69E6DCC940CA48D82337AD1000000000000000000000000058525000000000003000000000000000000000000055534400000000000A20B3C85F482532A9578DBB3950B85CA06594D100'; + const json = [ [{ account: 'r9hEDb4xBGRfBCcX3E4FirDWQBAYtpxC8K', currency: 'BTC', @@ -845,7 +844,7 @@ describe('Serialized types', function() { }] ]; - var result_json = [ + const result_json = [ [{ account: 'r9hEDb4xBGRfBCcX3E4FirDWQBAYtpxC8K', currency: 'BTC', @@ -919,24 +918,24 @@ describe('Serialized types', function() { }] ]; - var so = new SerializedObject(); + const so = new SerializedObject(); types.PathSet.serialize(so, json); assert.strictEqual(so.to_hex(), hex); - so = new SerializedObject(hex); - var parsed_path = SerializedObject.jsonify_structure(types.PathSet.parse(so)); + const so2 = new SerializedObject(hex); + const parsed_path = SerializedObject.jsonify_structure(types.PathSet.parse(so2)); assert.deepEqual(parsed_path, result_json); }); it('Parse single empty path [[]]', function() { - var so = new SerializedObject('00'); - var parsed_path = SerializedObject.jsonify_structure(types.PathSet.parse(so)); + const so = new SerializedObject('00'); + const parsed_path = SerializedObject.jsonify_structure(types.PathSet.parse(so)); assert.deepEqual(parsed_path, [[]]); }); it('Parse [[e],[e,e]]', function() { - var so = new SerializedObject('31000000000000000000000000000000000000007B00000000000000000000000055534400000000000000000000000000000000000000000000000315FF31000000000000000000000000000000000000007B000000000000000000000000425443000000000000000000000000000000000000000000000003153100000000000000000000000000000000000003DB0000000000000000000000004555520000000000000000000000000000000000000000000000014100'); + const so = new SerializedObject('31000000000000000000000000000000000000007B00000000000000000000000055534400000000000000000000000000000000000000000000000315FF31000000000000000000000000000000000000007B000000000000000000000000425443000000000000000000000000000000000000000000000003153100000000000000000000000000000000000003DB0000000000000000000000004555520000000000000000000000000000000000000000000000014100'); - var parsed_path = types.PathSet.parse(so); - var comp = [ + const parsed_path = types.PathSet.parse(so); + const comp = [ [ { account: 'rrrrrrrrrrrrrrrrrrrrNxV3Xza', @@ -970,10 +969,10 @@ describe('Serialized types', function() { describe('Object', function() { it('Can parse objects with VL encoded Vector256', function() { - var hex = '110064220000000058000360186E008422E06B72D5B275E29EE3BE9D87A370F424E0E7BF613C4659098214289D19799C892637306AAAF03805EDFCDF6C28B8011320081342A0AB45459A54D8E4FA1842339A102680216CF9A152BCE4F4CE467D8246'; - var so = new SerializedObject(hex); - var as_json = so.to_json(); - var expected_json = { + const hex = '110064220000000058000360186E008422E06B72D5B275E29EE3BE9D87A370F424E0E7BF613C4659098214289D19799C892637306AAAF03805EDFCDF6C28B8011320081342A0AB45459A54D8E4FA1842339A102680216CF9A152BCE4F4CE467D8246'; + const so = new SerializedObject(hex); + const as_json = so.to_json(); + const expected_json = { LedgerEntryType: 'DirectoryNode', Owner: 'rh6kN9s7spSb3vdv6H8ZGYzsddSLeEUGmc', Flags: 0, @@ -986,17 +985,17 @@ describe('Serialized types', function() { assert.strictEqual(SerializedObject.from_json(expected_json).to_hex(), hex); }); it('Serialize empty object {}', function() { - var so = new SerializedObject(); + const so = new SerializedObject(); types.Object.serialize(so, {}); assert.strictEqual(so.to_hex(), 'E1'); }); it('Parse empty object {}', function() { - var so = new SerializedObject('E1'); - var parsed_object = types.Object.parse(so); + const so = new SerializedObject('E1'); + const parsed_object = types.Object.parse(so); assert.deepEqual(parsed_object, {}); }); it('Serialize simple object {TakerPays:"87654321.12345678/EUR/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh", TakerGets:213, Fee:"789"}', function() { - var so = new SerializedObject(); + const so = new SerializedObject(); types.Object.serialize(so, { TakerPays: '87654321.12345678/EUR/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh', TakerGets: '213', @@ -1006,9 +1005,9 @@ describe('Serialized types', function() { // TODO: Check independently. }); it('Parse same object', function() { - var so = new SerializedObject('64D65F241D335BF24E0000000000000000000000004555520000000000B5F762798A53D543A014CAF8B297CFF8F2F937E86540000000000000D5684000000000000315E1'); - var parsed_object = types.Object.parse(so); - var comp = { + const so = new SerializedObject('64D65F241D335BF24E0000000000000000000000004555520000000000B5F762798A53D543A014CAF8B297CFF8F2F937E86540000000000000D5684000000000000315E1'); + const parsed_object = types.Object.parse(so); + const comp = { TakerPays: { value: '87654321.12345678', currency: 'EUR', @@ -1022,7 +1021,7 @@ describe('Serialized types', function() { }); it('Serialize simple object {DestinationTag:123, QualityIn:456, QualityOut:789}', function() { - var so = new SerializedObject(); + const so = new SerializedObject(); types.Object.serialize(so, { DestinationTag: 123, QualityIn: 456, @@ -1032,8 +1031,8 @@ describe('Serialized types', function() { // TODO: Check independently. }); it('Parse simple object {DestinationTag:123, QualityIn:456, QualityOut:789}', function() {// 2E0000007B22000001C82400000315E1 2E0000007B2002000001C8200200000315E1 - var so = new SerializedObject('2E0000007B2014000001C8201500000315E1'); - var parsed_object = types.Object.parse(so); + const so = new SerializedObject('2E0000007B2014000001C8201500000315E1'); + const parsed_object = types.Object.parse(so); assert.deepEqual(parsed_object, { DestinationTag: 123, QualityIn: 456, @@ -1045,17 +1044,17 @@ describe('Serialized types', function() { describe('Array', function() { it('Serialize empty array []', function() { - var so = new SerializedObject(); + const so = new SerializedObject(); types.Array.serialize(so, []); assert.strictEqual(so.to_hex(), 'F1'); }); it('Parse empty array []', function() { - var so = new SerializedObject('F1'); - var parsed_object = types.Array.parse(so); + const so = new SerializedObject('F1'); + const parsed_object = types.Array.parse(so); assert.deepEqual(parsed_object, []); }); it('Serialize 3-length array [{TakerPays:123}); {TakerGets:456}, {Fee:789}]', function() { - var so = new SerializedObject(); + const so = new SerializedObject(); types.Array.serialize(so, [ { TakerPays: 123 @@ -1071,9 +1070,9 @@ describe('Serialized types', function() { assert.strictEqual(so.to_hex(), '64400000000000007B6540000000000001C8684000000000000315F1'); }); it('Parse the same array', function() { - var so = new SerializedObject('64400000000000007B6540000000000001C8684000000000000315F1'); - var parsed_object = types.Array.parse(so); - var comp = [ + const so = new SerializedObject('64400000000000007B6540000000000001C8684000000000000315F1'); + const parsed_object = types.Array.parse(so); + const comp = [ { TakerPays: '123' }, @@ -1087,7 +1086,7 @@ describe('Serialized types', function() { assert.deepEqual(SerializedObject.jsonify_structure(parsed_object, ''), comp); }); it('Serialize 3-length array [{DestinationTag:123}); {QualityIn:456}, {Fee:789}]', function() { - var so = new SerializedObject(); + const so = new SerializedObject(); types.Array.serialize(so, [ { DestinationTag: 123 @@ -1103,9 +1102,9 @@ describe('Serialized types', function() { assert.strictEqual(so.to_hex(), '2E0000007B2014000001C8684000000000000315F1'); }); it('Parse the same array 2', function() { - var so = new SerializedObject('2E0000007B2014000001C8684000000000000315F1'); - var parsed_object = types.Array.parse(so); - var comp = [ + const so = new SerializedObject('2E0000007B2014000001C8684000000000000315F1'); + const parsed_object = types.Array.parse(so); + const comp = [ { DestinationTag: 123 },