github.com/stafiprotocol/go-substrate-rpc-client@v1.4.7/types/metadataV8_test.go (about)

     1  // Go Substrate RPC Client (GSRPC) provides APIs and types around Polkadot and any Substrate-based chain RPC calls
     2  //
     3  // Copyright 2020 Stafi Protocol
     4  //
     5  // Licensed under the Apache License, Version 2.0 (the "License");
     6  // you may not use this file except in compliance with the License.
     7  // You may obtain a copy of the License at
     8  //
     9  //     http://www.apache.org/licenses/LICENSE-2.0
    10  //
    11  // Unless required by applicable law or agreed to in writing, software
    12  // distributed under the License is distributed on an "AS IS" BASIS,
    13  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    14  // See the License for the specific language governing permissions and
    15  // limitations under the License.
    16  
    17  package types_test
    18  
    19  import (
    20  	"testing"
    21  
    22  	. "github.com/stafiprotocol/go-substrate-rpc-client/types"
    23  	"github.com/stretchr/testify/assert"
    24  )
    25  
    26  var exampleMetadataV8 = Metadata{
    27  	MagicNumber:  0x6174656d,
    28  	Version:      8,
    29  	IsMetadataV8: true,
    30  	AsMetadataV8: exampleRuntimeMetadataV8,
    31  }
    32  
    33  var exampleRuntimeMetadataV8 = MetadataV8{
    34  	Modules: []ModuleMetadataV8{exampleModuleMetadataV8Empty, exampleModuleMetadataV81, exampleModuleMetadataV82},
    35  }
    36  
    37  var exampleModuleMetadataV8Empty = ModuleMetadataV8{
    38  	Name:       "EmptyModule",
    39  	HasStorage: false,
    40  	Storage:    StorageMetadata{},
    41  	HasCalls:   false,
    42  	Calls:      nil,
    43  	HasEvents:  false,
    44  	Events:     nil,
    45  	Constants:  nil,
    46  	Errors:     nil,
    47  }
    48  
    49  var exampleModuleMetadataV81 = ModuleMetadataV8{
    50  	Name:       "Module1",
    51  	HasStorage: true,
    52  	Storage:    exampleStorageMetadata,
    53  	HasCalls:   true,
    54  	Calls:      []FunctionMetadataV4{exampleFunctionMetadataV4},
    55  	HasEvents:  true,
    56  	Events:     []EventMetadataV4{exampleEventMetadataV4},
    57  	Constants:  []ModuleConstantMetadataV6{exampleModuleConstantMetadataV6},
    58  	Errors:     []ErrorMetadataV8{exampleErrorMetadataV8},
    59  }
    60  
    61  var exampleModuleMetadataV82 = ModuleMetadataV8{
    62  	Name:       "Module2",
    63  	HasStorage: true,
    64  	Storage:    exampleStorageMetadata,
    65  	HasCalls:   true,
    66  	Calls:      []FunctionMetadataV4{exampleFunctionMetadataV4},
    67  	HasEvents:  true,
    68  	Events:     []EventMetadataV4{exampleEventMetadataV4},
    69  	Constants:  []ModuleConstantMetadataV6{exampleModuleConstantMetadataV6},
    70  	Errors:     []ErrorMetadataV8{exampleErrorMetadataV8},
    71  }
    72  
    73  var exampleErrorMetadataV8 = ErrorMetadataV8{
    74  	Name:          "My Error",
    75  	Documentation: []Text{"Error", "docs"},
    76  }
    77  
    78  func TestMetadataV8_EncodeDecode(t *testing.T) {
    79  	assertRoundtrip(t, exampleMetadataV8)
    80  }
    81  
    82  func TestFindEventNamesForEventIDV8(t *testing.T) {
    83  	module, event, err := exampleMetadataV8.FindEventNamesForEventID(EventID([2]byte{1, 0}))
    84  
    85  	assert.NoError(t, err)
    86  	assert.Equal(t, exampleModuleMetadataV82.Name, module)
    87  	assert.Equal(t, exampleEventMetadataV4.Name, event)
    88  }
    89  
    90  func TestFindStorageEntryMetadataV8(t *testing.T) {
    91  	_, err := exampleMetadataV8.FindStorageEntryMetadata("myStoragePrefix", "myStorageFunc2")
    92  	assert.NoError(t, err)
    93  }