Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
Bargsteen opened this issue Oct 13, 2023 · 0 comments
Labels
[Type] Change Request Some visible functionality should be change.

Comments

@Bargsteen
Copy link
Contributor

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 #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 Bargsteen added the [Type] Change Request Some visible functionality should be change. label Oct 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Type] Change Request Some visible functionality should be change.
Projects
None yet
Development

No branches or pull requests

1 participant