@@ -37,7 +37,6 @@ func TestMain(m *testing.M) {
3737
3838 cl , err := client .Connect (s .URL )
3939 // cl, err := client.Connect(config.NewDefaultConfig().RPCURL)
40- // cl, err := client.Connect("ws://35.246.140.178:9944")
4140 if err != nil {
4241 panic (err )
4342 }
@@ -48,14 +47,20 @@ func TestMain(m *testing.M) {
4847
4948// MockSrv holds data and methods exposed by the RPC Mock Server used in integration tests
5049type MockSrv struct {
51- blockHashLatest types.Hash
52- metadataString string
53- metadata * types.Metadata
54- runtimeVersion types.RuntimeVersion
55- storageKeyHex string
56- storageDataHex string
57- storageSize types.U64
58- storageHashHex string
50+ blockHashLatest types.Hash
51+ metadataString string
52+ metadata * types.Metadata
53+ runtimeVersion types.RuntimeVersion
54+ storageKeyHex string
55+ storageDataHex string
56+ storageSize types.U64
57+ storageHashHex string
58+ childStorageKeyHex string // the key pointing to the child storage trie
59+ childStorageTrieKeyHex string // a key within the child storage trie
60+ childStorageTrieValueHex string // a value stored int he child storage trie
61+ childStorageTrieValue ChildStorageTrieTestVal
62+ childStorageTrieSize types.U64
63+ childStorageTrieHashHex string
5964}
6065
6166func (s * MockSrv ) GetMetadata (hash * string ) string {
@@ -88,16 +93,72 @@ func (s *MockSrv) GetStorageHash(key string, hash *string) string {
8893 return mockSrv .storageHashHex
8994}
9095
96+ func (s * MockSrv ) GetChildKeys (childStorageKey , prefix string , hash * string ) []string {
97+ if childStorageKey != mockSrv .childStorageKeyHex {
98+ panic ("childStorageKey not found" )
99+ }
100+ if ! strings .HasPrefix (mockSrv .childStorageTrieKeyHex , prefix ) {
101+ panic ("no keys for prefix found" )
102+ }
103+ return []string {mockSrv .childStorageTrieKeyHex }
104+ }
105+
106+ func (s * MockSrv ) GetChildStorage (childStorageKey , key string , hash * string ) string {
107+ if childStorageKey != mockSrv .childStorageKeyHex {
108+ panic ("childStorageKey not found" )
109+ }
110+ if key != mockSrv .childStorageTrieKeyHex {
111+ panic ("key not found" )
112+ }
113+ return mockSrv .childStorageTrieValueHex
114+ }
115+
116+ func (s * MockSrv ) GetChildStorageSize (childStorageKey , key string , hash * string ) types.U64 {
117+ if childStorageKey != mockSrv .childStorageKeyHex {
118+ panic ("childStorageKey not found" )
119+ }
120+ if key != mockSrv .childStorageTrieKeyHex {
121+ panic ("key not found" )
122+ }
123+ return mockSrv .childStorageTrieSize
124+ }
125+
126+ func (s * MockSrv ) GetChildStorageHash (childStorageKey , key string , hash * string ) string {
127+ if childStorageKey != mockSrv .childStorageKeyHex {
128+ panic ("childStorageKey not found" )
129+ }
130+ if key != mockSrv .childStorageTrieKeyHex {
131+ panic ("key not found" )
132+ }
133+ return mockSrv .childStorageTrieHashHex
134+ }
135+
136+ type ChildStorageTrieTestVal struct {
137+ Key types.Hash
138+ OtherID types.Hash
139+ Value types.U32
140+ }
141+
91142// mockSrv sets default data used in tests. This data might become stale when substrate is updated – just run the tests
92143// against real servers and update the values stored here. To do that, replace s.URL with
93144// config.NewDefaultConfig().RPCURL
94145var mockSrv = MockSrv {
95- blockHashLatest : types.Hash {1 , 2 , 3 },
96- metadata : types .ExamplaryMetadataV4 ,
97- metadataString : types .ExamplaryMetadataV4String ,
98- runtimeVersion : types.RuntimeVersion {APIs : []types.RuntimeVersionAPI {{APIID : "0xdf6acb689907609b" , Version : 0x2 }, {APIID : "0x37e397fc7c91f5e4" , Version : 0x1 }, {APIID : "0x40fe3ad401f8959a" , Version : 0x3 }, {APIID : "0xd2bc9897eed08f15" , Version : 0x1 }, {APIID : "0xf78b278be53f454c" , Version : 0x1 }, {APIID : "0xed99c5acb25eedf5" , Version : 0x2 }, {APIID : "0xdd718d5cc53262d4" , Version : 0x1 }, {APIID : "0x7801759919ee83e5" , Version : 0x1 }}, AuthoringVersion : 0xa , ImplName : "substrate-node" , ImplVersion : 0x3e , SpecName : "node" , SpecVersion : 0x3c }, //nolint:lll
99- storageKeyHex : "0x0e4944cfd98d6f4cc374d16f5a4e3f9c" ,
100- storageDataHex : "0xb82d895d00000000" ,
101- storageSize : 926778 ,
102- storageHashHex : "0xdf0e877ee1cb973b9a566f53707d365b269d7131b55e65b9790994e4e63b95e1" ,
146+ blockHashLatest : types.Hash {1 , 2 , 3 },
147+ metadata : types .ExamplaryMetadataV4 ,
148+ metadataString : types .ExamplaryMetadataV4String ,
149+ runtimeVersion : types.RuntimeVersion {APIs : []types.RuntimeVersionAPI {{APIID : "0xdf6acb689907609b" , Version : 0x2 }, {APIID : "0x37e397fc7c91f5e4" , Version : 0x1 }, {APIID : "0x40fe3ad401f8959a" , Version : 0x3 }, {APIID : "0xd2bc9897eed08f15" , Version : 0x1 }, {APIID : "0xf78b278be53f454c" , Version : 0x1 }, {APIID : "0xed99c5acb25eedf5" , Version : 0x2 }, {APIID : "0xdd718d5cc53262d4" , Version : 0x1 }, {APIID : "0x7801759919ee83e5" , Version : 0x1 }}, AuthoringVersion : 0xa , ImplName : "substrate-node" , ImplVersion : 0x3e , SpecName : "node" , SpecVersion : 0x3c }, //nolint:lll
150+ storageKeyHex : "0x0e4944cfd98d6f4cc374d16f5a4e3f9c" ,
151+ storageDataHex : "0xb82d895d00000000" ,
152+ storageSize : 926778 ,
153+ storageHashHex : "0xdf0e877ee1cb973b9a566f53707d365b269d7131b55e65b9790994e4e63b95e1" ,
154+ childStorageKeyHex : "0x3a6368696c645f73746f726167653a64656661756c743a05470000" , //nolint:lll beginning with hex encoded `:child_storage:` as per https://github.com/paritytech/substrate/blob/master/core/primitives/storage/src/lib.rs#L71
155+ childStorageTrieKeyHex : "0x81914b11321c39f8728981888024196b616142cc0369234775b20b539aaf29d0" ,
156+ childStorageTrieValueHex : "0x81914b11321c39f8728981888024196b616142cc0369234775b20b539aaf29d09c1705d98d059a2d7f5faa89277ee5d0a38cc455f8b5fdf38fda471e988cb8a921000000" , //nolint:lll
157+ childStorageTrieValue : ChildStorageTrieTestVal {
158+ Key : types .NewHash (types .MustHexDecodeString ("0x81914b11321c39f8728981888024196b616142cc0369234775b20b539aaf29d0" )), //nolint:lll
159+ OtherID : types .NewHash (types .MustHexDecodeString ("0x9c1705d98d059a2d7f5faa89277ee5d0a38cc455f8b5fdf38fda471e988cb8a9" )), //nolint:lll
160+ Value : types .NewU32 (0x21 ),
161+ },
162+ childStorageTrieSize : 68 ,
163+ childStorageTrieHashHex : "0x20e3fc48a91087d091c17de08a5c470de53ccdaebd361025b0e5b7c65b9a0d30" , //nolint:lll
103164}
0 commit comments