首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >错误调用协作者契约

错误调用协作者契约
EN

Ethereum用户
提问于 2022-05-19 18:35:34
回答 1查看 195关注 0票数 0

当合同调用另一个注入的合同时,我得到以下错误:

错误:调用还原异常https://links.ethers.org/v5-errors-CALL_例外:请参阅

我不确定合作合同是否被正确地注入。从测试输出来看,这似乎是问题所在(测试输出中地址为零的原因)。总之,这是主要合同:

代码语言:javascript
复制
// SPDX-License-Identifier: MIT
pragma solidity 0.8.13;


import "hardhat/console.sol";
import "./TestDependency.sol";

contract TestContract
{
    TestDependency private testDep;

    function setDependency(address dependencyAddress) external
    {
        testDep = TestDependency(dependencyAddress);
    }

    function getDependency() external view returns (address)
    {
        return address(testDep);
    }

    function internalHello() public view returns (string memory) {
        console.log("internal hello function called");
        return "internal hello";
    }

    function helloWithDependency() public view returns (string memory) {
        console.log("helloWithDependency function called");
        return testDep.getConstant();
    }
}

扶养合同:

代码语言:javascript
复制
// SPDX-License-Identifier: MIT
pragma solidity 0.8.13;

import "hardhat/console.sol";

contract TestDependency
{
    function getConstant() public view returns (string memory) {
        console.log("getConstant function called");
        return "test123";
    }
}

还有一项测试:

代码语言:javascript
复制
const { expect } = require("chai");
const { ethers } = require("hardhat");

describe("Test", function () {
  it("Test dependency", async function () {

    const TestContract = await ethers.getContractFactory("TestContract");
    const testContract = await TestContract.deploy();
    await testContract.deployed();

    const TestDependency = await ethers.getContractFactory("TestDependency");
    const testDependency = await TestDependency.deploy();
    await testDependency.deployed();

    testContract.setDependency(testDependency);

    console.log("testContract.address:" + testContract.address);
    console.log("testDep.address:" + testDependency.address);    
    console.log("testDep injected dependency address:" + testContract.getDependency());    

    
    let internalHello = await testContract.internalHello();
    console.log("internalHello response:" + internalHello);

    let helloResp = await testContract.helloWithDependency();
    console.log("helloWithDependency response:" + helloResp);
  });
});

我得到了以下输出:

代码语言:javascript
复制
npx hardhat test test/test-dependency-test.js 


  Test
testContract.address:0x5FbDB2315678afecb367f032d93F642f64180aa3
testDep.address:0xe7f1725E7734CE288F8367e1Bb143E90bb3F0512
testDep injected dependency address:0x0000000000000000000000000000000000000000
internal hello function called
internalHello response:internal hello
helloWithDependency function called
    1) Test dependency


  0 passing (18s)
  1 failing

  1) Test
       Test dependency:
     **Error: call revert exception [ See: https://links.ethers.org/v5-errors-CALL_EXCEPTION ] (method="helloWithDependency()", data="0x", errorArgs=null, errorName=null, errorSignature=null, reason=null, code=CALL_EXCEPTION, version=abi/5.6.2)**
      at Logger.makeError (node_modules/@ethersproject/logger/src.ts/index.ts:261:28)
      at Logger.throwError (node_modules/@ethersproject/logger/src.ts/index.ts:273:20)
      at Interface.decodeFunctionResult (node_modules/@ethersproject/abi/src.ts/interface.ts:427:23)
      at Contract.<anonymous> (node_modules/@ethersproject/contracts/src.ts/index.ts:400:44)
      at step (node_modules/@ethersproject/contracts/lib/index.js:48:23)
      at Object.next (node_modules/@ethersproject/contracts/lib/index.js:29:53)
      at fulfilled (node_modules/@ethersproject/contracts/lib/index.js:20:58)

这可能是个新手的问题,但我在短期内对此很感兴趣。

提前谢谢你,马尔科

EN

回答 1

Ethereum用户

回答已采纳

发布于 2022-05-20 06:43:12

你离答案不远,检查一下你的

代码语言:javascript
复制
testContract.setDependency(testDependency);

to be replaced with
await testContract.setDependency(testDependency.address);
票数 1
EN
页面原文内容由Ethereum提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://ethereum.stackexchange.com/questions/128574

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档