Skip to content

Conversation

@alcuadrado
Copy link
Member

@alcuadrado alcuadrado commented Aug 11, 2025

Previously this would fail

const {networkHelpers: {mine}} = await network.connect();

@changeset-bot
Copy link

changeset-bot bot commented Aug 11, 2025

🦋 Changeset detected

Latest commit: 76ab773

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 21 packages
Name Type
@nomicfoundation/hardhat-network-helpers Patch
@nomicfoundation/hardhat-utils Patch
hardhat Patch
@nomicfoundation/hardhat-errors Patch
@nomicfoundation/hardhat-ethers-chai-matchers Patch
@nomicfoundation/hardhat-ignition Patch
@nomicfoundation/ignition-core Patch
@nomicfoundation/hardhat-ignition-ethers Patch
@nomicfoundation/ignition-ui Patch
@nomicfoundation/hardhat-ignition-viem Patch
@nomicfoundation/hardhat-keystore Patch
@nomicfoundation/hardhat-mocha Patch
@nomicfoundation/hardhat-node-test-reporter Patch
@nomicfoundation/hardhat-node-test-runner Patch
@nomicfoundation/hardhat-test-utils Patch
@nomicfoundation/hardhat-typechain Patch
@nomicfoundation/hardhat-toolbox-mocha-ethers Patch
@nomicfoundation/hardhat-verify Patch
@nomicfoundation/hardhat-viem Patch
@nomicfoundation/hardhat-viem-assertions Patch
@nomicfoundation/hardhat-zod-utils Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

This comment was marked as outdated.

alcuadrado and others added 2 commits August 11, 2025 14:19
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Luis Schaab <schaable@gmail.com>
Co-authored-by: Luis Schaab <schaable@gmail.com>
@alcuadrado alcuadrado requested a review from Copilot August 11, 2025 17:19
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR introduces a bindAllMethods utility function to solve a limitation where network helper methods would fail when destructured or assigned to independent variables. The fix ensures that methods from NetworkHelpers and Time classes maintain their this context when called independently.

  • Adds a new bindAllMethods utility function that binds all methods of an object to preserve this context
  • Updates NetworkHelpers and Time classes to use the binding utility in their constructors
  • Adds comprehensive test coverage for the new utility function and verifies the fix works for destructured methods

Reviewed Changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
v-next/hardhat-utils/src/lang.ts Implements the bindAllMethods utility function with proper method filtering
v-next/hardhat-utils/test/lang.ts Adds comprehensive test coverage for the new utility function
v-next/hardhat-network-helpers/src/internal/network-helpers/network-helpers.ts Applies method binding to NetworkHelpers class
v-next/hardhat-network-helpers/src/internal/network-helpers/time/time.ts Applies method binding to Time class
v-next/hardhat-network-helpers/test/index.ts Adds integration test verifying destructured methods work correctly
.changeset/wild-rivers-float.md Documents the addition of bindAllMethods utility
.changeset/gentle-planets-travel.md Documents the network helpers enhancement


for (const key of keys) {
const val = objAsAny[key];
if (
Copy link

Copilot AI Aug 11, 2025

Choose a reason for hiding this comment

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

The condition should also check if the property is writable to avoid attempting to bind read-only methods. Consider adding Object.getOwnPropertyDescriptor(obj, key)?.writable !== false to the condition.

Copilot uses AI. Check for mistakes.
Comment on lines 82 to 83
const keys = [
...Object.getOwnPropertyNames(Object.getPrototypeOf(obj)),
Copy link

Copilot AI Aug 11, 2025

Choose a reason for hiding this comment

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

This code will fail with a TypeError if obj is null or has a null prototype (like objects created with Object.create(null)). Consider adding a null check: Object.getPrototypeOf(obj) && Object.getOwnPropertyNames(Object.getPrototypeOf(obj)).

Suggested change
const keys = [
...Object.getOwnPropertyNames(Object.getPrototypeOf(obj)),
const proto = Object.getPrototypeOf(obj);
const keys = [
...(proto ? Object.getOwnPropertyNames(proto) : []),

Copilot uses AI. Check for mistakes.
@alcuadrado alcuadrado force-pushed the bind-all-network-helpers branch from 002851b to 76ab773 Compare August 11, 2025 17:25
@alcuadrado alcuadrado enabled auto-merge August 11, 2025 17:25
@alcuadrado alcuadrado added this pull request to the merge queue Aug 11, 2025
github-merge-queue bot pushed a commit that referenced this pull request Aug 11, 2025
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Aug 11, 2025
@alcuadrado alcuadrado added this pull request to the merge queue Aug 11, 2025
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Aug 11, 2025
@alcuadrado alcuadrado added this pull request to the merge queue Aug 11, 2025
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Aug 11, 2025
@kanej kanej added this pull request to the merge queue Aug 11, 2025
Merged via the queue into v-next with commit 428bfae Aug 11, 2025
234 checks passed
@kanej kanej deleted the bind-all-network-helpers branch August 11, 2025 20:50
@github-project-automation github-project-automation bot moved this from Backlog to Done in Hardhat Aug 11, 2025
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 10, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

4 participants