-
Notifications
You must be signed in to change notification settings - Fork 116
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
220 additions
and
0 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,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, | ||
} |
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,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) | ||
} | ||
} |
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,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) | ||
} |