Closed ailisp closed 3 years ago
@frol I took your answer from stackoverflow to try testing migrate state in a local node, then it seems that txn success but have no effect, then I further realize it's indeed env::write_state/storage_write
has no effect
If a method has &mut self
parameter, then SDK will generate code to read the state before the call and write the state after the call. The latter operation will overwrite whatever you wrote manually. You should probably not add self
parameter to a migration method.
@abacabadabacaba is correct. Indeed, I do need the self parameter as I need to read some state, mutate them in the migration method. I can use env::read
but has a &self
has sdk deserialize it for you is easier. And just make the migration method from &mut self
to &self
and near call
it works.
Feels like there's still at least a documentation problem here tbh.
To do a minimum repro, deploy any contract, for example, I deployed status-message.wasm on a local node. Add a new method:
deploy the new contract, call
migrate
and this txn success. Then call a view methodget_status
, it still success. Further more, if you do:to inspect state before and after the call (by replacing block_id), it shows the same state. So this indicates state_write/storage_write has no effect.
Full step to repro: