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


Python tester.k2方法代码示例

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


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

示例1: test_refund_disabled

# 需要导入模块: from ethereum import tester [as 别名]
# 或者: from ethereum.tester import k2 [as 别名]
def test_refund_disabled(self):
        addr, _ = self.deploy_contract(tester.a9, 1, 4)
        self.state.mine(1)
        value = 150000 * denoms.ether - 1
        self.c.create(sender=tester.k1, value=value)
        assert self.c.totalSupply() == value * 1000
        self.state.mine(3)
        self.c.create(sender=tester.k2, value=1)
        assert self.c.totalSupply() == 150000000 * denoms.ether
        self.state.mine(10)
        with self.assertRaises(TransactionFailed):
            self.c.refund(sender=tester.k1)
        with self.assertRaises(TransactionFailed):
            self.c.refund(sender=tester.k2)
        with self.assertRaises(TransactionFailed):
            self.c.refund(sender=tester.k3)
            self.c.finalize() 
开发者ID:golemfactory,项目名称:golem-crowdfunding,代码行数:19,代码来源:test_gnt.py

示例2: test_hedge

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

示例3: test_crowdfund

# 需要导入模块: from ethereum import tester [as 别名]
# 或者: from ethereum.tester import k2 [as 别名]
def test_crowdfund():
    s = tester.state()
    c = s.abi_contract(crowdfund_code)
    # Create a campaign with id 100
    c.create_campaign(100, 45, 100000, 2)
    # Create a campaign with id 200
    c.create_campaign(200, 48, 100000, 2)
    # Make some contributions
    c.contribute(100, value=1, sender=tester.k1)
    assert 1 == c.progress_report(100)
    c.contribute(200, value=30000, sender=tester.k2)
    c.contribute(100, value=59049, sender=tester.k3)
    assert 59050 == c.progress_report(100)
    c.contribute(200, value=70001, sender=tester.k4)
    # Expect the 100001 units to be delivered to the destination
    # account for campaign 2
    assert 100001 == s.block.get_balance(utils.int_to_addr(48))
    mida1 = s.block.get_balance(tester.a1)
    mida3 = s.block.get_balance(tester.a3)
    # Mine 5 blocks to expire the campaign
    s.mine(5)
    # Ping the campaign after expiry
    c.contribute(100, value=1)
    # Expect refunds
    assert mida1 + 1 == s.block.get_balance(tester.a1)
    assert mida3 + 59049 == s.block.get_balance(tester.a3) 
开发者ID:ethereumproject,项目名称:pyethereum,代码行数:28,代码来源:test_contracts.py

示例4: test_sell_order

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

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

        assert self.sell_heap.size() == 1
        order = self.sell_heap.top()
        assert decode_sell_order(order) == (800, 1000000, utils.decode_int256(tester.a2)) 
开发者ID:beaugunderson,项目名称:serplint,代码行数:11,代码来源:test_market.py

示例5: test_tick_partial_buy

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

示例6: test_tick_partial_sell

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

示例7: test_full_scenario

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

示例8: test_single_refund

# 需要导入模块: from ethereum import tester [as 别名]
# 或者: from ethereum.tester import k2 [as 别名]
def test_single_refund(self):
        addr, _ = self.deploy_contract(tester.a9, 1, 4)
        self.state.mine(1)
        value = 150000 * denoms.ether - 1
        self.c.create(sender=tester.k1, value=value)
        assert self.c.totalSupply() == value * 1000
        self.state.mine(6)

        lg = self.state.block.gas_used
        b = self.state.block.get_balance(tester.a1)

        with self.event_listener(self.c, self.state) as listener:
            self.c.refund(sender=tester.k1)

            assert listener.event('Refund',
                                  _from=tester.a1.encode('hex'),
                                  _value=value)
            assert not listener.events  # no more events

        refund = self.state.block.get_balance(tester.a1) - b
        assert refund == value - (self.state.block.gas_used - lg) * tester.gas_price

        b = self.state.block.get_balance(tester.a2)
        with self.assertRaises(TransactionFailed):
            self.c.refund(sender=tester.k2)
        refund = self.state.block.get_balance(tester.a2) - b
        assert refund < 0 
开发者ID:golemfactory,项目名称:golem-crowdfunding,代码行数:29,代码来源:test_gnt.py

示例9: test_payable_amounts

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

        self.state.mine(1)

        tokens_max = self.number_of_tokens_left()

        # invalid value
        with self.assertRaises(TransactionFailed):
            self.c.create(sender=tester.k1, value=0)

        # create 3 ether (value) worth of tokens for k1
        self.c.create(sender=tester.k1, value=value)
        numTokensCreated = value * self.c.tokenCreationRate()
        assert self.number_of_tokens_left() == tokens_max - numTokensCreated
        assert self.c.totalSupply() == numTokensCreated

        # create 3 ether (value) worth of tokens for k2
        self.c.create(sender=tester.k2, value=value)
        assert self.number_of_tokens_left() == tokens_max - 2 * numTokensCreated
        assert self.c.totalSupply() == 2 * numTokensCreated

        # issue remaining tokens, except 3 * "value" worth of tokens
        value_max = tokens_max / self.c.tokenCreationRate()
        self.c.create(sender=tester.k1, value=value_max - 3 * value)

        # number of tokens remaining is equal to 1*value (*creationRate)
        assert self.number_of_tokens_left() == numTokensCreated
        assert self.c.totalSupply() == tokens_max - numTokensCreated

        # more than available tokens
        with self.assertRaises(TransactionFailed):
            self.c.create(sender=tester.k2, value=2 * value)

        assert self.is_funding_active() is True

        # exact amount of available tokens
        self.c.create(sender=tester.k1, value=value)
        assert self.number_of_tokens_left() == 0
        assert self.c.totalSupply() == tokens_max

        # no tokens available
        with self.assertRaises(TransactionFailed):
            self.c.create(sender=tester.k2, value=value)

    # Check if the transfer() is locked during the funding period. 
开发者ID:golemfactory,项目名称:golem-crowdfunding,代码行数:49,代码来源:test_gnt.py


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