github.com/Finschia/ostracon@v1.1.5/state/export_test.go (about)

     1  package state
     2  
     3  import (
     4  	abci "github.com/tendermint/tendermint/abci/types"
     5  	tmstate "github.com/tendermint/tendermint/proto/tendermint/state"
     6  	tmproto "github.com/tendermint/tendermint/proto/tendermint/types"
     7  	dbm "github.com/tendermint/tm-db"
     8  
     9  	"github.com/Finschia/ostracon/types"
    10  )
    11  
    12  //
    13  // TODO: Remove dependence on all entities exported from this file.
    14  //
    15  // Every entity exported here is dependent on a private entity from the `state`
    16  // package. Currently, these functions are only made available to tests in the
    17  // `state_test` package, but we should not be relying on them for our testing.
    18  // Instead, we should be exclusively relying on exported entities for our
    19  // testing, and should be refactoring exported entities to make them more
    20  // easily testable from outside of the package.
    21  //
    22  
    23  const ValSetCheckpointInterval = valSetCheckpointInterval
    24  
    25  // UpdateState is an alias for updateState exported from execution.go,
    26  // exclusively and explicitly for testing.
    27  func UpdateState(
    28  	state State,
    29  	blockID types.BlockID,
    30  	header *types.Header,
    31  	entropy *types.Entropy,
    32  	abciResponses *tmstate.ABCIResponses,
    33  	validatorUpdates []*types.Validator,
    34  ) (State, error) {
    35  	return updateState(state, blockID, header, entropy, abciResponses, validatorUpdates)
    36  }
    37  
    38  // ValidateValidatorUpdates is an alias for validateValidatorUpdates exported
    39  // from execution.go, exclusively and explicitly for testing.
    40  func ValidateValidatorUpdates(abciUpdates []abci.ValidatorUpdate, params tmproto.ValidatorParams) error {
    41  	return validateValidatorUpdates(abciUpdates, params)
    42  }
    43  
    44  // SaveValidatorsInfo is an alias for the private saveValidatorsInfo method in
    45  // store.go, exported exclusively and explicitly for testing.
    46  func SaveValidatorsInfo(
    47  	db dbm.DB,
    48  	height, lastHeightChanged int64,
    49  	proofHash []byte,
    50  	valSet *types.ValidatorSet,
    51  ) error {
    52  	stateStore := dbStore{db, StoreOptions{DiscardABCIResponses: false}}
    53  	if err := db.Set(calcProofHashKey(height-1), proofHash); err != nil {
    54  		return err
    55  	}
    56  	return stateStore.saveValidatorsInfo(height, lastHeightChanged, valSet)
    57  }
    58  
    59  func SaveProofHash(db dbm.DB, height int64, proofHash []byte) error {
    60  	stateStore := dbStore{db, StoreOptions{DiscardABCIResponses: false}}
    61  	return stateStore.saveProofHash(height, proofHash)
    62  }