Test Failed: Transaction reverted

Hi,

I am sending ETher from the test contract and then checking the balance but I am getting the message, Test Failed and Transaction is reverted. My contracts are: //STFB5_test.sol // SPDX-License-Identifier: GPL-3.0

//STFB5_test.sol
// SPDX-License-Identifier: GPL-3.0

//pragma solidity >=0.4.22 <0.9.0;
pragma solidity ^0.5.3;
import "remix_tests.sol"; 
import "remix_accounts.sol";
import "./STFB5.sol";
import "./F5.sol";
// File name has to end with '_test.sol', this file can contain more than one testSuite contracts
contract testSuite {
    /// 'beforeAll' runs before all other tests
    /// More special functions are: 'beforeEach', 'beforeAll', 'afterEach' & 'afterAll'
    F5 obj1 = F5(0xd8b934580fcE35a11B58C6D73aDeE468a2833fa8);
    STFB5 obj2 = STFB5(0xd9145CCE52D386f254917e481eB44e9943F39138);
    address payable F5addr = 0xd8b934580fcE35a11B58C6D73aDeE468a2833fa8;
    address payable STFB5addr = 0xd9145CCE52D386f254917e481eB44e9943F39138;
   
    function beforeAll() public payable {
       uint a = 10;
       uint b = 20;
       F5addr.transfer(a);
       STFB5addr.transfer(b);
      
    }
     function initialValueofObj1ShouldBe100() public returns (bool) {
       return Assert.equal(obj1.getBalance(), 0, "initial value is not correct");
    }
    function initialValueofObj2ShouldBe100() public returns (bool) {
       return Assert.equal(obj2.getBalance(), 0, "initial value is not correct");
    }
 }

//STFB5.sol

pragma solidity ^0.5.3;
contract STFB5 {
    function transferToFallback(address payable _to) public payable {
        _to.transfer(msg.value);
    }

    //function() external payable{
    //}
    function getBalance() public view returns (uint) {
        return address(this).balance;
    }
    function () external payable {

    }
}

//F5.sol

pragma solidity ^0.5.3;

contract F5 {
    //event Log(uint gas);

    // Fallback function must be declared as external.
    //function() external payable {
        // send / transfer (forwards 2300 gas to this fallback function)
        // call (forwards all of the gas)
        //emit Log(gasleft());
    //}
    function () external payable  {}
    // Helper function to check the balance of this contract
    function getBalance() public view returns (uint) {
        return address(this).balance;
    }
   
}

I am getting transaction failed message:

FAIL testSuite (tests/Copy_STFB5_test.sol)
โœ˜ Before all
Error Message:
"Transaction has been reverted by the EVM: { "transactionHash": "0x64ecdb166bcfa8c401735cad166f4aad4dc85ba8695a972557f2e94d2d1bb888", "transactionIndex": 0, "blockHash": "0xd41280b6b4bb1d8d132ecf2bc941c1d2ca47c07e59a1133bb214f44ee82909b9", "blockNumber": 15, "gasUsed": 32750, "cumulativeGasUsed": 32750, "status": false, "to": "0x9d83e140330758a8fFD07F8Bd73e86ebcA8a5692", "events": {} }"
โœ˜ Initial valueof obj1 should be100
Error Message:
"Transaction has been reverted by the EVM: { "transactionHash": "0xf107ba86241746b12a9635e1eaef1e6b761356f7202d38594be34d6bf63d0e71", "transactionIndex": 0, "blockHash": "0x95b858e886318f16ebfa336536fe2d8610336a2e5f35343abe2563e0a9d2a0b8", "blockNumber": 16, "gasUsed": 26387, "cumulativeGasUsed": 26387, "status": false, "to": "0x9d83e140330758a8fFD07F8Bd73e86ebcA8a5692", "events": {} }"
โœ˜ Initial valueof obj2 should be100
Error Message:
"Transaction has been reverted by the EVM: { "transactionHash": "0x5982b16ffdaa0e8fef25b5880abb4b5fa619a9566e0e9ab8b27f80bce4856138", "transactionIndex": 0, "blockHash": "0x253a34e3eb4cbb3eb50bab6119ca74ca9dc9c3aec3ce4a1c05ca8c70de085a9a", "blockNumber": 17, "gasUsed": 26431, "cumulativeGasUsed": 26431, "status": false, "to": "0x9d83e140330758a8fFD07F8Bd73e86ebcA8a5692", "events": {} }"
Result for tests/Copy_STFB5_test.sol
Failing: 3
Total time: 0.15s

Somebody please guide me.
Zulfi.

do you know how to deploy those smart contracts in remix? you can debug in remix and see exactly at what line it reverts.

2 Likes

Hi,
It says โ€œinitial value of obj1should be100โ€.

Can you please tell me what does it mean? Is this value related to balance? I donโ€™t have any such statement in my SC. Please guide me.

Zulfi.

That message Looks to be something from your test suite

1 Like

Hi,
Thanks a lot.

Its the methodโ€™s name.

Zulfi.