Example #1
0
def run_simulation():
    s = tester.state()
    s.block.gas_limit = SIM_GAS * 2
    tester.gas_limit = SIM_GAS
    simulation = s.contract('simulation.se')
    logger.register_address('sim', simulation)
    a_ai = s.contract('ai_simple.se')
    logger.register_address('a_ai', a_ai)
    b_ai = s.contract('ai_two.se')
    #b_ai = s.contract('ai_simple.se')
    logger.register_address('b_ai', b_ai)

    try:
        winner = s.send(tester.k0, simulation, 0, data=[a_ai, b_ai])
    except Exception as e:
        print 'last messages'
        logger.print_log_history(8)
        raise e

    if not winner:
        print 'simulation failed, last logs:'
        print logger.print_log_history(2)
    elif a_ai in hex(winner[0]):
        print "A WINS " * 5
    else:
        assert b_ai in hex(winner[0])
        print "B WINS " * 5
Example #2
0
def run_simulation():
    s = tester.state()
    s.block.gas_limit = SIM_GAS * 2
    tester.gas_limit = SIM_GAS
    simulation = s.contract('simulation.se')
    logger.register_address('sim', simulation)
    a_ai = s.contract('ai_simple.se')
    logger.register_address('a_ai', a_ai)
    b_ai = s.contract('ai_two.se')
    #b_ai = s.contract('ai_simple.se')
    logger.register_address('b_ai', b_ai)

    try:
        winner = s.send(tester.k0, simulation, 0, data=[a_ai, b_ai])
    except Exception as e:
        print 'last messages'
        logger.print_log_history(8)
        raise e

    if not winner:
        print 'simulation failed, last logs:'
        print logger.print_log_history(2)
    elif a_ai in hex(winner[0]):
        print "A WINS " * 5
    else:
        assert b_ai in hex(winner[0])
        print "B WINS " * 5
Example #3
0
def test_simluation_setup():
    s = tester.state()
    simulation = s.contract("simulation.se")
    logger.register_address("sim", simulation)
    a_ai = s.contract("ai_simple.se")
    logger.register_address("a_ai", a_ai)
    b_ai = s.contract("ai_two.se")
    logger.register_address("b_ai", b_ai)
    try:
        print s.send(tester.k0, simulation, 0, data=[a_ai, b_ai])
    except Exception, e:
        print "\n".join(repr(x) for x in logger.get_history(1))
        raise e
Example #4
0
def test_simluation_setup():
    s = tester.state()
    simulation = s.contract('simulation.se')
    logger.register_address('sim', simulation)
    a_ai = s.contract('ai_simple.se')
    logger.register_address('a_ai', a_ai)
    b_ai = s.contract('ai_two.se')
    logger.register_address('b_ai', b_ai)
    try:
        print s.send(tester.k0, simulation, 0, data=[a_ai, b_ai])
    except Exception, e:
        print '\n'.join(repr(x) for x in logger.get_history(1))
        raise e
Example #5
0
"""

code_msg = """
address = msg.data[0]
insize = 68
outsize = 3
datarray = array(insize)
gas = 1000
value = 0
move = msg(gas, address, value, datarray, insize, outsize)
return(move, 3)
"""

print 'setting up contracts',
s = tester.state()
logger.register_address('EOA', tester.a0)

c1 = s.contract(code_sub, sender=tester.k0)
logger.register_address('code_sub', c1)

c2 = s.contract(code_call, sender=tester.k0)
logger.register_address('code_call', c2)

c3 = s.contract(code_msg, sender=tester.k0)
logger.register_address('code_msg', c3)

move = [1, 2, 3]

# fails on osx and linux
print
print "test msg()"
# not really py.test but used for testing while development

from testenv import tester
from testenv import run, logger

s = tester.state()
c = s.contract('quicksort_pairs_debug.se')
logger.register_address('qsort', c)

def test_quicksort(data, expected):


    print 'testing', data, expected
    r = s.send(tester.k0, c, 0, data=data)
    assert expected == r, (r, expected)

test_quicksort([30, 1],[30, 1])
test_quicksort([30, 1, 20, 2],[20, 2, 30, 1])
test_quicksort([30, 0, 20, 2],[20, 2, 30, 0])
test_quicksort([30, 1, 90, 2, 70, 3, 50, 4],[ 30, 1, 50, 4, 70, 3, 90, 2 ])


Example #7
0
# not really py.test but used for testing while development

from testenv import tester
from testenv import run, logger

s = tester.state()
c = s.contract('quicksort_pairs_debug.se')
logger.register_address('qsort', c)


def test_quicksort(data, expected):

    print 'testing', data, expected
    r = s.send(tester.k0, c, 0, data=data)
    assert expected == r, (r, expected)


test_quicksort([30, 1], [30, 1])
test_quicksort([30, 1, 20, 2], [20, 2, 30, 1])
test_quicksort([30, 0, 20, 2], [20, 2, 30, 0])
test_quicksort([30, 1, 90, 2, 70, 3, 50, 4], [30, 1, 50, 4, 70, 3, 90, 2])
Example #8
0
code_msg = """
address = msg.data[0]
insize = 68
outsize = 3
datarray = array(insize)
gas = 1000
value = 0
move = msg(gas, address, value, datarray, insize, outsize)
return(move, 3)
"""


print 'setting up contracts',
s = tester.state()
logger.register_address('EOA', tester.a0)

c1 = s.contract(code_sub, sender=tester.k0)
logger.register_address('code_sub', c1)

c2 = s.contract(code_call, sender=tester.k0)
logger.register_address('code_call', c2)

c3 = s.contract(code_msg, sender=tester.k0)
logger.register_address('code_msg', c3)



move = [1, 2, 3]