concordium-rust-smart-contracts icon indicating copy to clipboard operation
concordium-rust-smart-contracts copied to clipboard

Add helper method for deserializing events for a single contract in testing lib

Open Bargsteen opened this issue 1 year ago • 0 comments

Description Add a helper method on ContractInvokeSuccess for deserializing events into structured types. It should assume that only a single contract is called and thus that only one type of event is produced.

I needed this method several times for https://github.com/Concordium/concordium-rust-smart-contracts/pull/347 and @DOBEN pointed out that we should add it to the testing library.

This function achieves the same result for Cis2Events:

fn deserialize_update_events(
    update: &ContractInvokeSuccess,
) -> Vec<Cis2Event<ContractTokenId, ContractTokenAmount>> {
    update
        .events()
        .flat_map(|(_addr, events)| {
            events.iter().map(|e| {
                let e = from_bytes(e.as_ref()).expect("Deserialize event");
                e
            })
        })
        .collect()
}

Once implemented, we should replace all the deserialize_update_events in the example contracts with the new method.

Bargsteen avatar Oct 13 '23 13:10 Bargsteen