diff --git a/.golangci.yaml b/.golangci.yaml index 207a3cf..51882b9 100644 --- a/.golangci.yaml +++ b/.golangci.yaml @@ -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 diff --git a/app/ante/check_mint_address_decorator.go b/app/ante/check_mint_address_decorator.go index c9e06a3..9cfb8be 100644 --- a/app/ante/check_mint_address_decorator.go +++ b/app/ante/check_mint_address_decorator.go @@ -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()) } } diff --git a/app/ante/deduct_fee_decorator.go b/app/ante/deduct_fee_decorator.go index 3b85dad..4757dff 100644 --- a/app/ante/deduct_fee_decorator.go +++ b/app/ante/deduct_fee_decorator.go @@ -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 diff --git a/app/app_test.go b/app/app_test.go index e2c6874..49a1fa1 100644 --- a/app/app_test.go +++ b/app/app_test.go @@ -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'.") } diff --git a/app/simulation_test.go b/app/simulation_test.go index 53d43b6..a4f7085 100644 --- a/app/simulation_test.go +++ b/app/simulation_test.go @@ -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" diff --git a/cmd/planetmint-god/cmd/config_test.go b/cmd/planetmint-god/cmd/config_test.go index d58180c..c8c6c2c 100644 --- a/cmd/planetmint-god/cmd/config_test.go +++ b/cmd/planetmint-god/cmd/config_test.go @@ -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) diff --git a/config/config.go b/config/config.go index cc5b5ae..708b7ab 100644 --- a/config/config.go +++ b/config/config.go @@ -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 diff --git a/lib/config.go b/lib/config.go index 26eaca7..daecd6c 100644 --- a/lib/config.go +++ b/lib/config.go @@ -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 diff --git a/lib/tx.go b/lib/tx.go index 1022563..aa21717 100644 --- a/lib/tx.go +++ b/lib/tx.go @@ -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() { diff --git a/tests/e2e/asset/cli_test.go b/tests/e2e/asset/cli_test.go index b253bc0..3621897 100644 --- a/tests/e2e/asset/cli_test.go +++ b/tests/e2e/asset/cli_test.go @@ -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)) diff --git a/tests/e2e/dao/cli_test.go b/tests/e2e/dao/cli_test.go index b835205..841ffaf 100644 --- a/tests/e2e/dao/cli_test.go +++ b/tests/e2e/dao/cli_test.go @@ -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)) } diff --git a/tests/e2e/machine/cli_test.go b/tests/e2e/machine/cli_test.go index 28d895a..130ce81 100644 --- a/tests/e2e/machine/cli_test.go +++ b/tests/e2e/machine/cli_test.go @@ -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)) diff --git a/testutil/rest.go b/testutil/rest.go index 03d56b4..1eb1f77 100644 --- a/testutil/rest.go +++ b/testutil/rest.go @@ -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) } diff --git a/util/determine_block_proposer.go b/util/determine_block_proposer.go index bb79ec5..6137454 100644 --- a/util/determine_block_proposer.go +++ b/util/determine_block_proposer.go @@ -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) { diff --git a/util/rddl_token_test.go b/util/rddl_token_test.go index d4caded..b72b3ae 100644 --- a/util/rddl_token_test.go +++ b/util/rddl_token_test.go @@ -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) diff --git a/x/asset/genesis_test.go b/x/asset/genesis_test.go index eb4a7ea..91ae9ac 100644 --- a/x/asset/genesis_test.go +++ b/x/asset/genesis_test.go @@ -11,6 +11,7 @@ import ( ) func TestGenesis(t *testing.T) { + t.Parallel() genesisState := types.GenesisState{ Params: types.DefaultParams(), diff --git a/x/asset/keeper/asset_test.go b/x/asset/keeper/asset_test.go index 04f0ffc..7bc89b8 100644 --- a/x/asset/keeper/asset_test.go +++ b/x/asset/keeper/asset_test.go @@ -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") diff --git a/x/asset/keeper/msg_server_test.go b/x/asset/keeper/msg_server_test.go index c002df1..4e70f70 100644 --- a/x/asset/keeper/msg_server_test.go +++ b/x/asset/keeper/msg_server_test.go @@ -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() diff --git a/x/asset/keeper/params_test.go b/x/asset/keeper/params_test.go index 05b5d2d..37f0cd8 100644 --- a/x/asset/keeper/params_test.go +++ b/x/asset/keeper/params_test.go @@ -9,6 +9,7 @@ import ( ) func TestGetParams(t *testing.T) { + t.Parallel() k, ctx := testkeeper.AssetKeeper(t) params := types.DefaultParams() diff --git a/x/asset/keeper/query_get_cids_by_address_test.go b/x/asset/keeper/query_get_cids_by_address_test.go index bca2fbd..8529dc1 100644 --- a/x/asset/keeper/query_get_cids_by_address_test.go +++ b/x/asset/keeper/query_get_cids_by_address_test.go @@ -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 { diff --git a/x/asset/keeper/query_get_notarized_asset_test.go b/x/asset/keeper/query_get_notarized_asset_test.go index 556c0dc..0b31c5a 100644 --- a/x/asset/keeper/query_get_notarized_asset_test.go +++ b/x/asset/keeper/query_get_notarized_asset_test.go @@ -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 { diff --git a/x/asset/keeper/query_params_test.go b/x/asset/keeper/query_params_test.go index 87ec382..34ea124 100644 --- a/x/asset/keeper/query_params_test.go +++ b/x/asset/keeper/query_params_test.go @@ -10,6 +10,7 @@ import ( ) func TestParamsQuery(t *testing.T) { + t.Parallel() keeper, ctx := testkeeper.AssetKeeper(t) wctx := sdk.WrapSDKContext(ctx) params := types.DefaultParams() diff --git a/x/asset/types/genesis_test.go b/x/asset/types/genesis_test.go index 640586e..3c99c81 100644 --- a/x/asset/types/genesis_test.go +++ b/x/asset/types/genesis_test.go @@ -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) diff --git a/x/asset/types/message_notarize_asset_test.go b/x/asset/types/message_notarize_asset_test.go index fe61c68..54231bf 100644 --- a/x/asset/types/message_notarize_asset_test.go +++ b/x/asset/types/message_notarize_asset_test.go @@ -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) diff --git a/x/dao/abci.go b/x/dao/abci.go index 0238f52..c81a0c3 100644 --- a/x/dao/abci.go +++ b/x/dao/abci.go @@ -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 { diff --git a/x/dao/client/cli/query_get_reissuances.go b/x/dao/client/cli/query_get_reissuances.go index 87a0cf2..d9a78fc 100644 --- a/x/dao/client/cli/query_get_reissuances.go +++ b/x/dao/client/cli/query_get_reissuances.go @@ -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 diff --git a/x/dao/genesis_test.go b/x/dao/genesis_test.go index 7695486..4a201fb 100644 --- a/x/dao/genesis_test.go +++ b/x/dao/genesis_test.go @@ -11,6 +11,7 @@ import ( ) func TestGenesis(t *testing.T) { + t.Parallel() genesisState := types.GenesisState{ Params: types.DefaultParams(), diff --git a/x/dao/keeper/challenge_test.go b/x/dao/keeper/challenge_test.go index b50a949..ebd4a76 100644 --- a/x/dao/keeper/challenge_test.go +++ b/x/dao/keeper/challenge_test.go @@ -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 { diff --git a/x/dao/keeper/distribution_test.go b/x/dao/keeper/distribution_test.go index fc9bfc8..9d5d122 100644 --- a/x/dao/keeper/distribution_test.go +++ b/x/dao/keeper/distribution_test.go @@ -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) - } diff --git a/x/dao/keeper/mint_request.go b/x/dao/keeper/mint_request.go index d876ca4..279cd46 100644 --- a/x/dao/keeper/mint_request.go +++ b/x/dao/keeper/mint_request.go @@ -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) { diff --git a/x/dao/keeper/mint_request_test.go b/x/dao/keeper/mint_request_test.go index c38ef84..b0c74ee 100644 --- a/x/dao/keeper/mint_request_test.go +++ b/x/dao/keeper/mint_request_test.go @@ -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") diff --git a/x/dao/keeper/msg_server_test.go b/x/dao/keeper/msg_server_test.go index f155ad6..65decae 100644 --- a/x/dao/keeper/msg_server_test.go +++ b/x/dao/keeper/msg_server_test.go @@ -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") diff --git a/x/dao/keeper/params_test.go b/x/dao/keeper/params_test.go index f32c17e..35e0b96 100644 --- a/x/dao/keeper/params_test.go +++ b/x/dao/keeper/params_test.go @@ -9,6 +9,7 @@ import ( ) func TestGetParams(t *testing.T) { + t.Parallel() k, ctx := testkeeper.DaoKeeper(t) params := types.DefaultParams() diff --git a/x/dao/keeper/query_get_mint_requests_by_hash_test.go b/x/dao/keeper/query_get_mint_requests_by_hash_test.go index 79ad4d0..e65c248 100644 --- a/x/dao/keeper/query_get_mint_requests_by_hash_test.go +++ b/x/dao/keeper/query_get_mint_requests_by_hash_test.go @@ -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) diff --git a/x/dao/keeper/query_get_reissuance_test.go b/x/dao/keeper/query_get_reissuance_test.go index a379b6d..02923de 100644 --- a/x/dao/keeper/query_get_reissuance_test.go +++ b/x/dao/keeper/query_get_reissuance_test.go @@ -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) diff --git a/x/dao/keeper/query_get_reissuances.go b/x/dao/keeper/query_get_reissuances.go index 7181d78..6043036 100644 --- a/x/dao/keeper/query_get_reissuances.go +++ b/x/dao/keeper/query_get_reissuances.go @@ -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 - } diff --git a/x/dao/keeper/query_params_test.go b/x/dao/keeper/query_params_test.go index b75b559..0ccf188 100644 --- a/x/dao/keeper/query_params_test.go +++ b/x/dao/keeper/query_params_test.go @@ -10,6 +10,7 @@ import ( ) func TestParamsQuery(t *testing.T) { + t.Parallel() keeper, ctx := testkeeper.DaoKeeper(t) wctx := sdk.WrapSDKContext(ctx) params := types.DefaultParams() diff --git a/x/dao/keeper/reissuance_test.go b/x/dao/keeper/reissuance_test.go index 0ea6cdb..0eebbe6 100644 --- a/x/dao/keeper/reissuance_test.go +++ b/x/dao/keeper/reissuance_test.go @@ -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 { diff --git a/x/dao/types/genesis_test.go b/x/dao/types/genesis_test.go index 5fd9c75..4769cfc 100644 --- a/x/dao/types/genesis_test.go +++ b/x/dao/types/genesis_test.go @@ -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) diff --git a/x/dao/types/message_mint_token_test.go b/x/dao/types/message_mint_token_test.go index 58de1d4..0471c38 100644 --- a/x/dao/types/message_mint_token_test.go +++ b/x/dao/types/message_mint_token_test.go @@ -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) diff --git a/x/dao/types/message_update_params_test.go b/x/dao/types/message_update_params_test.go index 7d7c889..49dc88a 100644 --- a/x/dao/types/message_update_params_test.go +++ b/x/dao/types/message_update_params_test.go @@ -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) diff --git a/x/machine/genesis_test.go b/x/machine/genesis_test.go index af31716..53a348c 100644 --- a/x/machine/genesis_test.go +++ b/x/machine/genesis_test.go @@ -11,6 +11,7 @@ import ( ) func TestGenesis(t *testing.T) { + t.Parallel() genesisState := types.GenesisState{ Params: types.DefaultParams(), diff --git a/x/machine/keeper/machine_test.go b/x/machine/keeper/machine_test.go index c418d2e..c0349f7 100644 --- a/x/machine/keeper/machine_test.go +++ b/x/machine/keeper/machine_test.go @@ -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 { diff --git a/x/machine/keeper/msg_server_test.go b/x/machine/keeper/msg_server_test.go index cddae71..938063a 100644 --- a/x/machine/keeper/msg_server_test.go +++ b/x/machine/keeper/msg_server_test.go @@ -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", diff --git a/x/machine/keeper/params_test.go b/x/machine/keeper/params_test.go index 3dfbd91..2997b41 100644 --- a/x/machine/keeper/params_test.go +++ b/x/machine/keeper/params_test.go @@ -9,6 +9,7 @@ import ( ) func TestGetParams(t *testing.T) { + t.Parallel() k, ctx := testkeeper.MachineKeeper(t) params := types.DefaultParams() diff --git a/x/machine/keeper/query_get_machine_by_public_key_test.go b/x/machine/keeper/query_get_machine_by_public_key_test.go index 6650bdb..5059aa2 100644 --- a/x/machine/keeper/query_get_machine_by_public_key_test.go +++ b/x/machine/keeper/query_get_machine_by_public_key_test.go @@ -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 { diff --git a/x/machine/keeper/query_get_trust_anchor_status_test.go b/x/machine/keeper/query_get_trust_anchor_status_test.go index b00795c..9afacce 100644 --- a/x/machine/keeper/query_get_trust_anchor_status_test.go +++ b/x/machine/keeper/query_get_trust_anchor_status_test.go @@ -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) diff --git a/x/machine/keeper/query_params_test.go b/x/machine/keeper/query_params_test.go index 9de503b..7747b93 100644 --- a/x/machine/keeper/query_params_test.go +++ b/x/machine/keeper/query_params_test.go @@ -10,6 +10,7 @@ import ( ) func TestParamsQuery(t *testing.T) { + t.Parallel() keeper, ctx := testkeeper.MachineKeeper(t) wctx := sdk.WrapSDKContext(ctx) params := types.DefaultParams() diff --git a/x/machine/keeper/trust_anchor_test.go b/x/machine/keeper/trust_anchor_test.go index ddf1036..a162144 100644 --- a/x/machine/keeper/trust_anchor_test.go +++ b/x/machine/keeper/trust_anchor_test.go @@ -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 { diff --git a/x/machine/types/genesis_test.go b/x/machine/types/genesis_test.go index a6e552f..e2a5acc 100644 --- a/x/machine/types/genesis_test.go +++ b/x/machine/types/genesis_test.go @@ -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) diff --git a/x/machine/types/message_attest_machine_test.go b/x/machine/types/message_attest_machine_test.go index 4170ec6..138957f 100644 --- a/x/machine/types/message_attest_machine_test.go +++ b/x/machine/types/message_attest_machine_test.go @@ -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) diff --git a/x/machine/types/message_register_trust_anchor_test.go b/x/machine/types/message_register_trust_anchor_test.go index dac5f61..1e52114 100644 --- a/x/machine/types/message_register_trust_anchor_test.go +++ b/x/machine/types/message_register_trust_anchor_test.go @@ -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)