Skip to content

Commit

Permalink
fix(cli): fix tx submission result check (astriaorg#1113)
Browse files Browse the repository at this point in the history
## Summary
previously, the command was not erroring if `check_tx` failed as only
the `deliver_tx` response was checked. this PR fixes that and now checks
both responses

## Changes
- check `check_tx` result 

## Testing
i ran it manually with txs that fail check_tx.
  • Loading branch information
noot authored May 28, 2024
1 parent 5387149 commit 3473703
Showing 1 changed file with 15 additions and 25 deletions.
40 changes: 15 additions & 25 deletions crates/astria-cli/src/commands/sequencer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ pub(crate) async fn get_balance(args: &BasicAccountArgs) -> eyre::Result<()> {

println!("Balances for address {}:", hex::encode(address.0));
for balance in res.balances {
println!(" asset ID: {}", hex::encode(balance.denom.id()));
println!(" asset ID: {}", balance.denom.id());
println!(" {} {}", balance.balance, balance.denom);
}

Expand Down Expand Up @@ -191,7 +191,6 @@ pub(crate) async fn send_transfer(args: &TransferArgs) -> eyre::Result<()> {
.await
.wrap_err("failed to submit transfer transaction")?;

ensure!(res.tx_result.code.is_ok(), "error with transfer");
println!("Transfer completed!");
println!("Included in block: {}", res.height);
Ok(())
Expand All @@ -217,10 +216,6 @@ pub(crate) async fn ibc_relayer_add(args: &IbcRelayerChangeArgs) -> eyre::Result
.await
.wrap_err("failed to submit IbcRelayerChangeAction::Addition transaction")?;

ensure!(
res.tx_result.code.is_ok(),
"error with IbcRelayerChangeAction::Addition"
);
println!("IbcRelayerChangeAction::Addition completed!");
println!("Included in block: {}", res.height);
Ok(())
Expand All @@ -246,10 +241,6 @@ pub(crate) async fn ibc_relayer_remove(args: &IbcRelayerChangeArgs) -> eyre::Res
.await
.wrap_err("failed to submit IbcRelayerChangeAction::Removal transaction")?;

ensure!(
res.tx_result.code.is_ok(),
"error with IbcRelayerChangeAction::Removal"
);
println!("IbcRelayerChangeAction::Removal completed!");
println!("Included in block: {}", res.height);
Ok(())
Expand Down Expand Up @@ -285,7 +276,6 @@ pub(crate) async fn init_bridge_account(args: &InitBridgeAccountArgs) -> eyre::R
.await
.wrap_err("failed to submit InitBridgeAccount transaction")?;

ensure!(res.tx_result.code.is_ok(), "error with InitBridgeAccount");
println!("InitBridgeAccount completed!");
println!("Included in block: {}", res.height);
println!("Rollup name: {}", args.rollup_name);
Expand Down Expand Up @@ -321,7 +311,6 @@ pub(crate) async fn bridge_lock(args: &BridgeLockArgs) -> eyre::Result<()> {
.await
.wrap_err("failed to submit BridgeLock transaction")?;

ensure!(res.tx_result.code.is_ok(), "error with BridgeLock");
println!("BridgeLock completed!");
println!("Included in block: {}", res.height);
Ok(())
Expand Down Expand Up @@ -349,10 +338,6 @@ pub(crate) async fn fee_asset_add(args: &FeeAssetChangeArgs) -> eyre::Result<()>
.await
.wrap_err("failed to submit FeeAssetChangeAction::Addition transaction")?;

ensure!(
res.tx_result.code.is_ok(),
"error with FeeAssetChangeAction::Addition"
);
println!("FeeAssetChangeAction::Addition completed!");
println!("Included in block: {}", res.height);
Ok(())
Expand Down Expand Up @@ -380,10 +365,6 @@ pub(crate) async fn fee_asset_remove(args: &FeeAssetChangeArgs) -> eyre::Result<
.await
.wrap_err("failed to submit FeeAssetChangeAction::Removal transaction")?;

ensure!(
res.tx_result.code.is_ok(),
"error with FeeAssetChangeAction::Removal"
);
println!("FeeAssetChangeAction::Removal completed!");
println!("Included in block: {}", res.height);
Ok(())
Expand Down Expand Up @@ -412,7 +393,6 @@ pub(crate) async fn mint(args: &MintArgs) -> eyre::Result<()> {
.await
.wrap_err("failed to submit Mint transaction")?;

ensure!(res.tx_result.code.is_ok(), "error with Mint");
println!("Mint completed!");
println!("Included in block: {}", res.height);
Ok(())
Expand Down Expand Up @@ -440,7 +420,6 @@ pub(crate) async fn sudo_address_change(args: &SudoAddressChangeArgs) -> eyre::R
.await
.wrap_err("failed to submit SudoAddressChange transaction")?;

ensure!(res.tx_result.code.is_ok(), "error with SudoAddressChange");
println!("SudoAddressChange completed!");
println!("Included in block: {}", res.height);
Ok(())
Expand Down Expand Up @@ -475,7 +454,6 @@ pub(crate) async fn validator_update(args: &ValidatorUpdateArgs) -> eyre::Result
.await
.wrap_err("failed to submit ValidatorUpdate transaction")?;

ensure!(res.tx_result.code.is_ok(), "error with ValidatorUpdate");
println!("ValidatorUpdate completed!");
println!("Included in block: {}", res.height);
Ok(())
Expand All @@ -497,6 +475,7 @@ async fn submit_transaction(
let sequencer_key = SigningKey::from(private_key_bytes);

let from_address = *sequencer_key.verification_key().address();
println!("sending tx from address: {from_address}");

let nonce_res = sequencer_client
.get_latest_nonce(from_address)
Expand All @@ -511,10 +490,21 @@ async fn submit_transaction(
actions: vec![action],
}
.into_signed(&sequencer_key);
sequencer_client
let res = sequencer_client
.submit_transaction_commit(tx)
.await
.wrap_err("failed to submit transaction")
.wrap_err("failed to submit transaction")?;
ensure!(
res.check_tx.code.is_ok(),
"failed to check tx: {}",
res.check_tx.log
);
ensure!(
res.tx_result.code.is_ok(),
"failed to execute tx: {}",
res.tx_result.log
);
Ok(res)
}

#[cfg(test)]
Expand Down

0 comments on commit 3473703

Please sign in to comment.