diff --git a/src/api/common/index.js b/src/api/common/index.js index 2f56044a..7c65dfb6 100644 --- a/src/api/common/index.js +++ b/src/api/common/index.js @@ -17,6 +17,6 @@ module.exports = { convertExceptions: utils.convertExceptions, convertKeysFromSnakeCaseToCamelCase: utils.convertKeysFromSnakeCaseToCamelCase, - toTimestamp: utils.toTimestamp, - fromTimestamp: utils.fromTimestamp + rippleToUnixTimestamp: utils.rippleToUnixTimestamp, + unixToRippleTimestamp: utils.unixToRippleTimestamp }; diff --git a/src/api/common/utils.js b/src/api/common/utils.js index 3f42e3be..1b91e648 100644 --- a/src/api/common/utils.js +++ b/src/api/common/utils.js @@ -67,7 +67,7 @@ function removeUndefined(obj: Object): Object { * @return {Number} ms since unix epoch * */ -function toTimestamp(rpepoch: number): number { +function rippleToUnixTimestamp(rpepoch: number): number { return (rpepoch + 0x386D4380) * 1000; } @@ -75,7 +75,7 @@ function toTimestamp(rpepoch: number): number { * @param {Number|Date} timestamp (ms since unix epoch) * @return {Number} seconds since ripple epoch ( 1/1/2000 GMT) */ -function fromTimestamp(timestamp: number | Date): number { +function unixToRippleTimestamp(timestamp: number | Date): number { const timestamp_ = timestamp instanceof Date ? timestamp.getTime() : timestamp; @@ -90,6 +90,6 @@ module.exports = { generateAddressAPI, convertKeysFromSnakeCaseToCamelCase, removeUndefined, - toTimestamp, - fromTimestamp + rippleToUnixTimestamp, + unixToRippleTimestamp }; diff --git a/src/api/ledger/parse/utils.js b/src/api/ledger/parse/utils.js index 74852b2d..250dec6c 100644 --- a/src/api/ledger/parse/utils.js +++ b/src/api/ledger/parse/utils.js @@ -3,7 +3,7 @@ const _ = require('lodash'); const transactionParser = require('ripple-lib-transactionparser'); const utils = require('../utils'); -const toTimestamp = utils.common.toTimestamp; +const rippleToUnixTimestamp = utils.common.rippleToUnixTimestamp; const BigNumber = require('bignumber.js'); function adjustQualityForXRP( @@ -19,7 +19,8 @@ function adjustQualityForXRP( } function parseTimestamp(tx: {date: string}): string | void { - return tx.date ? (new Date(toTimestamp(tx.date))).toISOString() : undefined; + return tx.date ? (new Date(rippleToUnixTimestamp(tx.date))).toISOString() + : undefined; } function removeEmptyCounterparty(amount) { diff --git a/src/api/server/server.js b/src/api/server/server.js index 406a71b8..bf20ff49 100644 --- a/src/api/server/server.js +++ b/src/api/server/server.js @@ -29,7 +29,7 @@ function getFee(): Promise { } function rippleTimeToISO8601(rippleTime: string): string { - return new Date(common.toTimestamp(rippleTime)).toISOString(); + return new Date(common.rippleToUnixTimestamp(rippleTime)).toISOString(); } function formatLedgerClose(ledgerClose: Object): Object { diff --git a/src/api/transaction/suspended-payment-creation.js b/src/api/transaction/suspended-payment-creation.js index 4195aa35..bee83e15 100644 --- a/src/api/transaction/suspended-payment-creation.js +++ b/src/api/transaction/suspended-payment-creation.js @@ -2,7 +2,7 @@ 'use strict'; const _ = require('lodash'); const utils = require('./utils'); -const {validate, fromTimestamp, toRippledAmount} = utils.common; +const {validate, unixToRippleTimestamp, toRippledAmount} = utils.common; import type {Instructions, Prepare} from './types.js'; import type {Adjustment, MaxAdjustment, Memo} from '../common/types.js'; @@ -32,10 +32,10 @@ function createSuspendedPaymentCreationTransaction(account: string, txJSON.Digest = payment.digest; } if (payment.allowCancelAfter !== undefined) { - txJSON.CancelAfter = fromTimestamp(payment.allowCancelAfter); + txJSON.CancelAfter = unixToRippleTimestamp(payment.allowCancelAfter); } if (payment.allowExecuteAfter !== undefined) { - txJSON.FinishAfter = fromTimestamp(payment.allowExecuteAfter); + txJSON.FinishAfter = unixToRippleTimestamp(payment.allowExecuteAfter); } if (payment.source.tag !== undefined) { txJSON.SourceTag = payment.source.tag; diff --git a/test/account-test.js b/test/account-test.js index a6a57657..e32f7ad0 100644 --- a/test/account-test.js +++ b/test/account-test.js @@ -99,35 +99,34 @@ describe('Account', function() { it('should respond true if the public key corresponds to the account ' + ' address and the master key IS NOT disabled', function(done) { - const options = {Flags: 65536}; - const account = new Account(createRemote(options), - 'rKXCummUHnenhYudNb9UoJ4mGBR75vFcgz'); - account.publicKeyIsActive( - '025B32A54BFA33FB781581F49B235C0E2820C929FF41E677ADA5D3E53CFBA46332', - function(err, is_valid) { + const options = {Flags: 65536}; + const account = new Account(createRemote(options), + 'rKXCummUHnenhYudNb9UoJ4mGBR75vFcgz'); + account.publicKeyIsActive( + '025B32A54BFA33FB781581F49B235C0E2820C929FF41E677ADA5D3E53CFBA46332', + function(err, is_valid) { - assert(err === null); - assert(is_valid === true); - done(); - }); + assert(err === null); + assert(is_valid === true); + done(); + }); - }); + }); it('should respond false if the public key corresponds to the account ' + ' address and the master key IS disabled', function(done) { - const account = new Account(createRemote(), - 'rKXCummUHnenhYudNb9UoJ4mGBR75vFcgz'); - account.publicKeyIsActive( - '025B32A54BFA33FB781581F49B235C0E2820C929FF41E677ADA5D3E53CFBA46332', - function(err, is_valid) { + const account = new Account(createRemote(), + 'rKXCummUHnenhYudNb9UoJ4mGBR75vFcgz'); + account.publicKeyIsActive( + '025B32A54BFA33FB781581F49B235C0E2820C929FF41E677ADA5D3E53CFBA46332', + function(err, is_valid) { + assert(err === null); + assert(is_valid === false); + done(); + }); - assert(err === null); - assert(is_valid === false); - done(); - }); - - }); + }); it('should respond true if the public key corresponds to the regular key', function(done) { @@ -149,17 +148,17 @@ describe('Account', function() { it('should respond false if the public key does not correspond to an ' + ' active public key for the account', function(done) { - const account = new Account(createRemote(), - 'rKXCummUHnenhYudNb9UoJ4mGBR75vFcgz'); - account.publicKeyIsActive( - '032ECDA93970BC7E8872EF6582CB52A5557F117244A949EB4FA8AC7688CF24FBC8', - function(err, is_valid) { - assert(err === null); - assert(is_valid === false); - done(); - }); + const account = new Account(createRemote(), + 'rKXCummUHnenhYudNb9UoJ4mGBR75vFcgz'); + account.publicKeyIsActive( + '032ECDA93970BC7E8872EF6582CB52A5557F117244A949EB4FA8AC7688CF24FBC8', + function(err, is_valid) { + assert(err === null); + assert(is_valid === false); + done(); + }); - }); + }); it('should respond false if the public key is invalid', function(done) { @@ -189,17 +188,17 @@ describe('Account', function() { it('should respond false if the public key does not correspond to an ' + ' active public key for the unfunded account', function(done) { - const account = new Account(createRemote(), - 'rLdfp6eoR948KVxfn6EpaaNTKwfwXhzSeQ'); - account.publicKeyIsActive( - '032ECDA93970BC7E8872EF6582CB52A5557F117244A949EB4FA8AC7688CF24FBC8', - function(err, is_valid) { - assert(err === null); - assert(is_valid === false); - done(); - }); + const account = new Account(createRemote(), + 'rLdfp6eoR948KVxfn6EpaaNTKwfwXhzSeQ'); + account.publicKeyIsActive( + '032ECDA93970BC7E8872EF6582CB52A5557F117244A949EB4FA8AC7688CF24FBC8', + function(err, is_valid) { + assert(err === null); + assert(is_valid === false); + done(); + }); - }); + }); }); diff --git a/test/api-test.js b/test/api-test.js index b7df43cd..12fcfd8e 100644 --- a/test/api-test.js +++ b/test/api-test.js @@ -601,7 +601,7 @@ describe('RippleAPI', function() { assert(false, 'Should throw NetworkError'); }).catch(error => { assert(error instanceof this.api.errors.RippledError); - assert(error.message.indexOf('slowDown') !== -1); + assert(_.includes(error.message, 'slowDown')); }); });