Skip to content

Fix all 34 failing unit tests without modifying source files#458

Draft
Copilot wants to merge 3 commits intomainfrom
copilot/fix-tests-only
Draft

Fix all 34 failing unit tests without modifying source files#458
Copilot wants to merge 3 commits intomainfrom
copilot/fix-tests-only

Conversation

Copy link

Copilot AI commented Feb 19, 2026

Unit tests were failing due to missing environment variables, real network calls without mocks, and test logic issues. All fixes are confined to test files only.

Root Causes & Fixes

Missing env vars at test runtime

dotenv is only loaded by index.ts at app startup — never during mocha runs. Affected tests:

  • btc-last-block.service.unit.ts: Set BLOCKBOOK_URL and SYNC_INITIAL_BLOCK_HEIGHT in beforeEach
  • btc-utils.unit.ts: Set NETWORK=testnet so getAddress() uses the correct testnet prefix (default falls back to typo 'tesnet')
  • pegout-status.service.unit.ts, pegin-status.service.unit.ts, flyover-service.service.unit.ts, rsk-node.services.unit.ts: Set RSK_NODE_HOST to prevent new Web3('undefined') / new RskNodeService() constructor failures

Real network calls in unit tests

  • bridge.handler.unit.ts: Added sinon stubs for all BridgeService methods and BridgeTransactionParser.getBridgeTransactionByTxHash via beforeEach/afterEach
  • rsk-node.services.unit.ts: Rewrote to use stubs on web3.eth.* and bridgeTransactionParser after construction, replacing direct RSK node I/O
  • pegin-status.service.unit.ts: PeginStatusService internally calls isAFedAddress() which hits the bridge contract. Stubbed federation-addresses.isAFedAddress and RskNodeService.prototype.getBlockNumber via prototype to avoid the module-level BridgeService instance:
    sinon.stub(federationAddressUtils, 'isAFedAddress')
      .callsFake(async (address) => address === federationAddress);
    sinon.stub(RskNodeService.prototype, 'getBlockNumber').resolves(4000000);
  • pegout-data.processor.unit.ts: processBatchPegouts and processIndividualPegout call getTxFromRskTransaction (creates a fresh Web3 internally for a trace log). Stubbed as private method

Test logic bugs

  • api-information.controller.unit.ts: process.env.npm_package_version is only set when running under npm — switched to reading package.json directly, matching the controller implementation
  • pegout-data.processor.unit.ts: afterEach used sandbox.stub(process.env, 'NETWORK') to restore the env var, which throws when the property doesn't exist. Replaced with a conditional direct assignment and added sandbox.restore()
  • flyover-service.service.unit.ts: beforeEach instantiated an unused RskNodeService that was never injected into FlyoverService. Removed the dead variable; remaining stubs updated to reference flyoverService.rskNodeService directly

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • public-node.testnet.rsk.co
    • Triggering command: /home/REDACTED/work/_temp/ghcca-node/node/bin/node node ./node_modules/.bin/mocha --recursive dist/__tests__/**/*.unit.js --timeout 10000 /home/REDACTED/.cache/node-gyp/24.13.0/deps/v8/include -I /home/REDACTED/work/2wp-api/2wp-api/node_modules/secp256k1/node_modules/node-addon-api -I ../src --64 (dns block)
    • Triggering command: /usr/bin/curl curl -s -o /dev/null -w %{http_code} --max-time 5 REDACTED (dns block)
    • Triggering command: /home/REDACTED/work/_temp/ghcca-node/node/bin/node node ./node_modules/.bin/mocha --recursive dist/__tests__/**/*.unit.js --timeout 10000 --global odules/.bin/as user.email (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Original prompt

fix tests without change any other file

Created from VS Code.


🔒 GitHub Advanced Security automatically protects Copilot coding agent pull requests. You can protect all pull requests by enabling Advanced Security for your repositories. Learn more about Advanced Security.

Copilot AI and others added 2 commits February 19, 2026 20:27
Co-authored-by: alexjavabraz <14118998+alexjavabraz@users.noreply.github.com>
Co-authored-by: alexjavabraz <14118998+alexjavabraz@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix tests without changing any other file Fix all 34 failing unit tests without modifying source files Feb 19, 2026
Copilot AI requested a review from alexjavabraz February 19, 2026 20:47
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.

2 participants