scrtlabs / SecretNetwork

𝕊 The Secret Network
https://scrt.network
Other
529 stars 193 forks source link

added another test where the submsg issues a failing bank message #1541

Closed eshelB closed 11 months ago

eshelB commented 1 year ago

Another case I wanted to know and specifically verify - whether contracts preserve their state even if the submessage triggers a message that goes to other modules which fails the entire transaction.

Case 1: contract creates submessage, submessage creates failing bank message. everything reverts. Case 2: contract creates 1. submessage that succeeds, 2. bank message that fails. everything reverts. Case 3: contract creates submessage that suceeds. On reply endpoint, sends failing bank message. everything reverts.

Added comments explaning all tests up to now.

NOTE: I Observed a case where I think we differ from cosmwasm's documentation: It states here that:

"Submessages (and their replies) are all executed before any messages. They also follow the depth first rules as with messages. Here is a simple example. Contract A returns submessages S1 and S2, and message M1. Submessage S1 returns message N1. The order will be: S1, N1, reply(S1), S2, reply(S2), M1"

I don't know whether they mean that regular messages are postponed to the end of the whole message chain, or whether they are postponed just after all the submessages created by the current submsg. (probably latter as that would make executions not have to be context-aware). However, I think (based on a look into the code and the results of the tests) that regular messages are NOT postponed to the end of either. So the order will be based on the order of the addition to the result. See here.

This difference in outcomes is small when sdk message fails, because either way, the whole tx is reverted, but may be present in cases of contract-queries-to-chain if the sdk message succeeds.