github.com/Finschia/ostracon@v1.1.5/types/canonical_test.go (about)

     1  package types
     2  
     3  import (
     4  	"reflect"
     5  	"testing"
     6  
     7  	tmproto "github.com/tendermint/tendermint/proto/tendermint/types"
     8  
     9  	"github.com/Finschia/ostracon/crypto/tmhash"
    10  	tmrand "github.com/Finschia/ostracon/libs/rand"
    11  )
    12  
    13  func TestCanonicalizeBlockID(t *testing.T) {
    14  	randhash := tmrand.Bytes(tmhash.Size)
    15  	block1 := tmproto.BlockID{Hash: randhash,
    16  		PartSetHeader: tmproto.PartSetHeader{Total: 5, Hash: randhash}}
    17  	block2 := tmproto.BlockID{Hash: randhash,
    18  		PartSetHeader: tmproto.PartSetHeader{Total: 10, Hash: randhash}}
    19  	cblock1 := tmproto.CanonicalBlockID{Hash: randhash,
    20  		PartSetHeader: tmproto.CanonicalPartSetHeader{Total: 5, Hash: randhash}}
    21  	cblock2 := tmproto.CanonicalBlockID{Hash: randhash,
    22  		PartSetHeader: tmproto.CanonicalPartSetHeader{Total: 10, Hash: randhash}}
    23  
    24  	tests := []struct {
    25  		name string
    26  		args tmproto.BlockID
    27  		want *tmproto.CanonicalBlockID
    28  	}{
    29  		{"first", block1, &cblock1},
    30  		{"second", block2, &cblock2},
    31  	}
    32  	for _, tt := range tests {
    33  		tt := tt
    34  		t.Run(tt.name, func(t *testing.T) {
    35  			if got := CanonicalizeBlockID(tt.args); !reflect.DeepEqual(got, tt.want) {
    36  				t.Errorf("CanonicalizeBlockID() = %v, want %v", got, tt.want)
    37  			}
    38  		})
    39  	}
    40  }