1

I want to do some final tests on a smart contract that has been deployed on the Rinkeby testnet. I am trying to run the below script (saved in my hardhat test folder) with hardhat but get the following error "1) Should return the project Name and ID once it's deployed" when I run npx hardhat test --network rinkeby in the console.

Note that my hardhat.config.js file is configured correctly since I could deploy the contract on the Rinkeby testnet with hardhat.

if I replace provider by the addressed which deployed the contract I get the same error. Am I doing something incorrect in the way the contract instance is declared in the script file (using ether.js) ?

const { expect } = require("chai");
const { ethers } = require("hardhat");

describe("DesignManager", function () {
  it("Should return the project Name and ID once it's deployed", async function () {    

    //const DesignManager = await ethers.getContractFactory("DesignManager");

    const abi = [ { "anonymous": false, "inputs": [ { "indexed": true, "internalType": "address", "name": "previousOwner", "type": "address" }, { "indexed": true, "internalType": "address", "name": "newOwner", "type": "address" } ], "name": "OwnershipTransferred", "type": "event" }, { "inputs": [], "name": "owner", "outputs": [ { "internalType": "address", "name": "", "type": "address" } ], "stateMutability": "view", "type": "function" }, { "inputs": [], "name": "renounceOwnership", "outputs": [], "stateMutability": "nonpayable", "type": "function" }, { "inputs": [ { "internalType": "address", "name": "newOwner", "type": "address" } ], "name": "transferOwnership", "outputs": [], "stateMutability": "nonpayable", "type": "function" } ];

    const designManager = new ethers.Contract(0x60D70e76eF9158F1bBDC829f4b3CbabeAadF0F86, abi, provider);

    expect(await designManager.projectName()).to.equal("Project1");
    expect(await designManager.projectID()).to.equal("01");

  });
});
8
  • There must be an error listing below the test results, please include it, you just ut the name of the test that is failing, but at the end it lists the errors of the failed tests cases.
    – Julissa DC
    Commented Dec 20, 2021 at 19:38
  • Thanks for your comment, please see below the errors of the failed test cases: 0 passing (22s) 2 failing
    – user32379
    Commented Dec 21, 2021 at 4:17
  • 1) DesignManager Should return the project Name and ID once it's deployed: Error: invalid signer or provider (argument="signerOrProvider", value=1.364023963139541e+47, code=INVALID_ARGUMENT, version=contracts/5.5.0) at Logger.makeError (node_modules/@ethersproject/logger/src.ts/index.ts:225:28) at Logger.throwError (node_modules/@ethersproject/logger/src.ts/index.ts:237:20) at Logger.throwArgumentError (node_modules/@ethersproject/logger/src.ts/index.ts:241:21) at Contract.BaseContract (node_modules/@ethersproject/contracts/src.ts/index.ts:668:20)
    – user32379
    Commented Dec 21, 2021 at 4:21
  • at new Contract (node_modules/@ethersproject/contracts/lib/index.js:1047:42) at Context.<anonymous> (test/DesignManager_3D-test_rinkeby.js:12:27) 2) DesignManager Should return the project Name and ID once it's deployed: Error: Timeout of 20000ms exceeded. For async tests and hooks, ensure "done()" is called; if returning a Promise, ensure it resolves. (/Users/tristanw/Desktop/UNSW/Papers/Paper 2 - BCDT Architecture/code/test/DesignManager_3D.js) at listOnTimeout (node:internal/timers:557:17) at processTimers (node:internal/timers:500:7)
    – user32379
    Commented Dec 21, 2021 at 4:21
  • 1
    I want to test it on the Rinkeby because the contract is doing some API calls with Chainlink and I want to test how this works in real web based conditions.
    – user32379
    Commented Dec 21, 2021 at 12:43

1 Answer 1

2

Instead of writing your tests in Mocha/Jest framework. Write the above code in a separate script and run it using hardhat run scripts/<yourscriptname> --network rinkeby.

Please note that you will have to remove expect/describe and all functions related to mocha framework. Use simple assert functions in your testing script.

1
  • This answer needs to explain WHY
    – Madbreaks
    Commented Jun 2, 2022 at 1:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.