github.com/stafiprotocol/go-substrate-rpc-client@v1.4.7/types/metadataV11_test.go (about) 1 package types_test 2 3 import ( 4 "testing" 5 6 . "github.com/stafiprotocol/go-substrate-rpc-client/types" 7 "github.com/stretchr/testify/assert" 8 ) 9 10 var exampleMetadataV11 = Metadata{ 11 MagicNumber: 0x6174656d, 12 Version: 11, 13 IsMetadataV11: true, 14 AsMetadataV11: MetadataV11{MetadataV10: exampleRuntimeMetadataV10}, 15 } 16 17 func TestNewMetadataV11_Decode(t *testing.T) { 18 tests := []struct { 19 name, hexData string 20 }{ 21 { 22 "SubstrateV11", ExamplaryMetadataV11SubstrateString, 23 }, 24 25 { 26 "PolkadotV11", ExamplaryMetadataV11PolkadotString, 27 }, 28 } 29 30 for _, s := range tests { 31 t.Run(s.name, func(t *testing.T) { 32 metadata := NewMetadataV11() 33 err := DecodeFromBytes(MustHexDecodeString(s.hexData), metadata) 34 assert.NoError(t, err) 35 data, err := EncodeToBytes(metadata) 36 assert.NoError(t, err) 37 assert.Equal(t, s.hexData, HexEncodeToString(data)) 38 }) 39 40 } 41 } 42 43 func TestMetadataV11_ExistsModuleMetadata(t *testing.T) { 44 assert.True(t, exampleMetadataV11.ExistsModuleMetadata("EmptyModule")) 45 assert.False(t, exampleMetadataV11.ExistsModuleMetadata("NotExistModule")) 46 }