This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function testDonatingAfterTimeIsUp() public { | |
Funding funding = new Funding(0); | |
bool result = funding.call.value(10 finney)(bytes4(keccak256("donate()"))); | |
Assert.equal(result, false); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
FundingTest | |
✓ testSettingAnOwnerDuringCreation (64ms) | |
✓ testSettingAnOwnerOfDeployedContract (57ms) | |
✓ testAcceptingDonations (78ms) | |
✓ testTrackingDonatorsBalance (54ms) | |
Contract: Funding | |
✓ sets an owner | |
✓ accepts donations (60ms) | |
✓ keeps track of donator balance (89ms) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
FundingTest | |
✓ testSettingAnOwnerDuringCreation (64ms) | |
✓ testSettingAnOwnerOfDeployedContract (57ms) | |
✓ testAcceptingDonations (78ms) | |
✓ testTrackingDonatorsBalance (54ms) | |
Contract: Funding | |
✓ sets an owner | |
✓ accepts donations (60ms) | |
✓ keeps track of donator balance (89ms) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// contracts/Funding.sol | |
pragma solidity ^0.4.17; | |
contract Funding { | |
uint public raised; | |
uint public finishesAt; | |
address public owner; | |
mapping(address => uint) public balances; | |
function Funding(uint _duration) public { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const { increaseTime } = require("./utils"); | |
const DAY = 3600 * 24; | |
contract("Funding", accounts => { | |
[...] | |
let funding; | |
beforeEach(async () => { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// source: https://github.com/OpenZeppelin/zeppelin-solidity/blob/master/test/helpers/increaseTime.js | |
module.exports.increaseTime = function increaseTime(duration) { | |
const id = Date.now(); | |
return new Promise((resolve, reject) => { | |
web3.currentProvider.sendAsync( | |
{ | |
jsonrpc: "2.0", | |
method: "evm_increaseTime", | |
params: [duration], |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
FundingTest | |
✓ testSettingAnOwnerDuringCreation (86ms) | |
✓ testAcceptingDonations (112ms) | |
✓ testTrackingDonatorsBalance (64ms) | |
✓ testFinishingFundRising (58ms) | |
Contract: Funding | |
✓ sets an owner (64ms) | |
✓ accepts donations (115ms) | |
✓ keeps track of donator balance (165ms) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import "./Clock.sol"; | |
contract Funding { | |
[...] | |
uint public finishesAt; | |
Clock clock; | |
function Funding(uint _duration, address _clockAddress) public { | |
owner = msg.sender; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// migrations/2_funding.js | |
const Funding = artifacts.require("./Funding.sol"); | |
const Clock = artifacts.require("./Clock.sol"); | |
const DAY = 3600 * 24; | |
module.exports = async function(deployer) { | |
await deployer.deploy(Clock); | |
await deployer.deploy(Funding, DAY, Clock.address); | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function testFinishingFundRising() public { | |
Clock clock = Clock(DeployedAddresses.Clock()); | |
Funding funding = new Funding(1 days, address(clock)); | |
Assert.equal(funding.isFinished(), false); | |
clock.setNow(now + 1 days); | |
Assert.equal(funding.isFinished(), true); | |
} |
NewerOlder