Rust sdk decode_logs_with_type::<T> for a custom struct doesn't return any value

decode_logs_with_type works as expected for u64 and other types, but it returns empty value for a struct while decode_logs() does return the log event.

Steps to reproduce, have a struct for LogResult output,

struct CountEvent {
    pub user: Identity,
    pub count: u64,
}
/// fn count returns no value, but logs the event with CountEvent struct
abi Counter {
     #[storage(read, write)]
     fn count(user: Identity);
}
// use fuel::{prelude::*,programs::responses::*,}; // Imports for CallResponse, ....
// use crate::functions::setup::abigen_bindings::counter_mod::events::CountEvent; // Import for CountEvent type from abi

/// Function that calls counter
pub async fn count(contract: &Count<WalletUnlocked>, user: Identity) -> CallResponse<()> {
        contract
            .methods()
            .count(user)
            .call()
            .await
            .unwrap()
    }

#[tokio::test]
async fn test_count() {
          let (user, _) = setup().await;

          let counted = count(
            &user.counter,
            Identity::Address(user.wallet.address().into()),
            ).await;
           let log = counted
            .decode_logs_with_type::<CountEvent>().unwrap();
/// **Expected log was to have some value within array, but it returns [ ]**
/// When using u64 and other types, it returns the log except for Custom struct 
           let event = log.first().unwrap();
           
}

Installed toolchains

latest-x86_64-unknown-linux-gnu (default)
nightly-2024-05-28-x86_64-unknown-linux-gnu

active toolchain

latest-x86_64-unknown-linux-gnu (default)
forc : 0.64.0
- forc-client
- forc-deploy : 0.64.0
- forc-run : 0.64.0
- forc-crypto : 0.64.0
- forc-debug : 0.64.0
- forc-doc : 0.64.0
- forc-fmt : 0.64.0
- forc-lsp : 0.64.0
- forc-tx : 0.64.0
- forc-wallet : 0.9.1
fuel-core : 0.36.0
fuel-core-keygen : 0.36.0

fuels versions

forc : 0.66
forc-wallet : 0.66.5

1 Like

It is possible that you do not create a log of that type or that the decoding failed. Can you print all logs and see if your log is there.

       let logs = counted.decode_logs();
       dbg!(logs.filter_succeeded());
       dbg!(log.filter_failed());
1 Like

Thanks,
I found the reason was because I didn’t add .with_variable_output_policy(VariableOutputPolicy::Exactly(1)) before the .call()

1 Like

Great work, keep doing

1 Like