Improve linter setup (#186)

* [linter] Add `musttag`

Enforce field tags in (un)marshaled structs.

* [linter] Add `nestif`

Reports deeply nested if statements.

* [linter] Add `noctx`

Finds sending http request without context.Context.

* [linter] Add `paralleltest`

Paralleltest detects missing usage of t.Parallel() method in your Go
test.

* [linter] Add `tagalign`

Check that struct tags are well aligned.

* [linter] Add `tagliatelle`

Checks the struct tags.

* [linter] Add `whitespace`

Tool for detection of leading and trailing whitespace.

* [paralleltest] Exclude files bc of data race in tests

Signed-off-by: Julian Strobl <jmastr@mailbox.org>
This commit is contained in:
Julian Strobl 2023-11-17 10:56:25 +01:00 committed by GitHub
parent 5470fc668b
commit 5b25d4cefc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
52 changed files with 187 additions and 90 deletions

View File

@ -45,11 +45,15 @@ linters:
- makezero
- mirror
- misspell
- musttag
- nakedret
- nestif
- nilerr
- nilnil
- noctx
- nolintlint
- nosprintfhostport
- paralleltest
- perfsprint
- prealloc
- predeclared
@ -62,6 +66,8 @@ linters:
- sqlclosecheck
- staticcheck
- stylecheck
- tagalign
- tagliatelle
- tenv
- testableexamples
- tparallel
@ -70,10 +76,18 @@ linters:
- unused
- usestdlibvars
- wastedassign
- whitespace
- zerologlint
linters-settings:
nakedret:
max-func-lines: 100
tagalign:
strict: true
tagliatelle:
case:
use-field-name: true
rules:
json: kebab
issues:
exclude-rules:
- path: x/.*/types/message.*\.go
@ -85,3 +99,6 @@ issues:
- path: testutil/nullify/nullify\.go
linters:
- exhaustive
- path: x/.*/keeper/query.*\.go
linters:
- paralleltest

View File

@ -18,17 +18,19 @@ func NewCheckMintAddressDecorator(dk DaoKeeper) CheckMintAddressDecorator {
func (cmad CheckMintAddressDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate bool, next sdk.AnteHandler) (sdk.Context, error) {
for _, msg := range tx.GetMsgs() {
if sdk.MsgTypeURL(msg) == "/planetmintgo.dao.MsgMintToken" {
mintMsg, ok := msg.(*daotypes.MsgMintToken)
if ok {
if mintMsg.Creator != cmad.dk.GetMintAddress(ctx) {
return ctx, errorsmod.Wrapf(daotypes.ErrInvalidMintAddress, "expected: %s; got: %s", cmad.dk.GetMintAddress(ctx), mintMsg.Creator)
}
_, found := cmad.dk.GetMintRequestByHash(ctx, mintMsg.GetMintRequest().GetLiquidTxHash())
if found {
return ctx, errorsmod.Wrapf(daotypes.ErrAlreadyMinted, "liquid tx hash %s has already been minted", mintMsg.GetMintRequest().GetLiquidTxHash())
}
}
if sdk.MsgTypeURL(msg) != "/planetmintgo.dao.MsgMintToken" {
continue
}
mintMsg, ok := msg.(*daotypes.MsgMintToken)
if !ok {
continue
}
if mintMsg.Creator != cmad.dk.GetMintAddress(ctx) {
return ctx, errorsmod.Wrapf(daotypes.ErrInvalidMintAddress, "expected: %s; got: %s", cmad.dk.GetMintAddress(ctx), mintMsg.Creator)
}
_, found := cmad.dk.GetMintRequestByHash(ctx, mintMsg.GetMintRequest().GetLiquidTxHash())
if found {
return ctx, errorsmod.Wrapf(daotypes.ErrAlreadyMinted, "liquid tx hash %s has already been minted", mintMsg.GetMintRequest().GetLiquidTxHash())
}
}

View File

@ -45,25 +45,27 @@ func checkTxFee(ctx sdk.Context, tx sdk.Tx) (sdk.Coins, error) {
feeCoins := feeTx.GetFee()
if ctx.IsCheckTx() {
minGasPrices := ctx.MinGasPrices()
if !minGasPrices.IsZero() {
feeDenoms := feeCoins.Denoms()
if len(feeDenoms) != 1 {
return nil, errorsmod.Wrapf(sdkerrors.ErrInvalidCoins, "fee must be exactly one coin; got: %s", feeDenoms)
}
if !ctx.IsCheckTx() {
return feeCoins, nil
}
minGasPrices := ctx.MinGasPrices()
if minGasPrices.IsZero() {
return feeCoins, nil
}
feeDenoms := feeCoins.Denoms()
if len(feeDenoms) != 1 {
return nil, errorsmod.Wrapf(sdkerrors.ErrInvalidCoins, "fee must be exactly one coin; got: %s", feeDenoms)
}
gasDenom := minGasPrices.GetDenomByIndex(0)
if !sdk.SliceContains[string](feeDenoms, gasDenom) {
return nil, errorsmod.Wrapf(sdkerrors.ErrInvalidCoins, "received wrong fee denom; got: %s required: %s", feeDenoms[0], gasDenom)
}
gasDenom := minGasPrices.GetDenomByIndex(0)
if !sdk.SliceContains[string](feeDenoms, gasDenom) {
return nil, errorsmod.Wrapf(sdkerrors.ErrInvalidCoins, "received wrong fee denom; got: %s required: %s", feeDenoms[0], gasDenom)
}
requiredFees := sdk.Coins{sdk.NewCoin(gasDenom, sdk.OneInt())}
requiredFees := sdk.Coins{sdk.NewCoin(gasDenom, sdk.OneInt())}
if !feeCoins.IsAnyGTE(requiredFees) {
return nil, errorsmod.Wrapf(sdkerrors.ErrInsufficientFee, "insufficient fees; got: %s required: %s", feeCoins, requiredFees)
}
}
if !feeCoins.IsAnyGTE(requiredFees) {
return nil, errorsmod.Wrapf(sdkerrors.ErrInsufficientFee, "insufficient fees; got: %s required: %s", feeCoins, requiredFees)
}
return feeCoins, nil

View File

@ -8,6 +8,7 @@ import (
// TestAccountAddressPrefix makes sure that the account address prefix has a certain value.
func TestAccountAddressPrefix(t *testing.T) {
t.Parallel()
accountAddressPrefix := "plmnt"
assert.Equal(t, AccountAddressPrefix, accountAddressPrefix, "The account address prefix should be 'plmnt'.")
}

View File

@ -131,6 +131,7 @@ func BenchmarkSimulation(b *testing.B) {
}
func TestAppStateDeterminism(t *testing.T) {
t.Parallel()
if !simcli.FlagEnabledValue {
t.Skip("skipping application simulation")
}
@ -219,6 +220,7 @@ func TestAppStateDeterminism(t *testing.T) {
}
func TestAppImportExport(t *testing.T) {
t.Parallel()
config := simcli.NewConfigFromFlags()
config.ChainID = "mars-simapp-import"
@ -373,6 +375,7 @@ func TestAppImportExport(t *testing.T) {
}
func TestAppSimulationAfterImport(t *testing.T) {
t.Parallel()
config := simcli.NewConfigFromFlags()
config.ChainID = "mars-simapp-after-import"

View File

@ -8,6 +8,7 @@ import (
// TestDerivationPath makes sure that purpose and cointype are set to PLMNT (see https://github.com/satoshilabs/slips/blob/master/slip-0044.md)
func TestDerivationPath(t *testing.T) {
t.Parallel()
sdkConfig := initSDKConfig()
purpose := uint32(44)

View File

@ -33,23 +33,23 @@ distribution-epochs = {{ .PlmntConfig.DistributionEpochs }}
// Config defines Planetmint's top level configuration
type Config struct {
AssetRegistryEndpoint string `mapstructure:"asset-registry-endpoint " json:"asset-registry-endpoint "`
TokenDenom string `mapstructure:"token-denom" json:"token-denom"`
StakeDenom string `mapstructure:"stake-denom" json:"stake-denom"`
FeeDenom string `mapstructure:"fee-denom" json:"fee-denom"`
ConfigRootDir string
PoPEpochs int `mapstructure:"pop-epochs" json:"pop-epochs"`
RPCHost string `mapstructure:"rpc-host" json:"rpc-host"`
RPCPort int `mapstructure:"rpc-port" json:"rpc-port"`
RPCUser string `mapstructure:"rpc-user" json:"rpc-user"`
RPCPassword string `mapstructure:"rpc-password" json:"rpc-password"`
IssuanceServiceDir string `mapstructure:"issuance-service-dir" json:"issuance-service-dir"`
ReissuanceAsset string `mapstructure:"reissuance-asset" json:"reissuance-asset"`
ValidatorAddress string `mapstructure:"validator-address" json:"validator-address"`
DistributionAddrInv string `mapstructure:"distribution-address-inv" json:"distribution-address-inv"`
DistributionAddrDAO string `mapstructure:"distribution-address-dao" json:"distribution-address-dao"`
DistributionAddrPoP string `mapstructure:"distribution-address-pop" json:"distribution-address-pop"`
DistributionEpochs int `mapstructure:"distribution-epochs" json:"distribution-epochs"`
AssetRegistryEndpoint string `json:"asset-registry-endpoint" mapstructure:"asset-registry-endpoint"`
TokenDenom string `json:"token-denom" mapstructure:"token-denom"`
StakeDenom string `json:"stake-denom" mapstructure:"stake-denom"`
FeeDenom string `json:"fee-denom" mapstructure:"fee-denom"`
ConfigRootDir string `json:"config-root-dir" mapstructure:"config-root-dir"`
PoPEpochs int `json:"pop-epochs" mapstructure:"pop-epochs"` //nolint: tagliatelle // json(kebab): got 'pop-epochs' want 'po-p-epochs'
RPCHost string `json:"rpc-host" mapstructure:"rpc-host"`
RPCPort int `json:"rpc-port" mapstructure:"rpc-port"`
RPCUser string `json:"rpc-user" mapstructure:"rpc-user"`
RPCPassword string `json:"rpc-password" mapstructure:"rpc-password"`
IssuanceServiceDir string `json:"issuance-service-dir" mapstructure:"issuance-service-dir"`
ReissuanceAsset string `json:"reissuance-asset" mapstructure:"reissuance-asset"`
ValidatorAddress string `json:"validator-address" mapstructure:"validator-address"`
DistributionAddrInv string `json:"distribution-addr-inv" mapstructure:"distribution-addr-inv"`
DistributionAddrDAO string `json:"distribution-addr-dao" mapstructure:"distribution-addr-dao"`
DistributionAddrPoP string `json:"distribution-addr-pop" mapstructure:"distribution-addr-pop"` //nolint: tagliatelle // json(kebab): got 'distribution-addr-pop' want 'distribution-addr-po-p'
DistributionEpochs int `json:"distribution-epochs" mapstructure:"distribution-epochs"`
}
// cosmos-sdk wide global singleton

View File

@ -16,11 +16,11 @@ import (
// Config defines library top level configuration.
type Config struct {
ChainID string `mapstructure:"chain-id" json:"chain-id"`
EncodingConfig params.EncodingConfig `mapstructure:"encoding-config" json:"encoding-config"`
GRPCEndpoint string `mapstructure:"grpc-endpoint" json:"grpc-endpoint"`
GRPCTLSCert string `mapstructure:"grpc-tls-cert" json:"grpc-tls-cert"`
RootDir string `mapstructure:"root-dir" json:"root-dir"`
ChainID string `json:"chain-id" mapstructure:"chain-id"`
EncodingConfig params.EncodingConfig `json:"encoding-config" mapstructure:"encoding-config"`
GRPCEndpoint string `json:"grpc-endpoint" mapstructure:"grpc-endpoint"`
GRPCTLSCert string `json:"grpc-tls-cert" mapstructure:"grpc-tls-cert"` //nolint: tagliatelle // json(kebab): got 'grpc-tls-cert' want 'grpctls-cert'
RootDir string `json:"root-dir" mapstructure:"root-dir"`
}
// lib wide global singleton

View File

@ -26,7 +26,7 @@ type KeyPair struct {
// Result defines a generic way to receive responses from the RPC endpoint.
type Result struct {
Info map[string]interface{} `mapstructure:"info" json:"info"`
Info map[string]interface{} `json:"info" mapstructure:"info"`
}
func init() {

View File

@ -1,13 +1,15 @@
package asset
import (
"github.com/planetmint/planetmint-go/testutil/network"
"testing"
"github.com/planetmint/planetmint-go/testutil/network"
"github.com/stretchr/testify/suite"
)
func TestE2ETestSuite(t *testing.T) {
t.Parallel()
cfg := network.DefaultConfig()
cfg.NumValidators = 1
suite.Run(t, NewE2ETestSuite(cfg))

View File

@ -1,13 +1,15 @@
package dao
import (
"github.com/planetmint/planetmint-go/testutil/network"
"testing"
"github.com/planetmint/planetmint-go/testutil/network"
"github.com/stretchr/testify/suite"
)
func TestE2ETestSuite(t *testing.T) {
t.Parallel()
cfg := network.DefaultConfig()
suite.Run(t, NewE2ETestSuite(cfg))
}

View File

@ -1,13 +1,15 @@
package machine
import (
"github.com/planetmint/planetmint-go/testutil/network"
"testing"
"github.com/planetmint/planetmint-go/testutil/network"
"github.com/stretchr/testify/suite"
)
func TestE2ETestSuite(t *testing.T) {
t.Parallel()
cfg := network.DefaultConfig()
cfg.NumValidators = 1
suite.Run(t, NewE2ETestSuite(cfg))

View File

@ -21,7 +21,7 @@ import (
// GetRequest defines a wrapper around an HTTP GET request with a provided URL.
// An error is returned if the request or reading the body fails.
func GetRequest(url string) ([]byte, error) {
res, err := http.Get(url) //nolint:gosec // only used for testing
res, err := http.Get(url) //nolint:gosec,noctx // only used for testing
if err != nil {
return nil, err
}
@ -40,7 +40,7 @@ func GetRequest(url string) ([]byte, error) {
// PostRequest defines a wrapper around an HTTP POST request with a provided URL and data.
// An error is returned if the request or reading the body fails.
func PostRequest(url, contentType string, data []byte) ([]byte, error) {
res, err := http.Post(url, contentType, bytes.NewBuffer(data)) //nolint:gosec // only used for testing
res, err := http.Post(url, contentType, bytes.NewBuffer(data)) //nolint:gosec,noctx // only used for testing
if err != nil {
return nil, fmt.Errorf("error while sending post request: %w", err)
}

View File

@ -20,8 +20,8 @@ type Key struct {
type KeyFile struct {
Address string `json:"address"`
PubKey Key `json:"pub_key"`
PrivKey Key `json:"priv_key"`
PubKey Key `json:"pub-key"`
PrivKey Key `json:"priv-key"`
}
func GetValidatorCometBFTIdentity(ctx sdk.Context) (string, bool) {

View File

@ -7,18 +7,21 @@ import (
)
func Test2FloatConvertion(t *testing.T) {
t.Parallel()
var expectedValue uint64 = 99869000000
value := RDDLToken2Uint(998.69)
assert.Equal(t, expectedValue, value)
}
func Test2UintConvertion(t *testing.T) {
t.Parallel()
expectedValue := 998.69
value := RDDLToken2Float(99869000000)
assert.Equal(t, expectedValue, value)
}
func TestStringToFloat(t *testing.T) {
t.Parallel()
expectedValue := 998.69
value, err := RDDLTokenStringToFloat("998.69")
assert.Equal(t, expectedValue, value)
@ -26,6 +29,7 @@ func TestStringToFloat(t *testing.T) {
}
func TestStringToUint(t *testing.T) {
t.Parallel()
var expectedValue uint64 = 99869000000
value, err := RDDLTokenStringToUint("998.69")
assert.Equal(t, expectedValue, value)

View File

@ -11,6 +11,7 @@ import (
)
func TestGenesis(t *testing.T) {
t.Parallel()
genesisState := types.GenesisState{
Params: types.DefaultParams(),

View File

@ -29,6 +29,7 @@ func createNAsset(keeper *keeper.Keeper, ctx sdk.Context, n int) []types.MsgNota
}
func TestGetAsset(t *testing.T) {
t.Parallel()
keeper, ctx := keepertest.AssetKeeper(t)
items := createNAsset(keeper, ctx, 10)
for _, item := range items {
@ -38,6 +39,7 @@ func TestGetAsset(t *testing.T) {
}
}
func TestGetCids(t *testing.T) {
t.Parallel()
keeper, ctx := keepertest.AssetKeeper(t)
items := createNAsset(keeper, ctx, 10)
for _, item := range items {
@ -48,6 +50,7 @@ func TestGetCids(t *testing.T) {
}
func TestGetAssetByPubKeys(t *testing.T) {
t.Parallel()
keeper, ctx := keepertest.AssetKeeper(t)
_ = createNAsset(keeper, ctx, 10)
assets, found := keeper.GetCidsByAddress(ctx, "plmnt_address")

View File

@ -23,12 +23,14 @@ func setupMsgServer(t testing.TB) (types.MsgServer, context.Context) {
}
func TestMsgServer(t *testing.T) {
t.Parallel()
ms, ctx := setupMsgServer(t)
require.NotNil(t, ms)
require.NotNil(t, ctx)
}
func TestMsgServerNotarizeAsset(t *testing.T) {
t.Parallel()
extSk, _ := sample.ExtendedKeyPair(config.PlmntNetParams)
xskKey, _ := hdkeychain.NewKeyFromString(extSk)
privKey, _ := xskKey.ECPrivKey()

View File

@ -9,6 +9,7 @@ import (
)
func TestGetParams(t *testing.T) {
t.Parallel()
k, ctx := testkeeper.AssetKeeper(t)
params := types.DefaultParams()

View File

@ -34,7 +34,6 @@ func TestGetNotarizedAssetByAddress(t *testing.T) {
err: status.Error(codes.NotFound, "no CIDs found"),
},
} {
tc := tc
t.Run(tc.desc, func(t *testing.T) {
response, err := keeper.GetCIDsByAddress(wctx, tc.request)
if tc.err != nil {

View File

@ -33,7 +33,6 @@ func TestGetNotarizedAsset(t *testing.T) {
err: status.Error(codes.NotFound, "cid not found"),
},
} {
tc := tc
t.Run(tc.desc, func(t *testing.T) {
response, err := keeper.GetNotarizedAsset(wctx, tc.request)
if tc.err != nil {

View File

@ -10,6 +10,7 @@ import (
)
func TestParamsQuery(t *testing.T) {
t.Parallel()
keeper, ctx := testkeeper.AssetKeeper(t)
wctx := sdk.WrapSDKContext(ctx)
params := types.DefaultParams()

View File

@ -9,6 +9,7 @@ import (
)
func TestGenesisStateValidate(t *testing.T) {
t.Parallel()
tests := []struct {
desc string
genState *types.GenesisState
@ -30,7 +31,9 @@ func TestGenesisStateValidate(t *testing.T) {
// this line is used by starport scaffolding # types/genesis/testcase
}
for _, tc := range tests {
tc := tc
t.Run(tc.desc, func(t *testing.T) {
t.Parallel()
err := tc.genState.Validate()
if tc.valid {
require.NoError(t, err)

View File

@ -10,6 +10,7 @@ import (
)
func TestMsgNotarizeAssetValidateBasic(t *testing.T) {
t.Parallel()
tests := []struct {
name string
msg MsgNotarizeAsset
@ -29,7 +30,9 @@ func TestMsgNotarizeAssetValidateBasic(t *testing.T) {
},
}
for _, tt := range tests {
tt := tt
t.Run(tt.name, func(t *testing.T) {
t.Parallel()
err := tt.msg.ValidateBasic()
if tt.err != nil {
require.ErrorIs(t, err, tt.err)

View File

@ -17,32 +17,31 @@ func BeginBlocker(ctx sdk.Context, req abci.RequestBeginBlock, k keeper.Keeper)
// Check if node is block proposer
// take the following actions only once, that's why we filter for the Block Proposer
if util.IsValidatorBlockProposer(ctx, proposerAddress) {
blockHeight := req.Header.GetHeight()
if isPoPHeight(blockHeight) {
logger.Debug("TODO: implement PoP trigger")
hexProposerAddress := hex.EncodeToString(proposerAddress)
conf := config.GetConfig()
txUnsigned := keeper.GetReissuanceCommand(conf.ReissuanceAsset, blockHeight)
err := util.InitRDDLReissuanceProcess(ctx, hexProposerAddress, txUnsigned, blockHeight)
if err != nil {
logger.Error("error while initializing RDDL issuance", err)
}
}
if isDistributionHeight(blockHeight) {
// initialize the distribution message
distribution, err := k.GetDistributionForReissuedTokens(ctx, blockHeight)
if err != nil {
logger.Error("error while computing the RDDL distribution ", err)
}
err = util.SendRDDLDistributionRequest(ctx, distribution)
if err != nil {
logger.Error("sending the distribution request failed")
}
if !util.IsValidatorBlockProposer(ctx, proposerAddress) {
return
}
blockHeight := req.Header.GetHeight()
if isPoPHeight(blockHeight) {
logger.Debug("TODO: implement PoP trigger")
hexProposerAddress := hex.EncodeToString(proposerAddress)
conf := config.GetConfig()
txUnsigned := keeper.GetReissuanceCommand(conf.ReissuanceAsset, blockHeight)
err := util.InitRDDLReissuanceProcess(ctx, hexProposerAddress, txUnsigned, blockHeight)
if err != nil {
logger.Error("error while initializing RDDL issuance", err)
}
}
if isDistributionHeight(blockHeight) {
// initialize the distribution message
distribution, err := k.GetDistributionForReissuedTokens(ctx, blockHeight)
if err != nil {
logger.Error("error while computing the RDDL distribution ", err)
}
err = util.SendRDDLDistributionRequest(ctx, distribution)
if err != nil {
logger.Error("sending the distribution request failed")
}
}
}
func isPoPHeight(height int64) bool {

View File

@ -17,7 +17,6 @@ func CmdGetReissuances() *cobra.Command {
Short: "Query get_reissuances",
Args: cobra.ExactArgs(0),
RunE: func(cmd *cobra.Command, args []string) (err error) {
clientCtx, err := client.GetClientQueryContext(cmd)
if err != nil {
return err

View File

@ -11,6 +11,7 @@ import (
)
func TestGenesis(t *testing.T) {
t.Parallel()
genesisState := types.GenesisState{
Params: types.DefaultParams(),

View File

@ -27,6 +27,7 @@ func createNChallenge(keeper *keeper.Keeper, ctx sdk.Context, n int) []types.Cha
}
func TestGetChallenge(t *testing.T) {
t.Parallel()
keeper, ctx := keepertest.DaoKeeper(t)
items := createNChallenge(keeper, ctx, 10)
for _, item := range items {

View File

@ -31,6 +31,7 @@ func createNDistributionOrder(keeper *keeper.Keeper, ctx sdk.Context, n int) []t
}
func TestDistributionOrder(t *testing.T) {
t.Parallel()
keeper, ctx := keepertest.DaoKeeper(t)
items := createNDistributionOrder(keeper, ctx, 10)
for _, item := range items {
@ -45,6 +46,7 @@ func TestDistributionOrder(t *testing.T) {
}
func TestTokenDistribution(t *testing.T) {
t.Parallel()
k, ctx := keepertest.DaoKeeper(t)
var reissuanceValue uint64 = 99869000000
reissuances := 1000
@ -78,5 +80,4 @@ func TestTokenDistribution(t *testing.T) {
expSum = reissuanceValue * Amount2ndBatch // add the [0] of the
assert.Equal(t, expSum, sum)
assert.Equal(t, uint64(reissuances), Amount1stBatch+Amount2ndBatch)
}

View File

@ -16,7 +16,6 @@ func (k Keeper) StoreMintRequest(ctx sdk.Context, mintRequest types.MintRequest)
mintRequests.Requests = append(mintRequests.Requests, &mintRequest)
addressAppendValue := k.cdc.MustMarshal(&mintRequests)
addressStore.Set(getMintRequestKeyBytes(mintRequest.Beneficiary), addressAppendValue)
}
func (k Keeper) GetMintRequestsByAddress(ctx sdk.Context, address string) (val types.MintRequests, found bool) {

View File

@ -24,6 +24,7 @@ func createNMintRequests(keeper *keeper.Keeper, ctx sdk.Context, beneficiary str
}
func TestGetMintRequestByHash(t *testing.T) {
t.Parallel()
keeper, ctx := keepertest.DaoKeeper(t)
items := createNMintRequests(keeper, ctx, "beneficiary", 10)
for _, item := range items {
@ -34,6 +35,7 @@ func TestGetMintRequestByHash(t *testing.T) {
}
func TestGetMintRequestByAddress(t *testing.T) {
t.Parallel()
keeper, ctx := keepertest.DaoKeeper(t)
items := createNMintRequests(keeper, ctx, "beneficiary", 10)
mintRequests, found := keeper.GetMintRequestsByAddress(ctx, "beneficiary")

View File

@ -20,12 +20,14 @@ func setupMsgServer(t testing.TB) (types.MsgServer, context.Context) {
}
func TestMsgServer(t *testing.T) {
t.Parallel()
ms, ctx := setupMsgServer(t)
require.NotNil(t, ms)
require.NotNil(t, ctx)
}
func TestMsgServerReportPoPResult(t *testing.T) {
t.Parallel()
initiator := sample.Secp256k1AccAddress()
challenger := sample.Secp256k1AccAddress()
challengee := sample.Secp256k1AccAddress()
@ -94,6 +96,7 @@ func TestMsgServerReportPoPResult(t *testing.T) {
}
}
func TestMsgServerMintToken(t *testing.T) {
t.Parallel()
minter := sample.AccAddress()
beneficiary := sample.ConstBech32Addr
mintRequest := sample.MintRequest(beneficiary, 1000, "hash")
@ -113,6 +116,7 @@ func TestMsgServerMintToken(t *testing.T) {
}
func TestMsgServerMintTokenInvalidAddress(t *testing.T) {
t.Parallel()
minter := sample.AccAddress()
beneficiary := "invalid address"
mintRequest := sample.MintRequest(beneficiary, 1000, "hash")

View File

@ -9,6 +9,7 @@ import (
)
func TestGetParams(t *testing.T) {
t.Parallel()
k, ctx := testkeeper.DaoKeeper(t)
params := types.DefaultParams()

View File

@ -13,6 +13,7 @@ import (
)
func TestQueryGetMintRequestByHash(t *testing.T) {
t.Parallel()
keeper, ctx := keepertest.DaoKeeper(t)
wctx := sdk.WrapSDKContext(ctx)
items := createNMintRequests(keeper, ctx, sample.ConstBech32Addr, 1)
@ -34,7 +35,9 @@ func TestQueryGetMintRequestByHash(t *testing.T) {
err: status.Error(codes.NotFound, "mint request not found"),
},
} {
tc := tc
t.Run(tc.desc, func(t *testing.T) {
t.Parallel()
res, err := keeper.GetMintRequestsByHash(wctx, tc.request)
if tc.err != nil {
require.ErrorIs(t, err, tc.err)

View File

@ -12,6 +12,7 @@ import (
)
func TestQueryGetReissuance(t *testing.T) {
t.Parallel()
keeper, ctx := keepertest.DaoKeeper(t)
wctx := sdk.WrapSDKContext(ctx)
items := createNReissuances(keeper, ctx, 1)
@ -33,7 +34,9 @@ func TestQueryGetReissuance(t *testing.T) {
err: status.Error(codes.NotFound, "reissuance not found"),
},
} {
tc := tc
t.Run(tc.desc, func(t *testing.T) {
t.Parallel()
res, err := keeper.GetReissuance(wctx, tc.request)
if tc.err != nil {
require.ErrorIs(t, err, tc.err)

View File

@ -24,5 +24,4 @@ func (k Keeper) GetReissuances(goCtx context.Context, req *types.QueryGetReissua
return &types.QueryGetReissuancesResponse{Reissuance: &reissuances[0]}, nil
}
return &types.QueryGetReissuancesResponse{}, nil
}

View File

@ -10,6 +10,7 @@ import (
)
func TestParamsQuery(t *testing.T) {
t.Parallel()
keeper, ctx := testkeeper.DaoKeeper(t)
wctx := sdk.WrapSDKContext(ctx)
params := types.DefaultParams()

View File

@ -25,6 +25,7 @@ func createNReissuances(k *keeper.Keeper, ctx sdk.Context, n int) []types.Reissu
}
func TestGetReissuances(t *testing.T) {
t.Parallel()
keeper, ctx := keepertest.DaoKeeper(t)
items := createNReissuances(keeper, ctx, 10)
for _, item := range items {

View File

@ -8,6 +8,7 @@ import (
)
func TestGenesisState_Validate(t *testing.T) {
t.Parallel()
tests := []struct {
desc string
genState *types.GenesisState
@ -29,7 +30,9 @@ func TestGenesisState_Validate(t *testing.T) {
// this line is used by starport scaffolding # types/genesis/testcase
}
for _, tc := range tests {
tc := tc
t.Run(tc.desc, func(t *testing.T) {
t.Parallel()
err := tc.genState.Validate()
if tc.valid {
require.NoError(t, err)

View File

@ -8,6 +8,7 @@ import (
)
func TestMsgMintToken_ValidateBasic(t *testing.T) {
t.Parallel()
tests := []struct {
name string
msg MsgMintToken
@ -22,7 +23,9 @@ func TestMsgMintToken_ValidateBasic(t *testing.T) {
},
}
for _, tt := range tests {
tt := tt
t.Run(tt.name, func(t *testing.T) {
t.Parallel()
err := tt.msg.ValidateBasic()
if tt.err != nil {
require.ErrorIs(t, err, tt.err)

View File

@ -8,6 +8,7 @@ import (
)
func TestMsgUpdateParams_ValidateBasic(t *testing.T) {
t.Parallel()
tests := []struct {
name string
msg MsgUpdateParams
@ -22,7 +23,9 @@ func TestMsgUpdateParams_ValidateBasic(t *testing.T) {
},
}
for _, tt := range tests {
tt := tt
t.Run(tt.name, func(t *testing.T) {
t.Parallel()
err := tt.msg.ValidateBasic()
if tt.err != nil {
require.ErrorIs(t, err, tt.err)

View File

@ -11,6 +11,7 @@ import (
)
func TestGenesis(t *testing.T) {
t.Parallel()
genesisState := types.GenesisState{
Params: types.DefaultParams(),

View File

@ -26,6 +26,7 @@ func createNMachine(keeper *keeper.Keeper, ctx sdk.Context, n int) []types.Machi
}
func TestGetMachine(t *testing.T) {
t.Parallel()
keeper, ctx := keepertest.MachineKeeper(t)
items := createNMachine(keeper, ctx, 10)
for _, item := range items {
@ -42,6 +43,7 @@ func TestGetMachine(t *testing.T) {
}
func TestGetMachineIndexByPubKey(t *testing.T) {
t.Parallel()
keeper, ctx := keepertest.MachineKeeper(t)
items := createNMachine(keeper, ctx, 10)
for _, item := range items {

View File

@ -21,12 +21,14 @@ func setupMsgServer(t testing.TB) (types.MsgServer, context.Context) {
}
func TestMsgServer(t *testing.T) {
t.Parallel()
ms, ctx := setupMsgServer(t)
require.NotNil(t, ms)
require.NotNil(t, ctx)
}
func TestMsgServerAttestMachine(t *testing.T) {
t.Parallel()
sk, pk := sample.KeyPair()
ta := sample.TrustAnchor(pk)
taMsg := types.NewMsgRegisterTrustAnchor(pk, &ta)
@ -42,6 +44,7 @@ func TestMsgServerAttestMachine(t *testing.T) {
}
func TestMsgServerAttestMachineInvalidLiquidKey(t *testing.T) {
t.Parallel()
sk, pk := sample.KeyPair()
ta := sample.TrustAnchor(pk)
taMsg := types.NewMsgRegisterTrustAnchor(pk, &ta)
@ -56,6 +59,7 @@ func TestMsgServerAttestMachineInvalidLiquidKey(t *testing.T) {
}
func TestMsgServerRegisterTrustAnchor(t *testing.T) {
t.Parallel()
_, pk := sample.KeyPair()
ta := sample.TrustAnchor(pk)
msg := types.NewMsgRegisterTrustAnchor(pk, &ta)
@ -67,6 +71,7 @@ func TestMsgServerRegisterTrustAnchor(t *testing.T) {
}
func TestMsgServerRegisterTrustAnchorTwice(t *testing.T) {
t.Parallel()
_, pk := sample.KeyPair()
ta := sample.TrustAnchor(pk)
msg := types.NewMsgRegisterTrustAnchor(pk, &ta)
@ -80,6 +85,7 @@ func TestMsgServerRegisterTrustAnchorTwice(t *testing.T) {
}
func TestMsgServerRegisterTrustAnchorInvalidPubkey(t *testing.T) {
t.Parallel()
_, pk := sample.KeyPair()
ta := types.TrustAnchor{
Pubkey: "invalidpublickey",

View File

@ -9,6 +9,7 @@ import (
)
func TestGetParams(t *testing.T) {
t.Parallel()
k, ctx := testkeeper.MachineKeeper(t)
params := types.DefaultParams()

View File

@ -1,9 +1,10 @@
package keeper_test
import (
"testing"
keepertest "github.com/planetmint/planetmint-go/testutil/keeper"
"github.com/planetmint/planetmint-go/x/machine/types"
"testing"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/stretchr/testify/require"
@ -41,7 +42,6 @@ func TestGetMachineByPublicKey(t *testing.T) {
err: status.Error(codes.NotFound, "machine not found"),
},
} {
tc := tc
t.Run(tc.desc, func(t *testing.T) {
response, err := keeper.GetMachineByPublicKey(wctx, tc.request)
if tc.err != nil {

View File

@ -1,9 +1,10 @@
package keeper_test
import (
"testing"
keepertest "github.com/planetmint/planetmint-go/testutil/keeper"
"github.com/planetmint/planetmint-go/x/machine/types"
"testing"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/stretchr/testify/require"
@ -12,6 +13,7 @@ import (
)
func TestGetTrustAnchorQuery(t *testing.T) {
t.Parallel()
keeper, ctx := keepertest.MachineKeeper(t)
wctx := sdk.WrapSDKContext(ctx)
msgs := createNTrustAnchor(t, keeper, ctx, 2)
@ -39,6 +41,7 @@ func TestGetTrustAnchorQuery(t *testing.T) {
} {
tc := tc
t.Run(tc.desc, func(t *testing.T) {
t.Parallel()
response, err := keeper.GetTrustAnchorStatus(wctx, tc.request)
if tc.err != nil {
require.ErrorIs(t, err, tc.err)

View File

@ -10,6 +10,7 @@ import (
)
func TestParamsQuery(t *testing.T) {
t.Parallel()
keeper, ctx := testkeeper.MachineKeeper(t)
wctx := sdk.WrapSDKContext(ctx)
params := types.DefaultParams()

View File

@ -37,6 +37,7 @@ func createNTrustAnchor(t *testing.T, keeper *keeper.Keeper, ctx sdk.Context, n
}
func TestGetTrustAnchor(t *testing.T) {
t.Parallel()
keeper, ctx := keepertest.MachineKeeper(t)
items := createNTrustAnchor(t, keeper, ctx, 10)
for i, item := range items {
@ -52,6 +53,7 @@ func TestGetTrustAnchor(t *testing.T) {
}
func TestUpdateTrustAnchor(t *testing.T) {
t.Parallel()
keeper, ctx := keepertest.MachineKeeper(t)
items := createNTrustAnchor(t, keeper, ctx, 10)
for _, item := range items {
@ -69,6 +71,7 @@ func TestUpdateTrustAnchor(t *testing.T) {
}
func TestUpdateTrustAnchorInvalidPubKey(t *testing.T) {
t.Parallel()
keeper, ctx := keepertest.MachineKeeper(t)
items := createNTrustAnchor(t, keeper, ctx, 10)
for _, item := range items {

View File

@ -9,6 +9,7 @@ import (
)
func TestGenesisStateValidate(t *testing.T) {
t.Parallel()
tests := []struct {
desc string
genState *types.GenesisState
@ -30,7 +31,9 @@ func TestGenesisStateValidate(t *testing.T) {
// this line is used by starport scaffolding # types/genesis/testcase
}
for _, tc := range tests {
tc := tc
t.Run(tc.desc, func(t *testing.T) {
t.Parallel()
err := tc.genState.Validate()
if tc.valid {
require.NoError(t, err)

View File

@ -8,6 +8,7 @@ import (
)
func TestMsgAttestMachineValidateBasic(t *testing.T) {
t.Parallel()
tests := []struct {
name string
msg MsgAttestMachine
@ -22,7 +23,9 @@ func TestMsgAttestMachineValidateBasic(t *testing.T) {
},
}
for _, tt := range tests {
tt := tt
t.Run(tt.name, func(t *testing.T) {
t.Parallel()
err := tt.msg.ValidateBasic()
if tt.err != nil {
require.ErrorIs(t, err, tt.err)

View File

@ -8,6 +8,7 @@ import (
)
func TestMsgRegisterTrustAnchor_ValidateBasic(t *testing.T) {
t.Parallel()
tests := []struct {
name string
msg MsgRegisterTrustAnchor
@ -22,7 +23,9 @@ func TestMsgRegisterTrustAnchor_ValidateBasic(t *testing.T) {
},
}
for _, tt := range tests {
tt := tt
t.Run(tt.name, func(t *testing.T) {
t.Parallel()
err := tt.msg.ValidateBasic()
if tt.err != nil {
require.ErrorIs(t, err, tt.err)