HydraChain/hydrachain

Scalar TypedStorage misusage

RomanZacharia opened this issue · 3 comments

The Scalar data type in the Native Contracts' TypedStorage is being used incorrectly.
When the assignment operator is being used on the Scalar data type, the Scalar instance is being replaced by the actual integer/string value since there is no way to override the assignment operator in Python. This results in the value not being saved into the storage and remains only in the memory variable.
For example:
https://github.com/HydraChain/hydrachain/blob/develop/hydrachain/tests/test_native_contracts.py#L739
https://github.com/HydraChain/hydrachain/blob/develop/hydrachain/examples/native/fungible/fungible_contract.py#L46
Either the assignment operator should be emulated by getattr/setattr methods in NativeContract and TypedStorage classes or the usage should be replaced with calling the setter method instead of the assignment operator.

You are right, this hook does work. I didn't notice that because I replaced the contract storage with the regular dict to simplify the testing and perform whitebox tests.
However this works only for the Scalars that are not nested. The same hook should be added to the TypedStorage to handle the nested Scalars.

Implemented nested Scalars.