Eckelj/remove the smell (#326)

* removed some more code smell/error message aggregation
* removed obsolete/duplicate tests/code
* excluded TODOs (simulation) from being processed by sonarqube
* removed TODO code

Signed-off-by: Jürgen Eckel <juergen@riddleandcode.com>

---------

Signed-off-by: Jürgen Eckel <juergen@riddleandcode.com>
This commit is contained in:
Jürgen Eckel 2024-02-26 18:06:43 +01:00 committed by GitHub
parent 75ed13b357
commit 55b7065744
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
17 changed files with 28 additions and 78 deletions

View File

@ -1,2 +1,2 @@
sonar.projectKey=planetmint_planetmint-go_AYjnSLNdwwdSy162QoXI
sonar.exclusions=docs/static/openapi.yml,x/**/*.pb.go,x/**/*.pb.gw.go,x/**/module.go,x/**/types/genesis_test.go,x/**/types/params.go,x/**/client/cli/query_params.go,tests/e2e/**/suite.go,app/simulation_test.go,x/**/client/cli/tx_update_params.go,x/**/types/message_update_params_test.go,x/**/keeper/message_server_update_params.go
sonar.exclusions=docs/static/openapi.yml,x/**/*.pb.go,x/**/*.pb.gw.go,x/**/module.go,x/**/types/genesis_test.go,x/**/types/params.go,x/**/client/cli/query_params.go,tests/e2e/**/suite.go,app/simulation_test.go,x/**/client/cli/tx_update_params.go,x/**/types/message_update_params_test.go,x/**/keeper/message_server_update_params.go,x/**/types/message*test.go,x/**/module_simulation.go,x/**/simulation/*.go

View File

@ -67,7 +67,7 @@ func (s *AssetDistributionE2ETestSuite) TestAssetDistribution() {
break
}
}
errmsg := "rpc error: code = NotFound desc = distribution not found: key not found"
testCases := []struct {
name string
requestHeight int64
@ -76,17 +76,17 @@ func (s *AssetDistributionE2ETestSuite) TestAssetDistribution() {
{
"request height too low",
s.distributionOffset,
"rpc error: code = NotFound desc = distribution not found: key not found",
errmsg,
},
{
"wrong request height",
height,
"rpc error: code = NotFound desc = distribution not found: key not found",
errmsg,
},
{
"request height too high",
2*s.reissaunceEpochs + s.distributionOffset,
"rpc error: code = NotFound desc = distribution not found: key not found",
errmsg,
},
{
"valid distribution request",

View File

@ -10,7 +10,7 @@ import (
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
"github.com/planetmint/planetmint-go/lib"
clitestutil "github.com/planetmint/planetmint-go/testutil/cli"
moduleobjects "github.com/planetmint/planetmint-go/testutil/moduleobject"
"github.com/planetmint/planetmint-go/testutil/moduleobject"
"github.com/planetmint/planetmint-go/testutil/network"
"github.com/planetmint/planetmint-go/testutil/sample"
machinetypes "github.com/planetmint/planetmint-go/x/machine/types"
@ -76,7 +76,7 @@ func AttestMachine(network *network.Network, name string, mnemonic string, num i
// register Ta
prvKey, pubKey := sample.KeyPair(num)
ta := moduleobjects.TrustAnchor(pubKey)
ta := moduleobject.TrustAnchor(pubKey)
registerMsg := machinetypes.NewMsgRegisterTrustAnchor(val.Address.String(), &ta)
_, err = lib.BroadcastTxWithFileLock(val.Address, registerMsg)
if err != nil {
@ -92,7 +92,7 @@ func AttestMachine(network *network.Network, name string, mnemonic string, num i
return err
}
machine := moduleobjects.Machine(name, pubKey, prvKey, addr.String())
machine := moduleobject.Machine(name, pubKey, prvKey, addr.String())
attestMsg := machinetypes.NewMsgAttestMachine(addr.String(), &machine)
_, err = lib.BroadcastTxWithFileLock(addr, attestMsg)
if err != nil {

View File

@ -4,13 +4,9 @@ import (
"encoding/hex"
"fmt"
"github.com/btcsuite/btcd/btcutil/hdkeychain"
"github.com/btcsuite/btcd/chaincfg"
"github.com/cosmos/cosmos-sdk/crypto/keyring"
"github.com/cosmos/cosmos-sdk/crypto/keys/ed25519"
"github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/go-bip39"
)
// Mnemonic sample mnemonic to use in tests
@ -60,19 +56,3 @@ func Asset() string {
cid := "cid0"
return cid
}
func ExtendedKeyPair(cfg chaincfg.Params) (string, string) {
seed, err := bip39.NewSeedWithErrorChecking(Mnemonic, keyring.DefaultBIP39Passphrase)
if err != nil {
panic(err)
}
xprivKey, err := hdkeychain.NewMaster(seed, &cfg)
if err != nil {
panic(err)
}
xpubKey, err := xprivKey.Neuter()
if err != nil {
panic(err)
}
return xprivKey.String(), xpubKey.String()
}

View File

@ -48,7 +48,6 @@ func buildSignBroadcastTx(goCtx context.Context, loggingContext string, sendingV
func SendInitReissuance(goCtx context.Context, proposerAddress string, txUnsigned string, blockHeight int64,
firstIncludedPop int64, lastIncludedPop int64) {
// get_last_PoPBlockHeight() // TODO: to be read form the upcoming PoP-store
sendingValidatorAddress := config.GetConfig().ValidatorAddress
msg := daotypes.NewMsgReissueRDDLProposal(sendingValidatorAddress, proposerAddress, txUnsigned, blockHeight,
firstIncludedPop, lastIncludedPop)

View File

@ -24,6 +24,7 @@ func GetConnectFunc() mqtt.Token {
// GetDisconnectFunc fetches the mock client's `Disconnect` func
func GetDisconnectFunc(_ uint) {
// not implemented at this point in time
}
// GetPublishFunc fetches the mock client's `Publish` func

View File

@ -7,6 +7,7 @@ import (
"github.com/planetmint/planetmint-go/config"
keepertest "github.com/planetmint/planetmint-go/testutil/keeper"
"github.com/planetmint/planetmint-go/testutil/moduleobject"
"github.com/planetmint/planetmint-go/testutil/sample"
"github.com/planetmint/planetmint-go/x/asset/keeper"
"github.com/planetmint/planetmint-go/x/asset/types"
@ -31,7 +32,7 @@ func TestMsgServer(t *testing.T) {
func TestMsgServerNotarizeAsset(t *testing.T) {
t.Parallel()
extSk, _ := sample.ExtendedKeyPair(config.PlmntNetParams)
extSk, _ := moduleobject.ExtendedKeyPair(config.PlmntNetParams)
xskKey, _ := hdkeychain.NewKeyFromString(extSk)
privKey, _ := xskKey.ECPrivKey()
byteKey := privKey.Serialize()

View File

@ -4,6 +4,7 @@ import (
"testing"
"github.com/planetmint/planetmint-go/testutil/errormsg"
"github.com/planetmint/planetmint-go/testutil/sample"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
"github.com/stretchr/testify/require"
@ -17,11 +18,16 @@ func TestMsgNotarizeAssetValidateBasic(t *testing.T) {
err error
}{
{
name: "invalid address",
name: sdkerrors.ErrInvalidAddress.Error(),
msg: MsgNotarizeAsset{
Creator: errormsg.ErrorInvalidAddress,
},
err: sdkerrors.ErrInvalidAddress,
}, {
name: "valid address",
msg: MsgNotarizeAsset{
Creator: sample.AccAddress(),
},
},
}
for _, tt := range tests {

View File

@ -38,25 +38,6 @@ func (k Keeper) GetLastDistributionOrder(ctx sdk.Context) (val types.Distributio
return val, found
}
// TODO to be integrated at a later stage
// func (k Keeper) getDistributionRequestPage(ctx sdk.Context, key []byte, offset uint64, page_size uint64, all bool, reverse bool) (distribution_orders []types.DistributionOrder) {
// store := prefix.NewStore(ctx.KVStore(k.storeKey), types.KeyPrefix(types.DistributionKey))
// iterator := store.Iterator(nil, nil)
// defer iterator.Close()
// if reverse {
// iterator = store.ReverseIterator(nil, nil)
// defer iterator.Close()
// }
// for ; iterator.Valid(); iterator.Next() {
// distribution_order := iterator.Value()
// var distribution_order_org types.DistributionOrder
// k.cdc.MustUnmarshal(distribution_order, &distribution_order_org)
// distribution_orders = append(distribution_orders, distribution_order_org)
// }
// return distribution_orders
// }
func (k Keeper) ComputeDistribution(ctx sdk.Context, lastReissuance int64, blockHeight int64, amount uint64) (distribution types.DistributionOrder) {
distribution.FirstPop = lastReissuance
distribution.LastPop = blockHeight

View File

@ -8,7 +8,7 @@ import (
"github.com/stretchr/testify/require"
)
func TestMsgInitPop_ValidateBasic(t *testing.T) {
func TestMsgInitPopValidateBasic(t *testing.T) {
t.Parallel()
tests := []struct {
name string
@ -16,7 +16,7 @@ func TestMsgInitPop_ValidateBasic(t *testing.T) {
err error
}{
{
name: "invalid address",
name: sdkerrors.ErrInvalidAddress.Error(),
msg: MsgInitPop{
Creator: errormsg.ErrorInvalidAddress,
},

View File

@ -16,7 +16,7 @@ func TestMsgMintToken_ValidateBasic(t *testing.T) {
err error
}{
{
name: "invalid address",
name: sdkerrors.ErrInvalidAddress.Error(),
msg: MsgMintToken{
Creator: errormsg.ErrorInvalidAddress,
},

View File

@ -16,7 +16,7 @@ func TestMsgUpdateParams_ValidateBasic(t *testing.T) {
err error
}{
{
name: "invalid address",
name: sdkerrors.ErrInvalidAddress.Error(),
msg: MsgUpdateParams{
Authority: errormsg.ErrorInvalidAddress,
},

View File

@ -16,7 +16,7 @@ func TestMsgCreateRedeemClaim_ValidateBasic(t *testing.T) {
err error
}{
{
name: "invalid address",
name: sdkerrors.ErrInvalidAddress.Error(),
msg: MsgCreateRedeemClaim{
Creator: errormsg.ErrorInvalidAddress,
},
@ -45,7 +45,7 @@ func TestMsgUpdateRedeemClaim_ValidateBasic(t *testing.T) {
err error
}{
{
name: "invalid address",
name: sdkerrors.ErrInvalidAddress.Error(),
msg: MsgUpdateRedeemClaim{
Creator: errormsg.ErrorInvalidAddress,
},
@ -74,7 +74,7 @@ func TestMsgConfirmRedeemClaim_ValidateBasic(t *testing.T) {
err error
}{
{
name: "invalid address",
name: sdkerrors.ErrInvalidAddress.Error(),
msg: MsgConfirmRedeemClaim{
Creator: errormsg.ErrorInvalidAddress,
},

View File

@ -69,21 +69,3 @@ func TestUpdateTrustAnchor(t *testing.T) {
assert.True(t, activated)
}
}
func TestUpdateTrustAnchorInvalidPubKey(t *testing.T) {
t.Parallel()
keeper, ctx := keepertest.MachineKeeper(t)
items := createNTrustAnchor(t, keeper, ctx, 10)
for _, item := range items {
ta, activated, _ := keeper.GetTrustAnchor(ctx, item.Pubkey)
if !activated {
err := keeper.StoreTrustAnchor(ctx, ta, true)
assert.False(t, (err != nil))
}
}
for _, item := range items {
_, activated, _ := keeper.GetTrustAnchor(ctx, item.Pubkey)
assert.True(t, activated)
}
}

View File

@ -16,7 +16,7 @@ func TestMsgAttestMachineValidateBasic(t *testing.T) {
err error
}{
{
name: "invalid address",
name: sdkerrors.ErrInvalidAddress.Error(),
msg: MsgAttestMachine{
Creator: errormsg.ErrorInvalidAddress,
},

View File

@ -16,7 +16,7 @@ func TestMsgRegisterTrustAnchor_ValidateBasic(t *testing.T) {
err error
}{
{
name: "invalid address",
name: sdkerrors.ErrInvalidAddress.Error(),
msg: MsgRegisterTrustAnchor{
Creator: errormsg.ErrorInvalidAddress,
},

View File

@ -16,7 +16,7 @@ func TestMsgUpdateParams_ValidateBasic(t *testing.T) {
err error
}{
{
name: "invalid address",
name: sdkerrors.ErrInvalidAddress.Error(),
msg: MsgUpdateParams{
Authority: errormsg.ErrorInvalidAddress,
},