-
Notifications
You must be signed in to change notification settings - Fork 0
/
msgs_test.go
75 lines (59 loc) · 2.29 KB
/
msgs_test.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
package types_test
import (
"testing"
sdk "github.com/cosmos/cosmos-sdk/types"
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
ibctesting "github.com/cosmos/ibc-go/v5/testing"
"github.com/stretchr/testify/require"
"github.com/ingenuity-build/quicksilver/app"
"github.com/ingenuity-build/quicksilver/utils"
"github.com/ingenuity-build/quicksilver/x/interchainquery/keeper"
"github.com/ingenuity-build/quicksilver/x/interchainquery/types"
)
var (
coordinator *ibctesting.Coordinator
chainA *ibctesting.TestChain
chainB *ibctesting.TestChain
path *ibctesting.Path
testAddress sdk.AccAddress = utils.GenerateAccAddressForTest()
)
func init() {
ibctesting.DefaultTestingAppInit = app.SetupTestingApp
}
func GetSimApp(chain *ibctesting.TestChain) *app.Quicksilver {
app, ok := chain.App.(*app.Quicksilver)
if !ok {
panic("not quicksilver app")
}
return app
}
func newSimAppPath(chainA, chainB *ibctesting.TestChain) *ibctesting.Path {
path := ibctesting.NewPath(chainA, chainB)
path.EndpointA.ChannelConfig.PortID = ibctesting.TransferPort
path.EndpointB.ChannelConfig.PortID = ibctesting.TransferPort
return path
}
func TestMsgSubmitQueryResponse(t *testing.T) {
coordinator = ibctesting.NewCoordinator(t, 2)
chainA = coordinator.GetChain(ibctesting.GetChainID(1))
chainB = coordinator.GetChain(ibctesting.GetChainID(2))
path = newSimAppPath(chainA, chainB)
coordinator.SetupConnections(path)
bondedQuery := stakingtypes.QueryValidatorsRequest{Status: stakingtypes.BondStatusBonded}
bz, err := bondedQuery.Marshal()
require.NoError(t, err)
qvr := stakingtypes.QueryValidatorsResponse{
Validators: GetSimApp(chainB).StakingKeeper.GetBondedValidatorsByPower(chainB.GetContext()),
}
msg := types.MsgSubmitQueryResponse{
ChainId: chainB.ChainID + "-N",
QueryId: keeper.GenerateQueryHash(path.EndpointB.ConnectionID, chainB.ChainID, "cosmos.staking.v1beta1.Query/Validators", bz, ""),
Result: GetSimApp(chainB).AppCodec().MustMarshalJSON(&qvr),
Height: chainB.CurrentHeader.Height,
FromAddress: testAddress.String(),
}
require.NoError(t, msg.ValidateBasic())
require.Equal(t, types.RouterKey, msg.Route())
require.Equal(t, types.TypeMsgSubmitQueryResponse, msg.Type())
require.Equal(t, testAddress.String(), msg.GetSigners()[0].String())
}