本文整理匯總了Python中ethereum.tester.k1方法的典型用法代碼示例。如果您正苦於以下問題:Python tester.k1方法的具體用法?Python tester.k1怎麽用?Python tester.k1使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類ethereum.tester
的用法示例。
在下文中一共展示了tester.k1方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: test_data_feeds
# 需要導入模塊: from ethereum import tester [as 別名]
# 或者: from ethereum.tester import k1 [as 別名]
def test_data_feeds():
s = tester.state()
c = s.abi_contract(data_feed_code, sender=tester.k0)
o2 = c.get(500)
assert o2 == 0
o3 = c.set(500, 19)
assert o3 == 1
o4 = c.get(500)
assert o4 == 19
o5 = c.set(500, 726, sender=tester.k1)
assert o5 == 0
o6 = c.set(500, 726)
assert o6 == 1
return s, c
# Test an example hedging contract, using the data feed. This tests
# contracts calling other contracts
示例2: test_payable_period
# 需要導入模塊: from ethereum import tester [as 別名]
# 或者: from ethereum.tester import k1 [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)
示例3: test_good_wallet
# 需要導入模塊: from ethereum import tester [as 別名]
# 或者: from ethereum.tester import k1 [as 別名]
def test_good_wallet(self):
founder = tester.accounts[9]
key = tester.keys[9]
wallet_addr, g0 = self.deploy_wallet(founder)
c_addr = self.deploy_contract_on_wallet(wallet_addr, 1, 2)
value = int(self.c.tokenCreationMin() / self.c.tokenCreationRate())
self.state.mine(1)
self.c.create(sender=tester.k1, value=value)
self.state.mine(3)
extra = 0
self.wallet.set_extra_work(extra)
assert extra == self.wallet.get_extra_work()
initial_b = self.state.block.get_balance(wallet_addr)
self.wallet.finalize(c_addr, sender=key)
self.state.mine(1)
current_b = self.state.block.get_balance(wallet_addr)
assert current_b == initial_b + value
assert extra == self.wallet.get_out_i(sender=key)
示例4: test_crowdfund
# 需要導入模塊: from ethereum import tester [as 別名]
# 或者: from ethereum.tester import k1 [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 k1 [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_send_should_have_sufficient_balance
# 需要導入模塊: from ethereum import tester [as 別名]
# 或者: from ethereum.tester import k1 [as 別名]
def test_send_should_have_sufficient_balance(self):
assert self.c.send(tester.a2, 1000, sender=tester.k1) == 0
示例7: test_send_with_negative_amount_should_fail
# 需要導入模塊: from ethereum import tester [as 別名]
# 或者: from ethereum.tester import k1 [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
示例8: test_only_owner_can_modify
# 需要導入模塊: from ethereum import tester [as 別名]
# 或者: from ethereum.tester import k1 [as 別名]
def test_only_owner_can_modify(self):
self.c.push(1, sender=tester.k1)
assert self.c.size() == 0
assert self.c.top() == 0
self.c.push(1)
assert self.c.pop(sender=tester.k1) is None
assert self.c.size() == 1
assert self.c.top() == 1
示例9: test_single_refund
# 需要導入模塊: from ethereum import tester [as 別名]
# 或者: from ethereum.tester import k1 [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
示例10: test_bad_wallet
# 需要導入模塊: from ethereum import tester [as 別名]
# 或者: from ethereum.tester import k1 [as 別名]
def test_bad_wallet(self):
founder = tester.accounts[9]
key = tester.keys[9]
wallet_addr, g0 = self.deploy_wallet(founder)
c_addr = self.deploy_contract_on_wallet(wallet_addr, 1, 2)
value = int(self.c.tokenCreationMin() / self.c.tokenCreationRate())
self.state.mine(1)
self.c.create(sender=tester.k1, value=value)
self.state.mine(3)
# extra>0 will cause Wallet fallback function to burn gas;
# send executed from contract has hardcoded limit of gas (2300?)
# which is so small that it's not enough to do anything except for receive ether
extra = 1
self.wallet.set_extra_work(extra)
assert extra == self.wallet.get_extra_work()
initial_cb = self.state.block.get_balance(c_addr)
initial_wb = self.state.block.get_balance(wallet_addr)
initial_fb = self.state.block.get_balance(founder)
with self.assertRaises(TransactionFailed):
self.wallet.finalize(c_addr, sender=key)
self.state.mine(1)
current_cb = self.state.block.get_balance(c_addr)
current_wb = self.state.block.get_balance(wallet_addr)
current_fb = self.state.block.get_balance(founder)
assert 0 == self.wallet.get_out_i(sender=key) # OK
assert current_cb == initial_cb
assert current_wb == initial_wb
assert current_fb < initial_fb
# check if first failed attempt does not lock Token contract indefinitely
extra = 0
self.wallet.set_extra_work(extra)
assert extra == self.wallet.get_extra_work()
initial_wb = self.state.block.get_balance(wallet_addr)
self.wallet.finalize(c_addr, sender=key)
self.state.mine(1)
current_wb = self.state.block.get_balance(wallet_addr)
assert current_wb == initial_wb + value
assert extra == self.wallet.get_out_i(sender=key)
示例11: normal_case
# 需要導入模塊: from ethereum import tester [as 別名]
# 或者: from ethereum.tester import k1 [as 別名]
def normal_case():
print "=================================NORMAL CASE===================================="
s = tester.state()
alice = tester.k0
bob = tester.k1
silverToken = s.abi_contract(tokenCode, sender=alice)
goldToken = s.abi_contract(tokenCode, sender=bob)
start = s.block.gas_used
exchangeAlicePart = s.abi_contract(exchangeCode, sender=alice)
exchangeBobPart = s.abi_contract(exchangeCode, sender=bob)
print "Before exchange happens"
print "Alice has {token} silver token".format(token=silverToken.get_balance(utils.privtoaddr(alice)))
print "Bob has {token} silver token".format(token=silverToken.get_balance(utils.privtoaddr(bob)))
print "Alice has {token} gold token".format(token=goldToken.get_balance(utils.privtoaddr(alice)))
print "Bob has {} gold token".format(goldToken.get_balance(utils.privtoaddr(bob)))
pre_image = "10"
block_timeout = 50
exchangeAlicePart.initialize(utils.sha3(pre_image), block_timeout, utils.privtoaddr(bob), exchangeBobPart.address, goldToken.address, sender=alice)
exchangeBobPart.initialize(exchangeAlicePart.get_secret(), block_timeout, utils.privtoaddr(alice), 0, silverToken.address, sender=bob)
print "Alice first sends silver token to Bob part of the exchange contract"
silverToken.send_token(exchangeBobPart.address, 500, sender=alice)
print "Bob then sends gold token to Alice part of the exchange contract"
goldToken.send_token(exchangeAlicePart.address, 500, sender=bob)
print "Alice unlocks both contracts simutanously"
exchangeAlicePart.transfer(pre_image, sender=alice)
print ""
print ""
print "After exchange happens"
print "Alice has {token} silver token".format(token=silverToken.get_balance(utils.privtoaddr(alice)))
print "Bob has {token} silver token".format(token=silverToken.get_balance(utils.privtoaddr(bob)))
print "Alice has {token} gold token".format(token=goldToken.get_balance(utils.privtoaddr(alice)))
print "Bob has {} gold token".format(goldToken.get_balance(utils.privtoaddr(bob)))
end = s.block.gas_used
print "Gas used is {}".format(end - start)
示例12: timeout_case
# 需要導入模塊: from ethereum import tester [as 別名]
# 或者: from ethereum.tester import k1 [as 別名]
def timeout_case():
print "=================================TIME OUT CASE===================================="
s = tester.state()
alice = tester.k0
bob = tester.k1
silverToken = s.abi_contract(tokenCode, sender=alice)
goldToken = s.abi_contract(tokenCode, sender=bob)
start = s.block.gas_used
exchangeAlicePart = s.abi_contract(exchangeCode, sender=alice)
exchangeBobPart = s.abi_contract(exchangeCode, sender=bob)
print "Before exchange happens"
print "Alice has {token} silver token".format(token=silverToken.get_balance(utils.privtoaddr(alice)))
print "Bob has {token} silver token".format(token=silverToken.get_balance(utils.privtoaddr(bob)))
print "Alice has {token} gold token".format(token=goldToken.get_balance(utils.privtoaddr(alice)))
print "Bob has {} gold token".format(goldToken.get_balance(utils.privtoaddr(bob)))
pre_image = "10"
block_timeout = 50
exchangeAlicePart.initialize(utils.sha3(pre_image), block_timeout, utils.privtoaddr(bob), exchangeBobPart.address, goldToken.address, sender=alice)
exchangeBobPart.initialize(exchangeAlicePart.get_secret(), block_timeout, utils.privtoaddr(alice), 0, silverToken.address, sender=bob)
silverToken.send_token(exchangeBobPart.address, 500, sender=alice)
print "Bob does not want to do the exchange so he will not send any gold token to alice's part"
s.mine(51)
exchangeBobPart.refund(silverToken.address)
print ""
print ""
print "After timeout happens"
print "Alice has {token} silver token".format(token=silverToken.get_balance(utils.privtoaddr(alice)))
print "Bob has {token} silver token".format(token=silverToken.get_balance(utils.privtoaddr(bob)))
print "Alice has {token} gold token".format(token=goldToken.get_balance(utils.privtoaddr(alice)))
print "Bob has {} gold token".format(goldToken.get_balance(utils.privtoaddr(bob)))
#end = s.block.gas_used
#print "Gas used is {}".format(end - start)
示例13: test_payable_amounts
# 需要導入模塊: from ethereum import tester [as 別名]
# 或者: from ethereum.tester import k1 [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.
示例14: test_transfer_locked
# 需要導入模塊: from ethereum import tester [as 別名]
# 或者: from ethereum.tester import k1 [as 別名]
def test_transfer_locked(self):
addr, _ = self.deploy_contract(tester.a0, 1, 2)
assert not self.is_funding_active()
self.state.mine(1)
assert self.is_funding_active()
# Create tokens to meet minimum funding
tokens = self.c.tokenCreationMin()
value = tokens / self.c.tokenCreationRate()
with self.event_listener(self.c, self.state) as listener:
self.c.create(sender=tester.k1, value=value)
assert listener.event('Transfer',
_value=tokens,
_to=tester.a1.encode('hex'),
_from='0' * 40)
assert not listener.events # no more events
assert self.balance_of(1) == tokens
# At this point a1 has GNT but cannot transfer them.
assert self.c.funding()
with self.event_listener(self.c, self.state) as listener:
with self.assertRaises(TransactionFailed):
self.transfer(tester.k1, tester.a2, tokens)
assert not listener.events
# Funding has ended.
self.state.mine(2)
assert self.state.block.number == self.starting_block + 3
assert self.is_funding_active() is False
self.c.finalize()
assert not self.c.funding()
with self.event_listener(self.c, self.state) as listener:
assert self.transfer(tester.k1, tester.a2, tokens)
assert listener.event('Transfer',
_value=tokens,
_to=tester.a2.encode('hex'),
_from=tester.a1.encode('hex'))
assert not listener.events # no more events
assert self.balance_of(1) == 0
assert self.balance_of(2) == tokens
示例15: test_migration_master
# 需要導入模塊: from ethereum import tester [as 別名]
# 或者: from ethereum.tester import k1 [as 別名]
def test_migration_master(self):
s_addr, _ = self.deploy_contract(tester.a9, 1, 2,
migration_master=tester.a8)
source = self.c
tokens = source.tokenCreationCap()
eths = tokens / source.tokenCreationRate()
self.state.mine(1)
# funding
self.c.create(sender=tester.k1, value=eths)
# post funding
self.state.mine(1)
assert source.funding()
self._finalize_funding(s_addr, expected_supply=tokens)
assert not source.funding()
# migration and target token contracts
m_addr, _ = self.deploy_migration_contract(s_addr)
t_addr, _ = self.deploy_target_contract(m_addr)
migration = self.m
target = self.t
# attempt to enable migration using wrong keys
with self.assertRaises(TransactionFailed):
source.setMigrationAgent(m_addr, sender=tester.k9)
with self.assertRaises(TransactionFailed):
source.setMigrationAgent(m_addr, sender=tester.k7)
with self.assertRaises(TransactionFailed):
source.setMigrationMaster(tester.a7, sender=tester.k9)
with self.assertRaises(TransactionFailed):
source.setMigrationMaster(0, sender=tester.k8)
source.setMigrationMaster(tester.a7, sender=tester.k8)
# attempt to enable migration using migration master keys
source.setMigrationAgent(m_addr, sender=tester.k7)
migration.setTargetToken(t_addr, sender=tester.k9)
assert source.balanceOf(tester.a1) == tokens
assert target.balanceOf(tester.a1) == 0
with self.assertRaises(TransactionFailed):
source.migrate(0, sender=tester.k1)
with self.assertRaises(TransactionFailed):
source.migrate(tokens + 1, sender=tester.k1)