@@ -45,7 +45,7 @@ func (s *TestSuite) SetupTest() {
45
45
s .app = app
46
46
s .ctx = ctx
47
47
s .queryClient = queryClient
48
- s .addrs = simapp .AddTestAddrsIncremental (app , ctx , 3 , sdk .NewInt (30000000 ))
48
+ s .addrs = simapp .AddTestAddrsIncremental (app , ctx , 7 , sdk .NewInt (30000000 ))
49
49
}
50
50
51
51
func (s * TestSuite ) TestKeeper () {
@@ -366,6 +366,85 @@ func (s *TestSuite) TestDequeueAllGrantsQueue() {
366
366
require .Len (authzs , 1 )
367
367
}
368
368
369
+ func (s * TestSuite ) TestGetAuthorization () {
370
+ addr1 := s .addrs [3 ]
371
+ addr2 := s .addrs [4 ]
372
+ addr3 := s .addrs [5 ]
373
+ addr4 := s .addrs [6 ]
374
+
375
+ genAuthMulti := authz .NewGenericAuthorization (sdk .MsgTypeURL (& banktypes.MsgMultiSend {}))
376
+ genAuthSend := authz .NewGenericAuthorization (sdk .MsgTypeURL (& banktypes.MsgSend {}))
377
+ sendAuth := banktypes .NewSendAuthorization (coins10 )
378
+
379
+ start := s .ctx .BlockHeader ().Time
380
+ expired := start .Add (time .Duration (1 ) * time .Second )
381
+ notExpired := start .Add (time .Duration (5 ) * time .Hour )
382
+
383
+ s .Require ().NoError (s .app .AuthzKeeper .SaveGrant (s .ctx , addr1 , addr2 , genAuthMulti , nil ), "creating grant 1->2" )
384
+ s .Require ().NoError (s .app .AuthzKeeper .SaveGrant (s .ctx , addr1 , addr3 , genAuthSend , & expired ), "creating grant 1->3" )
385
+ s .Require ().NoError (s .app .AuthzKeeper .SaveGrant (s .ctx , addr1 , addr4 , sendAuth , & notExpired ), "creating grant 1->4" )
386
+ // Without access to private keeper methods, I don't know how to save a grant with an invalid authorization.
387
+ newCtx := s .ctx .WithBlockTime (start .Add (time .Duration (1 ) * time .Minute ))
388
+
389
+ tests := []struct {
390
+ name string
391
+ grantee sdk.AccAddress
392
+ granter sdk.AccAddress
393
+ msgType string
394
+ expAuth authz.Authorization
395
+ expExp * time.Time
396
+ }{
397
+ {
398
+ name : "grant has nil exp and is returned" ,
399
+ grantee : addr1 ,
400
+ granter : addr2 ,
401
+ msgType : genAuthMulti .MsgTypeURL (),
402
+ expAuth : genAuthMulti ,
403
+ expExp : nil ,
404
+ },
405
+ {
406
+ name : "grant is expired not returned" ,
407
+ grantee : addr1 ,
408
+ granter : addr3 ,
409
+ msgType : genAuthSend .MsgTypeURL (),
410
+ expAuth : nil ,
411
+ expExp : nil ,
412
+ },
413
+ {
414
+ name : "grant is not expired and is returned" ,
415
+ grantee : addr1 ,
416
+ granter : addr4 ,
417
+ msgType : sendAuth .MsgTypeURL (),
418
+ expAuth : sendAuth ,
419
+ expExp : & notExpired ,
420
+ },
421
+ {
422
+ name : "grant is not expired but wrong msg type returns nil" ,
423
+ grantee : addr1 ,
424
+ granter : addr4 ,
425
+ msgType : genAuthMulti .MsgTypeURL (),
426
+ expAuth : nil ,
427
+ expExp : nil ,
428
+ },
429
+ {
430
+ name : "no grant exists between the two" ,
431
+ grantee : addr2 ,
432
+ granter : addr3 ,
433
+ msgType : genAuthSend .MsgTypeURL (),
434
+ expAuth : nil ,
435
+ expExp : nil ,
436
+ },
437
+ }
438
+
439
+ for _ , tc := range tests {
440
+ s .Run (tc .name , func () {
441
+ actAuth , actExp := s .app .AuthzKeeper .GetAuthorization (newCtx , tc .grantee , tc .granter , tc .msgType )
442
+ s .Assert ().Equal (tc .expAuth , actAuth , "authorization" )
443
+ s .Assert ().Equal (tc .expExp , actExp , "expiration" )
444
+ })
445
+ }
446
+ }
447
+
369
448
func TestTestSuite (t * testing.T ) {
370
449
suite .Run (t , new (TestSuite ))
371
450
}
0 commit comments