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

     1  package state
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/stafiprotocol/go-substrate-rpc-client/pkg/client"
     7  	"github.com/stafiprotocol/go-substrate-rpc-client/types"
     8  	"github.com/stretchr/testify/assert"
     9  )
    10  
    11  func TestState_GetConstWithMetadataV12(t *testing.T) {
    12  	meta := types.NewMetadataV12()
    13  	types.DecodeFromBytes(types.MustHexDecodeString(types.ExamplaryMetadataV12PolkadotString), meta)
    14  	var cst types.U128
    15  	err := state.GetConstWithMetadata(meta, "Balances", "ExistentialDeposit", &cst)
    16  	assert.NoError(t, err)
    17  	assert.Equal(t, "100000000000000", cst.Int.String())
    18  }
    19  
    20  func TestState_GetConstWithMetadataV11(t *testing.T) {
    21  	meta := types.NewMetadataV11()
    22  	types.DecodeFromBytes(types.MustHexDecodeString(types.ExamplaryMetadataV11SubstrateString), meta)
    23  	//fmt.Printf("%+v\n", meta)
    24  	var cst types.U64
    25  	err := state.GetConstWithMetadata(meta, "Babe", "EpochDuration", &cst)
    26  	assert.NoError(t, err)
    27  	assert.Equal(t, 200, int(cst))
    28  }
    29  
    30  func TestState_GetConstWithMetadataV10(t *testing.T) {
    31  	meta := types.NewMetadataV11()
    32  	types.DecodeFromBytes(types.MustHexDecodeString(types.ExamplaryMetadataV10PolkadotString), meta)
    33  	var cst types.U64
    34  	err := state.GetConstWithMetadata(meta, "Babe", "EpochDuration", &cst)
    35  	assert.NoError(t, err)
    36  	assert.Equal(t, 600, int(cst))
    37  }
    38  
    39  func TestState_GetConst(t *testing.T) {
    40  	cl, err := client.Connect("ws://127.0.0.1:9944")
    41  	assert.NoError(t, err)
    42  
    43  	var cst types.U64
    44  	s := NewState(cl)
    45  	err = s.GetConst("Babe", "EpochDuration", &cst)
    46  	assert.NoError(t, err)
    47  	assert.Equal(t, 600, int(cst))
    48  }