-
Notifications
You must be signed in to change notification settings - Fork 101
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #793 from neutron-org/chore/tests-refactoring
chore: tests refactoring
- Loading branch information
Showing
17 changed files
with
268 additions
and
33 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package v505 | ||
|
||
import ( | ||
storetypes "cosmossdk.io/store/types" | ||
|
||
"github.com/neutron-org/neutron/v5/app/upgrades" | ||
) | ||
|
||
const ( | ||
// UpgradeName defines the on-chain upgrade name. | ||
UpgradeName = "v5.0.5" | ||
) | ||
|
||
var Upgrade = upgrades.Upgrade{ | ||
UpgradeName: UpgradeName, | ||
CreateUpgradeHandler: CreateUpgradeHandler, | ||
StoreUpgrades: storetypes.StoreUpgrades{}, | ||
} |
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,45 @@ | ||
package v505 | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
transfertypes "github.com/cosmos/ibc-go/v8/modules/apps/transfer/types" | ||
|
||
upgradetypes "cosmossdk.io/x/upgrade/types" | ||
"github.com/cosmos/cosmos-sdk/codec" | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
"github.com/cosmos/cosmos-sdk/types/module" | ||
|
||
"github.com/neutron-org/neutron/v5/app/upgrades" | ||
) | ||
|
||
func CreateUpgradeHandler( | ||
mm *module.Manager, | ||
configurator module.Configurator, | ||
keepers *upgrades.UpgradeKeepers, | ||
_ upgrades.StoreKeys, | ||
_ codec.Codec, | ||
) upgradetypes.UpgradeHandler { | ||
return func(c context.Context, _ upgradetypes.Plan, vm module.VersionMap) (module.VersionMap, error) { | ||
ctx := sdk.UnwrapSDKContext(c) | ||
|
||
ctx.Logger().Info("Starting module migrations...") | ||
|
||
vm, err := mm.RunMigrations(ctx, configurator, vm) | ||
if err != nil { | ||
return vm, err | ||
} | ||
|
||
transferChannels := keepers.ChannelKeeper.GetAllChannelsWithPortPrefix(ctx, keepers.TransferKeeper.GetPort(ctx)) | ||
for _, channel := range transferChannels { | ||
escrowAddress := transfertypes.GetEscrowAddress(channel.PortId, channel.ChannelId) | ||
ctx.Logger().Info("Saving escrow address", "port_id", channel.PortId, "channel_id", | ||
channel.ChannelId, "address", escrowAddress.String()) | ||
keepers.TokenFactoryKeeper.StoreEscrowAddress(ctx, escrowAddress) | ||
} | ||
|
||
ctx.Logger().Info(fmt.Sprintf("Migration {%s} applied", UpgradeName)) | ||
return vm, nil | ||
} | ||
} |
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,52 @@ | ||
package v505_test | ||
|
||
import ( | ||
"testing" | ||
|
||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
transfertypes "github.com/cosmos/ibc-go/v8/modules/apps/transfer/types" | ||
|
||
upgradetypes "cosmossdk.io/x/upgrade/types" | ||
"github.com/stretchr/testify/require" | ||
"github.com/stretchr/testify/suite" | ||
|
||
v505 "github.com/neutron-org/neutron/v5/app/upgrades/v5.0.5" | ||
"github.com/neutron-org/neutron/v5/testutil" | ||
) | ||
|
||
type UpgradeTestSuite struct { | ||
testutil.IBCConnectionTestSuite | ||
} | ||
|
||
func TestKeeperTestSuite(t *testing.T) { | ||
suite.Run(t, new(UpgradeTestSuite)) | ||
} | ||
|
||
func (suite *UpgradeTestSuite) SetupTest() { | ||
suite.IBCConnectionTestSuite.SetupTest() | ||
} | ||
|
||
func (suite *UpgradeTestSuite) TestUpgrade() { | ||
app := suite.GetNeutronZoneApp(suite.ChainA) | ||
ctx := suite.ChainA.GetContext().WithChainID("neutron-1") | ||
t := suite.T() | ||
|
||
upgrade := upgradetypes.Plan{ | ||
Name: v505.UpgradeName, | ||
Info: "some text here", | ||
Height: 100, | ||
} | ||
|
||
var escrowAddresses []sdk.AccAddress | ||
transferChannels := app.IBCKeeper.ChannelKeeper.GetAllChannelsWithPortPrefix(ctx, app.TransferKeeper.GetPort(ctx)) | ||
for _, channel := range transferChannels { | ||
escrowAddresses = append(escrowAddresses, transfertypes.GetEscrowAddress(channel.PortId, channel.ChannelId)) | ||
} | ||
require.Greater(t, len(escrowAddresses), 0) | ||
require.NoError(t, app.UpgradeKeeper.ApplyUpgrade(ctx, upgrade)) | ||
|
||
for _, escrowAddress := range escrowAddresses { | ||
require.True(t, app.TokenFactoryKeeper.IsEscrowAddress(ctx, escrowAddress)) | ||
} | ||
require.False(t, app.TokenFactoryKeeper.IsEscrowAddress(ctx, []byte{1, 2, 3, 4, 5})) | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package keeper | ||
|
||
import ( | ||
"cosmossdk.io/store/prefix" | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
"github.com/neutron-org/neutron/v5/x/tokenfactory/types" | ||
) | ||
|
||
// StoreEscrowAddress sets the total set of params. | ||
func (k Keeper) StoreEscrowAddress(ctx sdk.Context, address sdk.AccAddress) { | ||
prefixStore := prefix.NewStore(ctx.KVStore(k.storeKey), types.EscrowAddressKey) | ||
|
||
prefixStore.Set(address.Bytes(), []byte{0}) | ||
} | ||
|
||
func (k Keeper) IsEscrowAddress(ctx sdk.Context, address sdk.AccAddress) bool { | ||
prefixStore := prefix.NewStore(ctx.KVStore(k.storeKey), types.EscrowAddressKey) | ||
bz := prefixStore.Get(address.Bytes()) | ||
|
||
return len(bz) != 0 | ||
} |
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.