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 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, | ||||
jsonReviver, | jsonReviver, | ||||
getOutputScriptFromAddress, | |||||
} = require('../src/utils'); | } = require('../src/utils'); | ||||
const { addressPreviews } = require('./mocks/templates'); | const { addressPreviews } = require('./mocks/templates'); | ||||
describe('ecash-telegram-bot utils.js functions', function () { | describe('ecash-telegram-bot utils.js functions', function () { | ||||
it('returnAddressPreview converts a valid ecash: address into an abbreviated preview at various slice sizes', function () { | it('returnAddressPreview converts a valid ecash: address into an abbreviated preview at various slice sizes', function () { | ||||
for (let i = 0; i < addressPreviews.length; i += 1) { | for (let i = 0; i < addressPreviews.length; i += 1) { | ||||
const { address, preview, sliceSize } = addressPreviews[i]; | const { address, preview, sliceSize } = addressPreviews[i]; | ||||
assert.strictEqual( | assert.strictEqual( | ||||
▲ Show 20 Lines • Show All 188 Lines • ▼ Show 20 Lines | it('jsonReplacer and jsonReviver can encode and decode an object including a Set and a Map to and from JSON', async function () { | ||||
]); | ]); | ||||
const set = new Set(['one', 'two', 'three']); | const set = new Set(['one', 'two', 'three']); | ||||
const jsonText = JSON.stringify({ map, set }, jsonReplacer); | const jsonText = JSON.stringify({ map, set }, jsonReplacer); | ||||
const roundTrip = JSON.parse(jsonText, jsonReviver); | const roundTrip = JSON.parse(jsonText, jsonReviver); | ||||
assert.deepEqual({ map, set }, roundTrip); | assert.deepEqual({ map, set }, roundTrip); | ||||
}); | }); | ||||
// getOutputScriptFromAddress | |||||
it('getOutputScriptFromAddress returns expected outputScript of a p2pkh address', async function () { | |||||
assert.strictEqual( | |||||
getOutputScriptFromAddress( | |||||
'ecash:qz2708636snqhsxu8wnlka78h6fdp77ar59jrf5035', | |||||
), | |||||
`76a91495e79f51d4260bc0dc3ba7fb77c7be92d0fbdd1d88ac`, | |||||
); | |||||
}); | |||||
it('getOutputScriptFromAddress returns expected outputScript of the IFP address (p2sh)', async function () { | |||||
assert.strictEqual( | |||||
getOutputScriptFromAddress(config.ifpAddress), | |||||
`a914d37c4c809fe9840e7bfa77b86bd47163f6fb6c6087`, | |||||
); | |||||
}); | |||||
}); | }); |