github.com/franono/tendermint@v0.32.2-0.20200527150959-749313264ce9/consensus/types/round_state_test.go (about)

     1  package types
     2  
     3  import (
     4  	"testing"
     5  
     6  	amino "github.com/tendermint/go-amino"
     7  
     8  	"github.com/franono/tendermint/crypto/ed25519"
     9  	"github.com/franono/tendermint/crypto/tmhash"
    10  	tmrand "github.com/franono/tendermint/libs/rand"
    11  	"github.com/franono/tendermint/types"
    12  	tmtime "github.com/franono/tendermint/types/time"
    13  )
    14  
    15  func BenchmarkRoundStateDeepCopy(b *testing.B) {
    16  	b.StopTimer()
    17  
    18  	// Random validators
    19  	nval, ntxs := 100, 100
    20  	vset, _ := types.RandValidatorSet(nval, 1)
    21  	commitSigs := make([]types.CommitSig, nval)
    22  	blockID := types.BlockID{
    23  		Hash: tmrand.Bytes(tmhash.Size),
    24  		PartsHeader: types.PartSetHeader{
    25  			Hash:  tmrand.Bytes(tmhash.Size),
    26  			Total: 1000,
    27  		},
    28  	}
    29  	sig := make([]byte, ed25519.SignatureSize)
    30  	for i := 0; i < nval; i++ {
    31  		commitSigs[i] = (&types.Vote{
    32  			ValidatorAddress: types.Address(tmrand.Bytes(20)),
    33  			Timestamp:        tmtime.Now(),
    34  			BlockID:          blockID,
    35  			Signature:        sig,
    36  		}).CommitSig()
    37  	}
    38  	txs := make([]types.Tx, ntxs)
    39  	for i := 0; i < ntxs; i++ {
    40  		txs[i] = tmrand.Bytes(100)
    41  	}
    42  	// Random block
    43  	block := &types.Block{
    44  		Header: types.Header{
    45  			ChainID:         tmrand.Str(12),
    46  			Time:            tmtime.Now(),
    47  			LastBlockID:     blockID,
    48  			LastCommitHash:  tmrand.Bytes(20),
    49  			DataHash:        tmrand.Bytes(20),
    50  			ValidatorsHash:  tmrand.Bytes(20),
    51  			ConsensusHash:   tmrand.Bytes(20),
    52  			AppHash:         tmrand.Bytes(20),
    53  			LastResultsHash: tmrand.Bytes(20),
    54  			EvidenceHash:    tmrand.Bytes(20),
    55  		},
    56  		Data: types.Data{
    57  			Txs: txs,
    58  		},
    59  		Evidence:   types.EvidenceData{},
    60  		LastCommit: types.NewCommit(1, 0, blockID, commitSigs),
    61  	}
    62  	parts := block.MakePartSet(4096)
    63  	// Random Proposal
    64  	proposal := &types.Proposal{
    65  		Timestamp: tmtime.Now(),
    66  		BlockID:   blockID,
    67  		Signature: sig,
    68  	}
    69  	// Random HeightVoteSet
    70  	// TODO: hvs :=
    71  
    72  	rs := &RoundState{
    73  		StartTime:          tmtime.Now(),
    74  		CommitTime:         tmtime.Now(),
    75  		Validators:         vset,
    76  		Proposal:           proposal,
    77  		ProposalBlock:      block,
    78  		ProposalBlockParts: parts,
    79  		LockedBlock:        block,
    80  		LockedBlockParts:   parts,
    81  		ValidBlock:         block,
    82  		ValidBlockParts:    parts,
    83  		Votes:              nil, // TODO
    84  		LastCommit:         nil, // TODO
    85  		LastValidators:     vset,
    86  	}
    87  	b.StartTimer()
    88  
    89  	for i := 0; i < b.N; i++ {
    90  		amino.DeepCopy(rs)
    91  	}
    92  }