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


Python Contract.call方法代码示例

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


在下文中一共展示了Contract.call方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_close_early

# 需要导入模块: from web3.contract import Contract [as 别名]
# 或者: from web3.contract.Contract import call [as 别名]
def test_close_early(chain: TestRPCChain, ico: Contract, customer: str, preico_starts_at, preico_ends_at, team_multisig):
    """Soft cap triggered, close crowdsale early."""

    # Close earlier than anticipated
    new_early = preico_starts_at + 1*3600
    assert new_early < preico_ends_at

    time_travel(chain, preico_starts_at + 1)
    assert ico.call().getState() == CrowdsaleState.Funding
    ico.transact({"from": customer, "value": to_wei(1, "ether")}).buy()
    ico.transact({"from": team_multisig}).setEndsAt(new_early)

    # Here we try to switch the strategy, and buy again, 1 wei for 1 token
    args = [
        1,
    ]
    tx = {
        "from": team_multisig,
    }
    pricing_strategy, hash = chain.provider.deploy_contract('FlatPricing', deploy_args=args, deploy_transaction=tx)

    ico.transact({"from": team_multisig}).setPricingStrategy(pricing_strategy.address)
    assert ico.call().pricingStrategy() == pricing_strategy.address

    ico.transact({"from": customer, "value": 1}).buy()

    # Finally, here we travel in time to situation after the early closing:
    time_travel(chain, new_early + 1)
    assert ico.call().getState() == CrowdsaleState.Failure

    with pytest.raises(TransactionFailed):
        ico.transact({"from": customer, "value": to_wei(1, "ether")}).buy()
开发者ID:minibitsdice,项目名称:minibitsdice.github.io,代码行数:34,代码来源:test_uncapped_flatprice.py

示例2: test_token_rename

# 需要导入模块: from web3.contract import Contract [as 别名]
# 或者: from web3.contract.Contract import call [as 别名]
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,代码行数:9,代码来源:test_token.py

示例3: decimalize_token_amount

# 需要导入模块: from web3.contract import Contract [as 别名]
# 或者: from web3.contract.Contract import call [as 别名]
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,代码行数:12,代码来源:utils.py

示例4: test_unlock

# 需要导入模块: from web3.contract import Contract [as 别名]
# 或者: from web3.contract.Contract import call [as 别名]
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,代码行数:13,代码来源:test_time_vault.py

示例5: test_buy_one_investor

# 需要导入模块: from web3.contract import Contract [as 别名]
# 或者: from web3.contract.Contract import call [as 别名]
def test_buy_one_investor(chain: TestRPCChain, web3: Web3, ico: Contract, uncapped_token: Contract, customer: str, preico_token_price, preico_starts_at, team_multisig):
    """Can buy when crowdsale is running."""

    original_balance = web3.eth.getBalance(team_multisig)
    wei_value = to_wei(1, "ether")
    buys_tokens = wei_value // preico_token_price
    assert buys_tokens > 0

    time_travel(chain, preico_starts_at + 1)
    assert ico.call().getState() == CrowdsaleState.Funding
    assert ico.call().investorCount() == 0
    assert ico.call().investedAmountOf(customer) == 0
    ico.transact({"from": customer, "value": wei_value}).buy()

    #
    # See everything was correctly credited
    #

    # Tokens on every account
    assert uncapped_token.call().balanceOf(customer) == buys_tokens
    assert uncapped_token.call().totalSupply() == buys_tokens
    assert ico.call().tokensSold() == buys_tokens
    assert ico.call().investorCount() == 1

    # Ether on every account
    assert ico.call().weiRaised() == wei_value
    assert ico.call().investedAmountOf(customer) == wei_value
    balance_diff = web3.eth.getBalance(team_multisig) - original_balance
    assert balance_diff == wei_value

    # Investors
    assert ico.call().investorCount() == 1

    #
    # Events
    #

    # Crowdsale
    events = ico.pastEvents("Invested").get()
    assert len(events) == 1
    e = events[0]
    assert e["args"]["investor"] == customer
    assert e["args"]["weiAmount"] == wei_value
    assert e["args"]["tokenAmount"] == buys_tokens

    # ERC-20
    events = uncapped_token.pastEvents("Transfer").get()
    assert len(events) == 1
    e = events[0]
    assert e["args"]["from"] == "0x0000000000000000000000000000000000000000"
    assert e["args"]["to"] == customer
    assert e["args"]["value"] == buys_tokens
开发者ID:minibitsdice,项目名称:minibitsdice.github.io,代码行数:54,代码来源:test_uncapped_flatprice.py

示例6: test_cannot_transfer

# 需要导入模块: from web3.contract import Contract [as 别名]
# 或者: from web3.contract.Contract import call [as 别名]
def test_cannot_transfer(token: Contract, team_multisig, customer: str, customer_2: str):
    """Tokens cannot be transferred before they are released."""

    assert not token.call().released()

    # team_multisig is on the whitelisted transfer agent list
    assert token.call().transferAgents(team_multisig) == False
    with pytest.raises(TransactionFailed):
        token.transact({"from": team_multisig}).transfer(customer, 10000)

    # customer cannot transfer to customer 2 before release
    assert token.call().transferAgents(customer) == False
    with pytest.raises(TransactionFailed):
        token.transact({"from": customer}).transfer(customer_2, 10000)
开发者ID:minibitsdice,项目名称:minibitsdice.github.io,代码行数:16,代码来源:test_releasable.py

示例7: test_close_late

# 需要导入模块: from web3.contract import Contract [as 别名]
# 或者: from web3.contract.Contract import call [as 别名]
def test_close_late(chain: TestRPCChain, ico: Contract, customer: str, preico_starts_at, preico_ends_at, team_multisig):
    """Extend crowdsale."""

    new_end = preico_ends_at + 1*3600
    assert new_end > preico_ends_at

    time_travel(chain, preico_starts_at + 1)
    assert ico.call().getState() == CrowdsaleState.Funding
    ico.transact({"from": customer, "value": to_wei(1, "ether")}).buy()

    ico.transact({"from": team_multisig}).setEndsAt(new_end)

    time_travel(chain, preico_ends_at + 1)
    assert ico.call().getState() == CrowdsaleState.Funding
    ico.transact({"from": customer, "value": to_wei(1, "ether")}).buy()
开发者ID:minibitsdice,项目名称:minibitsdice.github.io,代码行数:17,代码来源:test_uncapped_flatprice.py

示例8: test_erc20_interface

# 需要导入模块: from web3.contract import Contract [as 别名]
# 或者: from web3.contract.Contract import call [as 别名]
def test_erc20_interface(token: Contract, token_owner: str, empty_address: str):
    """Token satisfies ERC-20 interface."""

    # https://github.com/OpenZeppelin/zeppelin-solidity/blob/master/contracts/token/ERC20.sol

    assert token.call().balanceOf(empty_address) == 0
    assert token.call().allowance(token_owner, empty_address) == 0

    # Event
    # We follow OpenZeppelin - in the ERO20 issue names are _from, _to, _value
    transfer = token._find_matching_event_abi("Transfer", ["from", "to", "value"])
    assert transfer

    approval = token._find_matching_event_abi("Approval", ["owner", "spender", "value"])
    assert approval
开发者ID:arinddas,项目名称:ico-contracts,代码行数:17,代码来源:test_erc20.py

示例9: test_halt

# 需要导入模块: from web3.contract import Contract [as 别名]
# 或者: from web3.contract.Contract import call [as 别名]
def test_halt(chain: TestRPCChain, web3: Web3, ico: Contract, uncapped_token: Contract, customer: str, preico_token_price, preico_starts_at, team_multisig):
    """Cannot buy tokens during the emergency pause mode."""

    time_travel(chain, preico_starts_at + 1)
    wei_value = to_wei(1, "ether")

    ico.transact({"from": team_multisig}).halt()
    assert ico.call().halted()

    with pytest.raises(TransactionFailed):
        ico.transact({"from": customer, "value": wei_value}).buy()

    ico.transact({"from": team_multisig}).unhalt()
    assert not ico.call().halted()
    ico.transact({"from": customer, "value": wei_value}).buy()
开发者ID:minibitsdice,项目名称:minibitsdice.github.io,代码行数:17,代码来源:test_uncapped_flatprice.py

示例10: test_buy_early

# 需要导入模块: from web3.contract import Contract [as 别名]
# 或者: from web3.contract.Contract import call [as 别名]
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,代码行数:9,代码来源:test_uncapped_flatprice.py

示例11: test_buy_late_goal_reached

# 需要导入模块: from web3.contract import Contract [as 别名]
# 或者: from web3.contract.Contract import call [as 别名]
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,代码行数:9,代码来源:test_uncapped_flatprice.py

示例12: test_early_whitelist_only_owner

# 需要导入模块: from web3.contract import Contract [as 别名]
# 或者: from web3.contract.Contract import call [as 别名]
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,代码行数:9,代码来源:test_uncapped_flatprice.py

示例13: failed_ico_ready_to_refund

# 需要导入模块: from web3.contract import Contract [as 别名]
# 或者: from web3.contract.Contract import call [as 别名]
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,代码行数:9,代码来源:test_refund.py

示例14: test_signature_contract_verify_v_r_s

# 需要导入模块: from web3.contract import Contract [as 别名]
# 或者: from web3.contract.Contract import call [as 别名]
def test_signature_contract_verify_v_r_s(web3: Web3, signature_contract: Contract):
    """Test that our signature verification works in Solidity contract.

    """

    # Use random Ethereum address as payload for signing
    data = "0xda39147df55f6c51ad539a5e108adc5d7284b309"

    # Convert address to raw bytes
    data_bin = binascii.unhexlify(data[2:])
    assert type(data_bin) == bytes

    private_key_seed = "foobar"
    # Address is 0x58708390680239282143999941903085911172379991841

    signature_data = sign(data_bin, private_key_seed)

    # hash = big_endian_to_int(signature_data["hash"])
    hash = signature_data["hash"]
    v = signature_data["v"]
    r = signature_data["r_bytes"]
    s = signature_data["s_bytes"]

    # 0x0a489345f9e9bc5254e18dd14fa7ecfdb2ce5f21
    result = signature_contract.call().verify(hash, v, r, s)
    assert result == signature_data["address_ethereum"]
开发者ID:websauna,项目名称:websauna.wallet,代码行数:28,代码来源:test_signature.py

示例15: sweep_account

# 需要导入模块: from web3.contract import Contract [as 别名]
# 或者: from web3.contract.Contract import call [as 别名]
def sweep_account(
        private_key: str,
        faucet_address: str,
        token_contract: Contract,
        web3: Web3,
        wait_for_transaction
):
    address = privkey_to_addr(private_key)
    log.info('Sweeping account {}'.format(address))
    token_balance = token_contract.call().balanceOf(address)
    if token_balance > 0:
        tx = create_signed_contract_transaction(
            private_key,
            token_contract,
            'transfer',
            [
                faucet_address,
                token_balance
            ]
        )
        try:
            tx_hash = web3.eth.sendRawTransaction(tx)
        except ValueError as e:
            if e.args[0]['message'].startswith('Insufficient funds.'):
                pass
            else:
                raise
        else:
            wait_for_transaction(tx_hash)
            assert token_contract.call().balanceOf(address) == 0

    balance = web3.eth.getBalance(address)
    if balance < NETWORK_CFG.POT_GAS_LIMIT * NETWORK_CFG.GAS_PRICE:
        return
    tx = create_signed_transaction(
        private_key,
        web3,
        to=faucet_address,
        value=balance - NETWORK_CFG.POT_GAS_LIMIT * NETWORK_CFG.GAS_PRICE,
        gas_limit=NETWORK_CFG.POT_GAS_LIMIT
    )
    tx_hash = web3.eth.sendRawTransaction(tx)
    wait_for_transaction(tx_hash)
    assert web3.eth.getBalance(address) == 0, (
        'Sweeping of account {} (private key {}) failed.'.format(address, private_key)
    )
开发者ID:AlphaX-IBS,项目名称:microraiden,代码行数:48,代码来源:accounts.py


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