MCPcopy
hub / github.com/canopy-network/canopy / TestDoublyNestedTxn

Function TestDoublyNestedTxn

store/store_test.go:83–128  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

81}
82
83func TestDoublyNestedTxn(t *testing.T) {
84 store, _, cleanup := testStore(t)
85 defer cleanup()
86 // set initial value to the store
87 baseKey := lib.JoinLenPrefix([]byte("base"))
88 nestedKey := lib.JoinLenPrefix([]byte("nested"))
89 doublyNestedKey := lib.JoinLenPrefix([]byte("doublyNested"))
90 store.Set(baseKey, baseKey)
91 // create a nested transaction
92 nested := store.NewTxn()
93 // set nested value
94 nested.Set(nestedKey, nestedKey)
95 // retrieve parent key
96 value, err := nested.Get(baseKey)
97 require.NoError(t, err)
98 require.Equal(t, baseKey, value)
99 // create a doubly nested transaction
100 doublyNested := nested.NewTxn()
101 // set doubly nested value
102 doublyNested.Set(doublyNestedKey, doublyNestedKey)
103 // commit doubly nested transaction
104 err = doublyNested.Flush()
105 // retrieve grandparent key
106 value, err = doublyNested.Get(baseKey)
107 require.NoError(t, err)
108 require.Equal(t, baseKey, value)
109 require.NoError(t, err)
110 // verify value can be retrieved from nested the store but
111 // not from the store itself
112 value, err = nested.Get(doublyNestedKey)
113 require.NoError(t, err)
114 require.Equal(t, doublyNestedKey, value)
115 value, err = store.Get(doublyNestedKey)
116 require.NoError(t, err)
117 require.Nil(t, value)
118 // commit nested transaction
119 err = nested.Flush()
120 require.NoError(t, err)
121 // verify both nested and doubly nested values can be retrieved from the store
122 value, err = store.Get(nestedKey)
123 require.NoError(t, err)
124 require.Equal(t, nestedKey, value)
125 value, err = store.Get(doublyNestedKey)
126 require.NoError(t, err)
127 require.Equal(t, doublyNestedKey, value)
128}
129
130func testStore(t *testing.T) (*Store, *pebble.DB, func()) {
131 fs := vfs.NewMem()

Callers

nothing calls this directly

Calls 9

SetMethod · 0.95
GetMethod · 0.95
JoinLenPrefixFunction · 0.92
testStoreFunction · 0.85
EqualMethod · 0.80
SetMethod · 0.65
NewTxnMethod · 0.65
FlushMethod · 0.65
GetMethod · 0.65

Tested by

no test coverage detected