本文整理汇总了Python中ethereum.tester.a2方法的典型用法代码示例。如果您正苦于以下问题:Python tester.a2方法的具体用法?Python tester.a2怎么用?Python tester.a2使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ethereum.tester
的用法示例。
在下文中一共展示了tester.a2方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: init_market
# 需要导入模块: from ethereum import tester [as 别名]
# 或者: from ethereum.tester import a2 [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)
示例2: test_lottery_5
# 需要导入模块: from ethereum import tester [as 别名]
# 或者: from ethereum.tester import a2 [as 别名]
def test_lottery_5(self):
payments = {
tester.a1: 1*eth,
tester.a4: 4*eth,
tester.a2: 2*eth,
tester.a5: 5*eth,
tester.a3: 3*eth,
}
lottery = Lottery(payments)
assert lottery.value == 15*eth
assert lottery.tickets[0].address == tester.a5
assert lottery.root.left.left.value == lottery.tickets[0]
assert lottery.root.left.right.value == lottery.tickets[1]
assert lottery.root.right.left.value == lottery.tickets[2]
assert lottery.root.right.right.left.value == lottery.tickets[3]
assert lottery.root.right.right.right.value == lottery.tickets[4]
assert lottery.root.hash.encode('hex') == 'a4a2fe70f894005badf01e06726c770f100f0969c491b065ef252f5ea48b87df'
示例3: test_lottery_randomise
# 需要导入模块: from ethereum import tester [as 别名]
# 或者: from ethereum.tester import a2 [as 别名]
def test_lottery_randomise(self):
self.deploy_contract()
lottery = Lottery({tester.a1: 50 * eth, tester.a2: 50 * eth})
assert lottery.value == 100 * eth
self.lottery_init(3, lottery)
assert self.lottery_get_value(lottery) == lottery.value
self.state.mine(11)
assert self.state.block.number == 11
assert self.state.block.number > self.lottery_get_maturity(lottery)
r = self.lottery_get_rand(lottery)
assert r == 0
g = self.lottery_randomise(3, lottery)
assert g <= 44919
r = self.lottery_get_rand(lottery)
r = zpad(int_to_big_endian(r), 4)
assert r == self.state.block.get_parent().hash[-4:]
assert self.lottery_get_maturity(lottery) == 0
assert self.lottery_get_value(lottery) == lottery.value
示例4: test_lottery_payer_deposit
# 需要导入模块: from ethereum import tester [as 别名]
# 或者: from ethereum.tester import a2 [as 别名]
def test_lottery_payer_deposit(self):
self.deploy_contract()
payer = tester.a6
w0 = self.state.block.get_balance(payer)
lottery = Lottery({tester.a1: 33 * eth, tester.a2: 17 * eth})
g1 = self.lottery_init(6, lottery)
v = 50 * eth
deposit = v / 10
assert self.lottery_get_value(lottery) == v
assert self.lottery_get_maturity(lottery) == 10
b = self.state.block.get_balance(payer) - w0
assert b == -(v + deposit + g1)
self.state.mine(11)
expected_rand = self.state.block.get_parent().hash[-4:]
self.state.mine(127)
self.lottery_randomise(9, lottery) # Payer gets the deposit
r = self.lottery_get_rand(lottery)
r = zpad(int_to_big_endian(r), 4)
assert r == expected_rand
b = self.state.block.get_balance(payer) - w0
assert b == -(v + g1)
示例5: test_currency
# 需要导入模块: from ethereum import tester [as 别名]
# 或者: from ethereum.tester import a2 [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
示例6: test_sell_order
# 需要导入模块: from ethereum import tester [as 别名]
# 或者: from ethereum.tester import a2 [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))
示例7: test_tick_partial_buy
# 需要导入模块: from ethereum import tester [as 别名]
# 或者: from ethereum.tester import a2 [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
示例8: test_tick_partial_sell
# 需要导入模块: from ethereum import tester [as 别名]
# 或者: from ethereum.tester import a2 [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
示例9: test_full_scenario
# 需要导入模块: from ethereum import tester [as 别名]
# 或者: from ethereum.tester import a2 [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
示例10: test_single_refund
# 需要导入模块: from ethereum import tester [as 别名]
# 或者: from ethereum.tester import a2 [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
示例11: test_lottery_2
# 需要导入模块: from ethereum import tester [as 别名]
# 或者: from ethereum.tester import a2 [as 别名]
def test_lottery_2(self):
payments = {
tester.a1: 1*eth,
tester.a2: 1*eth,
}
lottery = Lottery(payments)
assert lottery.value == 2*eth
assert lottery.tickets[0].address == tester.a1
assert lottery.root.left.value == lottery.tickets[0]
assert lottery.root.right.value == lottery.tickets[1]
assert lottery.root.hash.encode('hex') == '033978b28985c7e15b104b1c123511ae240b6a5cec8f07e718dcedc21e1067d7'
示例12: test_lottery_init
# 需要导入模块: from ethereum import tester [as 别名]
# 或者: from ethereum.tester import a2 [as 别名]
def test_lottery_init(self):
self.deploy_contract()
lottery = Lottery({tester.a1: 9, tester.a2: 1})
g = self.lottery_init(2, lottery)
assert g <= 84103
assert self.lottery_get_value(lottery) == 10
assert self.lottery_get_maturity(lottery) == 10
示例13: test_lottery_payer_deposit_owner
# 需要导入模块: from ethereum import tester [as 别名]
# 或者: from ethereum.tester import a2 [as 别名]
def test_lottery_payer_deposit_owner(self):
self.deploy_contract(9)
payer = tester.a6
w0 = self.state.block.get_balance(payer)
lottery = Lottery({tester.a1: 11 * eth, tester.a2: 39 * eth})
g1 = self.lottery_init(6, lottery)
v = 50 * eth
deposit = v / 10
assert self.lottery_get_value(lottery) == v
assert self.lottery_get_maturity(lottery) == 10
b = self.state.block.get_balance(payer) - w0
assert b == -(v + deposit + g1)
self.state.mine(256 + 11)
expected_rand = self.state.block.get_parent().hash[-4:]
# Owner gets the deposit
self.lottery_randomise(8, lottery)
r = self.lottery_get_rand(lottery)
r = zpad(int_to_big_endian(r), 4)
assert r == expected_rand
assert b == -(v + deposit + g1)
assert self.lottery_get_owner_deposit() == deposit
b0 = self.state.block.get_balance(tester.a9)
self.lottery_owner_payout()
b = self.state.block.get_balance(tester.a9) - b0
assert b == deposit
assert self.lottery_get_owner_deposit() == 0
示例14: test_lottery_find_winner
# 需要导入模块: from ethereum import tester [as 别名]
# 或者: from ethereum.tester import a2 [as 别名]
def test_lottery_find_winner(self):
lottery = Lottery({tester.a1: 50, tester.a2: 50})
r = 2**32/2
assert lottery.find_winner(r - 1)[0].address == tester.a1
assert lottery.find_winner(r)[0].address == tester.a2
示例15: test_lottery_find_winner2
# 需要导入模块: from ethereum import tester [as 别名]
# 或者: from ethereum.tester import a2 [as 别名]
def test_lottery_find_winner2(self):
lottery = Lottery({
tester.a4: 40 * eth,
tester.a3: 30 * eth,
tester.a2: 20 * eth,
tester.a1: 10 * eth,
})
r = int(2**32 * 0.4)
assert lottery.find_winner(r)[0].address == tester.a3