本文整理匯總了Python中web3.contract.Contract類的典型用法代碼示例。如果您正苦於以下問題:Python Contract類的具體用法?Python Contract怎麽用?Python Contract使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了Contract類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: test_cannot_mint
def test_cannot_mint(chain: TestRPCChain, web3: Web3, ico: Contract, uncapped_token: Contract, customer: str, preico_token_price, preico_starts_at, team_multisig):
"""Only crowdsale contract can mint new tokens."""
time_travel(chain, preico_starts_at + 1)
with pytest.raises(TransactionFailed):
uncapped_token.transact({"from": customer}).mint(customer, 1000)
示例2: test_buy_early
def test_buy_early(chain: TestRPCChain, ico: Contract, customer: str, preico_starts_at, uncapped_token):
"""Cannot buy too early."""
time_travel(chain, preico_starts_at - 1)
assert ico.call().getState() == CrowdsaleState.PreFunding
with pytest.raises(TransactionFailed):
ico.transact({"from": customer, "value": to_wei(1, "ether")}).buy()
示例3: test_token_rename
def test_token_rename(token: Contract, team_multisig, token_new_name, token_new_symbol):
"""We will update token's information here"""
token.transact({"from": team_multisig}).setTokenInformation(token_new_name, token_new_symbol)
assert token.call().name() == token_new_name
assert token.call().symbol() == token_new_symbol
示例4: failed_ico_ready_to_refund
def failed_ico_ready_to_refund(chain: TestRPCChain, failed_ico: Contract, team_multisig) -> Contract:
"""An ICO that did not reach a goal, but has participants.
The team has moved funds back from the multisig wallet on the crowdsale contract. Note that due to transaction fees you need to pay a minimal transaction cost out of your own pocket.
"""
failed_ico.transact({"from" : team_multisig, "value": failed_ico.call().weiRaised()}).loadRefund()
return failed_ico
示例5: test_early_whitelist_only_owner
def test_early_whitelist_only_owner(chain: TestRPCChain, ico: Contract, customer: str, preico_starts_at, team_multisig, uncapped_token):
"""Only owner can early whitelist."""
time_travel(chain, preico_starts_at - 1)
assert ico.call().getState() == CrowdsaleState.PreFunding
with pytest.raises(TransactionFailed):
ico.transact({"from": customer}).setEarlyParicipantWhitelist(customer, True)
示例6: test_change_end_at_only_owner
def test_change_end_at_only_owner(chain: TestRPCChain, ico: Contract, customer: str, preico_starts_at, preico_ends_at, team_multisig):
"""Only own can change end date."""
new_early = preico_starts_at + 1*3600
with pytest.raises(TransactionFailed):
ico.transact({"from": customer}).setEndsAt(new_early)
示例7: test_buy_late_goal_reached
def test_buy_late_goal_reached(chain: TestRPCChain, uncapped_flatprice_goal_reached: Contract, customer: str, preico_ends_at):
"""Cannot buy after closing time when the goal was not reached."""
time_travel(chain, preico_ends_at + 1)
assert uncapped_flatprice_goal_reached.call().getState() == CrowdsaleState.Success
with pytest.raises(TransactionFailed):
uncapped_flatprice_goal_reached.transact({"from": customer, "value": to_wei(1, "ether")}).buy()
示例8: test_buy_early_whitelisted
def test_buy_early_whitelisted(chain: TestRPCChain, ico: Contract, customer: str, preico_starts_at, team_multisig, uncapped_token):
"""Whitelisted participants can buy earliy."""
time_travel(chain, preico_starts_at - 1)
assert ico.call().getState() == CrowdsaleState.PreFunding
ico.transact({"from": team_multisig}).setEarlyParicipantWhitelist(customer, True)
ico.transact({"from": customer, "value": to_wei(1, "ether")}).buy()
assert uncapped_token.call().balanceOf(customer) > 0
示例9: test_cannot_upgrade_too_many
def test_cannot_upgrade_too_many(released_token: Contract, upgrade_agent: Contract, team_multisig, customer):
"""We cannot upgrade more tokens than we have."""
released_token.transact({"from": team_multisig}).setUpgradeAgent(upgrade_agent.address)
assert released_token.call().balanceOf(customer) == 10000
with pytest.raises(TransactionFailed):
released_token.transact({"from": customer}).upgrade(20000)
示例10: test_cannot_refund_twice
def test_cannot_refund_twice(failed_ico_ready_to_refund: Contract, customer: str):
"""Customer can reclaim refund only once."""
assert failed_ico_ready_to_refund.call().getState() == CrowdsaleState.Refunding
failed_ico_ready_to_refund.transact({"from": customer}).refund()
with pytest.raises(TransactionFailed):
failed_ico_ready_to_refund.transact({"from": customer}).refund()
示例11: test_buy_dust
def test_buy_dust(chain: TestRPCChain, web3: Web3, ico: Contract, uncapped_token: Contract, customer: str, preico_token_price, preico_starts_at, team_multisig):
"""Cannot buy with too small transaction."""
wei_value = 1
time_travel(chain, preico_starts_at + 1)
with pytest.raises(TransactionFailed):
ico.transact({"from": customer, "value": wei_value}).buy()
示例12: test_unlock_early
def test_unlock_early(chain, token: Contract, team_multisig: str, vault: Contract, unlock_time: int):
"""Early unlock fails."""
assert token.call().balanceOf(team_multisig) == 0
assert token.call().balanceOf(vault.address) == 1000000
time_travel(chain, unlock_time - 1)
with pytest.raises(TransactionFailed):
vault.transact({"from": team_multisig}).unlock()
示例13: test_buy_fail_goal
def test_buy_fail_goal(chain: TestRPCChain, ico: Contract, customer: str, preico_starts_at, preico_ends_at, preico_funding_goal):
"""Goal is not reached if there is not enough investment."""
time_travel(chain, preico_starts_at + 1)
wei_value = preico_funding_goal // 2
ico.transact({"from": customer, "value": wei_value}).buy()
time_travel(chain, preico_ends_at + 1)
assert ico.call().getState() == CrowdsaleState.Failure
示例14: decimalize_token_amount
def decimalize_token_amount(contract: Contract, amount: int) -> Decimal:
"""Convert raw fixed point token amount to decimal format.
:param contract: ERC-20 token contract with decimals field
:param amount: Raw token amount
:return: The resultdroping :py:class:`decimal.Decimal` carries a correct decimal places.
"""
val = Decimal(amount) / Decimal(10 ** contract.call().decimals())
quantizer = Decimal(1) / Decimal(10 ** contract.call().decimals())
return val.quantize(quantizer)
示例15: test_unlock
def test_unlock(chain, token: Contract, team_multisig: str, vault: Contract, unlock_time: int):
"""Unlock tokens."""
assert token.call().balanceOf(team_multisig) == 0
assert token.call().balanceOf(vault.address) == 1000000
time_travel(chain, unlock_time + 1)
vault.transact({"from": team_multisig}).unlock()
assert token.call().balanceOf(team_multisig) == 1000000
assert token.call().balanceOf(vault.address) == 0