Crate used:- https://github.com/paritytech/trie

fn test_two_assets_memory_db() {
    let mut memdb = MemoryDB::<BlakeTwo256>::new(&[0u8]);
    let mut root = H256::zero();

    let mut state = TrieDBMutBuilderV1::new(&mut memdb, &mut root).build();

    let key1 = [1u8;3];
    let data1 = [1u8;2];
    state.insert(key1.as_ref(), &data1).unwrap();
        assert_eq!(state.get(key1.as_ref()).unwrap().unwrap(),data1); //PASSING
    let key2 = [2u8;3];
    let data2 = [2u8;2];
    state.insert(key2.as_ref(), &data2).unwrap();
    assert_eq!(state.get(key1.as_ref()).unwrap().unwrap(),data1); //ERROR:- 'tests::test_two_assets_memory_db' panicked at 'called `Option::unwrap()` on a `None` value.

The test case test_two_assets_memory_db fails at the line assert_eq!(state.get(key1.as_ref()).unwrap().unwrap(),data1); when trying to fetch and assert the data associated with key1 after the second insertion operation. It appears that after the insertion of data associated with key2, the data tied to key1 is either removed or not accessible, leading to the Option::unwrap() call on a None value, which is causing the test to panic. The state database should ideally support multiple insertions and retrievals; however, in this instance, it fails to retrieve the value associated with key1 after a new key-value pair (key2, data2) has been inserted, could you please help me with this?


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.