当前位置: 首页>>代码示例>>Python>>正文


Python tester.k0方法代码示例

本文整理汇总了Python中ethereum.tester.k0方法的典型用法代码示例。如果您正苦于以下问题:Python tester.k0方法的具体用法?Python tester.k0怎么用?Python tester.k0使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ethereum.tester的用法示例。


在下文中一共展示了tester.k0方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: mktest

# 需要导入模块: from ethereum import tester [as 别名]
# 或者: from ethereum.tester import k0 [as 别名]
def mktest(code, language, data=None, fun=None, args=None,
           gas=1000000, value=0, test_type=VM):
    s = t.state(1)
    if language == 'evm':
        ca = s.contract('x = 5')
        s.block.set_code(ca, code)
        d = data or b''
    else:
        c = s.abi_contract(code, language=language)
        d = c._translator.encode(fun, args) if fun else (data or b'')
        ca = c.address
    pre = s.block.to_dict(True)['state']
    if test_type == VM:
        exek = {"address": ca, "caller": t.a0,
                "code": b'0x' + encode_hex(s.block.get_code(ca)),
                "data": b'0x' + encode_hex(d), "gas": to_string(gas),
                "gasPrice": to_string(1), "origin": t.a0,
                "value": to_string(value)}
        return fill_vm_test({"env": env, "pre": pre, "exec": exek})
    else:
        tx = {"data": b'0x' + encode_hex(d), "gasLimit": parse_int_or_hex(gas),
              "gasPrice": to_string(1), "nonce": to_string(s.block.get_nonce(t.a0)),
              "secretKey": encode_hex(t.k0), "to": ca, "value": to_string(value)}
        return fill_state_test({"env": env, "pre": pre, "transaction": tx})


# Fills up a vm test without post data, or runs the test 
开发者ID:ethereumproject,项目名称:pyethereum,代码行数:29,代码来源:testutils.py

示例2: test_evm

# 需要导入模块: from ethereum import tester [as 别名]
# 或者: from ethereum.tester import k0 [as 别名]
def test_evm():
    evm_code = serpent.compile(serpent_code)
    translator = abi.ContractTranslator(serpent.mk_full_signature(
                                        serpent_code))
    data = translator.encode('main', [2, 5])
    s = tester.state()
    c = s.evm(evm_code)
    o = translator.decode('main', s.send(tester.k0, c, 0, data))
    assert o == [32]


# Test serpent compilation of variables using _with_, doing a simple
# arithmetic calculation 20 * 30 + 10 = 610 
开发者ID:ethereumproject,项目名称:pyethereum,代码行数:15,代码来源:test_contracts.py

示例3: test_sixten

# 需要导入模块: from ethereum import tester [as 别名]
# 或者: from ethereum.tester import k0 [as 别名]
def test_sixten():
    s = tester.state()
    c = decode_hex('1231231231231234564564564564561231231231')
    s.block.set_code(c, serpent.compile_lll(sixten_code))
    o1 = s.send(tester.k0, c, 0)
    assert utils.big_endian_to_int(o1) == 610 
开发者ID:ethereumproject,项目名称:pyethereum,代码行数:8,代码来源:test_contracts.py

示例4: test_returnten

# 需要导入模块: from ethereum import tester [as 别名]
# 或者: from ethereum.tester import k0 [as 别名]
def test_returnten():
    s = tester.state()
    open(filename, 'w').write(mul2_code)
    c = s.contract(returnten_code)
    o1 = s.send(tester.k0, c, 0)
    os.remove(filename)
    assert utils.big_endian_to_int(o1) == 10


# Test inset 
开发者ID:ethereumproject,项目名称:pyethereum,代码行数:12,代码来源:test_contracts.py

示例5: test_currency

# 需要导入模块: from ethereum import tester [as 别名]
# 或者: from ethereum.tester import k0 [as 别名]
def test_currency():
    s = tester.state()
    c = s.abi_contract(currency_code, sender=tester.k0)
    o1 = c.send(tester.a2, 200)
    assert o1 == 1
    o2 = c.send(tester.a2, 900)
    assert o2 == 0
    o3 = c.query(tester.a0)
    assert o3 == 800
    o4 = c.query(tester.a2)
    assert o4 == 200

# Test a data feed 
开发者ID:ethereumproject,项目名称:pyethereum,代码行数:15,代码来源:test_contracts.py

示例6: test_hedge

# 需要导入模块: from ethereum import tester [as 别名]
# 或者: from ethereum.tester import k0 [as 别名]
def test_hedge():
    s, c = test_data_feeds()
    c2 = s.abi_contract(hedge_code, sender=tester.k0)
    # Have the first party register, sending 10^16 wei and
    # asking for a hedge using currency code 500
    o1 = c2.main(c.address, 500, value=10 ** 16)
    assert o1 == 1
    # Have the second party register. It should receive the
    # amount of units of the second currency that it is
    # entitled to. Note that from the previous test this is
    # set to 726
    o2 = c2.main(0, 0, value=10 ** 16, sender=tester.k2)
    assert o2 == 7260000000000000000
    snapshot = s.snapshot()
    # Set the price of the asset down to 300 wei
    o3 = c.set(500, 300)
    assert o3 == 1
    # Finalize the contract. Expect code 3, meaning a margin call
    o4 = c2.main(0, 0)
    assert o4 == 3
    s.revert(snapshot)
    # Don't change the price. Finalize, and expect code 5, meaning
    # the time has not expired yet
    o5 = c2.main(0, 0)
    assert o5 == 5
    s.mine(100, tester.a3)
    # Mine ten blocks, and try. Expect code 4, meaning a normal execution
    # where both get their share
    o6 = c2.main(0, 0)
    assert o6 == 4


# Test the LIFO nature of call 
开发者ID:ethereumproject,项目名称:pyethereum,代码行数:35,代码来源:test_contracts.py

示例7: test_callcode

# 需要导入模块: from ethereum import tester [as 别名]
# 或者: from ethereum.tester import k0 [as 别名]
def test_callcode():
    s = tester.state()
    open(filename3, 'w').write(add1_code)
    c = s.contract(callcode_test_code)
    o1 = s.send(tester.k0, c, 0)
    os.remove(filename3)
    assert utils.big_endian_to_int(o1) == 64


# https://github.com/ethereum/serpent/issues/8 
开发者ID:ethereumproject,项目名称:pyethereum,代码行数:12,代码来源:test_contracts.py

示例8: test_saveload2

# 需要导入模块: from ethereum import tester [as 别名]
# 或者: from ethereum.tester import k0 [as 别名]
def test_saveload2():
    s = tester.state()
    c = s.contract(saveload_code2)
    s.send(tester.k0, c, 0)
    assert bitcoin.encode(s.block.get_storage_data(c, 0), 256) == b'01ab' + b'\x00' * 28
    assert bitcoin.encode(s.block.get_storage_data(c, 1), 256) == b'01ab' + b'\x00' * 28 
开发者ID:ethereumproject,项目名称:pyethereum,代码行数:8,代码来源:test_contracts.py

示例9: test_types

# 需要导入模块: from ethereum import tester [as 别名]
# 或者: from ethereum.tester import k0 [as 别名]
def test_types():
    s = tester.state()
    c = s.contract(type_code)
    assert utils.big_endian_to_int(s.send(tester.k0, c, 0)) == 5 
开发者ID:ethereumproject,项目名称:pyethereum,代码行数:6,代码来源:test_contracts.py

示例10: test_returnten

# 需要导入模块: from ethereum import tester [as 别名]
# 或者: from ethereum.tester import k0 [as 别名]
def test_returnten():
    s = tester.state()
    open(filename, 'w').write(mul2_code)
    c = s.contract(returnten_code)
    s.send(tester.k0, c, 0)
    b2 = rlp.decode(rlp.encode(s.block), blocks.Block, env=s.env)
    assert rlp.encode(b2) == rlp.encode(s.block) 
开发者ID:ethereumproject,项目名称:pyethereum,代码行数:9,代码来源:test_serialization.py

示例11: test_buy_order

# 需要导入模块: from ethereum import tester [as 别名]
# 或者: from ethereum.tester import k0 [as 别名]
def test_buy_order(self):
        self.init_market()

        self.c1.send(self.m.address, 1000, sender=tester.k0)
        assert self.m.buy(1200, sender=tester.k0) == 1

        assert self.buy_heap.size() == 1
        order = self.buy_heap.top()
        assert decode_buy_order(order) == (1200, 1000, utils.decode_int256(tester.a0)) 
开发者ID:beaugunderson,项目名称:serplint,代码行数:11,代码来源:test_market.py

示例12: test_tick_partial_buy

# 需要导入模块: from ethereum import tester [as 别名]
# 或者: from ethereum.tester import k0 [as 别名]
def test_tick_partial_buy(self):
        self.init_market()

        self.c1.send(self.m.address, 1000, sender=tester.k0)
        assert self.m.buy(1200, sender=tester.k0) == 1
        self.c2.send(self.m.address, 100000, sender=tester.k2)
        assert self.m.sell(800, sender=tester.k2) == 1

        self.s.mine(100)
        assert self.m.tick() == 1

        assert self.m.volume() == 83
        assert self.m.price() == 1000

        assert self.c1.balance(tester.a0) == 0
        assert self.c2.balance(tester.a0) == 100000
        assert self.c1.balance(tester.a2) == 83
        assert self.c2.balance(tester.a2) == 1000000 - 100000

        assert self.c1.balance(self.m.address) == 917
        assert self.c2.balance(self.m.address) == 0

        assert self.buy_heap.size() == 1
        order = self.buy_heap.top()
        assert decode_buy_order(order) == (1200, 917, utils.decode_int256(tester.a0))

        assert self.sell_heap.size() == 0

        assert self.m.tick() == 0 
开发者ID:beaugunderson,项目名称:serplint,代码行数:31,代码来源:test_market.py

示例13: test_tick_partial_sell

# 需要导入模块: from ethereum import tester [as 别名]
# 或者: from ethereum.tester import k0 [as 别名]
def test_tick_partial_sell(self):
        self.init_market()

        self.c1.send(self.m.address, 100, sender=tester.k0)
        assert self.m.buy(1200, sender=tester.k0) == 1
        self.c2.send(self.m.address, 1000000, sender=tester.k2)
        assert self.m.sell(800, sender=tester.k2) == 1

        self.s.mine(100)
        assert self.m.tick() == 1

        assert self.m.volume() == 100
        assert self.m.price() == 1000

        assert self.c1.balance(tester.a0) == 1000 - 100
        assert self.c2.balance(tester.a0) == 80000
        assert self.c1.balance(tester.a2) == 100
        assert self.c2.balance(tester.a2) == 0

        assert self.c1.balance(self.m.address) == 0
        assert self.c2.balance(self.m.address) == 920000

        assert self.buy_heap.size() == 0
        assert self.sell_heap.size() == 1
        order = self.sell_heap.top()
        assert decode_sell_order(order) == (800, 920000, utils.decode_int256(tester.a2))

        assert self.m.tick() == 0 
开发者ID:beaugunderson,项目名称:serplint,代码行数:30,代码来源:test_market.py

示例14: test_full_scenario

# 需要导入模块: from ethereum import tester [as 别名]
# 或者: from ethereum.tester import k0 [as 别名]
def test_full_scenario(self):
        self.init_market()

        # Place orders
        self.c1.send(self.m.address, 1000, sender=tester.k0)
        self.m.buy(1200, sender=tester.k0)

        self.c1.send(self.m.address, 1000, sender=tester.k1)
        self.m.buy(1400, sender=tester.k1)

        self.c2.send(self.m.address, 1000000, sender=tester.k2)
        self.m.sell(800, sender=tester.k2)

        self.c2.send(self.m.address, 1000000, sender=tester.k3)
        self.m.sell(600, sender=tester.k3)

        print("Orders placed")

        # Next epoch and ping
        self.s.mine(100)
        print("Mined 100")
        assert self.m.tick() == 1
        print("Updating")

        # Check
        assert self.c2.balance(tester.a0) == 800000
        assert self.c2.balance(tester.a1) == 600000
        assert self.c1.balance(tester.a2) == 833
        assert self.c1.balance(tester.a3) == 714
        print("Balance checks passed")

        assert self.m.volume() == 1547
        assert self.m.price() == 1000
        assert self.c1.balance(self.m.address) == 453
        assert self.c2.balance(self.m.address) == 600000
        assert self.buy_heap.size() == 0
        assert self.sell_heap.size() == 0 
开发者ID:beaugunderson,项目名称:serplint,代码行数:39,代码来源:test_market.py

示例15: test_gas_for_finalize

# 需要导入模块: from ethereum import tester [as 别名]
# 或者: from ethereum.tester import k0 [as 别名]
def test_gas_for_finalize(self):
        addr, _ = self.deploy_contract(urandom(20), 1, 2)
        self.state.mine(1)
        for i, k in enumerate(tester.keys):
            v = random.randrange(15000 * denoms.ether, 82000 * denoms.ether)
            self.c.create(sender=k, value=v)
        self.state.mine(2)
        self.state.block.coinbase = urandom(20)
        m = self.monitor(0)
        self.c.finalize(sender=tester.k0)
        g = m.gas()
        assert g == 88551 
开发者ID:golemfactory,项目名称:golem-crowdfunding,代码行数:14,代码来源:test_gnt.py


注:本文中的ethereum.tester.k0方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。