0

I am writing a testing file for my coin flip project here is the beginning of the coin flip project:

contract CoinFlip {

address payable player;

address payable casino;
uint256 public casinoDeposit;
uint256 betAmount;
uint256 maxBet = .001 ether;
bytes32 commitHash;
uint gameTimeOut;
uint256  matchBetTimeOut;
uint256 revealTimeOut;
uint256 result;
bool win;
address payable contractAddress = address(this);

constructor () public payable{
    require(msg.value == 1 ether);
    casinoDeposit = msg.value;
}

Here is the testing file:

contract CoinFlipTest { CoinFlip v;

function beforeAll() public {
    // create a new instance of Value contract
    v = new CoinFlip();
}

Every time I try to run the testing file I get this error. I would appreciate some help on what I am doing wrong: ✘ Before all Error Message: "Transaction has been reverted by the EVM: { "transactionHash": "0x0e839950a7737797d4c9fca76adb24d1ec0ff7d07b3b87eea5c3a8487d123043", "transactionIndex": 0, "blockHash": "0x9cc0f6017494c03c53ebbe39aef033623ed7f6e6937c6d376b7c3a0d78392b86", "blockNumber": 8, "gasUsed": 5000000, "cumulativeGasUsed": 5000000, "status": false, "to": "0xd2a5bC10698FD955D1Fe6cb468a17809A08fd005", "events": {} }"

0

First of all in contract CoinFlip you need to have the following method in order to allow the incoming ether transfers:

receive() external payable {}

Secondly method beforeAll in contract CoinFlipTest is failing, because when you are creating the instance of contract CoinFlip you're not passing ethers to it and you have the following condition in the constructor which cause the error: require(msg.value == 1 ether); which says you have to pass exactly one ether when creating instance of this contract. You need to replace:

v = new CoinFlip();

With:

v = new CoinFlip{value: 1 ether}();
7
  • Thank you so much for responding! I added: receive() external payable {} to my main file and v = new CoinFlip{value: 1 ether}(); to my testing file and I am still getting the same error. Do you have any more tips on what it might be? – privaterabbit1 Feb 28 at 17:13
  • Did you made sure that contract CoinFlipTest actually have 1 ether to make the creation possible? Don't forget that CoinFlipTest is the creator of contract CoinFlip, so he need to have the needed eth balance for the creation. – Miroslav Nedelchev Feb 28 at 17:24
  • no i actually dont have 1 ether in my test account, how should I write it in my code? thank you so much for your help – privaterabbit1 Feb 28 at 17:30
  • Well add this constructor () public payable { } to contract CoinFlipTest and when creating instance of it you can select in remix to pass ether value. Then that contract should have ethers balance to create the other contract. – Miroslav Nedelchev Feb 28 at 17:33
  • Did you made it? – Miroslav Nedelchev Feb 28 at 18:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.