Skip to content

Commit

Permalink
add v7 files
Browse files Browse the repository at this point in the history
  • Loading branch information
affanv14 committed Aug 19, 2024
1 parent e16aa6f commit f1c7989
Show file tree
Hide file tree
Showing 3 changed files with 220 additions and 0 deletions.
13 changes: 13 additions & 0 deletions protocol/app/upgrades/v7.0.0/constants.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package v_7_0_0

import (
"github.com/dydxprotocol/v4-chain/protocol/app/upgrades"
)

const (
UpgradeName = "v7.0.0"
)

var Upgrade = upgrades.Upgrade{
UpgradeName: UpgradeName,
}
20 changes: 20 additions & 0 deletions protocol/app/upgrades/v7.0.0/upgrade.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package v_7_0_0

import (
"context"

clobtypes "github.com/dydxprotocol/v4-chain/protocol/x/clob/types"

upgradetypes "cosmossdk.io/x/upgrade/types"
"github.com/cosmos/cosmos-sdk/types/module"
)

func CreateUpgradeHandler(
mm *module.Manager,
configurator module.Configurator,
clobKeeper clobtypes.ClobKeeper,
) upgradetypes.UpgradeHandler {
return func(ctx context.Context, plan upgradetypes.Plan, vm module.VersionMap) (module.VersionMap, error) {
return mm.RunMigrations(ctx, configurator, vm)
}
}
187 changes: 187 additions & 0 deletions protocol/app/upgrades/v7.0.0/upgrade_container_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,187 @@
//go:build all || container_test

package v_7_0_0_test

import (
"testing"

v_7_0_0 "github.com/dydxprotocol/v4-chain/protocol/app/upgrades/v7.0.0"
"github.com/dydxprotocol/v4-chain/protocol/testing/containertest"
"github.com/dydxprotocol/v4-chain/protocol/testutil/constants"
clobtypes "github.com/dydxprotocol/v4-chain/protocol/x/clob/types"
satypes "github.com/dydxprotocol/v4-chain/protocol/x/subaccounts/types"
"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_7_0_0.UpgradeName)
require.NoError(t, err)

postUpgradeChecks(node, t)
}

func preUpgradeSetups(node *containertest.Node, t *testing.T) {
placeOrders(node, 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
}

func placeOrders(node *containertest.Node, t *testing.T) {
require.NoError(t, containertest.BroadcastTx(
node,
&clobtypes.MsgPlaceOrder{
Order: clobtypes.Order{
OrderId: clobtypes.OrderId{
ClientId: 0,
SubaccountId: satypes.SubaccountId{
Owner: constants.AliceAccAddress.String(),
Number: 0,
},
ClobPairId: 0,
},
Side: clobtypes.Order_SIDE_BUY,
Quantums: AliceBobBTCQuantums,
Subticks: 5_000_000,
GoodTilOneof: &clobtypes.Order_GoodTilBlock{
GoodTilBlock: 20,
},
},
},
constants.AliceAccAddress.String(),
))
require.NoError(t, containertest.BroadcastTx(
node,
&clobtypes.MsgPlaceOrder{
Order: clobtypes.Order{
OrderId: clobtypes.OrderId{
ClientId: 0,
SubaccountId: satypes.SubaccountId{
Owner: constants.BobAccAddress.String(),
Number: 0,
},
ClobPairId: 0,
},
Side: clobtypes.Order_SIDE_SELL,
Quantums: AliceBobBTCQuantums,
Subticks: 5_000_000,
GoodTilOneof: &clobtypes.Order_GoodTilBlock{
GoodTilBlock: 20,
},
},
},
constants.BobAccAddress.String(),
))
require.NoError(t, containertest.BroadcastTx(
node,
&clobtypes.MsgPlaceOrder{
Order: clobtypes.Order{
OrderId: clobtypes.OrderId{
ClientId: 0,
SubaccountId: satypes.SubaccountId{
Owner: constants.CarlAccAddress.String(),
Number: 0,
},
ClobPairId: 0,
},
Side: clobtypes.Order_SIDE_BUY,
Quantums: CarlDaveBTCQuantums,
Subticks: 5_000_000,
GoodTilOneof: &clobtypes.Order_GoodTilBlock{
GoodTilBlock: 20,
},
},
},
constants.CarlAccAddress.String(),
))
require.NoError(t, containertest.BroadcastTx(
node,
&clobtypes.MsgPlaceOrder{
Order: clobtypes.Order{
OrderId: clobtypes.OrderId{
ClientId: 0,
SubaccountId: satypes.SubaccountId{
Owner: constants.DaveAccAddress.String(),
Number: 0,
},
ClobPairId: 0,
},
Side: clobtypes.Order_SIDE_SELL,
Quantums: CarlDaveBTCQuantums,
Subticks: 5_000_000,
GoodTilOneof: &clobtypes.Order_GoodTilBlock{
GoodTilBlock: 20,
},
},
},
constants.DaveAccAddress.String(),
))
require.NoError(t, containertest.BroadcastTx(
node,
&clobtypes.MsgPlaceOrder{
Order: clobtypes.Order{
OrderId: clobtypes.OrderId{
ClientId: 0,
SubaccountId: satypes.SubaccountId{
Owner: constants.CarlAccAddress.String(),
Number: 0,
},
ClobPairId: 1,
},
Side: clobtypes.Order_SIDE_BUY,
Quantums: CarlDaveETHQuantums,
Subticks: 5_000_000,
GoodTilOneof: &clobtypes.Order_GoodTilBlock{
GoodTilBlock: 20,
},
},
},
constants.CarlAccAddress.String(),
))
require.NoError(t, containertest.BroadcastTx(
node,
&clobtypes.MsgPlaceOrder{
Order: clobtypes.Order{
OrderId: clobtypes.OrderId{
ClientId: 0,
SubaccountId: satypes.SubaccountId{
Owner: constants.DaveAccAddress.String(),
Number: 0,
},
ClobPairId: 1,
},
Side: clobtypes.Order_SIDE_SELL,
Quantums: CarlDaveETHQuantums,
Subticks: 5_000_000,
GoodTilOneof: &clobtypes.Order_GoodTilBlock{
GoodTilBlock: 20,
},
},
},
constants.DaveAccAddress.String(),
))
err := node.Wait(2)
require.NoError(t, err)
}

0 comments on commit f1c7989

Please sign in to comment.