Add tests to bitcore-cli#4105
Conversation
Co-authored-by: Copilot <copilot@github.com>
There was a problem hiding this comment.
Pull request overview
Adds a substantial automated test suite for bitcore-cli (unit tests + end-to-end CLI flows against a local BWS + MongoDB), and adjusts CLI behavior/types to support those tests (wallet creation/join flows, tx proposal pagination/actions, and build/test tooling).
Changes:
- Added extensive
bitcore-clitest coverage (utils/prompts/filestorage + CLI interaction tests for create/join, proposals, addresses). - Updated CLI wallet + txproposals logic to support new scenarios (join secret plumbing, pagination refactor, chain-specific behavior, token lookup scoping).
- Updated build/test tooling (prod tsconfig, test scripts, test wallet fixtures, and new dev deps for running an embedded BWS + MongoDB).
Reviewed changes
Copilot reviewed 29 out of 31 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| packages/bitcore-wallet-client/src/index.ts | Re-exports Constants from BWC for downstream usage. |
| packages/bitcore-cli/types/wallet.d.ts | Updates wallet create() type signature for join-secret flow + new return fields. |
| packages/bitcore-cli/tsconfig.prod.json | Adds prod TS config excluding tests. |
| packages/bitcore-cli/test/wallets/btc-singlesig.json | Adds wallet fixture used by CLI tests. |
| packages/bitcore-cli/test/wallets/btc-multisig-copayer1.json | Adds multisig copayer fixture. |
| packages/bitcore-cli/test/wallets/btc-multisig-copayer2.json | Adds multisig copayer fixture. |
| packages/bitcore-cli/test/utils.test.ts | Adds unit tests for Utils. |
| packages/bitcore-cli/test/tssCoordinator.ts | Adds helper to coordinate multiple CLI processes for TSS tests. |
| packages/bitcore-cli/test/proposals.test.ts | Adds end-to-end tests for viewing/accepting/rejecting/deleting proposals. |
| packages/bitcore-cli/test/prompts.test.ts | Adds tests for prompt helpers (env defaults, validation, cancel flow). |
| packages/bitcore-cli/test/helpers.ts | Adds BWS/Mongo-backed test harness and blockchainExplorer mock utilities. |
| packages/bitcore-cli/test/filestorage.test.ts | Adds tests for FileStorage behavior. |
| packages/bitcore-cli/test/data/walletsData.ts | Adds BWS wallet seed data for tests. |
| packages/bitcore-cli/test/data/test-config.ts | Adds test config for Mongo/BWS ports. |
| packages/bitcore-cli/test/data/proposalsData.ts | Adds BWS proposal seed data. |
| packages/bitcore-cli/test/data/addressesData.ts | Adds BWS address seed data. |
| packages/bitcore-cli/test/create.test.ts | Adds end-to-end tests for single-sig, multisig, and TSS wallet creation/join flows. |
| packages/bitcore-cli/test/commands.test.ts | Fixes type import paths for command tests. |
| packages/bitcore-cli/test/address.test.ts | Adds end-to-end tests for address generation + pagination. |
| packages/bitcore-cli/src/wallet.ts | Adds join-secret support to create(), adjusts completion/save logic, adds regtest currency URL requirement. |
| packages/bitcore-cli/src/utils.ts | Adjusts goodbye messages, parseAmount() error behavior, and documents paginate() types. |
| packages/bitcore-cli/src/commands/txproposals.ts | Refactors proposal viewing/actions onto shared paginator, adds --page option. |
| packages/bitcore-cli/src/commands/token.ts | Restricts token lookup to the wallet’s chain. |
| packages/bitcore-cli/src/commands/join/joinMultiSig.ts | Routes multisig join through wallet.create({ joinSecret }). |
| packages/bitcore-cli/src/commands/join/index.ts | Blocks Solana for multi-party join flows. |
| packages/bitcore-cli/src/commands/create/index.ts | Disables multi-party prompt for Solana creation. |
| packages/bitcore-cli/src/commands/create/createThresholdSig.ts | Adds explicit Solana guard for TSS creation. |
| packages/bitcore-cli/src/commands/create/createMultiSig.ts | Adds explicit chain support guard for multisig creation. |
| packages/bitcore-cli/package.json | Updates test/coverage scripts (copy fixtures, --exit), adds prod build, adds test deps. |
| packages/bitcore-cli/package-lock.json | Locks new dev dependencies (BWS, mongodb, supertest, etc.). |
| packages/bitcore-cli/copyTestWallets | Adds helper script to copy wallet fixtures into build output for tests. |
Files not reviewed (1)
- packages/bitcore-cli/package-lock.json: Language not supported
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 39 out of 42 changed files in this pull request and generated 10 comments.
Files not reviewed (2)
- packages/bitcore-cli/package-lock.json: Language not supported
- packages/bitcore-wallet-client/package-lock.json: Language not supported
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Copilot <copilot@github.com>
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 40 out of 43 changed files in this pull request and generated 7 comments.
Files not reviewed (2)
- packages/bitcore-cli/package-lock.json: Language not supported
- packages/bitcore-wallet-client/package-lock.json: Language not supported
…ds on wallet creation
…d infinite recursion
| const network = await getNetwork(); | ||
| const isMultiParty = await getIsMultiParty(); | ||
| // No solana support for multi-party wallets right now (TSS is ECDSA only) | ||
| const isMultiParty = chain === 'sol' ? false : await getIsMultiParty(); |
There was a problem hiding this comment.
You chain.toLowerCase() in the file above - should do that here too just to be safe?
|
|
||
| const chain = await getChain(); | ||
|
|
||
| if (chain === 'sol') { |
There was a problem hiding this comment.
same here - should be chain.toLowerCase()?
| } | ||
| } | ||
|
|
||
| export function difference(arr1: any[], arr2: any[]): any[] { |
There was a problem hiding this comment.
docs would be really nice here:
"Returns a new array of the elements in arr1 which are not in arr2"
| export function difference(arr1: any[], arr2: any[]): any[] { | ||
| arr1 = arr1 || []; | ||
| arr2 = arr2 || []; | ||
| const arr2Set = new Set(arr2); |
There was a problem hiding this comment.
Works fine for primitives, but Set.has() uses strict reference equality. Structurally identical objects are not considered equal - is that the desired behavior? That should maybe be specified in the docs too if so.
Run this script from bitcore root -
node - <<'NODE'
const { difference } = require('./packages/crypto-wallet-core/ts_build/src/utils');
const arr1 = [{ a: 1 }, { b: 2 }];
const arr2 = [{ a: 1 }];
const diff = difference(arr1, arr2);
// Many people would expect diff to ONLY include { b: 2 }, but it includes { a: 1 } as well.
console.log(JSON.stringify(diff));
NODEThere was a problem hiding this comment.
Here's a test which demonstrates the failure. That's assuming the intent is "structural equality" - same shape elements get filtered out.
it('should return objects not present in arr2 (structural equality)', () => {
const result = difference(
[{ a: 1 }, { b: 2 }],
[{ a: 1 }],
);
expect(result).to.deep.equal([{ b: 2 }]);
}); Ran this test - it fails.
AssertionError: expected [ { a: 1 }, { b: 2 } ] to deeply equal [ { b: 2 } ]
+ expected - actual
[
{
- "a": 1
- }
- {
"b": 2
}
]
| } | ||
| } | ||
|
|
||
| export function difference(arr1: any[], arr2: any[]): any[] { |
There was a problem hiding this comment.
This feels like a great candidate for a TS generic. Tightens up the usage contract.
export function difference<T>(arr1: T[], arr2: T[]): T[]| const b = stack.pop(); | ||
| if (a === b) continue; | ||
| if (a == null || b == null) return false; | ||
| if (typeof a !== 'object' || typeof b !== 'object') return false; |
There was a problem hiding this comment.
Should there be a specific a/b are Arrays check - or is that handled correctly downstream?
Description
Need more tests in bitcore-cli
Changelog
tsxdependency from BWCTesting Notes
cd packages/bitcore-cli && npm run testChecklist
BWCif modifying the bitcore-wallet-client package,CLIif modifying the bitcore-cli package, etc.)