sway icon indicating copy to clipboard operation
sway copied to clipboard

try_read returns invalid value for storage variable of type StorageMap<u64, StorageVec<u64>>

Open pgebal opened this issue 8 months ago • 1 comments

Related Component

compiler

Problem

try_read returns None even if the StorageVec value under given key is properly initialized and non-empty.

When test function is called on the contract below it reverts with try_read bug error.

My expectation is that try_read should return Some(...).

Steps

abi TestAbi {
    #[storage(read, write)]
    fn test(key: u64);
}

storage {
    test_1: StorageMap<u64, StorageVec<u64>> = StorageMap {},
}

impl TestAbi for Contract {

    #[storage(read, write)]
    fn test(key: u64) {
       require(storage.test_1.try_insert(key, StorageVec {}).is_ok(), "try_insert failed"); // initalized
       storage.test_1.get(key).push(1); // vector is non-empty
       require(storage.test_1.get(key).try_read().is_some(), "try_read bug"); // reverts here
    }
}

Possible Solution(s)

No response

Notes

No response

Installed components

fuelup check
latest  - Up to date
testnet - Up to date
fuelup  - Up to date

pgebal avatar Apr 17 '25 10:04 pgebal

Hi @pgebal I'm a new contributor and would love to handle this issue , I'm a full stack web developer thanks My contact info: *telegram: kellmusk ETA:2-3hrs

kelly-musk avatar Apr 20 '25 17:04 kelly-musk