Advertisement
Guest User

Untitled

a guest
Jun 27th, 2019
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.49 KB | None | 0 0
  1. pragma solidity ^0.5.0;
  2.  
  3. import "./DappToken.sol";
  4.  
  5. contract DappTokenSale {
  6.  
  7. address admin;
  8. DappToken public tokenContract;
  9.  
  10. constructor (DappToken _tokenContract) public {
  11. admin = msg.sender;
  12. tokenContract = _tokenContract;
  13.  
  14. }
  15. }
  16.  
  17. var DappTokenSale = artifacts.require('./DappTokenSale.sol');
  18.  
  19. contract('DappTokenSale', function(accounts) {
  20. var tokenSaleInstance;
  21.  
  22. it('initializes the contract with the correct values', function() {
  23. return DappTokenSale.deployed().then(function(instance) {
  24. tokenSaleInstance = instance;
  25. return tokenSaleInstance.address
  26. }).then(function(address) {
  27. assert.notEqual(address, 0x0, "has contract address");
  28. return tokenSaleInstance.tokenContract();
  29. })..then(function(address) {
  30. assert.notEqual(address, 0x0, "has token contract address");
  31. });
  32. });
  33. });
  34.  
  35. pragma solidity ^0.5.0;
  36.  
  37. contract DappToken {
  38. string public name = "Dapp Token";
  39. string public symbol = "DToken";
  40. string public standard = "DToken v1.0";
  41. uint256 public totalSupply;
  42.  
  43. event Transfer(
  44. address indexed _from,
  45. address indexed _to,
  46. uint256 _value
  47. );
  48.  
  49. event Approval(
  50. address indexed _owner,
  51. address indexed _spender,
  52. uint256 _value
  53. );
  54.  
  55. mapping(address => uint256) public balanceOf;
  56. mapping(address => mapping(address => uint256)) public allowance;
  57.  
  58. constructor(uint256 _initialSupply) public {
  59. balanceOf[msg.sender] = _initialSupply;
  60. totalSupply = _initialSupply;
  61. }
  62.  
  63. function transfer (address _to, uint256 _value) public returns(bool success) {
  64. require(balanceOf[msg.sender] >= _value);
  65. balanceOf[msg.sender] -= _value;
  66. balanceOf[_to] += _value;
  67.  
  68. emit Transfer(msg.sender, _to, _value);
  69. return true;
  70. }
  71.  
  72. function approve(address _spender, uint256 _value) public returns(bool success) {
  73. allowance[msg.sender][_spender] = _value;
  74. emit Approval(msg.sender, _spender, _value);
  75. return true;
  76. }
  77.  
  78. function transferFrom(address _from, address _to, uint256 _value) public returns(bool success) {
  79.  
  80. require (_value <= balanceOf[_from]);
  81. require (_value <= allowance[_from][msg.sender]);
  82.  
  83. balanceOf[_from] -= _value;
  84. balanceOf[_to] += _value;
  85.  
  86. allowance[_from][msg.sender] -= _value;
  87.  
  88. emit Transfer( _from, _to, _value);
  89. return true;
  90. }
  91.  
  92. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement