Hi,
Following are my contracts:
pragma solidity 0.5.16;
contract F1{
address public owner;
uint public bal= 1 ether;
constructor() public {
owner = msg.sender;
}
function() external payable {
bal = bal + msg.value;
}
}
== and my tester is:
pragma solidity ^0.5.16;
import "truffle/Assert.sol";
import "truffle/DeployedAddresses.sol";
import "../contracts/Funding.sol";
contract TestFunding {
// Truffle will send the TestContract one Ether after deploying the contract.
uint public initialBalance = 1 ether;
function testInitialBalanceUsingDeployedContract() public {
Funding funding = Funding(DeployedAddresses.Funding());
// perform an action which sends value to myContract, then assert.
address(funding).transfer(10);
Assert.equal(funding.bal(), 0, "Ether transferred");
//Assert.equal(funding.bal, 0,"Ether transferred");
//Assert.equal(funding.bal(), 11,"Ether not transferred");
}
function () external payable {
// This will NOT be executed when Ether is sent. \o/
}
}
2_deploy_contracts.js
const F1 = artifacts.require("F1");
module.exports = function(deployer) {
deployer.deploy(F1);
};
I am getting following error during truffle test:
$ truffle test
Using network 'development'.
Compiling your contracts...
===========================
> Compiling ./contracts/F1.sol
> Compiling ./test/TestF1.sol
> Artifacts written to /tmp/test--13270-blknLiBqwAGU
> Compiled successfully using:
- solc: 0.5.16+commit.9c3226ce.Emscripten.clang
TestF1
1) testInitialBalanceUsingDeployedContract
> No events were emitted
0 passing (6s)
1 failing
1) TestF1
testInitialBalanceUsingDeployedContract:
Error: Returned error: VM Exception while processing transaction: revert
at Context.TestCase (/truffle/build/webpack:/packages/core/lib/testing/SolidityTest.js:92:1)
at process._tickCallback (internal/process/next_tick.js:68:7)
@lc2530hz:~/Truffle_programs/TransferEther2$ truffle version
Truffle v5.1.67 (core: 5.1.67)
Solidity v0.5.16 (solc-js)
Node v10.23.3
Web3.js v1.2.9
Somebody please guide me.
Zulfi.