| 95 | } |
| 96 | |
| 97 | async fn run<C>(provider: &Provider<C>, opts: &Options) -> anyhow::Result<()> |
| 98 | where |
| 99 | C: JsonRpcClient + Clone + 'static, |
| 100 | { |
| 101 | let from = TestAccount::new(&opts.secret_key)?; |
| 102 | |
| 103 | tracing::info!(from = ?from.eth_addr, "ethereum address"); |
| 104 | tracing::info!("deploying Greeter"); |
| 105 | |
| 106 | let bytecode = Bytes::from(hex::decode(GREETER_HEX).context("failed to decode contract hex")?); |
| 107 | let abi: Abi = GREETER_ABI.clone(); |
| 108 | |
| 109 | let chain_id = provider.get_chainid().await?; |
| 110 | |
| 111 | let mw = make_middleware(provider.clone(), chain_id.as_u64(), &from) |
| 112 | .context("failed to create middleware")?; |
| 113 | |
| 114 | let mw = Arc::new(mw); |
| 115 | |
| 116 | const GREETING0: &str = "Welcome, weary traveller!"; |
| 117 | const GREETING1: &str = "Howdy doody!"; |
| 118 | |
| 119 | let factory = ContractFactory::new(abi, bytecode.clone(), mw.clone()); |
| 120 | let deployer = factory.deploy((GREETING0.to_string(),))?; |
| 121 | |
| 122 | let (contract, deploy_receipt): (_, TransactionReceipt) = deployer |
| 123 | .send_with_receipt() |
| 124 | .await |
| 125 | .context("failed to send deployment")?; |
| 126 | |
| 127 | tracing::info!(addr = ?contract.address(), "Greeter deployed"); |
| 128 | |
| 129 | let contract = Greeter::new(contract.address(), contract.client()); |
| 130 | |
| 131 | let greeting: String = contract |
| 132 | .greet() |
| 133 | .call() |
| 134 | .await |
| 135 | .context("failed to call greet")?; |
| 136 | |
| 137 | assert_eq!(greeting, GREETING0); |
| 138 | |
| 139 | let deploy_height = deploy_receipt.block_number.expect("deploy height is known"); |
| 140 | |
| 141 | // Set the greeting to emit an event. |
| 142 | let set_greeting: TestContractCall<_, ()> = contract.set_greeting(GREETING1.to_string()); |
| 143 | |
| 144 | let _tx_receipt: TransactionReceipt = set_greeting |
| 145 | .send() |
| 146 | .await |
| 147 | .context("failed to set greeting")? |
| 148 | .log_msg("set_greeting") |
| 149 | .retries(3) |
| 150 | .await? |
| 151 | .context("cannot get receipt")?; |
| 152 | |
| 153 | let greeting: String = contract |
| 154 | .greet() |