|
1 | 1 | use soroban_cli::{ |
| 2 | + commands::tx::fetch::GetTransactionEvents, |
2 | 3 | commands::tx::fetch::fee::FeeTable, |
3 | 4 | utils::transaction_hash, |
4 | 5 | xdr::{ |
@@ -284,6 +285,92 @@ async fn tx_fetch_fee() { |
284 | 285 | ); |
285 | 286 | } |
286 | 287 |
|
| 288 | +#[tokio::test] |
| 289 | +async fn tx_fetch_events() { |
| 290 | + let sandbox = &TestEnv::new(); |
| 291 | + let test_account_alias = "test"; |
| 292 | + let contract_id = deploy_contract( |
| 293 | + sandbox, |
| 294 | + HELLO_WORLD, |
| 295 | + DeployOptions { |
| 296 | + deployer: Some(test_account_alias.to_string()), |
| 297 | + ..Default::default() |
| 298 | + }, |
| 299 | + ) |
| 300 | + .await; |
| 301 | + |
| 302 | + let tx_xdr = sandbox |
| 303 | + .new_assert_cmd("contract") |
| 304 | + .arg("invoke") |
| 305 | + .arg("--build-only") |
| 306 | + .arg("--id") |
| 307 | + .arg(contract_id.clone()) |
| 308 | + .arg("--network") |
| 309 | + .arg("local") |
| 310 | + .arg("--") |
| 311 | + .arg("log") |
| 312 | + .arg("--str") |
| 313 | + .arg("hi") |
| 314 | + .assert() |
| 315 | + .success() |
| 316 | + .stdout_as_str(); |
| 317 | + |
| 318 | + let tx_simulated = sandbox |
| 319 | + .new_assert_cmd("tx") |
| 320 | + .arg("simulate") |
| 321 | + .write_stdin(tx_xdr.as_bytes()) |
| 322 | + .assert() |
| 323 | + .success() |
| 324 | + .stdout_as_str(); |
| 325 | + |
| 326 | + let signed = sandbox |
| 327 | + .new_assert_cmd("tx") |
| 328 | + .arg("sign") |
| 329 | + .arg("--sign-with-key") |
| 330 | + .arg("test") |
| 331 | + .write_stdin(tx_simulated.as_bytes()) |
| 332 | + .assert() |
| 333 | + .success() |
| 334 | + .stdout_as_str(); |
| 335 | + |
| 336 | + sandbox |
| 337 | + .new_assert_cmd("tx") |
| 338 | + .arg("send") |
| 339 | + .write_stdin(signed.as_bytes()) |
| 340 | + .assert() |
| 341 | + .success() |
| 342 | + .stdout_as_str(); |
| 343 | + |
| 344 | + let tx_env = TransactionEnvelope::from_xdr_base64(signed.clone(), Limits::none()).unwrap(); |
| 345 | + let tx = if let TransactionEnvelope::Tx(env) = tx_env { |
| 346 | + env.tx |
| 347 | + } else { |
| 348 | + panic!("Expected TransactionEnvelope::Tx, got something else"); |
| 349 | + }; |
| 350 | + |
| 351 | + let tx_hash = hex::encode(transaction_hash(&tx, &sandbox.network.network_passphrase).unwrap()); |
| 352 | + |
| 353 | + // fetch the tx events |
| 354 | + let output = sandbox |
| 355 | + .new_assert_cmd("tx") |
| 356 | + .arg("fetch") |
| 357 | + .arg("events") |
| 358 | + .arg("--hash") |
| 359 | + .arg(&tx_hash) |
| 360 | + .arg("--network") |
| 361 | + .arg("local") |
| 362 | + .arg("--output") |
| 363 | + .arg("json") |
| 364 | + .assert() |
| 365 | + .success() |
| 366 | + .stdout_as_str(); |
| 367 | + |
| 368 | + let parsed: GetTransactionEvents = serde_json::from_str(&output).unwrap(); |
| 369 | + assert!(parsed.diagnostic_events.is_empty()); |
| 370 | + assert_eq!(parsed.contract_events.len(), 1); |
| 371 | + assert_eq!(parsed.transaction_events.len(), 2); |
| 372 | +} |
| 373 | + |
287 | 374 | async fn add_account_data( |
288 | 375 | sandbox: &TestEnv, |
289 | 376 | account_alias: &str, |
|
0 commit comments