github.com/iotexproject/iotex-core@v1.14.1-rc1/action/protocol/staking/ethabi/stake_composite_bucketsbycandidate_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 TestBuildReadStateRequestCompositeBucketsByCandidate(t *testing.T) {
    14  	r := require.New(t)
    15  
    16  	// data, err := _compositeBucketsByCandidateMethod.Inputs.Pack("hello", uint32(0), uint32(1))
    17  	// r.NoError(err)
    18  	// data = append(_compositeBucketsByCandidateMethod.ID, data...)
    19  	// t.Logf("data: %s", hex.EncodeToString(data))
    20  
    21  	data, _ := hex.DecodeString("33df73c7000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000568656c6c6f000000000000000000000000000000000000000000000000000000")
    22  	req, err := BuildReadStateRequest(data)
    23  
    24  	r.Nil(err)
    25  	r.EqualValues("*ethabi.CompositeBucketsByCandidateStateContext", reflect.TypeOf(req).String())
    26  
    27  	method := &iotexapi.ReadStakingDataMethod{
    28  		Method: iotexapi.ReadStakingDataMethod_COMPOSITE_BUCKETS_BY_CANDIDATE,
    29  	}
    30  	methodBytes, _ := proto.Marshal(method)
    31  	r.EqualValues(methodBytes, req.Parameters().MethodName)
    32  
    33  	arguments := &iotexapi.ReadStakingDataRequest{
    34  		Request: &iotexapi.ReadStakingDataRequest_BucketsByCandidate{
    35  			BucketsByCandidate: &iotexapi.ReadStakingDataRequest_VoteBucketsByCandidate{
    36  				CandName: "hello",
    37  				Pagination: &iotexapi.PaginationParam{
    38  					Offset: 0,
    39  					Limit:  1,
    40  				},
    41  			},
    42  		},
    43  	}
    44  	argumentsBytes, _ := proto.Marshal(arguments)
    45  	r.EqualValues([][]byte{argumentsBytes}, req.Parameters().Arguments)
    46  }