-
Notifications
You must be signed in to change notification settings - Fork 103
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(app): add upgrade handlers (#1121)
* feat: wip mainnet upgrade handler * wip: add ecocredit state migrations * implement recover funds from lost account * chore: fix tests * chore: add test * chore: fix test * Update app/stable_appconfig.go * chore: cleanup * chore: cleanup * feat: add redwood migrations * Update x/ecocredit/migrations/v3/patch.go * feat: add redwood migration tests * chore: revert core_test.go * Update app/stable_appconfig.go Co-authored-by: Ryan Christoffersen <12519942+ryanchristo@users.noreply.github.com> * chore: review changes * chore: add redwood upgrade handler * Update app/stable_appconfig.go Co-authored-by: Ryan Christoffersen <12519942+ryanchristo@users.noreply.github.com> * Update app/stable_appconfig.go * Update x/ecocredit/migrations/v3/patch_test.go Co-authored-by: Cory <cjlevinson@gmail.com> * Update x/ecocredit/migrations/v3/patch_test.go Co-authored-by: Cory <cjlevinson@gmail.com> * Update x/ecocredit/migrations/v3/patch_test.go Co-authored-by: Cory <cjlevinson@gmail.com> * Update x/ecocredit/migrations/v3/patch_test.go Co-authored-by: Cory <cjlevinson@gmail.com> * chore: review changes * chore: fix errors * Update x/ecocredit/migrations/v3/patch.go Co-authored-by: Cory <cjlevinson@gmail.com> * update reference id comments and checks Co-authored-by: Ryan Christoffersen <12519942+ryanchristo@users.noreply.github.com> Co-authored-by: Anil Kumar Kammari <anil@vitwit.com> Co-authored-by: Cory <cjlevinson@gmail.com>
- Loading branch information
1 parent
abd6de2
commit 1abcee8
Showing
10 changed files
with
1,248 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
//go:build !experimental | ||
// +build !experimental | ||
|
||
package app | ||
|
||
import ( | ||
"encoding/json" | ||
"os" | ||
"testing" | ||
"time" | ||
|
||
"github.com/CosmWasm/wasmd/app" | ||
"github.com/cosmos/cosmos-sdk/simapp" | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" | ||
vestingtypes "github.com/cosmos/cosmos-sdk/x/auth/vesting/types" | ||
minttypes "github.com/cosmos/cosmos-sdk/x/mint/types" | ||
"github.com/stretchr/testify/require" | ||
abci "github.com/tendermint/tendermint/abci/types" | ||
"github.com/tendermint/tendermint/libs/log" | ||
tmproto "github.com/tendermint/tendermint/proto/tendermint/types" | ||
dbm "github.com/tendermint/tm-db" | ||
) | ||
|
||
func TestLostFunds(t *testing.T) { | ||
// address with funds inaccessible | ||
lostAddr, err := sdk.AccAddressFromBech32("regen1c3lpjaq0ytdtsrnjqzmtj3hceavl8fe2vtkj7f") | ||
require.NoError(t, err) | ||
|
||
// address that the community member has access to | ||
newAddr, err := sdk.AccAddressFromBech32("regen14tpuqrwf95evu3ejm9z7dn20ttcyzqy3jjpfv4") | ||
require.NoError(t, err) | ||
|
||
vestingPeriods := vestingtypes.Periods{ | ||
{ | ||
Length: 0, | ||
Amount: sdk.NewCoins(sdk.NewInt64Coin("uregen", 1000000)), | ||
}, | ||
{ | ||
Length: 28630800, | ||
Amount: sdk.NewCoins(sdk.NewInt64Coin("uregen", 406041682)), | ||
}, | ||
{ | ||
Length: 2629746, | ||
Amount: sdk.NewCoins(sdk.NewInt64Coin("uregen", 406041666)), | ||
}, | ||
{ | ||
Length: 2629746, | ||
Amount: sdk.NewCoins(sdk.NewInt64Coin("uregen", 406041666)), | ||
}, | ||
} | ||
|
||
encCfg := MakeEncodingConfig() | ||
db := dbm.NewMemDB() | ||
|
||
regenApp := NewRegenApp(log.NewTMLogger(log.NewSyncWriter(os.Stdout)), db, nil, true, map[int64]bool{}, | ||
app.DefaultNodeHome, 0, encCfg, simapp.EmptyAppOptions{}, nil) | ||
bz := NewDefaultGenesisState(encCfg.Marshaler) | ||
stateBytes, err := json.MarshalIndent(bz, "", " ") | ||
require.NoError(t, err) | ||
|
||
regenApp.InitChain( | ||
abci.RequestInitChain{ | ||
Validators: []abci.ValidatorUpdate{}, | ||
ConsensusParams: app.DefaultConsensusParams, | ||
AppStateBytes: stateBytes, | ||
}, | ||
) | ||
|
||
ctx := regenApp.BaseApp.NewContext(false, tmproto.Header{}) | ||
|
||
regenApp.AccountKeeper.SetAccount(ctx, authtypes.NewBaseAccount(newAddr, nil, 9068, 4)) | ||
oldAccountBalance := sdk.NewCoins(sdk.NewCoin("uregen", sdk.NewInt(1219125014))) | ||
regenApp.AccountKeeper.SetAccount(ctx, vestingtypes.NewPeriodicVestingAccount(authtypes.NewBaseAccount(lostAddr, nil, 146, 0), | ||
oldAccountBalance, 1618498800, vestingPeriods)) | ||
|
||
regenApp.BankKeeper.MintCoins(ctx, minttypes.ModuleName, oldAccountBalance) | ||
regenApp.BankKeeper.SendCoinsFromModuleToAccount(ctx, minttypes.ModuleName, lostAddr, oldAccountBalance) | ||
|
||
newAccountBalance := sdk.NewCoins(sdk.NewInt64Coin("uregen", 10747843)) | ||
regenApp.BankKeeper.MintCoins(ctx, minttypes.ModuleName, newAccountBalance) | ||
regenApp.BankKeeper.SendCoinsFromModuleToAccount(ctx, minttypes.ModuleName, newAddr, newAccountBalance) | ||
|
||
ctx = ctx.WithBlockTime(time.Now()) | ||
err = recoverFunds(ctx, regenApp.AccountKeeper, regenApp.BankKeeper) | ||
require.NoError(t, err) | ||
|
||
require.True(t, regenApp.BankKeeper.GetBalance(ctx, lostAddr, "uregen").IsZero()) | ||
newbalance := regenApp.BankKeeper.GetAllBalances(ctx, newAddr) | ||
// verify new account pre-existing balance also included | ||
require.Equal(t, newbalance, newAccountBalance.Add(oldAccountBalance...)) | ||
|
||
acc := regenApp.AccountKeeper.GetAccount(ctx, newAddr) | ||
pva, ok := acc.(*vestingtypes.PeriodicVestingAccount) | ||
require.True(t, ok) | ||
require.Equal(t, pva.GetVestingPeriods().String(), vestingPeriods.String()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.