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/Clock.sol | |
pragma solidity ^0.4.17; | |
contract Clock { | |
uint private timestamp; | |
function getNow() public view returns (uint) { | |
if (timestamp > 0) { | |
return timestamp; | |
} |
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 (61ms) | |
✓ testSettingAnOwnerOfDeployedContract (65ms) | |
✓ testAcceptingDonations (97ms) | |
✓ testTrackingDonatorsBalance (61ms) | |
Contract: Funding | |
✓ sets an owner (51ms) | |
✓ accepts donations (96ms) | |
✓ keeps track of donator balance (134ms) |
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
contract Funding { | |
uint public raised; | |
address public owner; | |
mapping(address => uint) public balances; | |
function Funding() public { | |
owner = msg.sender; | |
} | |
function donate() public payable { |
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
it("keeps track of donator balance", async () => { | |
const funding = await Funding.new(); | |
await funding.donate({ from: firstAccount, value: 5 * FINNEY }); | |
await funding.donate({ from: secondAccount, value: 15 * FINNEY }); | |
await funding.donate({ from: secondAccount, value: 3 * FINNEY }); | |
assert.equal(await funding.balances.call(firstAccount), 5 * FINNEY); | |
assert.equal(await funding.balances.call(secondAccount), 18 * FINNEY); | |
}); |
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 (68ms) | |
✓ testSettingAnOwnerOfDeployedContract (63ms) | |
✓ testAcceptingDonations (80ms) | |
Contract: Funding | |
✓ sets an owner (56ms) | |
✓ accepts donations (96ms) | |
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 testTrackingDonatorsBalance() public { | |
Funding funding = new Funding(); | |
funding.donate.value(5 finney)(); | |
funding.donate.value(15 finney)(); | |
Assert.equal(funding.balances(this), 20 finney); | |
} |
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
contract Funding { | |
uint public raised; | |
address public owner; | |
function Funding() public { | |
owner = msg.sender; | |
} | |
function donate() public payable { | |
raised += msg.value; |
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 FINNEY = 10**15; | |
contract("Funding", accounts => { | |
const [firstAccount, secondAccount] = accounts; | |
it("accepts donations", async () => { | |
const funding = await Funding.new(); | |
await funding.donate({ from: firstAccount, value: 10 * FINNEY }); | |
await funding.donate({ from: secondAccount, value: 20 * FINNEY }); | |
assert.equal(await funding.raised.call(), 30 * FINNEY); |
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
contract FundingTest { | |
uint public initialBalance = 10 ether; | |
function testAcceptingDonations() public { | |
Funding funding = new Funding(); | |
Assert.equal(funding.raised(), 0); | |
funding.donate.value(10 finney)(); | |
funding.donate.value(20 finney)(); | |
Assert.equal(funding.raised(), 30 finney); | |
} |
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 (70ms) | |
✓ testSettingAnOwnerOfDeployedContract (63ms) | |
Contract: Funding | |
✓ sets an owner (62ms) | |
3 passing (744ms) |