-
Notifications
You must be signed in to change notification settings - Fork 115
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
[TRA-654] add upgrade handler for v8.0.0 #2395
Open
shrenujb
wants to merge
5
commits into
main
Choose a base branch
from
tra654
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 4 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 was deleted.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package v_8_0_0 | ||
|
||
import ( | ||
store "cosmossdk.io/store/types" | ||
"github.com/dydxprotocol/v4-chain/protocol/app/upgrades" | ||
) | ||
|
||
const ( | ||
UpgradeName = "v7.1.0" | ||
) | ||
shrenujb marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
var Upgrade = upgrades.Upgrade{ | ||
UpgradeName: UpgradeName, | ||
StoreUpgrades: store.StoreUpgrades{ | ||
Added: []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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package v_8_0_0 | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
listingtypes "github.com/dydxprotocol/v4-chain/protocol/x/listing/types" | ||
|
||
upgradetypes "cosmossdk.io/x/upgrade/types" | ||
"github.com/cosmos/cosmos-sdk/types/module" | ||
"github.com/dydxprotocol/v4-chain/protocol/lib" | ||
listingkeeper "github.com/dydxprotocol/v4-chain/protocol/x/listing/keeper" | ||
) | ||
|
||
func initListingModuleState(ctx sdk.Context, listingKeeper listingkeeper.Keeper) { | ||
// Set hard cap on listed markets | ||
err := listingKeeper.SetMarketsHardCap(ctx, 500) | ||
if err != nil { | ||
panic(fmt.Sprintf("failed to set markets hard cap: %s", err)) | ||
} | ||
|
||
// Set listing vault deposit params | ||
err = listingKeeper.SetListingVaultDepositParams( | ||
ctx, | ||
listingtypes.DefaultParams(), | ||
) | ||
if err != nil { | ||
panic(fmt.Sprintf("failed to set listing vault deposit params: %s", err)) | ||
} | ||
} | ||
|
||
func CreateUpgradeHandler( | ||
mm *module.Manager, | ||
configurator module.Configurator, | ||
listingKeeper listingkeeper.Keeper, | ||
) upgradetypes.UpgradeHandler { | ||
return func(ctx context.Context, plan upgradetypes.Plan, vm module.VersionMap) (module.VersionMap, error) { | ||
sdkCtx := lib.UnwrapSDKContext(ctx, "app/upgrades") | ||
sdkCtx.Logger().Info(fmt.Sprintf("Running %s Upgrade...", UpgradeName)) | ||
|
||
initListingModuleState(sdkCtx, listingKeeper) | ||
|
||
return mm.RunMigrations(ctx, configurator, vm) | ||
} | ||
} |
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,82 @@ | ||
//go:build all || container_test | ||
|
||
package v_8_0_0_test | ||
|
||
import ( | ||
"testing" | ||
|
||
v_8_0_0 "github.com/dydxprotocol/v4-chain/protocol/app/upgrades/v7.1.0" | ||
shrenujb marked this conversation as resolved.
Show resolved
Hide resolved
|
||
listingtypes "github.com/dydxprotocol/v4-chain/protocol/x/listing/types" | ||
|
||
"github.com/cosmos/gogoproto/proto" | ||
|
||
"github.com/dydxprotocol/v4-chain/protocol/testing/containertest" | ||
"github.com/dydxprotocol/v4-chain/protocol/testutil/constants" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
const ( | ||
AliceBobBTCQuantums = 1_000_000 | ||
CarlDaveBTCQuantums = 2_000_000 | ||
CarlDaveETHQuantums = 4_000_000 | ||
) | ||
|
||
func TestStateUpgrade(t *testing.T) { | ||
testnet, err := containertest.NewTestnetWithPreupgradeGenesis() | ||
require.NoError(t, err, "failed to create testnet - is docker daemon running?") | ||
err = testnet.Start() | ||
require.NoError(t, err) | ||
defer testnet.MustCleanUp() | ||
node := testnet.Nodes["alice"] | ||
nodeAddress := constants.AliceAccAddress.String() | ||
|
||
preUpgradeSetups(node, t) | ||
preUpgradeChecks(node, t) | ||
|
||
err = containertest.UpgradeTestnet(nodeAddress, t, node, v_8_0_0.UpgradeName) | ||
require.NoError(t, err) | ||
|
||
postUpgradeChecks(node, t) | ||
} | ||
|
||
func preUpgradeSetups(node *containertest.Node, t *testing.T) {} | ||
|
||
func preUpgradeChecks(node *containertest.Node, t *testing.T) { | ||
// Add test for your upgrade handler logic below | ||
} | ||
|
||
func postUpgradeChecks(node *containertest.Node, t *testing.T) { | ||
// Add test for your upgrade handler logic below | ||
postUpgradeListingModuleStateCheck(node, t) | ||
} | ||
shrenujb marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
func postUpgradeListingModuleStateCheck(node *containertest.Node, t *testing.T) { | ||
// Check that the listing module state has been initialized with the hard cap and default deposit params. | ||
resp, err := containertest.Query( | ||
node, | ||
listingtypes.NewQueryClient, | ||
listingtypes.QueryClient.ListingVaultDepositParams, | ||
&listingtypes.QueryListingVaultDepositParams{}, | ||
) | ||
require.NoError(t, err) | ||
require.NotNil(t, resp) | ||
|
||
listingVaultDepositParamsResp := listingtypes.QueryListingVaultDepositParamsResponse{} | ||
err = proto.UnmarshalText(resp.String(), &listingVaultDepositParamsResp) | ||
require.NoError(t, err) | ||
require.Equal(t, listingtypes.DefaultParams(), listingVaultDepositParamsResp.Params) | ||
|
||
resp, err = containertest.Query( | ||
node, | ||
listingtypes.NewQueryClient, | ||
listingtypes.QueryClient.MarketsHardCap, | ||
&listingtypes.QueryMarketsHardCap{}, | ||
) | ||
require.NoError(t, err) | ||
require.NotNil(t, resp) | ||
|
||
marketsHardCapResp := listingtypes.QueryMarketsHardCapResponse{} | ||
err = proto.UnmarshalText(resp.String(), &marketsHardCapResp) | ||
require.NoError(t, err) | ||
require.Equal(t, uint32(500), marketsHardCapResp.HardCap) | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💡 Codebase verification
Inconsistent Upgrade Version in
constants.go
The
UpgradeName
constant inprotocol/app/upgrades/v8.0.0/constants.go
is set to"v7.1.0"
, which does not align with the package namev_8_0_0
and the directory pathv8.0.0
. Please update theUpgradeName
to"v8.0.0"
to ensure consistency across the codebase.🔗 Analysis chain
Verify package name consistency with upgrade version
The package name
v_8_0_0
and file pathv8.0.0
suggest this is for version 8.0.0, but theUpgradeName
constant (line 9) is set to "v7.1.0". Please ensure that the package name, file path, and upgrade version are consistent throughout the file and the entire upgrade process.🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
Length of output: 784