From 72e181339297f3ba65b664c7524d1d21a8b97e00 Mon Sep 17 00:00:00 2001 From: Brian Faust Date: Thu, 21 Feb 2019 14:36:46 +0200 Subject: [PATCH 01/18] refactor(core-tester-cli): setup the basic structure for the rewrite --- packages/core-tester-cli/package.json | 7 +- .../core-tester-cli/src/commands/command.ts | 344 +++-------------- .../src/commands/delegate-registration.ts | 110 ------ .../src/commands/multi-signature.ts | 352 ------------------ .../src/commands/second-signature.ts | 87 ----- .../core-tester-cli/src/commands/transfer.ts | 300 +-------------- packages/core-tester-cli/src/commands/vote.ts | 100 ----- packages/core-tester-cli/src/config.ts | 7 - packages/core-tester-cli/src/flags.ts | 23 +- packages/core-tester-cli/src/http-client.ts | 34 ++ packages/core-tester-cli/src/logger.ts | 7 + packages/core-tester-cli/src/utils.ts | 142 ------- yarn.lock | 12 - 13 files changed, 114 insertions(+), 1411 deletions(-) delete mode 100644 packages/core-tester-cli/src/commands/delegate-registration.ts delete mode 100644 packages/core-tester-cli/src/commands/multi-signature.ts delete mode 100644 packages/core-tester-cli/src/commands/second-signature.ts delete mode 100644 packages/core-tester-cli/src/commands/vote.ts delete mode 100644 packages/core-tester-cli/src/config.ts create mode 100644 packages/core-tester-cli/src/http-client.ts create mode 100644 packages/core-tester-cli/src/logger.ts delete mode 100644 packages/core-tester-cli/src/utils.ts diff --git a/packages/core-tester-cli/package.json b/packages/core-tester-cli/package.json index eebb8a23b9..347e7cd3fe 100644 --- a/packages/core-tester-cli/package.json +++ b/packages/core-tester-cli/package.json @@ -47,19 +47,14 @@ "@oclif/plugin-help": "^2.1.6", "@oclif/plugin-not-found": "^1.2.2", "@types/bip39": "^2.4.1", - "@types/clipboardy": "^1.1.0", - "@types/lodash.fill": "^3.4.4", "@types/pino": "^5.8.4", "@types/pluralize": "^0.0.29", "axios": "^0.18.0", "bip39": "^2.5.0", - "clipboardy": "^1.2.3", "delay": "^4.1.0", - "lodash.fill": "^3.4.0", "pino": "^5.11.1", "pino-pretty": "^2.5.0", - "pluralize": "^7.0.0", - "superheroes": "^2.0.0" + "pluralize": "^7.0.0" }, "devDependencies": { "axios-mock-adapter": "^1.16.0" diff --git a/packages/core-tester-cli/src/commands/command.ts b/packages/core-tester-cli/src/commands/command.ts index a42858a8cd..21374821a2 100644 --- a/packages/core-tester-cli/src/commands/command.ts +++ b/packages/core-tester-cli/src/commands/command.ts @@ -1,337 +1,101 @@ -import { bignumify } from "@arkecosystem/core-utils"; -import { Bignum, crypto } from "@arkecosystem/crypto"; +import { Bignum, configManager } from "@arkecosystem/crypto"; +import { client } from "@arkecosystem/crypto"; import Command, { flags } from "@oclif/command"; -import bip39 from "bip39"; -import clipboardy from "clipboardy"; -import delay from "delay"; -import fs from "fs"; -import path from "path"; -import pluralize from "pluralize"; -import { config } from "../config"; -import { customFlags } from "../flags"; -import { logger, paginate, request } from "../utils"; +import { satoshiFlag } from "../flags"; +import { http } from "../http-client"; +import { logger } from "../logger"; export abstract class BaseCommand extends Command { public static flags = { - number: flags.integer({ - description: "number of wallets", - default: 10, + network: flags.string({ + description: "crypto network", + default: "testnet", }), - amount: customFlags.number({ - description: "initial wallet token amount", - default: 2, + host: flags.string({ + description: "API host", + default: "http://localhost", }), - transferFee: customFlags.number({ - description: "transfer fee", - default: 0.1, - }), - baseUrl: flags.string({ - description: "base api url", - }), - apiPort: flags.integer({ - description: "base api port", + port: flags.integer({ + description: "API port", default: 4003, }), - p2pPort: flags.integer({ - description: "base p2p port", - default: 4002, - }), passphrase: flags.string({ description: "passphrase of initial wallet", + default: "clay harbor enemy utility margin pretty hub comic piece aerobic umbrella acquire", }), secondPassphrase: flags.string({ description: "second passphrase of initial wallet", }), - skipValidation: flags.boolean({ - description: "skip transaction validations", + number: flags.integer({ + description: "number of wallets", + default: 10, }), - skipTesting: flags.boolean({ - description: "skip testing", + amount: satoshiFlag({ + description: "initial wallet token amount", + default: 2, }), - copy: flags.boolean({ - description: "copy the transactions to the clipboard", + transferFee: satoshiFlag({ + description: "transfer fee", + default: 0.1, }), }; - public options: any; - public config: any; - - /** - * Init new instance of command. - * @param {Object} options - * @return {*} - */ - public async initialize(command): Promise { - // tslint:disable-next-line:no-shadowed-variable - const { flags } = this.parse(command); - - this.options = flags; - this.applyConfig(); - await this.loadConstants(); - await this.loadNetworkConfig(); - - return { flags }; - } - - /** - * Copy transactions to clipboard. - * @param {Object[]} transactions - * @return {void} - */ - public copyToClipboard(transactions) { - for (const transaction of transactions) { - transaction.serialized = transaction.serialized.toString("hex"); - } - - clipboardy.writeSync(JSON.stringify(transactions)); - logger.info(`Copied ${pluralize("transaction", transactions.length, true)}`); - } - - /** - * Generate wallets based on quantity. - * @param {Number} [quantity] - * @return {Object[]} - */ - public generateWallets(quantity: any = null) { - if (!quantity) { - quantity = this.options.number; - } - - const wallets = []; - for (let i = 0; i < quantity; i++) { - const passphrase = bip39.generateMnemonic(); - const keys = crypto.getKeys(passphrase); - const address = crypto.getAddress(keys.publicKey, this.config.network.version); - - wallets.push({ address, keys, passphrase }); - } - - const testWalletsPath = path.resolve(__dirname, "../../test-wallets"); - fs.appendFileSync(testWalletsPath, `${new Date().toLocaleDateString()} ${"-".repeat(70)}\n`); - for (const wallet of wallets) { - fs.appendFileSync(testWalletsPath, `${wallet.address}: ${wallet.passphrase}\n`); + protected async sendTransaction(transactions: any[]): Promise> { + if (!Array.isArray(transactions)) { + transactions = [transactions]; } - return wallets; - } - - /** - * Get delegate API response. - * @return {Object[]} - * @throws 'Could not get delegates' - */ - public async getDelegates() { - try { - const delegates = await paginate(this.config, "/api/v2/delegates"); - - return delegates; - } catch (error) { - const message = error.response ? error.response.data.message : error.message; - throw new Error(`Could not get delegates: ${message}`); - } - } - - /** - * Get transaction from API by ID. - * @param {String} id - * @return {(Object|null)} - */ - public async getTransaction(id) { - try { - const response = await request(this.config).get(`/api/v2/transactions/${id}`); - - if (response.data) { - return response.data; - } - } catch (error) { - // + for (const transaction of transactions) { + logger.info(`Posting Transaction: ${transaction.id}`); } - return null; + return http.post("transactions", { transactions }); } - /** - * Get delegate voters by public key. - * @param {String} publicKey - * @return {Object[]} - */ - public async getVoters(publicKey) { + protected async knockTransaction(id: string): Promise { try { - return paginate(this.config, `/api/v2/delegates/${publicKey}/voters`); - } catch (error) { - const message = error.response ? error.response.data.message : error.message; - throw new Error(`Could not get voters for '${publicKey}': ${message}`); - } - } + const { data } = await http.get(`transactions/${id}`); - /** - * Get wallet balance by address. - * @param {String} address - * @return {Bignum} - */ - public async getWalletBalance(address) { - try { - return bignumify((await this.getWallet(address)).balance); + logger.info(`${id} was included in block ${data.blockId}`); } catch (error) { - // - } - - return Bignum.ZERO; - } - - /** - * Get wallet by address. - * @param {String} address - * @return {Object} - */ - public async getWallet(address) { - try { - const response = await request(this.config).get(`/api/v2/wallets/${address}`); + logger.error(error.message); - if (response.data) { - return response.data; - } - - return null; - } catch (error) { - const message = error.response ? error.response.data.message : error.message; - throw new Error(`Could not get wallet for '${address}': ${message}`); + logger.info(`${id} was not included in any blocks`); } } - /** - * Send transactions to API and wait for response. - * @param {Object[]} transactions - * @param {String} [transactionType] - * @param {Boolean} [wait=true] - * @return {Object} - */ - public async sendTransactions(transactions, transactionType: any = null, wait = true) { - const response = await this.postTransactions(transactions); - - if (wait) { - const delaySeconds = this.getTransactionDelaySeconds(transactions); - transactionType = `${transactionType ? `${transactionType} ` : ""}transactions`; - logger.info(`Waiting ${delaySeconds} seconds to apply ${transactionType}`); - await delay(delaySeconds * 1000); - } - - return response; - } + protected async make(command): Promise { + const { args, flags } = this.parse(command); - /** - * Send transactions to API. - * @param {Object[]} transactions - * @return {Object} - */ - public async postTransactions(transactions) { - try { - const response = await request(this.config).post("/api/v2/transactions", { - transactions, - }); - return response.data; - } catch (error) { - const message = error.response ? error.response.data.message : error.message; - throw new Error(`Could not post transactions: ${message}`); - } - } + http.setup(flags.host, flags.port); - /** - * Load constants from API and apply to config. - * @return {void} - */ - public async loadConstants() { - try { - this.config.constants = (await request(this.config).get("/api/v2/node/configuration")).data.constants; - } catch (error) { - logger.error("Failed to get constants: ", error.message); - process.exit(1); - } - } + configManager.setFromPreset(flags.network); - /** - * Load network from API and apply to config. - * @return {void} - */ - public async loadNetworkConfig() { - try { - this.config.network = (await request(this.config).get("/config", true)).data.network; - } catch (error) { - logger.error("Failed to get network config: ", error.message); - process.exit(1); - } + return { args, flags }; } - /** - * Apply options to config. - * @return {void} - */ - protected applyConfig() { - this.config = { ...config }; + protected signTransaction(opts: Record): any { + const transfer = client + .getBuilder() + .transfer() + .fee(this.toSatoshi(opts.transferFee)) + .recipientId(opts.recipient) + .amount(this.toSatoshi(opts.amount)); - if (this.options.baseUrl) { - this.config.baseUrl = this.options.baseUrl.replace(/\/+$/, ""); + if (opts.vendorField) { + transfer.vendorField(opts.vendorField); } - if (this.options.apiPort) { - this.config.apiPort = this.options.apiPort; - } + transfer.sign(opts.passphrase); - if (this.options.p2pPort && process.env.NODE_ENV !== "test") { - this.config.p2pPort = this.options.p2pPort; + if (opts.secondPassphrase) { + transfer.secondSign(opts.secondPassphrase); } - if (this.options.passphrase) { - this.config.passphrase = this.options.passphrase; - } - - if (this.options.secondPassphrase) { - this.config.secondPassphrase = this.options.secondPassphrase; - } + return transfer.getStruct(); } - /** - * Quit command and output error when problem sending transactions. - * @param {Error} error - * @return {void} - */ - protected problemSendingTransactions(error) { - const message = error.response ? error.response.data.message : error.message; - logger.error(`There was a problem sending transactions: ${message}`); - process.exit(1); - } - - /** - * Determine how long to wait for transactions to process. - * @param {Object[]} transactions - * @return {Number} - */ - protected getTransactionDelaySeconds(transactions) { - if (process.env.NODE_ENV === "test") { - return 0; - } - - const waitPerBlock = Math.round(this.config.constants.blocktime / 10) * 20; - - return waitPerBlock * Math.ceil(transactions.length / this.config.constants.block.maxTransactions); - } - - protected castFlags(values: Record): string[] { - return Object.keys(BaseCommand.flags) - .filter(k => !["copy"].includes(k)) - .map((key: string) => { - const value = values[key]; - - if (value === undefined) { - return undefined; - } - - if (value === true) { - return `--${key}`; - } - - return `--${key}=${value}`; - }) - .filter(value => value !== undefined); + private toSatoshi(value: number): number { + return +new Bignum(value).times(1e8).toFixed(); } } diff --git a/packages/core-tester-cli/src/commands/delegate-registration.ts b/packages/core-tester-cli/src/commands/delegate-registration.ts deleted file mode 100644 index 7ccf5dc6ee..0000000000 --- a/packages/core-tester-cli/src/commands/delegate-registration.ts +++ /dev/null @@ -1,110 +0,0 @@ -import { client } from "@arkecosystem/crypto"; -import { flags } from "@oclif/command"; -import pluralize from "pluralize"; -import superheroes from "superheroes"; -import { customFlags } from "../flags"; -import { logger, parseFee, satoshiToArk } from "../utils"; -import { BaseCommand } from "./command"; -import { TransferCommand } from "./transfer"; - -export class DelegateRegistrationCommand extends BaseCommand { - public static description: string = "create multiple delegates"; - - public static flags = { - ...BaseCommand.flags, - delegateFee: customFlags.number({ - description: "delegate registration fee", - default: 25, - }), - }; - - /** - * Run delegate-registration command. - * @return {void} - */ - public async run(): Promise { - // tslint:disable-next-line: no-shadowed-variable - const { flags } = await this.initialize(DelegateRegistrationCommand); - - const wallets = this.generateWallets(); - - for (const wallet of wallets) { - await TransferCommand.run( - ["--amount", String(this.options.amount || 25), "--recipient", wallet.address, "--skipTesting"].concat( - this.castFlags(flags), - ), - ); - } - - const delegates = await this.getDelegates(); - - logger.error( - `Sending ${this.options.number} delegate registration ${pluralize("transaction", this.options.number)}`, - ); - - if (!this.options.skipValidation) { - logger.error(`Starting delegate count: ${delegates.length}`); - } - - const transactions = []; - const usedDelegateNames = delegates.map(delegate => delegate.username); - - wallets.forEach((wallet, i) => { - while (!wallet.username || usedDelegateNames.includes(wallet.username)) { - wallet.username = superheroes.random(); - } - - wallet.username = wallet.username.toLowerCase().replace(/ /g, "_"); - usedDelegateNames.push(wallet.username); - - const transaction = client - .getBuilder() - .delegateRegistration() - .fee(parseFee(this.options.delegateFee)) - .usernameAsset(wallet.username) - .network(this.config.network.version) - .sign(wallet.passphrase) - .secondSign(this.config.secondPassphrase) - .build(); - - transactions.push(transaction); - - logger.info( - `${i} ==> ${transaction.id}, ${wallet.address} (fee: ${satoshiToArk(transaction.fee)}, username: ${ - wallet.username - })`, - ); - }); - - if (this.options.copy) { - this.copyToClipboard(transactions); - return; - } - - const expectedDelegates = delegates.length + wallets.length; - if (!this.options.skipValidation) { - logger.info(`Expected end delegate count: ${expectedDelegates}`); - } - - try { - await this.sendTransactions(transactions, "delegate", !this.options.skipValidation); - - if (this.options.skipValidation) { - return; - } - - const targetDelegates = await this.getDelegates(); - logger.info(`All transactions have been sent! Total delegates: ${targetDelegates.length}`); - - if (targetDelegates.length !== expectedDelegates) { - logger.error( - `Delegate count incorrect. '${targetDelegates.length}' but should be '${expectedDelegates}'`, - ); - } - } catch (error) { - logger.error( - `There was a problem sending transactions: ${error.response ? error.response.data.message : error}`, - ); - } - } -} diff --git a/packages/core-tester-cli/src/commands/multi-signature.ts b/packages/core-tester-cli/src/commands/multi-signature.ts deleted file mode 100644 index adb4b97012..0000000000 --- a/packages/core-tester-cli/src/commands/multi-signature.ts +++ /dev/null @@ -1,352 +0,0 @@ -import { client } from "@arkecosystem/crypto"; -import { flags } from "@oclif/command"; -import take from "lodash/take"; -import pluralize from "pluralize"; -import { customFlags } from "../flags"; -import { arkToSatoshi, generateTransactions, logger, parseFee, satoshiToArk } from "../utils"; -import { BaseCommand } from "./command"; -import { TransferCommand } from "./transfer"; - -export class MultiSignatureCommand extends BaseCommand { - public static description: string = "create multiple multisig wallets"; - - public static flags = { - ...BaseCommand.flags, - multisigFee: customFlags.number({ - description: "multisig fee", - default: 5, - }), - min: flags.integer({ - description: "minimum number of signatures per transaction", - default: 2, - }), - lifetime: flags.integer({ - description: "lifetime of transaction", - default: 72, - }), - quantity: flags.integer({ - description: "number of signatures per wallet", - default: 3, - }), - skipTests: flags.boolean({ - description: "skip transaction tests", - }), - }; - - /** - * Run multi-signature command. - * @return {void} - */ - public async run(): Promise { - // tslint:disable-next-line: no-shadowed-variable - const { flags } = await this.initialize(MultiSignatureCommand); - - const approvalWallets = this.generateWallets(this.options.quantity); - const publicKeys = approvalWallets.map(wallet => `+${wallet.keys.publicKey}`); - const min = this.options.min ? Math.min(this.options.min, publicKeys.length) : publicKeys.length; - - const testCosts = this.options.skipTests ? 1 : 2; - const wallets = this.generateWallets(); - - for (const wallet of wallets) { - await TransferCommand.run( - [ - "--recipient", - wallet.address, - "--amount", - (publicKeys.length + 1) * 5 + testCosts, - "--skipTesting", - ].concat(this.castFlags(flags)), - ); - } - - const transactions = this.generateTransactions(wallets, approvalWallets, publicKeys, min); - - if (this.options.copy) { - this.copyToClipboard(transactions); - - return; - } - - try { - const response = await this.sendTransactions(transactions, "multi-signature", !this.options.skipValidation); - - if (!this.options.skipValidation) { - let hasUnprocessed = false; - for (const transaction of transactions) { - if (!response.accept.includes(transaction.id)) { - hasUnprocessed = true; - logger.error(`Multi-signature transaction '${transaction.id}' was not processed`); - } - } - if (hasUnprocessed) { - process.exit(1); - } - - for (const transaction of transactions) { - const tx = await this.getTransaction(transaction.id); - if (!tx) { - logger.error(`Transaction '${transaction.id}' should be on the blockchain`); - } - } - } - } catch (error) { - const message = error.response ? error.response.data.message : error.message; - logger.error(`There was a problem sending multi-signature transactions: ${message}`); - process.exit(1); - } - - if (this.options.skipTests || this.options.skipValidation) { - return; - } - - await this.testSendWithSignatures(wallets, approvalWallets); - await this.testSendWithMinSignatures(wallets, approvalWallets, min); - await this.testSendWithBelowMinSignatures(wallets, approvalWallets, min); - await this.testSendWithoutSignatures(wallets); - await this.testSendWithEmptySignatures(wallets); - await this.testNewMultiSignatureRegistration(wallets, approvalWallets, publicKeys, min); - } - - /** - * Generate batch of transactions based on wallets - * @param {Object[]} wallets - * @param {Object[]} [approvalWallets=[]] - * @param {String[]} [publicKeys=[]] - * @param {Number} [min=2] - * @param {Boolean} [log=true] - * @return {Object[]} - */ - public generateTransactions(wallets, approvalWallets = [], publicKeys = [], min = 2, log = true) { - const transactions = []; - wallets.forEach((wallet, i) => { - const builder = client.getBuilder().multiSignature(); - - builder - .fee(parseFee(this.options.multisigFee)) - .multiSignatureAsset({ - lifetime: this.options.lifetime, - keysgroup: publicKeys, - min, - }) - .network(this.config.network.version) - .sign(wallet.passphrase); - - if (wallet.secondPassphrase || this.config.secondPassphrase) { - builder.secondSign(wallet.secondPassphrase || this.config.secondPassphrase); - } - - if (approvalWallets) { - for (let j = approvalWallets.length - 1; j >= 0; j--) { - builder.multiSignatureSign(approvalWallets[j].passphrase); - } - } - - const transaction = builder.build(); - transactions.push(transaction); - - if (log) { - logger.info(`${i} ==> ${transaction.id}, ${wallet.address} (fee: ${satoshiToArk(transaction.fee)})`); - } - }); - - return transactions; - } - - /** - * Send transactions with approver signatures. - * @param {Object[]} wallets - * @param {Object[]} [approvalWallets=[]] - * @return {void} - */ - public async testSendWithSignatures(wallets, approvalWallets = []) { - logger.info("Sending transactions with signatures"); - - const transactions = generateTransactions(arkToSatoshi(2), wallets, approvalWallets, { - config: this.config, - ...this.options, - }); - - try { - await this.sendTransactions(transactions); - for (const transaction of transactions) { - const tx = await this.getTransaction(transaction.id); - if (!tx) { - logger.error(`Transaction '${transaction.id}' should be on the blockchain`); - } - } - } catch (error) { - this.problemSendingTransactions(error); - } - } - - /** - * Send transactions with min approver signatures. - * @param {Object[]} wallets - * @param {Object[]} [approvalWallets=[]] - * @param {Number} [min=2] - * @return {void} - */ - public async testSendWithMinSignatures(wallets, approvalWallets = [], min = 2) { - logger.info( - `Sending transactions with ${min} (min) of ${pluralize("signature", approvalWallets.length, true)}`, - ); - - const transactions = generateTransactions(arkToSatoshi(2), wallets, take(approvalWallets, min), { - config: this.config, - ...this.options, - }); - - try { - await this.sendTransactions(transactions); - for (const transaction of transactions) { - const tx = await this.getTransaction(transaction.id); - if (!tx) { - logger.error(`Transaction '${transaction.id}' should be on the blockchain`); - } - } - } catch (error) { - this.problemSendingTransactions(error); - } - } - - /** - * Send transactions with below min approver signatures. - * @param {Object[]} wallets - * @param {Object[]} [approvalWallets=[]] - * @param {Number} [min=2] - * @return {void} - */ - public async testSendWithBelowMinSignatures(wallets, approvalWallets = [], min = 2) { - const max = min - 1; - logger.info( - `Sending transactions with ${max} (below min) of ${pluralize("signature", approvalWallets.length, true)}`, - ); - - const transactions = generateTransactions(arkToSatoshi(2), wallets, take(approvalWallets, max), { - config: this.config, - ...this.options, - }); - - try { - await this.sendTransactions(transactions); - for (const transaction of transactions) { - try { - const tx = await this.getTransaction(transaction.id); - if (tx) { - logger.error(`Transaction '${transaction.id}' should not be on the blockchain`); - } - } catch (error) { - const message = error.response ? error.response.data.message : error.message; - if (message !== "Transaction not found") { - logger.error(`Failed to check transaction '${transaction.id}': ${message}`); - } - } - } - } catch (error) { - this.problemSendingTransactions(error); - } - } - - /** - * Send transactions without approver signatures. - * @param {Object[]} wallets - * @return {void} - */ - public async testSendWithoutSignatures(wallets) { - logger.info("Sending transactions without signatures"); - - const transactions = generateTransactions(arkToSatoshi(2), wallets, [], { - config: this.config, - ...this.options, - }); - - try { - await this.sendTransactions(transactions); - for (const transaction of transactions) { - try { - const tx = await this.getTransaction(transaction.id); - if (tx) { - logger.error(`Transaction '${transaction.id}' should not be on the blockchain`); - } - } catch (error) { - const message = error.response ? error.response.data.message : error.message; - if (message !== "Transaction not found") { - logger.error(`Failed to check transaction '${transaction.id}': ${message}`); - } - } - } - } catch (error) { - this.problemSendingTransactions(error); - } - } - - /** - * Send transactions with empty approver signatures. - * @param {Object[]} wallets - * @return {void} - */ - public async testSendWithEmptySignatures(wallets) { - logger.info("Sending transactions with empty signatures"); - - const transactions = generateTransactions(arkToSatoshi(2), wallets, [], { - config: this.config, - ...this.options, - }); - for (const transaction of transactions) { - transaction.data.signatures = []; - } - - try { - await this.sendTransactions(transactions); - for (const transaction of transactions) { - try { - const tx = await this.getTransaction(transaction.id); - if (tx) { - logger.error(`Transaction '${transaction.id}' should not be on the blockchain`); - } - } catch (error) { - const message = error.response ? error.response.data.message : error.message; - if (message !== "Transaction not found") { - logger.error(`Failed to check transaction '${transaction.id}': ${message}`); - } - } - } - } catch (error) { - this.problemSendingTransactions(error); - } - } - - /** - * Send transactions to re-register multi-signature wallets. - * @param {Object[]} wallets - * @param {Object[]} [approvalWallets=[]] - * @param {Object[]} [publicKeys=[]] - * @param {Number} [min=2] - * @return {void} - */ - public async testNewMultiSignatureRegistration(wallets, approvalWallets = [], publicKeys = [], min = 2) { - logger.info("Sending transactions to re-register multi-signature"); - - const transactions = this.generateTransactions(wallets, approvalWallets, publicKeys, min); - - try { - await this.sendTransactions(transactions); - for (const transaction of transactions) { - try { - const tx = await this.getTransaction(transaction.id); - if (tx) { - logger.error(`Transaction '${transaction.id}' should not be on the blockchain`); - } - } catch (error) { - const message = error.response ? error.response.data.message : error.message; - if (message !== "Transaction not found") { - logger.error(`Failed to check transaction '${transaction.id}': ${message}`); - } - } - } - } catch (error) { - this.problemSendingTransactions(error); - } - } -} diff --git a/packages/core-tester-cli/src/commands/second-signature.ts b/packages/core-tester-cli/src/commands/second-signature.ts deleted file mode 100644 index 5cc3325a9d..0000000000 --- a/packages/core-tester-cli/src/commands/second-signature.ts +++ /dev/null @@ -1,87 +0,0 @@ -import { client } from "@arkecosystem/crypto"; -import { flags } from "@oclif/command"; -import pluralize from "pluralize"; -import { customFlags } from "../flags"; -import { logger, parseFee, satoshiToArk } from "../utils"; -import { BaseCommand } from "./command"; -import { TransferCommand } from "./transfer"; - -export class SecondSignatureCommand extends BaseCommand { - public static description: string = "create wallets with second signature"; - - public static flags = { - ...BaseCommand.flags, - signatureFee: customFlags.number({ - description: "second signature fee", - default: 5, - }), - }; - - /** - * Run second-signature command. - * @return {void} - */ - public async run(): Promise { - // tslint:disable-next-line: no-shadowed-variable - const { flags } = await this.initialize(SecondSignatureCommand); - - const wallets = this.generateWallets(); - - for (const wallet of wallets) { - await TransferCommand.run( - ["--recipient", wallet.address, "--amount", String(this.options.amount || 5), "--skipTesting"].concat( - this.castFlags(flags), - ), - ); - } - - logger.info(`Sending ${this.options.number} second signature ${pluralize("transaction", this.options.number)}`); - - const transactions = []; - wallets.forEach((wallet, i) => { - wallet.secondPassphrase = this.config.secondPassphrase || wallet.passphrase; - const transaction = client - .getBuilder() - .secondSignature() - .fee(parseFee(this.options.signatureFee)) - .signatureAsset(wallet.secondPassphrase) - .network(this.config.network.version) - .sign(wallet.passphrase) - .build(); - - wallet.publicKey = transaction.senderPublicKey; - wallet.secondPublicKey = transaction.asset.signature.publicKey; - transactions.push(transaction); - - logger.info(`${i} ==> ${transaction.id}, ${wallet.address} (fee: ${satoshiToArk(transaction.fee)})`); - }); - - if (this.options.copy) { - this.copyToClipboard(transactions); - return; - } - - try { - await this.sendTransactions(transactions, "second-signature", !this.options.skipValidation); - - if (this.options.skipValidation) { - return; - } - - for (const walletObject of wallets) { - const wallet = await this.getWallet(walletObject.address); - - if ( - wallet.secondPublicKey !== walletObject.secondPublicKey || - wallet.publicKey !== walletObject.publicKey - ) { - logger.error(`Invalid second signature for ${walletObject.address}.`); - } - } - } catch (error) { - logger.error( - `There was a problem sending transactions: ${error.response ? error.response.data.message : error}`, - ); - } - } -} diff --git a/packages/core-tester-cli/src/commands/transfer.ts b/packages/core-tester-cli/src/commands/transfer.ts index cd1a07489e..a845464cb8 100644 --- a/packages/core-tester-cli/src/commands/transfer.ts +++ b/packages/core-tester-cli/src/commands/transfer.ts @@ -1,9 +1,5 @@ -import { Bignum, crypto } from "@arkecosystem/crypto"; import { flags } from "@oclif/command"; import delay from "delay"; -import unique from "lodash/uniq"; -import pluralize from "pluralize"; -import { arkToSatoshi, generateTransactions, logger, satoshiToArk } from "../utils"; import { BaseCommand } from "./command"; export class TransferCommand extends BaseCommand { @@ -14,302 +10,20 @@ export class TransferCommand extends BaseCommand { recipient: flags.string({ description: "recipient address", }), - floodAttempts: flags.integer({ - description: "flood node with same transactions", - default: 0, - }), - skipSecondRun: flags.string({ - description: "skip second sending of transactions", - }), - smartBridge: flags.string({ - description: "smart-bridge value to use", + vendorField: flags.string({ + description: "vendor field to use", }), }; - /** - * Run transfer command. - * @param {Object} options - * @return {void} - */ public async run(): Promise { - await this.initialize(TransferCommand); - - const primaryAddress = crypto.getAddress( - crypto.getKeys(this.config.passphrase).publicKey, - this.config.network.version, - ); - - let wallets = this.options.wallets; - if (wallets === undefined) { - wallets = this.generateWallets(); - } - - logger.info(`Sending ${wallets.length} transfer ${pluralize("transaction", wallets.length)}`); - - const walletBalance = await this.getWalletBalance(primaryAddress); - - if (!this.options.skipValidation) { - logger.info(`Sender starting balance: ${satoshiToArk(walletBalance)}`); - } - - let totalDeductions = Bignum.ZERO; - const transactionAmount = arkToSatoshi(this.options.amount || 2); - - const transactions = this.generateTransactions(transactionAmount, wallets, null, true); - for (const transaction of transactions) { - totalDeductions = totalDeductions.plus(transactionAmount).plus(transaction.fee); - } - - if (this.options.copy) { - this.copyToClipboard(transactions); - return; - } - - const expectedSenderBalance = new Bignum(walletBalance).minus(totalDeductions); - if (!this.options.skipValidation) { - logger.info(`Sender expected ending balance: ${satoshiToArk(expectedSenderBalance)}`); - } - - const runOptions = { - primaryAddress, - transactions, - wallets, - transactionAmount, - expectedSenderBalance, - skipValidation: this.options.skipValidation, - }; - - try { - if (!this.options.floodAttempts) { - const successfulTest = await this.performRun(runOptions, 1); - if ( - successfulTest && - !this.options.skipSecondRun && - !this.options.skipValidation && - !this.options.skipTesting - ) { - await this.performRun(runOptions, 2, false, true); - } - } else { - const attempts = this.options.floodAttempts; - for (let i = attempts; i > 0; i--) { - await this.performRun(runOptions, attempts - i + 1, i !== 1, i !== attempts); - } - } - } catch (error) { - const message = error.response ? error.response.data.message : error; - logger.error(`There was a problem sending transactions: ${message}`); - } - - if (this.options.skipValidation) { - return; - } - - await this.testVendorField(wallets); - await this.testEmptyVendorField(wallets); - - return; - } - - /** - * Generate batch of transactions based on wallets. - * @param {Bignum} transactionAmount - * @param {Object[]} wallets - * @param {Object[]} [approvalWallets=[]] - * @param {Boolean} [overridePassphrase=false] - * @param {String} [vendorField] - * @param {Boolean} [log=true] - * @return {Object[]} - */ - public generateTransactions( - transactionAmount, - wallets, - approvalWallets = [], - overridePassphrase = false, - vendorField = null, - log = true, - ) { - return generateTransactions(transactionAmount, wallets, approvalWallets, { - ...this.options, - config: this.config, - overridePassphrase, - vendorField: vendorField || this.options.smartBridge, - log, - }); - } - - /** - * Perform a run of transactions. - * @param {Object} runOptions - * @param {Number} [runNumber=1] - * @param {Boolean} [skipWait=false] - * @param {Boolean} [isSubsequentRun=false] - * @return {Boolean} - */ - public async performRun(runOptions, runNumber = 1, skipWait = false, isSubsequentRun = false) { - if (skipWait) { - runOptions.skipValidation = true; - this.sendTransactionsWithResults(runOptions, isSubsequentRun); - - return true; - } - - if (await this.sendTransactionsWithResults(runOptions, isSubsequentRun)) { - logger.info(`All transactions have been received and forged for run ${runNumber}!`); - - return true; - } - - logger.error(`Test failed on run ${runNumber}`); - - return false; - } - - /** - * Send transactions and validate results. - * @param {Object} runOptions - * @param {Boolean} isSubsequentRun - * @return {Boolean} - */ - public async sendTransactionsWithResults(runOptions, isSubsequentRun) { - let successfulTest = true; - - let postResponse; - try { - postResponse = await this.postTransactions(runOptions.transactions); - } catch (error) { - if (runOptions.skipValidation) { - return true; - } - - const message = error.response ? error.response.data.error : error.message; - logger.error(`Transaction request failed: ${message}`); - - return false; - } - - if (runOptions.skipValidation) { - return true; - } - - if (!isSubsequentRun && (!postResponse.accept || !postResponse.accept.length)) { - return false; - } - - if (!isSubsequentRun) { - for (const transaction of runOptions.transactions) { - if (!postResponse.accept.includes(transaction.id)) { - logger.error(`Transaction '${transaction.id}' didn't get approved on the network`); - - successfulTest = false; - } - } - } - - for (const key of Object.keys(postResponse)) { - if (key === "success") { - continue; - } - - const dataLength = postResponse[key].length; - const uniqueLength = unique(postResponse[key]).length; - if (dataLength !== uniqueLength) { - logger.error(`Response data for '${key}' has ${dataLength - uniqueLength} duplicate transaction ids`); - successfulTest = false; - } - } - - const delaySeconds = this.getTransactionDelaySeconds(runOptions.transactions); - logger.info(`Waiting ${delaySeconds} seconds to apply transfer transactions`); - await delay(delaySeconds * 1000); - - for (const transaction of runOptions.transactions) { - const transactionResponse = await this.getTransaction(transaction.id); - if (transactionResponse && transactionResponse.id !== transaction.id) { - logger.error(`Transaction '${transaction.id}' didn't get applied on the network`); - - successfulTest = false; - } - } - - if (runOptions.primaryAddress && runOptions.expectedSenderBalance) { - const walletBalance = await this.getWalletBalance(runOptions.primaryAddress); - if (!walletBalance.isEqualTo(runOptions.expectedSenderBalance)) { - successfulTest = false; - logger.error( - `Sender balance incorrect: '${satoshiToArk(walletBalance)}' but should be '${satoshiToArk( - runOptions.expectedSenderBalance, - )}'`, - ); - } - } - - for (const wallet of runOptions.wallets) { - const balance = await this.getWalletBalance(wallet.address); - if (!balance.isEqualTo(runOptions.transactionAmount)) { - successfulTest = false; - logger.error( - `Incorrect destination balance for ${wallet.address}. Should be '${satoshiToArk( - runOptions.transactionAmount, - )}' but is '${satoshiToArk(balance)}'`, - ); - } - } - - return successfulTest; - } - - /** - * Test vendor field is set correctly on blockchain. - * @param {Object[]} wallets - * @return {void} - */ - public async testVendorField(wallets) { - logger.info("Testing VendorField value is set correctly"); - - const transactions = this.generateTransactions(arkToSatoshi(2), wallets, null, null, "Testing VendorField"); - - try { - await this.sendTransactions(transactions); - - for (const transaction of transactions) { - const tx = await this.getTransaction(transaction.id); - if (!tx) { - logger.error(`Transaction '${transaction.id}' should be on the blockchain`); - } else if (tx.vendorField !== "Testing VendorField") { - logger.error(`Transaction '${transaction.id}' does not have correct vendorField value`); - } - } - } catch (error) { - this.problemSendingTransactions(error); - } - } + const { flags } = await this.make(TransferCommand); - /** - * Test empty vendor field is set correctly on blockchain. - * @param {Object[]} wallets - * @return {void} - */ - public async testEmptyVendorField(wallets) { - logger.info("Testing empty VendorField value"); + const transaction = this.signTransaction(flags); - const transactions = this.generateTransactions(arkToSatoshi(2), wallets, null, null, null); + await this.sendTransaction(transaction); - try { - await this.sendTransactions(transactions); + await delay(8000); - for (const transaction of transactions) { - const tx = await this.getTransaction(transaction.id); - if (!tx) { - logger.error(`Transaction '${transaction.id}' should be on the blockchain`); - } else if (tx.vendorField) { - logger.error( - `Transaction '${transaction.id}' should not have vendorField value '${tx.vendorField}'`, - ); - } - } - } catch (error) { - this.problemSendingTransactions(error); - } + await this.knockTransaction(transaction.id); } } diff --git a/packages/core-tester-cli/src/commands/vote.ts b/packages/core-tester-cli/src/commands/vote.ts deleted file mode 100644 index d8a4941f81..0000000000 --- a/packages/core-tester-cli/src/commands/vote.ts +++ /dev/null @@ -1,100 +0,0 @@ -import { client } from "@arkecosystem/crypto"; -import { flags } from "@oclif/command"; -import sample from "lodash/sample"; -import pluralize from "pluralize"; -import { customFlags } from "../flags"; -import { logger, parseFee, satoshiToArk } from "../utils"; -import { BaseCommand } from "./command"; -import { TransferCommand } from "./transfer"; - -export class VoteCommand extends BaseCommand { - public static description: string = "create multiple votes for a delegate"; - - public static flags = { - ...BaseCommand.flags, - delegate: flags.string({ - description: "delegate public key", - }), - voteFee: customFlags.number({ - description: "vote fee", - default: 1, - }), - }; - - /** - * Run vote command. - * @return {void} - */ - public async run(): Promise { - // tslint:disable-next-line: no-shadowed-variable - const { flags } = await this.initialize(VoteCommand); - - const wallets = this.generateWallets(); - - for (const wallet of wallets) { - await TransferCommand.run( - ["--recipient", wallet.address, "--amount", String(2), "--skipTesting"].concat(this.castFlags(flags)), - ); - } - - let delegate = this.options.delegate; - if (!delegate) { - try { - delegate = sample(await this.getDelegates()).publicKey; - } catch (error) { - logger.error(error); - return; - } - } - - const voters = await this.getVoters(delegate); - logger.info(`Sending ${this.options.number} vote ${pluralize("transaction", this.options.number)}`); - - const transactions = []; - wallets.forEach((wallet, i) => { - const transaction = client - .getBuilder() - .vote() - .fee(parseFee(this.options.voteFee)) - .votesAsset([`+${delegate}`]) - .network(this.config.network.version) - .sign(wallet.passphrase) - .secondSign(this.config.secondPassphrase) - .build(); - - transactions.push(transaction); - - logger.info(`${i} ==> ${transaction.id}, ${wallet.address} (fee: ${satoshiToArk(transaction.fee)})`); - }); - - if (this.options.copy) { - this.copyToClipboard(transactions); - return; - } - - const expectedVoterCount = voters.length + wallets.length; - if (!this.options.skipValidation) { - logger.info(`Expected end voters: ${expectedVoterCount}`); - } - - try { - await this.sendTransactions(transactions, "vote", !this.options.skipValidation); - - if (this.options.skipValidation) { - return; - } - - const voterCount = (await this.getVoters(delegate)).length; - - logger.info(`All transactions have been sent! Total voters: ${voterCount}`); - - if (voterCount !== expectedVoterCount) { - logger.error(`Delegate voter count incorrect. '${voterCount}' but should be '${expectedVoterCount}'`); - } - } catch (error) { - logger.error( - `There was a problem sending transactions: ${error.response ? error.response.data.message : error}`, - ); - } - } -} diff --git a/packages/core-tester-cli/src/config.ts b/packages/core-tester-cli/src/config.ts deleted file mode 100644 index 49fdac960a..0000000000 --- a/packages/core-tester-cli/src/config.ts +++ /dev/null @@ -1,7 +0,0 @@ -export const config = Object.freeze({ - apiPort: 4003, - p2pPort: 4000, - baseUrl: "http://localhost", - passphrase: "clay harbor enemy utility margin pretty hub comic piece aerobic umbrella acquire", - secondPassphrase: "", -}); diff --git a/packages/core-tester-cli/src/flags.ts b/packages/core-tester-cli/src/flags.ts index a75effe727..d9820bc27a 100644 --- a/packages/core-tester-cli/src/flags.ts +++ b/packages/core-tester-cli/src/flags.ts @@ -1,14 +1,13 @@ -import { flags as oclifFlags } from "@oclif/command"; +import { flags } from "@oclif/command"; -export const customFlags = { - number: oclifFlags.build({ - parse: input => { - const value = Number(input); - if (value < 1 / 1e8) { - throw new Error(`Expected number greater than 1 satoshi.`); - } +export const satoshiFlag = flags.build({ + parse: input => { + const value = Number(input); - return value; - }, - }), -}; + if (value < 1 / 1e8) { + throw new Error(`Expected number greater than 1 satoshi.`); + } + + return value; + }, +}); diff --git a/packages/core-tester-cli/src/http-client.ts b/packages/core-tester-cli/src/http-client.ts new file mode 100644 index 0000000000..f42a9442e7 --- /dev/null +++ b/packages/core-tester-cli/src/http-client.ts @@ -0,0 +1,34 @@ +import Axios from "axios"; +import { logger } from "./logger"; + +class HttpClient { + private instance: any; + + public setup(host: string, port: number) { + this.instance = Axios.create({ + baseURL: `${host}:${port}/api/v2/`, + }); + } + + public async get(path: string, params?: Record): Promise { + try { + const { data } = await this.instance.get(path, { params }); + + return data; + } catch (error) { + logger.error(error.message); + } + } + + public async post(path: string, payload: Record): Promise { + try { + const { data } = await this.instance.post(path, payload); + + return data; + } catch (error) { + logger.error(error.message); + } + } +} + +export const http = new HttpClient(); diff --git a/packages/core-tester-cli/src/logger.ts b/packages/core-tester-cli/src/logger.ts new file mode 100644 index 0000000000..1a857882bd --- /dev/null +++ b/packages/core-tester-cli/src/logger.ts @@ -0,0 +1,7 @@ +import pino from "pino"; + +export const logger = pino({ + name: "core-tester-cli", + safe: true, + prettyPrint: true, +}); diff --git a/packages/core-tester-cli/src/utils.ts b/packages/core-tester-cli/src/utils.ts deleted file mode 100644 index 6af7ea0894..0000000000 --- a/packages/core-tester-cli/src/utils.ts +++ /dev/null @@ -1,142 +0,0 @@ -import { bignumify } from "@arkecosystem/core-utils"; -import { Bignum, client, formatSatoshi } from "@arkecosystem/crypto"; -import axios from "axios"; -import pino from "pino"; - -export const logger = pino({ - name: "core-tester-cli", - safe: true, - prettyPrint: true, -}); - -export function request(config) { - const headers: any = {}; - if (config && config.network) { - headers.nethash = config.network.nethash; - headers.version = "2.1.0"; - headers.port = config.p2pPort; - headers["Content-Type"] = "application/json"; - } - - return { - get: async (endpoint, isP2P = false) => { - const baseUrl = `${config.baseUrl}:${isP2P ? config.p2pPort : config.apiPort}`; - - return (await axios.get(baseUrl + endpoint, { headers })).data; - }, - post: async (endpoint, data, isP2P = false) => { - const baseUrl = `${config.baseUrl}:${isP2P ? config.p2pPort : config.apiPort}`; - - return (await axios.post(baseUrl + endpoint, data, { headers })).data; - }, - }; -} - -export async function paginate(config, endpoint) { - const data = []; - let page = 1; - let maxPages = null; - while (maxPages === null || page <= maxPages) { - const response = await request(config).get(`${endpoint}?page=${page}`); - if (response) { - page++; - maxPages = response.meta.pageCount; - data.push(...response.data); - } else { - break; - } - } - - return data; -} - -/** - * Generate batch of transactions based on wallets. - */ -export function generateTransactions( - amountPerTransaction: any, - wallets: any[], - approvalWallets: any[], - options: { - config: any; - overridePassphrase?: false; - vendorField?: string; - log?: boolean; - [key: string]: any; - }, -) { - const transactions = []; - wallets.forEach((wallet, i) => { - const builder = client.getBuilder().transfer(); - // noinspection JSCheckFunctionSignatures - builder - .fee(this.parseFee(options.transferFee)) - .recipientId(options.recipient || wallet.address) - .network(options.config.network.version) - .amount(amountPerTransaction) - .vendorField(options.vendorField === undefined ? `Transaction ${i + 1}` : options.vendorField) - .sign(options.overridePassphrase ? options.config.passphrase : wallet.passphrase); - - if (wallet.secondPassphrase || options.config.secondPassphrase) { - builder.secondSign(wallet.secondPassphrase || options.config.secondPassphrase); - } - - if (approvalWallets) { - for (let j = approvalWallets.length - 1; j >= 0; j--) { - builder.multiSignatureSign(approvalWallets[j].passphrase); - } - } - - const transaction = builder.build(); - transactions.push(transaction); - - if (options.log) { - logger.info( - `${i} ==> ${transaction.id}, ${transaction.recipientId} (fee: ${this.satoshiToArk(transaction.fee)})`, - ); - } - }); - - return transactions; -} - -/** - * Parse fee based on input. - * @param {(String|Number)} fee - * @return {Bignum} - */ -export function parseFee(fee): Bignum { - if (typeof fee === "string" && fee.indexOf("-") !== -1) { - const feeRange = fee.split("-").map( - f => - +bignumify(f) - .times(1e8) - .toFixed(), - ); - if (feeRange[1] < feeRange[0]) { - return bignumify(feeRange[0]); - } - - return bignumify(Math.floor(Math.random() * (feeRange[1] - feeRange[0] + 1) + feeRange[0])); - } - - return bignumify(fee).times(1e8); -} - -/** - * Convert ARK to Satoshi. - * @param {Number} ark - * @return {Bignum} - */ -export function arkToSatoshi(ark) { - return bignumify(ark * 1e8); -} - -/** - * Convert Satoshi to ARK. - * @param {Bignum} satoshi - * @return {String} - */ -export function satoshiToArk(satoshi) { - return formatSatoshi(satoshi); -} diff --git a/yarn.lock b/yarn.lock index 6417b3b7b0..90329c1ae1 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2204,13 +2204,6 @@ dependencies: "@types/lodash" "*" -"@types/lodash.fill@^3.4.4": - version "3.4.4" - resolved "https://registry.yarnpkg.com/@types/lodash.fill/-/lodash.fill-3.4.4.tgz#c54608d7da691142bf281134149b6ecf0d1f701b" - integrity sha512-D2c164uS5YG3OYmalDFW3yXlhq3DmFE8y1EdQ9MqQ9VPFBD9+73GMzZxRAdG4/G8O3ZNeERkRGXMJCgsWi7c6A== - dependencies: - "@types/lodash" "*" - "@types/lodash.flatten@^4.4.4": version "4.4.4" resolved "https://registry.yarnpkg.com/@types/lodash.flatten/-/lodash.flatten-4.4.4.tgz#7f28009ef57c8d2b1d8463c3e53fdccf780120a5" @@ -9265,11 +9258,6 @@ lodash.compact@^3.0.1: resolved "https://registry.yarnpkg.com/lodash.compact/-/lodash.compact-3.0.1.tgz#540ce3837745975807471e16b4a2ba21e7256ca5" integrity sha1-VAzjg3dFl1gHRx4WtKK6IeclbKU= -lodash.fill@^3.4.0: - version "3.4.0" - resolved "https://registry.yarnpkg.com/lodash.fill/-/lodash.fill-3.4.0.tgz#a3c74ae640d053adf0dc2079f8720788e8bfef85" - integrity sha1-o8dK5kDQU63w3CB5+HIHiOi/74U= - lodash.findindex@^4.4.0, lodash.findindex@^4.6.0: version "4.6.0" resolved "https://registry.yarnpkg.com/lodash.findindex/-/lodash.findindex-4.6.0.tgz#a3245dee61fb9b6e0624b535125624bb69c11106" From ff192ac704ffda27a068f08770ae1e54ea17f55e Mon Sep 17 00:00:00 2001 From: Brian Faust Date: Thu, 21 Feb 2019 15:28:16 +0200 Subject: [PATCH 02/18] refactor: merge core-debugger-cli into core-tester-cli --- packages/core-debugger-cli/.gitattributes | 11 -- packages/core-debugger-cli/.gitignore | 1 - packages/core-debugger-cli/README.md | 23 --- .../__tests__/__fixtures__/block.json | 140 ------------------ .../__tests__/__fixtures__/identities.json | 6 - .../__fixtures__/transaction-second.json | 15 -- .../__tests__/__fixtures__/transaction.json | 14 -- .../__tests__/commands/deserialize.test.ts | 60 -------- .../__tests__/commands/identity.test.ts | 43 ------ .../__tests__/commands/serialize.test.ts | 26 ---- .../__tests__/commands/verify-second.test.ts | 18 --- .../__tests__/commands/verify.test.ts | 16 -- .../core-debugger-cli/__tests__/utils.test.ts | 36 ----- packages/core-debugger-cli/bin/run | 5 - packages/core-debugger-cli/bin/run.cmd | 3 - packages/core-debugger-cli/package.json | 67 --------- .../core-debugger-cli/src/commands/command.ts | 12 -- packages/core-debugger-cli/src/index.ts | 1 - packages/core-debugger-cli/tsconfig.json | 7 - packages/core-tester-cli/package.json | 2 + .../core-tester-cli/src/commands/command.ts | 11 +- .../src/commands/debug}/deserialize.ts | 9 +- .../src/commands/debug}/identity.ts | 9 +- .../src/commands/debug}/serialize.ts | 9 +- .../debug/verify-second-signature.ts} | 9 +- .../src/commands/debug}/verify.ts | 6 +- .../src/commands/{ => sent}/transfer.ts | 4 +- .../src/utils.ts | 0 28 files changed, 33 insertions(+), 530 deletions(-) delete mode 100644 packages/core-debugger-cli/.gitattributes delete mode 100644 packages/core-debugger-cli/.gitignore delete mode 100644 packages/core-debugger-cli/README.md delete mode 100644 packages/core-debugger-cli/__tests__/__fixtures__/block.json delete mode 100644 packages/core-debugger-cli/__tests__/__fixtures__/identities.json delete mode 100644 packages/core-debugger-cli/__tests__/__fixtures__/transaction-second.json delete mode 100644 packages/core-debugger-cli/__tests__/__fixtures__/transaction.json delete mode 100644 packages/core-debugger-cli/__tests__/commands/deserialize.test.ts delete mode 100644 packages/core-debugger-cli/__tests__/commands/identity.test.ts delete mode 100644 packages/core-debugger-cli/__tests__/commands/serialize.test.ts delete mode 100644 packages/core-debugger-cli/__tests__/commands/verify-second.test.ts delete mode 100644 packages/core-debugger-cli/__tests__/commands/verify.test.ts delete mode 100644 packages/core-debugger-cli/__tests__/utils.test.ts delete mode 100755 packages/core-debugger-cli/bin/run delete mode 100644 packages/core-debugger-cli/bin/run.cmd delete mode 100644 packages/core-debugger-cli/package.json delete mode 100644 packages/core-debugger-cli/src/commands/command.ts delete mode 100644 packages/core-debugger-cli/src/index.ts delete mode 100644 packages/core-debugger-cli/tsconfig.json rename packages/{core-debugger-cli/src/commands => core-tester-cli/src/commands/debug}/deserialize.ts (77%) rename packages/{core-debugger-cli/src/commands => core-tester-cli/src/commands/debug}/identity.ts (88%) rename packages/{core-debugger-cli/src/commands => core-tester-cli/src/commands/debug}/serialize.ts (81%) rename packages/{core-debugger-cli/src/commands/verify-second.ts => core-tester-cli/src/commands/debug/verify-second-signature.ts} (76%) rename packages/{core-debugger-cli/src/commands => core-tester-cli/src/commands/debug}/verify.ts (89%) rename packages/core-tester-cli/src/commands/{ => sent}/transfer.ts (90%) rename packages/{core-debugger-cli => core-tester-cli}/src/utils.ts (100%) diff --git a/packages/core-debugger-cli/.gitattributes b/packages/core-debugger-cli/.gitattributes deleted file mode 100644 index 60cc52db63..0000000000 --- a/packages/core-debugger-cli/.gitattributes +++ /dev/null @@ -1,11 +0,0 @@ -# Path-based git attributes -# https://www.kernel.org/pub/software/scm/git/docs/gitattributes.html - -# Ignore all test and documentation with "export-ignore". -/.editorconfig export-ignore -/.gitattributes export-ignore -/.gitignore export-ignore -/.travis.yml export-ignore -/__tests__ export-ignore -/docs export-ignore -/README.md export-ignore diff --git a/packages/core-debugger-cli/.gitignore b/packages/core-debugger-cli/.gitignore deleted file mode 100644 index 5dc9198e84..0000000000 --- a/packages/core-debugger-cli/.gitignore +++ /dev/null @@ -1 +0,0 @@ -test-wallets \ No newline at end of file diff --git a/packages/core-debugger-cli/README.md b/packages/core-debugger-cli/README.md deleted file mode 100644 index bc6530e60b..0000000000 --- a/packages/core-debugger-cli/README.md +++ /dev/null @@ -1,23 +0,0 @@ -# Ark Core - Debugger CLI - -

- -

- -## Documentation - -You can find installation instructions and detailed instructions on how to use this package at the [dedicated documentation site](https://docs.ark.io/guidebook/core/plugins/core-debugger-cli.html). - -## Security - -If you discover a security vulnerability within this package, please send an e-mail to security@ark.io. All security vulnerabilities will be promptly addressed. - -## Credits - -- [Brian Faust](https://github.com/faustbrian) -- [Joshua Noack](https://github.com/supaiku0) -- [All Contributors](../../../../contributors) - -## License - -[MIT](LICENSE) © [ArkEcosystem](https://ark.io) diff --git a/packages/core-debugger-cli/__tests__/__fixtures__/block.json b/packages/core-debugger-cli/__tests__/__fixtures__/block.json deleted file mode 100644 index d1228aa285..0000000000 --- a/packages/core-debugger-cli/__tests__/__fixtures__/block.json +++ /dev/null @@ -1,140 +0,0 @@ -{ - "data": { - "id": "7176646138626297930", - "version": 0, - "height": 2243161, - "timestamp": 24760440, - "previousBlock": "3112633353705641986", - "numberOfTransactions": 7, - "totalAmount": "3890300", - "totalFee": "70000000", - "reward": "200000000", - "payloadLength": 224, - "payloadHash": "3784b953afcf936bdffd43fdf005b5732b49c1fc6b11e195c364c20b2eb06282", - "generatorPublicKey": "020f5df4d2bc736d12ce43af5b1663885a893fade7ee5e62b3cc59315a63e6a325", - "blockSignature": "3045022100eee6c37b5e592e99811d588532726353592923f347c701d52912e6d583443e400220277ffe38ad31e216ba0907c4738fed19b2071246b150c72c0a52bae4477ebe29", - "transactions": [ - { - "type": 0, - "amount": 555760, - "fee": 10000000, - "recipientId": "DB4gFuDztmdGALMb8i1U4Z4R5SktxpNTAY", - "timestamp": 24760418, - "asset": {}, - "vendorField": "Goose Voter - True Block Weight", - "senderPublicKey": "0265c1f6b8c1966a90f3fed7bc32fd4f42238ab4938fdb2a4e7ddd01ae8b58b4c0", - "signature": "304402204f12469157b19edd06ba25fcad3d4a5ef5b057c23f9e02de4641e6f8eef0553e022010121ab282f83efe1043de9c16bbf2c6845a03684229a0d7c965ffb9abdfb978", - "signSignature": "30450221008327862f0b9178d6665f7d6674978c5caf749649558d814244b1c66cdf945c40022015918134ef01fed3fe2a2efde3327917731344332724522c75c2799a14f78717", - "id": "170543154a3b79459cbaa529f9f62b6f1342682799eb549dbf09fcca2d1f9c11", - "senderId": "DB8LnnQqYvHpG4WkGJ9AJWBYEct7G3yRZg", - "hop": 2, - "broadcast": false, - "blockId": "7176646138626297930" - }, - { - "type": 0, - "amount": 555750, - "fee": 10000000, - "recipientId": "DGExsNogZR7JFa2656ZFP9TMWJYJh5djzQ", - "timestamp": 24760416, - "asset": {}, - "vendorField": "Goose Voter - True Block Weight", - "senderPublicKey": "0265c1f6b8c1966a90f3fed7bc32fd4f42238ab4938fdb2a4e7ddd01ae8b58b4c0", - "signature": "304402205f82feb8c5d1d79c565c2ff7badb93e4c9827b132d135dda11cb25427d4ef8ac02205ff136f970533c4ec4c7d0cd1ea7e02d7b62629b66c6c93265f608d7f2389727", - "signSignature": "304402207e912031fcc700d8a55fbc415993302a0d8e6aea128397141b640b6dba52331702201fd1ad3984e42af44f548907add6cb7ad72ca0070c8cc1d8dc9bbda208c56bd9", - "id": "1da153f37eceda233ff1b407ac18e47b3cae47c14cdcd5297d929618a916c4a7", - "senderId": "DB8LnnQqYvHpG4WkGJ9AJWBYEct7G3yRZg", - "hop": 2, - "broadcast": false, - "blockId": "7176646138626297930" - }, - { - "type": 0, - "amount": 555770, - "fee": 10000000, - "recipientId": "DHGK5np6LuMMErfRfC5CmjpGu3ME85c25n", - "timestamp": 24760420, - "asset": {}, - "vendorField": "Goose Voter - True Block Weight", - "senderPublicKey": "0265c1f6b8c1966a90f3fed7bc32fd4f42238ab4938fdb2a4e7ddd01ae8b58b4c0", - "signature": "304502210083216e6969e068770e6d2fe5c244881002309df84d20290ddf3f858967ed010202202a479b3da5080ea475d310ff13494654b42db75886a8808bd211b4bdb9146a7a", - "signSignature": "3045022100e1dcab3406bbeb968146a4a391909ce41df9b71592a753b001e7c2ee1d382c5102202a74aeafd4a152ec61854636fbae829c41f1416c1e0637a0809408394973099f", - "id": "1e255f07dc25ce22d900ea81663c8f00d05a7b7c061e6fc3c731b05d642fa0b9", - "senderId": "DB8LnnQqYvHpG4WkGJ9AJWBYEct7G3yRZg", - "hop": 2, - "broadcast": false, - "blockId": "7176646138626297930" - }, - { - "type": 0, - "amount": 555750, - "fee": 10000000, - "recipientId": "D7pcLJNGe197ibmWEmT8mM9KKU1htrcDyW", - "timestamp": 24760417, - "asset": {}, - "vendorField": "Goose Voter - True Block Weight", - "senderPublicKey": "0265c1f6b8c1966a90f3fed7bc32fd4f42238ab4938fdb2a4e7ddd01ae8b58b4c0", - "signature": "3045022100cd4fa9855227be11e17201419dacfbbd5d9946df8d6792a9488160025693821402207fb83969bad6a26959f437b5bb88e255b0a48eb04964d0c0d29f7ee94bd15e11", - "signSignature": "304402205f50c2991a17743d17ffbb09159cadc35a3f848044261842879ccf5be9d81c5e022023bf21c32fb6e94494104f15f8d3a942ab120d0abd6fb4c93790b68e1b307a79", - "id": "66336c61d6ec623f8a1d2fd156a0fac16a4fe93bb3fba337859355c2119923a8", - "senderId": "DB8LnnQqYvHpG4WkGJ9AJWBYEct7G3yRZg", - "hop": 2, - "broadcast": false, - "blockId": "7176646138626297930" - }, - { - "type": 0, - "amount": 555760, - "fee": 10000000, - "recipientId": "DD4yhwzryQdNGqKtezmycToQv63g27Tqqq", - "timestamp": 24760418, - "asset": {}, - "vendorField": "Goose Voter - True Block Weight", - "senderPublicKey": "0265c1f6b8c1966a90f3fed7bc32fd4f42238ab4938fdb2a4e7ddd01ae8b58b4c0", - "signature": "30450221009c792062e13399ac6756b2e9f137194d06e106360ac0f3e24e55c7249cee0b3602205dc1d9c76d0451d1cb5a2396783a13e6d2d790ccfd49291e3d0a78349f7ea0e8", - "signSignature": "30440220083ba8a9af49b8be6e93794d71ec43ffc96a158375810e5d9f2478e71655315b0220278402ecaa1d224dab9f0f3b28295bbaea339c85c7400edafdc49df87439fc64", - "id": "78db36f7d79f51c67d7210ee3819dfb8d0d47b16a7484ebf55c5a055b17209a3", - "senderId": "DB8LnnQqYvHpG4WkGJ9AJWBYEct7G3yRZg", - "hop": 2, - "broadcast": false, - "blockId": "7176646138626297930" - }, - { - "type": 0, - "amount": 555760, - "fee": 10000000, - "recipientId": "D5LiYGXL5keycWuTF6AFFwSRc6Mt4uEHMu", - "timestamp": 24760419, - "asset": {}, - "vendorField": "Goose Voter - True Block Weight", - "senderPublicKey": "0265c1f6b8c1966a90f3fed7bc32fd4f42238ab4938fdb2a4e7ddd01ae8b58b4c0", - "signature": "3044022063c65263e42be02bd9831b375c1d76a88332f00ed0557ecc1e7d2375ca40070902206797b5932c0bad68444beb5a38daa7cadf536ee2144e0d9777b812284d14374e", - "signSignature": "3045022100b04da6692f75d43229ffd8486c1517e8952d38b4c03dfac38b6b360190a5c33e0220776622e5f09f92a1258b4a011f22181c977b622b8d1bbb2f83b42f4126d00739", - "id": "83c80bb58777bb43f5037544b44ef69f191d3548fd1b2a00bed368f9f0d694c5", - "senderId": "DB8LnnQqYvHpG4WkGJ9AJWBYEct7G3yRZg", - "hop": 2, - "broadcast": false, - "blockId": "7176646138626297930" - }, - { - "type": 0, - "amount": 555750, - "fee": 10000000, - "recipientId": "DPopNLwMvv4zSjdZnqUk8HFH13Mcb7NbEK", - "timestamp": 24760416, - "asset": {}, - "vendorField": "Goose Voter - True Block Weight", - "senderPublicKey": "0265c1f6b8c1966a90f3fed7bc32fd4f42238ab4938fdb2a4e7ddd01ae8b58b4c0", - "signature": "3045022100d4513c3608c2072e38e7a0e3bb8daf2cd5f7cc6fec9a5570dccd1eda696c591902202ecbbf3c9d0757be7b23c8b1cc6481c51600d158756c47fcb6f4a7f4893e31c4", - "signSignature": "304402201fed4858d0806dd32220960900a871dd2f60e1f623af75feef9b1034a9a0a46402205a29b27c63fcc3e1ee1e77ecbbf4dd6e7db09901e7a09b9fd490cd68d62392cb", - "id": "d2faf992fdd5da96d6d15038b6ddb65230338fa2096e45e44da51daad5e2f3ca", - "senderId": "DB8LnnQqYvHpG4WkGJ9AJWBYEct7G3yRZg", - "hop": 2, - "broadcast": false, - "blockId": "7176646138626297930" - } - ] - }, - "serialized": "0000000078d07901593a22002b324b8b33a85802070000007c5c3b0000000000801d2c040000000000c2eb0b00000000e00000003784b953afcf936bdffd43fdf005b5732b49c1fc6b11e195c364c20b2eb06282020f5df4d2bc736d12ce43af5b1663885a893fade7ee5e62b3cc59315a63e6a3253045022100eee6c37b5e592e99811d588532726353592923f347c701d52912e6d583443e400220277ffe38ad31e216ba0907c4738fed19b2071246b150c72c0a52bae4477ebe29", - "serializedFull": "0000000078d07901593a22002b324b8b33a85802070000007c5c3b0000000000801d2c040000000000c2eb0b00000000e00000003784b953afcf936bdffd43fdf005b5732b49c1fc6b11e195c364c20b2eb06282020f5df4d2bc736d12ce43af5b1663885a893fade7ee5e62b3cc59315a63e6a3253045022100eee6c37b5e592e99811d588532726353592923f347c701d52912e6d583443e400220277ffe38ad31e216ba0907c4738fed19b2071246b150c72c0a52bae4477ebe29ff000000fe00000000010000ff000000ff000000ff000000ff000000ff011e0062d079010265c1f6b8c1966a90f3fed7bc32fd4f42238ab4938fdb2a4e7ddd01ae8b58b4c080969800000000001f476f6f736520566f746572202d205472756520426c6f636b20576569676874f07a080000000000000000001e40fad23d21da7a4fd4decb5c49726ea22f5e6bf6304402204f12469157b19edd06ba25fcad3d4a5ef5b057c23f9e02de4641e6f8eef0553e022010121ab282f83efe1043de9c16bbf2c6845a03684229a0d7c965ffb9abdfb97830450221008327862f0b9178d6665f7d6674978c5caf749649558d814244b1c66cdf945c40022015918134ef01fed3fe2a2efde3327917731344332724522c75c2799a14f78717ff011e0060d079010265c1f6b8c1966a90f3fed7bc32fd4f42238ab4938fdb2a4e7ddd01ae8b58b4c080969800000000001f476f6f736520566f746572202d205472756520426c6f636b20576569676874e67a080000000000000000001e79c579fb08f448879c22fe965906b4e3b88d02ed304402205f82feb8c5d1d79c565c2ff7badb93e4c9827b132d135dda11cb25427d4ef8ac02205ff136f970533c4ec4c7d0cd1ea7e02d7b62629b66c6c93265f608d7f2389727304402207e912031fcc700d8a55fbc415993302a0d8e6aea128397141b640b6dba52331702201fd1ad3984e42af44f548907add6cb7ad72ca0070c8cc1d8dc9bbda208c56bd9ff011e0064d079010265c1f6b8c1966a90f3fed7bc32fd4f42238ab4938fdb2a4e7ddd01ae8b58b4c080969800000000001f476f6f736520566f746572202d205472756520426c6f636b20576569676874fa7a080000000000000000001e84fee45dde2b11525afe192a2e991d014ff93a36304502210083216e6969e068770e6d2fe5c244881002309df84d20290ddf3f858967ed010202202a479b3da5080ea475d310ff13494654b42db75886a8808bd211b4bdb9146a7a3045022100e1dcab3406bbeb968146a4a391909ce41df9b71592a753b001e7c2ee1d382c5102202a74aeafd4a152ec61854636fbae829c41f1416c1e0637a0809408394973099fff011e0061d079010265c1f6b8c1966a90f3fed7bc32fd4f42238ab4938fdb2a4e7ddd01ae8b58b4c080969800000000001f476f6f736520566f746572202d205472756520426c6f636b20576569676874e67a080000000000000000001e1d69583ede5ee82d220e74bffb36bae2ce762dfb3045022100cd4fa9855227be11e17201419dacfbbd5d9946df8d6792a9488160025693821402207fb83969bad6a26959f437b5bb88e255b0a48eb04964d0c0d29f7ee94bd15e11304402205f50c2991a17743d17ffbb09159cadc35a3f848044261842879ccf5be9d81c5e022023bf21c32fb6e94494104f15f8d3a942ab120d0abd6fb4c93790b68e1b307a79ff011e0062d079010265c1f6b8c1966a90f3fed7bc32fd4f42238ab4938fdb2a4e7ddd01ae8b58b4c080969800000000001f476f6f736520566f746572202d205472756520426c6f636b20576569676874f07a080000000000000000001e56f9a37a859f4f84e93ce7593e809b15a524db2930450221009c792062e13399ac6756b2e9f137194d06e106360ac0f3e24e55c7249cee0b3602205dc1d9c76d0451d1cb5a2396783a13e6d2d790ccfd49291e3d0a78349f7ea0e830440220083ba8a9af49b8be6e93794d71ec43ffc96a158375810e5d9f2478e71655315b0220278402ecaa1d224dab9f0f3b28295bbaea339c85c7400edafdc49df87439fc64ff011e0063d079010265c1f6b8c1966a90f3fed7bc32fd4f42238ab4938fdb2a4e7ddd01ae8b58b4c080969800000000001f476f6f736520566f746572202d205472756520426c6f636b20576569676874f07a080000000000000000001e0232a083c16aba4362dddec1b3050ffdd6d43f2e3044022063c65263e42be02bd9831b375c1d76a88332f00ed0557ecc1e7d2375ca40070902206797b5932c0bad68444beb5a38daa7cadf536ee2144e0d9777b812284d14374e3045022100b04da6692f75d43229ffd8486c1517e8952d38b4c03dfac38b6b360190a5c33e0220776622e5f09f92a1258b4a011f22181c977b622b8d1bbb2f83b42f4126d00739ff011e0060d079010265c1f6b8c1966a90f3fed7bc32fd4f42238ab4938fdb2a4e7ddd01ae8b58b4c080969800000000001f476f6f736520566f746572202d205472756520426c6f636b20576569676874e67a080000000000000000001eccc4fce0dc95f9951ee40c09a7ae807746cf51403045022100d4513c3608c2072e38e7a0e3bb8daf2cd5f7cc6fec9a5570dccd1eda696c591902202ecbbf3c9d0757be7b23c8b1cc6481c51600d158756c47fcb6f4a7f4893e31c4304402201fed4858d0806dd32220960900a871dd2f60e1f623af75feef9b1034a9a0a46402205a29b27c63fcc3e1ee1e77ecbbf4dd6e7db09901e7a09b9fd490cd68d62392cb" -} diff --git a/packages/core-debugger-cli/__tests__/__fixtures__/identities.json b/packages/core-debugger-cli/__tests__/__fixtures__/identities.json deleted file mode 100644 index 71063bafbc..0000000000 --- a/packages/core-debugger-cli/__tests__/__fixtures__/identities.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "passphrase": "this is a top secret passphrase", - "publicKey": "034151a3ec46b5670a682b0a63394f863587d1bc97483b1b6c70eb58e7f0aed192", - "privateKey": "d8839c2432bfd0a67ef10a804ba991eabba19f154a3d707917681d45822a5712", - "address": "D61mfSggzbvQgTUe6JhYKH2doHaqJ3Dyib" -} diff --git a/packages/core-debugger-cli/__tests__/__fixtures__/transaction-second.json b/packages/core-debugger-cli/__tests__/__fixtures__/transaction-second.json deleted file mode 100644 index 8a0ebe0907..0000000000 --- a/packages/core-debugger-cli/__tests__/__fixtures__/transaction-second.json +++ /dev/null @@ -1,15 +0,0 @@ -{ - "data": { - "type": 0, - "amount": 200000000, - "fee": 10000000, - "recipientId": "D61mfSggzbvQgTUe6JhYKH2doHaqJ3Dyib", - "timestamp": 41268430, - "asset": {}, - "senderPublicKey": "034151a3ec46b5670a682b0a63394f863587d1bc97483b1b6c70eb58e7f0aed192", - "signature": "304402206da703bfcc11ec2ccb3f363fa0e23fc64050fdf68e1f1852b7d4a5bb07824166022031ed1d86b586a79f9c1e5010dbc4f4cb36641c62a196536f90b1dfd6be1c9868", - "signSignature": "304402200759b6f9de5257aa3fcf54b9cd7a426a00af9368b7ea3d5ea2b13a91b97fb277022076e4d2d7deb9bdd8245b2533cab1eeeef72981e18576ef8455a61ee3e6f3fb57", - "id": "bb8054b6298d659d4b5d655e82de17b3504ba27655ec3d6e35d311f3104b1c43" - }, - "serialized": "ff011e00ceb47502034151a3ec46b5670a682b0a63394f863587d1bc97483b1b6c70eb58e7f0aed19280969800000000000000c2eb0b00000000000000001e0995750207ecaf0ccf251c1265b92ad84f553662304402206da703bfcc11ec2ccb3f363fa0e23fc64050fdf68e1f1852b7d4a5bb07824166022031ed1d86b586a79f9c1e5010dbc4f4cb36641c62a196536f90b1dfd6be1c9868304402200759b6f9de5257aa3fcf54b9cd7a426a00af9368b7ea3d5ea2b13a91b97fb277022076e4d2d7deb9bdd8245b2533cab1eeeef72981e18576ef8455a61ee3e6f3fb57" -} diff --git a/packages/core-debugger-cli/__tests__/__fixtures__/transaction.json b/packages/core-debugger-cli/__tests__/__fixtures__/transaction.json deleted file mode 100644 index 70490d28c9..0000000000 --- a/packages/core-debugger-cli/__tests__/__fixtures__/transaction.json +++ /dev/null @@ -1,14 +0,0 @@ -{ - "data": { - "type": 0, - "amount": 200000000, - "fee": 10000000, - "recipientId": "D61mfSggzbvQgTUe6JhYKH2doHaqJ3Dyib", - "timestamp": 41268326, - "asset": {}, - "senderPublicKey": "034151a3ec46b5670a682b0a63394f863587d1bc97483b1b6c70eb58e7f0aed192", - "signature": "3044022002994b30e08b58825c8c16ebf2cc693cfe706fb26571674784ead098accc89d702205b79dedc752a84504ecfe4b9e1292997f22260ee4daa102d2d9a61432d93b286", - "id": "da61c6cba363cc39baa0ca3f9ba2c5db81b9805045bd0b9fc58af07ad4206856" - }, - "serialized": "ff011e0066b47502034151a3ec46b5670a682b0a63394f863587d1bc97483b1b6c70eb58e7f0aed19280969800000000000000c2eb0b00000000000000001e0995750207ecaf0ccf251c1265b92ad84f5536623044022002994b30e08b58825c8c16ebf2cc693cfe706fb26571674784ead098accc89d702205b79dedc752a84504ecfe4b9e1292997f22260ee4daa102d2d9a61432d93b286" -} diff --git a/packages/core-debugger-cli/__tests__/commands/deserialize.test.ts b/packages/core-debugger-cli/__tests__/commands/deserialize.test.ts deleted file mode 100644 index a7b7fa572e..0000000000 --- a/packages/core-debugger-cli/__tests__/commands/deserialize.test.ts +++ /dev/null @@ -1,60 +0,0 @@ -import "jest-extended"; - -import { DeserializeCommand } from "../../src/commands/deserialize"; - -describe("Commands - Deserialize", () => { - const fixtureBlock = require("../__fixtures__/block.json"); - const fixtureTransaction = require("../__fixtures__/transaction.json"); - - it("should deserialize a block (not-full)", async () => { - const actual = JSON.parse(await DeserializeCommand.run(["--data", fixtureBlock.serialized, "--type", "block"])); - - expect(actual.data.version).toBe(fixtureBlock.data.version); - expect(actual.data.timestamp).toBe(fixtureBlock.data.timestamp); - expect(actual.data.height).toBe(fixtureBlock.data.height); - expect(actual.data.previousBlock).toBe(fixtureBlock.data.previousBlock); - expect(actual.data.numberOfTransactions).toBe(fixtureBlock.data.numberOfTransactions); - expect(actual.data.totalAmount).toBe(fixtureBlock.data.totalAmount); - expect(actual.data.totalFee).toBe(fixtureBlock.data.totalFee); - expect(actual.data.reward).toBe(fixtureBlock.data.reward); - expect(actual.data.payloadLength).toBe(fixtureBlock.data.payloadLength); - expect(actual.data.payloadHash).toBe(fixtureBlock.data.payloadHash); - expect(actual.data.generatorPublicKey).toBe(fixtureBlock.data.generatorPublicKey); - expect(actual.data.blockSignature).toBe(fixtureBlock.data.blockSignature); - }); - - it("should deserialize a block (full)", async () => { - const actual = JSON.parse( - await DeserializeCommand.run(["--data", fixtureBlock.serializedFull, "--type", "block"]), - ); - - expect(actual.data.version).toBe(fixtureBlock.data.version); - expect(actual.data.timestamp).toBe(fixtureBlock.data.timestamp); - expect(actual.data.height).toBe(fixtureBlock.data.height); - expect(actual.data.previousBlock).toBe(fixtureBlock.data.previousBlock); - expect(actual.data.numberOfTransactions).toBe(fixtureBlock.data.numberOfTransactions); - expect(actual.data.totalAmount).toBe(fixtureBlock.data.totalAmount); - expect(actual.data.totalFee).toBe(fixtureBlock.data.totalFee); - expect(actual.data.reward).toBe(fixtureBlock.data.reward); - expect(actual.data.payloadLength).toBe(fixtureBlock.data.payloadLength); - expect(actual.data.payloadHash).toBe(fixtureBlock.data.payloadHash); - expect(actual.data.generatorPublicKey).toBe(fixtureBlock.data.generatorPublicKey); - expect(actual.data.blockSignature).toBe(fixtureBlock.data.blockSignature); - expect(actual.transactions).toHaveLength(7); - }); - - it("should deserialize a transaction", async () => { - const actual = JSON.parse( - await DeserializeCommand.run(["--data", fixtureTransaction.serialized, "--type", "transaction"]), - ); - - expect(actual.type).toBe(fixtureTransaction.data.type); - expect(+actual.amount).toBe(fixtureTransaction.data.amount); - expect(+actual.fee).toBe(fixtureTransaction.data.fee); - expect(actual.recipientId).toBe(fixtureTransaction.data.recipientId); - expect(actual.timestamp).toBe(fixtureTransaction.data.timestamp); - expect(actual.senderPublicKey).toBe(fixtureTransaction.data.senderPublicKey); - expect(actual.signature).toBe(fixtureTransaction.data.signature); - expect(actual.id).toBe(fixtureTransaction.data.id); - }); -}); diff --git a/packages/core-debugger-cli/__tests__/commands/identity.test.ts b/packages/core-debugger-cli/__tests__/commands/identity.test.ts deleted file mode 100644 index 2fff72ab91..0000000000 --- a/packages/core-debugger-cli/__tests__/commands/identity.test.ts +++ /dev/null @@ -1,43 +0,0 @@ -import "jest-extended"; - -import { IdentityCommand } from "../../src/commands/identity"; - -describe("Commands - Identity", async () => { - const fixtureIdentities = require("../__fixtures__/identities.json"); - - it("should return identities from passphrase", async () => { - const expected = { - passphrase: "this is a top secret passphrase", - publicKey: "034151a3ec46b5670a682b0a63394f863587d1bc97483b1b6c70eb58e7f0aed192", - privateKey: "d8839c2432bfd0a67ef10a804ba991eabba19f154a3d707917681d45822a5712", - address: "D61mfSggzbvQgTUe6JhYKH2doHaqJ3Dyib", - }; - - expect(await IdentityCommand.run(["--data", fixtureIdentities.passphrase, "--type", "passphrase"])).toEqual( - expected, - ); - }); - - it("should return identities from privateKey", async () => { - const expected = { - publicKey: "034151a3ec46b5670a682b0a63394f863587d1bc97483b1b6c70eb58e7f0aed192", - privateKey: "d8839c2432bfd0a67ef10a804ba991eabba19f154a3d707917681d45822a5712", - address: "D61mfSggzbvQgTUe6JhYKH2doHaqJ3Dyib", - }; - - expect(await IdentityCommand.run(["--data", fixtureIdentities.privateKey, "--type", "privateKey"])).toEqual( - expected, - ); - }); - - it("should return identities from publicKey", async () => { - const expected = { - publicKey: "034151a3ec46b5670a682b0a63394f863587d1bc97483b1b6c70eb58e7f0aed192", - address: "D61mfSggzbvQgTUe6JhYKH2doHaqJ3Dyib", - }; - - expect(await IdentityCommand.run(["--data", fixtureIdentities.publicKey, "--type", "publicKey"])).toEqual( - expected, - ); - }); -}); diff --git a/packages/core-debugger-cli/__tests__/commands/serialize.test.ts b/packages/core-debugger-cli/__tests__/commands/serialize.test.ts deleted file mode 100644 index a2ddb006bb..0000000000 --- a/packages/core-debugger-cli/__tests__/commands/serialize.test.ts +++ /dev/null @@ -1,26 +0,0 @@ -import "jest-extended"; - -import { SerializeCommand } from "../../src/commands/serialize"; - -describe("Commands - Serialize", () => { - const fixtureBlock = require("../__fixtures__/block.json"); - const fixtureTransaction = require("../__fixtures__/transaction.json"); - - it("should serialize a block (not-full)", async () => { - expect(await SerializeCommand.run(["--data", JSON.stringify(fixtureBlock.data), "--type", "block"])).toEqual( - fixtureBlock.serialized, - ); - }); - - it("should serialize a block (full)", async () => { - expect( - await SerializeCommand.run(["--data", JSON.stringify(fixtureBlock.data), "--type", "block", "--full"]), - ).toEqual(fixtureBlock.serializedFull); - }); - - it("should serialize a transaction", async () => { - expect( - await SerializeCommand.run(["--data", JSON.stringify(fixtureTransaction.data), "--type", "transaction"]), - ).toEqual(fixtureTransaction.serialized); - }); -}); diff --git a/packages/core-debugger-cli/__tests__/commands/verify-second.test.ts b/packages/core-debugger-cli/__tests__/commands/verify-second.test.ts deleted file mode 100644 index 5cb6fb2b1a..0000000000 --- a/packages/core-debugger-cli/__tests__/commands/verify-second.test.ts +++ /dev/null @@ -1,18 +0,0 @@ -import "jest-extended"; - -import { VerifySecondSignatureCommand } from "../../src/commands/verify-second"; - -describe("Commands - Verify Second", () => { - const fixtureTransaction = require("../__fixtures__/transaction-second.json"); - - it("should verify a second signature", async () => { - expect( - await VerifySecondSignatureCommand.run([ - "--data", - fixtureTransaction.serialized, - "--publicKey", - "03699e966b2525f9088a6941d8d94f7869964a000efe65783d78ac82e1199fe609", - ]), - ).toBeTrue(); - }); -}); diff --git a/packages/core-debugger-cli/__tests__/commands/verify.test.ts b/packages/core-debugger-cli/__tests__/commands/verify.test.ts deleted file mode 100644 index 8827d94bc0..0000000000 --- a/packages/core-debugger-cli/__tests__/commands/verify.test.ts +++ /dev/null @@ -1,16 +0,0 @@ -import "jest-extended"; - -import { VerifyCommand } from "../../src/commands/verify"; - -describe("Commands - Verify", () => { - const fixtureBlock = require("../__fixtures__/block.json"); - const fixtureTransaction = require("../__fixtures__/transaction.json"); - - it("should verify a block", async () => { - expect(await VerifyCommand.run(["--data", fixtureBlock.serializedFull, "--type", "block"])).toBeTrue(); - }); - - it("should verify a transaction", async () => { - expect(await VerifyCommand.run(["--data", fixtureTransaction.serialized, "--type", "transaction"])).toBeTrue(); - }); -}); diff --git a/packages/core-debugger-cli/__tests__/utils.test.ts b/packages/core-debugger-cli/__tests__/utils.test.ts deleted file mode 100644 index b07503a359..0000000000 --- a/packages/core-debugger-cli/__tests__/utils.test.ts +++ /dev/null @@ -1,36 +0,0 @@ -import { readSync } from "clipboardy"; -import "jest-extended"; - -import { copyToClipboard, handleOutput } from "../src/utils"; - -const dummyData = { hello: "world" }; - -describe("Utils", () => { - describe("copyToClipboard", () => { - it("should contain the copied data", () => { - copyToClipboard(dummyData); - - expect(JSON.parse(readSync())).toEqual(dummyData); - }); - }); - - describe("handleOutput", () => { - it("should copy the data", () => { - handleOutput({ copy: true }, dummyData); - - expect(JSON.parse(readSync())).toEqual(dummyData); - }); - - it("should log the data", () => { - const method = jest.spyOn(global.console, "log"); - - handleOutput({ log: true }, dummyData); - - expect(method).toHaveBeenCalledWith(dummyData); - }); - - it("should return the data", () => { - expect(handleOutput({}, dummyData)).toEqual(dummyData); - }); - }); -}); diff --git a/packages/core-debugger-cli/bin/run b/packages/core-debugger-cli/bin/run deleted file mode 100755 index 30b14e1773..0000000000 --- a/packages/core-debugger-cli/bin/run +++ /dev/null @@ -1,5 +0,0 @@ -#!/usr/bin/env node - -require('@oclif/command').run() -.then(require('@oclif/command/flush')) -.catch(require('@oclif/errors/handle')) diff --git a/packages/core-debugger-cli/bin/run.cmd b/packages/core-debugger-cli/bin/run.cmd deleted file mode 100644 index 968fc30758..0000000000 --- a/packages/core-debugger-cli/bin/run.cmd +++ /dev/null @@ -1,3 +0,0 @@ -@echo off - -node "%~dp0\run" %* diff --git a/packages/core-debugger-cli/package.json b/packages/core-debugger-cli/package.json deleted file mode 100644 index 940e4e6231..0000000000 --- a/packages/core-debugger-cli/package.json +++ /dev/null @@ -1,67 +0,0 @@ -{ - "name": "@arkecosystem/core-debugger-cli", - "description": "Debugger CLI for Ark Core", - "version": "2.2.0-beta.4", - "contributors": [ - "Brian Faust " - ], - "license": "MIT", - "main": "dist/index.js", - "files": [ - "/bin", - "/dist", - "/oclif.manifest.json" - ], - "bin": { - "debugger": "./bin/run" - }, - "scripts": { - "debugger": "./bin/run", - "publish:alpha": "npm publish --tag alpha", - "publish:beta": "npm publish --tag beta", - "publish:rc": "npm publish --tag rc", - "publish:stable": "npm publish --tag latest", - "prepublishOnly": "yarn build", - "pretest": "yarn lint && yarn build", - "prepack": "oclif-dev manifest && npm shrinkwrap", - "postpack": "rm -f oclif.manifest.json", - "compile": "../../node_modules/typescript/bin/tsc", - "build": "yarn clean && yarn compile", - "build:watch": "yarn clean && yarn compile -w", - "clean": "del dist", - "docs": "../../node_modules/typedoc/bin/typedoc src --out docs", - "lint": "../../node_modules/tslint/bin/tslint -c ../../tslint.json 'src/**/*.ts' '__tests__/**/*.ts' --fix", - "test": "cross-env CORE_ENV=test jest --runInBand --forceExit", - "test:coverage": "cross-env CORE_ENV=test jest --coverage --coveragePathIgnorePatterns='/(defaults.ts|index.ts)$' --runInBand --forceExit", - "test:debug": "cross-env CORE_ENV=test node --inspect-brk ../../node_modules/.bin/jest --runInBand", - "test:watch": "cross-env CORE_ENV=test jest --runInBand --watch", - "test:watch:all": "cross-env CORE_ENV=test jest --runInBand --watchAll", - "updates": "../../node_modules/npm-check-updates/bin/npm-check-updates -a" - }, - "dependencies": { - "@arkecosystem/crypto": "^2.2.0-beta.4", - "@oclif/command": "^1.5.10", - "@oclif/config": "^1.12.6", - "@oclif/plugin-help": "^2.1.6", - "@oclif/plugin-not-found": "^1.2.2", - "@types/clipboardy": "^1.1.0", - "clipboardy": "^1.2.3" - }, - "publishConfig": { - "access": "public" - }, - "engines": { - "node": ">=10.x" - }, - "jest": { - "preset": "../../jest-preset.json" - }, - "oclif": { - "commands": "./dist/commands", - "bin": "debugger", - "plugins": [ - "@oclif/plugin-help", - "@oclif/plugin-not-found" - ] - } -} diff --git a/packages/core-debugger-cli/src/commands/command.ts b/packages/core-debugger-cli/src/commands/command.ts deleted file mode 100644 index 4ab327459a..0000000000 --- a/packages/core-debugger-cli/src/commands/command.ts +++ /dev/null @@ -1,12 +0,0 @@ -import Command, { flags } from "@oclif/command"; - -export abstract class BaseCommand extends Command { - public static flags = { - log: flags.string({ - description: "log the data to the console", - }), - copy: flags.string({ - description: "copy the data to the clipboard", - }), - }; -} diff --git a/packages/core-debugger-cli/src/index.ts b/packages/core-debugger-cli/src/index.ts deleted file mode 100644 index 8bdb76f9a0..0000000000 --- a/packages/core-debugger-cli/src/index.ts +++ /dev/null @@ -1 +0,0 @@ -export { run } from "@oclif/command"; diff --git a/packages/core-debugger-cli/tsconfig.json b/packages/core-debugger-cli/tsconfig.json deleted file mode 100644 index 0b089c5fa8..0000000000 --- a/packages/core-debugger-cli/tsconfig.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "extends": "../../tsconfig.json", - "compilerOptions": { - "outDir": "dist" - }, - "include": ["src/**/**.ts"] -} diff --git a/packages/core-tester-cli/package.json b/packages/core-tester-cli/package.json index 347e7cd3fe..c1339a2c58 100644 --- a/packages/core-tester-cli/package.json +++ b/packages/core-tester-cli/package.json @@ -51,12 +51,14 @@ "@types/pluralize": "^0.0.29", "axios": "^0.18.0", "bip39": "^2.5.0", + "clipboardy": "^1.2.3", "delay": "^4.1.0", "pino": "^5.11.1", "pino-pretty": "^2.5.0", "pluralize": "^7.0.0" }, "devDependencies": { + "@types/clipboardy": "^1.1.0", "axios-mock-adapter": "^1.16.0" }, "publishConfig": { diff --git a/packages/core-tester-cli/src/commands/command.ts b/packages/core-tester-cli/src/commands/command.ts index 21374821a2..d14f79578b 100644 --- a/packages/core-tester-cli/src/commands/command.ts +++ b/packages/core-tester-cli/src/commands/command.ts @@ -6,7 +6,7 @@ import { http } from "../http-client"; import { logger } from "../logger"; export abstract class BaseCommand extends Command { - public static flags = { + public static flagsSent = { network: flags.string({ description: "crypto network", default: "testnet", @@ -40,6 +40,15 @@ export abstract class BaseCommand extends Command { }), }; + public static flagsDebug = { + log: flags.string({ + description: "log the data to the console", + }), + copy: flags.string({ + description: "copy the data to the clipboard", + }), + }; + protected async sendTransaction(transactions: any[]): Promise> { if (!Array.isArray(transactions)) { transactions = [transactions]; diff --git a/packages/core-debugger-cli/src/commands/deserialize.ts b/packages/core-tester-cli/src/commands/debug/deserialize.ts similarity index 77% rename from packages/core-debugger-cli/src/commands/deserialize.ts rename to packages/core-tester-cli/src/commands/debug/deserialize.ts index 553fe65abb..7ac20ffbd2 100644 --- a/packages/core-debugger-cli/src/commands/deserialize.ts +++ b/packages/core-tester-cli/src/commands/debug/deserialize.ts @@ -1,13 +1,13 @@ import { models } from "@arkecosystem/crypto"; import { flags } from "@oclif/command"; -import { handleOutput } from "../utils"; -import { BaseCommand } from "./command"; +import { handleOutput } from "../../utils"; +import { BaseCommand } from "../command"; export class DeserializeCommand extends BaseCommand { public static description: string = "Deserialize the given HEX"; public static flags = { - ...BaseCommand.flags, + ...BaseCommand.flagsDebug, data: flags.string({ description: "the HEX blob to deserialize", required: true, @@ -20,8 +20,7 @@ export class DeserializeCommand extends BaseCommand { }; public async run(): Promise { - // tslint:disable-next-line:no-shadowed-variable - const { flags } = this.parse(DeserializeCommand); + const { flags } = await this.make(DeserializeCommand); const deserialized = flags.type === "transaction" ? new models.Transaction(flags.data) : new models.Block(flags.data); diff --git a/packages/core-debugger-cli/src/commands/identity.ts b/packages/core-tester-cli/src/commands/debug/identity.ts similarity index 88% rename from packages/core-debugger-cli/src/commands/identity.ts rename to packages/core-tester-cli/src/commands/debug/identity.ts index 0ed91c6ba3..71332dc390 100644 --- a/packages/core-debugger-cli/src/commands/identity.ts +++ b/packages/core-tester-cli/src/commands/debug/identity.ts @@ -1,13 +1,13 @@ import { crypto } from "@arkecosystem/crypto"; import { flags } from "@oclif/command"; -import { handleOutput } from "../utils"; -import { BaseCommand } from "./command"; +import { handleOutput } from "../../utils"; +import { BaseCommand } from "../command"; export class IdentityCommand extends BaseCommand { public static description: string = "Get identities from the given input"; public static flags = { - ...BaseCommand.flags, + ...BaseCommand.flagsDebug, data: flags.string({ description: "the data to get the identities from", required: true, @@ -24,8 +24,7 @@ export class IdentityCommand extends BaseCommand { }; public async run(): Promise { - // tslint:disable-next-line:no-shadowed-variable - const { flags } = this.parse(IdentityCommand); + const { flags } = await this.make(IdentityCommand); let output; diff --git a/packages/core-debugger-cli/src/commands/serialize.ts b/packages/core-tester-cli/src/commands/debug/serialize.ts similarity index 81% rename from packages/core-debugger-cli/src/commands/serialize.ts rename to packages/core-tester-cli/src/commands/debug/serialize.ts index 61c06590b6..d6055d424b 100644 --- a/packages/core-debugger-cli/src/commands/serialize.ts +++ b/packages/core-tester-cli/src/commands/debug/serialize.ts @@ -1,13 +1,13 @@ import { models } from "@arkecosystem/crypto"; import { flags } from "@oclif/command"; -import { handleOutput } from "../utils"; -import { BaseCommand } from "./command"; +import { handleOutput } from "../../utils"; +import { BaseCommand } from "../command"; export class SerializeCommand extends BaseCommand { public static description: string = "Serialize the given JSON"; public static flags = { - ...BaseCommand.flags, + ...BaseCommand.flagsDebug, data: flags.string({ description: "the HEX blob to serialize", required: true, @@ -23,8 +23,7 @@ export class SerializeCommand extends BaseCommand { }; public async run(): Promise { - // tslint:disable-next-line:no-shadowed-variable - const { flags } = this.parse(SerializeCommand); + const { flags } = await this.make(SerializeCommand); const serialized: any = flags.type === "transaction" diff --git a/packages/core-debugger-cli/src/commands/verify-second.ts b/packages/core-tester-cli/src/commands/debug/verify-second-signature.ts similarity index 76% rename from packages/core-debugger-cli/src/commands/verify-second.ts rename to packages/core-tester-cli/src/commands/debug/verify-second-signature.ts index aeed1cadb1..b9c15e6c63 100644 --- a/packages/core-debugger-cli/src/commands/verify-second.ts +++ b/packages/core-tester-cli/src/commands/debug/verify-second-signature.ts @@ -1,13 +1,13 @@ import { crypto, models } from "@arkecosystem/crypto"; import { flags } from "@oclif/command"; -import { handleOutput } from "../utils"; -import { BaseCommand } from "./command"; +import { handleOutput } from "../../utils"; +import { BaseCommand } from "../command"; export class VerifySecondSignatureCommand extends BaseCommand { public static description: string = "Verify a second signature of a transaction"; public static flags = { - ...BaseCommand.flags, + ...BaseCommand.flagsDebug, data: flags.string({ description: "the HEX blob to deserialize and verify", required: true, @@ -19,8 +19,7 @@ export class VerifySecondSignatureCommand extends BaseCommand { }; public async run(): Promise { - // tslint:disable-next-line:no-shadowed-variable - const { flags } = this.parse(VerifySecondSignatureCommand); + const { flags } = await this.make(VerifySecondSignatureCommand); const transaction = new models.Transaction(flags.data); diff --git a/packages/core-debugger-cli/src/commands/verify.ts b/packages/core-tester-cli/src/commands/debug/verify.ts similarity index 89% rename from packages/core-debugger-cli/src/commands/verify.ts rename to packages/core-tester-cli/src/commands/debug/verify.ts index 37deb12c65..9d598365da 100644 --- a/packages/core-debugger-cli/src/commands/verify.ts +++ b/packages/core-tester-cli/src/commands/debug/verify.ts @@ -1,13 +1,13 @@ import { models } from "@arkecosystem/crypto"; import { flags } from "@oclif/command"; -import { handleOutput } from "../utils"; -import { BaseCommand } from "./command"; +import { handleOutput } from "../../utils"; +import { BaseCommand } from "../command"; export class VerifyCommand extends BaseCommand { public static description: string = "Verify the given HEX"; public static flags = { - ...BaseCommand.flags, + ...BaseCommand.flagsDebug, data: flags.string({ description: "the HEX blob to deserialize and verify", required: true, diff --git a/packages/core-tester-cli/src/commands/transfer.ts b/packages/core-tester-cli/src/commands/sent/transfer.ts similarity index 90% rename from packages/core-tester-cli/src/commands/transfer.ts rename to packages/core-tester-cli/src/commands/sent/transfer.ts index a845464cb8..3d4c261f12 100644 --- a/packages/core-tester-cli/src/commands/transfer.ts +++ b/packages/core-tester-cli/src/commands/sent/transfer.ts @@ -1,12 +1,12 @@ import { flags } from "@oclif/command"; import delay from "delay"; -import { BaseCommand } from "./command"; +import { BaseCommand } from "../command"; export class TransferCommand extends BaseCommand { public static description: string = "send multiple transactions"; public static flags = { - ...BaseCommand.flags, + ...BaseCommand.flagsSent, recipient: flags.string({ description: "recipient address", }), diff --git a/packages/core-debugger-cli/src/utils.ts b/packages/core-tester-cli/src/utils.ts similarity index 100% rename from packages/core-debugger-cli/src/utils.ts rename to packages/core-tester-cli/src/utils.ts From 4ec810d11649431dd0cbb44d8248385e0c80dcce Mon Sep 17 00:00:00 2001 From: Brian Faust Date: Thu, 21 Feb 2019 15:34:11 +0200 Subject: [PATCH 03/18] chore(core-tester-cli): change bin name --- packages/core-tester-cli/package.json | 10 +++++++++- .../src/commands/{sent => send}/transfer.ts | 0 2 files changed, 9 insertions(+), 1 deletion(-) rename packages/core-tester-cli/src/commands/{sent => send}/transfer.ts (100%) diff --git a/packages/core-tester-cli/package.json b/packages/core-tester-cli/package.json index c1339a2c58..a597e2cdb4 100644 --- a/packages/core-tester-cli/package.json +++ b/packages/core-tester-cli/package.json @@ -72,7 +72,15 @@ }, "oclif": { "commands": "./dist/commands", - "bin": "snapshot", + "bin": "ark-tester", + "topics": { + "debug": { + "description": "debug blocks and transactions" + }, + "send": { + "description": "send transactions of various types" + } + }, "plugins": [ "@oclif/plugin-help", "@oclif/plugin-not-found" diff --git a/packages/core-tester-cli/src/commands/sent/transfer.ts b/packages/core-tester-cli/src/commands/send/transfer.ts similarity index 100% rename from packages/core-tester-cli/src/commands/sent/transfer.ts rename to packages/core-tester-cli/src/commands/send/transfer.ts From fb49ac2fb0c67e7e905c99355722ee5139128f3c Mon Sep 17 00:00:00 2001 From: Brian Faust Date: Thu, 21 Feb 2019 15:58:56 +0200 Subject: [PATCH 04/18] feat(core-tester-cli): load network config and constants --- .../core-tester-cli/src/commands/command.ts | 57 ++++++++++++------- .../src/commands/send/transfer.ts | 1 + packages/core-tester-cli/src/http-client.ts | 14 ++--- 3 files changed, 44 insertions(+), 28 deletions(-) diff --git a/packages/core-tester-cli/src/commands/command.ts b/packages/core-tester-cli/src/commands/command.ts index d14f79578b..48a8142420 100644 --- a/packages/core-tester-cli/src/commands/command.ts +++ b/packages/core-tester-cli/src/commands/command.ts @@ -1,24 +1,24 @@ -import { Bignum, configManager } from "@arkecosystem/crypto"; +import { Bignum } from "@arkecosystem/crypto"; import { client } from "@arkecosystem/crypto"; import Command, { flags } from "@oclif/command"; import { satoshiFlag } from "../flags"; -import { http } from "../http-client"; +import { HttpClient } from "../http-client"; import { logger } from "../logger"; export abstract class BaseCommand extends Command { public static flagsSent = { - network: flags.string({ - description: "crypto network", - default: "testnet", - }), host: flags.string({ description: "API host", default: "http://localhost", }), - port: flags.integer({ + portAPI: flags.integer({ description: "API port", default: 4003, }), + portP2P: flags.integer({ + description: "P2P port", + default: 4000, + }), passphrase: flags.string({ description: "passphrase of initial wallet", default: "clay harbor enemy utility margin pretty hub comic piece aerobic umbrella acquire", @@ -49,6 +49,23 @@ export abstract class BaseCommand extends Command { }), }; + protected api: HttpClient; + protected p2p: HttpClient; + protected network: Record; + protected constants: Record; + + protected async make(command): Promise { + const { args, flags } = this.parse(command); + + this.api = new HttpClient(`${flags.host}:${flags.portAPI}/api/v2/`); + this.p2p = new HttpClient(`${flags.host}:${flags.portP2P}/`); + + await this.setupConstants(); + await this.setupNetwork(); + + return { args, flags }; + } + protected async sendTransaction(transactions: any[]): Promise> { if (!Array.isArray(transactions)) { transactions = [transactions]; @@ -58,12 +75,12 @@ export abstract class BaseCommand extends Command { logger.info(`Posting Transaction: ${transaction.id}`); } - return http.post("transactions", { transactions }); + return this.api.post("transactions", { transactions }); } protected async knockTransaction(id: string): Promise { try { - const { data } = await http.get(`transactions/${id}`); + const { data } = await this.api.get(`transactions/${id}`); logger.info(`${id} was included in block ${data.blockId}`); } catch (error) { @@ -73,16 +90,6 @@ export abstract class BaseCommand extends Command { } } - protected async make(command): Promise { - const { args, flags } = this.parse(command); - - http.setup(flags.host, flags.port); - - configManager.setFromPreset(flags.network); - - return { args, flags }; - } - protected signTransaction(opts: Record): any { const transfer = client .getBuilder() @@ -104,6 +111,18 @@ export abstract class BaseCommand extends Command { return transfer.getStruct(); } + private async setupConstants() { + const { data } = await this.api.get("node/configuration"); + + this.constants = data.constants; + } + + private async setupNetwork() { + const { data } = await this.p2p.get("config"); + + this.network = data.network; + } + private toSatoshi(value: number): number { return +new Bignum(value).times(1e8).toFixed(); } diff --git a/packages/core-tester-cli/src/commands/send/transfer.ts b/packages/core-tester-cli/src/commands/send/transfer.ts index 3d4c261f12..84a358e067 100644 --- a/packages/core-tester-cli/src/commands/send/transfer.ts +++ b/packages/core-tester-cli/src/commands/send/transfer.ts @@ -1,3 +1,4 @@ +import { crypto } from "@arkecosystem/crypto"; import { flags } from "@oclif/command"; import delay from "delay"; import { BaseCommand } from "../command"; diff --git a/packages/core-tester-cli/src/http-client.ts b/packages/core-tester-cli/src/http-client.ts index f42a9442e7..69dc493e20 100644 --- a/packages/core-tester-cli/src/http-client.ts +++ b/packages/core-tester-cli/src/http-client.ts @@ -1,18 +1,16 @@ import Axios from "axios"; import { logger } from "./logger"; -class HttpClient { +export class HttpClient { private instance: any; - public setup(host: string, port: number) { - this.instance = Axios.create({ - baseURL: `${host}:${port}/api/v2/`, - }); + public constructor(baseURL: string) { + this.instance = Axios.create({ baseURL }); } - public async get(path: string, params?: Record): Promise { + public async get(path: string, params?: Record, headers?: Record): Promise { try { - const { data } = await this.instance.get(path, { params }); + const { data } = await this.instance.get(path, { params, headers }); return data; } catch (error) { @@ -30,5 +28,3 @@ class HttpClient { } } } - -export const http = new HttpClient(); From efa389204568ce373ba5ac3af79ed7d4fb453034 Mon Sep 17 00:00:00 2001 From: Brian Faust Date: Fri, 22 Feb 2019 08:02:53 +0200 Subject: [PATCH 05/18] feat(core-tester-cli): basic send command and wallet creation --- .../src/versions/2/wallets/methods.ts | 2 +- packages/core-tester-cli/package.json | 3 + .../core-tester-cli/src/commands/command.ts | 138 ++++++++++++++++-- .../src/commands/make/wallets.ts | 46 ++++++ .../src/commands/send/transfer.ts | 14 +- packages/core-tester-cli/src/http-client.ts | 5 +- 6 files changed, 185 insertions(+), 23 deletions(-) create mode 100644 packages/core-tester-cli/src/commands/make/wallets.ts diff --git a/packages/core-api/src/versions/2/wallets/methods.ts b/packages/core-api/src/versions/2/wallets/methods.ts index c354ff87f5..d9ccaf3904 100644 --- a/packages/core-api/src/versions/2/wallets/methods.ts +++ b/packages/core-api/src/versions/2/wallets/methods.ts @@ -122,7 +122,7 @@ export function registerMethods(server) { ...paginate(request), })) .method("v2.wallets.top", top, 30, request => paginate(request)) - .method("v2.wallets.show", show, 30, request => ({ id: request.params.id })) + .method("v2.wallets.show", show, 8, request => ({ id: request.params.id })) .method("v2.wallets.transactions", transactions, 30, request => ({ ...{ id: request.params.id }, ...request.query, diff --git a/packages/core-tester-cli/package.json b/packages/core-tester-cli/package.json index a597e2cdb4..8a7d112c98 100644 --- a/packages/core-tester-cli/package.json +++ b/packages/core-tester-cli/package.json @@ -79,6 +79,9 @@ }, "send": { "description": "send transactions of various types" + }, + "make": { + "description": "make new identities" } }, "plugins": [ diff --git a/packages/core-tester-cli/src/commands/command.ts b/packages/core-tester-cli/src/commands/command.ts index 48a8142420..7c89658849 100644 --- a/packages/core-tester-cli/src/commands/command.ts +++ b/packages/core-tester-cli/src/commands/command.ts @@ -1,12 +1,14 @@ -import { Bignum } from "@arkecosystem/crypto"; +import { bignumify } from "@arkecosystem/core-utils"; +import { Bignum, formatSatoshi } from "@arkecosystem/crypto"; import { client } from "@arkecosystem/crypto"; import Command, { flags } from "@oclif/command"; +import delay from "delay"; import { satoshiFlag } from "../flags"; import { HttpClient } from "../http-client"; import { logger } from "../logger"; export abstract class BaseCommand extends Command { - public static flagsSent = { + public static flagsConfig = { host: flags.string({ description: "API host", default: "http://localhost", @@ -19,6 +21,10 @@ export abstract class BaseCommand extends Command { description: "P2P port", default: 4000, }), + }; + + public static flagsSent = { + ...BaseCommand.flagsConfig, passphrase: flags.string({ description: "passphrase of initial wallet", default: "clay harbor enemy utility margin pretty hub comic piece aerobic umbrella acquire", @@ -72,29 +78,58 @@ export abstract class BaseCommand extends Command { } for (const transaction of transactions) { - logger.info(`Posting Transaction: ${transaction.id}`); + logger.info( + `[T] ${transaction.id} (${transaction.recipientId} / ${this.fromSatoshi( + transaction.amount, + )} / ${this.fromSatoshi(transaction.fee)})`, + ); } return this.api.post("transactions", { transactions }); } - protected async knockTransaction(id: string): Promise { + protected async knockTransaction(id: string): Promise { try { const { data } = await this.api.get(`transactions/${id}`); - logger.info(`${id} was included in block ${data.blockId}`); + logger.info(`[T] ${id} (${data.blockId})`); + + return true; } catch (error) { logger.error(error.message); - logger.info(`${id} was not included in any blocks`); + logger.error(`[T] ${id} (not forged)`); + + return false; + } + } + + protected async knockBalance(address: string, expected: Bignum): Promise { + const actual = await this.getWalletBalance(address); + + if (bignumify(expected).isEqualTo(actual)) { + logger.info(`[W] ${address} (${this.fromSatoshi(actual)})`); + } else { + logger.error(`[W] ${address} (${this.fromSatoshi(expected)} / ${this.fromSatoshi(actual)})`); + } + } + + protected async getWalletBalance(address: string): Promise { + try { + const { data } = await this.api.get(`wallets/${address}`); + + return bignumify(data.balance); + } catch (error) { + return bignumify(0); } } - protected signTransaction(opts: Record): any { + protected signTransfer(opts: Record): any { const transfer = client .getBuilder() .transfer() .fee(this.toSatoshi(opts.transferFee)) + .network(this.network.version) .recipientId(opts.recipient) .amount(this.toSatoshi(opts.amount)); @@ -111,19 +146,92 @@ export abstract class BaseCommand extends Command { return transfer.getStruct(); } - private async setupConstants() { - const { data } = await this.api.get("node/configuration"); + protected signTransfers(flags: Record, wallets: Record) { + const transactions = []; - this.constants = data.constants; + for (const wallet of Object.keys(wallets)) { + transactions.push(this.signTransfer({ ...flags, ...{ recipient: wallet } })); + } + + return transactions; } - private async setupNetwork() { - const { data } = await this.p2p.get("config"); + protected async verifyTransfers(transactions, wallets) { + for (const transaction of transactions) { + const wasCreated = await this.knockTransaction(transaction.id); - this.network = data.network; + if (wasCreated) { + await this.knockBalance(transaction.recipientId, wallets[transaction.recipientId].expectedBalance); + } + } } - private toSatoshi(value: number): number { - return +new Bignum(value).times(1e8).toFixed(); + protected async expectBalances(transactions, wallets) { + for (const transaction of transactions) { + const currentBalance = await this.getWalletBalance(transaction.recipientId); + wallets[transaction.recipientId].expectedBalance = currentBalance.plus(transaction.amount); + } + } + + protected async broadcastTransfers(transactions) { + const sendTransactions = []; + for (const transaction of transactions) { + sendTransactions.push(this.sendTransaction(transaction)); + } + + await Promise.all(sendTransactions); + + // @TODO make this dynamic + await delay(8000); + } + + protected castFlags(values: Record): string[] { + return Object.keys(BaseCommand.flagsConfig) + .map((key: string) => { + const value = values[key]; + + if (value === undefined) { + return undefined; + } + + if (value === true) { + return `--${key}`; + } + + return `--${key}=${value}`; + }) + .filter(value => value !== undefined); + } + + protected toSatoshi(value) { + return bignumify(value) + .times(1e8) + .toFixed(); + } + + protected fromSatoshi(satoshi) { + return formatSatoshi(satoshi); + } + + private async setupConstants() { + try { + const { data } = await this.api.get("node/configuration"); + + this.constants = data.constants; + } catch (error) { + logger.error(error.message); + process.exit(1); + } + } + + private async setupNetwork() { + try { + const { data } = await this.p2p.get("config"); + + this.network = data.network; + } catch (error) { + logger.error(error.message); + process.exit(1); + } } } diff --git a/packages/core-tester-cli/src/commands/make/wallets.ts b/packages/core-tester-cli/src/commands/make/wallets.ts new file mode 100644 index 0000000000..91dcd98872 --- /dev/null +++ b/packages/core-tester-cli/src/commands/make/wallets.ts @@ -0,0 +1,46 @@ +import { crypto } from "@arkecosystem/crypto"; +import { flags } from "@oclif/command"; +import { generateMnemonic } from "bip39"; +import { writeFileSync } from "fs"; +import { copyToClipboard } from "../../utils"; +import { BaseCommand } from "../command"; + +export class WalletCommand extends BaseCommand { + public static description: string = "send multiple transactions"; + + public static flags = { + ...BaseCommand.flagsConfig, + quantity: flags.integer({ + description: "number of wallets to generate", + }), + copy: flags.boolean({ + description: "write the wallets to the clipboard", + }), + write: flags.boolean({ + description: "write the wallets to the disk", + }), + }; + + public async run(): Promise> { + const { flags } = await this.make(WalletCommand); + + const wallets = {}; + for (let i = 0; i < flags.quantity; i++) { + const passphrase = generateMnemonic(); + const keys = crypto.getKeys(passphrase); + const address = crypto.getAddress(keys.publicKey, this.network.version); + + wallets[address] = { address, keys, passphrase }; + } + + if (flags.copy) { + copyToClipboard(JSON.stringify(wallets)); + } + + if (flags.write) { + writeFileSync("./wallets.json", JSON.stringify(wallets)); + } + + return wallets; + } +} diff --git a/packages/core-tester-cli/src/commands/send/transfer.ts b/packages/core-tester-cli/src/commands/send/transfer.ts index 84a358e067..95cf4069d7 100644 --- a/packages/core-tester-cli/src/commands/send/transfer.ts +++ b/packages/core-tester-cli/src/commands/send/transfer.ts @@ -2,6 +2,7 @@ import { crypto } from "@arkecosystem/crypto"; import { flags } from "@oclif/command"; import delay from "delay"; import { BaseCommand } from "../command"; +import { WalletCommand } from "../make/wallets"; export class TransferCommand extends BaseCommand { public static description: string = "send multiple transactions"; @@ -19,12 +20,17 @@ export class TransferCommand extends BaseCommand { public async run(): Promise { const { flags } = await this.make(TransferCommand); - const transaction = this.signTransaction(flags); + // Prepare... + const wallets = await WalletCommand.run([`--quantity=${flags.number}`].concat(this.castFlags(flags))); + const transactions = this.signTransfers(flags, wallets); - await this.sendTransaction(transaction); + // Expect... + await this.expectBalances(transactions, wallets); - await delay(8000); + // Send... + await this.broadcastTransfers(transactions); - await this.knockTransaction(transaction.id); + // Verify... + await this.verifyTransfers(transactions, wallets); } } diff --git a/packages/core-tester-cli/src/http-client.ts b/packages/core-tester-cli/src/http-client.ts index 69dc493e20..0bf6cc858a 100644 --- a/packages/core-tester-cli/src/http-client.ts +++ b/packages/core-tester-cli/src/http-client.ts @@ -1,5 +1,4 @@ import Axios from "axios"; -import { logger } from "./logger"; export class HttpClient { private instance: any; @@ -14,7 +13,7 @@ export class HttpClient { return data; } catch (error) { - logger.error(error.message); + // do nothing... } } @@ -24,7 +23,7 @@ export class HttpClient { return data; } catch (error) { - logger.error(error.message); + // do nothing... } } } From 991d09795bdb9c85df89cf09c0e428d290547ff7 Mon Sep 17 00:00:00 2001 From: Brian Faust Date: Fri, 22 Feb 2019 08:10:13 +0200 Subject: [PATCH 06/18] refactor(core-tester-cli): await confirmations based on blocktime --- packages/core-tester-cli/src/commands/command.ts | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/packages/core-tester-cli/src/commands/command.ts b/packages/core-tester-cli/src/commands/command.ts index 7c89658849..bf2a501467 100644 --- a/packages/core-tester-cli/src/commands/command.ts +++ b/packages/core-tester-cli/src/commands/command.ts @@ -120,7 +120,7 @@ export abstract class BaseCommand extends Command { return bignumify(data.balance); } catch (error) { - return bignumify(0); + return Bignum.ZERO; } } @@ -181,8 +181,7 @@ export abstract class BaseCommand extends Command { await Promise.all(sendTransactions); - // @TODO make this dynamic - await delay(8000); + return this.awaitConfirmations(transactions); } protected castFlags(values: Record): string[] { @@ -234,4 +233,15 @@ export abstract class BaseCommand extends Command { process.exit(1); } } + + private async awaitConfirmations(transactions): Promise { + if (process.env.NODE_ENV === "test") { + return; + } + + const waitPerBlock = + this.constants.blocktime * Math.ceil(transactions.length / this.constants.block.maxTransactions); + + await delay(waitPerBlock * 1000); + } } From dadcf2a64f8b6878b6289f6f3a5c96321e721b08 Mon Sep 17 00:00:00 2001 From: Brian Faust Date: Fri, 22 Feb 2019 08:49:01 +0200 Subject: [PATCH 07/18] feat(core-tester-cli): basic delegate registration command --- packages/core-tester-cli/package.json | 3 +- .../core-tester-cli/src/commands/command.ts | 69 ++++----------- .../commands/send/delegate-registration.ts | 83 +++++++++++++++++++ .../src/commands/send/transfer.ts | 35 +++++++- packages/core-tester-cli/src/signer.ts | 60 ++++++++++++++ 5 files changed, 193 insertions(+), 57 deletions(-) create mode 100644 packages/core-tester-cli/src/commands/send/delegate-registration.ts create mode 100644 packages/core-tester-cli/src/signer.ts diff --git a/packages/core-tester-cli/package.json b/packages/core-tester-cli/package.json index 8a7d112c98..153144f3c3 100644 --- a/packages/core-tester-cli/package.json +++ b/packages/core-tester-cli/package.json @@ -55,7 +55,8 @@ "delay": "^4.1.0", "pino": "^5.11.1", "pino-pretty": "^2.5.0", - "pluralize": "^7.0.0" + "pluralize": "^7.0.0", + "pokemon": "^1.2.3" }, "devDependencies": { "@types/clipboardy": "^1.1.0", diff --git a/packages/core-tester-cli/src/commands/command.ts b/packages/core-tester-cli/src/commands/command.ts index bf2a501467..ee6863caa5 100644 --- a/packages/core-tester-cli/src/commands/command.ts +++ b/packages/core-tester-cli/src/commands/command.ts @@ -1,11 +1,12 @@ import { bignumify } from "@arkecosystem/core-utils"; -import { Bignum, formatSatoshi } from "@arkecosystem/crypto"; +import { Address, Bignum, formatSatoshi } from "@arkecosystem/crypto"; import { client } from "@arkecosystem/crypto"; import Command, { flags } from "@oclif/command"; import delay from "delay"; import { satoshiFlag } from "../flags"; import { HttpClient } from "../http-client"; import { logger } from "../logger"; +import { Signer } from "../signer"; export abstract class BaseCommand extends Command { public static flagsConfig = { @@ -34,7 +35,7 @@ export abstract class BaseCommand extends Command { }), number: flags.integer({ description: "number of wallets", - default: 10, + default: 1, }), amount: satoshiFlag({ description: "initial wallet token amount", @@ -57,6 +58,7 @@ export abstract class BaseCommand extends Command { protected api: HttpClient; protected p2p: HttpClient; + protected signer: Signer; protected network: Record; protected constants: Record; @@ -69,6 +71,8 @@ export abstract class BaseCommand extends Command { await this.setupConstants(); await this.setupNetwork(); + this.signer = new Signer(this.network); + return { args, flags }; } @@ -78,10 +82,16 @@ export abstract class BaseCommand extends Command { } for (const transaction of transactions) { + let recipientId = transaction.recipientId; + + if (!recipientId) { + recipientId = Address.fromPublicKey(transaction.senderPublicKey, this.network.version); + } + logger.info( - `[T] ${transaction.id} (${transaction.recipientId} / ${this.fromSatoshi( - transaction.amount, - )} / ${this.fromSatoshi(transaction.fee)})`, + `[T] ${transaction.id} (${recipientId} / ${this.fromSatoshi(transaction.amount)} / ${this.fromSatoshi( + transaction.fee, + )})`, ); } @@ -124,55 +134,6 @@ export abstract class BaseCommand extends Command { } } - protected signTransfer(opts: Record): any { - const transfer = client - .getBuilder() - .transfer() - .fee(this.toSatoshi(opts.transferFee)) - .network(this.network.version) - .recipientId(opts.recipient) - .amount(this.toSatoshi(opts.amount)); - - if (opts.vendorField) { - transfer.vendorField(opts.vendorField); - } - - transfer.sign(opts.passphrase); - - if (opts.secondPassphrase) { - transfer.secondSign(opts.secondPassphrase); - } - - return transfer.getStruct(); - } - - protected signTransfers(flags: Record, wallets: Record) { - const transactions = []; - - for (const wallet of Object.keys(wallets)) { - transactions.push(this.signTransfer({ ...flags, ...{ recipient: wallet } })); - } - - return transactions; - } - - protected async verifyTransfers(transactions, wallets) { - for (const transaction of transactions) { - const wasCreated = await this.knockTransaction(transaction.id); - - if (wasCreated) { - await this.knockBalance(transaction.recipientId, wallets[transaction.recipientId].expectedBalance); - } - } - } - - protected async expectBalances(transactions, wallets) { - for (const transaction of transactions) { - const currentBalance = await this.getWalletBalance(transaction.recipientId); - wallets[transaction.recipientId].expectedBalance = currentBalance.plus(transaction.amount); - } - } - protected async broadcastTransfers(transactions) { const sendTransactions = []; for (const transaction of transactions) { diff --git a/packages/core-tester-cli/src/commands/send/delegate-registration.ts b/packages/core-tester-cli/src/commands/send/delegate-registration.ts new file mode 100644 index 0000000000..30b0735cac --- /dev/null +++ b/packages/core-tester-cli/src/commands/send/delegate-registration.ts @@ -0,0 +1,83 @@ +import { Address, client } from "@arkecosystem/crypto"; +import pokemon from "pokemon"; +import { satoshiFlag } from "../../flags"; +import { BaseCommand } from "../command"; +import { TransferCommand } from "./transfer"; + +export class DelegateRegistrationCommand extends BaseCommand { + public static description: string = "send multiple transactions"; + + public static flags = { + ...BaseCommand.flagsSent, + delegateFee: satoshiFlag({ + description: "delegate registration fee", + default: 25, + }), + }; + + public async run(): Promise { + const { flags } = await this.make(DelegateRegistrationCommand); + + // Prepare... + const wallets = await TransferCommand.run( + [`--amount=${flags.delegateFee}`, `--number=${flags.number}`].concat(this.castFlags(flags)), + ); + + // Sign... + const transactions = this.signTransactions(flags, wallets); + + // Expect... + await this.expectBalances(transactions, wallets); + + // Send... + await this.broadcastTransfers(transactions); + + // Verify... + await this.verifyTransactions(transactions, wallets); + + return wallets; + } + + protected signTransactions(flags: Record, wallets: Record) { + const transactions = []; + + for (const wallet of Object.values(wallets)) { + transactions.push( + this.signer.makeDelegate({ + ...flags, + ...{ + username: pokemon + .random() + .toLowerCase() + .replace(/ /g, "_"), + // @ts-ignore + passphrase: wallet.passphrase, + }, + }), + ); + } + + return transactions; + } + + private async expectBalances(transactions, wallets) { + for (const transaction of transactions) { + const recipientId = Address.fromPublicKey(transaction.senderPublicKey, this.network.version); + + const currentBalance = await this.getWalletBalance(recipientId); + wallets[recipientId].expectedBalance = currentBalance.minus(transaction.fee); + } + } + + private async verifyTransactions(transactions, wallets) { + for (const transaction of transactions) { + const wasCreated = await this.knockTransaction(transaction.id); + + if (wasCreated) { + const recipientId = Address.fromPublicKey(transaction.senderPublicKey, this.network.version); + + await this.knockBalance(recipientId, wallets[recipientId].expectedBalance); + } + } + } +} diff --git a/packages/core-tester-cli/src/commands/send/transfer.ts b/packages/core-tester-cli/src/commands/send/transfer.ts index 95cf4069d7..a9a84ce35c 100644 --- a/packages/core-tester-cli/src/commands/send/transfer.ts +++ b/packages/core-tester-cli/src/commands/send/transfer.ts @@ -22,7 +22,9 @@ export class TransferCommand extends BaseCommand { // Prepare... const wallets = await WalletCommand.run([`--quantity=${flags.number}`].concat(this.castFlags(flags))); - const transactions = this.signTransfers(flags, wallets); + + // Sign... + const transactions = this.signTransactions(flags, wallets); // Expect... await this.expectBalances(transactions, wallets); @@ -31,6 +33,35 @@ export class TransferCommand extends BaseCommand { await this.broadcastTransfers(transactions); // Verify... - await this.verifyTransfers(transactions, wallets); + await this.verifyTransactions(transactions, wallets); + + return wallets; + } + + protected signTransactions(flags: Record, wallets: Record) { + const transactions = []; + + for (const wallet of Object.keys(wallets)) { + transactions.push(this.signer.makeTransfer({ ...flags, ...{ recipient: wallet } })); + } + + return transactions; + } + + private async expectBalances(transactions, wallets) { + for (const transaction of transactions) { + const currentBalance = await this.getWalletBalance(transaction.recipientId); + wallets[transaction.recipientId].expectedBalance = currentBalance.plus(transaction.amount); + } + } + + private async verifyTransactions(transactions, wallets) { + for (const transaction of transactions) { + const wasCreated = await this.knockTransaction(transaction.id); + + if (wasCreated) { + await this.knockBalance(transaction.recipientId, wallets[transaction.recipientId].expectedBalance); + } + } } } diff --git a/packages/core-tester-cli/src/signer.ts b/packages/core-tester-cli/src/signer.ts new file mode 100644 index 0000000000..a55320e628 --- /dev/null +++ b/packages/core-tester-cli/src/signer.ts @@ -0,0 +1,60 @@ +import { bignumify } from "@arkecosystem/core-utils"; +import { formatSatoshi } from "@arkecosystem/crypto"; +import { client } from "@arkecosystem/crypto"; + +export class Signer { + protected network: Record; + + public constructor(network) { + this.network = network; + } + + public makeTransfer(opts: Record): any { + const transaction = client + .getBuilder() + .transfer() + .fee(this.toSatoshi(opts.transferFee)) + .network(this.network.version) + .recipientId(opts.recipient) + .amount(this.toSatoshi(opts.amount)); + + if (opts.vendorField) { + transaction.vendorField(opts.vendorField); + } + + transaction.sign(opts.passphrase); + + if (opts.secondPassphrase) { + transaction.secondSign(opts.secondPassphrase); + } + + return transaction.getStruct(); + } + + public makeDelegate(opts: Record): any { + const transaction = client + .getBuilder() + .delegateRegistration() + .fee(this.toSatoshi(opts.delegateFee)) + .network(this.network.version) + .usernameAsset(opts.username); + + transaction.sign(opts.passphrase); + + if (opts.secondPassphrase) { + transaction.secondSign(opts.secondPassphrase); + } + + return transaction.getStruct(); + } + + private toSatoshi(value) { + return bignumify(value) + .times(1e8) + .toFixed(); + } + + private fromSatoshi(satoshi) { + return formatSatoshi(satoshi); + } +} From 8566a375d97e55d80235aaf23c72beb7915c2a33 Mon Sep 17 00:00:00 2001 From: Brian Faust Date: Fri, 22 Feb 2019 09:03:31 +0200 Subject: [PATCH 08/18] feat(core-tester-cli): basic second signature registration command --- .../core-tester-cli/src/commands/command.ts | 4 +- .../commands/send/delegate-registration.ts | 28 ++++-- .../send/second-signature-registration.ts | 94 +++++++++++++++++++ .../src/commands/send/transfer.ts | 4 +- packages/core-tester-cli/src/signer.ts | 11 +++ 5 files changed, 130 insertions(+), 11 deletions(-) create mode 100644 packages/core-tester-cli/src/commands/send/second-signature-registration.ts diff --git a/packages/core-tester-cli/src/commands/command.ts b/packages/core-tester-cli/src/commands/command.ts index ee6863caa5..ad9b5dbb2c 100644 --- a/packages/core-tester-cli/src/commands/command.ts +++ b/packages/core-tester-cli/src/commands/command.ts @@ -24,7 +24,7 @@ export abstract class BaseCommand extends Command { }), }; - public static flagsSent = { + public static flagsSend = { ...BaseCommand.flagsConfig, passphrase: flags.string({ description: "passphrase of initial wallet", @@ -134,7 +134,7 @@ export abstract class BaseCommand extends Command { } } - protected async broadcastTransfers(transactions) { + protected async broadcastTransactions(transactions) { const sendTransactions = []; for (const transaction of transactions) { sendTransactions.push(this.sendTransaction(transaction)); diff --git a/packages/core-tester-cli/src/commands/send/delegate-registration.ts b/packages/core-tester-cli/src/commands/send/delegate-registration.ts index 30b0735cac..8cb1eb274c 100644 --- a/packages/core-tester-cli/src/commands/send/delegate-registration.ts +++ b/packages/core-tester-cli/src/commands/send/delegate-registration.ts @@ -1,6 +1,7 @@ import { Address, client } from "@arkecosystem/crypto"; import pokemon from "pokemon"; import { satoshiFlag } from "../../flags"; +import { logger } from "../../logger"; import { BaseCommand } from "../command"; import { TransferCommand } from "./transfer"; @@ -8,7 +9,7 @@ export class DelegateRegistrationCommand extends BaseCommand { public static description: string = "send multiple transactions"; public static flags = { - ...BaseCommand.flagsSent, + ...BaseCommand.flagsSend, delegateFee: satoshiFlag({ description: "delegate registration fee", default: 25, @@ -30,7 +31,7 @@ export class DelegateRegistrationCommand extends BaseCommand { await this.expectBalances(transactions, wallets); // Send... - await this.broadcastTransfers(transactions); + await this.broadcastTransactions(transactions); // Verify... await this.verifyTransactions(transactions, wallets); @@ -41,15 +42,17 @@ export class DelegateRegistrationCommand extends BaseCommand { protected signTransactions(flags: Record, wallets: Record) { const transactions = []; - for (const wallet of Object.values(wallets)) { + for (const [address, wallet] of Object.entries(wallets)) { + wallets[address].username = pokemon + .random() + .toLowerCase() + .replace(/ /g, "_"); + transactions.push( this.signer.makeDelegate({ ...flags, ...{ - username: pokemon - .random() - .toLowerCase() - .replace(/ /g, "_"), + username: wallets[address].username, // @ts-ignore passphrase: wallet.passphrase, }, @@ -77,7 +80,18 @@ export class DelegateRegistrationCommand extends BaseCommand { const recipientId = Address.fromPublicKey(transaction.senderPublicKey, this.network.version); await this.knockBalance(recipientId, wallets[recipientId].expectedBalance); + await this.knockUsername(recipientId, wallets[recipientId].username); } } } + + private async knockUsername(address: string, expected: string): Promise { + const { username: actual } = (await this.api.get(`wallets/${address}`)).data; + + if (actual === expected) { + logger.info(`[W] ${address} (${actual})`); + } else { + logger.error(`[W] ${address} (${expected} / ${actual})`); + } + } } diff --git a/packages/core-tester-cli/src/commands/send/second-signature-registration.ts b/packages/core-tester-cli/src/commands/send/second-signature-registration.ts new file mode 100644 index 0000000000..e64b498196 --- /dev/null +++ b/packages/core-tester-cli/src/commands/send/second-signature-registration.ts @@ -0,0 +1,94 @@ +import { Address, client } from "@arkecosystem/crypto"; +import pokemon from "pokemon"; +import { satoshiFlag } from "../../flags"; +import { logger } from "../../logger"; +import { BaseCommand } from "../command"; +import { TransferCommand } from "./transfer"; + +export class SecondSignatureRegistrationCommand extends BaseCommand { + public static description: string = "send multiple transactions"; + + public static flags = { + ...BaseCommand.flagsSend, + signatureFee: satoshiFlag({ + description: "second signature fee", + default: 5, + }), + }; + + public async run(): Promise { + const { flags } = await this.make(SecondSignatureRegistrationCommand); + + // Prepare... + const wallets = await TransferCommand.run( + [`--amount=${flags.signatureFee}`, `--number=${flags.number}`].concat(this.castFlags(flags)), + ); + + // Sign... + const transactions = this.signTransactions(flags, wallets); + + // Expect... + await this.expectBalances(transactions, wallets); + + // Send... + await this.broadcastTransactions(transactions); + + // Verify... + await this.verifyTransactions(transactions, wallets); + + return wallets; + } + + protected signTransactions(flags: Record, wallets: Record) { + const transactions = []; + + for (const [address, wallet] of Object.entries(wallets)) { + const transaction = this.signer.makeSecondSignature({ + ...flags, + ...{ + passphrase: wallet.passphrase, + secondPassphrase: wallet.passphrase, + }, + }); + + wallets[address].publicKey = transaction.senderPublicKey; + wallets[address].secondPublicKey = transaction.asset.signature.publicKey; + + transactions.push(transaction); + } + + return transactions; + } + + private async expectBalances(transactions, wallets) { + for (const transaction of transactions) { + const recipientId = Address.fromPublicKey(transaction.senderPublicKey, this.network.version); + + const currentBalance = await this.getWalletBalance(recipientId); + wallets[recipientId].expectedBalance = currentBalance.minus(transaction.fee); + } + } + + private async verifyTransactions(transactions, wallets) { + for (const transaction of transactions) { + const wasCreated = await this.knockTransaction(transaction.id); + + if (wasCreated) { + const recipientId = Address.fromPublicKey(transaction.senderPublicKey, this.network.version); + + await this.knockBalance(recipientId, wallets[recipientId].expectedBalance); + await this.knockSignature(recipientId, wallets[recipientId].secondPublicKey); + } + } + } + + private async knockSignature(address: string, expected: string): Promise { + const { secondPublicKey: actual } = (await this.api.get(`wallets/${address}`)).data; + + if (actual === expected) { + logger.info(`[W] ${address} (${actual})`); + } else { + logger.error(`[W] ${address} (${expected} / ${actual})`); + } + } +} diff --git a/packages/core-tester-cli/src/commands/send/transfer.ts b/packages/core-tester-cli/src/commands/send/transfer.ts index a9a84ce35c..e283f0dd2e 100644 --- a/packages/core-tester-cli/src/commands/send/transfer.ts +++ b/packages/core-tester-cli/src/commands/send/transfer.ts @@ -8,7 +8,7 @@ export class TransferCommand extends BaseCommand { public static description: string = "send multiple transactions"; public static flags = { - ...BaseCommand.flagsSent, + ...BaseCommand.flagsSend, recipient: flags.string({ description: "recipient address", }), @@ -30,7 +30,7 @@ export class TransferCommand extends BaseCommand { await this.expectBalances(transactions, wallets); // Send... - await this.broadcastTransfers(transactions); + await this.broadcastTransactions(transactions); // Verify... await this.verifyTransactions(transactions, wallets); diff --git a/packages/core-tester-cli/src/signer.ts b/packages/core-tester-cli/src/signer.ts index a55320e628..31e8823fae 100644 --- a/packages/core-tester-cli/src/signer.ts +++ b/packages/core-tester-cli/src/signer.ts @@ -48,6 +48,17 @@ export class Signer { return transaction.getStruct(); } + public makeSecondSignature(opts: Record): any { + return client + .getBuilder() + .secondSignature() + .fee(this.toSatoshi(opts.signatureFee)) + .network(this.network.version) + .signatureAsset(opts.secondPassphrase) + .sign(opts.passphrase) + .getStruct(); + } + private toSatoshi(value) { return bignumify(value) .times(1e8) From fc9735675fcfcf4ad2fb5b51bb30c29e93f42a40 Mon Sep 17 00:00:00 2001 From: Brian Faust Date: Fri, 22 Feb 2019 09:12:41 +0200 Subject: [PATCH 09/18] feat(core-tester-cli): basic vote command --- .../commands/send/delegate-registration.ts | 2 +- .../send/second-signature-registration.ts | 3 +- .../src/commands/send/transfer.ts | 2 - .../core-tester-cli/src/commands/send/vote.ts | 100 ++++++++++++++++++ packages/core-tester-cli/src/signer.ts | 25 +++-- packages/core-tester-cli/src/utils.ts | 1 - 6 files changed, 120 insertions(+), 13 deletions(-) create mode 100644 packages/core-tester-cli/src/commands/send/vote.ts diff --git a/packages/core-tester-cli/src/commands/send/delegate-registration.ts b/packages/core-tester-cli/src/commands/send/delegate-registration.ts index 8cb1eb274c..77e20cef12 100644 --- a/packages/core-tester-cli/src/commands/send/delegate-registration.ts +++ b/packages/core-tester-cli/src/commands/send/delegate-registration.ts @@ -1,4 +1,4 @@ -import { Address, client } from "@arkecosystem/crypto"; +import { Address } from "@arkecosystem/crypto"; import pokemon from "pokemon"; import { satoshiFlag } from "../../flags"; import { logger } from "../../logger"; diff --git a/packages/core-tester-cli/src/commands/send/second-signature-registration.ts b/packages/core-tester-cli/src/commands/send/second-signature-registration.ts index e64b498196..17397b7909 100644 --- a/packages/core-tester-cli/src/commands/send/second-signature-registration.ts +++ b/packages/core-tester-cli/src/commands/send/second-signature-registration.ts @@ -1,5 +1,4 @@ -import { Address, client } from "@arkecosystem/crypto"; -import pokemon from "pokemon"; +import { Address } from "@arkecosystem/crypto"; import { satoshiFlag } from "../../flags"; import { logger } from "../../logger"; import { BaseCommand } from "../command"; diff --git a/packages/core-tester-cli/src/commands/send/transfer.ts b/packages/core-tester-cli/src/commands/send/transfer.ts index e283f0dd2e..970313f534 100644 --- a/packages/core-tester-cli/src/commands/send/transfer.ts +++ b/packages/core-tester-cli/src/commands/send/transfer.ts @@ -1,6 +1,4 @@ -import { crypto } from "@arkecosystem/crypto"; import { flags } from "@oclif/command"; -import delay from "delay"; import { BaseCommand } from "../command"; import { WalletCommand } from "../make/wallets"; diff --git a/packages/core-tester-cli/src/commands/send/vote.ts b/packages/core-tester-cli/src/commands/send/vote.ts new file mode 100644 index 0000000000..8a0f0d04da --- /dev/null +++ b/packages/core-tester-cli/src/commands/send/vote.ts @@ -0,0 +1,100 @@ +import { Address } from "@arkecosystem/crypto"; +import { satoshiFlag } from "../../flags"; +import { logger } from "../../logger"; +import { BaseCommand } from "../command"; +import { TransferCommand } from "./transfer"; + +export class VoteCommand extends BaseCommand { + public static description: string = "send multiple transactions"; + + public static flags = { + ...BaseCommand.flagsSend, + voteFee: satoshiFlag({ + description: "vote fee", + default: 1, + }), + }; + + public async run(): Promise { + const { flags } = await this.make(VoteCommand); + + // Prepare... + const wallets = await TransferCommand.run( + [`--amount=${flags.voteFee}`, `--number=${flags.number}`].concat(this.castFlags(flags)), + ); + + // Sign... + const transactions = await this.signTransactions(flags, wallets); + + // Expect... + await this.expectBalances(transactions, wallets); + + // Send... + await this.broadcastTransactions(transactions); + + // Verify... + await this.verifyTransactions(transactions, wallets); + + return wallets; + } + + protected async signTransactions(flags: Record, wallets: Record) { + const transactions = []; + + for (const [address, wallet] of Object.entries(wallets)) { + const delegate = await this.getRandomDelegate(); + + const transaction = this.signer.makeVote({ + ...flags, + ...{ + delegate, + passphrase: wallet.passphrase, + }, + }); + + wallets[address].vote = delegate; + + transactions.push(transaction); + } + + return transactions; + } + + private async expectBalances(transactions, wallets) { + for (const transaction of transactions) { + const recipientId = Address.fromPublicKey(transaction.senderPublicKey, this.network.version); + + const currentBalance = await this.getWalletBalance(recipientId); + wallets[recipientId].expectedBalance = currentBalance.minus(transaction.fee); + } + } + + private async verifyTransactions(transactions, wallets) { + for (const transaction of transactions) { + const wasCreated = await this.knockTransaction(transaction.id); + + if (wasCreated) { + const recipientId = Address.fromPublicKey(transaction.senderPublicKey, this.network.version); + + await this.knockBalance(recipientId, wallets[recipientId].expectedBalance); + await this.knockVote(recipientId, wallets[recipientId].vote); + } + } + } + + private async knockVote(address: string, expected: string): Promise { + const { vote: actual } = (await this.api.get(`wallets/${address}`)).data; + + if (actual === expected) { + logger.info(`[W] ${address} (${actual})`); + } else { + logger.error(`[W] ${address} (${expected} / ${actual})`); + } + } + + private async getRandomDelegate() { + const { data } = await this.api.get("delegates"); + + return data[0].publicKey; + } +} diff --git a/packages/core-tester-cli/src/signer.ts b/packages/core-tester-cli/src/signer.ts index 31e8823fae..e1e7048a81 100644 --- a/packages/core-tester-cli/src/signer.ts +++ b/packages/core-tester-cli/src/signer.ts @@ -37,9 +37,8 @@ export class Signer { .delegateRegistration() .fee(this.toSatoshi(opts.delegateFee)) .network(this.network.version) - .usernameAsset(opts.username); - - transaction.sign(opts.passphrase); + .usernameAsset(opts.username) + .sign(opts.passphrase); if (opts.secondPassphrase) { transaction.secondSign(opts.secondPassphrase); @@ -59,13 +58,25 @@ export class Signer { .getStruct(); } + public makeVote(opts: Record): any { + const transaction = client + .getBuilder() + .vote() + .fee(this.toSatoshi(opts.voteFee)) + .votesAsset([`+${opts.delegate}`]) + .network(this.network.version) + .sign(opts.passphrase); + + if (opts.secondPassphrase) { + transaction.secondSign(opts.secondPassphrase); + } + + return transaction.getStruct(); + } + private toSatoshi(value) { return bignumify(value) .times(1e8) .toFixed(); } - - private fromSatoshi(satoshi) { - return formatSatoshi(satoshi); - } } diff --git a/packages/core-tester-cli/src/utils.ts b/packages/core-tester-cli/src/utils.ts index 2fbd8ef2ac..8ff6884a38 100644 --- a/packages/core-tester-cli/src/utils.ts +++ b/packages/core-tester-cli/src/utils.ts @@ -10,7 +10,6 @@ export function handleOutput(opts, data) { } if (opts.log) { - // tslint:disable-next-line:no-console return console.log(data); } From cd4c091ee597c92c8d47905c7ceba2de1b190d91 Mon Sep 17 00:00:00 2001 From: Brian Faust Date: Fri, 22 Feb 2019 09:26:42 +0200 Subject: [PATCH 10/18] refactor(core-tester-cli): reduce duplication --- .../commands/send/delegate-registration.ts | 37 ++++++------------- .../send/second-signature-registration.ts | 37 ++++++------------- .../src/commands/send/transfer.ts | 35 ++++++------------ .../core-tester-cli/src/commands/send/vote.ts | 37 ++++++------------- packages/core-tester-cli/src/shared/send.ts | 36 ++++++++++++++++++ 5 files changed, 83 insertions(+), 99 deletions(-) create mode 100644 packages/core-tester-cli/src/shared/send.ts diff --git a/packages/core-tester-cli/src/commands/send/delegate-registration.ts b/packages/core-tester-cli/src/commands/send/delegate-registration.ts index 77e20cef12..90bd7a022b 100644 --- a/packages/core-tester-cli/src/commands/send/delegate-registration.ts +++ b/packages/core-tester-cli/src/commands/send/delegate-registration.ts @@ -2,44 +2,31 @@ import { Address } from "@arkecosystem/crypto"; import pokemon from "pokemon"; import { satoshiFlag } from "../../flags"; import { logger } from "../../logger"; -import { BaseCommand } from "../command"; +import { SendCommand } from "../../shared/send"; import { TransferCommand } from "./transfer"; -export class DelegateRegistrationCommand extends BaseCommand { - public static description: string = "send multiple transactions"; +export class DelegateRegistrationCommand extends SendCommand { + public static description: string = "create multiple delegates"; public static flags = { - ...BaseCommand.flagsSend, + ...SendCommand.flagsSend, delegateFee: satoshiFlag({ description: "delegate registration fee", default: 25, }), }; - public async run(): Promise { - const { flags } = await this.make(DelegateRegistrationCommand); + protected getCommand(): any { + return DelegateRegistrationCommand; + } - // Prepare... - const wallets = await TransferCommand.run( + protected async createWalletsWithBalance(flags: Record): Promise { + return TransferCommand.run( [`--amount=${flags.delegateFee}`, `--number=${flags.number}`].concat(this.castFlags(flags)), ); - - // Sign... - const transactions = this.signTransactions(flags, wallets); - - // Expect... - await this.expectBalances(transactions, wallets); - - // Send... - await this.broadcastTransactions(transactions); - - // Verify... - await this.verifyTransactions(transactions, wallets); - - return wallets; } - protected signTransactions(flags: Record, wallets: Record) { + protected async signTransactions(flags: Record, wallets: Record): Promise { const transactions = []; for (const [address, wallet] of Object.entries(wallets)) { @@ -63,7 +50,7 @@ export class DelegateRegistrationCommand extends BaseCommand { return transactions; } - private async expectBalances(transactions, wallets) { + protected async expectBalances(transactions, wallets): Promise { for (const transaction of transactions) { const recipientId = Address.fromPublicKey(transaction.senderPublicKey, this.network.version); @@ -72,7 +59,7 @@ export class DelegateRegistrationCommand extends BaseCommand { } } - private async verifyTransactions(transactions, wallets) { + protected async verifyTransactions(transactions, wallets): Promise { for (const transaction of transactions) { const wasCreated = await this.knockTransaction(transaction.id); diff --git a/packages/core-tester-cli/src/commands/send/second-signature-registration.ts b/packages/core-tester-cli/src/commands/send/second-signature-registration.ts index 17397b7909..18c5bfe474 100644 --- a/packages/core-tester-cli/src/commands/send/second-signature-registration.ts +++ b/packages/core-tester-cli/src/commands/send/second-signature-registration.ts @@ -1,44 +1,31 @@ import { Address } from "@arkecosystem/crypto"; import { satoshiFlag } from "../../flags"; import { logger } from "../../logger"; -import { BaseCommand } from "../command"; +import { SendCommand } from "../../shared/send"; import { TransferCommand } from "./transfer"; -export class SecondSignatureRegistrationCommand extends BaseCommand { - public static description: string = "send multiple transactions"; +export class SecondSignatureRegistrationCommand extends SendCommand { + public static description: string = "create wallets with second signature"; public static flags = { - ...BaseCommand.flagsSend, + ...SendCommand.flagsSend, signatureFee: satoshiFlag({ description: "second signature fee", default: 5, }), }; - public async run(): Promise { - const { flags } = await this.make(SecondSignatureRegistrationCommand); + protected getCommand(): any { + return SecondSignatureRegistrationCommand; + } - // Prepare... - const wallets = await TransferCommand.run( + protected async createWalletsWithBalance(flags: Record): Promise { + return TransferCommand.run( [`--amount=${flags.signatureFee}`, `--number=${flags.number}`].concat(this.castFlags(flags)), ); - - // Sign... - const transactions = this.signTransactions(flags, wallets); - - // Expect... - await this.expectBalances(transactions, wallets); - - // Send... - await this.broadcastTransactions(transactions); - - // Verify... - await this.verifyTransactions(transactions, wallets); - - return wallets; } - protected signTransactions(flags: Record, wallets: Record) { + protected async signTransactions(flags: Record, wallets: Record): Promise { const transactions = []; for (const [address, wallet] of Object.entries(wallets)) { @@ -59,7 +46,7 @@ export class SecondSignatureRegistrationCommand extends BaseCommand { return transactions; } - private async expectBalances(transactions, wallets) { + protected async expectBalances(transactions, wallets): Promise { for (const transaction of transactions) { const recipientId = Address.fromPublicKey(transaction.senderPublicKey, this.network.version); @@ -68,7 +55,7 @@ export class SecondSignatureRegistrationCommand extends BaseCommand { } } - private async verifyTransactions(transactions, wallets) { + protected async verifyTransactions(transactions, wallets): Promise { for (const transaction of transactions) { const wasCreated = await this.knockTransaction(transaction.id); diff --git a/packages/core-tester-cli/src/commands/send/transfer.ts b/packages/core-tester-cli/src/commands/send/transfer.ts index 970313f534..3ec4cfb029 100644 --- a/packages/core-tester-cli/src/commands/send/transfer.ts +++ b/packages/core-tester-cli/src/commands/send/transfer.ts @@ -1,12 +1,12 @@ import { flags } from "@oclif/command"; -import { BaseCommand } from "../command"; +import { SendCommand } from "../../shared/send"; import { WalletCommand } from "../make/wallets"; -export class TransferCommand extends BaseCommand { +export class TransferCommand extends SendCommand { public static description: string = "send multiple transactions"; public static flags = { - ...BaseCommand.flagsSend, + ...SendCommand.flagsSend, recipient: flags.string({ description: "recipient address", }), @@ -15,28 +15,15 @@ export class TransferCommand extends BaseCommand { }), }; - public async run(): Promise { - const { flags } = await this.make(TransferCommand); - - // Prepare... - const wallets = await WalletCommand.run([`--quantity=${flags.number}`].concat(this.castFlags(flags))); - - // Sign... - const transactions = this.signTransactions(flags, wallets); - - // Expect... - await this.expectBalances(transactions, wallets); - - // Send... - await this.broadcastTransactions(transactions); - - // Verify... - await this.verifyTransactions(transactions, wallets); + protected getCommand(): any { + return TransferCommand; + } - return wallets; + protected async createWalletsWithBalance(flags: Record): Promise { + return WalletCommand.run([`--quantity=${flags.number}`].concat(this.castFlags(flags))); } - protected signTransactions(flags: Record, wallets: Record) { + protected async signTransactions(flags: Record, wallets: Record): Promise { const transactions = []; for (const wallet of Object.keys(wallets)) { @@ -46,14 +33,14 @@ export class TransferCommand extends BaseCommand { return transactions; } - private async expectBalances(transactions, wallets) { + protected async expectBalances(transactions, wallets): Promise { for (const transaction of transactions) { const currentBalance = await this.getWalletBalance(transaction.recipientId); wallets[transaction.recipientId].expectedBalance = currentBalance.plus(transaction.amount); } } - private async verifyTransactions(transactions, wallets) { + protected async verifyTransactions(transactions, wallets): Promise { for (const transaction of transactions) { const wasCreated = await this.knockTransaction(transaction.id); diff --git a/packages/core-tester-cli/src/commands/send/vote.ts b/packages/core-tester-cli/src/commands/send/vote.ts index 8a0f0d04da..d02f1c4306 100644 --- a/packages/core-tester-cli/src/commands/send/vote.ts +++ b/packages/core-tester-cli/src/commands/send/vote.ts @@ -1,44 +1,31 @@ import { Address } from "@arkecosystem/crypto"; import { satoshiFlag } from "../../flags"; import { logger } from "../../logger"; -import { BaseCommand } from "../command"; +import { SendCommand } from "../../shared/send"; import { TransferCommand } from "./transfer"; -export class VoteCommand extends BaseCommand { - public static description: string = "send multiple transactions"; +export class VoteCommand extends SendCommand { + public static description: string = "create multiple votes for a delegate"; public static flags = { - ...BaseCommand.flagsSend, + ...SendCommand.flagsSend, voteFee: satoshiFlag({ description: "vote fee", default: 1, }), }; - public async run(): Promise { - const { flags } = await this.make(VoteCommand); + protected getCommand(): any { + return VoteCommand; + } - // Prepare... - const wallets = await TransferCommand.run( + protected async createWalletsWithBalance(flags: Record): Promise { + return TransferCommand.run( [`--amount=${flags.voteFee}`, `--number=${flags.number}`].concat(this.castFlags(flags)), ); - - // Sign... - const transactions = await this.signTransactions(flags, wallets); - - // Expect... - await this.expectBalances(transactions, wallets); - - // Send... - await this.broadcastTransactions(transactions); - - // Verify... - await this.verifyTransactions(transactions, wallets); - - return wallets; } - protected async signTransactions(flags: Record, wallets: Record) { + protected async signTransactions(flags: Record, wallets: Record): Promise { const transactions = []; for (const [address, wallet] of Object.entries(wallets)) { @@ -60,7 +47,7 @@ export class VoteCommand extends BaseCommand { return transactions; } - private async expectBalances(transactions, wallets) { + protected async expectBalances(transactions, wallets): Promise { for (const transaction of transactions) { const recipientId = Address.fromPublicKey(transaction.senderPublicKey, this.network.version); @@ -69,7 +56,7 @@ export class VoteCommand extends BaseCommand { } } - private async verifyTransactions(transactions, wallets) { + protected async verifyTransactions(transactions, wallets): Promise { for (const transaction of transactions) { const wasCreated = await this.knockTransaction(transaction.id); diff --git a/packages/core-tester-cli/src/shared/send.ts b/packages/core-tester-cli/src/shared/send.ts new file mode 100644 index 0000000000..a4fe396169 --- /dev/null +++ b/packages/core-tester-cli/src/shared/send.ts @@ -0,0 +1,36 @@ +import { BaseCommand } from "../commands/command"; + +export abstract class SendCommand extends BaseCommand { + public async run(): Promise { + // Parse... + const { flags } = await this.make(this.getCommand()); + + // Prepare... + const wallets = await this.createWalletsWithBalance(flags); + + // Sign... + const transactions = await this.signTransactions(flags, wallets); + + // Expect... + await this.expectBalances(transactions, wallets); + + // Send... + await this.broadcastTransactions(transactions); + + // Verify... + await this.verifyTransactions(transactions, wallets); + + // Return... + return wallets; + } + + protected abstract getCommand(): Promise; + + protected abstract async createWalletsWithBalance(flags: Record): Promise; + + protected abstract async signTransactions(flags: Record, wallets: Record): Promise; + + protected abstract async expectBalances(transactions, wallets): Promise; + + protected abstract async verifyTransactions(transactions, wallets): Promise; +} From 725b658693bdcb14bdddf087c7f957770194864c Mon Sep 17 00:00:00 2001 From: Brian Faust Date: Tue, 26 Feb 2019 07:43:13 +0200 Subject: [PATCH 11/18] feat(core-tester-cli): add skipProbing flag --- packages/core-tester-cli/src/commands/command.ts | 3 +++ packages/core-tester-cli/src/shared/send.ts | 8 ++++++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/packages/core-tester-cli/src/commands/command.ts b/packages/core-tester-cli/src/commands/command.ts index ad9b5dbb2c..e8f19088b4 100644 --- a/packages/core-tester-cli/src/commands/command.ts +++ b/packages/core-tester-cli/src/commands/command.ts @@ -45,6 +45,9 @@ export abstract class BaseCommand extends Command { description: "transfer fee", default: 0.1, }), + skipProbing: flags.boolean({ + description: "skip transaction probing", + }), }; public static flagsDebug = { diff --git a/packages/core-tester-cli/src/shared/send.ts b/packages/core-tester-cli/src/shared/send.ts index a4fe396169..03013e3d82 100644 --- a/packages/core-tester-cli/src/shared/send.ts +++ b/packages/core-tester-cli/src/shared/send.ts @@ -12,13 +12,17 @@ export abstract class SendCommand extends BaseCommand { const transactions = await this.signTransactions(flags, wallets); // Expect... - await this.expectBalances(transactions, wallets); + if (!flags.skipProbing) { + await this.expectBalances(transactions, wallets); + } // Send... await this.broadcastTransactions(transactions); // Verify... - await this.verifyTransactions(transactions, wallets); + if (!flags.skipProbing) { + await this.verifyTransactions(transactions, wallets); + } // Return... return wallets; From fa458eed1068e56c78beab04c6efb4b489ebf595 Mon Sep 17 00:00:00 2001 From: Brian Faust Date: Tue, 26 Feb 2019 09:07:34 +0200 Subject: [PATCH 12/18] test(core-tester-cli): fix failing tests --- .../commands/delegate-registration.test.ts | 45 ++++------ .../commands/second-signature.test.ts | 39 ++++----- .../__tests__/commands/transfer.test.ts | 86 +++++++------------ .../__tests__/commands/vote.test.ts | 70 ++++++--------- packages/core-tester-cli/__tests__/shared.ts | 24 +++++- .../core-tester-cli/__tests__/utils.test.ts | 33 ------- .../core-tester-cli/src/commands/command.ts | 7 +- .../commands/send/delegate-registration.ts | 4 +- .../send/second-signature-registration.ts | 4 +- .../src/commands/send/transfer.ts | 15 +++- .../core-tester-cli/src/commands/send/vote.ts | 8 +- packages/core-tester-cli/src/http-client.ts | 10 +-- 12 files changed, 147 insertions(+), 198 deletions(-) delete mode 100644 packages/core-tester-cli/__tests__/utils.test.ts diff --git a/packages/core-tester-cli/__tests__/commands/delegate-registration.test.ts b/packages/core-tester-cli/__tests__/commands/delegate-registration.test.ts index 4fd7f335bc..609e253030 100644 --- a/packages/core-tester-cli/__tests__/commands/delegate-registration.test.ts +++ b/packages/core-tester-cli/__tests__/commands/delegate-registration.test.ts @@ -2,10 +2,9 @@ import "jest-extended"; import axios from "axios"; import MockAdapter from "axios-mock-adapter"; -import superheroes from "superheroes"; -import { DelegateRegistrationCommand } from "../../src/commands/delegate-registration"; -import { arkToSatoshi } from "../../src/utils"; -import { toFlags } from "../shared"; +import pokemon from "pokemon"; +import { DelegateRegistrationCommand } from "../../src/commands/send/delegate-registration"; +import { arkToSatoshi, captureTransactions, expectTransactions, toFlags } from "../shared"; const mockAxios = new MockAdapter(axios); @@ -34,28 +33,22 @@ describe("Commands - Delegate Registration", () => { meta: { pageCount: 1 }, data: [], }); - jest.spyOn(superheroes, "random").mockImplementation(() => expectedDelegateName); - - mockAxios.onPost("http://localhost:4003/api/v2/transactions").reply(200, { data: {} }); - - const flags = toFlags(opts); - await DelegateRegistrationCommand.run(flags); - - expect(axios.post).toHaveBeenCalledWith( - "http://localhost:4003/api/v2/transactions", - { - transactions: [ - expect.objectContaining({ - fee: arkToSatoshi(opts.delegateFee), - asset: { - delegate: { - username: expectedDelegateName, - }, - }, - }), - ], + jest.spyOn(pokemon, "random").mockImplementation(() => expectedDelegateName); + + const expectedTransactions = []; + captureTransactions(mockAxios, expectedTransactions); + + await DelegateRegistrationCommand.run(toFlags(opts)); + + expect(axios.post).toHaveBeenCalledTimes(2); + + expectTransactions(expectedTransactions, { + fee: arkToSatoshi(opts.delegateFee), + asset: { + delegate: { + username: expectedDelegateName, + }, }, - expect.any(Object), - ); + }); }); }); diff --git a/packages/core-tester-cli/__tests__/commands/second-signature.test.ts b/packages/core-tester-cli/__tests__/commands/second-signature.test.ts index cb600ec464..3fb6737b27 100644 --- a/packages/core-tester-cli/__tests__/commands/second-signature.test.ts +++ b/packages/core-tester-cli/__tests__/commands/second-signature.test.ts @@ -2,9 +2,8 @@ import "jest-extended"; import axios from "axios"; import MockAdapter from "axios-mock-adapter"; -import { SecondSignatureCommand } from "../../src/commands/second-signature"; -import { arkToSatoshi } from "../../src/utils"; -import { toFlags } from "../shared"; +import { SecondSignatureRegistrationCommand } from "../../src/commands/send/second-signature-registration"; +import { arkToSatoshi, captureTransactions, expectTransactions, toFlags } from "../shared"; const mockAxios = new MockAdapter(axios); @@ -27,26 +26,20 @@ describe("Commands - Second signature", () => { number: 1, }; - mockAxios.onPost("http://localhost:4003/api/v2/transactions").reply(200, { data: {} }); - - const flags = toFlags(opts); - await SecondSignatureCommand.run(flags); - - expect(axios.post).toHaveBeenCalledWith( - "http://localhost:4003/api/v2/transactions", - { - transactions: [ - expect.objectContaining({ - fee: arkToSatoshi(opts.signatureFee), - asset: { - signature: { - publicKey: expect.any(String), - }, - }, - }), - ], + const expectedTransactions = []; + captureTransactions(mockAxios, expectedTransactions); + + await SecondSignatureRegistrationCommand.run(toFlags(opts)); + + expect(axios.post).toHaveBeenCalledTimes(2); + + expectTransactions(expectedTransactions, { + fee: arkToSatoshi(opts.signatureFee), + asset: { + signature: { + publicKey: expect.any(String), + }, }, - expect.any(Object), - ); + }); }); }); diff --git a/packages/core-tester-cli/__tests__/commands/transfer.test.ts b/packages/core-tester-cli/__tests__/commands/transfer.test.ts index 4a0c9ddb31..af56d35e48 100644 --- a/packages/core-tester-cli/__tests__/commands/transfer.test.ts +++ b/packages/core-tester-cli/__tests__/commands/transfer.test.ts @@ -2,9 +2,8 @@ import "jest-extended"; import axios from "axios"; import MockAdapter from "axios-mock-adapter"; -import { TransferCommand } from "../../src/commands/transfer"; -import { arkToSatoshi } from "../../src/utils"; -import { toFlags } from "../shared"; +import { TransferCommand } from "../../src/commands/send/transfer"; +import { arkToSatoshi, captureTransactions, expectTransactions, toFlags } from "../shared"; const mockAxios = new MockAdapter(axios); @@ -26,56 +25,42 @@ describe("Commands - Transfer", () => { it("should postTransactions using custom smartBridge value", async () => { const expectedRecipientId = "DFyUhQW52sNB5PZdS7VD9HknwYrSNHPQDq"; const expectedTransactionAmount = 2; - const expectedFee = arkToSatoshi(0.1); + const expectedFee = 0.1; const opts = { amount: expectedTransactionAmount, transferFee: expectedFee, number: 1, - smartBridge: "foo bar", + vendorField: "foo bar", recipient: expectedRecipientId, }; - mockAxios.onPost("http://localhost:4003/api/v2/transactions").reply(200, { data: {} }); - let expectedTransactions = []; - // @ts-ignore - jest.spyOn(axios, "post").mockImplementation((uri, { transactions }) => { - expectedTransactions = transactions; - }); + const expectedTransactions = []; + captureTransactions(mockAxios, expectedTransactions); + + await TransferCommand.run(toFlags(opts)); - const flags = toFlags(opts); - await TransferCommand.run(flags); - - expect(expectedTransactions).toEqual( - expect.arrayContaining([ - expect.objectContaining({ - vendorField: "foo bar", - amount: arkToSatoshi(expectedTransactionAmount), - fee: arkToSatoshi(expectedFee), - recipientId: expectedRecipientId, - }), - ]), - ); + expectTransactions(expectedTransactions, { + vendorField: "foo bar", + amount: arkToSatoshi(expectedTransactionAmount), + fee: arkToSatoshi(expectedFee), + recipientId: expectedRecipientId, + }); }); it("should generate n transactions", async () => { const expectedTxCount = 5; const expectedRecipientId = "DFyUhQW52sNB5PZdS7VD9HknwYrSNHPQDq"; const opts = { - amount: arkToSatoshi(2), - transferFee: arkToSatoshi(2), + amount: 2, + transferFee: 2, number: expectedTxCount, recipient: expectedRecipientId, }; - mockAxios.onPost("http://localhost:4003/api/v2/transactions").reply(200, { data: {} }); - let expectedTransactions = []; - // @ts-ignore - jest.spyOn(axios, "post").mockImplementation((uri, { transactions }) => { - expectedTransactions = transactions; - }); + const expectedTransactions = []; + captureTransactions(mockAxios, expectedTransactions); - const flags = toFlags(opts); - await TransferCommand.run(flags); + await TransferCommand.run(toFlags(opts)); expect(expectedTransactions).toHaveLength(expectedTxCount); for (const t of expectedTransactions) { @@ -89,21 +74,16 @@ describe("Commands - Transfer", () => { const expectedTxCount = 10; const expectedRecipientId = "DFyUhQW52sNB5PZdS7VD9HknwYrSNHPQDq"; const opts = { - amount: arkToSatoshi(2), - transferFee: arkToSatoshi(0.1), + amount: 2, + transferFee: 0.1, number: expectedTxCount, recipient: expectedRecipientId, }; - mockAxios.onPost("http://localhost:4003/api/v2/transactions").reply(200, { data: {} }); - let expectedTransactions = []; - // @ts-ignore - jest.spyOn(axios, "post").mockImplementation((uri, { transactions }) => { - expectedTransactions = transactions; - }); + const expectedTransactions = []; + captureTransactions(mockAxios, expectedTransactions); - const flags = toFlags(opts); - await TransferCommand.run(flags); + await TransferCommand.run(toFlags(opts)); expect(expectedTransactions).toHaveLength(expectedTxCount); for (const t of expectedTransactions) { @@ -112,8 +92,8 @@ describe("Commands - Transfer", () => { }); it("should sign with 2nd passphrase if specified", async () => { - const expectedTransactionAmount = arkToSatoshi(2); - const expectedFee = arkToSatoshi(0.1); + const expectedTransactionAmount = 2; + const expectedFee = 0.1; const expectedRecipientId = "DFyUhQW52sNB5PZdS7VD9HknwYrSNHPQDq"; const opts = { @@ -124,20 +104,14 @@ describe("Commands - Transfer", () => { recipient: expectedRecipientId, }; - mockAxios.onPost("http://localhost:4003/api/v2/transactions").reply(200, { data: {} }); - let expectedTransactions = []; - // @ts-ignore - jest.spyOn(axios, "post").mockImplementation((uri, { transactions }) => { - expectedTransactions = transactions; - }); + const expectedTransactions = []; + captureTransactions(mockAxios, expectedTransactions); - const flags = toFlags(opts); - await TransferCommand.run(flags); + await TransferCommand.run(toFlags(opts)); expect(expectedTransactions).toHaveLength(1); for (const t of expectedTransactions) { - expect(t.secondSignature).toBeDefined(); - expect(t.signSignature).toEqual(t.secondSignature); + expect(t.signSignature).toBeDefined(); } }); }); diff --git a/packages/core-tester-cli/__tests__/commands/vote.test.ts b/packages/core-tester-cli/__tests__/commands/vote.test.ts index 0488bdc1eb..886d30c2dd 100644 --- a/packages/core-tester-cli/__tests__/commands/vote.test.ts +++ b/packages/core-tester-cli/__tests__/commands/vote.test.ts @@ -2,9 +2,8 @@ import "jest-extended"; import axios from "axios"; import MockAdapter from "axios-mock-adapter"; -import { VoteCommand } from "../../src/commands/vote"; -import { arkToSatoshi } from "../../src/utils"; -import { toFlags } from "../shared"; +import { VoteCommand } from "../../src/commands/send/vote"; +import { arkToSatoshi, captureTransactions, expectTransactions, toFlags } from "../shared"; const mockAxios = new MockAdapter(axios); @@ -18,6 +17,7 @@ beforeEach(() => { afterEach(() => { mockAxios.reset(); + jest.restoreAllMocks(); }); afterAll(() => mockAxios.restore()); @@ -31,59 +31,45 @@ describe("Commands - Vote", () => { delegate: expectedDelegate, }; - mockAxios.onGet(/http:\/\/localhost:4003\/api\/v2\/delegates.*/).reply(200); - mockAxios.onPost("http://localhost:4003/api/v2/transactions").reply(200, { data: {} }); - - const flags = toFlags(opts); - await VoteCommand.run(flags); - - expect(axios.post).toHaveBeenCalledWith( - "http://localhost:4003/api/v2/transactions", - { - transactions: [ - expect.objectContaining({ - fee: arkToSatoshi(opts.voteFee), - asset: { - votes: [`+${expectedDelegate}`], - }, - }), - ], + const expectedTransactions = []; + captureTransactions(mockAxios, expectedTransactions); + + await VoteCommand.run(toFlags(opts)); + + expect(axios.post).toHaveBeenCalledTimes(2); + + expectTransactions(expectedTransactions, { + fee: arkToSatoshi(opts.voteFee), + asset: { + votes: [`+${expectedDelegate}`], }, - expect.any(Object), - ); + }); }); it("should vote random delegate if non specified", async () => { - const expectedDelegate = "03f294777f7376e970b2bd4805b4a90c8449b5935d530bdb566d02800ac44a4c00"; + const expectedDelegate = "03287bfebba4c7881a0509717e71b34b63f31e40021c321f89ae04f84be6d6ac37"; const opts = { number: 1, voteFee: 1, }; - mockAxios.onPost("http://localhost:4003/api/v2/transactions").reply(200, { data: {} }); - mockAxios.onGet(/http:\/\/localhost:4003\/api\/v2\/delegates\/.*/).reply(200); // call to delegates/{publicKey}/voters - // call to /delegates mockAxios.onGet(/http:\/\/localhost:4003\/api\/v2\/delegates/).reply(200, { meta: { pageCount: 1 }, data: [{ publicKey: expectedDelegate }], }); - const flags = toFlags(opts); - await VoteCommand.run(flags); - - expect(axios.post).toHaveBeenCalledWith( - "http://localhost:4003/api/v2/transactions", - { - transactions: [ - expect.objectContaining({ - fee: arkToSatoshi(opts.voteFee), - asset: { - votes: [`+${expectedDelegate}`], - }, - }), - ], + const expectedTransactions = []; + captureTransactions(mockAxios, expectedTransactions); + + await VoteCommand.run(toFlags(opts)); + + expect(axios.post).toHaveBeenCalledTimes(2); + + expectTransactions(expectedTransactions, { + fee: arkToSatoshi(opts.voteFee), + asset: { + votes: [`+${expectedDelegate}`], }, - expect.any(Object), - ); + }); }); }); diff --git a/packages/core-tester-cli/__tests__/shared.ts b/packages/core-tester-cli/__tests__/shared.ts index 1562862cb6..a9a6e26131 100644 --- a/packages/core-tester-cli/__tests__/shared.ts +++ b/packages/core-tester-cli/__tests__/shared.ts @@ -1,7 +1,29 @@ -const defaultOpts = ["--skipTesting", "--skipValidation"]; +import { bignumify } from "@arkecosystem/core-utils"; +import axios from "axios"; + +const defaultOpts = ["--skipProbing"]; export const toFlags = (opts: object): string[] => { return Object.keys(opts) .map(k => [`--${k}`, String(opts[k])]) .reduce((a, b) => a.concat(b), defaultOpts); }; + +export const arkToSatoshi = value => + bignumify(value) + .times(1e8) + .toFixed(); + +export const expectTransactions = (transactions, obj) => + expect(transactions).toEqual(expect.arrayContaining([expect.objectContaining(obj)])); + +export const captureTransactions = (mockAxios, expectedTransactions) => { + mockAxios.onPost("http://localhost:4003/api/v2/transactions").reply(200, { data: {} }); + + // @ts-ignore + jest.spyOn(axios, "post").mockImplementation((uri, { transactions }) => { + for (const transaction of transactions) { + expectedTransactions.push(transaction); + } + }); +}; diff --git a/packages/core-tester-cli/__tests__/utils.test.ts b/packages/core-tester-cli/__tests__/utils.test.ts deleted file mode 100644 index eac906a633..0000000000 --- a/packages/core-tester-cli/__tests__/utils.test.ts +++ /dev/null @@ -1,33 +0,0 @@ -import { arkToSatoshi, parseFee, satoshiToArk } from "../src/utils"; - -describe("Utils", () => { - describe("parseFee", () => { - it("should give satoshi", () => { - expect(parseFee(0.1).toString()).toBe("10000000"); - expect(parseFee(1).toString()).toBe("100000000"); - expect(parseFee(10).toString()).toBe("1000000000"); - expect(parseFee("0.1").toString()).toBe("10000000"); - expect(parseFee("1").toString()).toBe("100000000"); - expect(parseFee("10").toString()).toBe("1000000000"); - expect(parseFee("0.001-0.005").toNumber()).toBeWithin(100000, 500000); - }); - }); - - describe("arkToSatoshi", () => { - it("should give satoshi", () => { - expect(arkToSatoshi(0.00000001).toString()).toBe("1"); - expect(arkToSatoshi(0.1).toString()).toBe("10000000"); - expect(arkToSatoshi(1).toString()).toBe("100000000"); - expect(arkToSatoshi(10).toString()).toBe("1000000000"); - }); - }); - - describe("satoshiToArk", () => { - it("should give ark", () => { - expect(satoshiToArk(1)).toBe("0.00000001 DѦ"); - expect(satoshiToArk(10000000)).toBe("0.1 DѦ"); - expect(satoshiToArk(100000000)).toBe("1 DѦ"); - expect(satoshiToArk(1000000000)).toBe("10 DѦ"); - }); - }); -}); diff --git a/packages/core-tester-cli/src/commands/command.ts b/packages/core-tester-cli/src/commands/command.ts index e8f19088b4..159973d879 100644 --- a/packages/core-tester-cli/src/commands/command.ts +++ b/packages/core-tester-cli/src/commands/command.ts @@ -138,12 +138,7 @@ export abstract class BaseCommand extends Command { } protected async broadcastTransactions(transactions) { - const sendTransactions = []; - for (const transaction of transactions) { - sendTransactions.push(this.sendTransaction(transaction)); - } - - await Promise.all(sendTransactions); + await this.sendTransaction(transactions); return this.awaitConfirmations(transactions); } diff --git a/packages/core-tester-cli/src/commands/send/delegate-registration.ts b/packages/core-tester-cli/src/commands/send/delegate-registration.ts index 90bd7a022b..af3f8f0f5e 100644 --- a/packages/core-tester-cli/src/commands/send/delegate-registration.ts +++ b/packages/core-tester-cli/src/commands/send/delegate-registration.ts @@ -22,7 +22,9 @@ export class DelegateRegistrationCommand extends SendCommand { protected async createWalletsWithBalance(flags: Record): Promise { return TransferCommand.run( - [`--amount=${flags.delegateFee}`, `--number=${flags.number}`].concat(this.castFlags(flags)), + [`--amount=${flags.delegateFee}`, `--number=${flags.number}`, "--skipProbing"].concat( + this.castFlags(flags), + ), ); } diff --git a/packages/core-tester-cli/src/commands/send/second-signature-registration.ts b/packages/core-tester-cli/src/commands/send/second-signature-registration.ts index 18c5bfe474..cd0adcd96d 100644 --- a/packages/core-tester-cli/src/commands/send/second-signature-registration.ts +++ b/packages/core-tester-cli/src/commands/send/second-signature-registration.ts @@ -21,7 +21,9 @@ export class SecondSignatureRegistrationCommand extends SendCommand { protected async createWalletsWithBalance(flags: Record): Promise { return TransferCommand.run( - [`--amount=${flags.signatureFee}`, `--number=${flags.number}`].concat(this.castFlags(flags)), + [`--amount=${flags.signatureFee}`, `--number=${flags.number}`, "--skipProbing"].concat( + this.castFlags(flags), + ), ); } diff --git a/packages/core-tester-cli/src/commands/send/transfer.ts b/packages/core-tester-cli/src/commands/send/transfer.ts index 3ec4cfb029..b893ce07b3 100644 --- a/packages/core-tester-cli/src/commands/send/transfer.ts +++ b/packages/core-tester-cli/src/commands/send/transfer.ts @@ -1,4 +1,5 @@ import { flags } from "@oclif/command"; +import { delay } from "bluebird"; import { SendCommand } from "../../shared/send"; import { WalletCommand } from "../make/wallets"; @@ -26,8 +27,18 @@ export class TransferCommand extends SendCommand { protected async signTransactions(flags: Record, wallets: Record): Promise { const transactions = []; - for (const wallet of Object.keys(wallets)) { - transactions.push(this.signer.makeTransfer({ ...flags, ...{ recipient: wallet } })); + for (let i = 0; i < flags.number; i++) { + const vendorField = flags.vendorField || `Transaction ${i}`; + + if (flags.recipient) { + transactions.push( + this.signer.makeTransfer({ ...flags, ...{ recipient: flags.recipient, vendorField } }), + ); + } else { + for (const wallet of Object.keys(wallets)) { + transactions.push(this.signer.makeTransfer({ ...flags, ...{ recipient: wallet, vendorField } })); + } + } } return transactions; diff --git a/packages/core-tester-cli/src/commands/send/vote.ts b/packages/core-tester-cli/src/commands/send/vote.ts index d02f1c4306..1dcaad6463 100644 --- a/packages/core-tester-cli/src/commands/send/vote.ts +++ b/packages/core-tester-cli/src/commands/send/vote.ts @@ -1,4 +1,5 @@ import { Address } from "@arkecosystem/crypto"; +import { flags } from "@oclif/command"; import { satoshiFlag } from "../../flags"; import { logger } from "../../logger"; import { SendCommand } from "../../shared/send"; @@ -9,6 +10,9 @@ export class VoteCommand extends SendCommand { public static flags = { ...SendCommand.flagsSend, + delegate: flags.string({ + description: "delegate public key", + }), voteFee: satoshiFlag({ description: "vote fee", default: 1, @@ -21,7 +25,7 @@ export class VoteCommand extends SendCommand { protected async createWalletsWithBalance(flags: Record): Promise { return TransferCommand.run( - [`--amount=${flags.voteFee}`, `--number=${flags.number}`].concat(this.castFlags(flags)), + [`--amount=${flags.voteFee}`, `--number=${flags.number}`, "--skipProbing"].concat(this.castFlags(flags)), ); } @@ -29,7 +33,7 @@ export class VoteCommand extends SendCommand { const transactions = []; for (const [address, wallet] of Object.entries(wallets)) { - const delegate = await this.getRandomDelegate(); + const delegate = flags.delegate || (await this.getRandomDelegate()); const transaction = this.signer.makeVote({ ...flags, diff --git a/packages/core-tester-cli/src/http-client.ts b/packages/core-tester-cli/src/http-client.ts index 0bf6cc858a..f0bc539481 100644 --- a/packages/core-tester-cli/src/http-client.ts +++ b/packages/core-tester-cli/src/http-client.ts @@ -1,15 +1,15 @@ -import Axios from "axios"; +import axios from "axios"; export class HttpClient { - private instance: any; + private baseURL: any; public constructor(baseURL: string) { - this.instance = Axios.create({ baseURL }); + this.baseURL = baseURL; } public async get(path: string, params?: Record, headers?: Record): Promise { try { - const { data } = await this.instance.get(path, { params, headers }); + const { data } = await axios.get(`${this.baseURL}${path}`, { params, headers }); return data; } catch (error) { @@ -19,7 +19,7 @@ export class HttpClient { public async post(path: string, payload: Record): Promise { try { - const { data } = await this.instance.post(path, payload); + const { data } = await axios.post(`${this.baseURL}${path}`, payload); return data; } catch (error) { From 25b24e98af03c28950a56713bfd8065b69baa8c1 Mon Sep 17 00:00:00 2001 From: Brian Faust Date: Tue, 26 Feb 2019 09:48:43 +0200 Subject: [PATCH 13/18] fix(core-tester-cli): get debugger cli commands working --- .../__tests__/server/internal.test.ts | 2 +- .../__tests__/__fixtures__/block.json | 140 ++++++++++++++++++ .../__tests__/__fixtures__/identities.json | 6 + .../__fixtures__/transaction-second.json | 15 ++ .../__tests__/__fixtures__/transaction.json | 14 ++ .../commands/debug/deserialize.test.ts | 60 ++++++++ .../__tests__/commands/debug/identity.test.ts | 43 ++++++ .../commands/debug/serialize.test.ts | 26 ++++ .../commands/debug/verify-second.test.ts | 18 +++ .../__tests__/commands/debug/verify.test.ts | 16 ++ .../{ => send}/delegate-registration.test.ts | 4 +- .../{ => send}/second-signature.test.ts | 4 +- .../commands/{ => send}/transfer.test.ts | 4 +- .../commands/{ => send}/vote.test.ts | 4 +- .../src/commands/debug/deserialize.ts | 2 +- .../src/commands/debug/identity.ts | 2 +- .../src/commands/debug/serialize.ts | 2 +- .../commands/debug/verify-second-signature.ts | 2 +- .../src/commands/debug/verify.ts | 1 - 19 files changed, 351 insertions(+), 14 deletions(-) create mode 100644 packages/core-tester-cli/__tests__/__fixtures__/block.json create mode 100644 packages/core-tester-cli/__tests__/__fixtures__/identities.json create mode 100644 packages/core-tester-cli/__tests__/__fixtures__/transaction-second.json create mode 100644 packages/core-tester-cli/__tests__/__fixtures__/transaction.json create mode 100644 packages/core-tester-cli/__tests__/commands/debug/deserialize.test.ts create mode 100644 packages/core-tester-cli/__tests__/commands/debug/identity.test.ts create mode 100644 packages/core-tester-cli/__tests__/commands/debug/serialize.test.ts create mode 100644 packages/core-tester-cli/__tests__/commands/debug/verify-second.test.ts create mode 100644 packages/core-tester-cli/__tests__/commands/debug/verify.test.ts rename packages/core-tester-cli/__tests__/commands/{ => send}/delegate-registration.test.ts (93%) rename packages/core-tester-cli/__tests__/commands/{ => send}/second-signature.test.ts (90%) rename packages/core-tester-cli/__tests__/commands/{ => send}/transfer.test.ts (97%) rename packages/core-tester-cli/__tests__/commands/{ => send}/vote.test.ts (96%) diff --git a/packages/core-p2p/__tests__/server/internal.test.ts b/packages/core-p2p/__tests__/server/internal.test.ts index 456adb707e..bf8bf22f2c 100644 --- a/packages/core-p2p/__tests__/server/internal.test.ts +++ b/packages/core-p2p/__tests__/server/internal.test.ts @@ -1,6 +1,6 @@ import { generateTransfers } from "@arkecosystem/core-test-utils/src/generators/transactions/transfer"; import { models } from "@arkecosystem/crypto"; -import blockFixture from "../../../core-debugger-cli/__tests__/__fixtures__/block.json"; +import blockFixture from "../../../core-tester-cli/__tests__/__fixtures__/block.json"; import { setUp, tearDown } from "../__support__/setup"; import { utils } from "../__support__/utils"; diff --git a/packages/core-tester-cli/__tests__/__fixtures__/block.json b/packages/core-tester-cli/__tests__/__fixtures__/block.json new file mode 100644 index 0000000000..d1228aa285 --- /dev/null +++ b/packages/core-tester-cli/__tests__/__fixtures__/block.json @@ -0,0 +1,140 @@ +{ + "data": { + "id": "7176646138626297930", + "version": 0, + "height": 2243161, + "timestamp": 24760440, + "previousBlock": "3112633353705641986", + "numberOfTransactions": 7, + "totalAmount": "3890300", + "totalFee": "70000000", + "reward": "200000000", + "payloadLength": 224, + "payloadHash": "3784b953afcf936bdffd43fdf005b5732b49c1fc6b11e195c364c20b2eb06282", + "generatorPublicKey": "020f5df4d2bc736d12ce43af5b1663885a893fade7ee5e62b3cc59315a63e6a325", + "blockSignature": "3045022100eee6c37b5e592e99811d588532726353592923f347c701d52912e6d583443e400220277ffe38ad31e216ba0907c4738fed19b2071246b150c72c0a52bae4477ebe29", + "transactions": [ + { + "type": 0, + "amount": 555760, + "fee": 10000000, + "recipientId": "DB4gFuDztmdGALMb8i1U4Z4R5SktxpNTAY", + "timestamp": 24760418, + "asset": {}, + "vendorField": "Goose Voter - True Block Weight", + "senderPublicKey": "0265c1f6b8c1966a90f3fed7bc32fd4f42238ab4938fdb2a4e7ddd01ae8b58b4c0", + "signature": "304402204f12469157b19edd06ba25fcad3d4a5ef5b057c23f9e02de4641e6f8eef0553e022010121ab282f83efe1043de9c16bbf2c6845a03684229a0d7c965ffb9abdfb978", + "signSignature": "30450221008327862f0b9178d6665f7d6674978c5caf749649558d814244b1c66cdf945c40022015918134ef01fed3fe2a2efde3327917731344332724522c75c2799a14f78717", + "id": "170543154a3b79459cbaa529f9f62b6f1342682799eb549dbf09fcca2d1f9c11", + "senderId": "DB8LnnQqYvHpG4WkGJ9AJWBYEct7G3yRZg", + "hop": 2, + "broadcast": false, + "blockId": "7176646138626297930" + }, + { + "type": 0, + "amount": 555750, + "fee": 10000000, + "recipientId": "DGExsNogZR7JFa2656ZFP9TMWJYJh5djzQ", + "timestamp": 24760416, + "asset": {}, + "vendorField": "Goose Voter - True Block Weight", + "senderPublicKey": "0265c1f6b8c1966a90f3fed7bc32fd4f42238ab4938fdb2a4e7ddd01ae8b58b4c0", + "signature": "304402205f82feb8c5d1d79c565c2ff7badb93e4c9827b132d135dda11cb25427d4ef8ac02205ff136f970533c4ec4c7d0cd1ea7e02d7b62629b66c6c93265f608d7f2389727", + "signSignature": "304402207e912031fcc700d8a55fbc415993302a0d8e6aea128397141b640b6dba52331702201fd1ad3984e42af44f548907add6cb7ad72ca0070c8cc1d8dc9bbda208c56bd9", + "id": "1da153f37eceda233ff1b407ac18e47b3cae47c14cdcd5297d929618a916c4a7", + "senderId": "DB8LnnQqYvHpG4WkGJ9AJWBYEct7G3yRZg", + "hop": 2, + "broadcast": false, + "blockId": "7176646138626297930" + }, + { + "type": 0, + "amount": 555770, + "fee": 10000000, + "recipientId": "DHGK5np6LuMMErfRfC5CmjpGu3ME85c25n", + "timestamp": 24760420, + "asset": {}, + "vendorField": "Goose Voter - True Block Weight", + "senderPublicKey": "0265c1f6b8c1966a90f3fed7bc32fd4f42238ab4938fdb2a4e7ddd01ae8b58b4c0", + "signature": "304502210083216e6969e068770e6d2fe5c244881002309df84d20290ddf3f858967ed010202202a479b3da5080ea475d310ff13494654b42db75886a8808bd211b4bdb9146a7a", + "signSignature": "3045022100e1dcab3406bbeb968146a4a391909ce41df9b71592a753b001e7c2ee1d382c5102202a74aeafd4a152ec61854636fbae829c41f1416c1e0637a0809408394973099f", + "id": "1e255f07dc25ce22d900ea81663c8f00d05a7b7c061e6fc3c731b05d642fa0b9", + "senderId": "DB8LnnQqYvHpG4WkGJ9AJWBYEct7G3yRZg", + "hop": 2, + "broadcast": false, + "blockId": "7176646138626297930" + }, + { + "type": 0, + "amount": 555750, + "fee": 10000000, + "recipientId": "D7pcLJNGe197ibmWEmT8mM9KKU1htrcDyW", + "timestamp": 24760417, + "asset": {}, + "vendorField": "Goose Voter - True Block Weight", + "senderPublicKey": "0265c1f6b8c1966a90f3fed7bc32fd4f42238ab4938fdb2a4e7ddd01ae8b58b4c0", + "signature": "3045022100cd4fa9855227be11e17201419dacfbbd5d9946df8d6792a9488160025693821402207fb83969bad6a26959f437b5bb88e255b0a48eb04964d0c0d29f7ee94bd15e11", + "signSignature": "304402205f50c2991a17743d17ffbb09159cadc35a3f848044261842879ccf5be9d81c5e022023bf21c32fb6e94494104f15f8d3a942ab120d0abd6fb4c93790b68e1b307a79", + "id": "66336c61d6ec623f8a1d2fd156a0fac16a4fe93bb3fba337859355c2119923a8", + "senderId": "DB8LnnQqYvHpG4WkGJ9AJWBYEct7G3yRZg", + "hop": 2, + "broadcast": false, + "blockId": "7176646138626297930" + }, + { + "type": 0, + "amount": 555760, + "fee": 10000000, + "recipientId": "DD4yhwzryQdNGqKtezmycToQv63g27Tqqq", + "timestamp": 24760418, + "asset": {}, + "vendorField": "Goose Voter - True Block Weight", + "senderPublicKey": "0265c1f6b8c1966a90f3fed7bc32fd4f42238ab4938fdb2a4e7ddd01ae8b58b4c0", + "signature": "30450221009c792062e13399ac6756b2e9f137194d06e106360ac0f3e24e55c7249cee0b3602205dc1d9c76d0451d1cb5a2396783a13e6d2d790ccfd49291e3d0a78349f7ea0e8", + "signSignature": "30440220083ba8a9af49b8be6e93794d71ec43ffc96a158375810e5d9f2478e71655315b0220278402ecaa1d224dab9f0f3b28295bbaea339c85c7400edafdc49df87439fc64", + "id": "78db36f7d79f51c67d7210ee3819dfb8d0d47b16a7484ebf55c5a055b17209a3", + "senderId": "DB8LnnQqYvHpG4WkGJ9AJWBYEct7G3yRZg", + "hop": 2, + "broadcast": false, + "blockId": "7176646138626297930" + }, + { + "type": 0, + "amount": 555760, + "fee": 10000000, + "recipientId": "D5LiYGXL5keycWuTF6AFFwSRc6Mt4uEHMu", + "timestamp": 24760419, + "asset": {}, + "vendorField": "Goose Voter - True Block Weight", + "senderPublicKey": "0265c1f6b8c1966a90f3fed7bc32fd4f42238ab4938fdb2a4e7ddd01ae8b58b4c0", + "signature": "3044022063c65263e42be02bd9831b375c1d76a88332f00ed0557ecc1e7d2375ca40070902206797b5932c0bad68444beb5a38daa7cadf536ee2144e0d9777b812284d14374e", + "signSignature": "3045022100b04da6692f75d43229ffd8486c1517e8952d38b4c03dfac38b6b360190a5c33e0220776622e5f09f92a1258b4a011f22181c977b622b8d1bbb2f83b42f4126d00739", + "id": "83c80bb58777bb43f5037544b44ef69f191d3548fd1b2a00bed368f9f0d694c5", + "senderId": "DB8LnnQqYvHpG4WkGJ9AJWBYEct7G3yRZg", + "hop": 2, + "broadcast": false, + "blockId": "7176646138626297930" + }, + { + "type": 0, + "amount": 555750, + "fee": 10000000, + "recipientId": "DPopNLwMvv4zSjdZnqUk8HFH13Mcb7NbEK", + "timestamp": 24760416, + "asset": {}, + "vendorField": "Goose Voter - True Block Weight", + "senderPublicKey": "0265c1f6b8c1966a90f3fed7bc32fd4f42238ab4938fdb2a4e7ddd01ae8b58b4c0", + "signature": "3045022100d4513c3608c2072e38e7a0e3bb8daf2cd5f7cc6fec9a5570dccd1eda696c591902202ecbbf3c9d0757be7b23c8b1cc6481c51600d158756c47fcb6f4a7f4893e31c4", + "signSignature": "304402201fed4858d0806dd32220960900a871dd2f60e1f623af75feef9b1034a9a0a46402205a29b27c63fcc3e1ee1e77ecbbf4dd6e7db09901e7a09b9fd490cd68d62392cb", + "id": "d2faf992fdd5da96d6d15038b6ddb65230338fa2096e45e44da51daad5e2f3ca", + "senderId": "DB8LnnQqYvHpG4WkGJ9AJWBYEct7G3yRZg", + "hop": 2, + "broadcast": false, + "blockId": "7176646138626297930" + } + ] + }, + "serialized": "0000000078d07901593a22002b324b8b33a85802070000007c5c3b0000000000801d2c040000000000c2eb0b00000000e00000003784b953afcf936bdffd43fdf005b5732b49c1fc6b11e195c364c20b2eb06282020f5df4d2bc736d12ce43af5b1663885a893fade7ee5e62b3cc59315a63e6a3253045022100eee6c37b5e592e99811d588532726353592923f347c701d52912e6d583443e400220277ffe38ad31e216ba0907c4738fed19b2071246b150c72c0a52bae4477ebe29", + "serializedFull": "0000000078d07901593a22002b324b8b33a85802070000007c5c3b0000000000801d2c040000000000c2eb0b00000000e00000003784b953afcf936bdffd43fdf005b5732b49c1fc6b11e195c364c20b2eb06282020f5df4d2bc736d12ce43af5b1663885a893fade7ee5e62b3cc59315a63e6a3253045022100eee6c37b5e592e99811d588532726353592923f347c701d52912e6d583443e400220277ffe38ad31e216ba0907c4738fed19b2071246b150c72c0a52bae4477ebe29ff000000fe00000000010000ff000000ff000000ff000000ff000000ff011e0062d079010265c1f6b8c1966a90f3fed7bc32fd4f42238ab4938fdb2a4e7ddd01ae8b58b4c080969800000000001f476f6f736520566f746572202d205472756520426c6f636b20576569676874f07a080000000000000000001e40fad23d21da7a4fd4decb5c49726ea22f5e6bf6304402204f12469157b19edd06ba25fcad3d4a5ef5b057c23f9e02de4641e6f8eef0553e022010121ab282f83efe1043de9c16bbf2c6845a03684229a0d7c965ffb9abdfb97830450221008327862f0b9178d6665f7d6674978c5caf749649558d814244b1c66cdf945c40022015918134ef01fed3fe2a2efde3327917731344332724522c75c2799a14f78717ff011e0060d079010265c1f6b8c1966a90f3fed7bc32fd4f42238ab4938fdb2a4e7ddd01ae8b58b4c080969800000000001f476f6f736520566f746572202d205472756520426c6f636b20576569676874e67a080000000000000000001e79c579fb08f448879c22fe965906b4e3b88d02ed304402205f82feb8c5d1d79c565c2ff7badb93e4c9827b132d135dda11cb25427d4ef8ac02205ff136f970533c4ec4c7d0cd1ea7e02d7b62629b66c6c93265f608d7f2389727304402207e912031fcc700d8a55fbc415993302a0d8e6aea128397141b640b6dba52331702201fd1ad3984e42af44f548907add6cb7ad72ca0070c8cc1d8dc9bbda208c56bd9ff011e0064d079010265c1f6b8c1966a90f3fed7bc32fd4f42238ab4938fdb2a4e7ddd01ae8b58b4c080969800000000001f476f6f736520566f746572202d205472756520426c6f636b20576569676874fa7a080000000000000000001e84fee45dde2b11525afe192a2e991d014ff93a36304502210083216e6969e068770e6d2fe5c244881002309df84d20290ddf3f858967ed010202202a479b3da5080ea475d310ff13494654b42db75886a8808bd211b4bdb9146a7a3045022100e1dcab3406bbeb968146a4a391909ce41df9b71592a753b001e7c2ee1d382c5102202a74aeafd4a152ec61854636fbae829c41f1416c1e0637a0809408394973099fff011e0061d079010265c1f6b8c1966a90f3fed7bc32fd4f42238ab4938fdb2a4e7ddd01ae8b58b4c080969800000000001f476f6f736520566f746572202d205472756520426c6f636b20576569676874e67a080000000000000000001e1d69583ede5ee82d220e74bffb36bae2ce762dfb3045022100cd4fa9855227be11e17201419dacfbbd5d9946df8d6792a9488160025693821402207fb83969bad6a26959f437b5bb88e255b0a48eb04964d0c0d29f7ee94bd15e11304402205f50c2991a17743d17ffbb09159cadc35a3f848044261842879ccf5be9d81c5e022023bf21c32fb6e94494104f15f8d3a942ab120d0abd6fb4c93790b68e1b307a79ff011e0062d079010265c1f6b8c1966a90f3fed7bc32fd4f42238ab4938fdb2a4e7ddd01ae8b58b4c080969800000000001f476f6f736520566f746572202d205472756520426c6f636b20576569676874f07a080000000000000000001e56f9a37a859f4f84e93ce7593e809b15a524db2930450221009c792062e13399ac6756b2e9f137194d06e106360ac0f3e24e55c7249cee0b3602205dc1d9c76d0451d1cb5a2396783a13e6d2d790ccfd49291e3d0a78349f7ea0e830440220083ba8a9af49b8be6e93794d71ec43ffc96a158375810e5d9f2478e71655315b0220278402ecaa1d224dab9f0f3b28295bbaea339c85c7400edafdc49df87439fc64ff011e0063d079010265c1f6b8c1966a90f3fed7bc32fd4f42238ab4938fdb2a4e7ddd01ae8b58b4c080969800000000001f476f6f736520566f746572202d205472756520426c6f636b20576569676874f07a080000000000000000001e0232a083c16aba4362dddec1b3050ffdd6d43f2e3044022063c65263e42be02bd9831b375c1d76a88332f00ed0557ecc1e7d2375ca40070902206797b5932c0bad68444beb5a38daa7cadf536ee2144e0d9777b812284d14374e3045022100b04da6692f75d43229ffd8486c1517e8952d38b4c03dfac38b6b360190a5c33e0220776622e5f09f92a1258b4a011f22181c977b622b8d1bbb2f83b42f4126d00739ff011e0060d079010265c1f6b8c1966a90f3fed7bc32fd4f42238ab4938fdb2a4e7ddd01ae8b58b4c080969800000000001f476f6f736520566f746572202d205472756520426c6f636b20576569676874e67a080000000000000000001eccc4fce0dc95f9951ee40c09a7ae807746cf51403045022100d4513c3608c2072e38e7a0e3bb8daf2cd5f7cc6fec9a5570dccd1eda696c591902202ecbbf3c9d0757be7b23c8b1cc6481c51600d158756c47fcb6f4a7f4893e31c4304402201fed4858d0806dd32220960900a871dd2f60e1f623af75feef9b1034a9a0a46402205a29b27c63fcc3e1ee1e77ecbbf4dd6e7db09901e7a09b9fd490cd68d62392cb" +} diff --git a/packages/core-tester-cli/__tests__/__fixtures__/identities.json b/packages/core-tester-cli/__tests__/__fixtures__/identities.json new file mode 100644 index 0000000000..71063bafbc --- /dev/null +++ b/packages/core-tester-cli/__tests__/__fixtures__/identities.json @@ -0,0 +1,6 @@ +{ + "passphrase": "this is a top secret passphrase", + "publicKey": "034151a3ec46b5670a682b0a63394f863587d1bc97483b1b6c70eb58e7f0aed192", + "privateKey": "d8839c2432bfd0a67ef10a804ba991eabba19f154a3d707917681d45822a5712", + "address": "D61mfSggzbvQgTUe6JhYKH2doHaqJ3Dyib" +} diff --git a/packages/core-tester-cli/__tests__/__fixtures__/transaction-second.json b/packages/core-tester-cli/__tests__/__fixtures__/transaction-second.json new file mode 100644 index 0000000000..8a0ebe0907 --- /dev/null +++ b/packages/core-tester-cli/__tests__/__fixtures__/transaction-second.json @@ -0,0 +1,15 @@ +{ + "data": { + "type": 0, + "amount": 200000000, + "fee": 10000000, + "recipientId": "D61mfSggzbvQgTUe6JhYKH2doHaqJ3Dyib", + "timestamp": 41268430, + "asset": {}, + "senderPublicKey": "034151a3ec46b5670a682b0a63394f863587d1bc97483b1b6c70eb58e7f0aed192", + "signature": "304402206da703bfcc11ec2ccb3f363fa0e23fc64050fdf68e1f1852b7d4a5bb07824166022031ed1d86b586a79f9c1e5010dbc4f4cb36641c62a196536f90b1dfd6be1c9868", + "signSignature": "304402200759b6f9de5257aa3fcf54b9cd7a426a00af9368b7ea3d5ea2b13a91b97fb277022076e4d2d7deb9bdd8245b2533cab1eeeef72981e18576ef8455a61ee3e6f3fb57", + "id": "bb8054b6298d659d4b5d655e82de17b3504ba27655ec3d6e35d311f3104b1c43" + }, + "serialized": "ff011e00ceb47502034151a3ec46b5670a682b0a63394f863587d1bc97483b1b6c70eb58e7f0aed19280969800000000000000c2eb0b00000000000000001e0995750207ecaf0ccf251c1265b92ad84f553662304402206da703bfcc11ec2ccb3f363fa0e23fc64050fdf68e1f1852b7d4a5bb07824166022031ed1d86b586a79f9c1e5010dbc4f4cb36641c62a196536f90b1dfd6be1c9868304402200759b6f9de5257aa3fcf54b9cd7a426a00af9368b7ea3d5ea2b13a91b97fb277022076e4d2d7deb9bdd8245b2533cab1eeeef72981e18576ef8455a61ee3e6f3fb57" +} diff --git a/packages/core-tester-cli/__tests__/__fixtures__/transaction.json b/packages/core-tester-cli/__tests__/__fixtures__/transaction.json new file mode 100644 index 0000000000..70490d28c9 --- /dev/null +++ b/packages/core-tester-cli/__tests__/__fixtures__/transaction.json @@ -0,0 +1,14 @@ +{ + "data": { + "type": 0, + "amount": 200000000, + "fee": 10000000, + "recipientId": "D61mfSggzbvQgTUe6JhYKH2doHaqJ3Dyib", + "timestamp": 41268326, + "asset": {}, + "senderPublicKey": "034151a3ec46b5670a682b0a63394f863587d1bc97483b1b6c70eb58e7f0aed192", + "signature": "3044022002994b30e08b58825c8c16ebf2cc693cfe706fb26571674784ead098accc89d702205b79dedc752a84504ecfe4b9e1292997f22260ee4daa102d2d9a61432d93b286", + "id": "da61c6cba363cc39baa0ca3f9ba2c5db81b9805045bd0b9fc58af07ad4206856" + }, + "serialized": "ff011e0066b47502034151a3ec46b5670a682b0a63394f863587d1bc97483b1b6c70eb58e7f0aed19280969800000000000000c2eb0b00000000000000001e0995750207ecaf0ccf251c1265b92ad84f5536623044022002994b30e08b58825c8c16ebf2cc693cfe706fb26571674784ead098accc89d702205b79dedc752a84504ecfe4b9e1292997f22260ee4daa102d2d9a61432d93b286" +} diff --git a/packages/core-tester-cli/__tests__/commands/debug/deserialize.test.ts b/packages/core-tester-cli/__tests__/commands/debug/deserialize.test.ts new file mode 100644 index 0000000000..14f9d6325e --- /dev/null +++ b/packages/core-tester-cli/__tests__/commands/debug/deserialize.test.ts @@ -0,0 +1,60 @@ +import "jest-extended"; + +import { DeserializeCommand } from "../../../src/commands/debug/deserialize"; + +describe("Commands - Deserialize", () => { + const fixtureBlock = require("../../__fixtures__/block.json"); + const fixtureTransaction = require("../../__fixtures__/transaction.json"); + + it("should deserialize a block (not-full)", async () => { + const actual = JSON.parse(await DeserializeCommand.run(["--data", fixtureBlock.serialized, "--type", "block"])); + + expect(actual.data.version).toBe(fixtureBlock.data.version); + expect(actual.data.timestamp).toBe(fixtureBlock.data.timestamp); + expect(actual.data.height).toBe(fixtureBlock.data.height); + expect(actual.data.previousBlock).toBe(fixtureBlock.data.previousBlock); + expect(actual.data.numberOfTransactions).toBe(fixtureBlock.data.numberOfTransactions); + expect(actual.data.totalAmount).toBe(fixtureBlock.data.totalAmount); + expect(actual.data.totalFee).toBe(fixtureBlock.data.totalFee); + expect(actual.data.reward).toBe(fixtureBlock.data.reward); + expect(actual.data.payloadLength).toBe(fixtureBlock.data.payloadLength); + expect(actual.data.payloadHash).toBe(fixtureBlock.data.payloadHash); + expect(actual.data.generatorPublicKey).toBe(fixtureBlock.data.generatorPublicKey); + expect(actual.data.blockSignature).toBe(fixtureBlock.data.blockSignature); + }); + + it("should deserialize a block (full)", async () => { + const actual = JSON.parse( + await DeserializeCommand.run(["--data", fixtureBlock.serializedFull, "--type", "block"]), + ); + + expect(actual.data.version).toBe(fixtureBlock.data.version); + expect(actual.data.timestamp).toBe(fixtureBlock.data.timestamp); + expect(actual.data.height).toBe(fixtureBlock.data.height); + expect(actual.data.previousBlock).toBe(fixtureBlock.data.previousBlock); + expect(actual.data.numberOfTransactions).toBe(fixtureBlock.data.numberOfTransactions); + expect(actual.data.totalAmount).toBe(fixtureBlock.data.totalAmount); + expect(actual.data.totalFee).toBe(fixtureBlock.data.totalFee); + expect(actual.data.reward).toBe(fixtureBlock.data.reward); + expect(actual.data.payloadLength).toBe(fixtureBlock.data.payloadLength); + expect(actual.data.payloadHash).toBe(fixtureBlock.data.payloadHash); + expect(actual.data.generatorPublicKey).toBe(fixtureBlock.data.generatorPublicKey); + expect(actual.data.blockSignature).toBe(fixtureBlock.data.blockSignature); + expect(actual.transactions).toHaveLength(7); + }); + + it("should deserialize a transaction", async () => { + const actual = JSON.parse( + await DeserializeCommand.run(["--data", fixtureTransaction.serialized, "--type", "transaction"]), + ); + + expect(actual.type).toBe(fixtureTransaction.data.type); + expect(+actual.amount).toBe(fixtureTransaction.data.amount); + expect(+actual.fee).toBe(fixtureTransaction.data.fee); + expect(actual.recipientId).toBe(fixtureTransaction.data.recipientId); + expect(actual.timestamp).toBe(fixtureTransaction.data.timestamp); + expect(actual.senderPublicKey).toBe(fixtureTransaction.data.senderPublicKey); + expect(actual.signature).toBe(fixtureTransaction.data.signature); + expect(actual.id).toBe(fixtureTransaction.data.id); + }); +}); diff --git a/packages/core-tester-cli/__tests__/commands/debug/identity.test.ts b/packages/core-tester-cli/__tests__/commands/debug/identity.test.ts new file mode 100644 index 0000000000..655903888d --- /dev/null +++ b/packages/core-tester-cli/__tests__/commands/debug/identity.test.ts @@ -0,0 +1,43 @@ +import "jest-extended"; + +import { IdentityCommand } from "../../../src/commands/debug/identity"; + +describe("Commands - Identity", async () => { + const fixtureIdentities = require("../../__fixtures__/identities.json"); + + it("should return identities from passphrase", async () => { + const expected = { + passphrase: "this is a top secret passphrase", + publicKey: "034151a3ec46b5670a682b0a63394f863587d1bc97483b1b6c70eb58e7f0aed192", + privateKey: "d8839c2432bfd0a67ef10a804ba991eabba19f154a3d707917681d45822a5712", + address: "D61mfSggzbvQgTUe6JhYKH2doHaqJ3Dyib", + }; + + expect(await IdentityCommand.run(["--data", fixtureIdentities.passphrase, "--type", "passphrase"])).toEqual( + expected, + ); + }); + + it("should return identities from privateKey", async () => { + const expected = { + publicKey: "034151a3ec46b5670a682b0a63394f863587d1bc97483b1b6c70eb58e7f0aed192", + privateKey: "d8839c2432bfd0a67ef10a804ba991eabba19f154a3d707917681d45822a5712", + address: "D61mfSggzbvQgTUe6JhYKH2doHaqJ3Dyib", + }; + + expect(await IdentityCommand.run(["--data", fixtureIdentities.privateKey, "--type", "privateKey"])).toEqual( + expected, + ); + }); + + it("should return identities from publicKey", async () => { + const expected = { + publicKey: "034151a3ec46b5670a682b0a63394f863587d1bc97483b1b6c70eb58e7f0aed192", + address: "D61mfSggzbvQgTUe6JhYKH2doHaqJ3Dyib", + }; + + expect(await IdentityCommand.run(["--data", fixtureIdentities.publicKey, "--type", "publicKey"])).toEqual( + expected, + ); + }); +}); diff --git a/packages/core-tester-cli/__tests__/commands/debug/serialize.test.ts b/packages/core-tester-cli/__tests__/commands/debug/serialize.test.ts new file mode 100644 index 0000000000..c7e20563e5 --- /dev/null +++ b/packages/core-tester-cli/__tests__/commands/debug/serialize.test.ts @@ -0,0 +1,26 @@ +import "jest-extended"; + +import { SerializeCommand } from "../../../src/commands/debug/serialize"; + +describe("Commands - Serialize", () => { + const fixtureBlock = require("../../__fixtures__/block.json"); + const fixtureTransaction = require("../../__fixtures__/transaction.json"); + + it("should serialize a block (not-full)", async () => { + expect(await SerializeCommand.run(["--data", JSON.stringify(fixtureBlock.data), "--type", "block"])).toEqual( + fixtureBlock.serialized, + ); + }); + + it("should serialize a block (full)", async () => { + expect( + await SerializeCommand.run(["--data", JSON.stringify(fixtureBlock.data), "--type", "block", "--full"]), + ).toEqual(fixtureBlock.serializedFull); + }); + + it("should serialize a transaction", async () => { + expect( + await SerializeCommand.run(["--data", JSON.stringify(fixtureTransaction.data), "--type", "transaction"]), + ).toEqual(fixtureTransaction.serialized); + }); +}); diff --git a/packages/core-tester-cli/__tests__/commands/debug/verify-second.test.ts b/packages/core-tester-cli/__tests__/commands/debug/verify-second.test.ts new file mode 100644 index 0000000000..8ac408883a --- /dev/null +++ b/packages/core-tester-cli/__tests__/commands/debug/verify-second.test.ts @@ -0,0 +1,18 @@ +import "jest-extended"; + +import { VerifySecondSignatureCommand } from "../../../src/commands/debug/verify-second-signature"; + +describe("Commands - Verify Second", () => { + const fixtureTransaction = require("../../__fixtures__/transaction-second.json"); + + it("should verify a second signature", async () => { + expect( + await VerifySecondSignatureCommand.run([ + "--data", + fixtureTransaction.serialized, + "--publicKey", + "03699e966b2525f9088a6941d8d94f7869964a000efe65783d78ac82e1199fe609", + ]), + ).toBeTrue(); + }); +}); diff --git a/packages/core-tester-cli/__tests__/commands/debug/verify.test.ts b/packages/core-tester-cli/__tests__/commands/debug/verify.test.ts new file mode 100644 index 0000000000..2556b4033f --- /dev/null +++ b/packages/core-tester-cli/__tests__/commands/debug/verify.test.ts @@ -0,0 +1,16 @@ +import "jest-extended"; + +import { VerifyCommand } from "../../../src/commands/debug/verify"; + +describe("Commands - Verify", () => { + const fixtureBlock = require("../../__fixtures__/block.json"); + const fixtureTransaction = require("../../__fixtures__/transaction.json"); + + it("should verify a block", async () => { + expect(await VerifyCommand.run(["--data", fixtureBlock.serializedFull, "--type", "block"])).toBeTrue(); + }); + + it("should verify a transaction", async () => { + expect(await VerifyCommand.run(["--data", fixtureTransaction.serialized, "--type", "transaction"])).toBeTrue(); + }); +}); diff --git a/packages/core-tester-cli/__tests__/commands/delegate-registration.test.ts b/packages/core-tester-cli/__tests__/commands/send/delegate-registration.test.ts similarity index 93% rename from packages/core-tester-cli/__tests__/commands/delegate-registration.test.ts rename to packages/core-tester-cli/__tests__/commands/send/delegate-registration.test.ts index 609e253030..25ec3be62f 100644 --- a/packages/core-tester-cli/__tests__/commands/delegate-registration.test.ts +++ b/packages/core-tester-cli/__tests__/commands/send/delegate-registration.test.ts @@ -3,8 +3,8 @@ import "jest-extended"; import axios from "axios"; import MockAdapter from "axios-mock-adapter"; import pokemon from "pokemon"; -import { DelegateRegistrationCommand } from "../../src/commands/send/delegate-registration"; -import { arkToSatoshi, captureTransactions, expectTransactions, toFlags } from "../shared"; +import { DelegateRegistrationCommand } from "../../../src/commands/send/delegate-registration"; +import { arkToSatoshi, captureTransactions, expectTransactions, toFlags } from "../../shared"; const mockAxios = new MockAdapter(axios); diff --git a/packages/core-tester-cli/__tests__/commands/second-signature.test.ts b/packages/core-tester-cli/__tests__/commands/send/second-signature.test.ts similarity index 90% rename from packages/core-tester-cli/__tests__/commands/second-signature.test.ts rename to packages/core-tester-cli/__tests__/commands/send/second-signature.test.ts index 3fb6737b27..759db098bb 100644 --- a/packages/core-tester-cli/__tests__/commands/second-signature.test.ts +++ b/packages/core-tester-cli/__tests__/commands/send/second-signature.test.ts @@ -2,8 +2,8 @@ import "jest-extended"; import axios from "axios"; import MockAdapter from "axios-mock-adapter"; -import { SecondSignatureRegistrationCommand } from "../../src/commands/send/second-signature-registration"; -import { arkToSatoshi, captureTransactions, expectTransactions, toFlags } from "../shared"; +import { SecondSignatureRegistrationCommand } from "../../../src/commands/send/second-signature-registration"; +import { arkToSatoshi, captureTransactions, expectTransactions, toFlags } from "../../shared"; const mockAxios = new MockAdapter(axios); diff --git a/packages/core-tester-cli/__tests__/commands/transfer.test.ts b/packages/core-tester-cli/__tests__/commands/send/transfer.test.ts similarity index 97% rename from packages/core-tester-cli/__tests__/commands/transfer.test.ts rename to packages/core-tester-cli/__tests__/commands/send/transfer.test.ts index af56d35e48..f755049db4 100644 --- a/packages/core-tester-cli/__tests__/commands/transfer.test.ts +++ b/packages/core-tester-cli/__tests__/commands/send/transfer.test.ts @@ -2,8 +2,8 @@ import "jest-extended"; import axios from "axios"; import MockAdapter from "axios-mock-adapter"; -import { TransferCommand } from "../../src/commands/send/transfer"; -import { arkToSatoshi, captureTransactions, expectTransactions, toFlags } from "../shared"; +import { TransferCommand } from "../../../src/commands/send/transfer"; +import { arkToSatoshi, captureTransactions, expectTransactions, toFlags } from "../../shared"; const mockAxios = new MockAdapter(axios); diff --git a/packages/core-tester-cli/__tests__/commands/vote.test.ts b/packages/core-tester-cli/__tests__/commands/send/vote.test.ts similarity index 96% rename from packages/core-tester-cli/__tests__/commands/vote.test.ts rename to packages/core-tester-cli/__tests__/commands/send/vote.test.ts index 886d30c2dd..2aa96608d5 100644 --- a/packages/core-tester-cli/__tests__/commands/vote.test.ts +++ b/packages/core-tester-cli/__tests__/commands/send/vote.test.ts @@ -2,8 +2,8 @@ import "jest-extended"; import axios from "axios"; import MockAdapter from "axios-mock-adapter"; -import { VoteCommand } from "../../src/commands/send/vote"; -import { arkToSatoshi, captureTransactions, expectTransactions, toFlags } from "../shared"; +import { VoteCommand } from "../../../src/commands/send/vote"; +import { arkToSatoshi, captureTransactions, expectTransactions, toFlags } from "../../shared"; const mockAxios = new MockAdapter(axios); diff --git a/packages/core-tester-cli/src/commands/debug/deserialize.ts b/packages/core-tester-cli/src/commands/debug/deserialize.ts index 7ac20ffbd2..ae56d37dd6 100644 --- a/packages/core-tester-cli/src/commands/debug/deserialize.ts +++ b/packages/core-tester-cli/src/commands/debug/deserialize.ts @@ -20,7 +20,7 @@ export class DeserializeCommand extends BaseCommand { }; public async run(): Promise { - const { flags } = await this.make(DeserializeCommand); + const { flags } = this.parse(DeserializeCommand); const deserialized = flags.type === "transaction" ? new models.Transaction(flags.data) : new models.Block(flags.data); diff --git a/packages/core-tester-cli/src/commands/debug/identity.ts b/packages/core-tester-cli/src/commands/debug/identity.ts index 71332dc390..3d257dff6e 100644 --- a/packages/core-tester-cli/src/commands/debug/identity.ts +++ b/packages/core-tester-cli/src/commands/debug/identity.ts @@ -24,7 +24,7 @@ export class IdentityCommand extends BaseCommand { }; public async run(): Promise { - const { flags } = await this.make(IdentityCommand); + const { flags } = this.parse(IdentityCommand); let output; diff --git a/packages/core-tester-cli/src/commands/debug/serialize.ts b/packages/core-tester-cli/src/commands/debug/serialize.ts index d6055d424b..40a479feb5 100644 --- a/packages/core-tester-cli/src/commands/debug/serialize.ts +++ b/packages/core-tester-cli/src/commands/debug/serialize.ts @@ -23,7 +23,7 @@ export class SerializeCommand extends BaseCommand { }; public async run(): Promise { - const { flags } = await this.make(SerializeCommand); + const { flags } = this.parse(SerializeCommand); const serialized: any = flags.type === "transaction" diff --git a/packages/core-tester-cli/src/commands/debug/verify-second-signature.ts b/packages/core-tester-cli/src/commands/debug/verify-second-signature.ts index b9c15e6c63..5b45f5f4b8 100644 --- a/packages/core-tester-cli/src/commands/debug/verify-second-signature.ts +++ b/packages/core-tester-cli/src/commands/debug/verify-second-signature.ts @@ -19,7 +19,7 @@ export class VerifySecondSignatureCommand extends BaseCommand { }; public async run(): Promise { - const { flags } = await this.make(VerifySecondSignatureCommand); + const { flags } = this.parse(VerifySecondSignatureCommand); const transaction = new models.Transaction(flags.data); diff --git a/packages/core-tester-cli/src/commands/debug/verify.ts b/packages/core-tester-cli/src/commands/debug/verify.ts index 9d598365da..00d8f05f80 100644 --- a/packages/core-tester-cli/src/commands/debug/verify.ts +++ b/packages/core-tester-cli/src/commands/debug/verify.ts @@ -19,7 +19,6 @@ export class VerifyCommand extends BaseCommand { }; public async run(): Promise { - // tslint:disable-next-line:no-shadowed-variable const { flags } = this.parse(VerifyCommand); const deserialized = From 61f10380f7bfaf87c34ab8ed656d044c3d277629 Mon Sep 17 00:00:00 2001 From: Brian Faust Date: Tue, 26 Feb 2019 09:51:29 +0200 Subject: [PATCH 14/18] chore: update CircleCI config --- .circleci/config.yml | 44 ++++++++++++++------------------------------ 1 file changed, 14 insertions(+), 30 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 587978f2a4..9b187be631 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -41,7 +41,6 @@ jobs: - ./packages/core-container/node_modules - ./packages/core-database/node_modules - ./packages/core-database-postgres/node_modules - - ./packages/core-debugger-cli/node_modules - ./packages/core-elasticsearch/node_modules - ./packages/core-error-tracker-bugsnag/node_modules - ./packages/core-error-tracker-sentry/node_modules @@ -94,10 +93,10 @@ jobs: cd ~/core/.circleci && ./rebuild-db.sh && cd ~/core/packages/core-database-postgres && yarn test:coverage - run: - name: core-debugger-cli + name: core-event-emitter command: >- cd ~/core/.circleci && ./rebuild-db.sh && cd - ~/core/packages/core-debugger-cli && yarn test:coverage + ~/core/packages/core-event-emitter && yarn test:coverage - run: name: Last 1000 lines of test output when: on_fail @@ -149,7 +148,6 @@ jobs: - ./packages/core-container/node_modules - ./packages/core-database/node_modules - ./packages/core-database-postgres/node_modules - - ./packages/core-debugger-cli/node_modules - ./packages/core-elasticsearch/node_modules - ./packages/core-error-tracker-bugsnag/node_modules - ./packages/core-error-tracker-sentry/node_modules @@ -202,10 +200,10 @@ jobs: cd ~/core/.circleci && ./rebuild-db.sh && cd ~/core/packages/core-database-postgres && yarn test:coverage - run: - name: core-debugger-cli + name: core-event-emitter command: >- cd ~/core/.circleci && ./rebuild-db.sh && cd - ~/core/packages/core-debugger-cli && yarn test:coverage + ~/core/packages/core-event-emitter && yarn test:coverage - run: name: Last 1000 lines of test output when: on_fail @@ -257,7 +255,6 @@ jobs: - ./packages/core-container/node_modules - ./packages/core-database/node_modules - ./packages/core-database-postgres/node_modules - - ./packages/core-debugger-cli/node_modules - ./packages/core-elasticsearch/node_modules - ./packages/core-error-tracker-bugsnag/node_modules - ./packages/core-error-tracker-sentry/node_modules @@ -284,11 +281,6 @@ jobs: - run: name: Create .core/database directory command: mkdir -p $HOME/.core/database - - run: - name: core-event-emitter - command: >- - cd ~/core/.circleci && ./rebuild-db.sh && cd - ~/core/packages/core-event-emitter && yarn test:coverage - run: name: core-forger command: >- @@ -329,6 +321,11 @@ jobs: command: >- cd ~/core/.circleci && ./rebuild-db.sh && cd ~/core/packages/core-p2p && yarn test:coverage + - run: + name: core-snapshots + command: >- + cd ~/core/.circleci && ./rebuild-db.sh && cd + ~/core/packages/core-snapshots && yarn test:coverage - run: name: Last 1000 lines of test output when: on_fail @@ -380,7 +377,6 @@ jobs: - ./packages/core-container/node_modules - ./packages/core-database/node_modules - ./packages/core-database-postgres/node_modules - - ./packages/core-debugger-cli/node_modules - ./packages/core-elasticsearch/node_modules - ./packages/core-error-tracker-bugsnag/node_modules - ./packages/core-error-tracker-sentry/node_modules @@ -407,11 +403,6 @@ jobs: - run: name: Create .core/database directory command: mkdir -p $HOME/.core/database - - run: - name: core-snapshots - command: >- - cd ~/core/.circleci && ./rebuild-db.sh && cd - ~/core/packages/core-snapshots && yarn test:coverage - run: name: core-test-utils command: >- @@ -498,7 +489,6 @@ jobs: - ./packages/core-container/node_modules - ./packages/core-database/node_modules - ./packages/core-database-postgres/node_modules - - ./packages/core-debugger-cli/node_modules - ./packages/core-elasticsearch/node_modules - ./packages/core-error-tracker-bugsnag/node_modules - ./packages/core-error-tracker-sentry/node_modules @@ -525,11 +515,6 @@ jobs: - run: name: Create .core/database directory command: mkdir -p $HOME/.core/database - - run: - name: core-event-emitter - command: >- - cd ~/core/.circleci && ./rebuild-db.sh && cd - ~/core/packages/core-event-emitter && yarn test:coverage - run: name: core-forger command: >- @@ -570,6 +555,11 @@ jobs: command: >- cd ~/core/.circleci && ./rebuild-db.sh && cd ~/core/packages/core-p2p && yarn test:coverage + - run: + name: core-snapshots + command: >- + cd ~/core/.circleci && ./rebuild-db.sh && cd + ~/core/packages/core-snapshots && yarn test:coverage - run: name: Last 1000 lines of test output when: on_fail @@ -621,7 +611,6 @@ jobs: - ./packages/core-container/node_modules - ./packages/core-database/node_modules - ./packages/core-database-postgres/node_modules - - ./packages/core-debugger-cli/node_modules - ./packages/core-elasticsearch/node_modules - ./packages/core-error-tracker-bugsnag/node_modules - ./packages/core-error-tracker-sentry/node_modules @@ -648,11 +637,6 @@ jobs: - run: name: Create .core/database directory command: mkdir -p $HOME/.core/database - - run: - name: core-snapshots - command: >- - cd ~/core/.circleci && ./rebuild-db.sh && cd - ~/core/packages/core-snapshots && yarn test:coverage - run: name: core-test-utils command: >- From 72e1c2ba01677af3da40e7d5c2d3a54843e32607 Mon Sep 17 00:00:00 2001 From: Brian Faust Date: Thu, 28 Feb 2019 12:11:16 +0200 Subject: [PATCH 15/18] imports --- .../unit/core-tester-cli/commands/debug/deserialize.test.ts | 2 +- __tests__/unit/core-tester-cli/commands/debug/identity.test.ts | 2 +- __tests__/unit/core-tester-cli/commands/debug/serialize.test.ts | 2 +- .../unit/core-tester-cli/commands/debug/verify-second.test.ts | 2 +- __tests__/unit/core-tester-cli/commands/debug/verify.test.ts | 2 +- .../core-tester-cli/commands/send/delegate-registration.test.ts | 2 +- .../unit/core-tester-cli/commands/send/second-signature.test.ts | 2 +- __tests__/unit/core-tester-cli/commands/send/transfer.test.ts | 2 +- __tests__/unit/core-tester-cli/commands/send/vote.test.ts | 2 +- 9 files changed, 9 insertions(+), 9 deletions(-) diff --git a/__tests__/unit/core-tester-cli/commands/debug/deserialize.test.ts b/__tests__/unit/core-tester-cli/commands/debug/deserialize.test.ts index 14f9d6325e..3775c3b78c 100644 --- a/__tests__/unit/core-tester-cli/commands/debug/deserialize.test.ts +++ b/__tests__/unit/core-tester-cli/commands/debug/deserialize.test.ts @@ -1,6 +1,6 @@ import "jest-extended"; -import { DeserializeCommand } from "../../../src/commands/debug/deserialize"; +import { DeserializeCommand } from "../../../../../packages/core-tester-cli/src/commands/debug/deserialize"; describe("Commands - Deserialize", () => { const fixtureBlock = require("../../__fixtures__/block.json"); diff --git a/__tests__/unit/core-tester-cli/commands/debug/identity.test.ts b/__tests__/unit/core-tester-cli/commands/debug/identity.test.ts index 655903888d..1362648740 100644 --- a/__tests__/unit/core-tester-cli/commands/debug/identity.test.ts +++ b/__tests__/unit/core-tester-cli/commands/debug/identity.test.ts @@ -1,6 +1,6 @@ import "jest-extended"; -import { IdentityCommand } from "../../../src/commands/debug/identity"; +import { IdentityCommand } from "../../../../../packages/core-tester-cli/src/commands/debug/identity"; describe("Commands - Identity", async () => { const fixtureIdentities = require("../../__fixtures__/identities.json"); diff --git a/__tests__/unit/core-tester-cli/commands/debug/serialize.test.ts b/__tests__/unit/core-tester-cli/commands/debug/serialize.test.ts index c7e20563e5..6e26821bb8 100644 --- a/__tests__/unit/core-tester-cli/commands/debug/serialize.test.ts +++ b/__tests__/unit/core-tester-cli/commands/debug/serialize.test.ts @@ -1,6 +1,6 @@ import "jest-extended"; -import { SerializeCommand } from "../../../src/commands/debug/serialize"; +import { SerializeCommand } from "../../../../../packages/core-tester-cli/src/commands/debug/serialize"; describe("Commands - Serialize", () => { const fixtureBlock = require("../../__fixtures__/block.json"); diff --git a/__tests__/unit/core-tester-cli/commands/debug/verify-second.test.ts b/__tests__/unit/core-tester-cli/commands/debug/verify-second.test.ts index 8ac408883a..40b8236663 100644 --- a/__tests__/unit/core-tester-cli/commands/debug/verify-second.test.ts +++ b/__tests__/unit/core-tester-cli/commands/debug/verify-second.test.ts @@ -1,6 +1,6 @@ import "jest-extended"; -import { VerifySecondSignatureCommand } from "../../../src/commands/debug/verify-second-signature"; +import { VerifySecondSignatureCommand } from "../../../../../packages/core-tester-cli/src/commands/debug/verify-second-signature"; describe("Commands - Verify Second", () => { const fixtureTransaction = require("../../__fixtures__/transaction-second.json"); diff --git a/__tests__/unit/core-tester-cli/commands/debug/verify.test.ts b/__tests__/unit/core-tester-cli/commands/debug/verify.test.ts index 2556b4033f..8425ac3ebb 100644 --- a/__tests__/unit/core-tester-cli/commands/debug/verify.test.ts +++ b/__tests__/unit/core-tester-cli/commands/debug/verify.test.ts @@ -1,6 +1,6 @@ import "jest-extended"; -import { VerifyCommand } from "../../../src/commands/debug/verify"; +import { VerifyCommand } from "../../../../../packages/core-tester-cli/src/commands/debug/verify"; describe("Commands - Verify", () => { const fixtureBlock = require("../../__fixtures__/block.json"); diff --git a/__tests__/unit/core-tester-cli/commands/send/delegate-registration.test.ts b/__tests__/unit/core-tester-cli/commands/send/delegate-registration.test.ts index 25ec3be62f..23145778c2 100644 --- a/__tests__/unit/core-tester-cli/commands/send/delegate-registration.test.ts +++ b/__tests__/unit/core-tester-cli/commands/send/delegate-registration.test.ts @@ -3,7 +3,7 @@ import "jest-extended"; import axios from "axios"; import MockAdapter from "axios-mock-adapter"; import pokemon from "pokemon"; -import { DelegateRegistrationCommand } from "../../../src/commands/send/delegate-registration"; +import { DelegateRegistrationCommand } from "../../../../../packages/core-tester-cli/src/commands/send/delegate-registration"; import { arkToSatoshi, captureTransactions, expectTransactions, toFlags } from "../../shared"; const mockAxios = new MockAdapter(axios); diff --git a/__tests__/unit/core-tester-cli/commands/send/second-signature.test.ts b/__tests__/unit/core-tester-cli/commands/send/second-signature.test.ts index 759db098bb..f0979127b7 100644 --- a/__tests__/unit/core-tester-cli/commands/send/second-signature.test.ts +++ b/__tests__/unit/core-tester-cli/commands/send/second-signature.test.ts @@ -2,7 +2,7 @@ import "jest-extended"; import axios from "axios"; import MockAdapter from "axios-mock-adapter"; -import { SecondSignatureRegistrationCommand } from "../../../src/commands/send/second-signature-registration"; +import { SecondSignatureRegistrationCommand } from "../../../../../packages/core-tester-cli/src/commands/send/second-signature-registration"; import { arkToSatoshi, captureTransactions, expectTransactions, toFlags } from "../../shared"; const mockAxios = new MockAdapter(axios); diff --git a/__tests__/unit/core-tester-cli/commands/send/transfer.test.ts b/__tests__/unit/core-tester-cli/commands/send/transfer.test.ts index f755049db4..a1890b364b 100644 --- a/__tests__/unit/core-tester-cli/commands/send/transfer.test.ts +++ b/__tests__/unit/core-tester-cli/commands/send/transfer.test.ts @@ -2,7 +2,7 @@ import "jest-extended"; import axios from "axios"; import MockAdapter from "axios-mock-adapter"; -import { TransferCommand } from "../../../src/commands/send/transfer"; +import { TransferCommand } from "../../../../../packages/core-tester-cli/src/commands/send/transfer"; import { arkToSatoshi, captureTransactions, expectTransactions, toFlags } from "../../shared"; const mockAxios = new MockAdapter(axios); diff --git a/__tests__/unit/core-tester-cli/commands/send/vote.test.ts b/__tests__/unit/core-tester-cli/commands/send/vote.test.ts index 2aa96608d5..19b1b8d678 100644 --- a/__tests__/unit/core-tester-cli/commands/send/vote.test.ts +++ b/__tests__/unit/core-tester-cli/commands/send/vote.test.ts @@ -2,7 +2,7 @@ import "jest-extended"; import axios from "axios"; import MockAdapter from "axios-mock-adapter"; -import { VoteCommand } from "../../../src/commands/send/vote"; +import { VoteCommand } from "../../../../../packages/core-tester-cli/src/commands/send/vote"; import { arkToSatoshi, captureTransactions, expectTransactions, toFlags } from "../../shared"; const mockAxios = new MockAdapter(axios); From 31bb15494e874cad7128835abea177d501d5c6e2 Mon Sep 17 00:00:00 2001 From: Brian Faust Date: Thu, 28 Feb 2019 12:17:48 +0200 Subject: [PATCH 16/18] test --- __tests__/unit/core-tester-cli/commands/send/transfer.test.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/__tests__/unit/core-tester-cli/commands/send/transfer.test.ts b/__tests__/unit/core-tester-cli/commands/send/transfer.test.ts index a1890b364b..aa9170fb3a 100644 --- a/__tests__/unit/core-tester-cli/commands/send/transfer.test.ts +++ b/__tests__/unit/core-tester-cli/commands/send/transfer.test.ts @@ -110,8 +110,8 @@ describe("Commands - Transfer", () => { await TransferCommand.run(toFlags(opts)); expect(expectedTransactions).toHaveLength(1); - for (const t of expectedTransactions) { - expect(t.signSignature).toBeDefined(); + for (const transaction of expectedTransactions) { + expect(transaction.secondSignature).toBeDefined(); } }); }); From 4190a4bf7a4d1fb19c16bad72063ffffa1e2baee Mon Sep 17 00:00:00 2001 From: Brian Faust Date: Thu, 28 Feb 2019 17:11:34 +0200 Subject: [PATCH 17/18] fixture --- .circleci/config.yml | 114 ++++++++++-------- .../core-tester-cli/__fixtures__/block.json | 14 +-- 2 files changed, 73 insertions(+), 55 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 2f0390d026..9c089921ff 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -41,6 +41,7 @@ jobs: - ./packages/core-container/node_modules - ./packages/core-database/node_modules - ./packages/core-database-postgres/node_modules + - ./packages/core-debugger-cli/node_modules - ./packages/core-elasticsearch/node_modules - ./packages/core-error-tracker-bugsnag/node_modules - ./packages/core-error-tracker-sentry/node_modules @@ -53,8 +54,10 @@ jobs: - ./packages/core-json-rpc/node_modules - ./packages/core-logger/node_modules - ./packages/core-logger-pino/node_modules + - ./packages/core-logger-winston/node_modules - ./packages/core-p2p/node_modules - ./packages/core-snapshots/node_modules + - ./packages/core-test-utils/node_modules - ./packages/core-tester-cli/node_modules - ./packages/core-transaction-pool/node_modules - ./packages/core-utils/node_modules @@ -95,12 +98,6 @@ jobs: cd ~/core/.circleci && ./rebuild-db.sh && cd ~/core && yarn test:coverage /unit/core-database-postgres/ --coverageDirectory .coverage/unit/core-database-postgres - - run: - name: core-event-emitter - unit - command: >- - cd ~/core/.circleci && ./rebuild-db.sh && cd ~/core && yarn - test:coverage /unit/core-event-emitter/ --coverageDirectory - .coverage/unit/core-event-emitter - run: name: core-api - integration command: >- @@ -164,6 +161,7 @@ jobs: - ./packages/core-container/node_modules - ./packages/core-database/node_modules - ./packages/core-database-postgres/node_modules + - ./packages/core-debugger-cli/node_modules - ./packages/core-elasticsearch/node_modules - ./packages/core-error-tracker-bugsnag/node_modules - ./packages/core-error-tracker-sentry/node_modules @@ -176,8 +174,10 @@ jobs: - ./packages/core-json-rpc/node_modules - ./packages/core-logger/node_modules - ./packages/core-logger-pino/node_modules + - ./packages/core-logger-winston/node_modules - ./packages/core-p2p/node_modules - ./packages/core-snapshots/node_modules + - ./packages/core-test-utils/node_modules - ./packages/core-tester-cli/node_modules - ./packages/core-transaction-pool/node_modules - ./packages/core-utils/node_modules @@ -218,12 +218,6 @@ jobs: cd ~/core/.circleci && ./rebuild-db.sh && cd ~/core && yarn test:coverage /unit/core-database-postgres/ --coverageDirectory .coverage/unit/core-database-postgres - - run: - name: core-event-emitter - unit - command: >- - cd ~/core/.circleci && ./rebuild-db.sh && cd ~/core && yarn - test:coverage /unit/core-event-emitter/ --coverageDirectory - .coverage/unit/core-event-emitter - run: name: core-api - integration command: >- @@ -287,6 +281,7 @@ jobs: - ./packages/core-container/node_modules - ./packages/core-database/node_modules - ./packages/core-database-postgres/node_modules + - ./packages/core-debugger-cli/node_modules - ./packages/core-elasticsearch/node_modules - ./packages/core-error-tracker-bugsnag/node_modules - ./packages/core-error-tracker-sentry/node_modules @@ -299,8 +294,10 @@ jobs: - ./packages/core-json-rpc/node_modules - ./packages/core-logger/node_modules - ./packages/core-logger-pino/node_modules + - ./packages/core-logger-winston/node_modules - ./packages/core-p2p/node_modules - ./packages/core-snapshots/node_modules + - ./packages/core-test-utils/node_modules - ./packages/core-tester-cli/node_modules - ./packages/core-transaction-pool/node_modules - ./packages/core-utils/node_modules @@ -311,6 +308,12 @@ jobs: - run: name: Create .core/database directory command: mkdir -p $HOME/.core/database + - run: + name: core-event-emitter - unit + command: >- + cd ~/core/.circleci && ./rebuild-db.sh && cd ~/core && yarn + test:coverage /unit/core-event-emitter/ --coverageDirectory + .coverage/unit/core-event-emitter - run: name: core-forger - unit command: >- @@ -341,30 +344,12 @@ jobs: cd ~/core/.circleci && ./rebuild-db.sh && cd ~/core && yarn test:coverage /unit/core-logger-pino/ --coverageDirectory .coverage/unit/core-logger-pino - - run: - name: core-p2p - unit - command: >- - cd ~/core/.circleci && ./rebuild-db.sh && cd ~/core && yarn - test:coverage /unit/core-p2p/ --coverageDirectory - .coverage/unit/core-p2p - - run: - name: core-snapshots - unit - command: >- - cd ~/core/.circleci && ./rebuild-db.sh && cd ~/core && yarn - test:coverage /unit/core-snapshots/ --coverageDirectory - .coverage/unit/core-snapshots - run: name: core-json-rpc - integration command: >- cd ~/core/.circleci && ./rebuild-db.sh && cd ~/core && yarn test:coverage /integration/core-json-rpc/ --coverageDirectory .coverage/integration/core-json-rpc - - run: - name: core-p2p - integration - command: >- - cd ~/core/.circleci && ./rebuild-db.sh && cd ~/core && yarn - test:coverage /integration/core-p2p/ --coverageDirectory - .coverage/integration/core-p2p - run: name: Last 1000 lines of test output when: on_fail @@ -416,6 +401,7 @@ jobs: - ./packages/core-container/node_modules - ./packages/core-database/node_modules - ./packages/core-database-postgres/node_modules + - ./packages/core-debugger-cli/node_modules - ./packages/core-elasticsearch/node_modules - ./packages/core-error-tracker-bugsnag/node_modules - ./packages/core-error-tracker-sentry/node_modules @@ -428,8 +414,10 @@ jobs: - ./packages/core-json-rpc/node_modules - ./packages/core-logger/node_modules - ./packages/core-logger-pino/node_modules + - ./packages/core-logger-winston/node_modules - ./packages/core-p2p/node_modules - ./packages/core-snapshots/node_modules + - ./packages/core-test-utils/node_modules - ./packages/core-tester-cli/node_modules - ./packages/core-transaction-pool/node_modules - ./packages/core-utils/node_modules @@ -440,6 +428,18 @@ jobs: - run: name: Create .core/database directory command: mkdir -p $HOME/.core/database + - run: + name: core-p2p - unit + command: >- + cd ~/core/.circleci && ./rebuild-db.sh && cd ~/core && yarn + test:coverage /unit/core-p2p/ --coverageDirectory + .coverage/unit/core-p2p + - run: + name: core-snapshots - unit + command: >- + cd ~/core/.circleci && ./rebuild-db.sh && cd ~/core && yarn + test:coverage /unit/core-snapshots/ --coverageDirectory + .coverage/unit/core-snapshots - run: name: core-tester-cli - unit command: >- @@ -476,6 +476,12 @@ jobs: cd ~/core/.circleci && ./rebuild-db.sh && cd ~/core && yarn test:coverage /unit/crypto/ --coverageDirectory .coverage/unit/crypto + - run: + name: core-p2p - integration + command: >- + cd ~/core/.circleci && ./rebuild-db.sh && cd ~/core && yarn + test:coverage /integration/core-p2p/ --coverageDirectory + .coverage/integration/core-p2p - run: name: core-transaction-pool - integration command: >- @@ -533,6 +539,7 @@ jobs: - ./packages/core-container/node_modules - ./packages/core-database/node_modules - ./packages/core-database-postgres/node_modules + - ./packages/core-debugger-cli/node_modules - ./packages/core-elasticsearch/node_modules - ./packages/core-error-tracker-bugsnag/node_modules - ./packages/core-error-tracker-sentry/node_modules @@ -545,8 +552,10 @@ jobs: - ./packages/core-json-rpc/node_modules - ./packages/core-logger/node_modules - ./packages/core-logger-pino/node_modules + - ./packages/core-logger-winston/node_modules - ./packages/core-p2p/node_modules - ./packages/core-snapshots/node_modules + - ./packages/core-test-utils/node_modules - ./packages/core-tester-cli/node_modules - ./packages/core-transaction-pool/node_modules - ./packages/core-utils/node_modules @@ -557,6 +566,12 @@ jobs: - run: name: Create .core/database directory command: mkdir -p $HOME/.core/database + - run: + name: core-event-emitter - unit + command: >- + cd ~/core/.circleci && ./rebuild-db.sh && cd ~/core && yarn + test:coverage /unit/core-event-emitter/ --coverageDirectory + .coverage/unit/core-event-emitter - run: name: core-forger - unit command: >- @@ -587,30 +602,12 @@ jobs: cd ~/core/.circleci && ./rebuild-db.sh && cd ~/core && yarn test:coverage /unit/core-logger-pino/ --coverageDirectory .coverage/unit/core-logger-pino - - run: - name: core-p2p - unit - command: >- - cd ~/core/.circleci && ./rebuild-db.sh && cd ~/core && yarn - test:coverage /unit/core-p2p/ --coverageDirectory - .coverage/unit/core-p2p - - run: - name: core-snapshots - unit - command: >- - cd ~/core/.circleci && ./rebuild-db.sh && cd ~/core && yarn - test:coverage /unit/core-snapshots/ --coverageDirectory - .coverage/unit/core-snapshots - run: name: core-json-rpc - integration command: >- cd ~/core/.circleci && ./rebuild-db.sh && cd ~/core && yarn test:coverage /integration/core-json-rpc/ --coverageDirectory .coverage/integration/core-json-rpc - - run: - name: core-p2p - integration - command: >- - cd ~/core/.circleci && ./rebuild-db.sh && cd ~/core && yarn - test:coverage /integration/core-p2p/ --coverageDirectory - .coverage/integration/core-p2p - run: name: Last 1000 lines of test output when: on_fail @@ -662,6 +659,7 @@ jobs: - ./packages/core-container/node_modules - ./packages/core-database/node_modules - ./packages/core-database-postgres/node_modules + - ./packages/core-debugger-cli/node_modules - ./packages/core-elasticsearch/node_modules - ./packages/core-error-tracker-bugsnag/node_modules - ./packages/core-error-tracker-sentry/node_modules @@ -674,8 +672,10 @@ jobs: - ./packages/core-json-rpc/node_modules - ./packages/core-logger/node_modules - ./packages/core-logger-pino/node_modules + - ./packages/core-logger-winston/node_modules - ./packages/core-p2p/node_modules - ./packages/core-snapshots/node_modules + - ./packages/core-test-utils/node_modules - ./packages/core-tester-cli/node_modules - ./packages/core-transaction-pool/node_modules - ./packages/core-utils/node_modules @@ -686,6 +686,18 @@ jobs: - run: name: Create .core/database directory command: mkdir -p $HOME/.core/database + - run: + name: core-p2p - unit + command: >- + cd ~/core/.circleci && ./rebuild-db.sh && cd ~/core && yarn + test:coverage /unit/core-p2p/ --coverageDirectory + .coverage/unit/core-p2p + - run: + name: core-snapshots - unit + command: >- + cd ~/core/.circleci && ./rebuild-db.sh && cd ~/core && yarn + test:coverage /unit/core-snapshots/ --coverageDirectory + .coverage/unit/core-snapshots - run: name: core-tester-cli - unit command: >- @@ -722,6 +734,12 @@ jobs: cd ~/core/.circleci && ./rebuild-db.sh && cd ~/core && yarn test:coverage /unit/crypto/ --coverageDirectory .coverage/unit/crypto + - run: + name: core-p2p - integration + command: >- + cd ~/core/.circleci && ./rebuild-db.sh && cd ~/core && yarn + test:coverage /integration/core-p2p/ --coverageDirectory + .coverage/integration/core-p2p - run: name: core-transaction-pool - integration command: >- diff --git a/__tests__/unit/core-tester-cli/__fixtures__/block.json b/__tests__/unit/core-tester-cli/__fixtures__/block.json index d1228aa285..ec148aa9e2 100644 --- a/__tests__/unit/core-tester-cli/__fixtures__/block.json +++ b/__tests__/unit/core-tester-cli/__fixtures__/block.json @@ -24,7 +24,7 @@ "vendorField": "Goose Voter - True Block Weight", "senderPublicKey": "0265c1f6b8c1966a90f3fed7bc32fd4f42238ab4938fdb2a4e7ddd01ae8b58b4c0", "signature": "304402204f12469157b19edd06ba25fcad3d4a5ef5b057c23f9e02de4641e6f8eef0553e022010121ab282f83efe1043de9c16bbf2c6845a03684229a0d7c965ffb9abdfb978", - "signSignature": "30450221008327862f0b9178d6665f7d6674978c5caf749649558d814244b1c66cdf945c40022015918134ef01fed3fe2a2efde3327917731344332724522c75c2799a14f78717", + "secondSignature": "30450221008327862f0b9178d6665f7d6674978c5caf749649558d814244b1c66cdf945c40022015918134ef01fed3fe2a2efde3327917731344332724522c75c2799a14f78717", "id": "170543154a3b79459cbaa529f9f62b6f1342682799eb549dbf09fcca2d1f9c11", "senderId": "DB8LnnQqYvHpG4WkGJ9AJWBYEct7G3yRZg", "hop": 2, @@ -41,7 +41,7 @@ "vendorField": "Goose Voter - True Block Weight", "senderPublicKey": "0265c1f6b8c1966a90f3fed7bc32fd4f42238ab4938fdb2a4e7ddd01ae8b58b4c0", "signature": "304402205f82feb8c5d1d79c565c2ff7badb93e4c9827b132d135dda11cb25427d4ef8ac02205ff136f970533c4ec4c7d0cd1ea7e02d7b62629b66c6c93265f608d7f2389727", - "signSignature": "304402207e912031fcc700d8a55fbc415993302a0d8e6aea128397141b640b6dba52331702201fd1ad3984e42af44f548907add6cb7ad72ca0070c8cc1d8dc9bbda208c56bd9", + "secondSignature": "304402207e912031fcc700d8a55fbc415993302a0d8e6aea128397141b640b6dba52331702201fd1ad3984e42af44f548907add6cb7ad72ca0070c8cc1d8dc9bbda208c56bd9", "id": "1da153f37eceda233ff1b407ac18e47b3cae47c14cdcd5297d929618a916c4a7", "senderId": "DB8LnnQqYvHpG4WkGJ9AJWBYEct7G3yRZg", "hop": 2, @@ -58,7 +58,7 @@ "vendorField": "Goose Voter - True Block Weight", "senderPublicKey": "0265c1f6b8c1966a90f3fed7bc32fd4f42238ab4938fdb2a4e7ddd01ae8b58b4c0", "signature": "304502210083216e6969e068770e6d2fe5c244881002309df84d20290ddf3f858967ed010202202a479b3da5080ea475d310ff13494654b42db75886a8808bd211b4bdb9146a7a", - "signSignature": "3045022100e1dcab3406bbeb968146a4a391909ce41df9b71592a753b001e7c2ee1d382c5102202a74aeafd4a152ec61854636fbae829c41f1416c1e0637a0809408394973099f", + "secondSignature": "3045022100e1dcab3406bbeb968146a4a391909ce41df9b71592a753b001e7c2ee1d382c5102202a74aeafd4a152ec61854636fbae829c41f1416c1e0637a0809408394973099f", "id": "1e255f07dc25ce22d900ea81663c8f00d05a7b7c061e6fc3c731b05d642fa0b9", "senderId": "DB8LnnQqYvHpG4WkGJ9AJWBYEct7G3yRZg", "hop": 2, @@ -75,7 +75,7 @@ "vendorField": "Goose Voter - True Block Weight", "senderPublicKey": "0265c1f6b8c1966a90f3fed7bc32fd4f42238ab4938fdb2a4e7ddd01ae8b58b4c0", "signature": "3045022100cd4fa9855227be11e17201419dacfbbd5d9946df8d6792a9488160025693821402207fb83969bad6a26959f437b5bb88e255b0a48eb04964d0c0d29f7ee94bd15e11", - "signSignature": "304402205f50c2991a17743d17ffbb09159cadc35a3f848044261842879ccf5be9d81c5e022023bf21c32fb6e94494104f15f8d3a942ab120d0abd6fb4c93790b68e1b307a79", + "secondSignature": "304402205f50c2991a17743d17ffbb09159cadc35a3f848044261842879ccf5be9d81c5e022023bf21c32fb6e94494104f15f8d3a942ab120d0abd6fb4c93790b68e1b307a79", "id": "66336c61d6ec623f8a1d2fd156a0fac16a4fe93bb3fba337859355c2119923a8", "senderId": "DB8LnnQqYvHpG4WkGJ9AJWBYEct7G3yRZg", "hop": 2, @@ -92,7 +92,7 @@ "vendorField": "Goose Voter - True Block Weight", "senderPublicKey": "0265c1f6b8c1966a90f3fed7bc32fd4f42238ab4938fdb2a4e7ddd01ae8b58b4c0", "signature": "30450221009c792062e13399ac6756b2e9f137194d06e106360ac0f3e24e55c7249cee0b3602205dc1d9c76d0451d1cb5a2396783a13e6d2d790ccfd49291e3d0a78349f7ea0e8", - "signSignature": "30440220083ba8a9af49b8be6e93794d71ec43ffc96a158375810e5d9f2478e71655315b0220278402ecaa1d224dab9f0f3b28295bbaea339c85c7400edafdc49df87439fc64", + "secondSignature": "30440220083ba8a9af49b8be6e93794d71ec43ffc96a158375810e5d9f2478e71655315b0220278402ecaa1d224dab9f0f3b28295bbaea339c85c7400edafdc49df87439fc64", "id": "78db36f7d79f51c67d7210ee3819dfb8d0d47b16a7484ebf55c5a055b17209a3", "senderId": "DB8LnnQqYvHpG4WkGJ9AJWBYEct7G3yRZg", "hop": 2, @@ -109,7 +109,7 @@ "vendorField": "Goose Voter - True Block Weight", "senderPublicKey": "0265c1f6b8c1966a90f3fed7bc32fd4f42238ab4938fdb2a4e7ddd01ae8b58b4c0", "signature": "3044022063c65263e42be02bd9831b375c1d76a88332f00ed0557ecc1e7d2375ca40070902206797b5932c0bad68444beb5a38daa7cadf536ee2144e0d9777b812284d14374e", - "signSignature": "3045022100b04da6692f75d43229ffd8486c1517e8952d38b4c03dfac38b6b360190a5c33e0220776622e5f09f92a1258b4a011f22181c977b622b8d1bbb2f83b42f4126d00739", + "secondSignature": "3045022100b04da6692f75d43229ffd8486c1517e8952d38b4c03dfac38b6b360190a5c33e0220776622e5f09f92a1258b4a011f22181c977b622b8d1bbb2f83b42f4126d00739", "id": "83c80bb58777bb43f5037544b44ef69f191d3548fd1b2a00bed368f9f0d694c5", "senderId": "DB8LnnQqYvHpG4WkGJ9AJWBYEct7G3yRZg", "hop": 2, @@ -126,7 +126,7 @@ "vendorField": "Goose Voter - True Block Weight", "senderPublicKey": "0265c1f6b8c1966a90f3fed7bc32fd4f42238ab4938fdb2a4e7ddd01ae8b58b4c0", "signature": "3045022100d4513c3608c2072e38e7a0e3bb8daf2cd5f7cc6fec9a5570dccd1eda696c591902202ecbbf3c9d0757be7b23c8b1cc6481c51600d158756c47fcb6f4a7f4893e31c4", - "signSignature": "304402201fed4858d0806dd32220960900a871dd2f60e1f623af75feef9b1034a9a0a46402205a29b27c63fcc3e1ee1e77ecbbf4dd6e7db09901e7a09b9fd490cd68d62392cb", + "secondSignature": "304402201fed4858d0806dd32220960900a871dd2f60e1f623af75feef9b1034a9a0a46402205a29b27c63fcc3e1ee1e77ecbbf4dd6e7db09901e7a09b9fd490cd68d62392cb", "id": "d2faf992fdd5da96d6d15038b6ddb65230338fa2096e45e44da51daad5e2f3ca", "senderId": "DB8LnnQqYvHpG4WkGJ9AJWBYEct7G3yRZg", "hop": 2, From 7b9d8e4ff21a22223a5f6db6462b7ab97a0cbd84 Mon Sep 17 00:00:00 2001 From: Brian Faust Date: Thu, 28 Feb 2019 17:14:59 +0200 Subject: [PATCH 18/18] test --- .circleci/config.yml | 114 ++++++++++++++++++------------------------- 1 file changed, 48 insertions(+), 66 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 9c089921ff..78acafff47 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -41,20 +41,17 @@ jobs: - ./packages/core-container/node_modules - ./packages/core-database/node_modules - ./packages/core-database-postgres/node_modules - - ./packages/core-debugger-cli/node_modules - ./packages/core-elasticsearch/node_modules - ./packages/core-error-tracker-bugsnag/node_modules - ./packages/core-error-tracker-sentry/node_modules - ./packages/core-event-emitter/node_modules - ./packages/core-forger/node_modules - - ./packages/core-graphql/node_modules - ./packages/core-http-utils/node_modules - ./packages/core-interfaces/node_modules - ./packages/core-jest-matchers/node_modules - ./packages/core-json-rpc/node_modules - ./packages/core-logger/node_modules - ./packages/core-logger-pino/node_modules - - ./packages/core-logger-winston/node_modules - ./packages/core-p2p/node_modules - ./packages/core-snapshots/node_modules - ./packages/core-test-utils/node_modules @@ -98,6 +95,12 @@ jobs: cd ~/core/.circleci && ./rebuild-db.sh && cd ~/core && yarn test:coverage /unit/core-database-postgres/ --coverageDirectory .coverage/unit/core-database-postgres + - run: + name: core-event-emitter - unit + command: >- + cd ~/core/.circleci && ./rebuild-db.sh && cd ~/core && yarn + test:coverage /unit/core-event-emitter/ --coverageDirectory + .coverage/unit/core-event-emitter - run: name: core-api - integration command: >- @@ -161,20 +164,17 @@ jobs: - ./packages/core-container/node_modules - ./packages/core-database/node_modules - ./packages/core-database-postgres/node_modules - - ./packages/core-debugger-cli/node_modules - ./packages/core-elasticsearch/node_modules - ./packages/core-error-tracker-bugsnag/node_modules - ./packages/core-error-tracker-sentry/node_modules - ./packages/core-event-emitter/node_modules - ./packages/core-forger/node_modules - - ./packages/core-graphql/node_modules - ./packages/core-http-utils/node_modules - ./packages/core-interfaces/node_modules - ./packages/core-jest-matchers/node_modules - ./packages/core-json-rpc/node_modules - ./packages/core-logger/node_modules - ./packages/core-logger-pino/node_modules - - ./packages/core-logger-winston/node_modules - ./packages/core-p2p/node_modules - ./packages/core-snapshots/node_modules - ./packages/core-test-utils/node_modules @@ -218,6 +218,12 @@ jobs: cd ~/core/.circleci && ./rebuild-db.sh && cd ~/core && yarn test:coverage /unit/core-database-postgres/ --coverageDirectory .coverage/unit/core-database-postgres + - run: + name: core-event-emitter - unit + command: >- + cd ~/core/.circleci && ./rebuild-db.sh && cd ~/core && yarn + test:coverage /unit/core-event-emitter/ --coverageDirectory + .coverage/unit/core-event-emitter - run: name: core-api - integration command: >- @@ -281,20 +287,17 @@ jobs: - ./packages/core-container/node_modules - ./packages/core-database/node_modules - ./packages/core-database-postgres/node_modules - - ./packages/core-debugger-cli/node_modules - ./packages/core-elasticsearch/node_modules - ./packages/core-error-tracker-bugsnag/node_modules - ./packages/core-error-tracker-sentry/node_modules - ./packages/core-event-emitter/node_modules - ./packages/core-forger/node_modules - - ./packages/core-graphql/node_modules - ./packages/core-http-utils/node_modules - ./packages/core-interfaces/node_modules - ./packages/core-jest-matchers/node_modules - ./packages/core-json-rpc/node_modules - ./packages/core-logger/node_modules - ./packages/core-logger-pino/node_modules - - ./packages/core-logger-winston/node_modules - ./packages/core-p2p/node_modules - ./packages/core-snapshots/node_modules - ./packages/core-test-utils/node_modules @@ -308,12 +311,6 @@ jobs: - run: name: Create .core/database directory command: mkdir -p $HOME/.core/database - - run: - name: core-event-emitter - unit - command: >- - cd ~/core/.circleci && ./rebuild-db.sh && cd ~/core && yarn - test:coverage /unit/core-event-emitter/ --coverageDirectory - .coverage/unit/core-event-emitter - run: name: core-forger - unit command: >- @@ -344,12 +341,30 @@ jobs: cd ~/core/.circleci && ./rebuild-db.sh && cd ~/core && yarn test:coverage /unit/core-logger-pino/ --coverageDirectory .coverage/unit/core-logger-pino + - run: + name: core-p2p - unit + command: >- + cd ~/core/.circleci && ./rebuild-db.sh && cd ~/core && yarn + test:coverage /unit/core-p2p/ --coverageDirectory + .coverage/unit/core-p2p + - run: + name: core-snapshots - unit + command: >- + cd ~/core/.circleci && ./rebuild-db.sh && cd ~/core && yarn + test:coverage /unit/core-snapshots/ --coverageDirectory + .coverage/unit/core-snapshots - run: name: core-json-rpc - integration command: >- cd ~/core/.circleci && ./rebuild-db.sh && cd ~/core && yarn test:coverage /integration/core-json-rpc/ --coverageDirectory .coverage/integration/core-json-rpc + - run: + name: core-p2p - integration + command: >- + cd ~/core/.circleci && ./rebuild-db.sh && cd ~/core && yarn + test:coverage /integration/core-p2p/ --coverageDirectory + .coverage/integration/core-p2p - run: name: Last 1000 lines of test output when: on_fail @@ -401,20 +416,17 @@ jobs: - ./packages/core-container/node_modules - ./packages/core-database/node_modules - ./packages/core-database-postgres/node_modules - - ./packages/core-debugger-cli/node_modules - ./packages/core-elasticsearch/node_modules - ./packages/core-error-tracker-bugsnag/node_modules - ./packages/core-error-tracker-sentry/node_modules - ./packages/core-event-emitter/node_modules - ./packages/core-forger/node_modules - - ./packages/core-graphql/node_modules - ./packages/core-http-utils/node_modules - ./packages/core-interfaces/node_modules - ./packages/core-jest-matchers/node_modules - ./packages/core-json-rpc/node_modules - ./packages/core-logger/node_modules - ./packages/core-logger-pino/node_modules - - ./packages/core-logger-winston/node_modules - ./packages/core-p2p/node_modules - ./packages/core-snapshots/node_modules - ./packages/core-test-utils/node_modules @@ -428,18 +440,6 @@ jobs: - run: name: Create .core/database directory command: mkdir -p $HOME/.core/database - - run: - name: core-p2p - unit - command: >- - cd ~/core/.circleci && ./rebuild-db.sh && cd ~/core && yarn - test:coverage /unit/core-p2p/ --coverageDirectory - .coverage/unit/core-p2p - - run: - name: core-snapshots - unit - command: >- - cd ~/core/.circleci && ./rebuild-db.sh && cd ~/core && yarn - test:coverage /unit/core-snapshots/ --coverageDirectory - .coverage/unit/core-snapshots - run: name: core-tester-cli - unit command: >- @@ -476,12 +476,6 @@ jobs: cd ~/core/.circleci && ./rebuild-db.sh && cd ~/core && yarn test:coverage /unit/crypto/ --coverageDirectory .coverage/unit/crypto - - run: - name: core-p2p - integration - command: >- - cd ~/core/.circleci && ./rebuild-db.sh && cd ~/core && yarn - test:coverage /integration/core-p2p/ --coverageDirectory - .coverage/integration/core-p2p - run: name: core-transaction-pool - integration command: >- @@ -539,20 +533,17 @@ jobs: - ./packages/core-container/node_modules - ./packages/core-database/node_modules - ./packages/core-database-postgres/node_modules - - ./packages/core-debugger-cli/node_modules - ./packages/core-elasticsearch/node_modules - ./packages/core-error-tracker-bugsnag/node_modules - ./packages/core-error-tracker-sentry/node_modules - ./packages/core-event-emitter/node_modules - ./packages/core-forger/node_modules - - ./packages/core-graphql/node_modules - ./packages/core-http-utils/node_modules - ./packages/core-interfaces/node_modules - ./packages/core-jest-matchers/node_modules - ./packages/core-json-rpc/node_modules - ./packages/core-logger/node_modules - ./packages/core-logger-pino/node_modules - - ./packages/core-logger-winston/node_modules - ./packages/core-p2p/node_modules - ./packages/core-snapshots/node_modules - ./packages/core-test-utils/node_modules @@ -566,12 +557,6 @@ jobs: - run: name: Create .core/database directory command: mkdir -p $HOME/.core/database - - run: - name: core-event-emitter - unit - command: >- - cd ~/core/.circleci && ./rebuild-db.sh && cd ~/core && yarn - test:coverage /unit/core-event-emitter/ --coverageDirectory - .coverage/unit/core-event-emitter - run: name: core-forger - unit command: >- @@ -602,12 +587,30 @@ jobs: cd ~/core/.circleci && ./rebuild-db.sh && cd ~/core && yarn test:coverage /unit/core-logger-pino/ --coverageDirectory .coverage/unit/core-logger-pino + - run: + name: core-p2p - unit + command: >- + cd ~/core/.circleci && ./rebuild-db.sh && cd ~/core && yarn + test:coverage /unit/core-p2p/ --coverageDirectory + .coverage/unit/core-p2p + - run: + name: core-snapshots - unit + command: >- + cd ~/core/.circleci && ./rebuild-db.sh && cd ~/core && yarn + test:coverage /unit/core-snapshots/ --coverageDirectory + .coverage/unit/core-snapshots - run: name: core-json-rpc - integration command: >- cd ~/core/.circleci && ./rebuild-db.sh && cd ~/core && yarn test:coverage /integration/core-json-rpc/ --coverageDirectory .coverage/integration/core-json-rpc + - run: + name: core-p2p - integration + command: >- + cd ~/core/.circleci && ./rebuild-db.sh && cd ~/core && yarn + test:coverage /integration/core-p2p/ --coverageDirectory + .coverage/integration/core-p2p - run: name: Last 1000 lines of test output when: on_fail @@ -659,20 +662,17 @@ jobs: - ./packages/core-container/node_modules - ./packages/core-database/node_modules - ./packages/core-database-postgres/node_modules - - ./packages/core-debugger-cli/node_modules - ./packages/core-elasticsearch/node_modules - ./packages/core-error-tracker-bugsnag/node_modules - ./packages/core-error-tracker-sentry/node_modules - ./packages/core-event-emitter/node_modules - ./packages/core-forger/node_modules - - ./packages/core-graphql/node_modules - ./packages/core-http-utils/node_modules - ./packages/core-interfaces/node_modules - ./packages/core-jest-matchers/node_modules - ./packages/core-json-rpc/node_modules - ./packages/core-logger/node_modules - ./packages/core-logger-pino/node_modules - - ./packages/core-logger-winston/node_modules - ./packages/core-p2p/node_modules - ./packages/core-snapshots/node_modules - ./packages/core-test-utils/node_modules @@ -686,18 +686,6 @@ jobs: - run: name: Create .core/database directory command: mkdir -p $HOME/.core/database - - run: - name: core-p2p - unit - command: >- - cd ~/core/.circleci && ./rebuild-db.sh && cd ~/core && yarn - test:coverage /unit/core-p2p/ --coverageDirectory - .coverage/unit/core-p2p - - run: - name: core-snapshots - unit - command: >- - cd ~/core/.circleci && ./rebuild-db.sh && cd ~/core && yarn - test:coverage /unit/core-snapshots/ --coverageDirectory - .coverage/unit/core-snapshots - run: name: core-tester-cli - unit command: >- @@ -734,12 +722,6 @@ jobs: cd ~/core/.circleci && ./rebuild-db.sh && cd ~/core && yarn test:coverage /unit/crypto/ --coverageDirectory .coverage/unit/crypto - - run: - name: core-p2p - integration - command: >- - cd ~/core/.circleci && ./rebuild-db.sh && cd ~/core && yarn - test:coverage /integration/core-p2p/ --coverageDirectory - .coverage/integration/core-p2p - run: name: core-transaction-pool - integration command: >-