From c4eb6113a82de29fc76ac3d6a18f34651ede1327 Mon Sep 17 00:00:00 2001 From: Sergio Mena Date: Thu, 11 Aug 2022 17:33:55 +0200 Subject: [PATCH] Remove unused code in internal directory (#9223) --- internal/test/block.go | 92 ----------------------------------- internal/test/doc.go | 6 --- internal/test/factory_test.go | 11 ----- internal/test/genesis.go | 34 ------------- internal/test/tx.go | 11 ----- internal/test/validator.go | 41 ---------------- internal/test/vote.go | 44 ----------------- 7 files changed, 239 deletions(-) delete mode 100644 internal/test/block.go delete mode 100644 internal/test/doc.go delete mode 100644 internal/test/factory_test.go delete mode 100644 internal/test/genesis.go delete mode 100644 internal/test/tx.go delete mode 100644 internal/test/validator.go delete mode 100644 internal/test/vote.go diff --git a/internal/test/block.go b/internal/test/block.go deleted file mode 100644 index 8b2bff5df..000000000 --- a/internal/test/block.go +++ /dev/null @@ -1,92 +0,0 @@ -package factory - -import ( - "testing" - "time" - - "github.com/stretchr/testify/require" - - "github.com/tendermint/tendermint/crypto" - "github.com/tendermint/tendermint/crypto/tmhash" - "github.com/tendermint/tendermint/types" - "github.com/tendermint/tendermint/version" -) - -const ( - DefaultTestChainID = "test-chain" -) - -var ( - DefaultTestTime = time.Date(2020, 1, 1, 0, 0, 0, 0, time.UTC) -) - -func RandomAddress() []byte { - return crypto.CRandBytes(crypto.AddressSize) -} - -func RandomHash() []byte { - return crypto.CRandBytes(tmhash.Size) -} - -func MakeBlockID() types.BlockID { - return MakeBlockIDWithHash(RandomHash()) -} - -func MakeBlockIDWithHash(hash []byte) types.BlockID { - return types.BlockID{ - Hash: hash, - PartSetHeader: types.PartSetHeader{ - Total: 100, - Hash: RandomHash(), - }, - } -} - -// MakeHeader fills the rest of the contents of the header such that it passes -// validate basic -func MakeHeader(t *testing.T, h *types.Header) *types.Header { - t.Helper() - if h.Version.Block == 0 { - h.Version.Block = version.BlockProtocol - } - if h.Height == 0 { - h.Height = 1 - } - if h.LastBlockID.IsZero() { - h.LastBlockID = MakeBlockID() - } - if h.ChainID == "" { - h.ChainID = DefaultTestChainID - } - if len(h.LastCommitHash) == 0 { - h.LastCommitHash = RandomHash() - } - if len(h.DataHash) == 0 { - h.DataHash = RandomHash() - } - if len(h.ValidatorsHash) == 0 { - h.ValidatorsHash = RandomHash() - } - if len(h.NextValidatorsHash) == 0 { - h.NextValidatorsHash = RandomHash() - } - if len(h.ConsensusHash) == 0 { - h.ConsensusHash = RandomHash() - } - if len(h.AppHash) == 0 { - h.AppHash = RandomHash() - } - if len(h.LastResultsHash) == 0 { - h.LastResultsHash = RandomHash() - } - if len(h.EvidenceHash) == 0 { - h.EvidenceHash = RandomHash() - } - if len(h.ProposerAddress) == 0 { - h.ProposerAddress = RandomAddress() - } - - require.NoError(t, h.ValidateBasic()) - - return h -} diff --git a/internal/test/doc.go b/internal/test/doc.go deleted file mode 100644 index 5b6b313f6..000000000 --- a/internal/test/doc.go +++ /dev/null @@ -1,6 +0,0 @@ -/* -Package factory provides generation code for common structs in Tendermint. -It is used primarily for the testing of internal components such as statesync, -consensus, blocksync etc.. -*/ -package factory diff --git a/internal/test/factory_test.go b/internal/test/factory_test.go deleted file mode 100644 index 9ef520ff6..000000000 --- a/internal/test/factory_test.go +++ /dev/null @@ -1,11 +0,0 @@ -package factory - -import ( - "testing" - - "github.com/tendermint/tendermint/types" -) - -func TestMakeHeader(t *testing.T) { - MakeHeader(t, &types.Header{}) -} diff --git a/internal/test/genesis.go b/internal/test/genesis.go deleted file mode 100644 index a385e51fc..000000000 --- a/internal/test/genesis.go +++ /dev/null @@ -1,34 +0,0 @@ -package factory - -import ( - "time" - - cfg "github.com/tendermint/tendermint/config" - tmproto "github.com/tendermint/tendermint/proto/tendermint/types" - "github.com/tendermint/tendermint/types" -) - -func GenesisDoc( - config *cfg.Config, - time time.Time, - validators []*types.Validator, - consensusParams *tmproto.ConsensusParams, -) *types.GenesisDoc { - - genesisValidators := make([]types.GenesisValidator, len(validators)) - - for i := range validators { - genesisValidators[i] = types.GenesisValidator{ - Power: validators[i].VotingPower, - PubKey: validators[i].PubKey, - } - } - - return &types.GenesisDoc{ - GenesisTime: time, - InitialHeight: 1, - ChainID: config.ChainID(), - Validators: genesisValidators, - ConsensusParams: consensusParams, - } -} diff --git a/internal/test/tx.go b/internal/test/tx.go deleted file mode 100644 index 725f3c720..000000000 --- a/internal/test/tx.go +++ /dev/null @@ -1,11 +0,0 @@ -package factory - -import "github.com/tendermint/tendermint/types" - -func MakeNTxs(height, n int64) []types.Tx { - txs := make([]types.Tx, n) - for i := range txs { - txs[i] = types.Tx([]byte{byte(height), byte(i / 256), byte(i % 256)}) - } - return txs -} diff --git a/internal/test/validator.go b/internal/test/validator.go deleted file mode 100644 index 71d35cede..000000000 --- a/internal/test/validator.go +++ /dev/null @@ -1,41 +0,0 @@ -package factory - -import ( - "context" - "sort" - "testing" - - "github.com/stretchr/testify/require" - - "github.com/tendermint/tendermint/types" -) - -func Validator(ctx context.Context, votingPower int64) (*types.Validator, types.PrivValidator, error) { - privVal := types.NewMockPV() - pubKey, err := privVal.GetPubKey() - if err != nil { - return nil, nil, err - } - - val := types.NewValidator(pubKey, votingPower) - return val, privVal, nil -} - -func ValidatorSet(ctx context.Context, t *testing.T, numValidators int, votingPower int64) (*types.ValidatorSet, []types.PrivValidator) { - var ( - valz = make([]*types.Validator, numValidators) - privValidators = make([]types.PrivValidator, numValidators) - ) - t.Helper() - - for i := 0; i < numValidators; i++ { - val, privValidator, err := Validator(ctx, votingPower) - require.NoError(t, err) - valz[i] = val - privValidators[i] = privValidator - } - - sort.Sort(types.PrivValidatorsByAddress(privValidators)) - - return types.NewValidatorSet(valz), privValidators -} diff --git a/internal/test/vote.go b/internal/test/vote.go deleted file mode 100644 index 1339d5258..000000000 --- a/internal/test/vote.go +++ /dev/null @@ -1,44 +0,0 @@ -package factory - -import ( - "context" - "time" - - tmproto "github.com/tendermint/tendermint/proto/tendermint/types" - "github.com/tendermint/tendermint/types" -) - -func MakeVote( - ctx context.Context, - val types.PrivValidator, - chainID string, - valIndex int32, - height int64, - round int32, - step int, - blockID types.BlockID, - time time.Time, -) (*types.Vote, error) { - pubKey, err := val.GetPubKey() - if err != nil { - return nil, err - } - - v := &types.Vote{ - ValidatorAddress: pubKey.Address(), - ValidatorIndex: valIndex, - Height: height, - Round: round, - Type: tmproto.SignedMsgType(step), - BlockID: blockID, - Timestamp: time, - } - - vpb := v.ToProto() - if err := val.SignVote(chainID, vpb); err != nil { - return nil, err - } - - v.Signature = vpb.Signature - return v, nil -}