Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 0 additions & 15 deletions packages/core-tester-cli/__tests__/commands/command.test.ts

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -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: [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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: [
Expand Down
6 changes: 2 additions & 4 deletions packages/core-tester-cli/__tests__/commands/vote.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: [
Expand Down Expand Up @@ -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: [
Expand Down
19 changes: 19 additions & 0 deletions packages/core-tester-cli/src/commands/command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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, any>): 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);
}
}
15 changes: 7 additions & 8 deletions packages/core-tester-cli/src/commands/delegate-registration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,17 @@ export class DelegateRegistrationCommand extends BaseCommand {
* @return {void}
*/
public async run(): Promise<void> {
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();
Expand Down
19 changes: 11 additions & 8 deletions packages/core-tester-cli/src/commands/multi-signature.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ export class MultiSignatureCommand extends BaseCommand {
* @return {void}
*/
public async run(): Promise<void> {
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}`);
Expand All @@ -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);
Expand Down
15 changes: 7 additions & 8 deletions packages/core-tester-cli/src/commands/second-signature.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,17 @@ export class SecondSignatureCommand extends BaseCommand {
* @return {void}
*/
public async run(): Promise<void> {
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)}`);
Expand Down
7 changes: 5 additions & 2 deletions packages/core-tester-cli/src/commands/vote.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,15 @@ export class VoteCommand extends BaseCommand {
* @return {void}
*/
public async run(): Promise<void> {
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;
Expand Down
2 changes: 1 addition & 1 deletion packages/core-tester-cli/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
}
Expand Down