0

This is the solidity function that I have written,

function jobAssignment(uint256 _jobID) external {
        //Require the job to be pending
        Job memory job = JobList[_jobID];
        require(
            job.jobStatus == JobStatus.PENDING,
            "This job is already accepted by a freelancer"
        );
        // Assign freelancer to job
        job.freelancer = msg.sender;
        // Change status of job
        job.jobStatus = JobStatus.IN_PROGRESS;
        // emit event
        emit JobAssigned(_jobID, msg.sender);
    }

I am using hardhat and trying to run a test on this function as follows,

describe("Job assignment to freelancer", function () {
    before(async function () {
    [jobOwner, freelancer] = await hre.ethers.getSigners();
      jobContract.createJob("Job2", ethers.utils.parseEther("1"), {
        from: jobOwner.address,
      });
    });
    it("Should emit event of job assignment", async function () {
      await jobContract.jobAssignment(2, {
        from: freelancer.address,
      });
      
    });
  });

jobOnwer is the one who deployed the contract and create the specific job in the test script. Now I want to call the function with the freelancer. But this error comes up

Error: Contract with a Signer cannot override from (operation="overrides.from", code=UNSUPPORTED_OPERATION, version=contracts/5.6.0)

These are the Dev dependecies,

"devDependencies": {
    "@nomiclabs/hardhat-ethers": "^2.0.5",    
    "@nomiclabs/hardhat-waffle": "^2.0.3",
    "chai": "^4.3.6",
    "ethereum-waffle": "^3.4.4",
    "ethers": "^5.6.4",
    "hardhat": "^2.9.3",
    "web3": "^1.7.3"
  }

Any help would be helpful.

1 Answer 1

0

Use this

await jobContract.connect(freelancer).jobAssignment(2)

For more reference refer to this https://hardhat.org/tutorial/testing-contracts.html under "Using a different account" topic

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.