From 966f26dfb23c532481972fa59ffd9cd395e24120 Mon Sep 17 00:00:00 2001 From: Christopher Goes Date: Wed, 18 Jul 2018 07:44:40 +0200 Subject: [PATCH] Remove print, quickfix --- cmd/gaia/app/sim_test.go | 5 ++++- x/stake/keeper/delegation.go | 6 ++++++ x/stake/simulation/invariants.go | 2 -- x/stake/types/errors.go | 4 ++++ 4 files changed, 14 insertions(+), 3 deletions(-) diff --git a/cmd/gaia/app/sim_test.go b/cmd/gaia/app/sim_test.go index a7b20586c..246d03a0f 100644 --- a/cmd/gaia/app/sim_test.go +++ b/cmd/gaia/app/sim_test.go @@ -4,7 +4,9 @@ import ( "encoding/json" "math/rand" "os" + "strconv" "testing" + "time" "github.com/stretchr/testify/require" @@ -70,6 +72,7 @@ func TestFullGaiaSimulation(t *testing.T) { require.Equal(t, "GaiaApp", app.Name()) var seed int64 + var err error envSeed := os.Getenv(simulationEnvSeed) if envSeed != "" { seed, err = strconv.ParseInt(envSeed, 10, 64) @@ -83,7 +86,7 @@ func TestFullGaiaSimulation(t *testing.T) { t, app.BaseApp, appStateFn, seed, []simulation.TestAndRunTx{ stakesim.SimulateMsgCreateValidator(app.accountMapper, app.stakeKeeper), - stakesim.SimulateMsgEditValidator(app.accountMapper, app.stakeKeeper), + stakesim.SimulateMsgEditValidator(app.stakeKeeper), stakesim.SimulateMsgDelegate(app.accountMapper, app.stakeKeeper), stakesim.SimulateMsgBeginUnbonding(app.accountMapper, app.stakeKeeper), stakesim.SimulateMsgCompleteUnbonding(app.stakeKeeper), diff --git a/x/stake/keeper/delegation.go b/x/stake/keeper/delegation.go index 4c7dab739..23b58108f 100644 --- a/x/stake/keeper/delegation.go +++ b/x/stake/keeper/delegation.go @@ -314,6 +314,12 @@ func (k Keeper) unbond(ctx sdk.Context, delegatorAddr, validatorAddr sdk.AccAddr // complete unbonding an unbonding record func (k Keeper) BeginUnbonding(ctx sdk.Context, delegatorAddr, validatorAddr sdk.AccAddress, sharesAmount sdk.Rat) sdk.Error { + // TODO quick fix, instead we should use an index, see https://github.com/cosmos/cosmos-sdk/issues/1402 + _, found := k.GetUnbondingDelegation(ctx, delegatorAddr, validatorAddr) + if found { + return types.ErrExistingUnbondingDelegation(k.Codespace()) + } + returnAmount, err := k.unbond(ctx, delegatorAddr, validatorAddr, sharesAmount) if err != nil { return err diff --git a/x/stake/simulation/invariants.go b/x/stake/simulation/invariants.go index e5f042a6e..776c8d1e7 100644 --- a/x/stake/simulation/invariants.go +++ b/x/stake/simulation/invariants.go @@ -1,7 +1,6 @@ package simulation import ( - "fmt" "testing" "github.com/stretchr/testify/require" @@ -38,7 +37,6 @@ func SupplyInvariants(ck bank.Keeper, k stake.Keeper, am auth.AccountMapper) sim return false }) k.IterateUnbondingDelegations(ctx, func(_ int64, ubd stake.UnbondingDelegation) bool { - fmt.Printf("found ubd with balance: %v\n", ubd.Balance) loose = loose.Add(ubd.Balance.Amount) return false }) diff --git a/x/stake/types/errors.go b/x/stake/types/errors.go index 237340b89..2ef747bae 100644 --- a/x/stake/types/errors.go +++ b/x/stake/types/errors.go @@ -120,6 +120,10 @@ func ErrNoUnbondingDelegation(codespace sdk.CodespaceType) sdk.Error { return sdk.NewError(codespace, CodeInvalidDelegation, "no unbonding delegation found") } +func ErrExistingUnbondingDelegation(codespace sdk.CodespaceType) sdk.Error { + return sdk.NewError(codespace, CodeInvalidDelegation, "existing unbonding delegation found") +} + func ErrNoRedelegation(codespace sdk.CodespaceType) sdk.Error { return sdk.NewError(codespace, CodeInvalidDelegation, "no redelegation found") }