import os import random from typing import Tuple from ContractTest import ContractTest,…
- User
import os import random from typing import Tuple
from ContractTest import ContractTest, Configuration
class CrowdTest(ContractTest): DONATE_FLAG_INDEX = 4 SPECIAL_DONATE_FLAG_INDEX = 5 WITHDRAW_FLAG_INDEX = 6 # totalDonateValue = 0 # donateCount = 0 # 调用部署时候的constructor函数,向里面传递受益人的地址self.config.configuration[Configuration.ACCOUNTS][0][Configuration.ADDRESS]就是受益人的地址 def init(self): self.configuration = Configuration(os.path.basename(file)) ContractTest.init(self, self.configuration) # Set the contract name to be tested. self.contract_test_name = "Crowd" pass
codedef init_test_result(self, test_result): #DONATE_FLAG_INDEX test_result.append(0) #SPECIAL_DONATE_FLAG_INDEX test_result.append(0) #WITHDRAW_FLAG_INDEX test_result.append(0) pass #调用部署时候的constructor函数,向里面传递受益人的地址self.config.configuration[Configuration.ACCOUNTS][1][Configuration.ADDRESS] #就是受益人的地址 def construct_contract(self, nonce, eoa_index): return self.current_contract.constructor(self.config.configuration[Configuration.ACCOUNTS] [1][Configuration.ADDRESS]).buildTransaction( { # "chainId": chain_id, "gas": 30000000, "gasPrice": self.web3.eth.gas_price, "from": self.config.configuration[Configuration.ACCOUNTS][eoa_index][Configuration.ADDRESS], "nonce": nonce, } ) # 向donate函数转账的Python函数 number 转账的数量,uint 转账的单位: "wei" 或 "ether" def send_wei_to_contract_donate(self, number: int, uint: str): tx_hash = self.current_contract.functions.donate().transact( {'from': self.config.configuration[Configuration.ACCOUNTS] [2][Configuration.ADDRESS], 'value': self.web3.toWei(number, uint)}) tx_receipt = self.web3.eth.waitForTransactionReceipt(tx_hash) # 收据:表示的是交易的详情,包含gas和转账金额 # print(tx_receipt) wallet = self.web3.to_checksum_address( self.config.configuration[Configuration.ACCOUNTS][1][Configuration.ADDRESS]) print(self.web3.eth.getBalance(wallet)) self.web3.eth.waitForTransactionReceipt(tx_hash) #使用部署者的地址作为构造函数的参数部署合约 #使用非部署者的地址作为构造函数的参数部署合约 #部署成功后检查(状态变量)fundingGoal的值是否为2ether # donate # 分别使用部署者、受益者、参与者的地址调用donate捐款(正常捐款,异常捐款) # specialDonate # 分别使用部署者、受益者、参与者的地址调用specialDonate捐款(正常捐款,异常捐款) # withdraw # 分别使用部署者、受益者、参与者的地址调用withdraw支取(正常支取,异常支取[金额,身份]) def donate_test(self): def execute(self): print(self.current_contract) - Assistant
There are some syntax errors in your code. I have fixed them for you:
python - User
continue
- Assistant