@@ -843,6 +843,163 @@ func TestHandler_DoubleTimeRejectUpgrade(t *testing.T) {
843
843
require .False (t , isFound )
844
844
}
845
845
846
+ func TestHandler_DoubleTimeProposeUpgradePlanHeightBiggerThanBlockHeight (t * testing.T ) {
847
+ setup := Setup (t )
848
+
849
+ trusteeAccAddress1 := testdata .GenerateAccAddress ()
850
+ trusteeAccAddress2 := testdata .GenerateAccAddress ()
851
+ trusteeAccAddress3 := testdata .GenerateAccAddress ()
852
+
853
+ setup .AddAccount (trusteeAccAddress1 , []dclauthtypes.AccountRole {dclauthtypes .Trustee })
854
+ setup .AddAccount (trusteeAccAddress2 , []dclauthtypes.AccountRole {dclauthtypes .Trustee })
855
+ setup .AddAccount (trusteeAccAddress3 , []dclauthtypes.AccountRole {dclauthtypes .Trustee })
856
+ setup .DclauthKeeper .On ("CountAccountsWithRole" , mock .Anything , dclauthtypes .Trustee ).Return (3 )
857
+
858
+ // propose new upgrade with plan height > block height
859
+ msgProposeUpgrade := NewMsgProposeUpgrade (trusteeAccAddress1 )
860
+ msgProposeUpgrade .Plan .Height = 3
861
+ setup .Ctx = setup .Ctx .WithBlockHeight (1 )
862
+
863
+ setup .UpgradeKeeper .On ("ScheduleUpgrade" , mock .Anything , msgProposeUpgrade .Plan ).Return (nil ).Once ()
864
+ _ , err := setup .Handler (setup .Ctx , msgProposeUpgrade )
865
+ require .NoError (t , err )
866
+
867
+ // second time propose upgrade same plan name with plan height > block height
868
+ msgProposeUpgrade = NewMsgProposeUpgrade (trusteeAccAddress2 )
869
+ msgProposeUpgrade .Plan .Height = 5
870
+ setup .Ctx = setup .Ctx .WithBlockHeight (2 )
871
+
872
+ setup .UpgradeKeeper .On ("ScheduleUpgrade" , mock .Anything , msgProposeUpgrade .Plan ).Return (nil ).Once ()
873
+ _ , err = setup .Handler (setup .Ctx , msgProposeUpgrade )
874
+ require .Error (t , err )
875
+ require .True (t , types .ErrProposedUpgradeAlreadyExists .Is (err ))
876
+ }
877
+
878
+ func TestHandler_ApproveUpgradePlanHeightLessThanBlockHeight_And_ReProposeUpgradePlanHeightBiggerThanBlockHeight (t * testing.T ) {
879
+ setup := Setup (t )
880
+
881
+ trusteeAccAddress1 := testdata .GenerateAccAddress ()
882
+ trusteeAccAddress2 := testdata .GenerateAccAddress ()
883
+ trusteeAccAddress3 := testdata .GenerateAccAddress ()
884
+ setup .AddAccount (trusteeAccAddress1 , []dclauthtypes.AccountRole {dclauthtypes .Trustee })
885
+ setup .AddAccount (trusteeAccAddress2 , []dclauthtypes.AccountRole {dclauthtypes .Trustee })
886
+ setup .AddAccount (trusteeAccAddress3 , []dclauthtypes.AccountRole {dclauthtypes .Trustee })
887
+ setup .DclauthKeeper .On ("CountAccountsWithRole" , mock .Anything , dclauthtypes .Trustee ).Return (3 )
888
+
889
+ // propose new upgrade
890
+ proposeUpgrade := NewMsgProposeUpgrade (trusteeAccAddress1 )
891
+ proposeUpgrade .Plan .Height = 2
892
+ setup .Ctx = setup .Ctx .WithBlockHeight (1 )
893
+
894
+ setup .UpgradeKeeper .On ("ScheduleUpgrade" , mock .Anything , proposeUpgrade .Plan ).Return (nil ).Once ()
895
+ _ , err := setup .Handler (setup .Ctx , proposeUpgrade )
896
+ require .NoError (t , err )
897
+
898
+ // check first proposed upgrade for being created
899
+ proposedUpgrade , isFound := setup .Keeper .GetProposedUpgrade (setup .Ctx , proposeUpgrade .Plan .Name )
900
+ require .True (t , isFound )
901
+
902
+ require .Equal (t , proposeUpgrade .Plan , proposedUpgrade .Plan )
903
+ require .Equal (t , proposeUpgrade .Creator , proposedUpgrade .Creator )
904
+
905
+ require .Equal (t , 1 , len (proposedUpgrade .Approvals ))
906
+
907
+ require .Equal (t , proposeUpgrade .Creator , proposedUpgrade .Approvals [0 ].Address )
908
+ require .Equal (t , proposeUpgrade .Time , proposedUpgrade .Approvals [0 ].Time )
909
+ require .Equal (t , proposeUpgrade .Info , proposedUpgrade .Approvals [0 ].Info )
910
+
911
+ // create approve message from trustee2
912
+ msgApproveUpgrade := NewMsgApproveUpgrade (trusteeAccAddress2 )
913
+
914
+ // approve new upgrade with plan height < block height
915
+ setup .Ctx = setup .Ctx .WithBlockHeight (3 )
916
+ setup .UpgradeKeeper .On ("ScheduleUpgrade" , mock .Anything , proposeUpgrade .Plan ).Return (sdkerrors .ErrInvalidRequest ).Once ()
917
+ _ , err = setup .Handler (setup .Ctx , msgApproveUpgrade )
918
+ require .Error (t , err , sdkerrors .ErrInvalidRequest )
919
+
920
+ // check upgrade for not being added to ApprovedUpgrade store
921
+ _ , isFound = setup .Keeper .GetApprovedUpgrade (setup .Ctx , proposeUpgrade .Plan .Name )
922
+ require .False (t , isFound )
923
+
924
+ // second time propose upgrade with same name with propose height > current height
925
+ proposeUpgrade = NewMsgProposeUpgrade (trusteeAccAddress3 )
926
+ proposeUpgrade .Plan .Height = 5
927
+
928
+ setup .UpgradeKeeper .On ("ScheduleUpgrade" , mock .Anything , proposeUpgrade .Plan ).Return (nil ).Once ()
929
+ _ , err = setup .Handler (setup .Ctx , proposeUpgrade )
930
+ require .NoError (t , err )
931
+
932
+ // check second proposed upgrade for being created
933
+ proposedUpgrade , isFound = setup .Keeper .GetProposedUpgrade (setup .Ctx , proposeUpgrade .Plan .Name )
934
+ require .True (t , isFound )
935
+
936
+ require .Equal (t , proposeUpgrade .Plan , proposedUpgrade .Plan )
937
+ require .Equal (t , proposeUpgrade .Creator , proposedUpgrade .Creator )
938
+
939
+ require .Equal (t , 1 , len (proposedUpgrade .Approvals ))
940
+
941
+ require .Equal (t , proposeUpgrade .Creator , proposedUpgrade .Approvals [0 ].Address )
942
+ require .Equal (t , proposeUpgrade .Time , proposedUpgrade .Approvals [0 ].Time )
943
+ require .Equal (t , proposeUpgrade .Info , proposedUpgrade .Approvals [0 ].Info )
944
+ }
945
+
946
+ func TestHandler_ApproveUpgradePlanHeightLessThanBlockHeight_And_ReProposeUpgradePlanHeightLessThanBlockHeight (t * testing.T ) {
947
+ setup := Setup (t )
948
+
949
+ trusteeAccAddress1 := testdata .GenerateAccAddress ()
950
+ trusteeAccAddress2 := testdata .GenerateAccAddress ()
951
+ trusteeAccAddress3 := testdata .GenerateAccAddress ()
952
+ setup .AddAccount (trusteeAccAddress1 , []dclauthtypes.AccountRole {dclauthtypes .Trustee })
953
+ setup .AddAccount (trusteeAccAddress2 , []dclauthtypes.AccountRole {dclauthtypes .Trustee })
954
+ setup .AddAccount (trusteeAccAddress3 , []dclauthtypes.AccountRole {dclauthtypes .Trustee })
955
+ setup .DclauthKeeper .On ("CountAccountsWithRole" , mock .Anything , dclauthtypes .Trustee ).Return (3 )
956
+
957
+ // propose new upgrade
958
+ proposeUpgrade := NewMsgProposeUpgrade (trusteeAccAddress1 )
959
+ proposeUpgrade .Plan .Height = 2
960
+ setup .Ctx = setup .Ctx .WithBlockHeight (1 )
961
+
962
+ setup .UpgradeKeeper .On ("ScheduleUpgrade" , mock .Anything , proposeUpgrade .Plan ).Return (nil ).Once ()
963
+ _ , err := setup .Handler (setup .Ctx , proposeUpgrade )
964
+ require .NoError (t , err )
965
+
966
+ // check first proposed upgrade for being created
967
+ proposedUpgrade , isFound := setup .Keeper .GetProposedUpgrade (setup .Ctx , proposeUpgrade .Plan .Name )
968
+ require .True (t , isFound )
969
+
970
+ require .Equal (t , proposeUpgrade .Plan , proposedUpgrade .Plan )
971
+ require .Equal (t , proposeUpgrade .Creator , proposedUpgrade .Creator )
972
+
973
+ require .Equal (t , 1 , len (proposedUpgrade .Approvals ))
974
+
975
+ require .Equal (t , proposeUpgrade .Creator , proposedUpgrade .Approvals [0 ].Address )
976
+ require .Equal (t , proposeUpgrade .Time , proposedUpgrade .Approvals [0 ].Time )
977
+ require .Equal (t , proposeUpgrade .Info , proposedUpgrade .Approvals [0 ].Info )
978
+
979
+ // create approve message from trustee2
980
+ msgApproveUpgrade := NewMsgApproveUpgrade (trusteeAccAddress2 )
981
+
982
+ // approve new upgrade with plan height < block height
983
+ setup .Ctx = setup .Ctx .WithBlockHeight (3 )
984
+ setup .UpgradeKeeper .On ("ScheduleUpgrade" , mock .Anything , proposeUpgrade .Plan ).Return (sdkerrors .ErrInvalidRequest ).Once ()
985
+ _ , err = setup .Handler (setup .Ctx , msgApproveUpgrade )
986
+ require .Error (t , err , sdkerrors .ErrInvalidRequest )
987
+
988
+ // check upgrade for not being added to ApprovedUpgrade store
989
+ _ , isFound = setup .Keeper .GetApprovedUpgrade (setup .Ctx , proposeUpgrade .Plan .Name )
990
+ require .False (t , isFound )
991
+
992
+ // second time propose upgrade with same name with propose height < current height
993
+ proposeUpgrade = NewMsgProposeUpgrade (trusteeAccAddress3 )
994
+ proposeUpgrade .Plan .Height = 3
995
+ setup .Ctx = setup .Ctx .WithBlockHeight (5 )
996
+
997
+ setup .UpgradeKeeper .On ("ScheduleUpgrade" , mock .Anything , proposeUpgrade .Plan ).Return (types .ErrProposedUpgradeAlreadyExists ).Once ()
998
+ _ , err = setup .Handler (setup .Ctx , proposeUpgrade )
999
+ require .Error (t , err )
1000
+ require .True (t , types .ErrProposedUpgradeAlreadyExists .Is (err ))
1001
+ }
1002
+
846
1003
func isContextWithCachedMultiStore (ctx sdk.Context ) bool {
847
1004
_ , ok := ctx .MultiStore ().(storetypes.CacheMultiStore )
848
1005
0 commit comments