首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >协定方法参数个数无效

协定方法参数个数无效
EN

Stack Overflow用户
提问于 2018-05-30 19:59:25
回答 1查看 433关注 0票数 1

我刚刚开始使用Truffle and Solidity,并写下了我的第一份基本合同。我也写了一个测试,但它总是失败,给我以下信息:

Error: Invalid number of arguments to Solidity function

现在,这个问题看起来很直截了当,我并没有提出正确的论点……除了我所能看到的我

这是我的相关合同代码:

代码语言:javascript
复制
pragma solidity ^0.4.18;

contract FundEth {

    mapping (uint => Project) _projects;

    struct Project {
        uint id;
        uint targetWei;
        uint targetBlock;
        uint balanceWei;
        string name;
        string description;
        bool payedOut;
    }

    function fund(uint projectId) public payable
    {
        _projects[projectId].balanceWei += msg.value;
    }

    function create(uint targetWei, uint blocks, string name, string description)
        public
        returns (uint)
    {
        Project memory p = Project({
            id: ++_indexCounter,
            targetWei: targetWei,
            targetBlock: block.number + blocks,
            balanceWei: 0,
            name: name,
            description: description,
            payedOut: false
        });

        _projects[p.id] = p;

        return p.id;
    }

    function getProjectName(uint projectId)
        public
        view
        returns (string)
    {
        return "FOO";
    }

    function getProjectBalance(uint projectId)
        public
        view
        returns (uint)
    {
        return 10000000;
    }

    ...
}

这是我的测试代码:

代码语言:javascript
复制
const FundEth = artifacts.require("./FundEth.sol");

contract('FundEth', accounts => {
    var _id;
    var _fundEth;

    it("should create a project", () => {
        return FundEth.deployed()
            .then(fundEth => {
                _fundEth = fundEth;
                return fundEth.create(1000000000000000000 /* 1 Eth */ , 5, "FOO", "We want to fund this for testing.")
            }).then(id => {
                _id = id;
                return _fundEth.getProjectName.call(_id)
            }).then(name => {
                assert.equal(name, "FOO", "Has not created a valid project.");
            });
    });

    it("should fund a project", () => {

        return FundEth.deployed()
            .then(fundEth => {
                assert.notEqual(_id, 0);
                _fundEth = fundEth;
                _fundEth.fund.sendTransaction(_id, { from: accounts[0], value: 10000000 }); << SEEMS TO FAIL HERE.
            }).then(() => {
                return _fundEth.getProjectBalance.call(_id);;
            }).then(balance => {
                assert.equal(balance, 10000000, "Balance of test project was not 1 ether.");
            });
    });
});

我知道这份合同现在不是很有用,但我不明白它为什么会失败。完整的错误:

代码语言:javascript
复制
1) Contract: FundEth
   should fund a project:
 Uncaught Error: Invalid number of arguments to Solidity function
  at Object.InvalidNumberOfSolidityArgs (/usr/local/lib/node_modules/truffle/build/webpack:/~/web3/lib/web3/errors.js:25:1)
  at SolidityFunction.validateArgs (/usr/local/lib/node_modules/truffle/build/webpack:/~/web3/lib/web3/function.js:74:1)
  at SolidityFunction.toPayload (/usr/local/lib/node_modules/truffle/build/webpack:/~/web3/lib/web3/function.js:90:1)
  at SolidityFunction.sendTransaction (/usr/local/lib/node_modules/truffle/build/webpack:/~/web3/lib/web3/function.js:163:1)
  at /usr/local/lib/node_modules/truffle/build/webpack:/~/truffle-contract/contract.js:135:1
  at new Promise (<anonymous>)
  at /usr/local/lib/node_modules/truffle/build/webpack:/~/truffle-contract/contract.js:126:1
  at <anonymous>
  at process._tickCallback (internal/process/next_tick.js:118:7)
EN

回答 1

Stack Overflow用户

发布于 2018-05-31 06:11:31

将行更改为

代码语言:javascript
复制
return _fundEth.fund(_id, { from: accounts[0], value: 10000000 });

似乎解决了这个问题。但是,我还需要在调用之前删除断言,以便进行有效的测试。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/50604141

复制
相关文章

相似问题

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