diff --git a/packages/tree-builder/package.json b/packages/tree-builder/package.json index 104822a..836ce2a 100644 --- a/packages/tree-builder/package.json +++ b/packages/tree-builder/package.json @@ -29,7 +29,7 @@ "postpack": "shx rm -f oclif.manifest.json", "prepack": "yarn build && oclif manifest && oclif readme", "prepare": "yarn build", - "test": "mocha --forbid-only \"test/**/*.ts\"", + "test": "mocha --forbid-only \"test/**/*.test.ts\"", "version": "oclif readme && git add README.md" }, "oclif": { @@ -42,12 +42,12 @@ "topicSeparator": " " }, "dependencies": { + "@liskhq/lisk-cryptography": "4.1.0", "@oclif/core": "^3", "@oclif/plugin-help": "^6", "@openzeppelin/merkle-tree": "^1.0.5", "ethereumjs-util": "^7.1.5", "ethers": "^6.8.1", - "@liskhq/lisk-cryptography": "4.1.0", "sinon": "^17.0.1", "tweetnacl": "^1.0.3" }, diff --git a/packages/tree-builder/src/applications/example/create_accounts.ts b/packages/tree-builder/src/applications/example/create_accounts.ts index 178b2bc..9c17185 100644 --- a/packages/tree-builder/src/applications/example/create_accounts.ts +++ b/packages/tree-builder/src/applications/example/create_accounts.ts @@ -1,5 +1,4 @@ import * as fs from 'fs'; -import * as path from 'path'; import { address } from '@liskhq/lisk-cryptography'; import { ExampleKey } from '../../interface'; @@ -45,7 +44,6 @@ const multiSigs = [ const randomBalance = (range: number): number => Number((range * Math.random()).toFixed(8)); export function createAccounts(numberOfAccounts = 54) { - console.log(path.join(__dirname, '../../../../../../data/example/accounts.json')); const keyPairs = JSON.parse( fs.readFileSync('../../data/example/key-pairs.json', 'utf-8'), ) as ExampleKey[]; diff --git a/packages/tree-builder/src/applications/generate-merkle-tree/build_tree.ts b/packages/tree-builder/src/applications/generate-merkle-tree/build_tree.ts index d3a010d..6f73688 100644 --- a/packages/tree-builder/src/applications/generate-merkle-tree/build_tree.ts +++ b/packages/tree-builder/src/applications/generate-merkle-tree/build_tree.ts @@ -3,6 +3,7 @@ import { StandardMerkleTree } from '@openzeppelin/merkle-tree'; import { Account, Leaf } from '../../interface'; import { LEAF_ENCODING } from '../../constants'; import { append0x } from '../../utils'; +import { debug, log } from 'oclif/lib/log'; export function createPayload(account: Account) { return [ @@ -33,7 +34,7 @@ export function build_tree(accounts: Account[]): { } } - console.log(`${accounts.length} Accounts to generate:`); + log(`${accounts.length} Accounts to generate:`); const leaves: Leaf[] = []; const tree = StandardMerkleTree.of( @@ -47,7 +48,7 @@ export function build_tree(accounts: Account[]): { const addressHex = address.getAddressFromLisk32Address(account.lskAddress); const payload = createPayload(account); - console.log( + debug( `${account.lskAddress}: ${account.balance} LSK (Multisig=${ account.numberOfSignatures && account.numberOfSignatures > 0 ? 'Y' : 'N' })`, @@ -70,6 +71,8 @@ export function build_tree(accounts: Account[]): { }); } + debug('===== ===== ===== ===== ===== ===== ===== ===== ===== ===== ===== ====='); + return { tree, leaves, diff --git a/packages/tree-builder/src/applications/generate-merkle-tree/build_tree_json.ts b/packages/tree-builder/src/applications/generate-merkle-tree/build_tree_json.ts index d213631..80c509c 100644 --- a/packages/tree-builder/src/applications/generate-merkle-tree/build_tree_json.ts +++ b/packages/tree-builder/src/applications/generate-merkle-tree/build_tree_json.ts @@ -2,6 +2,7 @@ import * as fs from 'fs'; import * as path from 'path'; import { Account } from '../../interface'; import { build_tree } from './build_tree'; +import { log } from 'oclif/lib/log'; export function buildTreeJson(outputPath: string) { let accounts: Account[]; @@ -10,17 +11,15 @@ export function buildTreeJson(outputPath: string) { try { accounts = JSON.parse(fs.readFileSync(accountsPath, 'utf-8')) as Account[]; } catch (err) { - console.log(`Error occurred reading ${accountsPath}`); + log(`Error occurred reading ${accountsPath}`); if (err instanceof Error) { - console.log(err.message); + log(err.message); } process.exit(1); } const { tree, leaves } = build_tree(accounts); - console.log('===== ===== ===== ===== ===== ===== ===== ===== ===== ===== ===== ====='); - const merkleTreeResultDetailedJSONPath = path.join( outputPath, 'merkle-tree-result-detailed.json', @@ -33,7 +32,7 @@ export function buildTreeJson(outputPath: string) { }), 'utf-8', ); - console.log(`Detailed result outputted to: ${merkleTreeResultDetailedJSONPath}`); + log(`Detailed result outputted to: ${merkleTreeResultDetailedJSONPath}`); const merkleTreeResultJSONPath = path.join(outputPath, 'merkle-tree-result.json'); fs.writeFileSync( @@ -51,7 +50,7 @@ export function buildTreeJson(outputPath: string) { }), 'utf-8', ); - console.log(`Lightweight result outputted to: ${merkleTreeResultJSONPath}`); + log(`Lightweight result outputted to: ${merkleTreeResultJSONPath}`); const merkleRootJSONPath = path.join(outputPath, 'merkle-root.json'); fs.writeFileSync( @@ -61,5 +60,5 @@ export function buildTreeJson(outputPath: string) { }), 'utf-8', ); - console.log(`MerkleRoot outputted to: ${merkleRootJSONPath}`); + log(`MerkleRoot outputted to: ${merkleRootJSONPath}`); } diff --git a/packages/tree-builder/src/commands/example/index.ts b/packages/tree-builder/src/commands/example/index.ts index 89182a8..4ab943f 100644 --- a/packages/tree-builder/src/commands/example/index.ts +++ b/packages/tree-builder/src/commands/example/index.ts @@ -21,7 +21,7 @@ export default class Example extends Command { static description = 'Generate example data for demo purpose'; - static examples = [`$ oex generate`]; + static examples = [`$ oex example`]; async run(): Promise { const { flags } = await this.parse(Example); @@ -33,7 +33,7 @@ export default class Example extends Command { createAccounts(flags.amountOfLeaves); // Build MerkleTree to example - buildTreeJson(`../../data/example`); + buildTreeJson('../../data/example'); // Sign all leaves using key-pairs.json signAccounts(flags.recipient);