本文整理汇总了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
示例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
示例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