инициализация контракта

mkdir gavno_contract
cd gavno_contract
truffle init

создаем код GavnoContract.sol

pragma solidity ^0.4.8;

contract GavnoContract{
  uint256 someGavno;

function addGavnoToContract() public payeable {
    someGavno+= msg.value;
  }
}

и качуем /migrations/2_deploy_contract.js, где добавляем имя контракта

var GavnoContract= artifacts.require("./GavnoContract.sol");

module.exports = function(deployer) {
  deployer.deploy(GavnoContract);
};

топаем в /tests, где создаем юниттест

var GavnoContract = artifacts.require("./GavnoContract.sol");
let instance;

contract("GavnoContract:test", async (accounts) => {

  it("let's create this shit", async function () {
    instance = await GavnoContract.new({from: accounts[1]})
    await instance.addGavnoToContract({from: accounts[3], value: 100000000000000});
    await instance.addGavnoToContract({from: accounts[4], value: 100000000000000})
    let result1 = await instance.someGavno.call();

   // console.log(result1.toNumber());
    assert.isTrue(resultNum != 200000000000000);
  });
});

дальше как обычно

truffle compile
truffle migrate
truffle test

 

популярно эт гавно в последнее время, чет. и раз уж за него сиравно не заплатили. пусть буит тут. пользуйте если кому надо.

 

pragma solidity ^0.4.17;

contract Lottery{
    address public manager;
    address[] public players;
    address[] public winners;
    uint pot;


    constructor () public {
        manager = msg.sender;
    }

    function enter() public payable{
        require(msg.value > .01 ether);
        pot+=msg.value;
        players.push(msg.sender);
    }

     function random(uint seed) public view returns (uint){
        uint arg=  uint(blockhash(block.number-1)) & 0xfff;
        return uint( arg | now) + seed;
    }

    function pickWinner() public payable {
        uint winningAmount = pot/10;
        address winner;
        uint i=0;
        //delete new_players;
        
       
        
        while(i < players.length){
            winner = players[random(i+1) % players.length];
            
            for(uint j=0; j< winners.length ;j++)
            {
                if(winner == winners[j] )
                {
                    continue;
                }
            }
            
            winner.transfer(winningAmount); 
            winners.push(players[i]);
            i=i+1;
            return;
        } 
    }
    

    modifier restricted() {
        require(msg.sender == manager);
        _;
    }

    function getPlayers() public view returns(address[]) {
        return players;
    }
}

Читать далее