diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..b1dc8d2 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,18 @@ +language: node_js +node_js: + - "stable" + +services: + - docker + +cache: + directories: + - node_modules + +before_install: + - npm install -g truffle + - docker run -d -p 8545:8545 trufflesuite/ganache-cli:latest + +script: + - truffle migrate + - truffle test diff --git a/README.md b/README.md index fa1ae3b..161b7cf 100644 --- a/README.md +++ b/README.md @@ -1,9 +1,14 @@ # testcoders-blockchain-meetup ## Getting started -Make sure you have `truffle` and `testrpc` installed +Make sure you have `truffle` and `ganache-cli` installed ```bash -npm install -g truffle ethereumjs-testrpc +npm install -g truffle npm ganache-cli +``` + +Run ganache (formerly known as testrpc) +```bash +ganache-cli ``` `cd` into the repository directory and run the following command to create build artifacts for the smart contract: diff --git a/contracts/TestCodersToken.sol b/contracts/TestCodersToken.sol index 7f0bcd9..54f37eb 100644 --- a/contracts/TestCodersToken.sol +++ b/contracts/TestCodersToken.sol @@ -3,24 +3,24 @@ pragma solidity ^0.4.18; contract ERC20Interface { // Get the total token supply - function totalSupply() constant returns (uint256); + function totalSupply() public constant returns (uint256); // Get the account balance of another account with address _owner - function balanceOf(address _owner) constant returns (uint256 balance); + function balanceOf(address _owner) public constant returns (uint256 balance); // Send _value amount of tokens to address _to - function transfer(address _to, uint256 _value) returns (bool success); + function transfer(address _to, uint256 _value) public returns (bool success); // Send _value amount of tokens from address _from to address _to - function transferFrom(address _from, address _to, uint256 _value) returns (bool success); + function transferFrom(address _from, address _to, uint256 _value) public returns (bool success); // Allow _spender to withdraw from your account, multiple times, up to the _value amount. // If this function is called again it overwrites the current allowance with _value. // this function is required for some DEX functionality - function approve(address _spender, uint256 _value) returns (bool success); + function approve(address _spender, uint256 _value) public returns (bool success); // Returns the amount which _spender is still allowed to withdraw from _owner - function allowance(address _owner, address _spender) constant returns (uint256 remaining); + function allowance(address _owner, address _spender) public constant returns (uint256 remaining); // Triggered when tokens are transferred. event Transfer(address indexed _from, address indexed _to, uint256 _value); @@ -53,26 +53,26 @@ contract TestCodersToken is ERC20Interface { } // Constructor - function TestCodersToken() { + function TestCodersToken() public { owner = msg.sender; balances[owner] = _totalSupply; } - function totalSupply() constant returns (uint256) { + function totalSupply() constant public returns (uint256) { return _totalSupply; } // What is the balance of a particular account? - function balanceOf(address _owner) constant returns (uint256 balance) { + function balanceOf(address _owner) constant public returns (uint256 balance) { return balances[_owner]; } // Transfer the balance from owner's account to another account - function transfer(address _to, uint256 _amount) returns (bool success) { + function transfer(address _to, uint256 _amount) public returns (bool success) { if (balances[msg.sender] >= _amount && _amount > 0 && balances[_to] + _amount > balances[_to]) { balances[msg.sender] -= _amount; balances[_to] += _amount; - Transfer(msg.sender, _to, _amount); + emit Transfer(msg.sender, _to, _amount); return true; } else { return false; @@ -89,12 +89,13 @@ contract TestCodersToken is ERC20Interface { address _from, address _to, uint256 _amount - ) returns (bool success) - { if (balances[_from] >= _amount && allowed[_from][msg.sender] >= _amount && _amount > 0 && balances[_to] + _amount > balances[_to]) { + ) public returns (bool success) + { + if (balances[_from] >= _amount && allowed[_from][msg.sender] >= _amount && _amount > 0 && balances[_to] + _amount > balances[_to]) { balances[_from] -= _amount; allowed[_from][msg.sender] -= _amount; balances[_to] += _amount; - Transfer(_from, _to, _amount); + emit Transfer(_from, _to, _amount); return true; } else { return false; @@ -103,13 +104,13 @@ contract TestCodersToken is ERC20Interface { // Allow _spender to withdraw from your account, multiple times, up to the _value amount. // If this function is called again it overwrites the current allowance with _value. - function approve(address _spender, uint256 _amount) returns (bool success) { + function approve(address _spender, uint256 _amount) public returns (bool success) { allowed[msg.sender][_spender] = _amount; - Approval(msg.sender, _spender, _amount); + emit Approval(msg.sender, _spender, _amount); return true; } - function allowance(address _owner, address _spender) constant returns (uint256 remaining) { + function allowance(address _owner, address _spender) public constant returns (uint256 remaining) { return allowed[_owner][_spender]; } } \ No newline at end of file