本文整理匯總了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()
示例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
示例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)
示例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))
示例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
示例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
示例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
示例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
示例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.