From ac8e00bf0d0b26570b2e2913ded8f01378f27d32 Mon Sep 17 00:00:00 2001 From: Jaguar0625 Date: Tue, 16 Nov 2021 08:55:35 -0400 Subject: [PATCH] task: remove cmc plugin and move cmcRoutes into mosaic:supplyRoutes --- .../src/plugins/catapultModelSystem.js | 4 +- catapult-sdk/src/plugins/cmc.js | 38 ------ .../test/plugins/catapultModelSystem_spec.js | 3 +- rest/src/plugins/cmc/CmcDb.js | 51 -------- rest/src/plugins/cmc/cmc.js | 40 ------ rest/src/plugins/cmc/cmcUtils.js | 26 ---- rest/src/plugins/mosaic/mosaic.js | 2 + .../cmcRoutes.js => mosaic/supplyRoutes.js} | 44 +++++-- rest/src/plugins/routeSystem.js | 4 +- rest/test/plugins/cmc/cmcDb_spec.js | 121 ------------------ rest/test/plugins/cmc/cmcUtils_spec.js | 36 ------ rest/test/plugins/cmc/cmc_spec.js | 49 ------- rest/test/plugins/mosaic/mosaic_spec.js | 5 +- .../supplyRoutes_spec.js} | 25 ++-- rest/test/plugins/routeSystem_spec.js | 3 +- 15 files changed, 52 insertions(+), 399 deletions(-) delete mode 100644 catapult-sdk/src/plugins/cmc.js delete mode 100644 rest/src/plugins/cmc/CmcDb.js delete mode 100644 rest/src/plugins/cmc/cmc.js delete mode 100644 rest/src/plugins/cmc/cmcUtils.js rename rest/src/plugins/{cmc/cmcRoutes.js => mosaic/supplyRoutes.js} (68%) delete mode 100644 rest/test/plugins/cmc/cmcDb_spec.js delete mode 100644 rest/test/plugins/cmc/cmcUtils_spec.js delete mode 100644 rest/test/plugins/cmc/cmc_spec.js rename rest/test/plugins/{cmc/cmcRoutes_spec.js => mosaic/supplyRoutes_spec.js} (87%) diff --git a/catapult-sdk/src/plugins/catapultModelSystem.js b/catapult-sdk/src/plugins/catapultModelSystem.js index 2de6c2c90..3de1adb87 100644 --- a/catapult-sdk/src/plugins/catapultModelSystem.js +++ b/catapult-sdk/src/plugins/catapultModelSystem.js @@ -22,7 +22,6 @@ /** @module plugins/catapultModelSystem */ const accountLink = require('./accountLink'); const aggregate = require('./aggregate'); -const cmc = require('./cmc'); const lockHash = require('./lockHash'); const lockSecret = require('./lockSecret'); const metadata = require('./metadata'); @@ -47,8 +46,7 @@ const plugins = { namespace, receipts, restrictions, - transfer, - cmc + transfer }; /** diff --git a/catapult-sdk/src/plugins/cmc.js b/catapult-sdk/src/plugins/cmc.js deleted file mode 100644 index 4cea11557..000000000 --- a/catapult-sdk/src/plugins/cmc.js +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Copyright (c) 2016-2019, Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. - * Copyright (c) 2020-present, Jaguar0625, gimre, BloodyRookie. - * All rights reserved. - * - * This file is part of Catapult. - * - * Catapult is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Catapult is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with Catapult. If not, see . - */ - -/** @module plugins/cmc */ - -// To ensure cmc able to load from the config, created empty plugins - -/* eslint-disable no-unused-vars */ - -/** - * Creates a cmc plugin use for CoinMarketCap. - * @type {module:plugins/CatapultPlugin} - */ -const cmcPlugin = { - registerSchema: builder => {}, - - registerCodecs: codecBuilder => {} -}; - -module.exports = cmcPlugin; diff --git a/catapult-sdk/test/plugins/catapultModelSystem_spec.js b/catapult-sdk/test/plugins/catapultModelSystem_spec.js index 9e69c719d..93ecdaa6d 100644 --- a/catapult-sdk/test/plugins/catapultModelSystem_spec.js +++ b/catapult-sdk/test/plugins/catapultModelSystem_spec.js @@ -56,8 +56,7 @@ describe('catapult model system', () => { 'namespace', 'receipts', 'restrictions', - 'transfer', - 'cmc' + 'transfer' ]); }); }); diff --git a/rest/src/plugins/cmc/CmcDb.js b/rest/src/plugins/cmc/CmcDb.js deleted file mode 100644 index c02cdcb3d..000000000 --- a/rest/src/plugins/cmc/CmcDb.js +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Copyright (c) 2016-2019, Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. - * Copyright (c) 2020-present, Jaguar0625, gimre, BloodyRookie. - * All rights reserved. - * - * This file is part of Catapult. - * - * Catapult is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Catapult is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with Catapult. If not, see . - */ - -const { convertToLong } = require('../../db/dbUtils'); - -class CmcDb { - /** - * Creates NetworkCurrencyDb around CatapultDb. - * @param {module:db/CatapultDb} db Catapult db instance. - */ - constructor(db) { - this.catapultDb = db; - } - - // region NetworkCurrency retrieval - /** - * Retrieves mosaics given their ids. - * @param {Array.} ids Mosaic ids. - * @returns {Promise.} Mosaics. - */ - mosaicsByIds(ids) { - const mosaicIds = ids.map(id => convertToLong(id)); - const conditions = { 'mosaic.id': { $in: mosaicIds } }; - const collection = this.catapultDb.database.collection('mosaics'); - return collection.find(conditions) - .sort({ _id: -1 }) - .toArray() - .then(entities => Promise.resolve(this.catapultDb.sanitizer.renameIds(entities))); - } - // endregion -} - -module.exports = CmcDb; diff --git a/rest/src/plugins/cmc/cmc.js b/rest/src/plugins/cmc/cmc.js deleted file mode 100644 index 7e7946075..000000000 --- a/rest/src/plugins/cmc/cmc.js +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Copyright (c) 2016-2019, Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. - * Copyright (c) 2020-present, Jaguar0625, gimre, BloodyRookie. - * All rights reserved. - * - * This file is part of Catapult. - * - * Catapult is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Catapult is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with Catapult. If not, see . - */ - -/** @module plugins/cmc */ -const CmcDb = require('./CmcDb'); -const cmcRoutes = require('./cmcRoutes'); - -/** - * Creates a cmc plugin. - * @type {module:plugins/CatapultRestPlugin} - */ -module.exports = { - createDb: db => new CmcDb(db), - - registerTransactionStates: () => {}, - - registerMessageChannels: () => {}, - - registerRoutes: (...args) => { - cmcRoutes.register(...args); - } -}; diff --git a/rest/src/plugins/cmc/cmcUtils.js b/rest/src/plugins/cmc/cmcUtils.js deleted file mode 100644 index 8314cc9e7..000000000 --- a/rest/src/plugins/cmc/cmcUtils.js +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright (c) 2016-2019, Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. - * Copyright (c) 2020-present, Jaguar0625, gimre, BloodyRookie. - * All rights reserved. - * - * This file is part of Catapult. - * - * Catapult is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Catapult is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with Catapult. If not, see . - */ - -const cmcUtils = { - convertToRelative: absolute => (Number(absolute) / (10 ** 6)).toFixed(6) -}; - -module.exports = cmcUtils; diff --git a/rest/src/plugins/mosaic/mosaic.js b/rest/src/plugins/mosaic/mosaic.js index 9e7c2ae5e..b626fa2b1 100644 --- a/rest/src/plugins/mosaic/mosaic.js +++ b/rest/src/plugins/mosaic/mosaic.js @@ -22,6 +22,7 @@ /** @module plugins/mosaic */ const MosaicDb = require('./MosaicDb'); const mosaicRoutes = require('./mosaicRoutes'); +const supplyRoutes = require('./supplyRoutes'); /** * Creates a mosaic plugin. @@ -36,5 +37,6 @@ module.exports = { registerRoutes: (...args) => { mosaicRoutes.register(...args); + supplyRoutes.register(...args); } }; diff --git a/rest/src/plugins/cmc/cmcRoutes.js b/rest/src/plugins/mosaic/supplyRoutes.js similarity index 68% rename from rest/src/plugins/cmc/cmcRoutes.js rename to rest/src/plugins/mosaic/supplyRoutes.js index 762b5d552..9e3ea4898 100644 --- a/rest/src/plugins/cmc/cmcRoutes.js +++ b/rest/src/plugins/mosaic/supplyRoutes.js @@ -19,7 +19,6 @@ * along with Catapult. If not, see . */ -const cmcUtils = require('./cmcUtils'); const { longToUint64 } = require('../../db/dbUtils'); const routeUtils = require('../../routes/routeUtils'); const AccountType = require('../AccountType'); @@ -32,7 +31,9 @@ const { convert, uint64 } = catapult.utils; module.exports = { register: (server, db, services) => { - const sender = routeUtils.createSender('cmc'); + const sender = routeUtils.createSender('supply'); + + const convertToFractionalWholeUnits = (value, divisibility) => (Number(value) / (10 ** divisibility)).toFixed(divisibility); const propertyValueToMosaicId = value => uint64.fromHex(value.replace(/'/g, '').replace('0x', '')); @@ -42,6 +43,14 @@ module.exports = { .then(fileData => ini.parse(fileData)); }; + const getMosaicProperties = async currencyMosaicId => { + const mosaics = await db.mosaicsByIds([currencyMosaicId]); + return { + totalSupply: mosaics[0].mosaic.supply.toNumber(), + divisibility: mosaics[0].mosaic.divisibility + }; + }; + const getUncirculatingAccountIds = propertiesObject => { const publicKeys = [propertiesObject.network.nemesisSignerPublicKey].concat(services.config.uncirculatingAccountPublicKeys); return publicKeys.map(publicKey => ({ [AccountType.publicKey]: convert.hexToUint8(publicKey) })); @@ -59,30 +68,37 @@ module.exports = { server.get('/network/currency/supply/circulating', (req, res, next) => readAndParseNetworkPropertiesFile() .then(async propertiesObject => { const currencyMosaicId = propertyValueToMosaicId(propertiesObject.chain.currencyMosaicId); - const mosaics = await db.mosaicsByIds([currencyMosaicId]); - const accounts = await db.catapultDb.accountsByIds(getUncirculatingAccountIds(propertiesObject)); + const currencyMosaicProperties = await getMosaicProperties(currencyMosaicId); - const totalSupply = mosaics[0].mosaic.supply.toNumber(); + const accounts = await db.catapultDb.accountsByIds(getUncirculatingAccountIds(propertiesObject)); const burnedSupply = accounts.reduce( (sum, account) => sum + lookupMosaicAmount(account.account.mosaics, currencyMosaicId), 0 ); - sender.sendPlainText(res, next)(cmcUtils.convertToRelative(totalSupply - burnedSupply)); + + sender.sendPlainText(res, next)(convertToFractionalWholeUnits( + currencyMosaicProperties.totalSupply - burnedSupply, + currencyMosaicProperties.divisibility + )); })); server.get('/network/currency/supply/total', (req, res, next) => readAndParseNetworkPropertiesFile() - .then(propertiesObject => { + .then(async propertiesObject => { const currencyMosaicId = propertyValueToMosaicId(propertiesObject.chain.currencyMosaicId); - return db.mosaicsByIds([currencyMosaicId]).then(response => { - const supply = response[0].mosaic.supply.toNumber(); - sender.sendPlainText(res, next)(cmcUtils.convertToRelative(supply)); - }); + const currencyMosaicProperties = await getMosaicProperties(currencyMosaicId); + sender.sendPlainText(res, next)(convertToFractionalWholeUnits( + currencyMosaicProperties.totalSupply, + currencyMosaicProperties.divisibility + )); })); server.get('/network/currency/supply/max', (req, res, next) => readAndParseNetworkPropertiesFile() - .then(propertiesObject => { - const supply = parseInt(propertiesObject.chain.maxMosaicAtomicUnits.replace(/'/g, ''), 10); - sender.sendPlainText(res, next)(cmcUtils.convertToRelative(supply)); + .then(async propertiesObject => { + const currencyMosaicId = propertyValueToMosaicId(propertiesObject.chain.currencyMosaicId); + const currencyMosaicProperties = await getMosaicProperties(currencyMosaicId); + + const maxSupply = parseInt(propertiesObject.chain.maxMosaicAtomicUnits.replace(/'/g, ''), 10); + sender.sendPlainText(res, next)(convertToFractionalWholeUnits(maxSupply, currencyMosaicProperties.divisibility)); })); } }; diff --git a/rest/src/plugins/routeSystem.js b/rest/src/plugins/routeSystem.js index 034bc43e0..fe27e42a3 100644 --- a/rest/src/plugins/routeSystem.js +++ b/rest/src/plugins/routeSystem.js @@ -20,7 +20,6 @@ */ const aggregate = require('./aggregate/aggregate'); -const cmc = require('./cmc/cmc'); const empty = require('./empty'); const lockHash = require('./lockHash/lockHash'); const lockSecret = require('./lockSecret/lockSecret'); @@ -44,8 +43,7 @@ const plugins = { namespace, receipts, restrictions, - transfer: empty, - cmc + transfer: empty }; module.exports = { diff --git a/rest/test/plugins/cmc/cmcDb_spec.js b/rest/test/plugins/cmc/cmcDb_spec.js deleted file mode 100644 index 5c64c1be6..000000000 --- a/rest/test/plugins/cmc/cmcDb_spec.js +++ /dev/null @@ -1,121 +0,0 @@ -/* - * Copyright (c) 2016-2019, Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. - * Copyright (c) 2020-present, Jaguar0625, gimre, BloodyRookie. - * All rights reserved. - * - * This file is part of Catapult. - * - * Catapult is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Catapult is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with Catapult. If not, see . - */ - -const CmcDb = require('../../../src/plugins/cmc/CmcDb'); -const test = require('../../db/utils/dbTestUtils'); -const { expect } = require('chai'); -const MongoDb = require('mongodb'); - -const { Binary, Long } = MongoDb; - -describe('cmc db', () => { - const { createObjectId } = test.db; - - const runCMCDbTest = (dbEntities, issueDbCommand, assertDbCommandResult) => - test.db.runDbTest(dbEntities, 'mosaics', db => new CmcDb(db), issueDbCommand, assertDbCommandResult); - - describe('mosaics by ids', () => { - const createMosaic = (id, mosaicId, ownerAddress, parentId) => { - const mosaic = { - ownerAddress: new Binary(ownerAddress), - id: Long.fromNumber(mosaicId), - namespaceId: Long.fromNumber(parentId) - }; - - return { _id: createObjectId(id), mosaic }; - }; - - /* - * Creates mosaics with ids in the 1000s range, whereas namespace ids will be in the 2000s range - */ - const createMosaics = (numNamespaces, numMosaicsPerNamespace) => { - const ownerAddress = test.random.address(); - const mosaics = []; - let dbId = 0; - let id = 10000; - for (let namespaceId = 0; namespaceId < numNamespaces; ++namespaceId) { - for (let i = 0; i < numMosaicsPerNamespace; ++i) - mosaics.push(createMosaic(dbId++, id++, ownerAddress, 20000 + namespaceId)); - } - - return mosaics; - }; - - it('returns empty array for unknown mosaic ids', () => { - // Arrange: - const mosaics = createMosaics(3, 4); - - // Assert: - return runCMCDbTest( - mosaics, - db => db.mosaicsByIds([[123, 456]]), - entities => { expect(entities).to.deep.equal([]); } - ); - }); - - it('returns single matching mosaic', () => { - // Arrange: - const mosaics = createMosaics(3, 4); - - // Assert: - return runCMCDbTest( - mosaics, - db => db.mosaicsByIds([[10010, 0]]), - entities => { - expect(entities).to.deep.equal([{ id: createObjectId(10), ...mosaics[10] }]); - } - ); - }); - - it('returns multiple matching mosaics', () => { - // Arrange: - const mosaics = createMosaics(3, 4); - - // Assert: - return runCMCDbTest( - mosaics, - db => db.mosaicsByIds([[10010, 0], [10007, 0], [10003, 0]]), - entities => { - expect(entities).to.deep.equal([ - { id: createObjectId(10), ...mosaics[10] }, - { id: createObjectId(7), ...mosaics[7] }, - { id: createObjectId(3), ...mosaics[3] } - ]); - } - ); - }); - - it('returns only known mosaics', () => { - // Arrange: - const mosaics = createMosaics(3, 4); - - // Assert: - return runCMCDbTest( - mosaics, - db => db.mosaicsByIds([[10010, 0], [10021, 0], [10003, 0]]), - entities => expect(entities).to.deep.equal([ - { id: createObjectId(10), ...mosaics[10] }, - { id: createObjectId(3), ...mosaics[3] } - ]) - ); - }); - }); -}); diff --git a/rest/test/plugins/cmc/cmcUtils_spec.js b/rest/test/plugins/cmc/cmcUtils_spec.js deleted file mode 100644 index 623b0dcd7..000000000 --- a/rest/test/plugins/cmc/cmcUtils_spec.js +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Copyright (c) 2016-2019, Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. - * Copyright (c) 2020-present, Jaguar0625, gimre, BloodyRookie. - * All rights reserved. - * - * This file is part of Catapult. - * - * Catapult is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Catapult is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with Catapult. If not, see . - */ - -const cmcUtils = require('../../../src/plugins/cmc/cmcUtils'); -const { expect } = require('chai'); - -describe('cmc utils', () => { - it('convertToRelative', () => { - // Arrange: - const absoluteAmout = '9000000000000000'; - const relativeAmount = '9000000000.000000'; - - // Act: - const converted = cmcUtils.convertToRelative(absoluteAmout); - // Assert: - expect(converted).equal(relativeAmount); - }); -}); diff --git a/rest/test/plugins/cmc/cmc_spec.js b/rest/test/plugins/cmc/cmc_spec.js deleted file mode 100644 index b36c76a17..000000000 --- a/rest/test/plugins/cmc/cmc_spec.js +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Copyright (c) 2016-2019, Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. - * Copyright (c) 2020-present, Jaguar0625, gimre, BloodyRookie. - * All rights reserved. - * - * This file is part of Catapult. - * - * Catapult is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Catapult is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with Catapult. If not, see . - */ - -const CmcDb = require('../../../src/plugins/cmc/CmcDb'); -const cmc = require('../../../src/plugins/cmc/cmc'); -const { test } = require('../../routes/utils/routeTestUtils'); -const pluginTest = require('../utils/pluginTestUtils'); - -describe('cmc plugin', () => { - pluginTest.assertThat.pluginCreatesDb(cmc, CmcDb); - pluginTest.assertThat.pluginDoesNotRegisterAdditionalTransactionStates(cmc); - pluginTest.assertThat.pluginDoesNotRegisterAdditionalMessageChannels(cmc); - - describe('register routes', () => { - it('registers GET routes', () => { - // Arrange: - const routes = []; - const server = test.setup.createCapturingMockServer('get', routes); - - // Act: - cmc.registerRoutes(server, {}); - - // Assert: - test.assert.assertRoutes(routes, [ - '/network/currency/supply/circulating', - '/network/currency/supply/total', - '/network/currency/supply/max' - ]); - }); - }); -}); diff --git a/rest/test/plugins/mosaic/mosaic_spec.js b/rest/test/plugins/mosaic/mosaic_spec.js index 5ed434b79..c7170c77e 100644 --- a/rest/test/plugins/mosaic/mosaic_spec.js +++ b/rest/test/plugins/mosaic/mosaic_spec.js @@ -42,7 +42,10 @@ describe('mosaic plugin', () => { test.assert.assertRoutes(routes, [ '/mosaics', '/mosaics/:mosaicId', - '/mosaics/:mosaicId/merkle' + '/mosaics/:mosaicId/merkle', + '/network/currency/supply/circulating', + '/network/currency/supply/total', + '/network/currency/supply/max' ]); }); diff --git a/rest/test/plugins/cmc/cmcRoutes_spec.js b/rest/test/plugins/mosaic/supplyRoutes_spec.js similarity index 87% rename from rest/test/plugins/cmc/cmcRoutes_spec.js rename to rest/test/plugins/mosaic/supplyRoutes_spec.js index dddd30f95..28adcb7bc 100644 --- a/rest/test/plugins/cmc/cmcRoutes_spec.js +++ b/rest/test/plugins/mosaic/supplyRoutes_spec.js @@ -20,15 +20,14 @@ */ const { convertToLong } = require('../../../src/db/dbUtils'); -const cmcRoutes = require('../../../src/plugins/cmc/cmcRoutes'); -const cmcUtils = require('../../../src/plugins/cmc/cmcUtils'); +const supplyRoutes = require('../../../src/plugins/mosaic/supplyRoutes'); const { MockServer } = require('../../routes/utils/routeTestUtils'); const catapult = require('catapult-sdk'); const { expect } = require('chai'); const sinon = require('sinon'); const fs = require('fs'); -describe('cmc routes', () => { +describe('supply routes', () => { describe('network currency supply', () => { const maxSupply = 9000000000000000; const xymSupply = 8998999998000000; @@ -97,7 +96,7 @@ describe('cmc routes', () => { uncirculatingAccountPublicKeys: [uncirculatingAccountPublicKey1, uncirculatingAccountPublicKey2] } }; - cmcRoutes.register(mockServer.server, db, services); + supplyRoutes.register(mockServer.server, db, services); const req = { params: {} }; @@ -108,6 +107,7 @@ describe('cmc routes', () => { }); describe('GET', () => { + // Arrange: it('network currency supply circulating (without burns)', () => { sinon.stub(fs, 'readFile').callsFake((path, data, callback) => callback(null, [ @@ -123,13 +123,12 @@ describe('cmc routes', () => { return mockServer.callRoute(route, req).then(() => { // Assert: expect(mockServer.next.calledOnce).to.equal(true); - - const expectedSupply = mosaicsSample[0].mosaic.supply - 0; - expect(mockServer.send.firstCall.args[0]).to.equal(cmcUtils.convertToRelative(expectedSupply)); + expect(mockServer.send.firstCall.args[0]).to.equal('8998999998000.000'); }); }); it('network currency supply circulating (with burns)', () => { + // Arrange: sinon.stub(fs, 'readFile').callsFake((path, data, callback) => callback(null, [ '[network]', @@ -144,13 +143,12 @@ describe('cmc routes', () => { return mockServer.callRoute(route, req).then(() => { // Assert: expect(mockServer.next.calledOnce).to.equal(true); - - const expectedSupply = mosaicsSample[0].mosaic.supply - 11000000; - expect(mockServer.send.firstCall.args[0]).to.equal(cmcUtils.convertToRelative(expectedSupply)); + expect(mockServer.send.firstCall.args[0]).to.equal('8998999987000.000'); }); }); it('network currency supply total', () => { + // Arrange: sinon.stub(fs, 'readFile').callsFake((path, data, callback) => callback(null, `[chain]\ncurrencyMosaicId = ${currencyMosaicId}`)); @@ -160,13 +158,14 @@ describe('cmc routes', () => { return mockServer.callRoute(route, req).then(() => { // Assert: expect(mockServer.next.calledOnce).to.equal(true); - expect(mockServer.send.firstCall.args[0]).to.equal(cmcUtils.convertToRelative(mosaicsSample[0].mosaic.supply)); + expect(mockServer.send.firstCall.args[0]).to.equal('8998999998000.000'); }); }); it('network currency supply max', () => { + // Arrange: sinon.stub(fs, 'readFile').callsFake((path, data, callback) => - callback(null, `[chain]\nmaxMosaicAtomicUnits = ${maxSupply}`)); + callback(null, `[chain]\ncurrencyMosaicId = ${currencyMosaicId}\nmaxMosaicAtomicUnits = ${maxSupply}`)); const route = mockServer.getRoute('/network/currency/supply/max').get(); @@ -174,7 +173,7 @@ describe('cmc routes', () => { return mockServer.callRoute(route, req).then(() => { // Assert: expect(mockServer.next.calledOnce).to.equal(true); - expect(mockServer.send.firstCall.args[0]).to.equal(cmcUtils.convertToRelative(maxSupply)); + expect(mockServer.send.firstCall.args[0]).to.equal('9000000000000.000'); }); }); }); diff --git a/rest/test/plugins/routeSystem_spec.js b/rest/test/plugins/routeSystem_spec.js index 1143cbb10..08db93438 100644 --- a/rest/test/plugins/routeSystem_spec.js +++ b/rest/test/plugins/routeSystem_spec.js @@ -49,8 +49,7 @@ describe('route system', () => { 'namespace', 'receipts', 'restrictions', - 'transfer', - 'cmc' + 'transfer' ]); });