1

I'm going to try to put this in simple. This is the code of my contract:

pragma solidity ^0.5.0;

contract Lottery {
    address public manager;
    address[] public players;
    event Deposit(address _from, uint value);

    constructor() public {
        manager = msg.sender;
    }

    function enter() public payable {
        require(msg.value > .01 ether, 'Not enough ether');
        players.push(msg.sender);
    }

    function numberPlayers() public view returns(uint) {
        return players.length;
    }
}

And this is the code of my test:

const lottery = artifacts.require('Lottery');

contract('Lottery', accounts => {
    let instance;

    beforeEach( async () => {
        instance = await lottery.deployed();
    });

    it('should have as manager the account which deployed', async () => {
        const manager = await instance.manager.call();

        assert.equal(manager, accounts[0]);
    });

    it('should create a player if the player send some ether', async () => {
        const payment = web3.utils.toWei("0.02", "ether");
        await instance.enter.sendTransaction({from: accounts[1], value: payment});
        const numberPlayers = await instance.numberPlayers.call();
        const player = await instance.players(numberPlayers - 1);

        assert.equal(player, accounts[1]);
    })
});

Everything works fine but if I comment the Deposit event in the line 6 like this:

pragma solidity ^0.5.0;

contract Lottery {
    address public manager;
    address[] public players;
    // event Deposit(address _from, uint value);

    constructor() public {
        manager = msg.sender;
    }

    function enter() public payable {
        require(msg.value > .01 ether, 'Not enough ether');
        players.push(msg.sender);
    }

    function numberPlayers() public view returns(uint) {
        return players.length;
    }
}

I'm getting the next error:

1) Contract: Lottery
       should create a player if the player send some ether:
     Error: Invalid number of parameters for "enter". Got 1 expected 2!
      at Object.InvalidNumberOfParams (/Users/adrian.ferrereses/.nvm/versions/node/v10.15.3/lib/node_modules/truffle/build/webpack:/~/web3-eth-contract/~/web3-core-helpers/src/errors.js:32:1)
      at Object._createTxObject (/Users/adrian.ferrereses/.nvm/versions/node/v10.15.3/lib/node_modules/truffle/build/webpack:/~/web3-eth-contract/src/index.js:699:1)
      at constructor.detectNetwork.then.network (/Users/adrian.ferrereses/.nvm/versions/node/v10.15.3/lib/node_modules/truffle/build/webpack:/packages/truffle-contract/lib/execute.js:170:1)
      at process._tickCallback (internal/process/next_tick.js:68:7)

I'm pretty new in solidity, so I do not know if I'm doing something wrong or if I've encountered an error in version 0.5 of the solidity compiler.

These are the versions of my environment:

Truffle v5.0.15 (core: 5.0.15)
Solidity v0.5.0 (solc-js)
Node v10.15.3
Web3.js v1.0.0-beta.37

If you want to test this issue by your self, you can download the code from this repository: https://github.com/ardiadrianadri/lotter-project

Thank you very much everyone for your time

1 Answer 1

0

I commented out the Deposit event and ran truffle test --network develop. It came out fine:


Compiling your contracts...
===========================
> Compiling ./contracts/Migrations.sol
> Compiling ./contracts/lottery.sol
> Artifacts written to /var/folders/ch/c9xd4bp91c5blg80llj8ytvc0000gn/T/test-119416-6547-11frumz.via4
> Compiled successfully using:
   - solc: 0.5.0+commit.1d4f565a.Emscripten.clang



  Contract: Lottery
    ✓ should have as manager the account which deployed
    ✓ should create a player if the player send some ether (92ms)


  2 passing (143ms)

It is most probably some weird Truffle quirk - they happen really often. Please, try removing your build directory and running tests again.

1
  • 1
    Thank you Ivan Andrusenko. I removed the build directory and everything went fine.
    – Adrian
    May 16, 2019 at 13:14

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.