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
var Election = artifacts.require("./Election.sol"); | |
contract("Election", function(accounts) { | |
var electionInstance; | |
it("initializes with two candidates", function() { | |
return Election.deployed().then(function(instance) { | |
return instance.candidatesCount(); | |
}).then(function(count) { | |
assert.equal(count, 2); |
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
App = { | |
web3Provider: null, | |
contracts: {}, | |
account: '0x0', | |
init: function() { | |
return App.initWeb3(); | |
}, | |
initWeb3: function() { |
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
pragma solidity 0.4.24; | |
contract Election { | |
// Read/write candidate | |
string public candidate; | |
// Constructor | |
constructor () public { | |
candidate = "Candidate 1"; | |
} |
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
var Election = artifacts.require("./Election.sol"); | |
module.exports = function(deployer) { | |
deployer.deploy(Election); | |
}; |
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 Election { | |
// Model a Candidate | |
struct Candidate { | |
uint id; | |
string name; | |
uint voteCount; | |
} | |
// Read/write Candidates | |
mapping(uint => Candidate) public candidates; |
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 Election { | |
// ... | |
function addCandidate (string _name) private { | |
candidatesCount ++; | |
candidates[candidatesCount] = Candidate(candidatesCount, _name, 0); | |
} | |
} |
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 Election { | |
// ... | |
constructor () public { | |
addCandidate("Candidate 1"); | |
addCandidate("Candidate 2"); | |
} | |
// ... | |
} |
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
pragma solidity ^0.4.24; | |
contract Election { | |
// Model a Candidate | |
struct Candidate { | |
uint id; | |
string name; | |
uint voteCount; | |
} |
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
var Election = artifacts.require("./Election.sol"); | |
contract("Election", function(accounts) { | |
var electionInstance; | |
it("initializes with two candidates", function() { | |
return Election.deployed().then(function(instance) { | |
return instance.candidatesCount(); | |
}).then(function(count) { | |
assert.equal(count, 2); |
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
App = { | |
web3Provider: null, | |
contracts: {}, | |
account: '0x0', | |
init: function() { | |
return App.initWeb3(); | |
}, | |
initWeb3: function() { |
OlderNewer