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

Function TestSet

store/smt_test.go:66–567  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

64}
65
66func TestSet(t *testing.T) {
67 tests := []struct {
68 name string
69 detail string
70 keyBitSize int
71 preset *NodeList
72 expected *NodeList
73 rootKey []byte
74 targetKey []byte
75 targetValue []byte
76 }{
77 {
78 name: "insert and target at 1110",
79 detail: `BEFORE root
80 / \
81 0000 1111
82
83 AFTER root
84 / \
85 0000 111
86 / \
87 *1110* 1111
88 `,
89 keyBitSize: 4,
90 rootKey: []byte{0b10010000}, // arbitrary
91 targetKey: []byte{5}, // hashes to [1110]
92 targetValue: []byte("some_value"),
93 preset: &NodeList{
94 Nodes: []*node{
95 newTestNode("1100", nil, "0000", "1111"), // root
96 newTestNode("0000", nil, "", ""), // leaf
97 newTestNode("1111", nil, "", ""), // leaf
98 },
99 },
100 expected: &NodeList{
101 Nodes: []*node{
102 newTestNode("0000", nil, "", ""), // leaf
103 newTestNode("111", nil, "1110", "1111"),
104 newTestNode( // root
105 "1100",
106 func() []byte {
107 // grandchildren
108 input1110 := append(keyBytesFromStr("1110"), crypto.Hash([]byte("some_value"))...)
109 input1111 := append(keyBytesFromStr("1111"), []byte{}...)
110 // children
111 input0000 := append(keyBytesFromStr("0000"), []byte{}...)
112 input111 := append(keyBytesFromStr("111"), crypto.Hash(append(input1110, input1111...))...)
113 // root
114 return crypto.Hash(append(input0000, input111...))
115 }(),
116 "0000", "111"),
117 newTestNode("1110", []byte("some_value"), "", ""), // new leaf
118 newTestNode("1111", nil, "", ""), // leaf
119 },
120 },
121 },
122 {
123 name: "insert and target at 011",

Callers

nothing calls this directly

Calls 15

HashFunction · 0.92
MemHashFunction · 0.92
UnmarshalFunction · 0.92
newTestNodeFunction · 0.85
keyBytesFromStrFunction · 0.85
NewTestSMTFunction · 0.85
newNodeFunction · 0.85
RunMethod · 0.80
fromBytesMethod · 0.80
EqualMethod · 0.80
CloseMethod · 0.65
CommitMethod · 0.65

Tested by

no test coverage detected