From f75be6473a0212d120998d015be76a5f17a81ce3 Mon Sep 17 00:00:00 2001 From: AbigailDeng Date: Wed, 21 Aug 2024 15:47:17 +0800 Subject: [PATCH] feat: extract endpoint --- README.md | 2 +- jest-report.xml | 408 +++++++++--------- jest.browser.config.js | 8 +- jest.node.config.js | 12 +- test/unit/chain/chainMethod.test.js | 11 +- test/unit/constant.js | 2 + test/unit/contract/index.test.js | 60 ++- test/unit/index.test.js | 12 +- test/unit/util/httpProvider.browser-test.js | 295 ++++--------- test/unit/util/httpProvider.data.js | 30 +- .../unit/util/httpProvider.fetch.node-test.js | 60 ++- test/unit/util/httpProvider.node-test.js | 117 ++--- test/unit/util/proto.test.js | 132 +++--- test/unit/util/requestManage.test.js | 77 ++-- test/unit/util/transform.test.js | 164 +++---- 15 files changed, 567 insertions(+), 823 deletions(-) create mode 100644 test/unit/constant.js diff --git a/README.md b/README.md index 591bdf83..1aa300d5 100644 --- a/README.md +++ b/README.md @@ -17,7 +17,7 @@ +| ![Statements](https://img.shields.io/badge/statements-97.88%25-brightgreen.svg?style=flat) | ![Branches](https://img.shields.io/badge/branches-95.1%25-brightgreen.svg?style=flat) | ![Functions](https://img.shields.io/badge/functions-98.61%25-brightgreen.svg?style=flat) | ![Lines](https://img.shields.io/badge/lines-97.89%25-brightgreen.svg?style=flat) | --> ## 1. Introduction diff --git a/jest-report.xml b/jest-report.xml index 5c60d650..821f898b 100644 --- a/jest-report.xml +++ b/jest-report.xml @@ -1,137 +1,137 @@ - - - + + + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - - + + - + - + - + - + - + - + - + - + - + + + - + - + - - - + - + - + - + - + - + - + - + - + - - + + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + @@ -141,59 +141,59 @@ - + - + - - + + - + - + - + - + - + - + - + - + - + - + - + - - + + - + - + @@ -201,27 +201,27 @@ - + - + - + - + - + - + - + @@ -229,181 +229,181 @@ - + - + - + - - + + - + - - + + - + - - + + - + - + + + - + - + - + - + - - + + - + - + - + - + - - - + - + - - + + - + - - + + - - + + - + - + - + - + - + - - + + - + - - + + - + - + - + - + - + - + - - + + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - - + + @@ -411,29 +411,29 @@ - + - + - + - + - + - + - + - + - + - - + + @@ -441,57 +441,57 @@ - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + \ No newline at end of file diff --git a/jest.browser.config.js b/jest.browser.config.js index 15775a5e..d4ace5c4 100644 --- a/jest.browser.config.js +++ b/jest.browser.config.js @@ -48,7 +48,7 @@ module.exports = { // ], // A list of reporter names that Jest uses when writing coverage reports - coverageReporters: ['text', 'json-summary'], + coverageReporters: ['text', 'json-summary', 'html'], // coverageReporters: [ // "json", // "text", @@ -104,7 +104,7 @@ module.exports = { // A map from regular expressions to module names that allow to stub out resources with a single module moduleNameMapper: { - '^randombytes$': '/node_modules/randombytes/index.js', + '^randombytes$': '/node_modules/randombytes/index.js' }, // An array of regexp pattern strings, matched against all module paths before considered 'visible' to the module loader @@ -202,8 +202,8 @@ module.exports = { // A map from regular expressions to paths to transformers transform: { - '^.+\\.js?$': 'babel-jest', - }, + '^.+\\.js?$': 'babel-jest' + } // An array of regexp pattern strings that are matched against all source file paths, matched files will skip transformation // transformIgnorePatterns: [ diff --git a/jest.node.config.js b/jest.node.config.js index 926a287c..774ce175 100644 --- a/jest.node.config.js +++ b/jest.node.config.js @@ -37,7 +37,7 @@ module.exports = { '!**/examples/**', '!**/dist/**', '!**/script/**', - '!**/build/**', + '!**/build/**' ], // An array of regexp pattern strings used to skip coverage collection @@ -46,7 +46,7 @@ module.exports = { // ], // A list of reporter names that Jest uses when writing coverage reports - coverageReporters: ['text', 'json-summary'], + coverageReporters: ['text', 'json-summary', 'html'], // coverageReporters: [ // "json", // "text", @@ -90,7 +90,7 @@ module.exports = { // A map from regular expressions to module names that allow to stub out resources with a single module moduleNameMapper: { - '^scryptsy$': path.resolve('src/scrypt-polyfill.js'), + '^scryptsy$': path.resolve('src/scrypt-polyfill.js') }, // An array of regexp pattern strings, matched against all module paths before considered 'visible' to the module loader @@ -156,7 +156,7 @@ module.exports = { testMatch: [ '**/test/unit/**/?(*.)+(test).[jt]s?(x)', '**/test/unit/util/httpProvider.node-test.js', - '**/test/unit/util/httpProvider.fetch.node-test.js', + '**/test/unit/util/httpProvider.fetch.node-test.js' ], testTimeout: 20000, @@ -182,8 +182,8 @@ module.exports = { // A map from regular expressions to paths to transformers transform: { - '^.+\\.js?$': 'babel-jest', - }, + '^.+\\.js?$': 'babel-jest' + } // An array of regexp pattern strings that are matched against all source file paths, matched files will skip transformation // transformIgnorePatterns: [ diff --git a/test/unit/chain/chainMethod.test.js b/test/unit/chain/chainMethod.test.js index 3ddc8ee5..676f1046 100644 --- a/test/unit/chain/chainMethod.test.js +++ b/test/unit/chain/chainMethod.test.js @@ -3,6 +3,7 @@ import ChainMethod from '../../../src/chain/chainMethod'; import { inputAddressFormatter, outputFileDescriptorSetFormatter } from '../../../src/util/formatters'; import HttpProvider from '../../../src/util/httpProvider'; import RequestManager from '../../../src/util/requestManage'; +import { tdvwEndPoint } from '../constant'; describe('chainMethod should work', () => { test('test format input params with no inputFormatter', () => { @@ -128,11 +129,11 @@ describe('chainMethod should work', () => { name: 'getChainStatus', call: 'blockChain/chainStatus' }); - const httpProvider = new HttpProvider('https://aelf-public-node.aelf.io'); + const httpProvider = new HttpProvider(tdvwEndPoint); const manager = new RequestManager(httpProvider); chainMethod.setRequestManager(manager); const result = chainMethod.run({ sync: true }); - expect(result.ChainId).toEqual('AELF'); + expect(result.ChainId).toEqual('tDVW'); }); test('test fn argument when async', async () => { const chainMethod = new ChainMethod({ @@ -141,12 +142,12 @@ describe('chainMethod should work', () => { method: 'GET', params: [] }); - const httpProvider = new HttpProvider('https://aelf-public-node.aelf.io'); + const httpProvider = new HttpProvider(tdvwEndPoint); const manager = new RequestManager(httpProvider); chainMethod.setRequestManager(manager); const fn = jest.fn(); const result = await chainMethod.run(fn); - expect(result.ChainId).toEqual('AELF'); + expect(result.ChainId).toEqual('tDVW'); expect(fn).toHaveBeenCalled(); expect(fn).toHaveBeenCalledWith(null, result); }); @@ -157,7 +158,7 @@ describe('chainMethod should work', () => { method: 'GET', params: ['transactionId'] }); - const httpProvider = new HttpProvider('https://aelf-public-node.aelf.io'); + const httpProvider = new HttpProvider(tdvwEndPoint); const manager = new RequestManager(httpProvider); chainMethod.setRequestManager(manager); // mock diff --git a/test/unit/constant.js b/test/unit/constant.js new file mode 100644 index 00000000..7c1c34c0 --- /dev/null +++ b/test/unit/constant.js @@ -0,0 +1,2 @@ +export const aelfEndPoint = 'https://aelf-test-node.aelf.io'; +export const tdvwEndPoint = 'https://tdvw-test-node.aelf.io'; diff --git a/test/unit/contract/index.test.js b/test/unit/contract/index.test.js index a24214d0..07452340 100644 --- a/test/unit/contract/index.test.js +++ b/test/unit/contract/index.test.js @@ -1,12 +1,12 @@ import ContractFactory from '../../../src/contract/index'; -const stageEndpoint = 'https://tdvw-test-node.aelf.io'; import AElf from '../../../src/index'; +import { tdvwEndPoint } from '../constant'; describe('contract factory', () => { - const aelf = new AElf(new AElf.providers.HttpProvider(stageEndpoint)); + const aelf = new AElf(new AElf.providers.HttpProvider(tdvwEndPoint)); const chain = aelf.chain; const address = 'ELF_2sGZFRtqQ57F55Z2KvhmoozKrf7ik2htNVQawEAo3Vyvcx9Qwr_tDVW'; const fds = chain.getContractFileDescriptorSet(address, { - sync: true, + sync: true }); const factory = new ContractFactory(chain, fds, AElf.wallet); test('constrcutor', () => { @@ -34,8 +34,8 @@ describe('contract factory', () => { Address: 'ELF_2sGZFRtqQ57F55Z2KvhmoozKrf7ik2htNVQawEAo3Vyvcx9Qwr_tDVW', Name: '.aelf.Hash', Indexed: null, - NonIndexed: 'CgNFTEYQoI/hGQ==', - }, + NonIndexed: 'CgNFTEYQoI/hGQ==' + } ]; const contractInstance = factory.at(address); const result = contractInstance.deserializeLog(Logs, '.aelf.Hash'); @@ -52,29 +52,23 @@ describe('contract factory', () => { 'EiIKIAR/b9iJa/+kT2+h9XAdQE0UX9wFZogfPtn9YvtlCnB2', 'GiIKICeR6ZKlfyjnWhHxOvLArsiw6zXS8EjULrqJAckuA3jc', 'IghUcmFuc2Zlcg==', - 'MiIKICWmXUMWhKDuXFdYz8/uF7ze4kC5r3i7boxM5Dj+RE4G', + 'MiIKICWmXUMWhKDuXFdYz8/uF7ze4kC5r3i7boxM5Dj+RE4G' ], - NonIndexed: - 'KjAKIgogIKCTibOwFJNFp0zUNEXymkyazYKz8LLwLqOZxEqKRF0SA09NSRiA0NvD9AI=', - }, + NonIndexed: 'KjAKIgogIKCTibOwFJNFp0zUNEXymkyazYKz8LLwLqOZxEqKRF0SA09NSRiA0NvD9AI=' + } ]; - const contractInstance = factory.at( - '238X6iw1j8YKcHvkDYVtYVbuYk2gJnK8UoNpVCtssynSpVC8hb' - ); - const result = contractInstance.deserializeLog( - Logs, - 'VirtualTransactionCreated' - ); - expect(result).toEqual( - [{ - "from": "2ytdtA2PDX7VLYWkqf36MQQ8wUtcXWRdpovX7Wxy8tJZXumaY", - "methodName": "Transfer", - "params": "CiIKICCgk4mzsBSTRadM1DRF8ppMms2Cs/Cy8C6jmcRKikRdEgNPTUkYgNDbw/QC", - "signatory": "HaiUnezHpBieiVZNuyQV4uLFspYDGxsEwt8wSFYqGSpXY3CzJ", - "to": "JRmBduh4nXWi1aXgdUsj5gJrzeZb2LxmrAbf7W99faZSvoAaE", - "virtualHash": "0f09d38a4b246347978cb6296b81262a5d5e3b49d85a2bad2451b91c7dc362d8", - }] - ); + const contractInstance = factory.at('238X6iw1j8YKcHvkDYVtYVbuYk2gJnK8UoNpVCtssynSpVC8hb'); + const result = contractInstance.deserializeLog(Logs, 'VirtualTransactionCreated'); + expect(result).toEqual([ + { + from: '2ytdtA2PDX7VLYWkqf36MQQ8wUtcXWRdpovX7Wxy8tJZXumaY', + methodName: 'Transfer', + params: 'CiIKICCgk4mzsBSTRadM1DRF8ppMms2Cs/Cy8C6jmcRKikRdEgNPTUkYgNDbw/QC', + signatory: 'HaiUnezHpBieiVZNuyQV4uLFspYDGxsEwt8wSFYqGSpXY3CzJ', + to: 'JRmBduh4nXWi1aXgdUsj5gJrzeZb2LxmrAbf7W99faZSvoAaE', + virtualHash: '0f09d38a4b246347978cb6296b81262a5d5e3b49d85a2bad2451b91c7dc362d8' + } + ]); expect(contractInstance.deserializeLog()).toEqual([]); }); test('test deserialize log with normal contract which has a method called VirtualTransactionCreated', () => { @@ -83,8 +77,8 @@ describe('contract factory', () => { Address: 'ELF_2sGZFRtqQ57F55Z2KvhmoozKrf7ik2htNVQawEAo3Vyvcx9Qwr_tDVW', Name: 'VirtualTransactionCreated', Indexed: null, - NonIndexed: 'CgNFTEYQoI/hGQ==', - }, + NonIndexed: 'CgNFTEYQoI/hGQ==' + } ]; const contractInstance = factory.at(address); expect(() => contractInstance.deserializeLog(Logs, 'VirtualTransactionCreated')).toThrow(); @@ -99,16 +93,14 @@ describe('contract factory', () => { { Indexed: [ 'CiIKIPoq3y6L7T71F5BynCBXISeMFKrCt4QayljkLE4U8St4', - 'EiIKIKt0P1P3+jKuU4Y5rSGOfzleHFw0YXn5eNM88jWfUWYR', + 'EiIKIKt0P1P3+jKuU4Y5rSGOfzleHFw0YXn5eNM88jWfUWYR' ], Name: '.aelf.Hash', - Address: 'ELF_2sGZFRtqQ57F55Z2KvhmoozKrf7ik2htNVQawEAo3Vyvcx9Qwr_tDVW', - }, + Address: 'ELF_2sGZFRtqQ57F55Z2KvhmoozKrf7ik2htNVQawEAo3Vyvcx9Qwr_tDVW' + } ]; const contractInstance = factory.at(address); const result = contractInstance.deserializeLog(Logs, '.aelf.Hash'); - expect(result).toEqual([ - '0a20fa2adf2e8bed3ef51790729c205721278c14aac2b7841aca58e42c4e14f12b78', - ]); + expect(result).toEqual(['0a20fa2adf2e8bed3ef51790729c205721278c14aac2b7841aca58e42c4e14f12b78']); }); }); diff --git a/test/unit/index.test.js b/test/unit/index.test.js index c12eaac4..e53ec601 100644 --- a/test/unit/index.test.js +++ b/test/unit/index.test.js @@ -1,16 +1,14 @@ import AElf from '../../src/index'; -const stageEndpoint = 'https://tdvw-test-node.aelf.io'; +import { aelfEndPoint, tdvwEndPoint } from './constant'; describe('test AElf', () => { test('test AElf is connected', () => { - const aelf = new AElf(new AElf.providers.HttpProvider(stageEndpoint)); + const aelf = new AElf(new AElf.providers.HttpProvider(tdvwEndPoint)); const result = aelf.isConnected(); expect(result).toBeTruthy(); }); test('test AElf set provider', () => { - const aelf = new AElf( - new AElf.providers.HttpProvider('https://aelf-public-node.aelf.io') - ); - aelf.setProvider(new AElf.providers.HttpProvider(stageEndpoint)); - expect(aelf.currentProvider.host).toEqual(stageEndpoint); + const aelf = new AElf(new AElf.providers.HttpProvider(aelfEndPoint)); + aelf.setProvider(new AElf.providers.HttpProvider(tdvwEndPoint)); + expect(aelf.currentProvider.host).toEqual(tdvwEndPoint); }); }); diff --git a/test/unit/util/httpProvider.browser-test.js b/test/unit/util/httpProvider.browser-test.js index ff1a6326..49d7a081 100644 --- a/test/unit/util/httpProvider.browser-test.js +++ b/test/unit/util/httpProvider.browser-test.js @@ -1,37 +1,11 @@ require('isomorphic-fetch'); import HttpProvider from '../../../src/util/httpProvider'; -const stageEndpoint = 'https://aelf-public-node.aelf.io/'; +import { tdvwEndPoint } from '../constant'; +import { blockByHeightRes } from './httpProvider.data'; // for test timeout jest.useFakeTimers(); jest.spyOn(global, 'setTimeout'); -const blockByHeightRes = { - BlockHash: 'f8bd119ae0a2a93913ad5104143cae05f71c9f4674b44462cfb39acf6e42f76d', - Header: { - PreviousBlockHash: - 'c9313e0db7962002df1ce90b367415c12be3ba0c963f864fe0f331c6a9af1294', - MerkleTreeRootOfTransactions: - '46d2955581d0d276fa42cd4928fd85a7c9935d4060b61afbebd5532008ad5b29', - MerkleTreeRootOfWorldState: - 'd3306b3f048fd26f62249e7ba9c9c04560abb41ec1581a4efc046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AAAAAAAAAAAAAAAAAAAAAAAABAAAAAAAAAAAAAAAAAAAAAAAAAAEAAAAAAAAAAAAAAAAAAAAAAAAAAAIAAACAABAAAAAAAAAAAAAAAAAAAAAAAAACACAAAAAAAAAAAAAAAAAAAAAAABAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAEAAAAAAAAAAAAAAAAAEAAAAAAAAAAAAAAAABAAAAAAgAAAAABAAAAAgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAEAAAAgAAAAAAAAAAAAAAAA==', - SignerPubkey: - '04f34af28e68d7c9bcfc7a9797a4d894ee9a9d3d142e275cd254b6495ed7ec95f95411c9819950c23c36fd00a2c610947487bd6e0b3e3ed8d2c90f089fa4f0c02a', - }, - Body: { - TransactionsCount: 2, - Transactions: [], - }, - BlockSize: 3589, -}; describe('test httpProvider', () => { beforeEach(() => { jest.resetModules(); @@ -41,23 +15,19 @@ describe('test httpProvider', () => { expect(httpProvider.host).toBe('http://localhost:8545'); }); test('test headers are Array', () => { - const httpProvider = new HttpProvider(stageEndpoint, 8000, [ + const httpProvider = new HttpProvider(tdvwEndPoint, 8000, [ { name: 'Last-Modified', - value: 'Wed, 21 Oct 2015 07:28:00 GMT', - }, + value: 'Wed, 21 Oct 2015 07:28:00 GMT' + } ]); - expect(httpProvider.headers['Last-Modified']).toEqual( - 'Wed, 21 Oct 2015 07:28:00 GMT' - ); + expect(httpProvider.headers['Last-Modified']).toEqual('Wed, 21 Oct 2015 07:28:00 GMT'); }); test('test headers are Object', () => { - const httpProvider = new HttpProvider(stageEndpoint, 8000, { - 'Last-Modified': 'Wed, 21 Oct 2015 07:28:00 GMT', + const httpProvider = new HttpProvider(tdvwEndPoint, 8000, { + 'Last-Modified': 'Wed, 21 Oct 2015 07:28:00 GMT' }); - expect(httpProvider.headers['Last-Modified']).toEqual( - 'Wed, 21 Oct 2015 07:28:00 GMT' - ); + expect(httpProvider.headers['Last-Modified']).toEqual('Wed, 21 Oct 2015 07:28:00 GMT'); }); test('test format response when can parse to JSON', () => { const response = HttpProvider.formatResponse('{"ok":true,"status":200}'); @@ -70,18 +40,18 @@ describe('test httpProvider', () => { test('test format response text with status and statusText', () => { const response = HttpProvider.formatResponseText({ status: 500, - statusText: 'server error', + statusText: 'server error' }); expect(response).toEqual({ Error: { message: 'server error' }, error: 500, status: 500, - statusText: 'server error', + statusText: 'server error' }); }); test('test format response text with status 200', () => { const response = HttpProvider.formatResponseText({ - status: 200, + status: 200 }); expect(response.error).toEqual(0); }); @@ -91,7 +61,7 @@ describe('test httpProvider', () => { Error: { message: undefined }, error: undefined, status: undefined, - statusText: undefined, + statusText: undefined }); }); test('test format response text when error', () => { @@ -106,108 +76,50 @@ describe('test httpProvider', () => { return expect(p).resolves.toEqual({ type: 'timeout' }); }); test('test get request send by fetch', async () => { - const httpProvider = new HttpProvider(stageEndpoint); + const httpProvider = new HttpProvider(tdvwEndPoint); const response = await httpProvider.requestSendByFetch( { url: 'blockChain/blockByHeight', method: 'GET', params: { - blockHeight: 43143609, - }, + blockHeight: 134573331 + } }, fetch ); const result = await response.text(); - expect(JSON.parse(result)).toEqual({ - BlockHash: - 'a09208b234f667329fb51e42be085f20f86bfcd9ddd7ce4d98d24bdb3d610bfc', - Header: { - PreviousBlockHash: - '40105e35140c2884148ee4d7dce5d7867850f165c6da44265787b377784e99d8', - MerkleTreeRootOfTransactions: - '1c9b53dbd5f42ccceca7c10215867874986e3a75f1d0279fd8f6a152f98e18f8', - MerkleTreeRootOfWorldState: - 'abf773002dbc0aa29e64064e6773bfe51cf23951adf4cb5bd3eda760a760a409', - MerkleTreeRootOfTransactionState: - 'c4084bd442913ba4b05f4552f3532755ccd23719fe381d5b97f10775f476f6c8', - Extra: - '{ "CrossChain": "", "Consensus": "CkEEWXakIxZReEEb+GIDju1ttbFuBKqigwGmHH7jPhl/Pppe16l10NTsk22Bu4ErYSm68mBE6TdS6O5QjXzKWph2eBK3BwjlgzgSggMKggEwNDU5NzZhNDIzMTY1MTc4N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mNDdmMmVlZDIwOTY2ZmQ2N2USABKHAQqCATA0NzQyNjZiMTczZWJjZmZjZTQ5MWE1MjY3ZjhjZDdhZDc4ZTg4ODQzYzc3NjhhZDdkOWNmMTM3ZGJjMWQ3Njg5OTY2ZWI0OWE1MmUwYTcwNDA5OGZjMGRkNmM5NjhkZDE1YzM2YTUzN2Y0ZTU5OGNjYzdiZmY0OTYwZjA2ZWEzYTUSAFCQ26etHhgE", "SystemTransactionCount": "CAI=" }', - Height: 43143609, - Time: '2021-08-22T07:27:04.6680186Z', - ChainId: 'AELF', - Bloom: - 'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA==', - SignerPubkey: - '045976a423165178411bf862038eed6db5b16e04aaa28301a61c7ee33e197f3e9a5ed7a975d0d4ec936d81bb812b6129baf26044e93752e8ee508d7cca5a987678', - }, - Body: { - TransactionsCount: 2, - Transactions: [], - }, - BlockSize: 1467, - }); + expect(JSON.parse(result)).toEqual(blockByHeightRes); }); test('test post request send by fetch', async () => { - const httpProvider = new HttpProvider(stageEndpoint); + const httpProvider = new HttpProvider(tdvwEndPoint); const response = await httpProvider.requestSendByFetch( { - url: 'blockChain/calculateTransactionFee', + url: 'blockChain/executeTransaction', params: { RawTransaction: - '0a220a2005c3b3959caeee55b5db4004f6f9d76860aae818ce7b33d210a446ecb275468212220a200e9a238616169860ba4fb502f8e87ce62db9ef321f29fd76d6e1ce30a0e0cdba18a8a19e022204fa60011c2a085472616e73666572322e0a220a200e9a238616169860ba4fb502f8e87ce62db9ef321f29fd76d6e1ce30a0e0cdba1203454c461880c2d72f82f10441ad1647aa462a8859c7a699f22d6124c82a5239c90746ac67ebfd8e1a7b4a25f343733351162d205fc881ea62072e9fe0fad5f6113734309b6666f6812d6b7a6400', - }, + '0a220a203000800ce18e6de0fc576a48759d9dc90a23f0ded388316b0f9f1274a45b809b12220a202ec3700300ef9c95ee67a20a35dad35b8b0d476533e009a746b015df7d051e2d2a1c43616c63756c6174654f7267616e697a6174696f6e4164647265737332560a240a220a2024447d28d0da2f7923a917a4176214032541bda3d0d1a4c8195f3ecccc034fc7120808011000180020011a240a220a2024447d28d0da2f7923a917a4176214032541bda3d0d1a4c8195f3ecccc034fc782f104417582ebfba9506ec499b4ac36653f0c8feefa66d32eb0cd88ed4a608187c85fea75e37405c37de7d9bf3ae03745ae6768da908aad3c0e10b1c48b0de321ad5d7201' + } }, fetch ); const result = await response.text(); - expect(JSON.parse(result)).toMatchObject({ - Success: false, - TransactionFee: null, - ResourceFee: null, - }); + expect(result).toEqual('0a20b2506d0e6a6f4901b85a4a9a57f30dc7acf95b9feba037566baedaf450a3b7be'); }); test('test send async by fetch', async () => { const xhr = window.XMLHttpRequest; delete window.XMLHttpRequest; window.fetch = fetch; const NewHttpProvider = require('../../../src/util/httpProvider').default; - const httpProvider = new NewHttpProvider(stageEndpoint); + const httpProvider = new NewHttpProvider(tdvwEndPoint); window.XMLHttpRequest = xhr; const result = await httpProvider.sendAsyncByFetch({ url: 'blockChain/blockByHeight', method: 'GET', params: { - blockHeight: 43143609, - }, - }); - expect(result).toEqual({ - BlockHash: - 'a09208b234f667329fb51e42be085f20f86bfcd9ddd7ce4d98d24bdb3d610bfc', - Header: { - PreviousBlockHash: - '40105e35140c2884148ee4d7dce5d7867850f165c6da44265787b377784e99d8', - MerkleTreeRootOfTransactions: - '1c9b53dbd5f42ccceca7c10215867874986e3a75f1d0279fd8f6a152f98e18f8', - MerkleTreeRootOfWorldState: - 'abf773002dbc0aa29e64064e6773bfe51cf23951adf4cb5bd3eda760a760a409', - MerkleTreeRootOfTransactionState: - 'c4084bd442913ba4b05f4552f3532755ccd23719fe381d5b97f10775f476f6c8', - Extra: - '{ "CrossChain": "", "Consensus": "CkEEWXakIxZReEEb+GIDju1ttbFuBKqigwGmHH7jPhl/Pppe16l10NTsk22Bu4ErYSm68mBE6TdS6O5QjXzKWph2eBK3BwjlgzgSggMKggEwNDU5NzZhNDIzMTY1MTc4NDExYmY4NjIwMzhlZWQ2ZGI1YjE2ZTA0YWFhMjgzMDFhNjFjN2VlMzNlMTk3ZjNlOWE1ZWQ3YTk3NWQwZDRlYzkzNmQ4MWJiODEyYjYxMjliYWYyNjA0NGU5Mzc1MmU4ZWU1MDhkN2NjYTVhOTg3Njc4EvoBONyXBkqCATA0NTk3NmE0MjMxNjUxNzg0MTFiZjg2MjAzOGVlZDZkYjViMTZlMDRhYWEyODMwMWE2MWM3ZWUzM2UxOTdmM2U5YTVlZDdhOTc1ZDBkNGVjOTM2ZDgxYmI4MTJiNjEyOWJhZjI2MDQ0ZTkzNzUyZThlZTUwOGQ3Y2NhNWE5ODc2NzhqBgjI+IeJBmoLCMj4h4kGEOi0kDBqCwjI+IeJBhDYsbtcagwIyPiHiQYQtIr0iQFqDAjI+IeJBhCEnMW3AWoMCMj4h4kGEKTsyeUBagwIyPiHiQYQ+MHHkQJqDAjI+IeJBhCoz8S+AoABCIgBsqPJFBKHAQqCATA0YzFiNGE3NWZkOWJhMzdlMGE4NGI5OTE2ZTUxN2U5YzU5MWM1YjllZmFjYWJmMWZlYjFhM2QzNGYzODkyMGEyNTA0NTRkYzlkY2UwZjgxMTk1NmQyMTA4MDRjOTA0OTU5YmU5NmE3NWE5ZDliMTQxMGFhMjVmN2Q5ZTFiNmY2OWMSABKHAQqCATA0YjZhODA2NTRhZGQxMmEyYzFhMTg1MGQwZTQ5MmUyNWVlMjE1MmJmZjNiNWVlOGFmZjUwZmVlYjJhYjA3YmViOWQxMmExNGVlOTc1OWQ1ZDBjY2IyYjU2NTYxMWY2MGZiMTFjZjFhMTk4YTQ2NjdkZjYyZDVkY2Y4MWNhZDMyMTQSABKHAQqCATA0YjI5YTQ3YjQ0N2YyM2JkZWE4OGQ0YzFlZTBiY2QwMmNmNWE3NTcyZWQ1ZmJhNTMwYzJkMmJjMzg4YjhmN2M4ZjVkZWRlYjYyZTE1MmQ1NTg0M2JiOTAxMjAxMzM0MzZjMGNhZmRkNWRhODQyYTBmNDdmMmVlZDIwOTY2ZmQ2N2USABKHAQqCATA0NzQyNjZiMTczZWJjZmZjZTQ5MWE1MjY3ZjhjZDdhZDc4ZTg4ODQzYzc3NjhhZDdkOWNmMTM3ZGJjMWQ3Njg5OTY2ZWI0OWE1MmUwYTcwNDA5OGZjMGRkNmM5NjhkZDE1YzM2YTUzN2Y0ZTU5OGNjYzdiZmY0OTYwZjA2ZWEzYTUSAFCQ26etHhgE", "SystemTransactionCount": "CAI=" }', - Height: 43143609, - Time: '2021-08-22T07:27:04.6680186Z', - ChainId: 'AELF', - Bloom: - 'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA==', - SignerPubkey: - '045976a423165178411bf862038eed6db5b16e04aaa28301a61c7ee33e197f3e9a5ed7a975d0d4ec936d81bb812b6129baf26044e93752e8ee508d7cca5a987678', - }, - Body: { - TransactionsCount: 2, - Transactions: [], - }, - BlockSize: 1467, + blockHeight: 134573331 + } }); + expect(result).toEqual(blockByHeightRes); }); test('test send async by fetch when no AbortController', async () => { const xhr = window.XMLHttpRequest; @@ -217,20 +129,20 @@ describe('test httpProvider', () => { const originFetch = fetch; window.fetch = jest.fn(() => Promise.resolve({ - type: 'timeout', + type: 'timeout' }) ); const NewHttpProvider = require('../../../src/util/httpProvider').default; - const httpProvider = new NewHttpProvider(stageEndpoint); + const httpProvider = new NewHttpProvider(tdvwEndPoint); window.XMLHttpRequest = xhr; window.fetch = originFetch; await expect( httpProvider.sendAsyncByFetch({ url: 'blockChain/blockHeight', - method: 'GET', + method: 'GET' }) ).rejects.toEqual({ - type: 'timeout', + type: 'timeout' }); global.AbortController = abortController; }); @@ -239,15 +151,15 @@ describe('test httpProvider', () => { delete window.XMLHttpRequest; window.fetch = fetch; const NewHttpProvider = require('../../../src/util/httpProvider').default; - const httpProvider = new NewHttpProvider(stageEndpoint); + const httpProvider = new NewHttpProvider(tdvwEndPoint); window.XMLHttpRequest = xhr; await expect( httpProvider.sendAsyncByFetch({ url: 'blockChain/executeTransaction', method: 'POST', params: { - RawTransaction: '111', - }, + RawTransaction: '111' + } }) ).rejects.toEqual({ Error: { @@ -255,8 +167,8 @@ describe('test httpProvider', () => { Message: 'Invalid params', Details: null, Data: {}, - ValidationErrors: null, - }, + ValidationErrors: null + } }); }); test('test send async by fetch without result.text', async () => { @@ -265,17 +177,17 @@ describe('test httpProvider', () => { const originFetch = fetch; window.fetch = jest.fn(() => Promise.resolve({ - ok: false, + ok: false }) ); const NewHttpProvider = require('../../../src/util/httpProvider').default; - const httpProvider = new NewHttpProvider(stageEndpoint); + const httpProvider = new NewHttpProvider(tdvwEndPoint); window.XMLHttpRequest = xhr; window.fetch = originFetch; await expect( httpProvider.sendAsyncByFetch({ url: 'blockChain/blockHeight', - method: 'GET', + method: 'GET' }) ).rejects.toEqual(TypeError('result.text is not a function')); }); @@ -286,17 +198,17 @@ describe('test httpProvider', () => { window.fetch = jest.fn(() => Promise.resolve({ ok: false, - text: () => Promise.reject('failed when reject'), + text: () => Promise.reject('failed when reject') }) ); const NewHttpProvider = require('../../../src/util/httpProvider').default; - const httpProvider = new NewHttpProvider(stageEndpoint); + const httpProvider = new NewHttpProvider(tdvwEndPoint); window.XMLHttpRequest = xhr; window.fetch = originFetch; await expect( httpProvider.sendAsyncByFetch({ url: 'blockChain/blockHeight', - method: 'GET', + method: 'GET' }) ).rejects.toEqual('failed when reject'); }); @@ -306,20 +218,20 @@ describe('test httpProvider', () => { const originFetch = fetch; window.fetch = jest.fn(() => Promise.resolve({ - type: 'timeout', + type: 'timeout' }) ); const NewHttpProvider = require('../../../src/util/httpProvider').default; - const httpProvider = new NewHttpProvider(stageEndpoint); + const httpProvider = new NewHttpProvider(tdvwEndPoint); window.XMLHttpRequest = xhr; window.fetch = originFetch; await expect( httpProvider.sendAsyncByFetch({ url: 'blockChain/blockHeight', - method: 'GET', + method: 'GET' }) ).rejects.toEqual({ - type: 'timeout', + type: 'timeout' }); }); test('test send async by fetch when status is not 200', async () => { @@ -329,17 +241,17 @@ describe('test httpProvider', () => { window.fetch = jest.fn(() => Promise.resolve({ status: 400, - text: () => Promise.resolve('failed when status is not 200'), + text: () => Promise.resolve('failed when status is not 200') }) ); const NewHttpProvider = require('../../../src/util/httpProvider').default; - const httpProvider = new NewHttpProvider(stageEndpoint); + const httpProvider = new NewHttpProvider(tdvwEndPoint); window.XMLHttpRequest = xhr; window.fetch = originFetch; await expect( httpProvider.sendAsyncByFetch({ url: 'blockChain/blockHeight', - method: 'GET', + method: 'GET' }) ).rejects.toEqual('failed when status is not 200'); }); @@ -350,22 +262,22 @@ describe('test httpProvider', () => { window.fetch = jest.fn(() => Promise.resolve({ ok: false, - text: () => Promise.resolve('failed when result is not ok'), + text: () => Promise.resolve('failed when result is not ok') }) ); const NewHttpProvider = require('../../../src/util/httpProvider').default; - const httpProvider = new NewHttpProvider(stageEndpoint); + const httpProvider = new NewHttpProvider(tdvwEndPoint); window.XMLHttpRequest = xhr; window.fetch = originFetch; await expect( httpProvider.sendAsyncByFetch({ url: 'blockChain/blockHeight', - method: 'GET', + method: 'GET' }) ).rejects.toEqual('failed when result is not ok'); }); test('test get request send by xhr', () => { - const httpProvider = new HttpProvider(stageEndpoint); + const httpProvider = new HttpProvider(tdvwEndPoint); const RequestLibrary = window.XMLHttpRequest; const request = new RequestLibrary(); request.withCredentials = false; @@ -374,19 +286,17 @@ describe('test httpProvider', () => { url: 'blockChain/blockByHeight', method: 'GET', params: { - blockHeight: 136240697, - }, + blockHeight: 134573331 + } }, request ); const result = JSON.parse(request.responseText); - expect(result.BlockHash).toBe( - 'f8bd119ae0a2a93913ad5104143cae05f71c9f4674b44462cfb39acf6e42f76d' - ); + expect(result.BlockHash).toBe('2267716b9af2d6c306ded8eb992ce04518ec965704298c80e10df4b4e5358eb5'); }); test('test post request send by xhr', () => { - const httpProvider = new HttpProvider(stageEndpoint); + const httpProvider = new HttpProvider(tdvwEndPoint); const RequestLibrary = window.XMLHttpRequest; const request = new RequestLibrary(); request.withCredentials = false; @@ -395,8 +305,8 @@ describe('test httpProvider', () => { url: 'blockChain/calculateTransactionFee', params: { RawTransaction: - '0a220a2005c3b3959caeee55b5db4004f6f9d76860aae818ce7b33d210a446ecb275468212220a200e9a238616169860ba4fb502f8e87ce62db9ef321f29fd76d6e1ce30a0e0cdba18a8a19e022204fa60011c2a085472616e73666572322e0a220a200e9a238616169860ba4fb502f8e87ce62db9ef321f29fd76d6e1ce30a0e0cdba1203454c461880c2d72f82f10441ad1647aa462a8859c7a699f22d6124c82a5239c90746ac67ebfd8e1a7b4a25f343733351162d205fc881ea62072e9fe0fad5f6113734309b6666f6812d6b7a6400', - }, + '0a220a2005c3b3959caeee55b5db4004f6f9d76860aae818ce7b33d210a446ecb275468212220a200e9a238616169860ba4fb502f8e87ce62db9ef321f29fd76d6e1ce30a0e0cdba18a8a19e022204fa60011c2a085472616e73666572322e0a220a200e9a238616169860ba4fb502f8e87ce62db9ef321f29fd76d6e1ce30a0e0cdba1203454c461880c2d72f82f10441ad1647aa462a8859c7a699f22d6124c82a5239c90746ac67ebfd8e1a7b4a25f343733351162d205fc881ea62072e9fe0fad5f6113734309b6666f6812d6b7a6400' + } }, request ); @@ -404,7 +314,7 @@ describe('test httpProvider', () => { expect(JSON.parse(result)).toMatchObject({ Success: false, TransactionFee: null, - ResourceFee: null, + ResourceFee: null }); }); @@ -413,28 +323,26 @@ describe('test httpProvider', () => { delete window.XMLHttpRequest; window.fetch = fetch; const NewHttpProvider = require('../../../src/util/httpProvider').default; - const httpProvider = new NewHttpProvider(stageEndpoint); + const httpProvider = new NewHttpProvider(tdvwEndPoint); window.XMLHttpRequest = xhr; try { httpProvider.send({ url: 'blockChain/blockHeight', - method: 'GET', + method: 'GET' }); } catch (e) { - expect(e).toEqual( - new Error("Can not get XMLHttpRequest, invalid parameter: 'sync'") - ); + expect(e).toEqual(new Error("Can not get XMLHttpRequest, invalid parameter: 'sync'")); } }); test('test send by xhr', async () => { - const httpProvider = new HttpProvider(stageEndpoint); + const httpProvider = new HttpProvider(tdvwEndPoint); const result = httpProvider.send({ url: 'blockChain/blockByHeight', method: 'GET', params: { - blockHeight: 136240697, - }, + blockHeight: 134573331 + } }); expect(result).toEqual(blockByHeightRes); }); @@ -444,21 +352,21 @@ describe('test httpProvider', () => { send: jest.fn(), setRequestHeader: jest.fn(), responseText: { - Error: 'error xhr', - }, + Error: 'error xhr' + } }); const xhr = window.XMLHttpRequest; window.XMLHttpRequest = jest.fn().mockImplementation(xhrMockClass); const NewHttpProvider = require('../../../src/util/httpProvider').default; - const httpProvider = new NewHttpProvider(stageEndpoint); + const httpProvider = new NewHttpProvider(tdvwEndPoint); window.XMLHttpRequest = xhr; try { httpProvider.send({ url: 'blockChain/blockByHeight', method: 'GET', params: { - blockHeight: 136240697, - }, + blockHeight: 134573331 + } }); } catch (e) { expect(e).toEqual({ Error: 'error xhr' }); @@ -469,76 +377,47 @@ describe('test httpProvider', () => { delete window.XMLHttpRequest; window.fetch = fetch; const NewHttpProvider = require('../../../src/util/httpProvider').default; - const httpProvider = new NewHttpProvider(stageEndpoint); + const httpProvider = new NewHttpProvider(tdvwEndPoint); window.XMLHttpRequest = xhr; const result = await httpProvider.sendAsync({ url: 'blockChain/blockByHeight', method: 'GET', params: { - blockHeight: 136240697, - }, - }); - expect(result).toEqual({ - BlockHash: - 'f8bd119ae0a2a93913ad5104143cae05f71c9f4674b44462cfb39acf6e42f76d', - Header: { - PreviousBlockHash: - 'c9313e0db7962002df1ce90b367415c12be3ba0c963f864fe0f331c6a9af1294', - MerkleTreeRootOfTransactions: - '46d2955581d0d276fa42cd4928fd85a7c9935d4060b61afbebd5532008ad5b29', - MerkleTreeRootOfWorldState: - 'd3306b3f048fd26f62249e7ba9c9c04560abb41ec1581a4efc046448975d8994', - MerkleTreeRootOfTransactionState: - '8601777b7246af5be7b3c31bd44c9826480f9785645ce216a709c1ce2da217ab', - Extra: - '{ "CrossChain": "", "Consensus": "CkEE80ryjmjXybz8epeXpNiU7pqdPRQuJ1zSVLZJXtfslflUEcmBmVDCPDb9AKLGEJR0h71uCz4+2NLJDwifpPDAKhL+FQin+W8SvQIKggEwNGYzNGFmMjhlNjhkN2M5YmNmYzdhOTc5N2E0ZDg5NGVlOWE5ZDNkMTQyZTI3NWNkMjU0YjY0OTVlZDdlYzk1Zjk1NDExYzk4MTk5NTBjMjNjMzZmZDAwYTJjNjEwOTQ3NDg3YmQ2ZTBiM2UzZWQ4ZDJjOTBmMDg5ZmE0ZjBjMDJhErUBOLOZA0qCATA0ZjM0YWYyOGU2OGQ3YzliY2ZjN2E5Nzk3YTRkODk0ZWU5YTlkM2QxNDJlMjc1Y2QyNTRiNjQ5NWVkN2VjOTVmOTU0MTFjOTgxOTk1MGMyM2MzNmZkMDBhMmM2MTA5NDc0ODdiZDZlMGIzZTNlZDhkMmM5MGYwODlmYTRmMGMwMmFqBgiki9afBmoLCKS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ZjNiZmI5ODAyYzJkNzBkODQ3NzFkODEwNjJiMGJjMWEyNWM5YzFkZGFkMjVjODg4YmViYTBiODllYzBiZDcyOTAyMmVhMjlmNDI4ZDdjYjc0MDUzZTM5ZTFmMWYSABKHAQqCATA0OWQ4ZDZiOGI3OGI2MDRkOWE4NDA2MTM4NzVmZWQyYjkwNDhmYTBmZWYxZTA5ZjQ5NmUxYTExYjJhNzAxZGE3NDZiMWFmZTU0ZGVmMDJmMmZmYTBiOGNjNDFhN2NjNzQxZDVmMzU2YjYxZDE1NjEzOGI1MGQ0NWVkZmI5N2I2NzcSAFDk0uPZdhgE", "SystemTransactionCount": "CAI=" }', - Height: 136240697, - Time: '2023-02-22T03:01:56.4141789Z', - ChainId: 'AELF', - Bloom: - 'AAAAAAAAAAIAAAAAAAAAIABAAAAAAAgAAAAAAAAAAACAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABAAAAAAAAAAAAAAAAAAAAAAAAAAEAAAAAAAAAAAAAAAAAAAAAAAAAAAIAAACAABAAAAAAAAAAAAAAAAAAAAAAAAACACAAAAAAAAAAAAAAAAAAAAAAABAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAEAAAAAAAAAAAAAAAAAEAAAAAAAAAAAAAAAABAAAAAAgAAAAABAAAAAgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAEAAAAgAAAAAAAAAAAAAAAA==', - SignerPubkey: - '04f34af28e68d7c9bcfc7a9797a4d894ee9a9d3d142e275cd254b6495ed7ec95f95411c9819950c23c36fd00a2c610947487bd6e0b3e3ed8d2c90f089fa4f0c02a', - }, - Body: { - TransactionsCount: 2, - Transactions: [], - }, - BlockSize: 3589, + blockHeight: 134573331 + } }); + expect(result).toEqual(blockByHeightRes); }); test('test send async by xhr method', async () => { - const httpProvider = new HttpProvider(stageEndpoint); + const httpProvider = new HttpProvider(tdvwEndPoint); const result = await httpProvider.sendAsync({ url: 'blockChain/blockByHeight', method: 'GET', params: { - blockHeight: 136240697, - }, + blockHeight: 134573331 + } }); expect(result).toEqual(blockByHeightRes); }); test('test send async by xhr', async () => { - const httpProvider = new HttpProvider(stageEndpoint); + const httpProvider = new HttpProvider(tdvwEndPoint); const result = await httpProvider.sendAsyncByXMLHttp({ url: 'blockChain/blockByHeight', method: 'GET', params: { - blockHeight: 136240697, - }, + blockHeight: 134573331 + } }); expect(result).toEqual(blockByHeightRes); }); test('test send async by xhr when error', async () => { // use stageEndPoint may cause: // Cross origin http://localhost forbidden - const httpProvider = new HttpProvider( - 'https://explorer-test.aelf.io/chain' - ); + const httpProvider = new HttpProvider('https://explorer-test.aelf.io/chain'); await expect( httpProvider.sendAsyncByXMLHttp({ url: 'blockChain/executeTransaction', - method: 'POST', + method: 'POST' }) ).rejects.toEqual({ Error: { @@ -546,12 +425,12 @@ describe('test httpProvider', () => { Data: {}, Details: null, Message: 'Invalid params', - ValidationErrors: null, - }, + ValidationErrors: null + } }); }); test('test is connected', () => { - const httpProvider = new HttpProvider(stageEndpoint); + const httpProvider = new HttpProvider(tdvwEndPoint); const result = httpProvider.isConnected(); expect(result).toBeTruthy(); }); @@ -565,13 +444,13 @@ describe('test httpProvider', () => { delete window.XMLHttpRequest; window.fetch = fetch; const NewHttpProvider = require('../../../src/util/httpProvider').default; - const httpProvider = new NewHttpProvider(stageEndpoint); + const httpProvider = new NewHttpProvider(tdvwEndPoint); window.XMLHttpRequest = xhr; const result = await httpProvider.isConnectedAsync(); expect(!!result).toBeTruthy(); }); test('test is not connected when async', async () => { - const httpProvider = new HttpProvider(stageEndpoint); + const httpProvider = new HttpProvider(tdvwEndPoint); const result = await httpProvider.isConnectedAsync(); expect(result).toBeFalsy(); }); diff --git a/test/unit/util/httpProvider.data.js b/test/unit/util/httpProvider.data.js index f6911456..4d8cf96a 100644 --- a/test/unit/util/httpProvider.data.js +++ b/test/unit/util/httpProvider.data.js @@ -1,27 +1,23 @@ export const blockByHeightRes = { - BlockHash: 'f8bd119ae0a2a93913ad5104143cae05f71c9f4674b44462cfb39acf6e42f76d', + BlockHash: '2267716b9af2d6c306ded8eb992ce04518ec965704298c80e10df4b4e5358eb5', Header: { - PreviousBlockHash: - 'c9313e0db7962002df1ce90b367415c12be3ba0c963f864fe0f331c6a9af1294', - MerkleTreeRootOfTransactions: - '46d2955581d0d276fa42cd4928fd85a7c9935d4060b61afbebd5532008ad5b29', - MerkleTreeRootOfWorldState: - 'd3306b3f048fd26f62249e7ba9c9c04560abb41ec1581a4efc046448975d8994', - MerkleTreeRootOfTransactionState: - '8601777b7246af5be7b3c31bd44c9826480f9785645ce216a709c1ce2da217ab', + PreviousBlockHash: 'c6d1142ab62e6a9d8ed1c09387c93a85698782e9fff6c3ab0580816a2c9456e0', + MerkleTreeRootOfTransactions: '56403fb4c93574713d4b22f2ed8159aa1933350f5daa113865b6de159330cc92', + MerkleTreeRootOfWorldState: 'cbf8816225d99877a840170ab8ced2e1e7a926b8fd622ba99b5871fcf727033a', + MerkleTreeRootOfTransactionState: 'c16938414dbfc92c696beef5eafc04cd01d9293f2c04e6eb61e389a9d73c05b2', Extra: - '{ "CrossChain": "", "Consensus": "CkEE80ryjmjXybz8epeXpNiU7pqdPRQuJ1zSVLZJXtfslflUEcmBmVDCPDb9AKLGEJR0h71uCz4+2NLJDwifpPDAKhL+FQin+W8SvQIKggEwNGYzNGFmMjhlNjhkN2M5YmNmYzdhOTc5N2E0ZDg5NGVlOWE5ZDNkMTQyZTI3NWNkMjU0YjY0OTVlZDdlYzk1Zjk1NDExYzk4MTk5NTBjMjNjMzZmZDAwYTJjNjEwOTQ3NDg3YmQ2ZTBiM2UzZWQ4ZDJjOTBmMDg5ZmE0ZjBjMDJhErUBOLOZA0qCATA0ZjM0YWYyOGU2OGQ3YzliY2ZjN2E5Nzk3YTRkODk0ZWU5YTlkM2QxNDJlMjc1Y2QyNTRiNjQ5NWVkN2VjOTVmOTU0MTFjOTgxOTk1MGMyM2MzNmZkMDBhMmM2MTA5NDc0ODdiZDZlMGIzZTNlZDh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AAAAAAEAAAAAAAAAAAAAAAAAEAAAAAAAAAAAAAAAABAAAAAAgAAAAABAAAAAgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAEAAAAgAAAAAAAAAAAAAAAA==', + 'AAAAAAAAAAAAAAAAAAIAAABAAAAAAAAAAAAAAAAAAACAAAAAAAgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAEAAAAAACAAAAAABAAAAAAAAAAAAQCAAAAAAAAAAACACAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAgAAAAAAAAAAAAAAAAAAAAAAAAAAAAgAAAAAAAAAAAAAAAAAAAAQAAAAAEAAAAAIEAIAAAEAAAAAAEAAAAACAAAAAA==', SignerPubkey: - '04f34af28e68d7c9bcfc7a9797a4d894ee9a9d3d142e275cd254b6495ed7ec95f95411c9819950c23c36fd00a2c610947487bd6e0b3e3ed8d2c90f089fa4f0c02a', + '0487bb19291fe71bd3f8d8cf1d46e1ba7d05f30e28d91fe3d4e248ad46e4581fd2a653cec123b12a8f6850e2c1952c8b29616359f9fa4752d4bec69d92a13a4451' }, Body: { TransactionsCount: 2, - Transactions: [], + Transactions: [] }, - BlockSize: 3589, + BlockSize: 1664 }; diff --git a/test/unit/util/httpProvider.fetch.node-test.js b/test/unit/util/httpProvider.fetch.node-test.js index d80403f0..30033071 100644 --- a/test/unit/util/httpProvider.fetch.node-test.js +++ b/test/unit/util/httpProvider.fetch.node-test.js @@ -2,8 +2,8 @@ import HttpProvider from '../../../src/util/httpProvider'; import http from 'node:http'; import https from 'node:https'; import { blockByHeightRes } from './httpProvider.data'; +import { tdvwEndPoint } from '../constant'; const fetch = require('node-fetch'); -const stageEndpoint = 'https://aelf-public-node.aelf.io/'; // for test timeout jest.useFakeTimers(); jest.spyOn(global, 'setTimeout'); @@ -14,14 +14,14 @@ describe('test httpProvider', () => { }); test('test get request send by fetch', async () => { - const httpProvider = new HttpProvider(stageEndpoint); + const httpProvider = new HttpProvider(tdvwEndPoint); const response = await httpProvider.requestSendByFetch( { url: 'blockChain/blockByHeight', method: 'GET', params: { - blockHeight: 136240697, - }, + blockHeight: 134573331 + } }, fetch ); @@ -36,7 +36,7 @@ describe('test httpProvider', () => { keepAlive: true }); const options = { - agent: function(_parsedURL) { + agent: function (_parsedURL) { if (_parsedURL.protocol === 'http:') { return httpAgent; } else { @@ -45,14 +45,14 @@ describe('test httpProvider', () => { } }; - const httpProvider = new HttpProvider(stageEndpoint, 8000, {}, options); + const httpProvider = new HttpProvider(tdvwEndPoint, 8000, {}, options); const response = await httpProvider.requestSendByFetch( { url: 'blockChain/blockByHeight', method: 'GET', params: { - blockHeight: 136240697, - }, + blockHeight: 134573331 + } }, fetch ); @@ -60,45 +60,41 @@ describe('test httpProvider', () => { expect(JSON.parse(result)).toEqual(blockByHeightRes); }); test('test post request send by fetch', async () => { - const httpProvider = new HttpProvider(stageEndpoint); + const httpProvider = new HttpProvider(tdvwEndPoint); const response = await httpProvider.requestSendByFetch( { - url: 'blockChain/calculateTransactionFee', + url: 'blockChain/executeTransaction', params: { RawTransaction: - '0a220a2005c3b3959caeee55b5db4004f6f9d76860aae818ce7b33d210a446ecb275468212220a200e9a238616169860ba4fb502f8e87ce62db9ef321f29fd76d6e1ce30a0e0cdba18a8a19e022204fa60011c2a085472616e73666572322e0a220a200e9a238616169860ba4fb502f8e87ce62db9ef321f29fd76d6e1ce30a0e0cdba1203454c461880c2d72f82f10441ad1647aa462a8859c7a699f22d6124c82a5239c90746ac67ebfd8e1a7b4a25f343733351162d205fc881ea62072e9fe0fad5f6113734309b6666f6812d6b7a6400', - }, + '0a220a203000800ce18e6de0fc576a48759d9dc90a23f0ded388316b0f9f1274a45b809b12220a202ec3700300ef9c95ee67a20a35dad35b8b0d476533e009a746b015df7d051e2d2a1c43616c63756c6174654f7267616e697a6174696f6e4164647265737332560a240a220a2024447d28d0da2f7923a917a4176214032541bda3d0d1a4c8195f3ecccc034fc7120808011000180020011a240a220a2024447d28d0da2f7923a917a4176214032541bda3d0d1a4c8195f3ecccc034fc782f104417582ebfba9506ec499b4ac36653f0c8feefa66d32eb0cd88ed4a608187c85fea75e37405c37de7d9bf3ae03745ae6768da908aad3c0e10b1c48b0de321ad5d7201' + } }, fetch ); const result = await response.text(); - expect(JSON.parse(result)).toMatchObject({ - Success: false, - TransactionFee: null, - ResourceFee: null, - }); + expect(result).toEqual('0a20b2506d0e6a6f4901b85a4a9a57f30dc7acf95b9feba037566baedaf450a3b7be'); }); test('test send async by fetch', async () => { - const httpProvider = new HttpProvider(stageEndpoint); + const httpProvider = new HttpProvider(tdvwEndPoint); const result = await httpProvider.sendAsyncByFetch({ url: 'blockChain/blockByHeight', method: 'GET', params: { - blockHeight: 136240697, - }, + blockHeight: 134573331 + } }); expect(result).toEqual(blockByHeightRes); }); test('test send async by fetch when error', async () => { - const httpProvider = new HttpProvider(stageEndpoint); + const httpProvider = new HttpProvider(tdvwEndPoint); await expect( httpProvider.sendAsyncByFetch({ url: 'blockChain/executeTransaction', method: 'POST', params: { - RawTransaction: '111', - }, + RawTransaction: '111' + } }) ).rejects.toEqual({ Error: { @@ -106,33 +102,31 @@ describe('test httpProvider', () => { Message: 'Invalid params', Details: null, Data: {}, - ValidationErrors: null, - }, + ValidationErrors: null + } }); }); test('test send by fetch', () => { - const httpProvider = new HttpProvider(stageEndpoint); + const httpProvider = new HttpProvider(tdvwEndPoint); try { httpProvider.send({ url: 'blockChain/blockHeight', - method: 'GET', + method: 'GET' }); } catch (e) { - expect(e).toEqual( - new Error("Can not get XMLHttpRequest, invalid parameter: 'sync'") - ); + expect(e).toEqual(new Error("Can not get XMLHttpRequest, invalid parameter: 'sync'")); } }); test('test send async by fetch method', async () => { - const httpProvider = new HttpProvider(stageEndpoint); + const httpProvider = new HttpProvider(tdvwEndPoint); const result = await httpProvider.sendAsync({ url: 'blockChain/blockByHeight', method: 'GET', params: { - blockHeight: 136240697, - }, + blockHeight: 134573331 + } }); expect(result).toEqual(blockByHeightRes); }); diff --git a/test/unit/util/httpProvider.node-test.js b/test/unit/util/httpProvider.node-test.js index b3ec192e..a0036bb7 100644 --- a/test/unit/util/httpProvider.node-test.js +++ b/test/unit/util/httpProvider.node-test.js @@ -1,36 +1,10 @@ import HttpProvider from '../../../src/util/httpProvider'; -const stageEndpoint = 'https://aelf-public-node.aelf.io/'; +import { tdvwEndPoint } from '../constant'; +import { blockByHeightRes } from './httpProvider.data'; // for test timeout jest.useFakeTimers(); jest.spyOn(global, 'setTimeout'); -const blockByHeightRes = { - BlockHash: 'f8bd119ae0a2a93913ad5104143cae05f71c9f4674b44462cfb39acf6e42f76d', - Header: { - PreviousBlockHash: - 'c9313e0db7962002df1ce90b367415c12be3ba0c963f864fe0f331c6a9af1294', - MerkleTreeRootOfTransactions: - '46d2955581d0d276fa42cd4928fd85a7c9935d4060b61afbebd5532008ad5b29', - MerkleTreeRootOfWorldState: - 'd3306b3f048fd26f62249e7ba9c9c04560abb41ec1581a4efc046448975d8994', - MerkleTreeRootOfTransactionState: - '8601777b7246af5be7b3c31bd44c9826480f9785645ce216a709c1ce2da217ab', - Extra: - '{ "CrossChain": "", "Consensus": "CkEE80ryjmjXybz8epeXpNiU7pqdPRQuJ1zSVLZJXtfslflUEcmBmVDCPDb9AKLGEJR0h71uCz4+2NLJDwifpPDAKhL+FQin+W8SvQIKggEwNGYzNGFmMjhlNjhkN2M5YmNmYzdhOTc5N2E0ZDg5NGVlOWE5ZDNkMTQyZTI3NWNkMjU0YjY0OTVlZDdlYzk1Zjk1NDExYzk4MTk5NTBjMjNjMzZmZDAwYTJjNjEwOTQ3NDg3YmQ2ZTBiM2UzZWQ4ZDJjOTBmMDg5ZmE0ZjBjMDJhErUBOLOZA0qCATA0ZjM0YWYyOGU2OGQ3YzliY2ZjN2E5Nzk3YTRkODk0ZWU5YTlkM2QxNDJlMjc1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WM0Y2E4YzcxNGViZjVhNWZjY2JlZWVhNTkyODM4Y2RmM2I5MzU2MjQ4NDA4MTg0MGISABKHAQqCATA0MTY5ODY4YjdjY2M0ODIyZjI3YWZkNjQ5N2E5NGYyODA0OGE0ZjNiZmI5ODAyYzJkNzBkODQ3NzFkODEwNjJiMGJjMWEyNWM5YzFkZGFkMjVjODg4YmViYTBiODllYzBiZDcyOTAyMmVhMjlmNDI4ZDdjYjc0MDUzZTM5ZTFmMWYSABKHAQqCATA0OWQ4ZDZiOGI3OGI2MDRkOWE4NDA2MTM4NzVmZWQyYjkwNDhmYTBmZWYxZTA5ZjQ5NmUxYTExYjJhNzAxZGE3NDZiMWFmZTU0ZGVmMDJmMmZmYTBiOGNjNDFhN2NjNzQxZDVmMzU2YjYxZDE1NjEzOGI1MGQ0NWVkZmI5N2I2NzcSAFDk0uPZdhgE", "SystemTransactionCount": "CAI=" }', - Height: 136240697, - Time: '2023-02-22T03:01:56.4141789Z', - ChainId: 'AELF', - Bloom: - 'AAAAAAAAAAIAAAAAAAAAIABAAAAAAAgAAAAAAAAAAACAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABAAAAAAAAAAAAAAAAAAAAAAAAAAEAAAAAAAAAAAAAAAAAAAAAAAAAAAIAAACAABAAAAAAAAAAAAAAAAAAAAAAAAACACAAAAAAAAAAAAAAAAAAAAAAABAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAEAAAAAAAAAAAAAAAAAEAAAAAAAAAAAAAAAABAAAAAAgAAAAABAAAAAgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAEAAAAgAAAAAAAAAAAAAAAA==', - SignerPubkey: - '04f34af28e68d7c9bcfc7a9797a4d894ee9a9d3d142e275cd254b6495ed7ec95f95411c9819950c23c36fd00a2c610947487bd6e0b3e3ed8d2c90f089fa4f0c02a', - }, - Body: { - TransactionsCount: 2, - Transactions: [], - }, - BlockSize: 3589, -}; describe('test httpProvider', () => { beforeEach(() => { jest.resetModules(); @@ -40,23 +14,19 @@ describe('test httpProvider', () => { expect(httpProvider.host).toBe('http://localhost:8545'); }); test('test headers are Array', () => { - const httpProvider = new HttpProvider(stageEndpoint, 8000, [ + const httpProvider = new HttpProvider(tdvwEndPoint, 8000, [ { name: 'Last-Modified', - value: 'Wed, 21 Oct 2015 07:28:00 GMT', - }, + value: 'Wed, 21 Oct 2015 07:28:00 GMT' + } ]); - expect(httpProvider.headers['Last-Modified']).toEqual( - 'Wed, 21 Oct 2015 07:28:00 GMT' - ); + expect(httpProvider.headers['Last-Modified']).toEqual('Wed, 21 Oct 2015 07:28:00 GMT'); }); test('test headers are Object', () => { - const httpProvider = new HttpProvider(stageEndpoint, 8000, { - 'Last-Modified': 'Wed, 21 Oct 2015 07:28:00 GMT', + const httpProvider = new HttpProvider(tdvwEndPoint, 8000, { + 'Last-Modified': 'Wed, 21 Oct 2015 07:28:00 GMT' }); - expect(httpProvider.headers['Last-Modified']).toEqual( - 'Wed, 21 Oct 2015 07:28:00 GMT' - ); + expect(httpProvider.headers['Last-Modified']).toEqual('Wed, 21 Oct 2015 07:28:00 GMT'); }); test('test format response when can parse to JSON', () => { const response = HttpProvider.formatResponse('{"ok":true,"status":200}'); @@ -69,18 +39,18 @@ describe('test httpProvider', () => { test('test format response text with status and statusText', () => { const response = HttpProvider.formatResponseText({ status: 500, - statusText: 'server error', + statusText: 'server error' }); expect(response).toEqual({ Error: { message: 'server error' }, error: 500, status: 500, - statusText: 'server error', + statusText: 'server error' }); }); test('test format response text with status 200', () => { const response = HttpProvider.formatResponseText({ - status: 200, + status: 200 }); expect(response.error).toEqual(0); }); @@ -90,7 +60,7 @@ describe('test httpProvider', () => { Error: { message: undefined }, error: undefined, status: undefined, - statusText: undefined, + statusText: undefined }); }); test('test format response text when error', () => { @@ -105,7 +75,7 @@ describe('test httpProvider', () => { return expect(p).resolves.toEqual({ type: 'timeout' }); }); test('test get request send by xhr', () => { - const httpProvider = new HttpProvider(stageEndpoint); + const httpProvider = new HttpProvider(tdvwEndPoint); const RequestLibrary = require('xmlhttprequest').XMLHttpRequest; const request = new RequestLibrary(); request.withCredentials = false; @@ -114,19 +84,17 @@ describe('test httpProvider', () => { url: 'blockChain/blockByHeight', method: 'GET', params: { - blockHeight: 136240697, - }, + blockHeight: 134573331 + } }, request ); const result = JSON.parse(request.responseText); - expect(result.BlockHash).toBe( - 'f8bd119ae0a2a93913ad5104143cae05f71c9f4674b44462cfb39acf6e42f76d' - ); + expect(result).toEqual(blockByHeightRes); }); test('test post request send by xhr', () => { - const httpProvider = new HttpProvider(stageEndpoint); + const httpProvider = new HttpProvider(tdvwEndPoint); const RequestLibrary = require('xmlhttprequest').XMLHttpRequest; const request = new RequestLibrary(); request.withCredentials = false; @@ -135,8 +103,8 @@ describe('test httpProvider', () => { url: 'blockChain/calculateTransactionFee', params: { RawTransaction: - '0a220a2005c3b3959caeee55b5db4004f6f9d76860aae818ce7b33d210a446ecb275468212220a200e9a238616169860ba4fb502f8e87ce62db9ef321f29fd76d6e1ce30a0e0cdba18a8a19e022204fa60011c2a085472616e73666572322e0a220a200e9a238616169860ba4fb502f8e87ce62db9ef321f29fd76d6e1ce30a0e0cdba1203454c461880c2d72f82f10441ad1647aa462a8859c7a699f22d6124c82a5239c90746ac67ebfd8e1a7b4a25f343733351162d205fc881ea62072e9fe0fad5f6113734309b6666f6812d6b7a6400', - }, + '0a220a2005c3b3959caeee55b5db4004f6f9d76860aae818ce7b33d210a446ecb275468212220a200e9a238616169860ba4fb502f8e87ce62db9ef321f29fd76d6e1ce30a0e0cdba18a8a19e022204fa60011c2a085472616e73666572322e0a220a200e9a238616169860ba4fb502f8e87ce62db9ef321f29fd76d6e1ce30a0e0cdba1203454c461880c2d72f82f10441ad1647aa462a8859c7a699f22d6124c82a5239c90746ac67ebfd8e1a7b4a25f343733351162d205fc881ea62072e9fe0fad5f6113734309b6666f6812d6b7a6400' + } }, request ); @@ -144,18 +112,18 @@ describe('test httpProvider', () => { expect(JSON.parse(result)).toMatchObject({ Success: false, TransactionFee: null, - ResourceFee: null, + ResourceFee: null }); }); test('test send by xhr', async () => { - const httpProvider = new HttpProvider(stageEndpoint); + const httpProvider = new HttpProvider(tdvwEndPoint); const result = httpProvider.send({ url: 'blockChain/blockByHeight', method: 'GET', params: { - blockHeight: 136240697, - }, + blockHeight: 134573331 + } }); expect(result).toEqual(blockByHeightRes); }); @@ -165,22 +133,19 @@ describe('test httpProvider', () => { send: jest.fn(), setRequestHeader: jest.fn(), responseText: { - Error: 'error xhr', - }, + Error: 'error xhr' + } }); - HttpProvider.__Rewire__( - 'RequestLibrary', - jest.fn().mockImplementation(xhrMockClass) - ); - const httpProvider = new HttpProvider(stageEndpoint); + HttpProvider.__Rewire__('RequestLibrary', jest.fn().mockImplementation(xhrMockClass)); + const httpProvider = new HttpProvider(tdvwEndPoint); try { httpProvider.send({ url: 'blockChain/blockByHeight', method: 'GET', params: { - blockHeight: 136240697, - }, + blockHeight: 134573331 + } }); } catch (e) { expect(e).toEqual({ Error: 'error xhr' }); @@ -188,33 +153,33 @@ describe('test httpProvider', () => { HttpProvider.__ResetDependency__('RequestLibrary'); }); test('test send async by xhr method', async () => { - const httpProvider = new HttpProvider(stageEndpoint); + const httpProvider = new HttpProvider(tdvwEndPoint); const result = await httpProvider.sendAsync({ url: 'blockChain/blockByHeight', method: 'GET', params: { - blockHeight: 136240697, - }, + blockHeight: 134573331 + } }); expect(result).toEqual(blockByHeightRes); }); test('test send async by xhr', async () => { - const httpProvider = new HttpProvider(stageEndpoint); + const httpProvider = new HttpProvider(tdvwEndPoint); const result = await httpProvider.sendAsyncByXMLHttp({ url: 'blockChain/blockByHeight', method: 'GET', params: { - blockHeight: 136240697, - }, + blockHeight: 134573331 + } }); expect(result).toEqual(blockByHeightRes); }); test('test send async by xhr when error', async () => { - const httpProvider = new HttpProvider(stageEndpoint); + const httpProvider = new HttpProvider(tdvwEndPoint); await expect( httpProvider.sendAsyncByXMLHttp({ url: 'blockChain/executeTransaction', - method: 'POST', + method: 'POST' }) ).rejects.toEqual({ Error: { @@ -222,12 +187,12 @@ describe('test httpProvider', () => { Data: {}, Details: null, Message: 'Invalid params', - ValidationErrors: null, - }, + ValidationErrors: null + } }); }); test('test is connected', () => { - const httpProvider = new HttpProvider(stageEndpoint); + const httpProvider = new HttpProvider(tdvwEndPoint); const result = httpProvider.isConnected(); expect(result).toBeTruthy(); }); diff --git a/test/unit/util/proto.test.js b/test/unit/util/proto.test.js index 6a1991e7..2138188d 100644 --- a/test/unit/util/proto.test.js +++ b/test/unit/util/proto.test.js @@ -12,19 +12,18 @@ import { getHashObjectFromHex, encodeTransaction, getTransaction, - deserializeLog, + deserializeLog } from '../../../src/util/proto'; import ContractFactory from '../../../src/contract/index'; import AElf from '../../../src/index'; +import { tdvwEndPoint } from '../constant'; -describe('test proto',() => { - const stageEndpoint = 'https://tdvw-test-node.aelf.io'; - const aelf = new AElf(new AElf.providers.HttpProvider(stageEndpoint)); +describe('test proto', () => { + const aelf = new AElf(new AElf.providers.HttpProvider(tdvwEndPoint)); const chain = aelf.chain; - const address = - 'ELF_2sGZFRtqQ57F55Z2KvhmoozKrf7ik2htNVQawEAo3Vyvcx9Qwr_tDVW'; + const address = 'ELF_2sGZFRtqQ57F55Z2KvhmoozKrf7ik2htNVQawEAo3Vyvcx9Qwr_tDVW'; const fds = chain.getContractFileDescriptorSet(address, { - sync: true, + sync: true }); const factory = new ContractFactory(chain, fds, AElf.wallet); @@ -34,20 +33,18 @@ describe('test proto',() => { Address: '25CecrU94dmMdbhC3LWMKxtoaL4Wv8PChGvVJM6PxkHAyvXEhB', Name: 'TransactionFeeCharged', Indexed: null, - NonIndexed: 'CgNFTEYQoI/hGQ==', - }, + NonIndexed: 'CgNFTEYQoI/hGQ==' + } ]; expect(getTransactionFee(Logs)).toEqual([ { symbol: 'ELF', chargingAddress: null, - amount: '54020000', - }, + amount: '54020000' + } ]); expect(getTransactionFee(Logs).length).toEqual(1); - expect(getFee('CgNFTEYQoI/hGQ==', 'TransactionFeeCharged')).toEqual( - getTransactionFee(Logs)[0] - ); + expect(getFee('CgNFTEYQoI/hGQ==', 'TransactionFeeCharged')).toEqual(getTransactionFee(Logs)[0]); expect(getResourceFee(Logs).length).toEqual(0); expect(() => getFee('CgNFTEYQoI/hGQ==', 'ResourceToken')).toThrow(); }); @@ -56,12 +53,12 @@ describe('test proto',() => { expect(result).toEqual({ symbol: 'ELF', chargingAddress: null, - amount: '54020000', + amount: '54020000' }); expect(getFee('CgNFTEYQoI/hGQ==')).toEqual({ symbol: 'ELF', chargingAddress: null, - amount: '54020000', + amount: '54020000' }); }); test('test fee with ResourceTokenCharged type', () => { @@ -69,7 +66,7 @@ describe('test proto',() => { expect(result).toEqual({ symbol: 'ELF', amount: '54020000', - contractAddress: null, + contractAddress: null }); }); test('test fee with wrong type', () => { @@ -80,11 +77,11 @@ describe('test proto',() => { Indexed: [ 'CiIKILEmXenHStaFyei2ijKTSRTSXFwtYJZtuzCVOHs3KWEp', 'EiIKIIw9aDQ+0IsgauW4z2rbA/hDk944n5QN6KI2S6s3Bb3h', - 'GgNFTEY=', + 'GgNFTEY=' ], NonIndexed: 'IIDIr6Al', Name: 'Transferred', - Address: 'ELF_JRmBduh4nXWi1aXgdUsj5gJrzeZb2LxmrAbf7W99faZSvoAaE_AELF', + Address: 'ELF_JRmBduh4nXWi1aXgdUsj5gJrzeZb2LxmrAbf7W99faZSvoAaE_AELF' }; const result = getSerializedDataFromLog(log); expect(result).toEqual( @@ -95,10 +92,10 @@ describe('test proto',() => { Indexed: [ 'CiIKILEmXenHStaFyei2ijKTSRTSXFwtYJZtuzCVOHs3KWEp', 'EiIKIIw9aDQ+0IsgauW4z2rbA/hDk944n5QN6KI2S6s3Bb3h', - 'GgNFTEY=', + 'GgNFTEY=' ], Name: 'Transferred', - Address: 'ELF_JRmBduh4nXWi1aXgdUsj5gJrzeZb2LxmrAbf7W99faZSvoAaE_AELF', + Address: 'ELF_JRmBduh4nXWi1aXgdUsj5gJrzeZb2LxmrAbf7W99faZSvoAaE_AELF' }) ).toEqual( 'CiIKILEmXenHStaFyei2ijKTSRTSXFwtYJZtuzCVOHs3KWEpEiIKIIw9aDQ+0IsgauW4z2rbA/hDk944n5QN6KI2S6s3Bb3hGgNFTEY=' @@ -109,7 +106,7 @@ describe('test proto',() => { Indexed: null, NonIndexed: 'IIDIr6Al', Name: 'Transferred', - Address: 'ELF_JRmBduh4nXWi1aXgdUsj5gJrzeZb2LxmrAbf7W99faZSvoAaE_AELF', + Address: 'ELF_JRmBduh4nXWi1aXgdUsj5gJrzeZb2LxmrAbf7W99faZSvoAaE_AELF' }; const result = getSerializedDataFromLog(log); expect(result).toEqual('IIDIr6Al'); @@ -117,7 +114,7 @@ describe('test proto',() => { getSerializedDataFromLog({ NonIndexed: 'IIDIr6Al', Name: 'Transferred', - Address: 'ELF_JRmBduh4nXWi1aXgdUsj5gJrzeZb2LxmrAbf7W99faZSvoAaE_AELF', + Address: 'ELF_JRmBduh4nXWi1aXgdUsj5gJrzeZb2LxmrAbf7W99faZSvoAaE_AELF' }) ).toEqual('IIDIr6Al'); }); @@ -127,21 +124,19 @@ describe('test proto',() => { Address: '25CecrU94dmMdbhC3LWMKxtoaL4Wv8PChGvVJM6PxkHAyvXEhB', Name: 'ResourceTokenCharged', Indexed: null, - NonIndexed: 'CgNFTEYQoI/hGQ==', - }, + NonIndexed: 'CgNFTEYQoI/hGQ==' + } ]; const result = getResourceFee(logs); - expect(result).toEqual([ - { symbol: 'ELF', amount: '54020000', contractAddress: null }, - ]); + expect(result).toEqual([{ symbol: 'ELF', amount: '54020000', contractAddress: null }]); }); test('test get resource fee without ResourceTokenCharged type', () => { const logs = [ { Address: '25CecrU94dmMdbhC3LWMKxtoaL4Wv8PChGvVJM6PxkHAyvXEhB', Name: 'TransactionFeeCharged', - NonIndexed: 'CgNFTEYQoI/hGQ==', - }, + NonIndexed: 'CgNFTEYQoI/hGQ==' + } ]; const result = getResourceFee(logs); expect(result.length).toEqual(0); @@ -155,13 +150,11 @@ describe('test proto',() => { { Address: '25CecrU94dmMdbhC3LWMKxtoaL4Wv8PChGvVJM6PxkHAyvXEhB', Name: 'TransactionFeeCharged', - NonIndexed: 'CgNFTEYQoI/hGQ==', - }, + NonIndexed: 'CgNFTEYQoI/hGQ==' + } ]; const result = getTransactionFee(logs); - expect(result).toEqual([ - { symbol: 'ELF', chargingAddress: null, amount: '54020000' }, - ]); + expect(result).toEqual([{ symbol: 'ELF', chargingAddress: null, amount: '54020000' }]); }); test('test get transaction fee without TransactionFeeCharged type', () => { const logs = [ @@ -169,8 +162,8 @@ describe('test proto',() => { Address: '25CecrU94dmMdbhC3LWMKxtoaL4Wv8PChGvVJM6PxkHAyvXEhB', Name: 'ResourceTokenCharged', Indexed: null, - NonIndexed: 'CgNFTEYQoI/hGQ==', - }, + NonIndexed: 'CgNFTEYQoI/hGQ==' + } ]; const result = getTransactionFee(logs); expect(result.length).toEqual(0); @@ -190,11 +183,9 @@ describe('test proto',() => { }); test('test get rep from address', () => { const result = getRepForAddress({ - value: '25CecrU94dmMdbhC3LWMKxtoaL4Wv8PChGvVJM6PxkHAyvXEhB', + value: '25CecrU94dmMdbhC3LWMKxtoaL4Wv8PChGvVJM6PxkHAyvXEhB' }); - expect(result).toEqual( - 'q9sA88YfqXJEQrKx8vmECZzMJytpw7GySFRnyYSJoBGqfsgFZpdf1SwQ' - ); + expect(result).toEqual('q9sA88YfqXJEQrKx8vmECZzMJytpw7GySFRnyYSJoBGqfsgFZpdf1SwQ'); }); test('test get rep from address with invalid params', () => { const result = getRepForAddress({}); @@ -202,54 +193,36 @@ describe('test proto',() => { }); test('test get address from rep', () => { - const buffer = getAddressFromRep( - 'q9sA88YfqXJEQrKx8vmECZzMJytpw7GySFRnyYSJoBGqfsgFZpdf1SwQ' - ).value; + const buffer = getAddressFromRep('q9sA88YfqXJEQrKx8vmECZzMJytpw7GySFRnyYSJoBGqfsgFZpdf1SwQ').value; expect(buffer).toBeInstanceOf(Buffer); const str = buffer.toString('hex'); - expect(str).toEqual( - 'db909e72b53de1d98c75b842dcb58c2b1b6868be16bfc3c2846bd524ce8fc641c0caf5c484' - ); + expect(str).toEqual('db909e72b53de1d98c75b842dcb58c2b1b6868be16bfc3c2846bd524ce8fc641c0caf5c484'); }); test('test get address object from rep', () => { - const buffer = getAddressObjectFromRep( - 'q9sA88YfqXJEQrKx8vmECZzMJytpw7GySFRnyYSJoBGqfsgFZpdf1SwQ' - ).value; + const buffer = getAddressObjectFromRep('q9sA88YfqXJEQrKx8vmECZzMJytpw7GySFRnyYSJoBGqfsgFZpdf1SwQ').value; expect(buffer).toBeInstanceOf(Buffer); const str = buffer.toString('hex'); - expect(str).toEqual( - 'db909e72b53de1d98c75b842dcb58c2b1b6868be16bfc3c2846bd524ce8fc641c0caf5c484' - ); + expect(str).toEqual('db909e72b53de1d98c75b842dcb58c2b1b6868be16bfc3c2846bd524ce8fc641c0caf5c484'); }); test('test get rep from hash', () => { const result = getRepForHash({ - value: '25CecrU94dmMdbhC3LWMKxtoaL4Wv8PChGvVJM6PxkHAyvXEhB', + value: '25CecrU94dmMdbhC3LWMKxtoaL4Wv8PChGvVJM6PxkHAyvXEhB' }); - expect(result).toEqual( - 'db909e72b53de1d98c75b842dcb58c2b1b6868be16bfc3c2846bd524ce8fc641c0caf5c484' - ); + expect(result).toEqual('db909e72b53de1d98c75b842dcb58c2b1b6868be16bfc3c2846bd524ce8fc641c0caf5c484'); }); test('test get rep from hash with invalid params', () => { const result = getRepForHash({}); expect(result).toEqual(''); }); test('test get hash from hex', () => { - const result = getHashFromHex( - 'db909e72b53de1d98c75b842dcb58c2b1b6868be16bfc3c2846bd524ce8fc641c0caf5c484' - ); + const result = getHashFromHex('db909e72b53de1d98c75b842dcb58c2b1b6868be16bfc3c2846bd524ce8fc641c0caf5c484'); const hex = result.value.toString('hex'); - expect(hex).toEqual( - 'db909e72b53de1d98c75b842dcb58c2b1b6868be16bfc3c2846bd524ce8fc641c0caf5c484' - ); + expect(hex).toEqual('db909e72b53de1d98c75b842dcb58c2b1b6868be16bfc3c2846bd524ce8fc641c0caf5c484'); }); test('test get hash object from hex', () => { - const result = getHashObjectFromHex( - 'db909e72b53de1d98c75b842dcb58c2b1b6868be16bfc3c2846bd524ce8fc641c0caf5c484' - ); + const result = getHashObjectFromHex('db909e72b53de1d98c75b842dcb58c2b1b6868be16bfc3c2846bd524ce8fc641c0caf5c484'); const hex = result.value.toString('hex'); - expect(hex).toEqual( - 'db909e72b53de1d98c75b842dcb58c2b1b6868be16bfc3c2846bd524ce8fc641c0caf5c484' - ); + expect(hex).toEqual('db909e72b53de1d98c75b842dcb58c2b1b6868be16bfc3c2846bd524ce8fc641c0caf5c484'); }); test('test encode transaction to protobuf type', () => { const result = encodeTransaction({ @@ -259,9 +232,8 @@ describe('test proto',() => { '{ "blockHash": "21cbeb3ac049d5a91c66c87f7ae48923fa469c11794f7eecdc721d4e26be48f9", "blockHeight": "136624547" }', refBlockNumber: 136624547, refBlockPrefix: 'IcvrOg==', - signature: - '+9HkFh+ApJqnJp9gmLVwdQQFH283lQaLNpU5udWa818r6ig2ACll/CjFMSvvCsUkvC2xAoIJjruB+WgabiGs9gA=', - to: 'JRmBduh4nXWi1aXgdUsj5gJrzeZb2LxmrAbf7W99faZSvoAaE', + signature: '+9HkFh+ApJqnJp9gmLVwdQQFH283lQaLNpU5udWa818r6ig2ACll/CjFMSvvCsUkvC2xAoIJjruB+WgabiGs9gA=', + to: 'JRmBduh4nXWi1aXgdUsj5gJrzeZb2LxmrAbf7W99faZSvoAaE' }); expect(result).toBeInstanceOf(Buffer); const hex = result.toString('hex'); @@ -281,9 +253,7 @@ describe('test proto',() => { 'f9609c60db810203811cd99a9714b45be196c313348063a82d35faafd037480c' ); expect(result.to.value).toBeInstanceOf(Buffer); - expect(result.to.value.toString('hex')).toEqual( - '2791e992a57f28e75a11f13af2c0aec8b0eb35d2f048d42eba8901c92e0378dc' - ); + expect(result.to.value.toString('hex')).toEqual('2791e992a57f28e75a11f13af2c0aec8b0eb35d2f048d42eba8901c92e0378dc'); }); test('test deserialize logs with unsupported dataType', async () => { const Logs = [ @@ -291,14 +261,16 @@ describe('test proto',() => { Address: 'ELF_2sGZFRtqQ57F55Z2KvhmoozKrf7ik2htNVQawEAo3Vyvcx9Qwr_tDVW', Name: 'FAKE', Indexed: null, - NonIndexed: 'CgNFTEYQoI/hGQ==', - }, + NonIndexed: 'CgNFTEYQoI/hGQ==' + } ]; const contractInstance = factory.at(address); const result = deserializeLog(Logs, contractInstance.services); - expect(result).toEqual([{ - message: 'This log is not supported.', - }]); + expect(result).toEqual([ + { + message: 'This log is not supported.' + } + ]); }); test('test deserialize logs with empty logs', async () => { const result = deserializeLog(); diff --git a/test/unit/util/requestManage.test.js b/test/unit/util/requestManage.test.js index 0e78e0f8..4c8dc7a0 100644 --- a/test/unit/util/requestManage.test.js +++ b/test/unit/util/requestManage.test.js @@ -1,14 +1,14 @@ import RequestManager from '../../../src/util/requestManage'; import HttpProvider from '../../../src/util/httpProvider'; -const stageEndpoint = 'https://explorer-test-tdvw.aelf.io/'; +import { tdvwEndPoint } from '../constant'; describe('test requestManage', () => { test('test prepare request with lower case', () => { const result = RequestManager.prepareRequest({ requestMethod: 'get', method: 'blockHeight', params: { - addition: 'test', - }, + addition: 'test' + } }); expect(result.method).toEqual('GET'); expect(result.url).toEqual('blockHeight'); @@ -17,42 +17,30 @@ describe('test requestManage', () => { test('test prepare request with empty params', () => { const result = RequestManager.prepareRequest({ requestMethod: 'get', - method: 'blockHeight', + method: 'blockHeight' }); expect(result.method).toEqual('GET'); expect(result.url).toEqual('blockHeight'); expect(result.params).toEqual({}); }); test('test set provider', () => { - const httpProvider = new HttpProvider(stageEndpoint); + const httpProvider = new HttpProvider(tdvwEndPoint); const requestManage = new RequestManager(); requestManage.setProvider(httpProvider); expect(requestManage.provider).toBe(httpProvider); }); test('test send with provider', () => { - const httpProvider = new HttpProvider('https://aelf-public-node.aelf.io'); + const httpProvider = new HttpProvider(tdvwEndPoint); const requestManage = new RequestManager(httpProvider); - try { - const result = requestManage.send({ - requestMethod: 'post', - method: 'blockChain/calculateTransactionFee', - params: { - RawTransaction: - '0a220a2005c3b3959caeee55b5db4004f6f9d76860aae818ce7b33d210a446ecb275468212220a200e9a238616169860ba4fb502f8e87ce62db9ef321f29fd76d6e1ce30a0e0cdba18a8a19e022204fa60011c2a085472616e73666572322e0a220a200e9a238616169860ba4fb502f8e87ce62db9ef321f29fd76d6e1ce30a0e0cdba1203454c461880c2d72f82f10441ad1647aa462a8859c7a699f22d6124c82a5239c90746ac67ebfd8e1a7b4a25f343733351162d205fc881ea62072e9fe0fad5f6113734309b6666f6812d6b7a6400', - }, - }); - expect(result).toMatchObject({ - Success: false, - TransactionFee: null, - ResourceFee: null, - }); - } catch(error) { - expect(error).toMatchObject({ - Success: false, - TransactionFee: null, - ResourceFee: null, - }); - } + const result = requestManage.send({ + requestMethod: 'post', + method: 'blockChain/executeTransaction', + params: { + RawTransaction: + '0a220a203000800ce18e6de0fc576a48759d9dc90a23f0ded388316b0f9f1274a45b809b12220a202ec3700300ef9c95ee67a20a35dad35b8b0d476533e009a746b015df7d051e2d2a1c43616c63756c6174654f7267616e697a6174696f6e4164647265737332560a240a220a2024447d28d0da2f7923a917a4176214032541bda3d0d1a4c8195f3ecccc034fc7120808011000180020011a240a220a2024447d28d0da2f7923a917a4176214032541bda3d0d1a4c8195f3ecccc034fc782f104417582ebfba9506ec499b4ac36653f0c8feefa66d32eb0cd88ed4a608187c85fea75e37405c37de7d9bf3ae03745ae6768da908aad3c0e10b1c48b0de321ad5d7201' + } + }); + expect(result).toEqual('0a20b2506d0e6a6f4901b85a4a9a57f30dc7acf95b9feba037566baedaf450a3b7be'); }); test('test send without provider', () => { const requestManage = new RequestManager(); @@ -61,30 +49,23 @@ describe('test requestManage', () => { method: 'blockChain/calculateTransactionFee', params: { RawTransaction: - '0a220a2005c3b3959caeee55b5db4004f6f9d76860aae818ce7b33d210a446ecb275468212220a200e9a238616169860ba4fb502f8e87ce62db9ef321f29fd76d6e1ce30a0e0cdba18a8a19e022204fa60011c2a085472616e73666572322e0a220a200e9a238616169860ba4fb502f8e87ce62db9ef321f29fd76d6e1ce30a0e0cdba1203454c461880c2d72f82f10441ad1647aa462a8859c7a699f22d6124c82a5239c90746ac67ebfd8e1a7b4a25f343733351162d205fc881ea62072e9fe0fad5f6113734309b6666f6812d6b7a6400', - }, + '0a220a2005c3b3959caeee55b5db4004f6f9d76860aae818ce7b33d210a446ecb275468212220a200e9a238616169860ba4fb502f8e87ce62db9ef321f29fd76d6e1ce30a0e0cdba18a8a19e022204fa60011c2a085472616e73666572322e0a220a200e9a238616169860ba4fb502f8e87ce62db9ef321f29fd76d6e1ce30a0e0cdba1203454c461880c2d72f82f10441ad1647aa462a8859c7a699f22d6124c82a5239c90746ac67ebfd8e1a7b4a25f343733351162d205fc881ea62072e9fe0fad5f6113734309b6666f6812d6b7a6400' + } }); expect(result).toEqual(null); }); test('test send async with provider', async () => { - const httpProvider = new HttpProvider('https://aelf-public-node.aelf.io'); + const httpProvider = new HttpProvider(tdvwEndPoint); const requestManage = new RequestManager(httpProvider); - try { - const result = await requestManage.sendAsync({ - requestMethod: 'post', - method: 'blockChain/calculateTransactionFee', - params: { - RawTransaction: - '0a220a2005c3b3959caeee55b5db4004f6f9d76860aae818ce7b33d210a446ecb275468212220a200e9a238616169860ba4fb502f8e87ce62db9ef321f29fd76d6e1ce30a0e0cdba18a8a19e022204fa60011c2a085472616e73666572322e0a220a200e9a238616169860ba4fb502f8e87ce62db9ef321f29fd76d6e1ce30a0e0cdba1203454c461880c2d72f82f10441ad1647aa462a8859c7a699f22d6124c82a5239c90746ac67ebfd8e1a7b4a25f343733351162d205fc881ea62072e9fe0fad5f6113734309b6666f6812d6b7a6400', - }, - }); - } catch (error) { - expect(error).toMatchObject({ - Success: false, - TransactionFee: null, - ResourceFee: null, - }); - } + const result = await requestManage.sendAsync({ + requestMethod: 'post', + method: 'blockChain/executeTransaction', + params: { + RawTransaction: + '0a220a203000800ce18e6de0fc576a48759d9dc90a23f0ded388316b0f9f1274a45b809b12220a202ec3700300ef9c95ee67a20a35dad35b8b0d476533e009a746b015df7d051e2d2a1c43616c63756c6174654f7267616e697a6174696f6e4164647265737332560a240a220a2024447d28d0da2f7923a917a4176214032541bda3d0d1a4c8195f3ecccc034fc7120808011000180020011a240a220a2024447d28d0da2f7923a917a4176214032541bda3d0d1a4c8195f3ecccc034fc782f104417582ebfba9506ec499b4ac36653f0c8feefa66d32eb0cd88ed4a608187c85fea75e37405c37de7d9bf3ae03745ae6768da908aad3c0e10b1c48b0de321ad5d7201' + } + }); + expect(result).toEqual('0a20b2506d0e6a6f4901b85a4a9a57f30dc7acf95b9feba037566baedaf450a3b7be'); }); test('test send async without provider', async () => { const requestManage = new RequestManager(); @@ -93,8 +74,8 @@ describe('test requestManage', () => { method: 'blockChain/calculateTransactionFee', params: { RawTransaction: - '0a220a2005c3b3959caeee55b5db4004f6f9d76860aae818ce7b33d210a446ecb275468212220a200e9a238616169860ba4fb502f8e87ce62db9ef321f29fd76d6e1ce30a0e0cdba18a8a19e022204fa60011c2a085472616e73666572322e0a220a200e9a238616169860ba4fb502f8e87ce62db9ef321f29fd76d6e1ce30a0e0cdba1203454c461880c2d72f82f10441ad1647aa462a8859c7a699f22d6124c82a5239c90746ac67ebfd8e1a7b4a25f343733351162d205fc881ea62072e9fe0fad5f6113734309b6666f6812d6b7a6400', - }, + '0a220a2005c3b3959caeee55b5db4004f6f9d76860aae818ce7b33d210a446ecb275468212220a200e9a238616169860ba4fb502f8e87ce62db9ef321f29fd76d6e1ce30a0e0cdba18a8a19e022204fa60011c2a085472616e73666572322e0a220a200e9a238616169860ba4fb502f8e87ce62db9ef321f29fd76d6e1ce30a0e0cdba1203454c461880c2d72f82f10441ad1647aa462a8859c7a699f22d6124c82a5239c90746ac67ebfd8e1a7b4a25f343733351162d205fc881ea62072e9fe0fad5f6113734309b6666f6812d6b7a6400' + } }); expect(result).toEqual(null); }); diff --git a/test/unit/util/transform.test.js b/test/unit/util/transform.test.js index 7c63c242..4c3026c1 100644 --- a/test/unit/util/transform.test.js +++ b/test/unit/util/transform.test.js @@ -4,12 +4,11 @@ import { transformArrayToMap, encodeAddress, INPUT_TRANSFORMERS, - OUTPUT_TRANSFORMERS, + OUTPUT_TRANSFORMERS } from '../../../src/util/transform'; import AElf from '../../../src/index'; import tokenProto from './token.proto.json'; import nonStandardProto from './non-standard.proto.json'; -const endpoint = 'https://aelf-public-node.aelf.io'; describe('test httpProvider', () => { test('test transform with fieldsArray', async () => { @@ -19,19 +18,17 @@ describe('test httpProvider', () => { const params = { to: '7RzVGiuVWkvL4VfVHdZfQF2Tri3sgLe9U991bohHFfSRZXuGX', amount: '100000000', - symbol: 'ELF', + symbol: 'ELF' }; const result = transform(transferInput, params, INPUT_TRANSFORMERS); - expect(result.to.value.toString('hex')).toEqual( - '0e9a238616169860ba4fb502f8e87ce62db9ef321f29fd76d6e1ce30a0e0cdba' - ); + expect(result.to.value.toString('hex')).toEqual('0e9a238616169860ba4fb502f8e87ce62db9ef321f29fd76d6e1ce30a0e0cdba'); expect(result.amount).toEqual('100000000'); expect(result.symbol).toEqual('ELF'); }); test('test transform with empty inputType fieldsArray', async () => { const params = { amount: '100000000', - symbol: 'ELF', + symbol: 'ELF' }; const result = transform({}, params, INPUT_TRANSFORMERS); expect(result).toEqual(params); @@ -42,7 +39,7 @@ describe('test httpProvider', () => { const transferInput = dataType.lookupType('TransferInput'); const params = { amount: '100000000', - symbol: 'ELF', + symbol: 'ELF' }; const result = transform(transferInput, params, INPUT_TRANSFORMERS); expect(result.to).toEqual(undefined); @@ -51,7 +48,7 @@ describe('test httpProvider', () => { const params1 = { to: '', amount: '100000000', - symbol: 'ELF', + symbol: 'ELF' }; const result1 = transform(transferInput, params1, INPUT_TRANSFORMERS); expect(result1.to).toEqual(''); @@ -66,9 +63,9 @@ describe('test httpProvider', () => { merklePathNodes: [ { hash: '0x967f2a2c7f3d22f9278175c1e6aa39cf9171db91dceacd5ee0f37c2e507b5abe', - isLeftChildNode: true, - }, - ], + isLeftChildNode: true + } + ] }; const result = transform(transferInput, params, INPUT_TRANSFORMERS); expect(result.merklePathNodes[0].hash.value.toString('hex')).toEqual( @@ -85,9 +82,9 @@ describe('test httpProvider', () => { merklePathNodes: [ { hash: '0x967f2a2c7f3d22f9278175c1e6aa39cf9171db91dceacd5ee0f37c2e507b5abe', - isLeftChildNode: true, - }, - ], + isLeftChildNode: true + } + ] }; const result = transform(transferInput, params); expect(result).toEqual(params); @@ -117,14 +114,14 @@ describe('test httpProvider', () => { const params = { address: '7RzVGiuVWkvL4VfVHdZfQF2Tri3sgLe9U991bohHFfSRZXuGX', amount: '100000000', - symbol: 'ELF', + symbol: 'ELF' }; const result = transformMapToArray(transferInput, params); expect(result).toEqual({ address: '7RzVGiuVWkvL4VfVHdZfQF2Tri3sgLe9U991bohHFfSRZXuGX', amount: '100000000', symbol: 'ELF', - to: undefined, + to: undefined }); }); test('test transformMapToArray with fieldsArray which has resolvedType', async () => { @@ -135,9 +132,9 @@ describe('test httpProvider', () => { merklePathNodes: [ { to: '0x967f2a2c7f3d22f9278175c1e6aa39cf9171db91dceacd5ee0f37c2e507b5abe', - isLeftChildNode: true, - }, - ], + isLeftChildNode: true + } + ] }; const result = transformMapToArray(transferInput, params); expect(result).toEqual({ @@ -145,9 +142,9 @@ describe('test httpProvider', () => { { to: '0x967f2a2c7f3d22f9278175c1e6aa39cf9171db91dceacd5ee0f37c2e507b5abe', isLeftChildNode: true, - hash: undefined, - }, - ], + hash: undefined + } + ] }); }); test('test transformMapToArray with map_entry option', () => { @@ -156,16 +153,15 @@ describe('test httpProvider', () => { const transferInput = dataType.lookupType('MerklePathNodeMapEntry'); const params = { hash: '0x967f2a2c7f3d22f9278175c1e6aa39cf9171db91dceacd5ee0f37c2e507b5abe', - isLeftChildNode: true, + isLeftChildNode: true }; const result = transformMapToArray(transferInput, params); expect(result).toEqual([ { key: 'hash', - value: - '0x967f2a2c7f3d22f9278175c1e6aa39cf9171db91dceacd5ee0f37c2e507b5abe', + value: '0x967f2a2c7f3d22f9278175c1e6aa39cf9171db91dceacd5ee0f37c2e507b5abe' }, - { key: 'isLeftChildNode', value: true }, + { key: 'isLeftChildNode', value: true } ]); }); test('test transformMapToArray without inputType fieldsArray', async () => { @@ -193,14 +189,14 @@ describe('test httpProvider', () => { const params = { address: '7RzVGiuVWkvL4VfVHdZfQF2Tri3sgLe9U991bohHFfSRZXuGX', amount: '100000000', - symbol: 'ELF', + symbol: 'ELF' }; const result = transformArrayToMap(transferInput, params); expect(result).toEqual({ address: '7RzVGiuVWkvL4VfVHdZfQF2Tri3sgLe9U991bohHFfSRZXuGX', amount: '100000000', symbol: 'ELF', - to: undefined, + to: undefined }); }); test('test transformArrayToMap with fieldsArray which has resolvedType', async () => { @@ -211,9 +207,9 @@ describe('test httpProvider', () => { merklePathNodes: [ { to: '0x967f2a2c7f3d22f9278175c1e6aa39cf9171db91dceacd5ee0f37c2e507b5abe', - isLeftChildNode: true, - }, - ], + isLeftChildNode: true + } + ] }; const result = transformArrayToMap(transferInput, params); expect(result).toEqual({ @@ -221,9 +217,9 @@ describe('test httpProvider', () => { { to: '0x967f2a2c7f3d22f9278175c1e6aa39cf9171db91dceacd5ee0f37c2e507b5abe', isLeftChildNode: true, - hash: undefined, - }, - ], + hash: undefined + } + ] }); }); test('test transformArrayToMap with map_entry option', async () => { @@ -233,15 +229,14 @@ describe('test httpProvider', () => { const params = [ { key: 'hash', - value: - '0x967f2a2c7f3d22f9278175c1e6aa39cf9171db91dceacd5ee0f37c2e507b5abe', + value: '0x967f2a2c7f3d22f9278175c1e6aa39cf9171db91dceacd5ee0f37c2e507b5abe' }, - { key: 'isLeftChildNode', value: true }, + { key: 'isLeftChildNode', value: true } ]; const result = transformArrayToMap(transferInput, params); expect(result).toEqual({ hash: '0x967f2a2c7f3d22f9278175c1e6aa39cf9171db91dceacd5ee0f37c2e507b5abe', - isLeftChildNode: true, + isLeftChildNode: true }); }); test('test transformArrayToMap with map_entry and repeated options', async () => { @@ -252,18 +247,17 @@ describe('test httpProvider', () => { merklePathNodes: [ { key: 'hash', - value: - '0x967f2a2c7f3d22f9278175c1e6aa39cf9171db91dceacd5ee0f37c2e507b5abe', + value: '0x967f2a2c7f3d22f9278175c1e6aa39cf9171db91dceacd5ee0f37c2e507b5abe' }, - { key: 'isLeftChildNode', value: true }, - ], + { key: 'isLeftChildNode', value: true } + ] }; const result = transformArrayToMap(transferInput, params); expect(result).toEqual({ merklePathNodes: { hash: '0x967f2a2c7f3d22f9278175c1e6aa39cf9171db91dceacd5ee0f37c2e507b5abe', - isLeftChildNode: true, - }, + isLeftChildNode: true + } }); }); test('test transformArrayToMap with Enum Array', async () => { @@ -271,20 +265,17 @@ describe('test httpProvider', () => { dataType.resolveAll(); const enumArray = dataType.lookupType('TestEnumArray'); const params = { - type: ['EMAIL', 'PHONE'], + type: ['EMAIL', 'PHONE'] }; const result = transformArrayToMap(enumArray, params); expect(result).toEqual({ - type: ['EMAIL', 'PHONE'], + type: ['EMAIL', 'PHONE'] }); }); test('test encode address', async () => { - const address = - '0x967f2a2c7f3d22f9278175c1e6aa39cf9171db91dceacd5ee0f37c2e507b5abe'; + const address = '0x967f2a2c7f3d22f9278175c1e6aa39cf9171db91dceacd5ee0f37c2e507b5abe'; const result = encodeAddress(address); - expect(result).toEqual( - '4rgQm9utVaWDGc8pAexoktzeMDPumVQPZd54geUMDLovuYqZfYXpWdwn8dVa8m5a7DvgA1KLF' - ); + expect(result).toEqual('4rgQm9utVaWDGc8pAexoktzeMDPumVQPZd54geUMDLovuYqZfYXpWdwn8dVa8m5a7DvgA1KLF'); }); test('test input address filter with Address format', async () => { const dataType = AElf.pbjs.Root.fromJSON(nonStandardProto); @@ -293,90 +284,63 @@ describe('test httpProvider', () => { expect(result).toBeFalsy(); }); test('test input address transformer with string origin', () => { - const address = - 'ELF_UFRnXNHnVNiWfKZ9c5hSSt9Vt97zYf6xHF7nTNkq7WoiLL4BU_AELF'; + const address = 'ELF_UFRnXNHnVNiWfKZ9c5hSSt9Vt97zYf6xHF7nTNkq7WoiLL4BU_AELF'; const result = INPUT_TRANSFORMERS[0].transformer(address); - expect(result.value.toString('hex')).toEqual( - '3ddf220f80720e28a5d21229adc212acfe89d88b89728a573e25f87e730f51a6' - ); + expect(result.value.toString('hex')).toEqual('3ddf220f80720e28a5d21229adc212acfe89d88b89728a573e25f87e730f51a6'); }); test('test input address transformer with array origin', () => { - const address = [ - 'ELF_UFRnXNHnVNiWfKZ9c5hSSt9Vt97zYf6xHF7nTNkq7WoiLL4BU_AELF', - ]; + const address = ['ELF_UFRnXNHnVNiWfKZ9c5hSSt9Vt97zYf6xHF7nTNkq7WoiLL4BU_AELF']; const result = INPUT_TRANSFORMERS[0].transformer(address); - expect(result[0].value.toString('hex')).toEqual( - '3ddf220f80720e28a5d21229adc212acfe89d88b89728a573e25f87e730f51a6' - ); + expect(result[0].value.toString('hex')).toEqual('3ddf220f80720e28a5d21229adc212acfe89d88b89728a573e25f87e730f51a6'); }); test('test input hash transformer with string origin', () => { - const address = - '0x967f2a2c7f3d22f9278175c1e6aa39cf9171db91dceacd5ee0f37c2e507b5abe'; + const address = '0x967f2a2c7f3d22f9278175c1e6aa39cf9171db91dceacd5ee0f37c2e507b5abe'; const result = INPUT_TRANSFORMERS[1].transformer(address); - expect(result.value.toString('hex')).toEqual( - '967f2a2c7f3d22f9278175c1e6aa39cf9171db91dceacd5ee0f37c2e507b5abe' - ); + expect(result.value.toString('hex')).toEqual('967f2a2c7f3d22f9278175c1e6aa39cf9171db91dceacd5ee0f37c2e507b5abe'); }); test('test input hash transformer with array origin', () => { - const address = [ - '0x967f2a2c7f3d22f9278175c1e6aa39cf9171db91dceacd5ee0f37c2e507b5abe', - ]; + const address = ['0x967f2a2c7f3d22f9278175c1e6aa39cf9171db91dceacd5ee0f37c2e507b5abe']; const result = INPUT_TRANSFORMERS[1].transformer(address); - expect(result[0].value.toString('hex')).toEqual( - '967f2a2c7f3d22f9278175c1e6aa39cf9171db91dceacd5ee0f37c2e507b5abe' - ); + expect(result[0].value.toString('hex')).toEqual('967f2a2c7f3d22f9278175c1e6aa39cf9171db91dceacd5ee0f37c2e507b5abe'); }); test('test output address transformer with string origin', () => { - const address = - 'ELF_UFRnXNHnVNiWfKZ9c5hSSt9Vt97zYf6xHF7nTNkq7WoiLL4BU_AELF'; + const address = 'ELF_UFRnXNHnVNiWfKZ9c5hSSt9Vt97zYf6xHF7nTNkq7WoiLL4BU_AELF'; const result = OUTPUT_TRANSFORMERS[0].transformer(address); - expect(result).toEqual( - 'ELF_UFRnXNHnVNiWfKZ9c5hSSt9Vt97zYf6xHF7nTNkq7WoiLL4BU_AELF' - ); + expect(result).toEqual('ELF_UFRnXNHnVNiWfKZ9c5hSSt9Vt97zYf6xHF7nTNkq7WoiLL4BU_AELF'); }); test('test output address transformer with object origin', () => { const address = { - value: 'ELF_UFRnXNHnVNiWfKZ9c5hSSt9Vt97zYf6xHF7nTNkq7WoiLL4BU_AELF', + value: 'ELF_UFRnXNHnVNiWfKZ9c5hSSt9Vt97zYf6xHF7nTNkq7WoiLL4BU_AELF' }; const result = OUTPUT_TRANSFORMERS[0].transformer(address); - expect(result).toEqual( - '93i8Rz5MTnfLURQ7drVMoFoMJGV1axnMQqJL3TpS65aRpMqb4XD8THJvcMFFxeVv' - ); + expect(result).toEqual('93i8Rz5MTnfLURQ7drVMoFoMJGV1axnMQqJL3TpS65aRpMqb4XD8THJvcMFFxeVv'); }); test('test output address transformer with array object origin', () => { const address = [ { - value: 'FXD7R7PHkfRn4fmEDvHCN+7hb2XD0NgAcxXjYkMccuY=', - }, + value: 'FXD7R7PHkfRn4fmEDvHCN+7hb2XD0NgAcxXjYkMccuY=' + } ]; const result = OUTPUT_TRANSFORMERS[0].transformer(address); - expect(result).toEqual([ - 'ASh2Wt7nSEmYqnGxPPzp4pnVDU4uhj1XW9Se5VeZcX2UDdyjx', - ]); + expect(result).toEqual(['ASh2Wt7nSEmYqnGxPPzp4pnVDU4uhj1XW9Se5VeZcX2UDdyjx']); }); test('test output hash transformer with string origin', () => { - const address = - '0x967f2a2c7f3d22f9278175c1e6aa39cf9171db91dceacd5ee0f37c2e507b5abe'; + const address = '0x967f2a2c7f3d22f9278175c1e6aa39cf9171db91dceacd5ee0f37c2e507b5abe'; const result = OUTPUT_TRANSFORMERS[1].transformer(address); - expect(result).toEqual( - '0x967f2a2c7f3d22f9278175c1e6aa39cf9171db91dceacd5ee0f37c2e507b5abe' - ); + expect(result).toEqual('0x967f2a2c7f3d22f9278175c1e6aa39cf9171db91dceacd5ee0f37c2e507b5abe'); }); test('test output hash transformer with array object origin', () => { const address = [ { - value: 'FXD7R7PHkfRn4fmEDvHCN+7hb2XD0NgAcxXjYkMccuY=', - }, + value: 'FXD7R7PHkfRn4fmEDvHCN+7hb2XD0NgAcxXjYkMccuY=' + } ]; const result = OUTPUT_TRANSFORMERS[1].transformer(address); - expect(result).toEqual([ - '1570fb47b3c791f467e1f9840ef1c237eee16f65c3d0d8007315e362431c72e6', - ]); + expect(result).toEqual(['1570fb47b3c791f467e1f9840ef1c237eee16f65c3d0d8007315e362431c72e6']); }); test('test output address transformer with object origin', () => { const address = { - value: - '0x967f2a2c7f3d22f9278175c1e6aa39cf9171db91dceacd5ee0f37c2e507b5abe', + value: '0x967f2a2c7f3d22f9278175c1e6aa39cf9171db91dceacd5ee0f37c2e507b5abe' }; const result = OUTPUT_TRANSFORMERS[1].transformer(address); expect(result).toEqual(