diff --git a/packages/core-tester-cli/__tests__/commands/command.test.ts b/packages/core-tester-cli/__tests__/commands/command.test.ts deleted file mode 100644 index 4753621140..0000000000 --- a/packages/core-tester-cli/__tests__/commands/command.test.ts +++ /dev/null @@ -1,15 +0,0 @@ -import "jest-extended"; - -import axios from "axios"; -import MockAdapter from "axios-mock-adapter"; -import { BaseCommand } from "../../src/commands/command"; - -const mockAxios = new MockAdapter(axios); - -beforeEach(() => { - mockAxios.reset(); -}); - -describe("Command Base", () => { - it.skip("", () => false); -}); 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 933ca3e913..4fd7f335bc 100644 --- a/packages/core-tester-cli/__tests__/commands/delegate-registration.test.ts +++ b/packages/core-tester-cli/__tests__/commands/delegate-registration.test.ts @@ -41,8 +41,7 @@ describe("Commands - Delegate Registration", () => { const flags = toFlags(opts); await DelegateRegistrationCommand.run(flags); - expect(axios.post).toHaveBeenNthCalledWith( - 4, + expect(axios.post).toHaveBeenCalledWith( "http://localhost:4003/api/v2/transactions", { transactions: [ 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 52f427431a..cb600ec464 100644 --- a/packages/core-tester-cli/__tests__/commands/second-signature.test.ts +++ b/packages/core-tester-cli/__tests__/commands/second-signature.test.ts @@ -32,8 +32,7 @@ describe("Commands - Second signature", () => { const flags = toFlags(opts); await SecondSignatureCommand.run(flags); - expect(axios.post).toHaveBeenNthCalledWith( - 4, + expect(axios.post).toHaveBeenCalledWith( "http://localhost:4003/api/v2/transactions", { transactions: [ diff --git a/packages/core-tester-cli/__tests__/commands/vote.test.ts b/packages/core-tester-cli/__tests__/commands/vote.test.ts index acfd94b706..0488bdc1eb 100644 --- a/packages/core-tester-cli/__tests__/commands/vote.test.ts +++ b/packages/core-tester-cli/__tests__/commands/vote.test.ts @@ -37,8 +37,7 @@ describe("Commands - Vote", () => { const flags = toFlags(opts); await VoteCommand.run(flags); - expect(axios.post).toHaveBeenNthCalledWith( - 4, + expect(axios.post).toHaveBeenCalledWith( "http://localhost:4003/api/v2/transactions", { transactions: [ @@ -72,8 +71,7 @@ describe("Commands - Vote", () => { const flags = toFlags(opts); await VoteCommand.run(flags); - expect(axios.post).toHaveBeenNthCalledWith( - 4, + expect(axios.post).toHaveBeenCalledWith( "http://localhost:4003/api/v2/transactions", { transactions: [ diff --git a/packages/core-tester-cli/src/commands/command.ts b/packages/core-tester-cli/src/commands/command.ts index 208133a5da..a42858a8cd 100644 --- a/packages/core-tester-cli/src/commands/command.ts +++ b/packages/core-tester-cli/src/commands/command.ts @@ -315,4 +315,23 @@ export abstract class BaseCommand extends Command { 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); + } } diff --git a/packages/core-tester-cli/src/commands/delegate-registration.ts b/packages/core-tester-cli/src/commands/delegate-registration.ts index e94293ef4a..7ccf5dc6ee 100644 --- a/packages/core-tester-cli/src/commands/delegate-registration.ts +++ b/packages/core-tester-cli/src/commands/delegate-registration.ts @@ -23,18 +23,17 @@ export class DelegateRegistrationCommand extends BaseCommand { * @return {void} */ public async run(): Promise { - await this.initialize(DelegateRegistrationCommand); + // 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", - ]); + await TransferCommand.run( + ["--amount", String(this.options.amount || 25), "--recipient", wallet.address, "--skipTesting"].concat( + this.castFlags(flags), + ), + ); } const delegates = await this.getDelegates(); diff --git a/packages/core-tester-cli/src/commands/multi-signature.ts b/packages/core-tester-cli/src/commands/multi-signature.ts index 5d16487b82..adb4b97012 100644 --- a/packages/core-tester-cli/src/commands/multi-signature.ts +++ b/packages/core-tester-cli/src/commands/multi-signature.ts @@ -38,7 +38,8 @@ export class MultiSignatureCommand extends BaseCommand { * @return {void} */ public async run(): Promise { - this.initialize(MultiSignatureCommand); + // 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}`); @@ -48,13 +49,15 @@ export class MultiSignatureCommand extends BaseCommand { const wallets = this.generateWallets(); for (const wallet of wallets) { - await TransferCommand.run([ - "--recipient", - wallet.address, - "--amount", - (publicKeys.length + 1) * 5 + testCosts, - "--skipTesting", - ]); + 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); diff --git a/packages/core-tester-cli/src/commands/second-signature.ts b/packages/core-tester-cli/src/commands/second-signature.ts index faed947cfc..5cc3325a9d 100644 --- a/packages/core-tester-cli/src/commands/second-signature.ts +++ b/packages/core-tester-cli/src/commands/second-signature.ts @@ -22,18 +22,17 @@ export class SecondSignatureCommand extends BaseCommand { * @return {void} */ public async run(): Promise { - await this.initialize(SecondSignatureCommand); + // 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", - ]); + 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)}`); diff --git a/packages/core-tester-cli/src/commands/vote.ts b/packages/core-tester-cli/src/commands/vote.ts index b5a5d092dd..d8a4941f81 100644 --- a/packages/core-tester-cli/src/commands/vote.ts +++ b/packages/core-tester-cli/src/commands/vote.ts @@ -26,12 +26,15 @@ export class VoteCommand extends BaseCommand { * @return {void} */ public async run(): Promise { - await this.initialize(VoteCommand); + // 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"]); + await TransferCommand.run( + ["--recipient", wallet.address, "--amount", String(2), "--skipTesting"].concat(this.castFlags(flags)), + ); } let delegate = this.options.delegate; diff --git a/packages/core-tester-cli/src/utils.ts b/packages/core-tester-cli/src/utils.ts index e02ecc8312..6af7ea0894 100644 --- a/packages/core-tester-cli/src/utils.ts +++ b/packages/core-tester-cli/src/utils.ts @@ -13,7 +13,7 @@ export function request(config) { const headers: any = {}; if (config && config.network) { headers.nethash = config.network.nethash; - headers.version = "2.0.0"; + headers.version = "2.1.0"; headers.port = config.p2pPort; headers["Content-Type"] = "application/json"; }