github.com/evdatsion/aphelion-dpos-bft@v0.32.1/consensus/types/round_state_test.go (about)

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