@@ -22,7 +22,6 @@ import (
22
22
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
23
23
"github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1"
24
24
sdk "github.com/cosmos/cosmos-sdk/types"
25
- authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
26
25
"github.com/monerium/module-noble/v2/keeper"
27
26
"github.com/monerium/module-noble/v2/types"
28
27
"github.com/monerium/module-noble/v2/utils"
@@ -229,14 +228,11 @@ func TestBurn(t *testing.T) {
229
228
bz , _ := base64 .StdEncoding .DecodeString ("AlE8CxHR19ID5lxrVtTxSgJFlK3T+eYtyDM/vBA3Fowr" )
230
229
pubkey , _ := codectypes .NewAnyWithValue (& secp256k1.PubKey {Key : bz })
231
230
232
- account := mocks.AccountKeeper {
233
- Accounts : make (map [string ]sdk.AccountI ),
234
- }
235
231
bank := mocks.BankKeeper {
236
232
Balances : make (map [string ]sdk.Coins ),
237
233
Restriction : mocks .NoOpSendRestrictionFn ,
238
234
}
239
- k , ctx := mocks .FlorinWithKeepers (account , bank )
235
+ k , ctx := mocks .FlorinWithKeepers (bank )
240
236
goCtx := sdk .WrapSDKContext (ctx )
241
237
server := keeper .NewMsgServer (k )
242
238
@@ -257,34 +253,36 @@ func TestBurn(t *testing.T) {
257
253
// ASSERT: The action should've failed due to invalid signer.
258
254
require .ErrorIs (t , err , types .ErrInvalidSystem )
259
255
260
- // ACT: Attempt to burn with no account in state.
256
+ // ACT: Attempt to burn with invalid any.
257
+ invalidPubKey , _ := codectypes .NewAnyWithValue (& types.MsgBurn {})
261
258
_ , err = server .Burn (goCtx , & types.MsgBurn {
262
259
Denom : "ueure" ,
263
260
Signer : system .Address ,
264
- From : "noble1rwvjzk28l38js7xx6mq23nrpghd8qqvxmj6ep2" ,
261
+ PubKey : invalidPubKey ,
265
262
})
266
- // ASSERT: The action should've failed due to no account .
267
- require .ErrorIs (t , err , types . ErrNoPubKey )
263
+ // ASSERT: The action should've failed due to invalid any .
264
+ require .ErrorContains (t , err , "unable to unpack pubkey" )
268
265
269
- // ARRANGE: Set account in state, without pubkey.
270
- account .Accounts ["noble1rwvjzk28l38js7xx6mq23nrpghd8qqvxmj6ep2" ] = & authtypes.BaseAccount {}
266
+ // ACT: Attempt to burn with invalid user address.
267
+ _ , err = server .Burn (goCtx , & types.MsgBurn {
268
+ Denom : "ueure" ,
269
+ Signer : system .Address ,
270
+ From : utils .TestAccount ().Invalid ,
271
+ PubKey : pubkey ,
272
+ })
273
+ // ASSERT: The action should've failed due to invalid user address.
274
+ require .ErrorContains (t , err , "unable to decode user address" )
271
275
272
- // ACT: Attempt to burn with no pubkey in state.
276
+ // ACT: Attempt to burn with invalid public key.
277
+ invalidPubKey , _ = codectypes .NewAnyWithValue (secp256k1 .GenPrivKey ().PubKey ())
273
278
_ , err = server .Burn (goCtx , & types.MsgBurn {
274
279
Denom : "ueure" ,
275
280
Signer : system .Address ,
276
281
From : "noble1rwvjzk28l38js7xx6mq23nrpghd8qqvxmj6ep2" ,
282
+ PubKey : invalidPubKey ,
277
283
})
278
- // ASSERT: The action should've failed due to no pubkey.
279
- require .ErrorIs (t , err , types .ErrNoPubKey )
280
-
281
- // ARRANGE: Set pubkey in state.
282
- account .Accounts ["noble1rwvjzk28l38js7xx6mq23nrpghd8qqvxmj6ep2" ] = & authtypes.BaseAccount {
283
- Address : "noble1rwvjzk28l38js7xx6mq23nrpghd8qqvxmj6ep2" ,
284
- PubKey : pubkey ,
285
- AccountNumber : 0 ,
286
- Sequence : 0 ,
287
- }
284
+ // ASSERT: The action should've failed due to invalid public key.
285
+ require .ErrorIs (t , err , types .ErrInvalidPubKey )
288
286
289
287
// ACT: Attempt to burn with invalid signature.
290
288
signature , _ := base64 .StdEncoding .DecodeString ("QBrRfIqjdBvXx9zaBcuiE9P5SVesxFO/He3deyx2OE0NoSNqwmSb7b5iP2UhZRI1duiOeho3+NETUkCBv14zjQ==" )
@@ -293,6 +291,7 @@ func TestBurn(t *testing.T) {
293
291
Signer : system .Address ,
294
292
From : "noble1rwvjzk28l38js7xx6mq23nrpghd8qqvxmj6ep2" ,
295
293
Signature : signature ,
294
+ PubKey : pubkey ,
296
295
})
297
296
// ASSERT: The action should've failed due to invalid signature.
298
297
require .ErrorIs (t , err , types .ErrInvalidSignature )
@@ -305,6 +304,7 @@ func TestBurn(t *testing.T) {
305
304
From : "noble1rwvjzk28l38js7xx6mq23nrpghd8qqvxmj6ep2" ,
306
305
Amount : One ,
307
306
Signature : signature ,
307
+ PubKey : pubkey ,
308
308
})
309
309
// ASSERT: The action should've failed due to insufficient balance.
310
310
require .ErrorContains (t , err , "unable to transfer from user to module" )
@@ -319,6 +319,7 @@ func TestBurn(t *testing.T) {
319
319
From : "noble1rwvjzk28l38js7xx6mq23nrpghd8qqvxmj6ep2" ,
320
320
Amount : One ,
321
321
Signature : signature ,
322
+ PubKey : pubkey ,
322
323
})
323
324
// ASSERT: The action should've succeeded.
324
325
require .NoError (t , err )
@@ -330,7 +331,7 @@ func TestMint(t *testing.T) {
330
331
Balances : make (map [string ]sdk.Coins ),
331
332
Restriction : mocks .NoOpSendRestrictionFn ,
332
333
}
333
- k , ctx := mocks .FlorinWithKeepers (mocks. AccountKeeper {}, bank )
334
+ k , ctx := mocks .FlorinWithKeepers (bank )
334
335
goCtx := sdk .WrapSDKContext (ctx )
335
336
server := keeper .NewMsgServer (k )
336
337
@@ -375,6 +376,16 @@ func TestMint(t *testing.T) {
375
376
// ARRANGE: Generate a user account.
376
377
user := utils .TestAccount ()
377
378
379
+ // ACT: Attempt to mint with invalid user address.
380
+ _ , err = server .Mint (goCtx , & types.MsgMint {
381
+ Denom : "ueure" ,
382
+ Signer : system .Address ,
383
+ To : user .Invalid ,
384
+ Amount : math .ZeroInt (),
385
+ })
386
+ // ASSERT: The action should've failed due to invalid user address.
387
+ require .ErrorContains (t , err , "unable to decode user address" )
388
+
378
389
// ACT: Attempt to mint.
379
390
_ , err = server .Mint (goCtx , & types.MsgMint {
380
391
Denom : "ueure" ,
@@ -406,14 +417,11 @@ func TestRecover(t *testing.T) {
406
417
bz , _ := base64 .StdEncoding .DecodeString ("AlE8CxHR19ID5lxrVtTxSgJFlK3T+eYtyDM/vBA3Fowr" )
407
418
pubkey , _ := codectypes .NewAnyWithValue (& secp256k1.PubKey {Key : bz })
408
419
409
- account := mocks.AccountKeeper {
410
- Accounts : make (map [string ]sdk.AccountI ),
411
- }
412
420
bank := mocks.BankKeeper {
413
421
Balances : make (map [string ]sdk.Coins ),
414
422
Restriction : mocks .NoOpSendRestrictionFn ,
415
423
}
416
- k , ctx := mocks .FlorinWithKeepers (account , bank )
424
+ k , ctx := mocks .FlorinWithKeepers (bank )
417
425
goCtx := sdk .WrapSDKContext (ctx )
418
426
server := keeper .NewMsgServer (k )
419
427
@@ -434,34 +442,36 @@ func TestRecover(t *testing.T) {
434
442
// ASSERT: The action should've failed due to invalid signer.
435
443
require .ErrorIs (t , err , types .ErrInvalidSystem )
436
444
437
- // ACT: Attempt to recover with no account in state.
445
+ // ACT: Attempt to recover with invalid any.
446
+ invalidPubKey , _ := codectypes .NewAnyWithValue (& types.MsgRecover {})
438
447
_ , err = server .Recover (goCtx , & types.MsgRecover {
439
448
Denom : "ueure" ,
440
449
Signer : system .Address ,
441
- From : "noble1rwvjzk28l38js7xx6mq23nrpghd8qqvxmj6ep2" ,
450
+ PubKey : invalidPubKey ,
442
451
})
443
- // ASSERT: The action should've failed due to no account .
444
- require .ErrorIs (t , err , types . ErrNoPubKey )
452
+ // ASSERT: The action should've failed due to invalid any .
453
+ require .ErrorContains (t , err , "unable to unpack pubkey" )
445
454
446
- // ARRANGE: Set account in state, without pubkey.
447
- account .Accounts ["noble1rwvjzk28l38js7xx6mq23nrpghd8qqvxmj6ep2" ] = & authtypes.BaseAccount {}
455
+ // ACT: Attempt to recover with invalid user address.
456
+ _ , err = server .Recover (goCtx , & types.MsgRecover {
457
+ Denom : "ueure" ,
458
+ Signer : system .Address ,
459
+ From : utils .TestAccount ().Invalid ,
460
+ PubKey : pubkey ,
461
+ })
462
+ // ASSERT: The action should've failed due to invalid user address.
463
+ require .ErrorContains (t , err , "unable to decode user address" )
448
464
449
- // ACT: Attempt to recover with no pubkey in state.
465
+ // ACT: Attempt to recover with invalid public key.
466
+ invalidPubKey , _ = codectypes .NewAnyWithValue (secp256k1 .GenPrivKey ().PubKey ())
450
467
_ , err = server .Recover (goCtx , & types.MsgRecover {
451
468
Denom : "ueure" ,
452
469
Signer : system .Address ,
453
470
From : "noble1rwvjzk28l38js7xx6mq23nrpghd8qqvxmj6ep2" ,
471
+ PubKey : invalidPubKey ,
454
472
})
455
- // ASSERT: The action should've failed due to no pubkey.
456
- require .ErrorIs (t , err , types .ErrNoPubKey )
457
-
458
- // ARRANGE: Set pubkey in state.
459
- account .Accounts ["noble1rwvjzk28l38js7xx6mq23nrpghd8qqvxmj6ep2" ] = & authtypes.BaseAccount {
460
- Address : "noble1rwvjzk28l38js7xx6mq23nrpghd8qqvxmj6ep2" ,
461
- PubKey : pubkey ,
462
- AccountNumber : 0 ,
463
- Sequence : 0 ,
464
- }
473
+ // ASSERT: The action should've failed due to invalid public key.
474
+ require .ErrorIs (t , err , types .ErrInvalidPubKey )
465
475
466
476
// ACT: Attempt to recover with invalid signature.
467
477
signature , _ := base64 .StdEncoding .DecodeString ("QBrRfIqjdBvXx9zaBcuiE9P5SVesxFO/He3deyx2OE0NoSNqwmSb7b5iP2UhZRI1duiOeho3+NETUkCBv14zjQ==" )
@@ -470,6 +480,7 @@ func TestRecover(t *testing.T) {
470
480
Signer : system .Address ,
471
481
From : "noble1rwvjzk28l38js7xx6mq23nrpghd8qqvxmj6ep2" ,
472
482
Signature : signature ,
483
+ PubKey : pubkey ,
473
484
})
474
485
// ASSERT: The action should've failed due to invalid signature.
475
486
require .ErrorIs (t , err , types .ErrInvalidSignature )
@@ -485,20 +496,34 @@ func TestRecover(t *testing.T) {
485
496
From : "noble1rwvjzk28l38js7xx6mq23nrpghd8qqvxmj6ep2" ,
486
497
To : recipient .Address ,
487
498
Signature : signature ,
499
+ PubKey : pubkey ,
488
500
})
489
501
// ASSERT: The action should've succeeded.
490
502
require .NoError (t , err )
491
503
492
504
// ARRANGE: Give user 1 $EURe.
493
505
bank .Balances ["noble1rwvjzk28l38js7xx6mq23nrpghd8qqvxmj6ep2" ] = sdk .NewCoins (sdk .NewCoin ("ueure" , One ))
494
506
507
+ // ACT: Attempt to recover with invalid user address.
508
+ _ , err = server .Recover (goCtx , & types.MsgRecover {
509
+ Denom : "ueure" ,
510
+ Signer : system .Address ,
511
+ From : "noble1rwvjzk28l38js7xx6mq23nrpghd8qqvxmj6ep2" ,
512
+ To : recipient .Invalid ,
513
+ Signature : signature ,
514
+ PubKey : pubkey ,
515
+ })
516
+ // ASSERT: The action should've failed due to invalid user address.
517
+ require .ErrorContains (t , err , "unable to decode user address" )
518
+
495
519
// ACT: Attempt to recover.
496
520
_ , err = server .Recover (goCtx , & types.MsgRecover {
497
521
Denom : "ueure" ,
498
522
Signer : system .Address ,
499
523
From : "noble1rwvjzk28l38js7xx6mq23nrpghd8qqvxmj6ep2" ,
500
524
To : recipient .Address ,
501
525
Signature : signature ,
526
+ PubKey : pubkey ,
502
527
})
503
528
// ASSERT: The action should've succeeded.
504
529
require .NoError (t , err )
0 commit comments