I'm having problems with testrpc, or at least I think that's the cause. This particular portion of code
if (now > info.deadline) {
ended = true;
refundEnabled = true;
return false;
}
is never executed, it's as if now (or block.timestamp) is always smaller than deadline even when it's clearly not. Deadline is in unix timestamp (for example 1487399645), but that code is not executed even if I put 1.
Here's the contract:
pragma solidity ^0.4.6;
contract Project {
struct projectInfo {
address projectOwner;
string name;
uint256 amountToRaise;
uint256 deadline;
}
projectInfo public info;
uint256 public amountRaised;
bool public ended;
bool public refundEnabled;
mapping(address => uint256) public contributions;
function Project(string name, uint256 amountToRaise, uint256 deadline) {
info = projectInfo(tx.origin, name, amountToRaise, deadline);
amountRaised = 0;
ended = false;
refundEnabled = false;
}
function getInfo() constant returns (address, string, uint256, uint256) {
return (info.projectOwner, info.name, info.amountToRaise, info.deadline);
}
function fund() payable returns (bool successful) {
if (ended) {
return false;
}
contributions[tx.origin] += msg.value;
amountRaised += msg.value;
if (now > info.deadline) {
ended = true;
refundEnabled = true;
return false;
}
if (amountRaised >= info.amountToRaise) {
ended = true;
payout();
}
return true;
}
function payout() private returns (bool successful) {
if (ended) {
if (!info.projectOwner.send(this.balance)) {
throw;
}
}
}
function refund() public returns (bool successful) {
if (refundEnabled) {
if (contributions[msg.sender] > 0) {
if (msg.sender.send(contributions[msg.sender])) {
contributions[msg.sender] = 0;
return true;
} else {
return false;
}
} else {
throw;
}
}
}
}
I'm deploying the contract from another contract and I'm testing fund() with this piece of Javascript:
function fund(address) {
project = Project.at(address);
project.fund({from: coinbase, value: 50, gas: 150000}).then(function(value) {
console.log(value);
});
}
The contract works perfectly on Browser Solidity, on TestRPC everything works fine except that particular if statement. Is this a problem of TestRPC or am I doing something wrong? I'm using TestRPC v3.0.3.