github.com/iotexproject/iotex-core@v1.14.1-rc1/action/protocol/staking/ethabi/stakebucketsbycandidate_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/stretchr/testify/require" 10 "google.golang.org/protobuf/proto" 11 ) 12 13 func TestBuildReadStateRequestBucketsByCandidate(t *testing.T) { 14 r := require.New(t) 15 16 data, _ := hex.DecodeString("387c001b000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000568656c6c6f000000000000000000000000000000000000000000000000000000") 17 req, err := BuildReadStateRequest(data) 18 19 r.Nil(err) 20 r.EqualValues("*ethabi.BucketsByCandidateStateContext", reflect.TypeOf(req).String()) 21 22 method := &iotexapi.ReadStakingDataMethod{ 23 Method: iotexapi.ReadStakingDataMethod_BUCKETS_BY_CANDIDATE, 24 } 25 methodBytes, _ := proto.Marshal(method) 26 r.EqualValues(methodBytes, req.Parameters().MethodName) 27 28 arguments := &iotexapi.ReadStakingDataRequest{ 29 Request: &iotexapi.ReadStakingDataRequest_BucketsByCandidate{ 30 BucketsByCandidate: &iotexapi.ReadStakingDataRequest_VoteBucketsByCandidate{ 31 CandName: "hello", 32 Pagination: &iotexapi.PaginationParam{ 33 Offset: 0, 34 Limit: 1, 35 }, 36 }, 37 }, 38 } 39 argumentsBytes, _ := proto.Marshal(arguments) 40 r.EqualValues([][]byte{argumentsBytes}, req.Parameters().Arguments) 41 }