@@ -618,30 +618,89 @@ func TestMigrateWithDispatchedMessage(t *testing.T) {
618
618
require .NoError (t , err )
619
619
620
620
ctx = ctx .WithBlockHeight (ctx .BlockHeight () + 1 )
621
- addr , err := keeper .Instantiate (ctx , originalContractID , creator , fred , initMsgBz , "demo contract" , deposit )
621
+ contractAddr , err := keeper .Instantiate (ctx , originalContractID , creator , fred , initMsgBz , "demo contract" , deposit )
622
622
require .NoError (t , err )
623
623
624
624
migMsg := struct {
625
625
Payout sdk.AccAddress `json:"payout"`
626
626
}{Payout : myPayoutAddr }
627
627
migMsgBz , err := json .Marshal (migMsg )
628
628
require .NoError (t , err )
629
-
630
- res , err := keeper .Migrate (ctx , addr , fred , burnerContractID , migMsgBz )
629
+ ctx = ctx . WithEventManager ( sdk . NewEventManager ()). WithBlockHeight ( ctx . BlockHeight () + 1 )
630
+ res , err := keeper .Migrate (ctx , contractAddr , fred , burnerContractID , migMsgBz )
631
631
require .NoError (t , err )
632
632
dataBz , err := base64 .StdEncoding .DecodeString (string (res .Data ))
633
633
require .NoError (t , err )
634
634
assert .Equal (t , "burnt" , string (dataBz ))
635
+ assert .Equal (t , "" , res .Log )
636
+ type dict map [string ]interface {}
637
+ expEvents := []dict {
638
+ {
639
+ "Type" : "wasm" ,
640
+ "Attr" : []dict {
641
+ {"contract_address" : contractAddr },
642
+ {"action" : "burn" },
643
+ {"payout" : myPayoutAddr },
644
+ },
645
+ },
646
+ {
647
+ "Type" : "transfer" ,
648
+ "Attr" : []dict {
649
+ {"recipient" : myPayoutAddr },
650
+ {"sender" : contractAddr },
651
+ {"amount" : "100000denom" },
652
+ },
653
+ },
654
+ {
655
+ "Type" : "message" ,
656
+ "Attr" : []dict {
657
+ {"sender" : contractAddr },
658
+ },
659
+ },
660
+ {
661
+ "Type" : "message" ,
662
+ "Attr" : []dict {
663
+ {"module" : "bank" },
664
+ },
665
+ },
666
+ }
667
+ expJsonEvts := string (mustMarshal (t , expEvents ))
668
+ assert .JSONEq (t , expJsonEvts , prettyEvents (t , ctx .EventManager ().Events ()))
635
669
636
670
// all persistent data cleared
637
- m := keeper .QueryRaw (ctx , addr , []byte ("config" ))
671
+ m := keeper .QueryRaw (ctx , contractAddr , []byte ("config" ))
638
672
require .Len (t , m , 0 )
639
673
640
674
// and all deposit tokens sent to myPayoutAddr
641
675
balance := accKeeper .GetAccount (ctx , myPayoutAddr ).GetCoins ()
642
676
assert .Equal (t , deposit , balance )
643
677
}
644
678
679
+ func prettyEvents (t * testing.T , events sdk.Events ) string {
680
+ t .Helper ()
681
+ type prettyEvent struct {
682
+ Type string
683
+ Attr []map [string ]string
684
+ }
685
+
686
+ r := make ([]prettyEvent , len (events ))
687
+ for i , e := range events {
688
+ attr := make ([]map [string ]string , len (e .Attributes ))
689
+ for j , a := range e .Attributes {
690
+ attr [j ] = map [string ]string {string (a .Key ): string (a .Value )}
691
+ }
692
+ r [i ] = prettyEvent {Type : e .Type , Attr : attr }
693
+ }
694
+ return string (mustMarshal (t , r ))
695
+ }
696
+
697
+ func mustMarshal (t * testing.T , r interface {}) []byte {
698
+ t .Helper ()
699
+ bz , err := json .Marshal (r )
700
+ require .NoError (t , err )
701
+ return bz
702
+ }
703
+
645
704
func TestUpdateContractAdmin (t * testing.T ) {
646
705
tempDir , err := ioutil .TempDir ("" , "wasm" )
647
706
require .NoError (t , err )
0 commit comments