github.com/iotexproject/iotex-core@v1.14.1-rc1/action/protocol/staking/ethabi/staketotalstakingamount_test.go (about) 1 package ethabi 2 3 import ( 4 "encoding/hex" 5 "reflect" 6 "testing" 7 8 "github.com/iotexproject/iotex-proto/golang/iotexapi" 9 "github.com/iotexproject/iotex-proto/golang/iotextypes" 10 "github.com/stretchr/testify/require" 11 "google.golang.org/protobuf/proto" 12 ) 13 14 func TestBuildReadStateRequestTotalStakingAmount(t *testing.T) { 15 r := require.New(t) 16 17 data, _ := hex.DecodeString("d201114a") 18 req, err := BuildReadStateRequest(data) 19 20 r.Nil(err) 21 r.EqualValues("*ethabi.TotalStakingAmountStateContext", reflect.TypeOf(req).String()) 22 23 method := &iotexapi.ReadStakingDataMethod{ 24 Method: iotexapi.ReadStakingDataMethod_TOTAL_STAKING_AMOUNT, 25 } 26 methodBytes, _ := proto.Marshal(method) 27 r.EqualValues(methodBytes, req.Parameters().MethodName) 28 29 arguments := &iotexapi.ReadStakingDataRequest{ 30 Request: &iotexapi.ReadStakingDataRequest_TotalStakingAmount_{ 31 TotalStakingAmount: &iotexapi.ReadStakingDataRequest_TotalStakingAmount{}, 32 }, 33 } 34 argumentsBytes, _ := proto.Marshal(arguments) 35 r.EqualValues([][]byte{argumentsBytes}, req.Parameters().Arguments) 36 } 37 38 func TestEncodeTotalStakingAmountToEth(t *testing.T) { 39 r := require.New(t) 40 41 meta := &iotextypes.AccountMeta{ 42 Address: "io000000000000000000000000stakingprotocol", 43 Balance: "100000000000000000000", 44 } 45 metaBytes, _ := proto.Marshal(meta) 46 resp := &iotexapi.ReadStateResponse{ 47 Data: metaBytes, 48 } 49 50 ctx := &TotalStakingAmountStateContext{} 51 data, err := ctx.EncodeToEth(resp) 52 r.Nil(err) 53 r.EqualValues("0000000000000000000000000000000000000000000000056bc75e2d63100000", data) 54 }