Conversation
|
Great to see some work on that!! I personally would prefer your alternate option 1. Would there be a way to just not care about the contract ID? I would suspect that in lot of cases people would not care much about asserting that no? In basic instances, I actually might just want to check that I have an instance of a specific event and don't need to check the inner values. |
You would need to compare the parts of the event you care about manually within the test. e.g. let event = Transfer {
from: from.clone(),
to: to.address(),
amount,
to_muxed_id: to.id(),
};
let (_, topics, data) = env.events().all()[0]
assert_eq!(topics, event.topics());
assert_eq!(data, event.data());I don't think it would be a good idea for contract IDs to be omitted from the
You would also likely just compare the first topic, or perform some One advantage of the assert!(env.events().all().contains(
&Transfer {
from: from.clone(),
to: to.clone(),
amount,
to_muxed_id: None,
}
.to_contract_event(&env, &contract_id)
));This is neat for composed contracts where their event might be one of many in the test transaction. i didn't try super hard to see if we could get this to work for option 2, where |
Fair enough, your example is a simple enough syntax 👍
This would be great to be able to do some contains like that 💯 One question, is there actually an advantage in having |
This is nice and simpler, I like it! I am not sure about the wording |
leighmcculloch
left a comment
There was a problem hiding this comment.
I haven't reviewed the whole diff yet, but some thoughts inline.
9fa7b86 to
ba841fc
Compare
|
closing in favor of #1638 |
What
Updates
testutils::Eventsread functions to use thexdr::ContractEventtype and deprecates the currentallfunction. Adds helpers tocontracteventstructs to easily transform event structs intoxdr::ContractEvent's for easy comparison during tests.Finally, this also adds function to
testutils::Eventsto allow test writers to easily pull events published by a specificcontract_id.As a side effect, using xdr also allows the assertion debug info to display what is different between events.
For example:
instead of
Why
Helps test write easier event comparison.
For a lighter solution, we can also consider #1634 . This just adds a few utils to make building events in tests easier.
Known limitations
None