本文整理汇总了Python中ethereum.tester.a3方法的典型用法代码示例。如果您正苦于以下问题:Python tester.a3方法的具体用法?Python tester.a3怎么用?Python tester.a3使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ethereum.tester
的用法示例。
在下文中一共展示了tester.a3方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: init_market
# 需要导入模块: from ethereum import tester [as 别名]
# 或者: from ethereum.tester import a3 [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 a3 [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_hedge
# 需要导入模块: from ethereum import tester [as 别名]
# 或者: from ethereum.tester import a3 [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
示例4: test_crowdfund
# 需要导入模块: from ethereum import tester [as 别名]
# 或者: from ethereum.tester import a3 [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)
示例5: test_full_scenario
# 需要导入模块: from ethereum import tester [as 别名]
# 或者: from ethereum.tester import a3 [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
示例6: test_create
# 需要导入模块: from ethereum import tester [as 别名]
# 或者: from ethereum.tester import a3 [as 别名]
def test_create(self):
addr, _ = self.deploy_contract(urandom(20), 1, 2)
self.state.mine(1)
v = 13 * denoms.ether + 13
self.c.create(sender=tester.k3, value=v)
assert self.c.balanceOf(tester.a3) == v * self.c.tokenCreationRate()
示例7: test_create_raw
# 需要导入模块: from ethereum import tester [as 别名]
# 或者: from ethereum.tester import a3 [as 别名]
def test_create_raw(self):
addr, _ = self.deploy_contract(urandom(20), 1, 2)
self.state.mine(1)
v = 13 * denoms.ether + 13
create_fn_id = decode_hex('efc81a8c')
self.state.send(tester.k3, addr, value=v, evmdata=create_fn_id)
assert self.c.balanceOf(tester.a3) == v * self.c.tokenCreationRate()
示例8: test_no_fallback_fn
# 需要导入模块: from ethereum import tester [as 别名]
# 或者: from ethereum.tester import a3 [as 别名]
def test_no_fallback_fn(self):
addr, _ = self.deploy_contract(urandom(20), 1, 2)
self.state.mine(1)
v = 13 * denoms.ether + 13
with self.assertRaises(TransactionFailed):
self.state.send(tester.k3, addr, value=v)
assert self.c.balanceOf(tester.a3) == 0
示例9: test_lottery_find_winner2
# 需要导入模块: from ethereum import tester [as 别名]
# 或者: from ethereum.tester import a3 [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
示例10: test_lottery_payout
# 需要导入模块: from ethereum import tester [as 别名]
# 或者: from ethereum.tester import a3 [as 别名]
def test_lottery_payout(self):
self.deploy_contract()
lottery = Lottery({
tester.a4: 40 * eth,
tester.a3: 30 * eth,
tester.a2: 20 * eth,
tester.a1: 10 * eth,
})
self.lottery_init(5, lottery)
self.state.mine(100)
self.lottery_randomise(5, lottery)
self.state.mine(1)
self.lottery_get_value(lottery) != 0
lottery._print_tree()
r = self.lottery_get_rand(lottery)
assert r != 0
winner, proof = lottery.find_winner(r)
validate_proof(lottery, winner, proof)
assert winner.address in (tester.a1, tester.a2, tester.a3, tester.a4)
w0 = self.state.block.get_balance(winner.address)
g = self.lottery_payout(5, lottery, r)
assert g <= 50000
win = self.state.block.get_balance(winner.address) - w0
assert win == lottery.value