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


Python tester.a0方法代码示例

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


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

示例1: test_abi_logging

# 需要导入模块: from ethereum import tester [as 别名]
# 或者: from ethereum.tester import a0 [as 别名]
def test_abi_logging():
    s = tester.state()
    c = s.abi_contract(abi_logging_code)
    o = []
    s.block.log_listeners.append(lambda x: o.append(c.translator.listen(x)))
    c.test_rabbit(3)
    assert o == [{"_event_type": b"rabbit", "x": 3}]
    o.pop()
    c.test_frog(5)
    assert o == [{"_event_type": b"frog", "y": 5}]
    o.pop()
    c.test_moose(7, "nine", 11, [13, 15, 17])
    assert o == [{"_event_type": b"moose", "a": 7, "b": b"nine",
                 "c": 11, "d": [13, 15, 17]}]
    o.pop()
    c.test_chicken(tester.a0)
    assert o == [{"_event_type": b"chicken",
                  "m": utils.encode_hex(tester.a0)}]
    o.pop() 
开发者ID:ethereumproject,项目名称:pyethereum,代码行数:21,代码来源:test_contracts.py

示例2: init_market

# 需要导入模块: from ethereum import tester [as 别名]
# 或者: from ethereum.tester import a0 [as 别名]
def init_market(self):
        self.buy_heap = self.s.abi_contract(self.HEAP_CONTRACT)
        self.sell_heap = self.s.abi_contract(self.HEAP_CONTRACT)

        self.buy_heap.set_owner(self.m.address)
        self.sell_heap.set_owner(self.m.address)

        self.c1 = self.s.abi_contract(self.SUBCURRENCY_CONTRACT)
        self.c2 = self.s.abi_contract(self.SUBCURRENCY_CONTRACT)

        self.c1.issue(tester.a0, 1000)
        self.c1.issue(tester.a1, 1000)
        self.c2.issue(tester.a2, 1000000)
        self.c2.issue(tester.a3, 1000000)

        self.m.init_market(self.buy_heap.address, self.sell_heap.address, self.c1.address, self.c2.address) 
开发者ID:beaugunderson,项目名称:serplint,代码行数:18,代码来源:test_market.py

示例3: test_payable_period

# 需要导入模块: from ethereum import tester [as 别名]
# 或者: from ethereum.tester import a0 [as 别名]
def test_payable_period(self):
        c_addr, _ = self.deploy_contract(tester.a0, 2, 3)
        value = 3 * denoms.ether

        # before funding
        self.state.mine(1)
        with self.assertRaises(TransactionFailed):
            self.c.create(sender=tester.k1, value=value)

        # during funding
        self.state.mine(1)
        self.c.create(sender=tester.k1, value=value)

        # post funding
        self.state.mine(2)
        with self.assertRaises(TransactionFailed):
            self.c.create(sender=tester.k1, value=value) 
开发者ID:golemfactory,项目名称:golem-crowdfunding,代码行数:19,代码来源:test_gnt.py

示例4: test_abi_logging

# 需要导入模块: from ethereum import tester [as 别名]
# 或者: from ethereum.tester import a0 [as 别名]
def test_abi_logging():
    s = tester.state()
    c = s.abi_contract(abi_logging_code)
    o = []
    s.block.log_listeners.append(lambda x: o.append(c.translator.listen(x)))
    c.test_rabbit(3)
    assert o == [{"_event_type": b"rabbit", "x": 3}]
    o.pop()
    c.test_frog(5)
    assert o == [{"_event_type": b"frog", "y": 5}]
    o.pop()
    c.test_moose(7, b"nine", 11, [13, 15, 17])
    assert o == [{"_event_type": b"moose", "a": 7, "b": b"nine",
                 "c": 11, "d": [13, 15, 17]}]
    o.pop()
    c.test_chicken(tester.a0)
    assert o == [{"_event_type": b"chicken",
                  "m": utils.encode_hex(tester.a0)}]
    o.pop() 
开发者ID:EthereumWebhooks,项目名称:blockhooks,代码行数:21,代码来源:test_contracts.py

示例5: test_token

# 需要导入模块: from ethereum import tester [as 别名]
# 或者: from ethereum.tester import a0 [as 别名]
def test_token():
    standard_token_path = get_contract_path('StandardToken.sol')
    human_token_path = get_contract_path('HumanStandardToken.sol')

    state = tester.state()
    state.block.number = 1158001

    address0 = tester.a0
    address1 = tester.a1

    standard_token = state.abi_contract(
        None,
        path=standard_token_path,
        language='solidity',
    )

    contract_libraries = {
        'StandardToken': hexlify(standard_token.address),
    }
    human_token = state.abi_contract(
        None,
        path=human_token_path,
        language='solidity',
        libraries=contract_libraries,
        constructor_parameters=[10000, 'raiden', 0, 'rd'],
    )

    # pylint: disable=no-member
    assert human_token.balanceOf(address0) == 10000
    assert human_token.balanceOf(address1) == 0
    assert human_token.transfer(address1, 5000) is True
    assert human_token.balanceOf(address0) == 5000
    assert human_token.balanceOf(address1) == 5000 
开发者ID:raiden-network,项目名称:raiden,代码行数:35,代码来源:test_token.py

示例6: mktest

# 需要导入模块: from ethereum import tester [as 别名]
# 或者: from ethereum.tester import a0 [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

示例7: test_currency

# 需要导入模块: from ethereum import tester [as 别名]
# 或者: from ethereum.tester import a0 [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

示例8: test_buy_order

# 需要导入模块: from ethereum import tester [as 别名]
# 或者: from ethereum.tester import a0 [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

示例9: test_tick_partial_buy

# 需要导入模块: from ethereum import tester [as 别名]
# 或者: from ethereum.tester import a0 [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

示例10: test_tick_partial_sell

# 需要导入模块: from ethereum import tester [as 别名]
# 或者: from ethereum.tester import a0 [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

示例11: test_full_scenario

# 需要导入模块: from ethereum import tester [as 别名]
# 或者: from ethereum.tester import a0 [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

示例12: test_send_with_negative_amount_should_fail

# 需要导入模块: from ethereum import tester [as 别名]
# 或者: from ethereum.tester import a0 [as 别名]
def test_send_with_negative_amount_should_fail(self):
        self.c.issue(tester.a0, 100000000000)
        assert self.c.send(tester.a0, -1000, sender=tester.k1) == 0
        assert self.c.balance(tester.a0) == 100000000000
        assert self.c.balance(tester.a1) == 0 
开发者ID:beaugunderson,项目名称:serplint,代码行数:7,代码来源:test_subcurrency.py

示例13: test_init

# 需要导入模块: from ethereum import tester [as 别名]
# 或者: from ethereum.tester import a0 [as 别名]
def test_init(self):
        assert self.s.block.get_code(self.c.address) != ''
        assert utils.int_to_addr(self.s.block.get_storage_data(self.c.address, 0)) == tester.a0
        assert self.c.size() == 0
        assert self.c.top() == 0 
开发者ID:beaugunderson,项目名称:serplint,代码行数:7,代码来源:test_heap.py

示例14: test_send_value_through_other_function

# 需要导入模块: from ethereum import tester [as 别名]
# 或者: from ethereum.tester import a0 [as 别名]
def test_send_value_through_other_function(self):
        addr, _ = self.deploy_contract(tester.a0, 17, 19)

        with self.assertRaises(TransactionFailed):
            self.c.totalSupply(value=13, sender=tester.k0)
        assert self.contract_balance() == 0

        with self.assertRaises(TransactionFailed):
            self.c.tokenCreationRate(value=13000000, sender=tester.k0)
        assert self.contract_balance() == 0 
开发者ID:golemfactory,项目名称:golem-crowdfunding,代码行数:12,代码来源:test_gnt.py

示例15: test_token_approve

# 需要导入模块: from ethereum import tester [as 别名]
# 或者: from ethereum.tester import a0 [as 别名]
def test_token_approve():
    test_path = os.path.join(os.path.dirname(__file__), 'SimpleApproveTransfer.sol')

    standard_token_path = get_contract_path('StandardToken.sol')
    human_token_path = get_contract_path('HumanStandardToken.sol')

    state = tester.state()
    state.block.number = 1158001

    address0 = tester.a0
    address1 = tester.a1

    standard_token = state.abi_contract(
        None,
        path=standard_token_path,
        language='solidity',
    )

    contract_libraries = {
        'StandardToken': hexlify(standard_token.address),
    }
    human_token = state.abi_contract(
        None,
        path=human_token_path,
        language='solidity',
        libraries=contract_libraries,
        constructor_parameters=[10000, 'raiden', 0, 'rd'],
    )

    test = state.abi_contract(
        None,
        path=test_path,
        language='solidity',
        constructor_parameters=[human_token.address],
    )

    # pylint: disable=no-member
    assert human_token.balanceOf(address0) == 10000
    assert human_token.balanceOf(address1) == 0
    assert human_token.balanceOf(test.address) == 0
    assert human_token.allowance(address0, address0) == 0
    assert human_token.allowance(address0, address1) == 0
    assert human_token.allowance(address0, test.address) == 0

    assert human_token.approve(test.address, 5000) is True
    assert human_token.balanceOf(address0) == 10000
    assert human_token.balanceOf(address1) == 0
    assert human_token.balanceOf(test.address) == 0
    assert human_token.allowance(address0, address0) == 0
    assert human_token.allowance(address0, address1) == 0
    assert human_token.allowance(address0, test.address) == 5000

    assert test.transfer(address1, 2000) is True
    assert human_token.balanceOf(address0) == 10000 - 2000
    assert human_token.balanceOf(address1) == 0 + 2000
    assert human_token.balanceOf(test.address) == 0
    assert human_token.allowance(address0, address0) == 0
    assert human_token.allowance(address0, address1) == 0
    assert human_token.allowance(address0, test.address) == 5000 - 2000 
开发者ID:raiden-network,项目名称:raiden,代码行数:61,代码来源:test_token.py


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