Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(core-tester-cli): add make:block command #2221

Merged
merged 18 commits into from Mar 12, 2019

Conversation

Projects
None yet
5 participants
@faustbrian
Copy link
Collaborator

faustbrian commented Mar 11, 2019

Proposed changes

Sometimes I need to generate some fake blocks to test something, been doing that so far with a script but it can now be used via tester make:block.

Will switch the tests from axios to got/nock after #2203 has been merged.

Types of changes

  • New feature (non-breaking change which adds functionality)

Checklist

  • I have read the CONTRIBUTING documentation
  • Lint and unit tests pass locally with my changes
@codecov-io

This comment has been minimized.

Copy link

codecov-io commented Mar 11, 2019

Codecov Report

Merging #2221 into develop will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@           Coverage Diff            @@
##           develop    #2221   +/-   ##
========================================
  Coverage    73.29%   73.29%           
========================================
  Files          318      318           
  Lines         7213     7213           
  Branches       332      332           
========================================
  Hits          5287     5287           
  Misses        1884     1884           
  Partials        42       42

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 34d43b4...dac5a11. Read the comment docs.

@vasild

This comment has been minimized.

Copy link
Contributor

vasild commented Mar 11, 2019

Could end up with:

        "verification": {
            "verified": false,
            "errors": [
                "Encountered duplicate transaction: 8309ffb072b2333284e0729bb78ea1168d61e329c690d6c7a4e7b88b6eacb3a3"
            ]
        }

if more than one transaction is generated and the timestamps of the transactions are equal.

}),
);

await delay(100);

This comment has been minimized.

@vasild

vasild Mar 11, 2019

Contributor

Why this?

This comment has been minimized.

@faustbrian

faustbrian Mar 11, 2019

Author Collaborator

To avoid duplicate transactions caused by timestamps, anything below 100 causes duplicates.

This comment has been minimized.

@vasild

vasild Mar 11, 2019

Contributor

Then this is not enough as I still got duplicate txs - anything below 1000ms (1s) has a chance of ending up in the same second. But adding 1s delay here would make it too slow - if many transactions are to be generated.

What about using different amount or different sender or different recipient in order to avoid duplicates?

This comment has been minimized.

@faustbrian

faustbrian Mar 11, 2019

Author Collaborator

Changing the recipient would probably be already enough, ideally we only use genesisBlock.transactions.map(t => Address.fromPublicKey(t.senderPublicKey)) or genesisBlock.transactions.map(t => t.recipientId) so we can be sure the wallets exist.

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.
@vasild

This comment has been minimized.

Copy link
Contributor

vasild commented Mar 11, 2019

commit 638394f3 (HEAD -> feat/blocks-gen)
Parent: 925fcbab
Author:     Vasil Dimov <vd@FreeBSD.org>
AuthorDate: Mon Mar 11 14:28:58 2019 +0100
Commit:     Vasil Dimov <vd@FreeBSD.org>
CommitDate: Mon Mar 11 14:28:58 2019 +0100
gpg: Signature made Mon Mar 11 14:31:04 2019 CET
gpg:                using RSA key E64D8D45614DB07545D9CCC154DF06F64B55CBBF
gpg: Good signature from "Vasil Dimov <vd@myforest.net>" [ultimate]
gpg:                 aka "Vasil Dimov <vd@ark.io>" [ultimate]
gpg:                 aka "Vasil Dimov <vd@FreeBSD.org>" [ultimate]
gpg:                 aka "Vasil Dimov <vasild@gmail.com>" [ultimate]


    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.

diff --git a/packages/core-tester-cli/src/commands/make/block.ts b/packages/core-tester-cli/src/commands/make/block.ts
index 2c3330a4..a27c07a5 100644
--- a/packages/core-tester-cli/src/commands/make/block.ts
+++ b/packages/core-tester-cli/src/commands/make/block.ts
@@ -29,24 +29,32 @@ export class BlockCommand extends BaseCommand {
             default: 0.1,
         }),
         passphrase: flags.string({
             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",
         }),
     };
 
     public async run(): Promise<models.IBlock[]> {
         const { flags } = await this.make(BlockCommand);
 
         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[] = [];
 
         for (let i = 0; i < flags.number; i++) {
             const milestone = configManager.getMilestone(previousBlock.height);
             const delegate = new models.Delegate(flags.passphrase, configManager.get("pubKeyHash"));

ok to push to feat/blocks-gen?

@faustbrian

This comment has been minimized.

Copy link
Collaborator Author

faustbrian commented Mar 11, 2019

@vasild apply it 👍

@ArkEcosystemBot

This comment has been minimized.

Copy link
Member

ArkEcosystemBot commented Mar 11, 2019

The ci/circleci: test-node11-2 job is failing as of 1123e5383336802ee554dc3fdc03a8000ebc235d. Please review the logs for more information.

Once you've pushed the fixes, the build will automatically re-run. Thanks!

@faustbrian faustbrian marked this pull request as ready for review Mar 11, 2019

@faustbrian faustbrian requested review from kristjank and supaiku0 as code owners Mar 11, 2019

faustbrian added some commits Mar 11, 2019

supaiku0 added some commits Mar 12, 2019

@supaiku0 supaiku0 merged commit 9ca8f61 into develop Mar 12, 2019

6 checks passed

ci/circleci: test-node10-0 Your tests passed on CircleCI!
Details
ci/circleci: test-node10-1 Your tests passed on CircleCI!
Details
ci/circleci: test-node10-2 Your tests passed on CircleCI!
Details
ci/circleci: test-node11-0 Your tests passed on CircleCI!
Details
ci/circleci: test-node11-1 Your tests passed on CircleCI!
Details
ci/circleci: test-node11-2 Your tests passed on CircleCI!
Details

@supaiku0 supaiku0 deleted the feat/blocks-gen branch Mar 12, 2019

vasild added a commit that referenced this pull request Mar 12, 2019

Merge remote-tracking branch 'ArkEcosystem/core/develop' into blockid
* ArkEcosystem/core/develop:
  fix(core-api): properly sort semver versions (#2229)
  feat(core-tester-cli): add make:block command (#2221)
  refactor: replace axios with got (#2203)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.