-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlumera.go
More file actions
231 lines (187 loc) · 7.86 KB
/
lumera.go
File metadata and controls
231 lines (187 loc) · 7.86 KB
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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
package testutil
import (
"context"
"strconv"
"github.com/LumeraProtocol/lumera/x/action/types"
supernodeTypes "github.com/LumeraProtocol/lumera/x/supernode/types"
"github.com/LumeraProtocol/supernode/pkg/lumera"
"github.com/LumeraProtocol/supernode/pkg/lumera/modules/action"
"github.com/LumeraProtocol/supernode/pkg/lumera/modules/action_msg"
"github.com/LumeraProtocol/supernode/pkg/lumera/modules/auth"
"github.com/LumeraProtocol/supernode/pkg/lumera/modules/node"
"github.com/LumeraProtocol/supernode/pkg/lumera/modules/supernode"
"github.com/LumeraProtocol/supernode/pkg/lumera/modules/tx"
cmtservice "github.com/cosmos/cosmos-sdk/client/grpc/cmtservice"
"github.com/cosmos/cosmos-sdk/crypto/keyring"
sdktx "github.com/cosmos/cosmos-sdk/types/tx"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
)
// MockLumeraClient implements the lumera.Client interface for testing purposes
type MockLumeraClient struct {
authMod *MockAuthModule
actionMod *MockActionModule
actionMsgMod *MockActionMsgModule
supernodeMod *MockSupernodeModule
txMod *MockTxModule
nodeMod *MockNodeModule
kr keyring.Keyring
addresses []string // Store node addresses for testing
}
// NewMockLumeraClient creates a new mock Lumera client for testing
func NewMockLumeraClient(kr keyring.Keyring, addresses []string) (lumera.Client, error) {
actionMod := &MockActionModule{}
actionMsgMod := &MockActionMsgModule{}
supernodeMod := &MockSupernodeModule{addresses: addresses}
txMod := &MockTxModule{}
nodeMod := &MockNodeModule{}
return &MockLumeraClient{
authMod: &MockAuthModule{},
actionMod: actionMod,
actionMsgMod: actionMsgMod,
supernodeMod: supernodeMod,
txMod: txMod,
nodeMod: nodeMod,
kr: kr,
addresses: addresses,
}, nil
}
// Auth returns the Auth module client
func (c *MockLumeraClient) Auth() auth.Module {
return c.authMod
}
// Action returns the Action module client
func (c *MockLumeraClient) Action() action.Module {
return c.actionMod
}
// ActionMsg returns the ActionMsg module client
func (c *MockLumeraClient) ActionMsg() action_msg.Module {
return c.actionMsgMod
}
// SuperNode returns the SuperNode module client
func (c *MockLumeraClient) SuperNode() supernode.Module {
return c.supernodeMod
}
// Tx returns the Transaction module client
func (c *MockLumeraClient) Tx() tx.Module {
return c.txMod
}
// Node returns the Node module client
func (c *MockLumeraClient) Node() node.Module {
return c.nodeMod
}
// Close closes all connections
func (c *MockLumeraClient) Close() error {
return nil
}
// MockAuthModule implements the auth.Module interface for testing
type MockAuthModule struct{}
// AccountInfoByAddress mocks the behavior of retrieving account info by address
func (m *MockAuthModule) AccountInfoByAddress(ctx context.Context, addr string) (*authtypes.QueryAccountInfoResponse, error) {
// Mock response: Return an empty response for testing, modify as needed
return &authtypes.QueryAccountInfoResponse{}, nil
}
// Verify mocks the behavior of verifying data with a given account address
func (m *MockAuthModule) Verify(ctx context.Context, accAddress string, data, signature []byte) error {
// In the mock implementation, we just return nil to indicate success
return nil
}
// MockActionModule implements the action.Module interface for testing
type MockActionModule struct{}
func (m *MockActionModule) GetAction(ctx context.Context, actionID string) (*types.QueryGetActionResponse, error) {
return &types.QueryGetActionResponse{}, nil
}
func (m *MockActionModule) GetActionFee(ctx context.Context, dataSize string) (*types.QueryGetActionFeeResponse, error) {
return &types.QueryGetActionFeeResponse{}, nil
}
func (m *MockActionModule) GetParams(ctx context.Context) (*types.QueryParamsResponse, error) {
return &types.QueryParamsResponse{}, nil
}
// MockActionMsgModule implements the action_msg.Module interface for testing
type MockActionMsgModule struct{}
// Add methods as needed based on the actual action_msg.Module interface
// For now, this is a placeholder implementation
// FinalizeCascadeAction implements the required method from action_msg.Module interface
func (m *MockActionMsgModule) FinalizeCascadeAction(ctx context.Context, actionId string, signatures []string) (*action_msg.FinalizeActionResult, error) {
// Mock implementation returns success with empty result
return &action_msg.FinalizeActionResult{}, nil
}
// MockSupernodeModule implements the supernode.Module interface for testing
type MockSupernodeModule struct {
addresses []string
}
func (m *MockSupernodeModule) GetTopSuperNodesForBlock(ctx context.Context, blockHeight uint64) (*supernodeTypes.QueryGetTopSuperNodesForBlockResponse, error) {
// Create supernodes with the actual node addresses supplied in the test
supernodes := make([]*supernodeTypes.SuperNode, 0, len(m.addresses))
for i, addr := range m.addresses {
if i >= 2 { // Only use first couple for bootstrap
break
}
supernode := &supernodeTypes.SuperNode{
SupernodeAccount: addr, // Use the real account address for testing
PrevIpAddresses: []*supernodeTypes.IPAddressHistory{
{
Address: "127.0.0.1:900" + strconv.Itoa(i),
Height: 10,
},
},
}
supernodes = append(supernodes, supernode)
}
return &supernodeTypes.QueryGetTopSuperNodesForBlockResponse{
Supernodes: supernodes,
}, nil
}
func (m *MockSupernodeModule) GetSuperNode(ctx context.Context, address string) (*supernodeTypes.QueryGetSuperNodeResponse, error) {
return &supernodeTypes.QueryGetSuperNodeResponse{}, nil
}
func (m *MockSupernodeModule) GetSupernodeBySupernodeAddress(ctx context.Context, address string) (*supernodeTypes.SuperNode, error) {
return &supernodeTypes.SuperNode{}, nil
}
func (m *MockSupernodeModule) GetParams(ctx context.Context) (*supernodeTypes.QueryParamsResponse, error) {
return &supernodeTypes.QueryParamsResponse{}, nil
}
// MockTxModule implements the tx.Module interface for testing
type MockTxModule struct{}
func (m *MockTxModule) BroadcastTx(ctx context.Context, txBytes []byte, mode sdktx.BroadcastMode) (*sdktx.BroadcastTxResponse, error) {
return &sdktx.BroadcastTxResponse{}, nil
}
func (m *MockTxModule) SimulateTx(ctx context.Context, txBytes []byte) (*sdktx.SimulateResponse, error) {
return &sdktx.SimulateResponse{}, nil
}
func (m *MockTxModule) GetTx(ctx context.Context, hash string) (*sdktx.GetTxResponse, error) {
return &sdktx.GetTxResponse{}, nil
}
// MockNodeModule implements the node.Module interface for testing
type MockNodeModule struct{}
// Sign implements node.Module.
func (m *MockNodeModule) Sign(snAccAddress string, data []byte) (signature []byte, err error) {
panic("unimplemented")
}
// Verify implements node.Module.
func (m *MockNodeModule) Verify(accAddress string, data []byte, signature []byte) (err error) {
panic("unimplemented")
}
func (m *MockNodeModule) GetLatestBlock(ctx context.Context) (*cmtservice.GetLatestBlockResponse, error) {
return &cmtservice.GetLatestBlockResponse{
SdkBlock: &cmtservice.Block{
Header: cmtservice.Header{
Height: 100,
},
},
}, nil
}
func (m *MockNodeModule) GetBlockByHeight(ctx context.Context, height int64) (*cmtservice.GetBlockByHeightResponse, error) {
return &cmtservice.GetBlockByHeightResponse{}, nil
}
func (m *MockNodeModule) GetNodeInfo(ctx context.Context) (*cmtservice.GetNodeInfoResponse, error) {
return &cmtservice.GetNodeInfoResponse{}, nil
}
func (m *MockNodeModule) GetSyncing(ctx context.Context) (*cmtservice.GetSyncingResponse, error) {
return &cmtservice.GetSyncingResponse{}, nil
}
func (m *MockNodeModule) GetLatestValidatorSet(ctx context.Context) (*cmtservice.GetLatestValidatorSetResponse, error) {
return &cmtservice.GetLatestValidatorSetResponse{}, nil
}
func (m *MockNodeModule) GetValidatorSetByHeight(ctx context.Context, height int64) (*cmtservice.GetValidatorSetByHeightResponse, error) {
return &cmtservice.GetValidatorSetByHeightResponse{}, nil
}