From ad2987daf3f33fbd73de18b007cc756b3c33097e Mon Sep 17 00:00:00 2001 From: yAmanda Date: Tue, 22 Oct 2019 14:54:04 +0800 Subject: [PATCH] refactor: not parse response data to object any more --- README.md | 15 +++- README_zh.md | 15 +++- lib/const.js | 25 ++++-- lib/modules/account.js | 14 ++-- lib/network/data_parser.js | 68 ++++------------- test/datas.js | 153 ++++++++++++++++++++++++------------- test/modules/account.js | 35 +++------ 7 files changed, 175 insertions(+), 150 deletions(-) diff --git a/README.md b/README.md index 45031c2..6cde1ec 100644 --- a/README.md +++ b/README.md @@ -582,13 +582,24 @@ None ##### Returns `Promise` - Call `then` method to get the address list of current deputy nodes. The address can be used to [connect](#submodule-net-connect) LemoChain node. + `minerAddress` - (string)The address of miner account who receive miner benefit + `incomeAddress` - (string)Nodal incomeAddress + `nodeID` - (string)The LemoChain node ID, it is from the public key whose private key is using for sign blocks. The length should be 130 characters with `0x` + `rank` - (string)The rank of the outgoing node + `votes` - (string)Node votes + `host` - (string)The LemoChain node ID, it is from the public key whose private key is using for sign blocks. The length should be 130 characters with `0x` + `port` - (string)Port of the candidate node server + `depositAmount` - (string)deposit amount + `introduction` - (string)Introduction of node ##### Example ```js lemo.getDeputyNodeList().then(function(nodeList) { console.log(nodeList.length) // 1 - console.log(nodeList[0]) // "0x5e3600755f9b512a65603b38e30885c98cbac70259c3235c9b3f42ee563b480edea351ba0ff5748a638fe0aeff5d845bf37a3b437831871b48fd32f33cd9a3c0@149.28.68.93:7003" - lemo.net.connect(nodeList[0]) + console.log(JSON.stringify(nodeList[0])) +// "{"minerAddress":"Lemo83DZ5J99JSK5ZH89TCW7T6ZZCWJ8H7FDGA7W","incomeAddress":"Lemo83DZ5J99JSK5ZH89TCW7T6ZZCWJ8H7FDGA7W","nodeID":"0x0e7dcd418dbe7717eb0e83162f8810a3c7725e0d386b324dc5f3ef5a27a2a83e393a193f6ab53d3a51b490adeee362357676f50eed3d188824ef1fb3af02b2d0","rank":"0","votes":"50000","host":"127.0.0.1","port":"8080","depositAmount":"5000000000000000000000000","introduction":"ddf"}" + const nodeName = `${nodeList[0].nodeID}@${nodeList[0].host}:${nodeList[0].port}` + lemo.net.connect(nodeName) }) ``` diff --git a/README_zh.md b/README_zh.md index dcef947..841566b 100644 --- a/README_zh.md +++ b/README_zh.md @@ -655,13 +655,24 @@ lemo.getDeputyNodeList() ##### Returns `Promise` - 通过`then`可以获取当前所有共识节点的地址列表。该地址可用于[连接节点](#submodule-net-connect) + `minerAddress` - (string)节点出块账号 + `incomeAddress` - (string)节点收益账号 + `nodeID` - (string)节点ID + `rank` - (string)出块节点所在的排名 + `votes` - (string)节点所得票数 + `host` - (string)节点域名 + `port` - (string)端口号 + `depositAmount` - (string)质押金额 + `introduction` - (string)节点简介 ##### Example ```js lemo.getDeputyNodeList().then(function(nodeList) { console.log(nodeList.length) // 1 - console.log(nodeList[0]) // "5e3600755f9b512a65603b38e30885c98cbac70259c3235c9b3f42ee563b480edea351ba0ff5748a638fe0aeff5d845bf37a3b437831871b48fd32f33cd9a3c0@149.28.68.93:7003" - lemo.net.connect(nodeList[0]) + console.log(JSON.stringify(nodeList[0])) +// "{"minerAddress":"Lemo83DZ5J99JSK5ZH89TCW7T6ZZCWJ8H7FDGA7W","incomeAddress":"Lemo83DZ5J99JSK5ZH89TCW7T6ZZCWJ8H7FDGA7W","nodeID":"0x0e7dcd418dbe7717eb0e83162f8810a3c7725e0d386b324dc5f3ef5a27a2a83e393a193f6ab53d3a51b490adeee362357676f50eed3d188824ef1fb3af02b2d0","rank":"0","votes":"50000","host":"127.0.0.1","port":"8080","depositAmount":"5000000000000000000000000","introduction":"ddf"}" + const nodeName = `${nodeList[0].nodeID}@${nodeList[0].host}:${nodeList[0].port}` + lemo.net.connect(nodeName) }) ``` diff --git a/lib/const.js b/lib/const.js index 2e04c5f..ed34043 100644 --- a/lib/const.js +++ b/lib/const.js @@ -35,14 +35,23 @@ export const TxType = { export const ChangeLogTypes = { BalanceLog: 1, StorageLog: 2, - CodeLog: 3, - AddEventLog: 4, - SuicideLog: 5, - VoteForLog: 6, - VotesLog: 7, - CandidateProfileLog: 8, - TxCountLog: 9, - SignersLog: 10, + StorageRootLog: 3, + AssetCodeLog: 4, + AssetCodeStateLog: 5, + AssetCodeRootLog: 6, + AssetCodeTotalSupplyLog: 7, + AssetIdLog: 8, + AssetIdRootLog: 9, + EquityLog: 10, + EquityRootLog: 11, + CandidateLog: 12, + CandidateStateLog: 13, + CodeLog: 14, + AddEventLog: 15, + SuicideLog: 16, + VoteForLog: 17, + VotesLog: 18, + SignerLog: 19, } // module name diff --git a/lib/modules/account.js b/lib/modules/account.js index 225c76c..56b0dc9 100644 --- a/lib/modules/account.js +++ b/lib/modules/account.js @@ -6,14 +6,13 @@ const apis = { /** * Get account information * @param {string} address - * @return {Promise} + * @return {Promise} */ - async getAccount(address) { + getAccount(address) { if (!isLemoAddress(address)) { throw new Error(error.InvalidAddress(address)) } - const result = await this.requester.send(`${ACCOUNT_NAME}_getAccount`, [address]) - return this.parser.parseAccount(result) + return this.requester.send(`${ACCOUNT_NAME}_getAccount`, [address]) }, /** * Get candidate information @@ -30,14 +29,13 @@ const apis = { /** * Get balance from account * @param {string} address - * @return {Promise} + * @return {Promise} */ - async getBalance(address) { + getBalance(address) { if (!isLemoAddress(address)) { throw new Error(error.InvalidAddress(address)) } - const result = await this.requester.send(`${ACCOUNT_NAME}_getBalance`, [address]) - return this.parser.parseMoney(result) + return this.requester.send(`${ACCOUNT_NAME}_getBalance`, [address]) }, } diff --git a/lib/network/data_parser.js b/lib/network/data_parser.js index 314875c..1ed3f02 100644 --- a/lib/network/data_parser.js +++ b/lib/network/data_parser.js @@ -26,15 +26,12 @@ export function parseBlock(block, withBody) { } export function parseAccount(account) { - account.balance = parseMoney(account.balance) - account.txCount = parseNumber(account.txCount) - const oldRecords = account.records || {} account.records = {} Object.entries(oldRecords).forEach(([logType, record]) => { record.height = parseNumber(record.height) record.version = parseNumber(record.version) - account.records[parseChangeLogType(logType)] = record + account.records[parseNumber(logType)] = record }) if (account.candidate) { @@ -47,100 +44,62 @@ export function parseAccount(account) { export function parseCandidate(candidate) { if (candidate.profile) { candidate.profile.isCandidate = /true/i.test(candidate.profile.isCandidate) - candidate.profile.port = parseNumber(candidate.profile.port) } return candidate } export function parseChangeLog(changeLog) { - changeLog.type = parseChangeLogType(changeLog.type) + changeLog.type = parseNumber(changeLog.type) changeLog.version = parseNumber(changeLog.version) return changeLog } -export function parseChangeLogType(logType) { - logType = parseInt(logType, 10) - const typeInfo = Object.entries(ChangeLogTypes).find(item => logType === item[1]) - if (!typeInfo) { - return `UnknonwType(${logType})` - } - return typeInfo[0] -} - function parseTx(tx) { - // new Tx will fill default fields such as gasPrice. So we couldn't return it directly - const txObj = new LemoTx(tx) - tx.from = txObj.from - tx.type = txObj.type - tx.typeText = parseTxType(txObj.type) - tx.version = txObj.version - tx.amountText = String(tx.amount) - tx.gasPriceText = String(tx.gasPrice) - tx.amount = parseMoney(tx.amount) + tx.type = parseNumber(tx.type) + tx.version = parseNumber(tx.version) tx.expirationTime = parseNumber(tx.expirationTime) - tx.gasPrice = parseMoney(tx.gasPrice) tx.gasLimit = parseNumber(tx.gasLimit) - tx.data = parseTxData(tx.type, tx.data) + tx.parsedData = parseTxData(tx.type, tx.data) + tx.gasUsed = parseNumber(tx.gasUsed) return tx } -function parseTxType(txType) { - txType = parseInt(txType, 10) - const typeInfo = Object.entries(TxType).find(item => txType === item[1]) - if (!typeInfo) { - return `UnknonwType(${txType})` - } - return typeInfo[0] -} - function parseNumber(str) { return parseInt(str, 10) || 0 } export function parseTxData(type, data) { type = parseNumber(type) + let result switch (type) { case TxType.ORDINARY: - break case TxType.CREATE_CONTRACT: + case TxType.VOTE: + result = undefined break case TxType.BOX_TX: data = JSON.parse(toBuffer(data).toString()) - data = data.map(parseTx) + result = data.map(parseTx) break default: - data = JSON.parse(toBuffer(data).toString()) + result = JSON.parse(toBuffer(data).toString()) break } - return data -} - -export function parseBigNumber(str) { - return new BigNumber(str) -} - -export function parseMoney(str) { - const result = new BigNumber(str) - Object.defineProperty(result, 'toMoney', { - enumerable: false, - value: formatLEMO.bind(null, result), - }) return result } export function parseAsset(result) { result.equities.forEach(item => { - item.equity = parseBigNumber(item.equity) + item.equity = parseNumber(item.equity) }) return result } export function parseAssetInfo(result) { result.decimal = parseNumber(result.decimal) - result.totalSupply = parseBigNumber(result.totalSupply) return result } @@ -151,13 +110,12 @@ export function parseMetaData(result) { return result } + export default { parseBlock, parseAccount, parseCandidate, parseTx, - parseBigNumber, - parseMoney, parseAsset, parseAssetInfo, parseMetaData, diff --git a/test/datas.js b/test/datas.js index af1ca11..57fd125 100644 --- a/test/datas.js +++ b/test/datas.js @@ -1,8 +1,10 @@ import BigNumber from 'bignumber.js' +import {ChangeLogTypes, TxType} from '../lib/const' const bigNum = '0x111111111111111111111111111111111111111111111111111111111111' const bigString = '888888888888888888888888888888888888888888888888888888888888' const bigData = '0x4949494949494949' +const balanceLog = ChangeLogTypes.BalanceLog export const testPrivate = '0x432a86ab8765d82415a803e29864dcfc1ed93dac949abf6f95a583179f27e4bb' export const testAddr = 'Lemo836BQKCBZ8Z7B7N4G4N4SNGBT24ZZSJQD24D' @@ -23,7 +25,7 @@ export const infos = { } export const emptyAccount = { - balance: '0x0', + balance: '0', codeHash: '0x0000000000000000000000000000000000000000000000000000000000000000', records: {}, root: '0x0000000000000000000000000000000000000000000000000000000000000000', @@ -34,9 +36,9 @@ export const miner = { balance: '1599999999999999999999999900', codeHash: '0x0000000000000000000000000000000000000000000000000000000000000000', records: { - 1: { - height: '1', - version: '3', + [balanceLog]: { + height: 1, + version: 3, }, }, root: '0x0000000000000000000000000000000000000000000000000000000000000000', @@ -44,7 +46,7 @@ export const miner = { candidate: { profile: { host: '127.0.0.1', - isCandidate: 'true', + isCandidate: true, minerAddress: 'Lemobw', nodeID: '0x5e3600755f9b512a65603b38e30885c98cbac70259c3235c9b3f42ee563b480edea351ba0ff5748a638fe0aeff5d845bf37a3b437831871b48fd32f33cd9a3c0', @@ -56,9 +58,9 @@ export const miner = { } export const formatedMiner = { ...miner, - balance: new BigNumber('1599999999999999999999999900'), + balance: '1599999999999999999999999900', records: { - BalanceLog: { + [balanceLog]: { height: 1, version: 3, }, @@ -67,11 +69,9 @@ export const formatedMiner = { profile: { ...miner.candidate.profile, isCandidate: true, - port: 7001, }, votes: '1599999000', }, - txCount: 0, } export const formattedSpecialLemoBase = { ...emptyAccount, @@ -104,7 +104,7 @@ export const txInfo = { txConfig: { chainID, version: 1, - type: 0, + type: TxType.ORDINARY, to: 'Lemo846Q4NQCKJ2YWY6GHTSQHC7K24JDC7CPCWYH', toName: 'aa', gasPrice: 2, @@ -128,7 +128,7 @@ export const bigTxInfo = { txConfig: { chainID, version: 1, - type: 0, + type: TxType.ORDINARY, to: 'Lemo837J796DDHYTQTRTQDT7B4QJJ9B6H559BCCT', toName: bigString, gasPrice: bigNum, @@ -189,12 +189,13 @@ export const currentBlock = { { chainID: '1', version: '1', - type: '0', + type: TxType.ORDINARY, from: 'Lemo836BQKCBZ8Z7B7N4G4N4SNGBT24ZZSJQD24D', to: 'Lemo83JW7TBPA7P2P6AR9ZC2WCQJYRNHZ4NJD4CY', toName: 'aa', gasPrice: '3000000000', gasLimit: '2000000', + gasUsed: 0, amount: '101', data: '0x0c', expirationTime: '1541649536', @@ -218,14 +219,12 @@ export const formattedCurrentBlock = { transactions: [ { ...currentBlock.transactions[0], - gasPriceText: '3000000000', - gasPrice: new BigNumber('3000000000'), + gasPrice: '3000000000', gasLimit: 2000000, - amountText: '101', - amount: new BigNumber('101'), + amount: '101', expirationTime: 1541649536, - type: 0, - typeText: 'ORDINARY', + type: TxType.ORDINARY, + parsedData: undefined, version: 1, }, ], @@ -255,12 +254,13 @@ export const block1 = { { chainID: '1', version: '1', - type: '0', + type: TxType.ORDINARY, from: 'Lemo83GN72GYH2NZ8BA729Z9TCT7KQ5FC3CR6DJG', to: 'Lemo83JW7TBPA7P2P6AR9ZC2WCQJYRNHZ4NJD4CY', toName: '', gasPrice: '3000000000', gasLimit: '2000000', + gasUsed: 0, amount: '100', data: '0x', expirationTime: '1541649535', @@ -272,21 +272,21 @@ export const block1 = { ], changeLogs: [ { - type: '1', + type: TxType.ORDINARY, address: 'Lemo83GN72GYH2NZ8BA729Z9TCT7KQ5FC3CR6DJG', version: '2', newValue: '0x8c052b7d2dcc8093e1eb610f9c', extra: '', }, { - type: '1', + type: TxType.ORDINARY, address: 'Lemo83JW7TBPA7P2P6AR9ZC2WCQJYRNHZ4NJD4CY', version: '1', newValue: '0x64', extra: '', }, { - type: '1', + type: TxType.ORDINARY, address: 'Lemo83GN72GYH2NZ8BA729Z9TCT7KQ5FC3CR6DJG', version: '3', newValue: '0x8c052b7d2dcc80cd2e3fffff9c', @@ -310,31 +310,30 @@ export const formattedBlock1 = { transactions: [ { ...block1.transactions[0], - gasPriceText: '3000000000', - gasPrice: new BigNumber('3000000000'), + gasPrice: '3000000000', gasLimit: 2000000, - amountText: '100', - amount: new BigNumber('100'), + gasUsed: 0, + amount: '100', expirationTime: 1541649535, - type: 0, - typeText: 'ORDINARY', + type: TxType.ORDINARY, + parsedData: undefined, version: 1, }, ], changeLogs: [ { ...block1.changeLogs[0], - type: 'BalanceLog', + type: TxType.ORDINARY, version: 2, }, { ...block1.changeLogs[1], - type: 'BalanceLog', + type: TxType.ORDINARY, version: 1, }, { ...block1.changeLogs[2], - type: 'BalanceLog', + type: TxType.ORDINARY, version: 3, }, ], @@ -397,7 +396,7 @@ export const oneChangeLogBlock = { transactions: [], changeLogs: [ { - type: '1', + type: TxType.VOTE, address: 'Lemo83GN72GYH2NZ8BA729Z9TCT7KQ5FC3CR6DJG', version: '2', newValue: '0x8c052b7d2dcc8093e1eb610f9c', @@ -430,7 +429,7 @@ export const formattedOneChangeLogBlock = { changeLogs: [ { ...oneChangeLogBlock.changeLogs[0], - type: 'BalanceLog', + type: TxType.VOTE, version: 2, }, ], @@ -441,10 +440,11 @@ export const txInfos = [emptyTxInfo, txInfo, bigTxInfo] const tx1 = { ...emptyTxInfo.txConfig, version: '1', - type: '0', + type: TxType.ORDINARY, toName: '', gasPrice: '3000000000', gasLimit: '2000000', + gasUsed: 0, amount: '0', data: '0x', expirationTime: '1544584596', @@ -455,21 +455,24 @@ const tx1 = { const formattedTx1 = { ...tx1, from: testAddr, - gasPrice: new BigNumber('3000000000'), + gasPrice: '3000000000', gasLimit: 2000000, expirationTime: 1544584596, - amount: new BigNumber('0'), - type: 0, - typeText: 'ORDINARY', + amount: '0', + type: TxType.ORDINARY, + parsedData: undefined, version: 1, } const tx2 = { ...txInfo.txConfig, version: '1', - type: '0', + type: TxType.ORDINARY, gasPrice: '2', + gasPriceText: '2', gasLimit: '100', + gasUsed: 0, + amountText: '1', amount: '1', expirationTime: '1544584596', sigs: ['0x8c0499083cb3d27bead4f21994aeebf8e75fa11df6bfe01c71cad583fc9a3c70778a437607d072540719a866adb630001fabbfb6b032d1a8dfbffac7daed8f0201'], @@ -478,21 +481,22 @@ const tx2 = { const formattedTx2 = { ...tx2, from: testAddr, - gasPrice: new BigNumber('2'), + gasPrice: '2', gasLimit: 100, expirationTime: 1544584596, - amount: new BigNumber('1'), - type: 0, - typeText: 'ORDINARY', + amount: '1', + type: TxType.ORDINARY, + parsedData: undefined, version: 1, } const tx3 = { ...bigTxInfo.txConfig, version: '1', - type: '0', + type: TxType.ORDINARY, gasPrice: bigNum, gasLimit: '100', + gasUsed: 10, amount: bigNum, expirationTime: '1544584596', sigs: ['0xacba6ce994874d7b856d663a7f1d04bc7bf65278d33afb0a7fd8da69f626292a01e6badf976c360673b71c54ff363bbcb521ae545fec47cb0bf83eb4c83332b601'], @@ -501,12 +505,12 @@ const tx3 = { const formattedTx3 = { ...tx3, from: testAddr, - gasPrice: new BigNumber(bigNum), + gasPrice: '0x111111111111111111111111111111111111111111111111111111111111', gasLimit: 100, expirationTime: 1544584596, - amount: new BigNumber(bigNum), - type: 0, - typeText: 'ORDINARY', + amount: '0x111111111111111111111111111111111111111111111111111111111111', + type: TxType.ORDINARY, + parsedData: undefined, version: 1, } @@ -521,13 +525,19 @@ export const txRes1 = { height: '100', time: '1541649535', tx: tx1, + pHash: '0x0000000000000000000000000000000000000000000000000000000000000000', + assetCode: '0x0000000000000000000000000000000000000000000000000000000000000000', + assetId: '0x0000000000000000000000000000000000000000000000000000000000000000', } export const formattedTxRes1 = { ...formattedTx1, blockHeight: 100, minedTime: 1541649535, + pHash: '0x0000000000000000000000000000000000000000000000000000000000000000', blockHash: '0x425f4ca99da879aa97bd6feaef0d491096ff3437934a139f423fecf06f9fd5ab', + assetCode: '0x0000000000000000000000000000000000000000000000000000000000000000', + assetId: '0x0000000000000000000000000000000000000000000000000000000000000000', } export const txRes2 = { @@ -535,12 +545,14 @@ export const txRes2 = { height: '100', time: '1541649535', tx: tx2, + pHash: '0x0000000000000000000000000000000000000000000000000000000000000000', } export const formattedTxRes2 = { ...formattedTx2, blockHeight: 100, minedTime: 1541649535, + pHash: '0x0000000000000000000000000000000000000000000000000000000000000000', blockHash: '0x425f4ca99da879aa97bd6feaef0d491096ff3437934a139f423fecf06f9fd5ab', } export const txRes3 = { @@ -548,6 +560,7 @@ export const txRes3 = { height: '100', time: '1541649535', tx: tx3, + pHash: '0x0000000000000000000000000000000000000000000000000000000000000000', } export const formattedTxRes3 = { @@ -561,30 +574,68 @@ export const txList = [ { tx: tx1, time: '1541649535', + pHash: '0x0000000000000000000000000000000000000000000000000000000000000000', + assetId: '0x1b9ef0086053ca7e41b7b5e5f0db422e4c987a5504f373fed5176635838ca446', + assetCode: '0x1b9ef0086053ca7e41b7b5e5f0db422e4c987a5504f373fed5176635838ca446', }, { tx: tx2, time: '1541649536', + pHash: '0x0000000000000000000000000000000000000000000000000000000000000000', + assetId: '0x1b9ef0086053ca7e41b7b5e5f0db422e4c987a5504f373fed5176635838ca446', + assetCode: '0x1b9ef0086053ca7e41b7b5e5f0db422e4c987a5504f373fed5176635838ca446', }, { tx: tx3, time: '1541649536', + pHash: '0x0000000000000000000000000000000000000000000000000000000000000000', + assetId: '0x8dd85a833c482b4cb24f261e2d5378c14507eb01a92d89eb4a8278302f70cff5', + assetCode: '0x8dd85a833c482b4cb24f261e2d5378c14507eb01a92d89eb4a8278302f70cff5', }, ] + +export const formattedAssetTxListRes = { + txList: [ + { + ...formattedTx1, + minedTime: 1541649535, + pHash: '0x0000000000000000000000000000000000000000000000000000000000000000', + assetId: '0x1b9ef0086053ca7e41b7b5e5f0db422e4c987a5504f373fed5176635838ca446', + assetCode: '0x1b9ef0086053ca7e41b7b5e5f0db422e4c987a5504f373fed5176635838ca446', + }, + { + ...formattedTx2, + minedTime: 1541649536, + pHash: '0x0000000000000000000000000000000000000000000000000000000000000000', + assetId: '0x1b9ef0086053ca7e41b7b5e5f0db422e4c987a5504f373fed5176635838ca446', + assetCode: '0x1b9ef0086053ca7e41b7b5e5f0db422e4c987a5504f373fed5176635838ca446', + }, + ], + total: 2, +} export const formattedTxListRes = { txList: [ { ...formattedTx1, minedTime: 1541649535, + pHash: '0x0000000000000000000000000000000000000000000000000000000000000000', + assetId: '0x1b9ef0086053ca7e41b7b5e5f0db422e4c987a5504f373fed5176635838ca446', + assetCode: '0x1b9ef0086053ca7e41b7b5e5f0db422e4c987a5504f373fed5176635838ca446', }, { ...formattedTx2, minedTime: 1541649536, + pHash: '0x0000000000000000000000000000000000000000000000000000000000000000', + assetId: '0x1b9ef0086053ca7e41b7b5e5f0db422e4c987a5504f373fed5176635838ca446', + assetCode: '0x1b9ef0086053ca7e41b7b5e5f0db422e4c987a5504f373fed5176635838ca446', }, { ...formattedTx3, minedTime: 1541649536, + pHash: '0x0000000000000000000000000000000000000000000000000000000000000000', + assetId: '0x8dd85a833c482b4cb24f261e2d5378c14507eb01a92d89eb4a8278302f70cff5', + assetCode: '0x8dd85a833c482b4cb24f261e2d5378c14507eb01a92d89eb4a8278302f70cff5', }, ], total: 3, @@ -607,7 +658,7 @@ const formattedCandidate1 = { profile: { ...candidate1.profile, isCandidate: true, - port: 7001, + port: '7001', }, votes: '1599999000000000000000000001', } @@ -629,7 +680,7 @@ const formattedCandidate2 = { profile: { ...candidate2.profile, isCandidate: true, - port: 8080, + port: '8080', }, } @@ -656,7 +707,7 @@ export const formattedEquities = [ { assertCode: '0xd0befd3850c574b7f6ad6f7943fe19b212affb90162978adc2193a035ced8884', assetId: '0x34b04e018488f37f449193af2f24feb3b034c994cde95d30e3181403ac76528a', - equity: new BigNumber(1), + equity: 1, }, ] diff --git a/test/modules/account.js b/test/modules/account.js index fd2a8b8..b2aa6df 100644 --- a/test/modules/account.js +++ b/test/modules/account.js @@ -14,23 +14,17 @@ describe('module_account_getAccount', () => { it('account with special balance', async () => { const lemo = new LemoCore() const addr = '0x015780F8456F9c1532645087a19DcF9a7e0c7F97' - const expectedErr = errors.InvalidAddress(addr) - return lemo.account.getAccount(addr).then(() => { - assert.fail('success', `throw error: ${expectedErr}`) - }, e => { - return assert.equal(e.message, expectedErr) - }) + assert.throws(() => { + lemo.account.getAccount(addr) + }, errors.InvalidAddress(addr)) }) it('account is empty', async () => { const lemo = new LemoCore() const addr = '' - const expectedErr = errors.InvalidAddress(addr) - return lemo.account.getAccount(addr).then(() => { - assert.fail('success', `throw error: ${expectedErr}`) - }, e => { - return assert.equal(e.message, expectedErr) - }) + assert.throws(() => { + lemo.account.getAccount(addr) + }, errors.InvalidAddress(addr)) }) }) @@ -61,25 +55,18 @@ describe('module_account_getBalance', () => { it('no-balance', async () => { const lemo = new LemoCore() const result = await lemo.account.getBalance('Lemo846Q4NQCKJ2YWY6GHTSQHC7K24JDC7CPCWYH') - assert.strictEqual(result instanceof BigNumber, true) - assert.exists(result.toMoney) - assert.strictEqual(result.toMoney(), '0 LEMO') + assert.strictEqual(result, '0') }) it('balance', async () => { const lemo = new LemoCore() const result = await lemo.account.getBalance('Lemo83GN72GYH2NZ8BA729Z9TCT7KQ5FC3CR6DJG') - assert.strictEqual(result instanceof BigNumber, true) - assert.exists(result.toMoney) - assert.strictEqual(result.toMoney(), '1599999999.9999999999999999 LEMO') + assert.equal(result, '1599999999999999999999999900') }) it('getBalance_error', () => { const lemo = new LemoCore() const addr = '0x015780F8456F9c1532645087a19DcF9a7e0c7F97' - const expectedErr = errors.InvalidAddress(addr) - return lemo.account.getBalance(addr).then(() => { - assert.fail('success', `throw error: ${expectedErr}`) - }, e => { - return assert.equal(e.message, expectedErr) - }) + assert.throws(() => { + lemo.account.getBalance(addr) + }, errors.InvalidAddress(addr)) }) })