Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Injectable locked coins functionality #577

Merged
merged 10 commits into from
Jul 18, 2023
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@ Ref: https://keepachangelog.com/en/1.0.0/

## Unreleased

* nothing
### Features

* [#577](https://github.com/provenance-io/cosmos-sdk/pull/577) Add an injectable `GetLockedCoinsFn` to the bank module.

---

Expand Down
10 changes: 5 additions & 5 deletions simapp/sim_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -254,16 +254,16 @@ func TestAppSimulationAfterImport(t *testing.T) {
PrintStats(db)
}

if stopEarly {
fmt.Println("can't export or import a zero-validator genesis, exiting test...")
return
}

fmt.Printf("exporting genesis...\n")

exported, err := app.ExportAppStateAndValidators(true, []string{})
require.NoError(t, err)

if stopEarly || len(exported.Validators) == 0 {
fmt.Println("can't import a zero-validator genesis, exiting test...")
return
}

fmt.Printf("importing genesis...\n")

_, newDB, newDir, _, _, err := SetupSimulation("leveldb-app-sim-2", "Simulation-2")
Expand Down
15 changes: 15 additions & 0 deletions x/bank/keeper/export_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,25 @@ import "github.com/cosmos/cosmos-sdk/x/bank/types"
// This file exists in the keeper package to expose some private things
// for the purpose of testing in the keeper_test package.

// SetSendRestriction is a TEST ONLY method for overwriting the SendRestrictionFn.
func (k BaseSendKeeper) SetSendRestriction(restriction types.SendRestrictionFn) {
k.sendRestriction.fn = restriction
}

// GetSendRestrictionFn is a TEST ONLY exposure of the currently defined SendRestrictionFn.
func (k BaseSendKeeper) GetSendRestrictionFn() types.SendRestrictionFn {
return k.sendRestriction.fn
}

// SetLockedCoinsGetter is a TEST ONLY method for overwriting the GetLockedCoinsFn.
func (k BaseSendKeeper) SetLockedCoinsGetter(getter types.GetLockedCoinsFn) {
k.lockedCoinsGetter.fn = getter
}

// GetLockedCoinsGetter is a TEST ONLY exposure of the currently defined GetLockedCoinsFn.
func (k BaseViewKeeper) GetLockedCoinsGetter() types.GetLockedCoinsFn {
return k.lockedCoinsGetter.fn
}

// GetLockedCoinsFnWrapper is a TEST ONLY exposure of the getLockedCoinsFnWrapper function.
var GetLockedCoinsFnWrapper = getLockedCoinsFnWrapper
4 changes: 4 additions & 0 deletions x/bank/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,10 @@ func (k BaseKeeper) DelegateCoins(ctx sdk.Context, delegatorAddr, moduleAccAddr
}
}

if _, err := k.sendRestriction.apply(ctx, delegatorAddr, moduleAccAddr, amt); err != nil {
return err
}

if err := k.trackDelegation(ctx, delegatorAddr, balances, amt); err != nil {
return sdkerrors.Wrap(err, "failed to track delegation")
}
Expand Down
Loading