github.com/iotexproject/iotex-core@v1.14.1-rc1/action/protocol/staking/ethabi/stakebucketsbyvoter_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 TestBuildReadStateRequestBucketsByVoter(t *testing.T) {
    14  	r := require.New(t)
    15  
    16  	data, _ := hex.DecodeString("4a0c59f9000000000000000000000000000000000000000000000000000000000000006400000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000002")
    17  	req, err := BuildReadStateRequest(data)
    18  
    19  	r.Nil(err)
    20  	r.EqualValues("*ethabi.BucketsByVoterStateContext", reflect.TypeOf(req).String())
    21  
    22  	method := &iotexapi.ReadStakingDataMethod{
    23  		Method: iotexapi.ReadStakingDataMethod_BUCKETS_BY_VOTER,
    24  	}
    25  	methodBytes, _ := proto.Marshal(method)
    26  	r.EqualValues(methodBytes, req.Parameters().MethodName)
    27  
    28  	arguments := &iotexapi.ReadStakingDataRequest{
    29  		Request: &iotexapi.ReadStakingDataRequest_BucketsByVoter{
    30  			BucketsByVoter: &iotexapi.ReadStakingDataRequest_VoteBucketsByVoter{
    31  				VoterAddress: "io1qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqryn4k9fw",
    32  				Pagination: &iotexapi.PaginationParam{
    33  					Offset: 1,
    34  					Limit:  2,
    35  				},
    36  			},
    37  		},
    38  	}
    39  	argumentsBytes, _ := proto.Marshal(arguments)
    40  	r.EqualValues([][]byte{argumentsBytes}, req.Parameters().Arguments)
    41  }