github.com/iotexproject/iotex-core@v1.14.1-rc1/action/protocol/staking/ethabi/stake_composite_bucketscount_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 TestBuildReadStateRequestCompositeBucketsCount(t *testing.T) { 15 r := require.New(t) 16 17 data, _ := hex.DecodeString("a40d6b8c") 18 req, err := BuildReadStateRequest(data) 19 20 r.Nil(err) 21 r.EqualValues("*ethabi.CompositeBucketsCountStateContext", reflect.TypeOf(req).String()) 22 23 method := &iotexapi.ReadStakingDataMethod{ 24 Method: iotexapi.ReadStakingDataMethod_COMPOSITE_BUCKETS_COUNT, 25 } 26 methodBytes, _ := proto.Marshal(method) 27 r.EqualValues(methodBytes, req.Parameters().MethodName) 28 29 arguments := &iotexapi.ReadStakingDataRequest{ 30 Request: &iotexapi.ReadStakingDataRequest_BucketsCount_{ 31 BucketsCount: &iotexapi.ReadStakingDataRequest_BucketsCount{}, 32 }, 33 } 34 argumentsBytes, _ := proto.Marshal(arguments) 35 r.EqualValues([][]byte{argumentsBytes}, req.Parameters().Arguments) 36 } 37 38 func TestEncodeCompositeBucketsCountToEth(t *testing.T) { 39 r := require.New(t) 40 41 count := &iotextypes.BucketsCount{ 42 Total: 5, 43 Active: 2, 44 } 45 countBytes, _ := proto.Marshal(count) 46 resp := &iotexapi.ReadStateResponse{ 47 Data: countBytes, 48 } 49 50 ctx := &CompositeBucketsCountStateContext{} 51 data, err := ctx.EncodeToEth(resp) 52 r.Nil(err) 53 r.EqualValues("00000000000000000000000000000000000000000000000000000000000000050000000000000000000000000000000000000000000000000000000000000002", data) 54 }