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 159 Lines • ▼ Show 20 Lines | it('jsonReplacer and jsonReviver can encode and decode a Map to and from JSON', async function () { | ||||
[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 Map containing a BigNumber', async function () { | |||||
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 |