Exemplo n.º 1
0
def erc20():
    t.languages['viper'] = compiler.Compiler()
    contract_code = open('examples/tokens/vipercoin.v.py').read()
    return s.contract(
        contract_code,
        language='viper',
        args=[TOKEN_NAME, TOKEN_SYMBOL, TOKEN_DECIMALS, TOKEN_INITIAL_SUPPLY])
def custom_chain(tester,
                 alloc={},
                 genesis_gas_limit=4712388,
                 min_gas_limit=5000,
                 startgas=3141592):
    # alloc
    for i in range(9):
        alloc[utils.int_to_addr(i)] = {'balance': 1}
    # genesis
    from ethereum.genesis_helpers import mk_basic_state
    header = {
        "number": 0,
        "gas_limit": genesis_gas_limit,
        "gas_used": 0,
        "timestamp": 1467446877,
        "difficulty": 1,
        "uncles_hash": '0x' + utils.encode_hex(utils.sha3(rlp.encode([])))
    }
    genesis = mk_basic_state(alloc, header, tester.get_env(None))
    # tester
    tester.languages['viper'] = compiler.Compiler()
    tester.STARTGAS = startgas
    c = tester.Chain(alloc=alloc, genesis=genesis)
    c.chain.env.config['MIN_GAS_LIMIT'] = min_gas_limit
    c.mine(1)
    return c
Exemplo n.º 3
0
 def setUp(self):
     # Initialize tester, contract and expose relevant objects
     self.t = tester
     self.s = self.t.Chain()
     from viper import compiler
     self.t.languages['viper'] = compiler.Compiler()
     self.c = self.s.contract(open('erc20.v.py').read(), language='viper')
def identiy_tester():
    tester.s = tester.Chain()
    from viper import compiler
    tester.languages['viper'] = compiler.Compiler()
    contract_code = open('contracts/identity/erc_735.v.py').read()
    tester.c = tester.s.contract(contract_code, language='viper', args=[])
    return tester
Exemplo n.º 5
0
def test_chain(alloc={},
               genesis_gas_limit=9999999,
               min_gas_limit=5000,
               startgas=3141592):
    # alloc
    alloc[tester.a0] = {'balance': 100000 * utils.denoms.ether}

    for i in range(9):
        alloc[utils.int_to_addr(i)] = {'balance': 1}
    # genesis
    header = {
        "number": 0,
        "gas_limit": genesis_gas_limit,
        "gas_used": 0,
        "timestamp": 1467446877,
        "difficulty": 1,
        "uncles_hash": '0x' + utils.encode_hex(utils.sha3(rlp.encode([])))
    }
    genesis = mk_basic_state(alloc, header, tester.get_env(None))
    # tester
    tester.languages['viper'] = compiler.Compiler()
    tester.STARTGAS = startgas
    chain = tester.Chain(alloc=alloc, genesis=genesis)
    chain.chain.env.config['MIN_GAS_LIMIT'] = min_gas_limit
    chain.mine(1)
    return chain
Exemplo n.º 6
0
def auction_tester(t):
    from viper import compiler
    t.languages['viper'] = compiler.Compiler()
    contract_code = open('examples/auctions/simple_open_auction.v.py').read()
    t.c = t.s.contract(contract_code,
                       language='viper',
                       args=[t.accounts[0], FIVE_DAYS])
    return t
Exemplo n.º 7
0
 def __init__(self, web3_address, owner, owner_password):
     self.web3 = Web3(HTTPProvider(web3_address))
     self.web3.personal.unlockAccount(owner, owner_password, 0)
     self.owner = owner
     self.cmp = compiler.Compiler()
     self.wait_delta = 5
     self.wait_total = 120
     self.gas = 2500000
Exemplo n.º 8
0
 def setUp(self):
     # Initialize tester, contract and expose relevant objects
     self.t = tester
     self.s = self.t.Chain()
     from viper import compiler
     self.t.languages['viper'] = compiler.Compiler()
     contract_code = open('examples/voting/ballot.v.py').read()
     self.c = self.s.contract(contract_code, language='viper', args=[["Clinton", "Trump"]])
Exemplo n.º 9
0
 def setUp(self):
     print("testing set-up, and initialization")
     # Initialize tester, contract and expose relevant objects
     self.t = tester
     self.s = self.t.Chain()
     from viper import compiler
     self.t.languages['viper'] = compiler.Compiler()
     self.c = self.s.contract(open('erc223.v.py').read(),
                              args=['VitalikToken', 'VTK'],
                              language='viper')
Exemplo n.º 10
0
def tester():
    tester = t
    tester.s = t.Chain()
    tester.s.head_state.gas_limit = 10**9
    tester.languages['viper'] = compiler.Compiler()
    contract_code = open('examples/stock/company.v.py').read()
    tester.company_address = t.a0
    # Company with 1000 shares @ 10^6 wei / share
    tester.c = tester.s.contract(contract_code, language='viper', \
            args=[tester.company_address, 1000, 10**6])
    return tester
Exemplo n.º 11
0
def token_tester():
    t = tester
    tester.s = t.Chain()
    from viper import compiler
    t.languages['viper'] = compiler.Compiler()
    contract_code = open('examples/tokens/vipercoin.v.py').read()
    tester.c = tester.s.contract(
        contract_code,
        language='viper',
        args=[TOKEN_NAME, TOKEN_SYMBOL, TOKEN_DECIMALS, TOKEN_INITIAL_SUPPLY])
    return tester
Exemplo n.º 12
0
    def setUpClass(cls):
        super(TestViperERC20, cls).setUpClass()

        from viper import compiler
        cls.t.languages['viper'] = compiler.Compiler()
        contract_code = open(PATH_TO_CONTRACTS + '/../../../../examples/tokens/ERC20_solidity_compatible/ERC20.v.py').read()
        cls.c = cls.s.contract(contract_code, language='viper')
        # Bad version of contract where totalSupply / num_issued never gets updated after init
        # (required for full decision/branch coverage)
        bad_code = contract_code.replace("self.num_issued = num256_add", "x = num256_add")
        cls.c_bad = cls.s.contract(bad_code, language='viper')

        cls.initial_state = cls.s.snapshot()
        cls.strict_log_mode = True
        cls.listenForEvents()
Exemplo n.º 13
0
def test_chain(alloc=tester.base_alloc, genesis_gas_limit=9999999,
               min_gas_limit=5000, startgas=3141592):
    # genesis
    header = {
        "number": 0, "gas_limit": genesis_gas_limit,
        "gas_used": 0, "timestamp": 1467446877, "difficulty": 1,
        "uncles_hash": '0x'+utils.encode_hex(utils.sha3(rlp.encode([])))
    }
    genesis = mk_basic_state(alloc, header, tester.get_env(None))
    # tester
    tester.languages['viper'] = compiler.Compiler()
    tester.STARTGAS = startgas
    chain = tester.Chain(alloc=alloc, genesis=genesis)
    chain.chain.env.config['MIN_GAS_LIMIT'] = min_gas_limit
    chain.mine(1)
    return chain
Exemplo n.º 14
0
import pytest
from functools import wraps

from viper import parser, compile_lll, utils
from viper import compiler
from ethereum.tools import tester
from ethereum import transactions, messages
from ethereum import utils as ethereum_utils
import rlp
from ethereum.slogging import LogRecorder, configure_logging, set_level
config_string = ':info,eth.vm.log:trace,eth.vm.op:trace,eth.vm.stack:trace,eth.vm.exit:trace,eth.pb.msg:trace,eth.pb.tx:debug'
#configure_logging(config_string=config_string)

chain = tester.Chain()
tester.languages['viper'] = compiler.Compiler()


def inject_tx(txhex):
    tx = rlp.decode(ethereum_utils.decode_hex(txhex[2:]),
                    transactions.Transaction)
    chain.head_state.set_balance(tx.sender, tx.startgas * tx.gasprice)
    chain.chain.state.set_balance(tx.sender, tx.startgas * tx.gasprice)
    messages.apply_transaction(chain.head_state, tx)
    chain.block.transactions.append(tx)
    contract_address = ethereum_utils.sha3(rlp.encode([tx.sender, 0]))[12:]
    assert chain.head_state.get_code(contract_address)
    chain.mine(1)
    return contract_address


_rlp_decoder_address = inject_tx(
Exemplo n.º 15
0
def srp_tester():
    t = tester
    tester.s = t.Chain()
    from viper import compiler
    t.languages["viper"] = compiler.Compiler()
    return tester
Exemplo n.º 16
0
def market_maker(t, chain):
    t.languages['viper'] = compiler.Compiler()
    contract_code = open('examples/market_maker/on_chain_market_maker.v.py').read()
    return chain.contract(contract_code, language='viper')