Changeset View
Changeset View
Standalone View
Standalone View
apps/ecash-herald/test/utilsTests.js
// Copyright (c) 2023 The Bitcoin developers | // Copyright (c) 2023 The Bitcoin developers | ||||
// Distributed under the MIT software license, see the accompanying | // Distributed under the MIT software license, see the accompanying | ||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php. | // file COPYING or http://www.opensource.org/licenses/mit-license.php. | ||||
'use strict'; | 'use strict'; | ||||
const assert = require('assert'); | const assert = require('assert'); | ||||
const BigNumber = require('bignumber.js'); | |||||
const axios = require('axios'); | const axios = require('axios'); | ||||
const MockAdapter = require('axios-mock-adapter'); | const MockAdapter = require('axios-mock-adapter'); | ||||
const config = require('../config'); | const config = require('../config'); | ||||
const { | const { | ||||
returnAddressPreview, | returnAddressPreview, | ||||
getCoingeckoPrices, | getCoingeckoPrices, | ||||
formatPrice, | formatPrice, | ||||
jsonReplacer, | jsonReplacer, | ||||
▲ Show 20 Lines • Show All 147 Lines • ▼ Show 20 Lines | it('formatPrice correctly formats a GBP price greater than 100', async function () { | ||||
assert.strictEqual(formatPrice(1523.134239, 'gbp'), `£1,523`); | assert.strictEqual(formatPrice(1523.134239, 'gbp'), `£1,523`); | ||||
}); | }); | ||||
it('formatPrice correctly formats a JPY price greater than ¥100', async function () { | it('formatPrice correctly formats a JPY price greater than ¥100', async function () { | ||||
assert.strictEqual(formatPrice(100000.999923422, 'jpy'), `¥100,001`); | assert.strictEqual(formatPrice(100000.999923422, 'jpy'), `¥100,001`); | ||||
}); | }); | ||||
it('formatPrice omits a currency symbol if it cannot find it', async function () { | it('formatPrice omits a currency symbol if it cannot find it', async function () { | ||||
assert.strictEqual(formatPrice(100000.999923422, 'cad'), `100,001`); | assert.strictEqual(formatPrice(100000.999923422, 'cad'), `100,001`); | ||||
}); | }); | ||||
it('jsonReplacer and jsonReviver can encode and decode an empty Map to and from JSON', async function () { | |||||
Fabien: Same, should be its own diff | |||||
bytesofmanAuthorUnsubmitted Done Inline Actionswill just get rid of this test. I added it when I hadn't figured out that BigNumber was causing the problem. the test proved that this wasn't the issue. bytesofman: will just get rid of this test. I added it when I hadn't figured out that BigNumber was causing… | |||||
const map = new Map(); | |||||
const jsonText = JSON.stringify(map, jsonReplacer); | |||||
const roundTrip = JSON.parse(jsonText, jsonReviver); | |||||
assert.deepEqual(map, roundTrip); | |||||
}); | |||||
it('jsonReplacer and jsonReviver can encode and decode a Map to and from JSON', async function () { | it('jsonReplacer and jsonReviver can encode and decode a Map to and from JSON', async function () { | ||||
const map = new Map([ | const map = new Map([ | ||||
[1, 'one'], | [1, 'one'], | ||||
[2, 'two'], | [2, 'two'], | ||||
[3, 'three'], | [3, 'three'], | ||||
]); | ]); | ||||
const jsonText = JSON.stringify(map, jsonReplacer); | const jsonText = JSON.stringify(map, jsonReplacer); | ||||
const roundTrip = JSON.parse(jsonText, jsonReviver); | const roundTrip = JSON.parse(jsonText, jsonReviver); | ||||
assert.deepEqual(map, roundTrip); | assert.deepEqual(map, roundTrip); | ||||
}); | }); | ||||
it('jsonReplacer and jsonReviver can encode and decode an empty Set to and from JSON', async function () { | |||||
const set = new Set(); | |||||
const jsonText = JSON.stringify(set, jsonReplacer); | |||||
const roundTrip = JSON.parse(jsonText, jsonReviver); | |||||
assert.deepEqual(set, roundTrip); | |||||
}); | |||||
it('jsonReplacer and jsonReviver can encode and decode Map containing a BigNumber', async function () { | |||||
FabienUnsubmitted Not Done Inline ActionsOnly this part is relevant to this diff, and even so it could be split if necessary Fabien: Only this part is relevant to this diff, and even so it could be split if necessary | |||||
bytesofmanAuthorUnsubmitted Done Inline ActionsCould be split, but the functionality is directly required by the specific data types introduced in this diff (Maps that include BigNumber types in the values). It's a pretty customized mod. We might need more similar mods in the future that would also be related to specific data types introduced at some stage of this app. I think less confusing to any future diff peruser if it's kept here. bytesofman: Could be split, but the functionality is directly required by the specific data types… | |||||
const bigNumberMap = new Map([ | |||||
[ | |||||
'76a9144c1efd024f560e4e1aaf4b62416cd1e82fbed24f88ac', | |||||
new BigNumber(36), | |||||
], | |||||
[ | |||||
'76a9144c1efd024f560e4e1aaf4b62416cd1e82fbed24f88ac', | |||||
new BigNumber(72), | |||||
], | |||||
]); | |||||
const jsonText = JSON.stringify(bigNumberMap, jsonReplacer); | |||||
const roundTrip = JSON.parse(jsonText, jsonReviver); | |||||
assert.deepEqual(bigNumberMap, roundTrip); | |||||
}); | |||||
it('jsonReplacer and jsonReviver can encode and decode a Set to and from JSON', async function () { | it('jsonReplacer and jsonReviver can encode and decode a Set to and from JSON', async function () { | ||||
const set = new Set(['one', 'two', 'three']); | const set = new Set(['one', 'two', 'three']); | ||||
const jsonText = JSON.stringify(set, jsonReplacer); | const jsonText = JSON.stringify(set, jsonReplacer); | ||||
const roundTrip = JSON.parse(jsonText, jsonReviver); | const roundTrip = JSON.parse(jsonText, jsonReviver); | ||||
assert.deepEqual(set, roundTrip); | assert.deepEqual(set, roundTrip); | ||||
}); | }); | ||||
Show All 14 Lines |
Same, should be its own diff