github.com/iotexproject/iotex-core@v1.14.1-rc1/action/putpollresult_test.go (about)

     1  // Copyright (c) 2019 IoTeX Foundation
     2  // This source code is provided 'as is' and no warranties are given as to title or non-infringement, merchantability
     3  // or fitness for purpose and, to the extent permitted by law, all liability for your use of the code is disclaimed.
     4  // This source code is governed by Apache License 2.0 that can be found in the LICENSE file.
     5  
     6  package action
     7  
     8  import (
     9  	"math/big"
    10  	"testing"
    11  
    12  	"github.com/stretchr/testify/assert"
    13  
    14  	"github.com/iotexproject/iotex-core/state"
    15  	"github.com/iotexproject/iotex-core/test/identityset"
    16  )
    17  
    18  func TestPutPollResult(t *testing.T) {
    19  	candidates := state.CandidateList{}
    20  	pk := identityset.PrivateKey(32).PublicKey()
    21  	addr := pk.Address()
    22  	assert.NotNil(t, addr)
    23  	candidates = append(candidates, &state.Candidate{
    24  		Address: addr.String(),
    25  		Votes:   big.NewInt(1000),
    26  	})
    27  	r := NewPutPollResult(1, 10001, candidates)
    28  	assert.Equal(t, uint64(1), r.Nonce())
    29  	igas, err := r.IntrinsicGas()
    30  	assert.NoError(t, err)
    31  	assert.Equal(t, uint64(0), igas)
    32  	cost, err := r.Cost()
    33  	assert.NoError(t, err)
    34  	assert.Equal(t, 0, big.NewInt(0).Cmp(cost))
    35  	pb := r.Proto()
    36  	assert.NotNil(t, pb)
    37  	clone := &PutPollResult{}
    38  	assert.NoError(t, clone.LoadProto(pb))
    39  	assert.Equal(t, uint64(10001), clone.Height())
    40  
    41  }