github.com/iotexproject/iotex-core@v1.14.1-rc1/db/trie/mptrie/twolayertrie_test.go (about) 1 // Copyright (c) 2020 IoTeX Foundation 2 // This source code is provided 'as is' and no warranties are given as to title or non-infringement, merchantability 3 // or fitness for purpose and, to the extent permitted by law, all liability for your use of the code is disclaimed. 4 // This source code is governed by Apache License 2.0 that can be found in the LICENSE file. 5 6 package mptrie 7 8 import ( 9 "context" 10 "testing" 11 12 "github.com/stretchr/testify/require" 13 14 "github.com/iotexproject/iotex-core/db/trie" 15 ) 16 17 func TestTwoLayerTrie(t *testing.T) { 18 tlt := NewTwoLayerTrie(trie.NewMemKVStore(), "rootKey") 19 require.NoError(t, tlt.Start(context.Background())) 20 defer require.NoError(t, tlt.Stop(context.Background())) 21 _, err := tlt.Get([]byte("layerOneKey111111111"), []byte("layerTwoKey1")) 22 require.Error(t, err) 23 require.Error(t, tlt.Delete([]byte("layerOneKey111111111"), []byte("layerTwoKey1"))) 24 require.NoError(t, tlt.Upsert([]byte("layerOneKey111111111"), []byte("layerTwoKey1"), []byte("value"))) 25 _, err = tlt.Get([]byte("layerOneKey111111111"), []byte("layerTwoKey2")) 26 require.Error(t, err) 27 value, err := tlt.Get([]byte("layerOneKey111111111"), []byte("layerTwoKey1")) 28 require.NoError(t, err) 29 require.Equal(t, []byte("value"), value) 30 require.Error(t, tlt.Delete([]byte("layerOneKey111111111"), []byte("layerTwoKey2"))) 31 require.NoError(t, tlt.Delete([]byte("layerOneKey111111111"), []byte("layerTwoKey1"))) 32 _, err = tlt.Get([]byte("layerOneKey111111111"), []byte("layerTwoKey1")) 33 require.Error(t, err) 34 }