# VM Exception while processing transaction revert

**URL:** <https://forum.openzeppelin.com/t/vm-exception-while-processing-transaction-revert/20872>\
**Category:** General\
**Created:** [December 13, 2021, 5:22am UTC](https://forum.openzeppelin.com/t/vm-exception-while-processing-transaction-revert/20872 "2021-12-13T05:22:05Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![zak100](https://avatars.discourse-cdn.com/v4/letter/z/d26b3c/32.png) [@zak100](https://forum.openzeppelin.com/u/zak100)\
**Post date:** [December 13, 2021, 5:22am UTC](https://forum.openzeppelin.com/t/vm-exception-while-processing-transaction-revert/20872/1 "2021-12-13T05:22:05Z")

</div>

Hi,  
I have two smart contracts (SCs): sender and receiver and a tester. I am using truffle test. I don't know how to send Ether to a SC using truffle test. The sender has no Ether balance. Maybe this is the reason, I am getting VM error:

```auto
pragma solidity ^0.5.8;

contract sender{
   address owner;
constructor () public{
   owner = msg.sender;
}

function transferTo(address to, uint amount) public{
   (bool success,) = to.call.value(amount)("");
   require (success);
}
function() external payable{}
}

```

Following is my receiver:

```auto
pragma solidity ^0.5.8;
contract receiver{
   address public owner;
   mapping(address => uint) public balance; 
constructor () public{
   owner = msg.sender;
}
function() external payable{
   balance[owner] += msg.value;}
}

```

Following is my tester:

```auto

pragma solidity ^0.5.8;
import "truffle/Assert.sol";
import "../contracts/sender.sol";
import "../contracts/receiver.sol";
contract TestTransfer{
   function testTransfer() public{
      sender senderObj = new sender();
      receiver receiverObj = new receiver();
      senderObj.transferTo(msg.sender, 10);
      Assert.equal(receiverObj.balance(receiverObj.owner()), 10, "Received amount is not correct");
   }
}

```

Output says that my test fails and displays an error message.

The output and the error message is given below:

```auto
TestTransfer
    1) testTransfer
    > No events were emitted

  0 passing (5s)
  1 failing

  1) TestTransfer
       testTransfer:
     Error: Returned error: VM Exception while processing transaction: revert
      at Context.TestCase (/home/zulfi/.nvm/versions/node/v10.23.3/lib/node_modules/truffle/build/webpack:/packages/core/lib/testing/SolidityTest.js:92:1)
      at process._tickCallback (internal/process/next_tick.js:68:7)

```

Somebody please guide me. Maybe sender does not have any Ether.  
Zulfi.

---

<div class="post-metadata">

**Author:** ![Skyge](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.openzeppelin.com/skyge/32/343_2.png) [@Skyge](https://forum.openzeppelin.com/u/Skyge)\
**Post date:** [December 14, 2021, 4:13pm UTC](https://forum.openzeppelin.com/t/vm-exception-while-processing-transaction-revert/20872/2 "2021-12-14T16:13:02Z")

</div>

Hey, I think there is no Ether in the `sender` contract when you call `testTransfer` to make a new one, so maybe you can change your code like this:

```auto
function testTransfer() public payable{
      sender senderObj = new sender();
      address(senderObj).transfer(msg.value); // <<<--- add this line to transfer some ETH
      receiver receiverObj = new receiver();
      senderObj.transferTo(msg.sender, 10);
      //Assert.equal(receiverObj.balance(msg.sender)), 10, "Received amount is not correct"); 
}

```

If Alice calls `testTransfer`, she is the `msg.sender`, and in this function, it creates two new contracts, so for these two contracts, `msg.sender` is the contract `TestTransfer `, so if the `sender` contract has ether, and when it executes `senderObj.transferTo(msg.sender, 10);`, the caller(Alice) should get 10 wei.

---

<div class="post-metadata">

**Author:** ![zak100](https://avatars.discourse-cdn.com/v4/letter/z/d26b3c/32.png) [@zak100](https://forum.openzeppelin.com/u/zak100)\
**Post date:** [December 15, 2021, 3:41am UTC](https://forum.openzeppelin.com/t/vm-exception-while-processing-transaction-revert/20872/3 "2021-12-15T03:41:34Z")

</div>

Hi my friend,  
Thanks for your response. Actually, I am executing "Truffle test". testTransfer is the function of TestTransfer, so it will execute. No body is calling testTransfer() except "Truffle test". Your changes are giving the same error.

```auto
$ truffle test
Using network 'development'.

Compiling your contracts...
===========================
> Compiling ./test/testingTransfer.sol
> Artifacts written to /tmp/test--9488-EXBU1Pcl3Vyp
> Compiled successfully using:
   - solc: 0.5.16+commit.9c3226ce.Emscripten.clang

  TestTransfer
    1) testTransfer

```

```
> No events were emitted

```

0 passing (6s)  
1 failing

> 1. TestTransfer  
> testTransfer:  
> Error: Returned error: VM Exception while processing transaction: revert  
> at Context.TestCase (testing/SolidityTest.js:92:1)  
> at process.\_tickCallback (internal/process/next\_tick.js:68:7)

Somebody please guide me.

Zulfi.
