Skip to content

Conversation

lklimek
Copy link
Contributor

@lklimek lklimek commented Oct 3, 2025

Issue being fixed or feature implemented

When testing DAPI, we sometimes want to direct platform-test-suite tests to use some prefefined DAPI endpoint

What was done?

Added support for DAPI_ADDRESSES env variable.

How Has This Been Tested?

Local devnet with DAPI_ADDRESSES=127.0.0.1:2443

Breaking Changes

None

Checklist:

  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have added or updated relevant unit/integration/functional/e2e tests
  • I have added "!" to the title and described breaking changes in the corresponding section if my code contains any
  • I have made corresponding changes to the documentation if needed

For repository code-owners and collaborators only

  • I have assigned this pull request to a milestone

Summary by CodeRabbit

  • New Features

    • Added support for connecting directly to specified DAPI nodes via the DAPI_ADDRESSES environment variable (comma-separated ip:port). Falls back to automatic discovery when not set.
    • Applied this configuration to all test suite clients, including faucet and wallet/non-wallet setups.
  • Documentation

    • Updated usage instructions to describe setting DAPI_ADDRESSES to bypass discovery and connect only to specified nodes.

@lklimek lklimek added this to the v2.1.0 milestone Oct 3, 2025
Copy link
Contributor

coderabbitai bot commented Oct 3, 2025

Walkthrough

Adds environment-driven DAPI endpoint selection across test client creators: parse DAPI_ADDRESSES and prefer them over seed discovery; otherwise fall back to getDAPISeeds(). README mentions setting DAPI_ADDRESSES to bypass SML discovery. No exported API changes.

Changes

Cohort / File(s) Summary
Env-driven DAPI address support
packages/.../lib/test/createClientWithFundedWallet.js, packages/.../lib/test/createClientWithoutWallet.js, packages/.../lib/test/createFaucetClient.js
Parse DAPI_ADDRESSES (comma-separated) into dapiAddresses; conditionally set clientOpts to use dapiAddresses when present, else use seeds from getDAPISeeds(); control flow updated accordingly.
Documentation update
packages/platform-test-suite/README.md
Usage note added: set DAPI_ADDRESSES="ip:port" to bypass SML discovery and connect only to specified nodes.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  actor Tester
  participant Env as Env (DAPI_ADDRESSES)
  participant Factory as create*Client(...)\n(test suite)
  participant Seeds as getDAPISeeds()
  participant Dash as new Dash.Client(opts)

  Tester->>Factory: invoke
  Factory->>Env: read DAPI_ADDRESSES
  alt DAPI_ADDRESSES provided and non-empty
    note right of Factory: Build opts with dapiAddresses
  else
    Factory->>Seeds: fetch seeds
    Seeds-->>Factory: seeds[]
    note right of Factory: Build opts with seeds
  end
  Factory->>Dash: instantiate client
  Dash-->>Factory: client
  Factory-->>Tester: return client
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Suggested reviewers

  • QuantumExplorer
  • shumkov

Poem

I sniff the breeze for IPs and ports,
A hop to seeds if silence reports.
Env-carrots guide my burrowed ways,
To DAPI fields through leafy arrays.
Thump-thump! The README hums along—
I choose my path and bound on strong. 🥕🐇

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The title clearly and concisely states that the platform-test-suite now accepts the DAPI_ADDRESSES environment variable, which is the primary change introduced by the pull request, and it uses a common prefix to signal its scope, making the intent immediately understandable to reviewers.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch test/test-suite-dapi-address

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

♻️ Duplicate comments (2)
packages/platform-test-suite/lib/test/createFaucetClient.js (1)

24-27: Extract duplicated DAPI address parsing logic.

This parsing logic is duplicated from createClientWithoutWallet.js and createClientWithFundedWallet.js. See the refactoring suggestion in createClientWithoutWallet.js (lines 8-11).

packages/platform-test-suite/lib/test/createClientWithFundedWallet.js (1)

24-27: Extract duplicated DAPI address parsing logic.

This parsing logic is duplicated from createClientWithoutWallet.js and createFaucetClient.js. See the refactoring suggestion in createClientWithoutWallet.js (lines 8-11).

🧹 Nitpick comments (3)
packages/platform-test-suite/lib/test/createClientWithoutWallet.js (2)

8-11: Extract duplicated DAPI address parsing logic.

This parsing logic is duplicated across three files: createClientWithoutWallet.js, createClientWithFundedWallet.js, and createFaucetClient.js. Extract it into a shared helper function to improve maintainability.

Consider creating a helper function in a shared location:

// lib/test/parseDapiAddresses.js
function parseDapiAddresses() {
  return (process.env.DAPI_ADDRESSES || '')
    .split(',')
    .map((address) => address.trim())
    .filter(Boolean);
}

module.exports = parseDapiAddresses;

Then import and use it in all three files:

+const parseDapiAddresses = require('./parseDapiAddresses');
+
 function createClientWithoutWallet() {
-  const dapiAddresses = (process.env.DAPI_ADDRESSES || '')
-    .split(',')
-    .map((address) => address.trim())
-    .filter(Boolean);
+  const dapiAddresses = parseDapiAddresses();

8-11: Consider validating DAPI address format.

The parsing accepts any non-empty string. Invalid formats like "foo:bar" or malformed addresses will pass through and potentially cause runtime errors when the Dash client attempts to connect.

Consider adding basic validation:

 const dapiAddresses = (process.env.DAPI_ADDRESSES || '')
   .split(',')
   .map((address) => address.trim())
-  .filter(Boolean);
+  .filter((address) => {
+    if (!address) return false;
+    // Basic validation: ensure format is host:port or just host
+    const parts = address.split(':');
+    if (parts.length > 2) return false;
+    if (parts.length === 2 && isNaN(parseInt(parts[1], 10))) return false;
+    return true;
+  });
packages/platform-test-suite/lib/test/createClientWithFundedWallet.js (1)

39-43: Consider using conditional spread for consistency.

This file uses an if-else block to conditionally add properties, while createClientWithoutWallet.js and createFaucetClient.js use a conditional spread operator for the same purpose. Using consistent patterns improves codebase maintainability.

Apply this diff for consistency:

-  if (dapiAddresses.length > 0) {
-    clientOpts.dapiAddresses = dapiAddresses;
-  } else {
-    clientOpts.seeds = getDAPISeeds();
-  }
+  Object.assign(clientOpts, 
+    dapiAddresses.length > 0
+      ? { dapiAddresses }
+      : { seeds: getDAPISeeds() }
+  );

Or refactor the entire clientOpts construction to match the pattern in the other files:

 const clientOpts = {
+  ...(dapiAddresses.length > 0
+    ? { dapiAddresses }
+    : { seeds: getDAPISeeds() }),
   network: process.env.NETWORK,
   timeout: 25000,
   apps: {
     dpns: {
       contractId: dpnsContractId,
     },
   },
 };
-
-  if (dapiAddresses.length > 0) {
-    clientOpts.dapiAddresses = dapiAddresses;
-  } else {
-    clientOpts.seeds = getDAPISeeds();
-  }
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between d6f9d9e and 5513cbc.

📒 Files selected for processing (4)
  • packages/platform-test-suite/README.md (2 hunks)
  • packages/platform-test-suite/lib/test/createClientWithFundedWallet.js (2 hunks)
  • packages/platform-test-suite/lib/test/createClientWithoutWallet.js (1 hunks)
  • packages/platform-test-suite/lib/test/createFaucetClient.js (1 hunks)
🧰 Additional context used
📓 Path-based instructions (2)
packages/platform-test-suite/**

📄 CodeRabbit inference engine (AGENTS.md)

packages/platform-test-suite/**: Keep end-to-end tests and helpers in packages/platform-test-suite
Keep all E2E tests exclusively in packages/platform-test-suite

Files:

  • packages/platform-test-suite/README.md
  • packages/platform-test-suite/lib/test/createClientWithoutWallet.js
  • packages/platform-test-suite/lib/test/createClientWithFundedWallet.js
  • packages/platform-test-suite/lib/test/createFaucetClient.js
packages/**/**/*.{js,ts,jsx,tsx}

📄 CodeRabbit inference engine (AGENTS.md)

packages/**/**/*.{js,ts,jsx,tsx}: Adhere to ESLint with Airbnb/TypeScript configs for JS/TS code
Use camelCase for JS/TS variables and functions
Use PascalCase for JS/TS classes
Prefer kebab-case filenames within JS packages

Files:

  • packages/platform-test-suite/lib/test/createClientWithoutWallet.js
  • packages/platform-test-suite/lib/test/createClientWithFundedWallet.js
  • packages/platform-test-suite/lib/test/createFaucetClient.js
🧬 Code graph analysis (3)
packages/platform-test-suite/lib/test/createClientWithoutWallet.js (2)
packages/platform-test-suite/lib/test/createClientWithFundedWallet.js (3)
  • dapiAddresses (24-27)
  • Dash (1-1)
  • getDAPISeeds (9-9)
packages/platform-test-suite/lib/test/createFaucetClient.js (3)
  • dapiAddresses (24-27)
  • Dash (1-1)
  • getDAPISeeds (19-19)
packages/platform-test-suite/lib/test/createClientWithFundedWallet.js (2)
packages/platform-test-suite/lib/test/createClientWithoutWallet.js (2)
  • dapiAddresses (8-11)
  • getDAPISeeds (5-5)
packages/platform-test-suite/lib/test/createFaucetClient.js (3)
  • dapiAddresses (24-27)
  • clientOpts (29-39)
  • getDAPISeeds (19-19)
packages/platform-test-suite/lib/test/createFaucetClient.js (2)
packages/platform-test-suite/lib/test/createClientWithFundedWallet.js (3)
  • dapiAddresses (24-27)
  • clientOpts (29-37)
  • getDAPISeeds (9-9)
packages/platform-test-suite/lib/test/createClientWithoutWallet.js (2)
  • dapiAddresses (8-11)
  • getDAPISeeds (5-5)
🔇 Additional comments (4)
packages/platform-test-suite/README.md (1)

42-42: LGTM!

The documentation accurately describes the new DAPI_ADDRESSES environment variable and its purpose to bypass SML discovery.

Also applies to: 82-82

packages/platform-test-suite/lib/test/createClientWithoutWallet.js (1)

14-16: LGTM!

The conditional logic correctly prioritizes environment-provided DAPI addresses over seed discovery, with a clean fallback mechanism.

packages/platform-test-suite/lib/test/createFaucetClient.js (1)

30-32: LGTM!

The conditional spread operator correctly integrates DAPI addresses when available, maintaining backward compatibility with seed-based discovery.

packages/platform-test-suite/lib/test/createClientWithFundedWallet.js (1)

39-43: LGTM!

The logic correctly prioritizes DAPI_ADDRESSES over seed discovery and integrates properly with the existing client configuration.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant