Skip to content

Commit

Permalink
Merge pull request #39 from regen-network/clevinson/vesting-accounts-…
Browse files Browse the repository at this point in the history
…patch

Fix VestingAccount bug in track delegation / undelegation
  • Loading branch information
clevinson authored Mar 29, 2021
2 parents 7648bfc + 620c1c9 commit 448cfce
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
2 changes: 1 addition & 1 deletion client/keys/import_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func Test_runImportCmd(t *testing.T) {
kbHome := t.TempDir()
kb, err := keyring.New(sdk.KeyringServiceName(), keyring.BackendTest, kbHome, mockIn)

clientCtx := client.Context{}.WithKeyring(kb)
clientCtx := client.Context{}.WithKeyring(kb).WithKeyringDir(kbHome)
ctx := context.WithValue(context.Background(), client.ClientContextKey, &clientCtx)

require.NoError(t, err)
Expand Down
2 changes: 2 additions & 0 deletions x/bank/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,7 @@ func (k BaseKeeper) trackDelegation(ctx sdk.Context, addr sdk.AccAddress, blockT
if ok {
// TODO: return error on account.TrackDelegation
vacc.TrackDelegation(blockTime, balance, amt)
k.ak.SetAccount(ctx, acc)
}

return nil
Expand All @@ -407,6 +408,7 @@ func (k BaseKeeper) trackUndelegation(ctx sdk.Context, addr sdk.AccAddress, amt
if ok {
// TODO: return error on account.TrackUndelegation
vacc.TrackUndelegation(amt)
k.ak.SetAccount(ctx, acc)
}

return nil
Expand Down
14 changes: 14 additions & 0 deletions x/bank/keeper/keeper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"testing"
"time"


"github.com/stretchr/testify/suite"
abci "github.com/tendermint/tendermint/abci/types"
tmproto "github.com/tendermint/tendermint/proto/tendermint/types"
Expand All @@ -15,6 +16,7 @@ import (
authkeeper "github.com/cosmos/cosmos-sdk/x/auth/keeper"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
vesting "github.com/cosmos/cosmos-sdk/x/auth/vesting/types"
"github.com/cosmos/cosmos-sdk/x/auth/vesting/exported"
"github.com/cosmos/cosmos-sdk/x/bank/keeper"
"github.com/cosmos/cosmos-sdk/x/bank/types"
)
Expand Down Expand Up @@ -905,6 +907,12 @@ func (suite *IntegrationTestSuite) TestDelegateCoins() {
// require the ability for a vesting account to delegate
suite.Require().NoError(app.BankKeeper.DelegateCoins(ctx, addr1, addrModule, delCoins))
suite.Require().Equal(delCoins, app.BankKeeper.GetAllBalances(ctx, addr1))

// require that delegated vesting amount is equal to what was delegated with DelegateCoins
acc = app.AccountKeeper.GetAccount(ctx, addr1)
vestingAcc, ok := acc.(exported.VestingAccount)
suite.Require().True(ok)
suite.Require().Equal(delCoins, vestingAcc.GetDelegatedVesting())
}

func (suite *IntegrationTestSuite) TestDelegateCoins_Invalid() {
Expand Down Expand Up @@ -982,6 +990,12 @@ func (suite *IntegrationTestSuite) TestUndelegateCoins() {

suite.Require().Equal(origCoins, app.BankKeeper.GetAllBalances(ctx, addr1))
suite.Require().True(app.BankKeeper.GetAllBalances(ctx, addrModule).Empty())

// require that delegated vesting amount is completely empty, since they were completely undelegated
acc = app.AccountKeeper.GetAccount(ctx, addr1)
vestingAcc, ok := acc.(exported.VestingAccount)
suite.Require().True(ok)
suite.Require().Empty(vestingAcc.GetDelegatedVesting())
}

func (suite *IntegrationTestSuite) TestUndelegateCoins_Invalid() {
Expand Down

0 comments on commit 448cfce

Please sign in to comment.