/
utils.go
111 lines (99 loc) · 3.73 KB
/
utils.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
package encoding
import (
"testing"
"github.com/cosmos/gogoproto/proto"
ica "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts"
"github.com/cosmos/ibc-go/v7/modules/apps/transfer"
ibc "github.com/cosmos/ibc-go/v7/modules/core"
ibcclientclient "github.com/cosmos/ibc-go/v7/modules/core/02-client/client"
ibctm "github.com/cosmos/ibc-go/v7/modules/light-clients/07-tendermint"
custommodule "github.com/jinxprotocol/v4-chain/protocol/app/module"
bridgemodule "github.com/jinxprotocol/v4-chain/protocol/x/bridge"
clobtypes "github.com/jinxprotocol/v4-chain/protocol/x/clob/types"
"github.com/jinxprotocol/v4-chain/protocol/x/feetiers"
perpetualtypes "github.com/jinxprotocol/v4-chain/protocol/x/perpetuals/types"
pricestypes "github.com/jinxprotocol/v4-chain/protocol/x/prices/types"
sendingtypes "github.com/jinxprotocol/v4-chain/protocol/x/sending/types"
subaccountsmodule "github.com/jinxprotocol/v4-chain/protocol/x/subaccounts"
"github.com/stretchr/testify/require"
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/module/testutil"
"github.com/cosmos/cosmos-sdk/x/auth"
"github.com/cosmos/cosmos-sdk/x/bank"
"github.com/cosmos/cosmos-sdk/x/capability"
"github.com/cosmos/cosmos-sdk/x/consensus"
"github.com/cosmos/cosmos-sdk/x/crisis"
distr "github.com/cosmos/cosmos-sdk/x/distribution"
feegrantmodule "github.com/cosmos/cosmos-sdk/x/feegrant/module"
"github.com/cosmos/cosmos-sdk/x/genutil"
genutiltypes "github.com/cosmos/cosmos-sdk/x/genutil/types"
"github.com/cosmos/cosmos-sdk/x/gov"
govclient "github.com/cosmos/cosmos-sdk/x/gov/client"
"github.com/cosmos/cosmos-sdk/x/params"
paramsclient "github.com/cosmos/cosmos-sdk/x/params/client"
"github.com/cosmos/cosmos-sdk/x/staking"
"github.com/cosmos/cosmos-sdk/x/upgrade"
upgradeclient "github.com/cosmos/cosmos-sdk/x/upgrade/client"
)
// GetTestEncodingCfg returns an encoding config for testing purposes.
func GetTestEncodingCfg() testutil.TestEncodingConfig {
encodingCfg := testutil.MakeTestEncodingConfig(
auth.AppModuleBasic{},
genutil.NewAppModuleBasic(genutiltypes.DefaultMessageValidator),
bank.AppModuleBasic{},
capability.AppModuleBasic{},
staking.AppModuleBasic{},
distr.AppModuleBasic{},
gov.NewAppModuleBasic(
[]govclient.ProposalHandler{
paramsclient.ProposalHandler,
upgradeclient.LegacyProposalHandler,
upgradeclient.LegacyCancelProposalHandler,
ibcclientclient.UpdateClientProposalHandler,
ibcclientclient.UpgradeProposalHandler,
},
),
params.AppModuleBasic{},
crisis.AppModuleBasic{},
custommodule.SlashingModuleBasic{},
feegrantmodule.AppModuleBasic{},
feetiers.AppModuleBasic{},
ibc.AppModuleBasic{},
ibctm.AppModuleBasic{},
ica.AppModuleBasic{},
upgrade.AppModuleBasic{},
transfer.AppModuleBasic{},
consensus.AppModuleBasic{},
// Custom modules
bridgemodule.AppModuleBasic{},
subaccountsmodule.AppModuleBasic{})
msgInterfacesToRegister := []sdk.Msg{
// Clob.
&clobtypes.MsgProposedOperations{},
&clobtypes.MsgPlaceOrder{},
&clobtypes.MsgCancelOrder{},
// Perpetuals.
&perpetualtypes.MsgAddPremiumVotes{},
// Prices.
&pricestypes.MsgUpdateMarketPrices{},
// Sending.
&sendingtypes.MsgCreateTransfer{},
&sendingtypes.MsgDepositToSubaccount{},
&sendingtypes.MsgWithdrawFromSubaccount{},
}
for _, msg := range msgInterfacesToRegister {
encodingCfg.InterfaceRegistry.RegisterInterface(
"/"+proto.MessageName(msg),
(*sdk.Msg)(nil),
msg,
)
}
return encodingCfg
}
// EncodeMessageToAny converts a message to an Any object for protobuf encoding.
func EncodeMessageToAny(t *testing.T, msg sdk.Msg) *codectypes.Any {
any, err := codectypes.NewAnyWithValue(msg)
require.NoError(t, err)
return any
}