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
Original file line number Diff line number Diff line change
@@ -1,18 +1,13 @@
import "jest-extended";

import { deserialize } from "../../src/commands/deserialize";
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)", () => {
const actual = JSON.parse(
deserialize({
data: fixtureBlock.serialized,
type: "block",
}),
);
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);
Expand All @@ -28,12 +23,9 @@ describe("Commands - Deserialize", () => {
expect(actual.data.blockSignature).toBe(fixtureBlock.data.blockSignature);
});

it("should deserialize a block (full)", () => {
it("should deserialize a block (full)", async () => {
const actual = JSON.parse(
deserialize({
data: fixtureBlock.serializedFull,
type: "block",
}),
await DeserializeCommand.run(["--data", fixtureBlock.serializedFull, "--type", "block"]),
);

expect(actual.data.version).toBe(fixtureBlock.data.version);
Expand All @@ -51,12 +43,9 @@ describe("Commands - Deserialize", () => {
expect(actual.transactions).toHaveLength(7);
});

it("should deserialize a transaction", () => {
it("should deserialize a transaction", async () => {
const actual = JSON.parse(
deserialize({
data: fixtureTransaction.serialized,
type: "transaction",
}),
await DeserializeCommand.run(["--data", fixtureTransaction.serialized, "--type", "transaction"]),
);

expect(actual.type).toBe(fixtureTransaction.data.type);
Expand Down
41 changes: 14 additions & 27 deletions packages/core-debugger-cli/__tests__/commands/identity.test.ts
Original file line number Diff line number Diff line change
@@ -1,56 +1,43 @@
import "jest-extended";

import { identity } from "../../src/commands/identity";
import { IdentityCommand } from "../../src/commands/identity";

describe("Commands - Identity", () => {
describe("Commands - Identity", async () => {
const fixtureIdentities = require("../__fixtures__/identities.json");

it("should return identities from passphrase", () => {
it("should return identities from passphrase", async () => {
const expected = {
passphrase: "this is a top secret passphrase",
publicKey: "034151a3ec46b5670a682b0a63394f863587d1bc97483b1b6c70eb58e7f0aed192",
privateKey: "d8839c2432bfd0a67ef10a804ba991eabba19f154a3d707917681d45822a5712",
address: "D61mfSggzbvQgTUe6JhYKH2doHaqJ3Dyib",
};

expect(
identity({
data: fixtureIdentities.passphrase,
type: "passphrase",
}),
).toEqual(expected);
expect(await IdentityCommand.run(["--data", fixtureIdentities.passphrase, "--type", "passphrase"])).toEqual(
expected,
);
});

it("should return identities from privateKey", () => {
it("should return identities from privateKey", async () => {
const expected = {
publicKey: "034151a3ec46b5670a682b0a63394f863587d1bc97483b1b6c70eb58e7f0aed192",
privateKey: "d8839c2432bfd0a67ef10a804ba991eabba19f154a3d707917681d45822a5712",
address: "D61mfSggzbvQgTUe6JhYKH2doHaqJ3Dyib",
};

expect(
identity({
data: fixtureIdentities.privateKey,
type: "privateKey",
}),
).toEqual(expected);
expect(await IdentityCommand.run(["--data", fixtureIdentities.privateKey, "--type", "privateKey"])).toEqual(
expected,
);
});

it("should return identities from publicKey", () => {
it("should return identities from publicKey", async () => {
const expected = {
publicKey: "034151a3ec46b5670a682b0a63394f863587d1bc97483b1b6c70eb58e7f0aed192",
address: "D61mfSggzbvQgTUe6JhYKH2doHaqJ3Dyib",
};

expect(
identity({
data: fixtureIdentities.publicKey,
type: "publicKey",
}),
).toEqual(expected);
});

it("should not return anything for empty input", () => {
expect(identity({})).toEqual(undefined);
expect(await IdentityCommand.run(["--data", fixtureIdentities.publicKey, "--type", "publicKey"])).toEqual(
expected,
);
});
});
29 changes: 9 additions & 20 deletions packages/core-debugger-cli/__tests__/commands/serialize.test.ts
Original file line number Diff line number Diff line change
@@ -1,37 +1,26 @@
import "jest-extended";

import { serialize } from "../../src/commands/serialize";
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)", () => {
expect(
serialize({
data: JSON.stringify(fixtureBlock.data),
type: "block",
full: false,
}),
).toEqual(fixtureBlock.serialized);
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)", () => {
it("should serialize a block (full)", async () => {
expect(
serialize({
data: JSON.stringify(fixtureBlock.data),
type: "block",
full: true,
}),
await SerializeCommand.run(["--data", JSON.stringify(fixtureBlock.data), "--type", "block", "--full"]),
).toEqual(fixtureBlock.serializedFull);
});

it("should serialize a transaction", () => {
it("should serialize a transaction", async () => {
expect(
serialize({
data: JSON.stringify(fixtureTransaction.data),
type: "transaction",
}),
await SerializeCommand.run(["--data", JSON.stringify(fixtureTransaction.data), "--type", "transaction"]),
).toEqual(fixtureTransaction.serialized);
});
});
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
import "jest-extended";

import { verifySecondSignature } from "../../src/commands/verify-second";
import { VerifySecondSignatureCommand } from "../../src/commands/verify-second";

describe("Commands - Verify Second", () => {
const fixtureTransaction = require("../__fixtures__/transaction-second.json");

it("should verify a second signature", () => {
it("should verify a second signature", async () => {
expect(
verifySecondSignature({
data: fixtureTransaction.serialized,
publicKey: "03699e966b2525f9088a6941d8d94f7869964a000efe65783d78ac82e1199fe609",
}),
await VerifySecondSignatureCommand.run([
"--data",
fixtureTransaction.serialized,
"--publicKey",
"03699e966b2525f9088a6941d8d94f7869964a000efe65783d78ac82e1199fe609",
]),
).toBeTrue();
});
});
20 changes: 5 additions & 15 deletions packages/core-debugger-cli/__tests__/commands/verify.test.ts
Original file line number Diff line number Diff line change
@@ -1,26 +1,16 @@
import "jest-extended";

import { verify } from "../../src/commands/verify";
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", () => {
expect(
verify({
data: fixtureBlock.serializedFull,
type: "block",
}),
).toBeTrue();
it("should verify a block", async () => {
expect(await VerifyCommand.run(["--data", fixtureBlock.serializedFull, "--type", "block"])).toBeTrue();
});

it("should verify a transaction", () => {
expect(
verify({
data: fixtureTransaction.serialized,
type: "transaction",
}),
).toBeTrue();
it("should verify a transaction", async () => {
expect(await VerifyCommand.run(["--data", fixtureTransaction.serialized, "--type", "transaction"])).toBeTrue();
});
});
57 changes: 0 additions & 57 deletions packages/core-debugger-cli/bin/debugger

This file was deleted.

5 changes: 5 additions & 0 deletions packages/core-debugger-cli/bin/run
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/usr/bin/env node

require('@oclif/command').run()
.then(require('@oclif/command/flush'))
.catch(require('@oclif/errors/handle'))
3 changes: 3 additions & 0 deletions packages/core-debugger-cli/bin/run.cmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
@echo off

node "%~dp0\run" %*
25 changes: 20 additions & 5 deletions packages/core-debugger-cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,19 @@
"license": "MIT",
"main": "dist/index.js",
"files": [
"dist"
"/bin",
"/dist",
"/oclif.manifest.json"
],
"bin": {
"core:debugger": "./bin/debugger"
"debugger": "./bin/run"
},
"scripts": {
"start": "./bin/debugger",
"debugger": "./bin/run",
"prepublishOnly": "yarn test && 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",
Expand All @@ -32,9 +36,12 @@
},
"dependencies": {
"@arkecosystem/crypto": "^2.1.0",
"@oclif/command": "^1.5.8",
"@oclif/config": "^1.12.4",
"@oclif/plugin-help": "^2.1.6",
"@oclif/plugin-not-found": "^1.2.2",
"@types/clipboardy": "^1.1.0",
"clipboardy": "^1.2.3",
"commander": "^2.19.0"
"clipboardy": "^1.2.3"
},
"publishConfig": {
"access": "public"
Expand All @@ -44,5 +51,13 @@
},
"jest": {
"preset": "../../jest-preset.json"
},
"oclif": {
"commands": "./dist/commands",
"bin": "debugger",
"plugins": [
"@oclif/plugin-help",
"@oclif/plugin-not-found"
]
}
}
12 changes: 12 additions & 0 deletions packages/core-debugger-cli/src/commands/command.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
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",
}),
};
}
Loading