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


Python Contract.transact方法代码示例

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


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

示例1: failed_ico_ready_to_refund

# 需要导入模块: from web3.contract import Contract [as 别名]
# 或者: from web3.contract.Contract import transact [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

示例2: test_buy_early

# 需要导入模块: from web3.contract import Contract [as 别名]
# 或者: from web3.contract.Contract import transact [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

示例3: test_early_whitelist_only_owner

# 需要导入模块: from web3.contract import Contract [as 别名]
# 或者: from web3.contract.Contract import transact [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

示例4: test_change_end_at_only_owner

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

示例5: test_buy_late_goal_reached

# 需要导入模块: from web3.contract import Contract [as 别名]
# 或者: from web3.contract.Contract import transact [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

示例6: test_close_early

# 需要导入模块: from web3.contract import Contract [as 别名]
# 或者: from web3.contract.Contract import transact [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

示例7: test_cannot_mint

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

示例8: test_token_rename

# 需要导入模块: from web3.contract import Contract [as 别名]
# 或者: from web3.contract.Contract import transact [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

示例9: test_buy_early_whitelisted

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

示例10: test_cannot_refund_twice

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

示例11: test_cannot_upgrade_too_many

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

示例12: test_buy_dust

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

示例13: test_unlock_early

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

示例14: test_buy_fail_goal

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

示例15: test_unlock

# 需要导入模块: from web3.contract import Contract [as 别名]
# 或者: from web3.contract.Contract import transact [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


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