• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python contract.Contract类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中web3.contract.Contract的典型用法代码示例。如果您正苦于以下问题:Python Contract类的具体用法?Python Contract怎么用?Python Contract使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了Contract类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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


示例16: test_bad_released

def test_bad_released(token: Contract, team_multisig: str, malicious_address: str, empty_address: str):
    """Only release agent can make token transferable."""

    assert not token.call().released()

    with pytest.raises(TransactionFailed):
        token.transact({"from": malicious_address}).releaseTokenTransfer()

    # Even owner cannot release, need to go through release agent process
    with pytest.raises(TransactionFailed):
        token.transact({"from": team_multisig}).releaseTokenTransfer()
开发者ID:minibitsdice,项目名称:minibitsdice.github.io,代码行数:11,代码来源:test_releasable.py


示例17: test_finalize_fail_goal

def test_finalize_fail_goal(chain: TestRPCChain, uncapped_flatprice_final: Contract, customer: str, preico_starts_at, preico_ends_at, preico_funding_goal):
    """Finalize can be done only for successful crowdsales."""

    time_travel(chain, preico_starts_at + 1)
    wei_value = preico_funding_goal // 2

    uncapped_flatprice_final.transact({"from": customer, "value": wei_value}).buy()

    time_travel(chain, preico_ends_at + 1)
    assert uncapped_flatprice_final.call().getState() == CrowdsaleState.Failure

    with pytest.raises(TransactionFailed):
        uncapped_flatprice_final.transact().finalize()
开发者ID:minibitsdice,项目名称:minibitsdice.github.io,代码行数:13,代码来源:test_finalize.py


示例18: test_set_upgrade_agent

def test_set_upgrade_agent(upgradeable_token: Contract, upgrade_agent: Contract, team_multisig):
    """Upgrade agent can be set on a released token."""

    # Preconditions are met
    assert upgrade_agent.call().isUpgradeAgent()
    assert upgradeable_token.call().canUpgrade()
    assert upgradeable_token.call().upgradeMaster() == team_multisig
    assert upgrade_agent.call().oldToken() == upgradeable_token.address
    assert upgrade_agent.call().originalSupply() == upgradeable_token.call().totalSupply()
    assert upgradeable_token.call().getUpgradeState() == UpgradeState.WaitingForAgent

    upgradeable_token.transact({"from": team_multisig}).setUpgradeAgent(upgrade_agent.address)
    assert upgradeable_token.call().getUpgradeState() == UpgradeState.ReadyToUpgrade
开发者ID:arinddas,项目名称:ico-contracts,代码行数:13,代码来源:test_upgrade.py


示例19: test_finalize_only_by_crowdsale

def test_finalize_only_by_crowdsale(chain: TestRPCChain, uncapped_flatprice_final: Contract, team_multisig: str, customer: str, preico_starts_at, preico_ends_at, preico_funding_goal, default_finalize_agent):
    """Finalizer can be only triggered by crowdsale."""

    time_travel(chain, preico_starts_at + 1)
    wei_value = preico_funding_goal

    uncapped_flatprice_final.transact({"from": customer, "value": wei_value}).buy()

    time_travel(chain, preico_ends_at + 1)
    assert uncapped_flatprice_final.call().getState() == CrowdsaleState.Success

    # Checks for the owner
    with pytest.raises(TransactionFailed):
        default_finalize_agent.transact({"from": team_multisig}).finalizeCrowdsale()
开发者ID:minibitsdice,项目名称:minibitsdice.github.io,代码行数:14,代码来源:test_finalize.py


示例20: execute

    def execute(
        self, to_contract: Contract, func: str, args=None, amount_in_eth: Optional[Decimal] = None, max_gas=100000
    ):
        """Calls a smart contract from the hosted wallet.

        Creates a transaction that is proxyed through hosted wallet execute method. We need to have ABI as Populus Contract instance.

        :param wallet_address: Wallet address
        :param contract: Contract to called as address bound Populus Contract class
        :param func: Method name to be called
        :param args: Arguments passed to the method
        :param value: Additional value carried in the call in ETH
        :param gas: The max amount of gas the coinbase account is allowed to pay for this transaction.
        :return: txid of the execution as hex string
        """

        assert isinstance(to_contract, Contract)

        if amount_in_eth:
            assert isinstance(amount_in_eth, Decimal)  # Don't let floats slip through
            value = to_wei(amount_in_eth)
        else:
            value = 0

        # Encode function arguments
        function_abi = to_contract._find_matching_fn_abi(func, args)
        # 4 byte function hash
        function_selector = function_abi_to_4byte_selector(function_abi)

        # data payload passed to the function
        arg_data = to_contract.encodeABI(func, args=args)

        call_data = function_selector + arg_data[2:]

        # test_event_execute() call data should look like
        # function selector + random int as 256-bit
        # 0x5093dc7d000000000000000000000000000000000000000000000000000000002a3f58fe

        # web3 takes bytes argument as actual bytes, not hex
        call_data = binascii.unhexlify(call_data[2:])

        tx_info = {
            # The Ethereum account that pays the gas for this operation
            "from": self.contract.web3.eth.coinbase,
            "gas": max_gas,
        }

        txid = self.contract.transact(tx_info).execute(to_contract.address, value, max_gas, call_data)
        return txid
开发者ID:websauna,项目名称:websauna.wallet,代码行数:49,代码来源:wallet.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python dockletRequest.post函数代码示例发布时间:2022-05-26
下一篇:
Python web3.Web3类代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap