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