@@ -22,7 +22,6 @@ import (
22
22
"testing"
23
23
24
24
"github.com/ChainSafe/chaindb"
25
-
26
25
"github.com/ChainSafe/gossamer/dot/types"
27
26
"github.com/ChainSafe/gossamer/lib/common"
28
27
"github.com/ChainSafe/gossamer/lib/trie"
@@ -70,6 +69,71 @@ func TestChildStateGetKeys(t *testing.T) {
70
69
}
71
70
}
72
71
72
+ func TestChildStateGetStorageSize (t * testing.T ) {
73
+ mod , blockHash := setupChildStateStorage (t )
74
+ invalidHash := common .BytesToHash ([]byte ("invalid block hash" ))
75
+
76
+ tests := []struct {
77
+ expect uint64
78
+ err error
79
+ hash * common.Hash
80
+ keyChild []byte
81
+ entry []byte
82
+ }{
83
+ {
84
+ err : nil ,
85
+ expect : uint64 (len ([]byte (":child_first_value" ))),
86
+ hash : nil ,
87
+ entry : []byte (":child_first" ),
88
+ keyChild : []byte (":child_storage_key" ),
89
+ },
90
+ {
91
+ err : nil ,
92
+ expect : uint64 (len ([]byte (":child_second_value" ))),
93
+ hash : & blockHash ,
94
+ entry : []byte (":child_second" ),
95
+ keyChild : []byte (":child_storage_key" ),
96
+ },
97
+ {
98
+ err : nil ,
99
+ expect : 0 ,
100
+ hash : nil ,
101
+ entry : []byte (":not_found_so_size_0" ),
102
+ keyChild : []byte (":child_storage_key" ),
103
+ },
104
+ {
105
+ err : fmt .Errorf ("child trie does not exist at key %s%s" , trie .ChildStorageKeyPrefix , []byte (":not_exist" )),
106
+ hash : & blockHash ,
107
+ entry : []byte (":child_second" ),
108
+ keyChild : []byte (":not_exist" ),
109
+ },
110
+ {
111
+ err : chaindb .ErrKeyNotFound ,
112
+ hash : & invalidHash ,
113
+ },
114
+ }
115
+
116
+ for _ , test := range tests {
117
+ var req GetChildStorageRequest
118
+ var res uint64
119
+
120
+ req .Hash = test .hash
121
+ req .EntryKey = test .entry
122
+ req .KeyChild = test .keyChild
123
+
124
+ err := mod .GetStorageSize (nil , & req , & res )
125
+
126
+ if test .err != nil {
127
+ require .Error (t , err )
128
+ require .Equal (t , err , test .err )
129
+ } else {
130
+ require .NoError (t , err )
131
+ }
132
+
133
+ require .Equal (t , test .expect , res )
134
+ }
135
+ }
136
+
73
137
func TestGetStorageHash (t * testing.T ) {
74
138
mod , blockHash := setupChildStateStorage (t )
75
139
invalidBlockHash := common .BytesToHash ([]byte ("invalid block hash" ))
0 commit comments