Giter Site home page Giter Site logo

hashgraph / hedera-hardhat-hethers Goto Github PK

View Code? Open in Web Editor NEW
5.0 5.0 0.0 1.06 MB

DEPRECATED Hardhat plugin for integration with hethers.js.

License: Apache License 2.0

JavaScript 2.56% TypeScript 94.58% Solidity 2.86%
deprecated deprecated-repo deprecated-repository

hedera-hardhat-hethers's People

Contributors

georgi-l95 avatar ivo-yankov avatar kalina-todorova avatar natanasow avatar nathanklick avatar simihunjan avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

hedera-hardhat-hethers's Issues

Compatibility with hardhat-deploy

Problem

hardhat-deploy doesn't work with @hashgraph/hardhat-hethers.
Attempting await deployments.fixtures() results in the following error stack trace:

TypeError: this.network.provider.send is not a function
      at DeploymentsManager.getChainId (node_modules/hardhat-deploy/src/DeploymentsManager.ts:443:51)
      at DeploymentsManager.loadDeployments (node_modules/hardhat-deploy/src/DeploymentsManager.ts:619:28)
      at DeploymentsManager.runDeploy (node_modules/hardhat-deploy/src/DeploymentsManager.ts:998:16)
      at Object.fixture (node_modules/hardhat-deploy/src/DeploymentsManager.ts:315:20)
      at runMicrotasks (<anonymous>)
      at processTicksAndRejections (node:internal/process/task_queues:96:5)
      at async initialize (test/helpers.ts:40:3)
      at async Context.<anonymous> (test/_/Contract.test.ts:10:5)

Solution

  • In hardhat-deploy the DeploymentsManager's constructor's 2nd parameter i.e. network is set to env.network i.e. hre.network. Potentially have hedera-hardhat-hethers plugin load network: Network into hre with a compatible Provider

Alternatives

No response

chai expect to be revertedWith does not work

Problem

The error with which a contract call reverts can be tested positively as follows:

import { expect } from "chai";

  await expect(
    contract.foo(-1)
  ).to.be.revertedWith("OUT_OF_RANGE");

If the contract reverts with another error an AssertionError like the following is normally in hardhat:

AssertionError: Expected transaction to be reverted with OUT_OF_RANGE, but other exception was thrown: Error: VM Exception while processing transaction: reverted with custom error 'OutOfRange()'

The response from a contract call that reverted using @hashgraph/hardhat-hethers does not have parity with the default hardhat functionality and instead throws the follows AssertionError:

AssertionError: Expected transaction to be reverted with OUT_OF_RANGE, but other exception was thrown: Error: receipt for transaction [email protected] contained error status CONTRACT_REVERT_EXECUTED (code=CONTRACT_REVERT_EXECUTED, version=providers/1.2.0)

Solution

  • Have hedera-hardhat-ethers decode and handle CONTRACT_REVERT_EXECUTED calls identically to hardhat-ethers

Alternatives

No response

Contract call event logs assertion does not work

As a user I want to be able to assert that certain events have been emitted in a certain transaction I am making.

await expect(smartContract.method(arg1, arg2, arg3)).to.emit(contract, "SomeEvent").withArgs(arg1, arg2, arg3);

Currently the snippet above does not work.

Cannot pass BigNumber to Contract constructor parameter

Description

BigNumber variables cannot be passed to constructor params(and though untested possibly function params as well). number variables work fine. The error that is thrown is:

Error: missing argument:  in Contract constructor (count=2, expectedCount=3, code=MISSING_ARGUMENT, version=contracts/1.2.0)

Steps to reproduce

const ERC20 = await hre.hethers.getContractFactory("ERC20Mock", accounts[0]);

// number works:
await ERC20.deploy(`Token A`, `TOKENA`, 1_000_000))

// BigNumber fails:
const supply = BigNumber.from(1_000_000).mul(BigNumber.from(10).pow(0));
await ERC20.deploy(`Token A`, `TOKENA`, supply))

// Using BigNumber.toString() works:
const supply = BigNumber.from(1_000_000).mul(BigNumber.from(10).pow(0)).toString();
await ERC20.deploy(`Token A`, `TOKENA`, supply))

Additional context

No response

Hedera network

other

Version

1.0.2

Operating system

macOS

Update workflows to use self hosted runners

Description

We need to update the .github/workflows/nodejs.yml workflow to use the ephemeral self-hosted runners which are now configured on this repository. Additionally, we should add a workflow dispatch trigger to improve ease of testing.

Requirements

  • Change the runs-on specification to the following stanza:
    • runs-on: [self-hosted, hardhat, hethers, standard, ephemeral]
  • Add a workflow_dispatch trigger to the on declaration
  • Update the following actions to use the v3 version:
    • actions/setup-node
    • actions/checkout
  • Enable NodeJS caching support

Support for max_automatic_token_associations at contract.deploy()

As a user I'd like to be able to set the property for max automatic token associations somewhere within the deploy() method of a contract.

Reference for max_automatic_token_associations:
This property is supported both for accounts and contracts, but the documentation is not yet updated so I am linking the cryptocreate page for reference instead.

This is where the property should be populated. I am referencing it as a starting point.

Add license headers to source files

Add the following license headers to all source files (example).

/*-
 * ‌
 * Hedera Hardhat Hethers
 * ​
 * Copyright (C) 2022 - 2023 Hedera Hashgraph, LLC
 * ​
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * ‍
 */

The `--network` argument is being ignored

  1. Create a sample hardhat project
  2. Add the network config and include a set of networks (previewnet, testnet, local f.e). Example config:
previewnet: {
		accounts: [ ACCS_HERE ]
	},
	testnet: {
		accounts: [ACCS_HERE  ]
	},
	local: {
		name: 'local',
		consensusNodes: [
			{
				url: '127.0.0.1:50211',
				nodeId: '0.0.3'
			}
		],
		mirrorNodeUrl: '127.0.0.1:5551',
		chainId: 0,
		accounts: [
			{
				account: '0.0.1001',
				privateKey: "0x7f109a9e3b0d8ecfba9cc23a3614433ce0fa7ddcc80f2a8f10b222179a5a80d6",
			},
			{
				account: '0.0.1002',
				privateKey: "0x6ec1f2e7d126a74a1d2ff9e1c5d90b92378c725e506651ff8bb8616a5c724628",
			},
			{
				account: '0.0.1003',
				privateKey: "0xb4d7f7e82f61d81c95985771b8abf518f9328d019c36849d4214b5f995d13814",
			}
		]
	}
  1. Create a script that deploys a sample contract to the network
  2. When executing the script, the --network tag is ignored and the network being used is always the one defined as defaultNetwork in the hardhat.config file.

If defaultNetwork: 'previewnet', is set in the hardhat.config file, the scripts are always using the previewnet network.

Excpectation
When running the script:

npx hardhat deploy --network local

I would expect that the used network is local and not previewnet

Hbar amount passed as `value` is HBARs not `tinybars`

When defining value as part of a contract call, the amount is denominated in hbars however it should be in tinybars
Example code:

 const depositTx = await WHBAR.deposit({value: hbarAmount, gasLimit: 150_000});

In this case hbarAmount is in hbars and not tinybars

Deprecated: Use `ledgerId` instead

Description

Did not see this error until switching to hethers.
Can't seem to figure out what it's complaining about.
You will see this when running any command npx hardhat run ...

Steps to reproduce

npx hardhat run ...

Additional context

No response

Hedera network

testnet

Version

Latest

Operating system

macOS

`waitForDeployment` is not a function

Description

Upon running something like this errors in: TypeError: collectionImpl.waitForDeployment is not a function

import { hethers } from 'hardhat'

const main = async () => {
    const CollectionImplV1 = await hethers.getContractFactory('CollectionImplV1')

    const collectionImpl = await CollectionImplV1.deploy()
    await collectionImpl.waitForDeployment()

    console.log(`Collection Implementation: ${collectionImpl.target}`)
}

main().catch((error) => {
    console.error(error)
    process.exitCode = 1
})

Steps to reproduce

npx hardhat run script/ScriptName.s.ts --network testnet

Additional context

No response

Hedera network

testnet

Version

Latest

Operating system

macOS

Compatibility with solidity-coverage

Problem

The solidity-coverage plugin cannot be used simultaneously with @hashgraph/hardhat-hethers.

Attempting to analyse code coverage with command npx hardhat coverage throws the following error:

Error in plugin solidity-coverage: HardhatError: HH10: Error while loading Hardhat's configuration.
You or one of your plugins is trying to modify the userConfig.hedera.networks.localHederaNetwork.allowUnlimitedContractSize value from a config extender

Solution

  • Possibly update the HederaConfig type to include all properties present in HardhatUserConfig including the allowUnlimitedContractSize property with identical defaults.

Alternatives

No response

Export extended hre and config types

There are errors when the plugin is installed in a typescript project: Property 'hethers' does not exist on type 'HardhatRuntimeEnvironment'.

Cannot access namedAccounts

Problem

In hardhat.config.ts:

const config: HardhatUserConfig = {
  defaultNetwork: "localHederaNetwork",
  ...,
  namedAccounts: {
    deployer: {
      default: 0, // maps to account 0.0.1002
    },
    dev: {
      default: 1, // maps to account 0.0.1003
    },
  },
  hedera: {
    ...,
    localHederaNetwork: {
      ...,
      accounts: [
        {
          account: "0.0.1002",
          privateKey: "0x7f109a9e3b0d8ecfba9cc23a3614433ce0fa7ddcc80f2a8f10b222179a5a80d6",
        },
        {
          account: "0.0.1003",
          privateKey: "0x6ec1f2e7d126a74a1d2ff9e1c5d90b92378c725e506651ff8bb8616a5c724628",
        }
      ]      
    },
  }
}

In script:

import {getNamedAccounts } from "hardhat";

const { deployer, dev } = await getNamedAccounts();

On getNamedAccounts() fails with the following error stack trace:

TypeError: this.network.provider.send is not a function
      at DeploymentsManager.getChainId (node_modules/hardhat-deploy/src/DeploymentsManager.ts:443:51)
      at DeploymentsManager.setupAccounts (node_modules/hardhat-deploy/src/DeploymentsManager.ts:1505:34)
      at DeploymentsManager.getNamedAccounts (node_modules/hardhat-deploy/src/DeploymentsManager.ts:574:16)
      at initialize (test/harness/ConstantProduct.ts:60:36)
      at runMicrotasks (<anonymous>)
      at processTicksAndRejections (node:internal/process/task_queues:96:5)
      at async Context.<anonymous> (test/Test.test.ts:10:5)

Solution

  • Given the stack trace appears to be similar to that of this issue the solution would likely be the same

Alternatives

No response

Return type of deploy contract doesn't match contract type

Problem

The only allowed return type of the deployed contract is Contract, however, the type of the deployed contract should also be allowed.

const ERC20Factory = await hre.hethers.getContractFactory("ERC20", accounts[0]);

// works fine
const erc20contract1: Contract = await ERC20Factory.deploy(`Token A`, `TOKENA`, 1_000_000);

// type error:
// Type 'Contract' is missing the following properties from type 'ERC20': DOMAIN_SEPARATOR, allowance, approve, balanceOf, and 11 more.
const erc20contract2: ERC20 = await ERC20Factory.deploy(`Token A`, `TOKENA`, 1_000_000);

Solution

  • the return type of hethers.ContractFactory.deploy should allow for both hethers.Contract or type of Contract which is identical to the contract name.

Alternatives

No response

Functional Hedera network configured in HardhatUserConfig.networks

Problem

A hedera network configured in HardhatUserConfig.networks isn't functional presumably due to the lack of parity in the hedera-json-rpc-relay with the standard ethereum json rpc.

import { HardhatUserConfig } from "hardhat/config";
import "@nomicfoundation/hardhat-toolbox";

const config: HardhatUserConfig = {
  ...,
  defaultNetwork: "hedera",
  networks: {
    hedera: {
      url: "http://127.0.0.1:7546",
      chainId: 298,
      accounts: [
        // Alias ECDSA keys private keys
        "0x105d050185ccb907fba04dd92d8de9e32c18305e097ab41dadda21489a211524",
        "0x2e1d968b041d84dd120a5860cee60cd83f9374ef527ca86996317ada3d0d03e7",
        "0x45a5a7108a18dd5013cf2d5857a28144beadc9c70b3bdbd914e38df4e804b8d8",
        "0x6e9d61a325be3f6675cf8b7676c70e4a004d2308e3e182370a41f5653d52c6bd",
        "0x0b58b1bd44469ac9f813b5aeaf6213ddaea26720f0b2f133d08b6f234130a64f",
        "0x95eac372e0f0df3b43740fa780e62458b2d2cc32d6a440877f1cc2a9ad0c35cc",
        "0x6c6e6727b40c8d4b616ab0d26af357af09337299f09c66704146e14236972106",
        "0x5072e7aa1b03f531b4731a32a021f6a5d20d5ddc4e55acbb71ae202fc6f3a26d",
        "0x60fe891f13824a2c1da20fb6a14e28fa353421191069ba6b6d09dd6c29b90eff",
        "0xeae4e00ece872dd14fb6dc7a04f390563c7d69d16326f2a703ec8e0934060cc7",
      ],
    },
  }
  ...,
};

export default config;

Attempting to run a simple test fails on the first call to the json rpc relay i.e. deploy:

import { expect } from "chai";
import { ethers } from 'hardhat';

describe("Greeter", function () {
  it("Should return the new greeting once it's changed", async function () {

    const signers = await ethers.getSigners();

    const signer = signers[0];

    const Greeter = await ethers.getContractFactory("Greeter", signer);

    // fails here
    const greeter = await Greeter.deploy("Hello, world!");

    await greeter.deployed();

    expect(await greeter.greet()).to.equal("Hello, world!");

    const setGreetingTx = await greeter.setGreeting("Hola, mundo!");

    // wait until the transaction is mined
    await setGreetingTx.wait();

    expect(await greeter.greet()).to.equal("Hola, mundo!");
  });
});

Hardhat error stack trace:

ProviderError: Internal error
  at HttpProvider.request (node_modules/hardhat/src/internal/core/providers/http.ts:78:19)
  at LocalAccountsProvider.request (node_modules/hardhat/src/internal/core/providers/accounts.ts:188:34)
  at async EthersProviderWrapper.send (node_modules/@nomiclabs/hardhat-ethers/src/internal/ethers-provider-wrapper.ts:13:20)

Greeter.sol:

//SPDX-License-Identifier: Unlicense
pragma solidity ^0.8.9;

contract Greeter {
    string private greeting;

    constructor(string memory _greeting) {
        greeting = _greeting;
    }

    function greet() public view returns (string memory) {
        return greeting;
    }

    function setGreeting(string memory _greeting) public {
        greeting = _greeting;
    }
}

json-rpc-relay docker container logs:

[2022-08-29 08:42:13.714 +0000] INFO (rpc-server/50 on baafe97141e2): [GET]: /health/liveness 1 ms
[2022-08-29 08:42:13.958 +0000] DEBUG (rpc-server/50 on baafe97141e2): eth_chainId
[2022-08-29 08:42:13.958 +0000] TRACE (relay-eth/50 on baafe97141e2): chainId()
[2022-08-29 08:42:13.960 +0000] INFO (rpc-server/50 on baafe97141e2): [POST] eth_chainId: 200 1 ms 
[2022-08-29 08:42:13.964 +0000] DEBUG (rpc-server/50 on baafe97141e2): eth_chainId
[2022-08-29 08:42:13.964 +0000] TRACE (relay-eth/50 on baafe97141e2): chainId()
[2022-08-29 08:42:13.964 +0000] INFO (rpc-server/50 on baafe97141e2): [POST] eth_chainId: 200 0 ms 
[2022-08-29 08:42:13.971 +0000] DEBUG (rpc-server/50 on baafe97141e2): eth_chainId
[2022-08-29 08:42:13.971 +0000] TRACE (relay-eth/50 on baafe97141e2): chainId()
[2022-08-29 08:42:13.971 +0000] INFO (rpc-server/50 on baafe97141e2): [POST] eth_chainId: 200 0 ms 
[2022-08-29 08:42:13.997 +0000] DEBUG (rpc-server/50 on baafe97141e2): eth_blockNumber
[2022-08-29 08:42:13.998 +0000] TRACE (relay-eth/50 on baafe97141e2): blockNumber()
[2022-08-29 08:42:14.024 +0000] DEBUG (rpc-server/50 on baafe97141e2): eth_chainId
[2022-08-29 08:42:14.024 +0000] TRACE (relay-eth/50 on baafe97141e2): chainId()
[2022-08-29 08:42:14.024 +0000] INFO (rpc-server/50 on baafe97141e2): [POST] eth_chainId: 200 0 ms 
[2022-08-29 08:42:14.037 +0000] ERROR (mirror-node/50 on baafe97141e2): [GET] blocks?limit=1&order=desc 567 status
    err: {
      "type": "Error",
      "message": "connect ECONNREFUSED 127.0.0.1:5551",
      "stack":
          Error: connect ECONNREFUSED 127.0.0.1:5551
              at MirrorNodeClient.handleError (/home/node/app/packages/relay/dist/lib/clients/mirrorNodeClient.js:107:27)
              at MirrorNodeClient.<anonymous> (/home/node/app/packages/relay/dist/lib/clients/mirrorNodeClient.js:95:22)
              at Generator.throw (<anonymous>)
              at rejected (/home/node/app/packages/relay/dist/lib/clients/mirrorNodeClient.js:25:65)
              at processTicksAndRejections (node:internal/process/task_queues:96:5)
    }
[2022-08-29 08:42:14.042 +0000] ERROR (Internal error/50 on baafe97141e2): [POST] eth_blockNumber: -32603 45 ms
    code: -32603
    message: "Unknown error invoking RPC"

Solution

  • Requires further investigation.

Alternatives

No response

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.