当前位置: 首页>>代码示例>>Python>>正文


Python contract.Contract类代码示例

本文整理汇总了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)
开发者ID:minibitsdice,项目名称:minibitsdice.github.io,代码行数:7,代码来源:test_uncapped_flatprice.py

示例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()
开发者ID:minibitsdice,项目名称:minibitsdice.github.io,代码行数:7,代码来源:test_uncapped_flatprice.py

示例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
开发者ID:minibitsdice,项目名称:minibitsdice.github.io,代码行数:7,代码来源:test_token.py

示例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
开发者ID:minibitsdice,项目名称:minibitsdice.github.io,代码行数:7,代码来源:test_refund.py

示例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)
开发者ID:minibitsdice,项目名称:minibitsdice.github.io,代码行数:7,代码来源:test_uncapped_flatprice.py

示例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)
开发者ID:minibitsdice,项目名称:minibitsdice.github.io,代码行数:7,代码来源:test_uncapped_flatprice.py

示例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()
开发者ID:minibitsdice,项目名称:minibitsdice.github.io,代码行数:7,代码来源:test_uncapped_flatprice.py

示例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
开发者ID:minibitsdice,项目名称:minibitsdice.github.io,代码行数:8,代码来源:test_uncapped_flatprice.py

示例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)
开发者ID:minibitsdice,项目名称:minibitsdice.github.io,代码行数:8,代码来源:test_upgrade.py

示例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()
开发者ID:minibitsdice,项目名称:minibitsdice.github.io,代码行数:8,代码来源:test_refund.py

示例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()
开发者ID:minibitsdice,项目名称:minibitsdice.github.io,代码行数:9,代码来源:test_uncapped_flatprice.py

示例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()
开发者ID:minibitsdice,项目名称:minibitsdice.github.io,代码行数:9,代码来源:test_time_vault.py

示例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
开发者ID:minibitsdice,项目名称:minibitsdice.github.io,代码行数:10,代码来源:test_uncapped_flatprice.py

示例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)
开发者ID:minibitsdice,项目名称:minibitsdice.github.io,代码行数:10,代码来源:utils.py

示例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
开发者ID:minibitsdice,项目名称:minibitsdice.github.io,代码行数:11,代码来源:test_time_vault.py


注:本文中的web3.contract.Contract类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。