From d22c82669aba78612c7f6dfb5938d92b6452c2a6 Mon Sep 17 00:00:00 2001 From: Brian Faust Date: Mon, 11 Mar 2019 09:26:58 +0200 Subject: [PATCH 01/15] feat(core-tester-cli): add make:block command --- .circleci/config.yml | 90 +++++++++------- .../commands/make/block.test.ts | 59 +++++++++++ .../src/commands/make/block.ts | 100 ++++++++++++++++++ 3 files changed, 213 insertions(+), 36 deletions(-) create mode 100644 __tests__/integration/core-tester-cli/commands/make/block.test.ts create mode 100644 packages/core-tester-cli/src/commands/make/block.ts diff --git a/.circleci/config.yml b/.circleci/config.yml index eac4f6ec65..63f2d0c189 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -47,14 +47,17 @@ jobs: - ./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 - ./packages/core-tester-cli/node_modules - ./packages/core-transaction-pool/node_modules - ./packages/core-transactions/node_modules @@ -165,14 +168,17 @@ jobs: - ./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 - ./packages/core-tester-cli/node_modules - ./packages/core-transaction-pool/node_modules - ./packages/core-transactions/node_modules @@ -283,14 +289,17 @@ jobs: - ./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 - ./packages/core-tester-cli/node_modules - ./packages/core-transaction-pool/node_modules - ./packages/core-transactions/node_modules @@ -338,18 +347,6 @@ 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-forger - integration command: >- @@ -362,12 +359,6 @@ jobs: 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 @@ -425,14 +416,17 @@ jobs: - ./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 - ./packages/core-tester-cli/node_modules - ./packages/core-transaction-pool/node_modules - ./packages/core-transactions/node_modules @@ -444,6 +438,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-transaction-pool - unit command: >- @@ -474,6 +480,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-tester-cli - integration command: >- @@ -555,14 +567,17 @@ jobs: - ./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 - ./packages/core-tester-cli/node_modules - ./packages/core-transaction-pool/node_modules - ./packages/core-transactions/node_modules @@ -610,18 +625,6 @@ 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-forger - integration command: >- @@ -634,12 +637,6 @@ jobs: 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 @@ -697,14 +694,17 @@ jobs: - ./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 - ./packages/core-tester-cli/node_modules - ./packages/core-transaction-pool/node_modules - ./packages/core-transactions/node_modules @@ -716,6 +716,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-transaction-pool - unit command: >- @@ -746,6 +758,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-tester-cli - integration command: >- diff --git a/__tests__/integration/core-tester-cli/commands/make/block.test.ts b/__tests__/integration/core-tester-cli/commands/make/block.test.ts new file mode 100644 index 0000000000..1a32d36bbf --- /dev/null +++ b/__tests__/integration/core-tester-cli/commands/make/block.test.ts @@ -0,0 +1,59 @@ +import "jest-extended"; + +import axios from "axios"; +import MockAdapter from "axios-mock-adapter"; +import { BlockCommand } from "../../../../../packages/core-tester-cli/dist/commands/make/block"; + +const mockAxios = new MockAdapter(axios); + +beforeEach(() => { + // Just passthru. We'll test the Command class logic in its own test file more thoroughly + mockAxios.onGet("http://localhost:4003/api/v2/node/configuration").reply(200, { data: { constants: {} } }); + mockAxios.onGet("http://localhost:4000/config").reply(200, { data: { network: { version: 23 } } }); +}); + +afterEach(() => { + mockAxios.reset(); +}); + +afterAll(() => mockAxios.restore()); + +describe("make:block", () => { + it("should generate 1 block with default flags", async () => { + const blocks = await BlockCommand.run([]); + + expect(blocks).toHaveLength(1); + + expect(blocks[0].data.generatorPublicKey).toBe( + "03287bfebba4c7881a0509717e71b34b63f31e40021c321f89ae04f84be6d6ac37", + ); + }); + + it("should generate 1 block with 10 transactions", async () => { + const blocks = await BlockCommand.run(["--transactions=10"]); + + expect(blocks[0].transactions).toHaveLength(10); + }); + + it("should generate 10 blocks", async () => { + const blocks = await BlockCommand.run(["--number=10"]); + + expect(blocks).toHaveLength(10); + }); + + it("should generate 10 blocks with 10 transactions", async () => { + const blocks = await BlockCommand.run(["--transactions=10"]); + + for (const block of blocks) { + expect(block.transactions).toHaveLength(10); + } + }); + + it("should generate a block with a custom passphrase", async () => { + const blocks = await BlockCommand.run(["--passphrase=123"]); + + expect(blocks[0].data.generatorPublicKey).toBe( + "03be686ed7f0539affbaf634f3bcc2b235e8e220e7be57e9397ab1c14c39137eb4", + ); + }); +}); diff --git a/packages/core-tester-cli/src/commands/make/block.ts b/packages/core-tester-cli/src/commands/make/block.ts new file mode 100644 index 0000000000..9255942edf --- /dev/null +++ b/packages/core-tester-cli/src/commands/make/block.ts @@ -0,0 +1,100 @@ +import { bignumify } from "@arkecosystem/core-utils"; +import { Address, configManager, models, slots } from "@arkecosystem/crypto"; +import { flags } from "@oclif/command"; +import delay from "delay"; +import { writeFileSync } from "fs"; +import { satoshiFlag } from "../../flags"; +import { copyToClipboard } from "../../utils"; +import { BaseCommand } from "../command"; + +export class BlockCommand extends BaseCommand { + public static description: string = "send multiple transactions"; + + public static flags = { + ...BaseCommand.flagsConfig, + number: flags.integer({ + description: "number of blocks to generate", + default: 1, + }), + transactions: flags.integer({ + description: "number of transactions to generate", + default: 0, + }), + transactionAmount: satoshiFlag({ + description: "initial wallet token amount", + default: 2, + }), + transactionFee: satoshiFlag({ + description: "transfer fee", + default: 0.1, + }), + passphrase: flags.string({ + description: "passphrase of the forger", + default: "clay harbor enemy utility margin pretty hub comic piece aerobic umbrella acquire", + }), + log: flags.boolean({ + description: "write the blocks to the CLI", + }), + copy: flags.boolean({ + description: "write the blocks to the clipboard", + }), + write: flags.boolean({ + description: "write the blocks to the disk", + }), + }; + + public async run(): Promise { + const { flags } = await this.make(BlockCommand); + + configManager.setFromPreset("unitnet"); + + // We always start with the genesis block! + let previousBlock = configManager.get("genesisBlock"); + + const blocks: models.IBlock[] = []; + + for (let i = 0; i < flags.number; i++) { + const milestone = configManager.getMilestone(previousBlock.height); + const delegate = new models.Delegate(flags.passphrase, configManager.get("pubKeyHash")); + + const transactions = []; + for (let i = 0; i < flags.transactions; i++) { + transactions.push( + this.signer.makeTransfer({ + ...flags, + ...{ + amount: flags.transactionAmount + 10, + transferFee: flags.transactionFee, + recipient: Address.fromPassphrase(flags.passphrase), + }, + }), + ); + + await delay(100); + } + + const newBlock = await delegate.forge(transactions, { + previousBlock, + timestamp: slots.getSlotNumber(slots.getTime()) * milestone.blocktime, + reward: milestone.reward, + }); + previousBlock = newBlock.data; + + blocks.push(newBlock); + } + + if (flags.log) { + console.log(JSON.stringify(blocks, null, 4)); + } + + if (flags.copy) { + copyToClipboard(JSON.stringify(blocks, null, 4)); + } + + if (flags.write) { + writeFileSync("./blocks.json", JSON.stringify(blocks)); + } + + return blocks; + } +} From b1d3297d9ca866568fc4aad55810e355ec8b2c91 Mon Sep 17 00:00:00 2001 From: Brian Faust Date: Mon, 11 Mar 2019 09:29:56 +0200 Subject: [PATCH 02/15] chore: update CircleCI config --- .circleci/config.yml | 90 ++++++++++++++++++-------------------------- 1 file changed, 36 insertions(+), 54 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 63f2d0c189..eac4f6ec65 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -47,17 +47,14 @@ jobs: - ./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 - ./packages/core-tester-cli/node_modules - ./packages/core-transaction-pool/node_modules - ./packages/core-transactions/node_modules @@ -168,17 +165,14 @@ jobs: - ./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 - ./packages/core-tester-cli/node_modules - ./packages/core-transaction-pool/node_modules - ./packages/core-transactions/node_modules @@ -289,17 +283,14 @@ jobs: - ./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 - ./packages/core-tester-cli/node_modules - ./packages/core-transaction-pool/node_modules - ./packages/core-transactions/node_modules @@ -347,6 +338,18 @@ 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-forger - integration command: >- @@ -359,6 +362,12 @@ jobs: 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,17 +425,14 @@ jobs: - ./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 - ./packages/core-tester-cli/node_modules - ./packages/core-transaction-pool/node_modules - ./packages/core-transactions/node_modules @@ -438,18 +444,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-transaction-pool - unit command: >- @@ -480,12 +474,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-tester-cli - integration command: >- @@ -567,17 +555,14 @@ jobs: - ./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 - ./packages/core-tester-cli/node_modules - ./packages/core-transaction-pool/node_modules - ./packages/core-transactions/node_modules @@ -625,6 +610,18 @@ 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-forger - integration command: >- @@ -637,6 +634,12 @@ jobs: 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 @@ -694,17 +697,14 @@ jobs: - ./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 - ./packages/core-tester-cli/node_modules - ./packages/core-transaction-pool/node_modules - ./packages/core-transactions/node_modules @@ -716,18 +716,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-transaction-pool - unit command: >- @@ -758,12 +746,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-tester-cli - integration command: >- From 925fcbabad508b9446a7081a08a3651eb84d0825 Mon Sep 17 00:00:00 2001 From: Brian Faust Date: Mon, 11 Mar 2019 09:34:23 +0200 Subject: [PATCH 03/15] test(core-tester-cli): pass in unitnet as network --- .../core-tester-cli/commands/make/block.test.ts | 10 +++++----- packages/core-tester-cli/src/commands/make/block.ts | 12 +++--------- 2 files changed, 8 insertions(+), 14 deletions(-) diff --git a/__tests__/integration/core-tester-cli/commands/make/block.test.ts b/__tests__/integration/core-tester-cli/commands/make/block.test.ts index 1a32d36bbf..580d154637 100644 --- a/__tests__/integration/core-tester-cli/commands/make/block.test.ts +++ b/__tests__/integration/core-tester-cli/commands/make/block.test.ts @@ -20,7 +20,7 @@ afterAll(() => mockAxios.restore()); describe("make:block", () => { it("should generate 1 block with default flags", async () => { - const blocks = await BlockCommand.run([]); + const blocks = await BlockCommand.run(["--network=unitnet"]); expect(blocks).toHaveLength(1); @@ -30,19 +30,19 @@ describe("make:block", () => { }); it("should generate 1 block with 10 transactions", async () => { - const blocks = await BlockCommand.run(["--transactions=10"]); + const blocks = await BlockCommand.run(["--network=unitnet", "--transactions=10"]); expect(blocks[0].transactions).toHaveLength(10); }); it("should generate 10 blocks", async () => { - const blocks = await BlockCommand.run(["--number=10"]); + const blocks = await BlockCommand.run(["--network=unitnet", "--number=10"]); expect(blocks).toHaveLength(10); }); it("should generate 10 blocks with 10 transactions", async () => { - const blocks = await BlockCommand.run(["--transactions=10"]); + const blocks = await BlockCommand.run(["--network=unitnet", "--transactions=10"]); for (const block of blocks) { expect(block.transactions).toHaveLength(10); @@ -50,7 +50,7 @@ describe("make:block", () => { }); it("should generate a block with a custom passphrase", async () => { - const blocks = await BlockCommand.run(["--passphrase=123"]); + const blocks = await BlockCommand.run(["--network=unitnet", "--passphrase=123"]); expect(blocks[0].data.generatorPublicKey).toBe( "03be686ed7f0539affbaf634f3bcc2b235e8e220e7be57e9397ab1c14c39137eb4", diff --git a/packages/core-tester-cli/src/commands/make/block.ts b/packages/core-tester-cli/src/commands/make/block.ts index 9255942edf..2c3330a4da 100644 --- a/packages/core-tester-cli/src/commands/make/block.ts +++ b/packages/core-tester-cli/src/commands/make/block.ts @@ -1,5 +1,4 @@ -import { bignumify } from "@arkecosystem/core-utils"; -import { Address, configManager, models, slots } from "@arkecosystem/crypto"; +import { Address, configManager, models, NetworkName, slots } from "@arkecosystem/crypto"; import { flags } from "@oclif/command"; import delay from "delay"; import { writeFileSync } from "fs"; @@ -12,6 +11,7 @@ export class BlockCommand extends BaseCommand { public static flags = { ...BaseCommand.flagsConfig, + ...BaseCommand.flagsDebug, number: flags.integer({ description: "number of blocks to generate", default: 1, @@ -32,12 +32,6 @@ export class BlockCommand extends BaseCommand { description: "passphrase of the forger", default: "clay harbor enemy utility margin pretty hub comic piece aerobic umbrella acquire", }), - log: flags.boolean({ - description: "write the blocks to the CLI", - }), - copy: flags.boolean({ - description: "write the blocks to the clipboard", - }), write: flags.boolean({ description: "write the blocks to the disk", }), @@ -46,7 +40,7 @@ export class BlockCommand extends BaseCommand { public async run(): Promise { const { flags } = await this.make(BlockCommand); - configManager.setFromPreset("unitnet"); + configManager.setFromPreset(flags.network as NetworkName); // We always start with the genesis block! let previousBlock = configManager.get("genesisBlock"); From 638394f34f4f65898bec942b1eb49ad295594068 Mon Sep 17 00:00:00 2001 From: Vasil Dimov Date: Mon, 11 Mar 2019 14:28:58 +0100 Subject: [PATCH 04/15] feat(core-tester-cli): Make it possible to override the base block Add the ability to manually set the block on which newly generated blocks will be based. --- packages/core-tester-cli/src/commands/make/block.ts | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/packages/core-tester-cli/src/commands/make/block.ts b/packages/core-tester-cli/src/commands/make/block.ts index 2c3330a4da..a27c07a572 100644 --- a/packages/core-tester-cli/src/commands/make/block.ts +++ b/packages/core-tester-cli/src/commands/make/block.ts @@ -32,6 +32,10 @@ export class BlockCommand extends BaseCommand { description: "passphrase of the forger", default: "clay harbor enemy utility margin pretty hub comic piece aerobic umbrella acquire", }), + previousBlock: flags.string({ + description: `Previous block to base the generated block(s) on. For example: '{ "height": 50, "id": "123", "idHex": "7b" }'`, + default: "The genesis block" + }), write: flags.boolean({ description: "write the blocks to the disk", }), @@ -42,8 +46,12 @@ export class BlockCommand extends BaseCommand { configManager.setFromPreset(flags.network as NetworkName); - // We always start with the genesis block! - let previousBlock = configManager.get("genesisBlock"); + let previousBlock + if (flags.previousBlock) { + previousBlock = JSON.parse(flags.previousBlock); + } else { + previousBlock = configManager.get("genesisBlock"); + } const blocks: models.IBlock[] = []; From 39d96ce8318ae7ca53b5c0fbd852313f8f8ae55e Mon Sep 17 00:00:00 2001 From: Brian Faust Date: Mon, 11 Mar 2019 16:48:58 +0200 Subject: [PATCH 05/15] fix(core-tester-cli): remove default of previousBlock --- packages/core-tester-cli/src/commands/make/block.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/core-tester-cli/src/commands/make/block.ts b/packages/core-tester-cli/src/commands/make/block.ts index a27c07a572..7ca4595ddd 100644 --- a/packages/core-tester-cli/src/commands/make/block.ts +++ b/packages/core-tester-cli/src/commands/make/block.ts @@ -34,7 +34,6 @@ export class BlockCommand extends BaseCommand { }), previousBlock: flags.string({ description: `Previous block to base the generated block(s) on. For example: '{ "height": 50, "id": "123", "idHex": "7b" }'`, - default: "The genesis block" }), write: flags.boolean({ description: "write the blocks to the disk", From 08505903cee9114280facb75e9c90ab877c70a0c Mon Sep 17 00:00:00 2001 From: Brian Faust Date: Tue, 12 Mar 2019 06:29:34 +0200 Subject: [PATCH 06/15] feat(core-tester-cli): allow offline usage --- package.json | 4 +++- packages/core-tester-cli/src/commands/command.ts | 12 +++++++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index bdc4700c13..084a9038fc 100644 --- a/package.json +++ b/package.json @@ -123,6 +123,8 @@ "!**/node_modules/**" ], "watchman": false, - "setupTestFrameworkScriptFile": "jest-extended" + "setupFilesAfterEnv": [ + "jest-extended" + ] } } diff --git a/packages/core-tester-cli/src/commands/command.ts b/packages/core-tester-cli/src/commands/command.ts index 2b79a87801..5b0c121b0c 100644 --- a/packages/core-tester-cli/src/commands/command.ts +++ b/packages/core-tester-cli/src/commands/command.ts @@ -1,5 +1,5 @@ import { bignumify } from "@arkecosystem/core-utils"; -import { Address, Bignum, formatSatoshi } from "@arkecosystem/crypto"; +import { Address, Bignum, configManager, formatSatoshi, NetworkName } from "@arkecosystem/crypto"; import Command, { flags } from "@oclif/command"; import delay from "delay"; import { satoshiFlag } from "../flags"; @@ -86,6 +86,16 @@ export abstract class BaseCommand extends Command { return { args, flags }; } + protected makeWithoutNetwork(command): any { + const { args, flags } = this.parse(command); + + configManager.setFromPreset(flags.network as NetworkName); + + this.signer = new Signer(configManager.all()); + + return { args, flags }; + } + protected async sendTransaction(transactions: any[]): Promise> { if (!Array.isArray(transactions)) { transactions = [transactions]; From 2ceda9b9ae604cac0fbfd09578ab439de8bafb28 Mon Sep 17 00:00:00 2001 From: Brian Faust Date: Tue, 12 Mar 2019 06:30:10 +0200 Subject: [PATCH 07/15] fix(core-tester-cli): use random recipient to avoid duplicate transactions --- .../core-tester-cli/src/commands/make/block.ts | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/packages/core-tester-cli/src/commands/make/block.ts b/packages/core-tester-cli/src/commands/make/block.ts index 7ca4595ddd..f5ab516e35 100644 --- a/packages/core-tester-cli/src/commands/make/block.ts +++ b/packages/core-tester-cli/src/commands/make/block.ts @@ -41,16 +41,12 @@ export class BlockCommand extends BaseCommand { }; public async run(): Promise { - const { flags } = await this.make(BlockCommand); + const { flags } = this.makeWithoutNetwork(BlockCommand); - configManager.setFromPreset(flags.network as NetworkName); + const genesisBlock = configManager.get("genesisBlock"); + const genesisWallets = genesisBlock.transactions.map(t => t.recipientId).filter(a => !!a); - let previousBlock - if (flags.previousBlock) { - previousBlock = JSON.parse(flags.previousBlock); - } else { - previousBlock = configManager.get("genesisBlock"); - } + let previousBlock = flags.previousBlock ? JSON.parse(flags.previousBlock) : genesisBlock; const blocks: models.IBlock[] = []; @@ -64,14 +60,12 @@ export class BlockCommand extends BaseCommand { this.signer.makeTransfer({ ...flags, ...{ - amount: flags.transactionAmount + 10, + amount: flags.transactionAmount + i, transferFee: flags.transactionFee, - recipient: Address.fromPassphrase(flags.passphrase), + recipient: genesisWallets[Math.floor(Math.random() * genesisWallets.length)], }, }), ); - - await delay(100); } const newBlock = await delegate.forge(transactions, { From edb25a51e4d1e1ff403539ec01f83a5d28f36ada Mon Sep 17 00:00:00 2001 From: Brian Faust Date: Tue, 12 Mar 2019 06:31:48 +0200 Subject: [PATCH 08/15] refactor: method name --- packages/core-tester-cli/src/commands/command.ts | 2 +- packages/core-tester-cli/src/commands/make/block.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/core-tester-cli/src/commands/command.ts b/packages/core-tester-cli/src/commands/command.ts index 5b0c121b0c..54f0b78baa 100644 --- a/packages/core-tester-cli/src/commands/command.ts +++ b/packages/core-tester-cli/src/commands/command.ts @@ -86,7 +86,7 @@ export abstract class BaseCommand extends Command { return { args, flags }; } - protected makeWithoutNetwork(command): any { + protected makeOffline(command): any { const { args, flags } = this.parse(command); configManager.setFromPreset(flags.network as NetworkName); diff --git a/packages/core-tester-cli/src/commands/make/block.ts b/packages/core-tester-cli/src/commands/make/block.ts index f5ab516e35..525dd51066 100644 --- a/packages/core-tester-cli/src/commands/make/block.ts +++ b/packages/core-tester-cli/src/commands/make/block.ts @@ -41,7 +41,7 @@ export class BlockCommand extends BaseCommand { }; public async run(): Promise { - const { flags } = this.makeWithoutNetwork(BlockCommand); + const { flags } = this.makeOffline(BlockCommand); const genesisBlock = configManager.get("genesisBlock"); const genesisWallets = genesisBlock.transactions.map(t => t.recipientId).filter(a => !!a); From 123ee850ab4d8d547b1f20bf1850a544089ea78c Mon Sep 17 00:00:00 2001 From: Brian Faust Date: Tue, 12 Mar 2019 12:17:23 +0200 Subject: [PATCH 09/15] test(core-tester-cli): remove network mocks --- .../core-tester-cli/commands/make/block.test.ts | 16 ---------------- 1 file changed, 16 deletions(-) diff --git a/__tests__/integration/core-tester-cli/commands/make/block.test.ts b/__tests__/integration/core-tester-cli/commands/make/block.test.ts index 580d154637..503091105d 100644 --- a/__tests__/integration/core-tester-cli/commands/make/block.test.ts +++ b/__tests__/integration/core-tester-cli/commands/make/block.test.ts @@ -1,23 +1,7 @@ import "jest-extended"; -import axios from "axios"; -import MockAdapter from "axios-mock-adapter"; import { BlockCommand } from "../../../../../packages/core-tester-cli/dist/commands/make/block"; -const mockAxios = new MockAdapter(axios); - -beforeEach(() => { - // Just passthru. We'll test the Command class logic in its own test file more thoroughly - mockAxios.onGet("http://localhost:4003/api/v2/node/configuration").reply(200, { data: { constants: {} } }); - mockAxios.onGet("http://localhost:4000/config").reply(200, { data: { network: { version: 23 } } }); -}); - -afterEach(() => { - mockAxios.reset(); -}); - -afterAll(() => mockAxios.restore()); - describe("make:block", () => { it("should generate 1 block with default flags", async () => { const blocks = await BlockCommand.run(["--network=unitnet"]); From dac5a112e836f2727268469635ea8928a3632d99 Mon Sep 17 00:00:00 2001 From: supaiku Date: Tue, 12 Mar 2019 14:38:51 +0100 Subject: [PATCH 10/15] refactor: change description --- packages/core-tester-cli/src/commands/make/block.ts | 2 +- packages/core-tester-cli/src/commands/make/wallets.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/core-tester-cli/src/commands/make/block.ts b/packages/core-tester-cli/src/commands/make/block.ts index 525dd51066..304e27a8eb 100644 --- a/packages/core-tester-cli/src/commands/make/block.ts +++ b/packages/core-tester-cli/src/commands/make/block.ts @@ -7,7 +7,7 @@ import { copyToClipboard } from "../../utils"; import { BaseCommand } from "../command"; export class BlockCommand extends BaseCommand { - public static description: string = "send multiple transactions"; + public static description: string = "create a new block"; public static flags = { ...BaseCommand.flagsConfig, diff --git a/packages/core-tester-cli/src/commands/make/wallets.ts b/packages/core-tester-cli/src/commands/make/wallets.ts index 91dcd98872..13a65d5127 100644 --- a/packages/core-tester-cli/src/commands/make/wallets.ts +++ b/packages/core-tester-cli/src/commands/make/wallets.ts @@ -6,7 +6,7 @@ import { copyToClipboard } from "../../utils"; import { BaseCommand } from "../command"; export class WalletCommand extends BaseCommand { - public static description: string = "send multiple transactions"; + public static description: string = "create new wallets"; public static flags = { ...BaseCommand.flagsConfig, From be7e3fa0eee38324c3633e5ab3f349642c1b4077 Mon Sep 17 00:00:00 2001 From: supaiku Date: Tue, 12 Mar 2019 14:55:52 +0100 Subject: [PATCH 11/15] fix: block payload output --- .../src/commands/make/block.ts | 20 ++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/packages/core-tester-cli/src/commands/make/block.ts b/packages/core-tester-cli/src/commands/make/block.ts index 304e27a8eb..4e9a172a4d 100644 --- a/packages/core-tester-cli/src/commands/make/block.ts +++ b/packages/core-tester-cli/src/commands/make/block.ts @@ -1,13 +1,12 @@ -import { Address, configManager, models, NetworkName, slots } from "@arkecosystem/crypto"; +import { configManager, models, slots } from "@arkecosystem/crypto"; import { flags } from "@oclif/command"; -import delay from "delay"; import { writeFileSync } from "fs"; import { satoshiFlag } from "../../flags"; import { copyToClipboard } from "../../utils"; import { BaseCommand } from "../command"; export class BlockCommand extends BaseCommand { - public static description: string = "create a new block"; + public static description: string = "create new blocks"; public static flags = { ...BaseCommand.flagsConfig, @@ -48,7 +47,7 @@ export class BlockCommand extends BaseCommand { let previousBlock = flags.previousBlock ? JSON.parse(flags.previousBlock) : genesisBlock; - const blocks: models.IBlock[] = []; + const blocks: models.IBlockData[] = []; for (let i = 0; i < flags.number; i++) { const milestone = configManager.getMilestone(previousBlock.height); @@ -73,9 +72,16 @@ export class BlockCommand extends BaseCommand { timestamp: slots.getSlotNumber(slots.getTime()) * milestone.blocktime, reward: milestone.reward, }); - previousBlock = newBlock.data; - blocks.push(newBlock); + const blockPayload = newBlock.data; + blockPayload.transactions = newBlock.transactions.map(tx => ({ + ...tx.toJson(), + serialized: tx.serialized.toString("hex"), + })); + blockPayload.serialized = newBlock.serialized; + previousBlock = blockPayload; + + blocks.push(blockPayload); } if (flags.log) { @@ -90,6 +96,6 @@ export class BlockCommand extends BaseCommand { writeFileSync("./blocks.json", JSON.stringify(blocks)); } - return blocks; + return blocks as any; } } From f85b1ef4d459656651e7f75d08c7b6b5f2c66153 Mon Sep 17 00:00:00 2001 From: supaiku Date: Tue, 12 Mar 2019 14:58:09 +0100 Subject: [PATCH 12/15] refactor: log block fixture by default --- packages/core-tester-cli/src/commands/make/block.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/packages/core-tester-cli/src/commands/make/block.ts b/packages/core-tester-cli/src/commands/make/block.ts index 4e9a172a4d..aaa1238fdd 100644 --- a/packages/core-tester-cli/src/commands/make/block.ts +++ b/packages/core-tester-cli/src/commands/make/block.ts @@ -37,6 +37,10 @@ export class BlockCommand extends BaseCommand { write: flags.boolean({ description: "write the blocks to the disk", }), + log: flags.boolean({ + description: "log the data to the console", + default: true, + }), }; public async run(): Promise { From 9b6a090b5034030360c3b8adcba95b41de5ee1c4 Mon Sep 17 00:00:00 2001 From: supaiku Date: Tue, 12 Mar 2019 14:59:38 +0100 Subject: [PATCH 13/15] refactor: remove cast --- packages/core-tester-cli/src/commands/make/block.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/core-tester-cli/src/commands/make/block.ts b/packages/core-tester-cli/src/commands/make/block.ts index aaa1238fdd..8bb44b7a29 100644 --- a/packages/core-tester-cli/src/commands/make/block.ts +++ b/packages/core-tester-cli/src/commands/make/block.ts @@ -43,7 +43,7 @@ export class BlockCommand extends BaseCommand { }), }; - public async run(): Promise { + public async run(): Promise { const { flags } = this.makeOffline(BlockCommand); const genesisBlock = configManager.get("genesisBlock"); @@ -100,6 +100,6 @@ export class BlockCommand extends BaseCommand { writeFileSync("./blocks.json", JSON.stringify(blocks)); } - return blocks as any; + return blocks; } } From 1123e5383336802ee554dc3fdc03a8000ebc235d Mon Sep 17 00:00:00 2001 From: supaiku Date: Tue, 12 Mar 2019 15:04:57 +0100 Subject: [PATCH 14/15] test: fix --- .../integration/core-tester-cli/commands/make/block.test.ts | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/__tests__/integration/core-tester-cli/commands/make/block.test.ts b/__tests__/integration/core-tester-cli/commands/make/block.test.ts index 503091105d..98f9a81b29 100644 --- a/__tests__/integration/core-tester-cli/commands/make/block.test.ts +++ b/__tests__/integration/core-tester-cli/commands/make/block.test.ts @@ -8,9 +8,7 @@ describe("make:block", () => { expect(blocks).toHaveLength(1); - expect(blocks[0].data.generatorPublicKey).toBe( - "03287bfebba4c7881a0509717e71b34b63f31e40021c321f89ae04f84be6d6ac37", - ); + expect(blocks[0].generatorPublicKey).toBe("03287bfebba4c7881a0509717e71b34b63f31e40021c321f89ae04f84be6d6ac37"); }); it("should generate 1 block with 10 transactions", async () => { From 9d986f83e0ef8328a399aef550827c0b027117d0 Mon Sep 17 00:00:00 2001 From: supaiku Date: Tue, 12 Mar 2019 15:57:47 +0100 Subject: [PATCH 15/15] test: fix --- .../integration/core-tester-cli/commands/make/block.test.ts | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/__tests__/integration/core-tester-cli/commands/make/block.test.ts b/__tests__/integration/core-tester-cli/commands/make/block.test.ts index 98f9a81b29..a2b9188123 100644 --- a/__tests__/integration/core-tester-cli/commands/make/block.test.ts +++ b/__tests__/integration/core-tester-cli/commands/make/block.test.ts @@ -34,8 +34,6 @@ describe("make:block", () => { it("should generate a block with a custom passphrase", async () => { const blocks = await BlockCommand.run(["--network=unitnet", "--passphrase=123"]); - expect(blocks[0].data.generatorPublicKey).toBe( - "03be686ed7f0539affbaf634f3bcc2b235e8e220e7be57e9397ab1c14c39137eb4", - ); + expect(blocks[0].generatorPublicKey).toBe("03be686ed7f0539affbaf634f3bcc2b235e8e220e7be57e9397ab1c14c39137eb4"); }); });