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


Python Contract.pastEvents方法代码示例

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


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

示例1: test_buy_one_investor

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

示例2: test_buy_two_investors

# 需要导入模块: from web3.contract import Contract [as 别名]
# 或者: from web3.contract.Contract import pastEvents [as 别名]
def test_buy_two_investors(chain: TestRPCChain, web3: Web3, ico: Contract, uncapped_token: Contract, customer: str, customer_2, preico_token_price, preico_starts_at, team_multisig):
    """Two different customers buy in."""

    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)

    # Buy twice
    ico.transact({"from": customer, "value": wei_value}).buy()
    ico.transact({"from": customer_2, "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 * 2
    assert ico.call().tokensSold() == buys_tokens * 2

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

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

    #
    # Events
    #

    # Crowdsale
    events = ico.pastEvents("Invested").get()
    assert len(events) == 2

    # ERC-20
    events = uncapped_token.pastEvents("Transfer").get()
    assert len(events) == 2
开发者ID:minibitsdice,项目名称:minibitsdice.github.io,代码行数:45,代码来源:test_uncapped_flatprice.py

示例3: test_buy_reach_goal

# 需要导入模块: from web3.contract import Contract [as 别名]
# 或者: from web3.contract.Contract import pastEvents [as 别名]
def test_buy_reach_goal(chain: TestRPCChain, flat_pricing, ico: Contract, customer: str, preico_starts_at, preico_ends_at, preico_funding_goal):
    """Goal can be reached with a sufficient investment."""

    time_travel(chain, preico_starts_at + 1)
    wei_value = preico_funding_goal

    # Check that we don't have issues with our pricing
    assert flat_pricing.call().calculatePrice(wei_value, 0, 0, customer, 0) > 0

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

    # We got investment event
    events = ico.pastEvents("Invested").get()
    assert len(events) == 1
    e = events[0]
    assert e["args"]["investor"] == customer
    assert e["args"]["weiAmount"] == wei_value

    assert ico.call().weiRaised() == wei_value
    assert ico.call().weiRaised() == ico.call().minimumFundingGoal()
    assert ico.call().isMinimumGoalReached()

    time_travel(chain, preico_ends_at + 1)
    assert ico.call().getState() == CrowdsaleState.Success
开发者ID:minibitsdice,项目名称:minibitsdice.github.io,代码行数:26,代码来源:test_uncapped_flatprice.py


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