mirror of
https://github.com/planetmint/planetmint-go.git
synced 2025-03-30 15:08:28 +00:00
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:
parent
75ed13b357
commit
55b7065744
@ -1,2 +1,2 @@
|
|||||||
sonar.projectKey=planetmint_planetmint-go_AYjnSLNdwwdSy162QoXI
|
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
|
||||||
|
@ -67,7 +67,7 @@ func (s *AssetDistributionE2ETestSuite) TestAssetDistribution() {
|
|||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
errmsg := "rpc error: code = NotFound desc = distribution not found: key not found"
|
||||||
testCases := []struct {
|
testCases := []struct {
|
||||||
name string
|
name string
|
||||||
requestHeight int64
|
requestHeight int64
|
||||||
@ -76,17 +76,17 @@ func (s *AssetDistributionE2ETestSuite) TestAssetDistribution() {
|
|||||||
{
|
{
|
||||||
"request height too low",
|
"request height too low",
|
||||||
s.distributionOffset,
|
s.distributionOffset,
|
||||||
"rpc error: code = NotFound desc = distribution not found: key not found",
|
errmsg,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"wrong request height",
|
"wrong request height",
|
||||||
height,
|
height,
|
||||||
"rpc error: code = NotFound desc = distribution not found: key not found",
|
errmsg,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"request height too high",
|
"request height too high",
|
||||||
2*s.reissaunceEpochs + s.distributionOffset,
|
2*s.reissaunceEpochs + s.distributionOffset,
|
||||||
"rpc error: code = NotFound desc = distribution not found: key not found",
|
errmsg,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"valid distribution request",
|
"valid distribution request",
|
||||||
|
@ -10,7 +10,7 @@ import (
|
|||||||
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
|
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
|
||||||
"github.com/planetmint/planetmint-go/lib"
|
"github.com/planetmint/planetmint-go/lib"
|
||||||
clitestutil "github.com/planetmint/planetmint-go/testutil/cli"
|
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/network"
|
||||||
"github.com/planetmint/planetmint-go/testutil/sample"
|
"github.com/planetmint/planetmint-go/testutil/sample"
|
||||||
machinetypes "github.com/planetmint/planetmint-go/x/machine/types"
|
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
|
// register Ta
|
||||||
prvKey, pubKey := sample.KeyPair(num)
|
prvKey, pubKey := sample.KeyPair(num)
|
||||||
ta := moduleobjects.TrustAnchor(pubKey)
|
ta := moduleobject.TrustAnchor(pubKey)
|
||||||
registerMsg := machinetypes.NewMsgRegisterTrustAnchor(val.Address.String(), &ta)
|
registerMsg := machinetypes.NewMsgRegisterTrustAnchor(val.Address.String(), &ta)
|
||||||
_, err = lib.BroadcastTxWithFileLock(val.Address, registerMsg)
|
_, err = lib.BroadcastTxWithFileLock(val.Address, registerMsg)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -92,7 +92,7 @@ func AttestMachine(network *network.Network, name string, mnemonic string, num i
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
machine := moduleobjects.Machine(name, pubKey, prvKey, addr.String())
|
machine := moduleobject.Machine(name, pubKey, prvKey, addr.String())
|
||||||
attestMsg := machinetypes.NewMsgAttestMachine(addr.String(), &machine)
|
attestMsg := machinetypes.NewMsgAttestMachine(addr.String(), &machine)
|
||||||
_, err = lib.BroadcastTxWithFileLock(addr, attestMsg)
|
_, err = lib.BroadcastTxWithFileLock(addr, attestMsg)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -4,13 +4,9 @@ import (
|
|||||||
"encoding/hex"
|
"encoding/hex"
|
||||||
"fmt"
|
"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/ed25519"
|
||||||
"github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1"
|
"github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1"
|
||||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||||
"github.com/cosmos/go-bip39"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// Mnemonic sample mnemonic to use in tests
|
// Mnemonic sample mnemonic to use in tests
|
||||||
@ -60,19 +56,3 @@ func Asset() string {
|
|||||||
cid := "cid0"
|
cid := "cid0"
|
||||||
return cid
|
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()
|
|
||||||
}
|
|
||||||
|
@ -48,7 +48,6 @@ func buildSignBroadcastTx(goCtx context.Context, loggingContext string, sendingV
|
|||||||
|
|
||||||
func SendInitReissuance(goCtx context.Context, proposerAddress string, txUnsigned string, blockHeight int64,
|
func SendInitReissuance(goCtx context.Context, proposerAddress string, txUnsigned string, blockHeight int64,
|
||||||
firstIncludedPop int64, lastIncludedPop int64) {
|
firstIncludedPop int64, lastIncludedPop int64) {
|
||||||
// get_last_PoPBlockHeight() // TODO: to be read form the upcoming PoP-store
|
|
||||||
sendingValidatorAddress := config.GetConfig().ValidatorAddress
|
sendingValidatorAddress := config.GetConfig().ValidatorAddress
|
||||||
msg := daotypes.NewMsgReissueRDDLProposal(sendingValidatorAddress, proposerAddress, txUnsigned, blockHeight,
|
msg := daotypes.NewMsgReissueRDDLProposal(sendingValidatorAddress, proposerAddress, txUnsigned, blockHeight,
|
||||||
firstIncludedPop, lastIncludedPop)
|
firstIncludedPop, lastIncludedPop)
|
||||||
|
@ -24,6 +24,7 @@ func GetConnectFunc() mqtt.Token {
|
|||||||
|
|
||||||
// GetDisconnectFunc fetches the mock client's `Disconnect` func
|
// GetDisconnectFunc fetches the mock client's `Disconnect` func
|
||||||
func GetDisconnectFunc(_ uint) {
|
func GetDisconnectFunc(_ uint) {
|
||||||
|
// not implemented at this point in time
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetPublishFunc fetches the mock client's `Publish` func
|
// GetPublishFunc fetches the mock client's `Publish` func
|
||||||
|
@ -7,6 +7,7 @@ import (
|
|||||||
|
|
||||||
"github.com/planetmint/planetmint-go/config"
|
"github.com/planetmint/planetmint-go/config"
|
||||||
keepertest "github.com/planetmint/planetmint-go/testutil/keeper"
|
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/testutil/sample"
|
||||||
"github.com/planetmint/planetmint-go/x/asset/keeper"
|
"github.com/planetmint/planetmint-go/x/asset/keeper"
|
||||||
"github.com/planetmint/planetmint-go/x/asset/types"
|
"github.com/planetmint/planetmint-go/x/asset/types"
|
||||||
@ -31,7 +32,7 @@ func TestMsgServer(t *testing.T) {
|
|||||||
|
|
||||||
func TestMsgServerNotarizeAsset(t *testing.T) {
|
func TestMsgServerNotarizeAsset(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
extSk, _ := sample.ExtendedKeyPair(config.PlmntNetParams)
|
extSk, _ := moduleobject.ExtendedKeyPair(config.PlmntNetParams)
|
||||||
xskKey, _ := hdkeychain.NewKeyFromString(extSk)
|
xskKey, _ := hdkeychain.NewKeyFromString(extSk)
|
||||||
privKey, _ := xskKey.ECPrivKey()
|
privKey, _ := xskKey.ECPrivKey()
|
||||||
byteKey := privKey.Serialize()
|
byteKey := privKey.Serialize()
|
||||||
|
@ -4,6 +4,7 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/planetmint/planetmint-go/testutil/errormsg"
|
"github.com/planetmint/planetmint-go/testutil/errormsg"
|
||||||
|
"github.com/planetmint/planetmint-go/testutil/sample"
|
||||||
|
|
||||||
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
|
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
@ -17,11 +18,16 @@ func TestMsgNotarizeAssetValidateBasic(t *testing.T) {
|
|||||||
err error
|
err error
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
name: "invalid address",
|
name: sdkerrors.ErrInvalidAddress.Error(),
|
||||||
msg: MsgNotarizeAsset{
|
msg: MsgNotarizeAsset{
|
||||||
Creator: errormsg.ErrorInvalidAddress,
|
Creator: errormsg.ErrorInvalidAddress,
|
||||||
},
|
},
|
||||||
err: sdkerrors.ErrInvalidAddress,
|
err: sdkerrors.ErrInvalidAddress,
|
||||||
|
}, {
|
||||||
|
name: "valid address",
|
||||||
|
msg: MsgNotarizeAsset{
|
||||||
|
Creator: sample.AccAddress(),
|
||||||
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
for _, tt := range tests {
|
for _, tt := range tests {
|
||||||
|
@ -38,25 +38,6 @@ func (k Keeper) GetLastDistributionOrder(ctx sdk.Context) (val types.Distributio
|
|||||||
return val, found
|
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) {
|
func (k Keeper) ComputeDistribution(ctx sdk.Context, lastReissuance int64, blockHeight int64, amount uint64) (distribution types.DistributionOrder) {
|
||||||
distribution.FirstPop = lastReissuance
|
distribution.FirstPop = lastReissuance
|
||||||
distribution.LastPop = blockHeight
|
distribution.LastPop = blockHeight
|
||||||
|
@ -8,7 +8,7 @@ import (
|
|||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestMsgInitPop_ValidateBasic(t *testing.T) {
|
func TestMsgInitPopValidateBasic(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
name string
|
name string
|
||||||
@ -16,7 +16,7 @@ func TestMsgInitPop_ValidateBasic(t *testing.T) {
|
|||||||
err error
|
err error
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
name: "invalid address",
|
name: sdkerrors.ErrInvalidAddress.Error(),
|
||||||
msg: MsgInitPop{
|
msg: MsgInitPop{
|
||||||
Creator: errormsg.ErrorInvalidAddress,
|
Creator: errormsg.ErrorInvalidAddress,
|
||||||
},
|
},
|
||||||
|
@ -16,7 +16,7 @@ func TestMsgMintToken_ValidateBasic(t *testing.T) {
|
|||||||
err error
|
err error
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
name: "invalid address",
|
name: sdkerrors.ErrInvalidAddress.Error(),
|
||||||
msg: MsgMintToken{
|
msg: MsgMintToken{
|
||||||
Creator: errormsg.ErrorInvalidAddress,
|
Creator: errormsg.ErrorInvalidAddress,
|
||||||
},
|
},
|
||||||
|
@ -16,7 +16,7 @@ func TestMsgUpdateParams_ValidateBasic(t *testing.T) {
|
|||||||
err error
|
err error
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
name: "invalid address",
|
name: sdkerrors.ErrInvalidAddress.Error(),
|
||||||
msg: MsgUpdateParams{
|
msg: MsgUpdateParams{
|
||||||
Authority: errormsg.ErrorInvalidAddress,
|
Authority: errormsg.ErrorInvalidAddress,
|
||||||
},
|
},
|
||||||
|
@ -16,7 +16,7 @@ func TestMsgCreateRedeemClaim_ValidateBasic(t *testing.T) {
|
|||||||
err error
|
err error
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
name: "invalid address",
|
name: sdkerrors.ErrInvalidAddress.Error(),
|
||||||
msg: MsgCreateRedeemClaim{
|
msg: MsgCreateRedeemClaim{
|
||||||
Creator: errormsg.ErrorInvalidAddress,
|
Creator: errormsg.ErrorInvalidAddress,
|
||||||
},
|
},
|
||||||
@ -45,7 +45,7 @@ func TestMsgUpdateRedeemClaim_ValidateBasic(t *testing.T) {
|
|||||||
err error
|
err error
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
name: "invalid address",
|
name: sdkerrors.ErrInvalidAddress.Error(),
|
||||||
msg: MsgUpdateRedeemClaim{
|
msg: MsgUpdateRedeemClaim{
|
||||||
Creator: errormsg.ErrorInvalidAddress,
|
Creator: errormsg.ErrorInvalidAddress,
|
||||||
},
|
},
|
||||||
@ -74,7 +74,7 @@ func TestMsgConfirmRedeemClaim_ValidateBasic(t *testing.T) {
|
|||||||
err error
|
err error
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
name: "invalid address",
|
name: sdkerrors.ErrInvalidAddress.Error(),
|
||||||
msg: MsgConfirmRedeemClaim{
|
msg: MsgConfirmRedeemClaim{
|
||||||
Creator: errormsg.ErrorInvalidAddress,
|
Creator: errormsg.ErrorInvalidAddress,
|
||||||
},
|
},
|
||||||
|
@ -69,21 +69,3 @@ func TestUpdateTrustAnchor(t *testing.T) {
|
|||||||
assert.True(t, activated)
|
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)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
@ -16,7 +16,7 @@ func TestMsgAttestMachineValidateBasic(t *testing.T) {
|
|||||||
err error
|
err error
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
name: "invalid address",
|
name: sdkerrors.ErrInvalidAddress.Error(),
|
||||||
msg: MsgAttestMachine{
|
msg: MsgAttestMachine{
|
||||||
Creator: errormsg.ErrorInvalidAddress,
|
Creator: errormsg.ErrorInvalidAddress,
|
||||||
},
|
},
|
||||||
|
@ -16,7 +16,7 @@ func TestMsgRegisterTrustAnchor_ValidateBasic(t *testing.T) {
|
|||||||
err error
|
err error
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
name: "invalid address",
|
name: sdkerrors.ErrInvalidAddress.Error(),
|
||||||
msg: MsgRegisterTrustAnchor{
|
msg: MsgRegisterTrustAnchor{
|
||||||
Creator: errormsg.ErrorInvalidAddress,
|
Creator: errormsg.ErrorInvalidAddress,
|
||||||
},
|
},
|
||||||
|
@ -16,7 +16,7 @@ func TestMsgUpdateParams_ValidateBasic(t *testing.T) {
|
|||||||
err error
|
err error
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
name: "invalid address",
|
name: sdkerrors.ErrInvalidAddress.Error(),
|
||||||
msg: MsgUpdateParams{
|
msg: MsgUpdateParams{
|
||||||
Authority: errormsg.ErrorInvalidAddress,
|
Authority: errormsg.ErrorInvalidAddress,
|
||||||
},
|
},
|
||||||
|
Loading…
x
Reference in New Issue
Block a user