5
5
"math/big"
6
6
7
7
tmrpcclient "github.com/cometbft/cometbft/rpc/client"
8
+ "github.com/cosmos/cosmos-sdk/client"
9
+ codectypes "github.com/cosmos/cosmos-sdk/codec/types"
10
+ "github.com/cosmos/cosmos-sdk/crypto"
8
11
sdk "github.com/cosmos/cosmos-sdk/types"
9
12
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
10
13
"github.com/ethereum/go-ethereum/common"
@@ -96,48 +99,24 @@ func (suite *BackendTestSuite) TestSetGasPrice() {
96
99
}
97
100
}
98
101
99
- // TODO (https://github.com/zeta-chain/node/issues/2302): Combine these 2 into one test since the code is identical
100
- func (suite * BackendTestSuite ) TestListAccounts () {
102
+ func (suite * BackendTestSuite ) TestAccounts () {
101
103
testCases := []struct {
102
- name string
103
- registerMock func ()
104
- expAddr []common.Address
105
- expPass bool
104
+ name string
105
+ accountsRetrievalMethod func () ([]common.Address , error )
106
+ registerMock func ()
107
+ expAddr []common.Address
108
+ expPass bool
106
109
}{
107
110
{
108
- "pass - returns empty address" ,
111
+ "pass - returns acc from keyring from ListAccounts" ,
112
+ suite .backend .ListAccounts ,
109
113
func () {},
110
114
[]common.Address {},
111
115
true ,
112
116
},
113
- }
114
-
115
- for _ , tc := range testCases {
116
- suite .Run (fmt .Sprintf ("case %s" , tc .name ), func () {
117
- suite .SetupTest () // reset test and queries
118
- tc .registerMock ()
119
-
120
- output , err := suite .backend .ListAccounts ()
121
-
122
- if tc .expPass {
123
- suite .Require ().NoError (err )
124
- suite .Require ().Equal (tc .expAddr , output )
125
- } else {
126
- suite .Require ().Error (err )
127
- }
128
- })
129
- }
130
- }
131
-
132
- func (suite * BackendTestSuite ) TestAccounts () {
133
- testCases := []struct {
134
- name string
135
- registerMock func ()
136
- expAddr []common.Address
137
- expPass bool
138
- }{
139
117
{
140
- "pass - returns empty address" ,
118
+ "pass - returns acc from keyring from Accounts" ,
119
+ suite .backend .Accounts ,
141
120
func () {},
142
121
[]common.Address {},
143
122
true ,
@@ -149,7 +128,7 @@ func (suite *BackendTestSuite) TestAccounts() {
149
128
suite .SetupTest () // reset test and queries
150
129
tc .registerMock ()
151
130
152
- output , err := suite . backend . Accounts ()
131
+ output , err := tc . accountsRetrievalMethod ()
153
132
154
133
if tc .expPass {
155
134
suite .Require ().NoError (err )
@@ -272,31 +251,55 @@ func (suite *BackendTestSuite) TestSetEtherbase() {
272
251
common.Address {},
273
252
false ,
274
253
},
275
- // TODO (https://github.com/zeta-chain/node/issues/2302): Finish this test case once ABCIQuery GetAccount is fixed
276
- //{
277
- // "pass - set the etherbase for the miner",
278
- // func() {
279
- // client := suite.backend.clientCtx.Client.(*mocks.Client)
280
- // queryClient := suite.backend.queryClient.QueryClient.(*mocks.EVMQueryClient)
281
- // RegisterStatus(client)
282
- // RegisterValidatorAccount(queryClient, suite.acc)
283
- // c := sdk.NewDecCoin("azeta", sdk.NewIntFromBigInt(big.NewInt(1)))
284
- // suite.backend.cfg.SetMinGasPrices(sdk.DecCoins{c})
285
- // delAddr, _ := suite.backend.GetCoinbase()
286
- // account, _ := suite.backend.clientCtx.AccountRetriever.GetAccount(suite.backend.clientCtx, delAddr)
287
- // delCommonAddr := common.BytesToAddress(delAddr.Bytes())
288
- // request := &authtypes.QueryAccountRequest{Address: sdk.AccAddress(delCommonAddr.Bytes()).String()}
289
- // requestMarshal, _ := request.Marshal()
290
- // RegisterABCIQueryAccount(
291
- // client,
292
- // requestMarshal,
293
- // tmrpcclient.ABCIQueryOptions{Height: int64(1), Prove: false},
294
- // account,
295
- // )
296
- // },
297
- // common.Address{},
298
- // false,
299
- //},
254
+ {
255
+ "pass - set the etherbase for the miner" ,
256
+ func () {
257
+ priv , err := ethsecp256k1 .GenerateKey ()
258
+ suite .Require ().NoError (err )
259
+
260
+ armor := crypto .EncryptArmorPrivKey (priv , "" , "eth_secp256k1" )
261
+ suite .backend .clientCtx .Keyring .ImportPrivKey ("test_key" , armor , "" )
262
+
263
+ suite .acc = sdk .AccAddress (priv .PubKey ().Address ().Bytes ())
264
+ accounts := map [string ]client.TestAccount {}
265
+ accounts [suite .acc .String ()] = client.TestAccount {
266
+ Address : suite .acc ,
267
+ Num : uint64 (1 ),
268
+ Seq : uint64 (1 ),
269
+ }
270
+
271
+ suite .backend .clientCtx = suite .backend .clientCtx .WithAccountRetriever (
272
+ client.TestAccountRetriever {Accounts : accounts },
273
+ )
274
+ var header metadata.MD
275
+ queryClient := suite .backend .queryClient .QueryClient .(* mocks.EVMQueryClient )
276
+ RegisterParams (queryClient , & header , 1 )
277
+ suite .backend .clientCtx = suite .backend .clientCtx .WithInterfaceRegistry (
278
+ codectypes .NewInterfaceRegistry (),
279
+ )
280
+ client := suite .backend .clientCtx .Client .(* mocks.Client )
281
+ RegisterStatus (client )
282
+ RegisterValidatorAccount (queryClient , suite .acc )
283
+ c := sdk .NewDecCoin ("azeta" , sdk .NewIntFromBigInt (big .NewInt (1 )))
284
+ suite .backend .cfg .SetMinGasPrices (sdk.DecCoins {c })
285
+ delAddr , _ := suite .backend .GetCoinbase ()
286
+ account , _ := suite .backend .clientCtx .AccountRetriever .GetAccount (suite .backend .clientCtx , delAddr )
287
+ delCommonAddr := common .BytesToAddress (delAddr .Bytes ())
288
+ request := & authtypes.QueryAccountRequest {Address : sdk .AccAddress (delCommonAddr .Bytes ()).String ()}
289
+ requestMarshal , _ := request .Marshal ()
290
+ RegisterUnconfirmedTxsEmpty (client , nil )
291
+ RegisterABCIQueryAccount (
292
+ client ,
293
+ requestMarshal ,
294
+ tmrpcclient.ABCIQueryOptions {Height : int64 (1 ), Prove : false },
295
+ account ,
296
+ )
297
+ RegisterABCIQuerySimulate (client , tmrpcclient.ABCIQueryOptions {Height : int64 (1 ), Prove : false })
298
+ RegisterBroadcastTxAny (client )
299
+ },
300
+ common.Address {},
301
+ true ,
302
+ },
300
303
}
301
304
302
305
for _ , tc := range testCases {
0 commit comments