@@ -926,7 +926,7 @@ func TestBeginBlockInit(t *testing.T) {
926
926
100000000000 ,
927
927
100000000000 ,
928
928
100000000000 ,
929
- 67 ,
929
+ 50 ,
930
930
).(* providertypes.ConsumerAdditionProposal ),
931
931
providertypes .NewConsumerAdditionProposal (
932
932
"title" , "spawn time passed" , "chain2" , clienttypes .NewHeight (3 , 4 ), []byte {}, []byte {},
@@ -938,7 +938,7 @@ func TestBeginBlockInit(t *testing.T) {
938
938
100000000000 ,
939
939
100000000000 ,
940
940
100000000000 ,
941
- 0 ,
941
+ 50 ,
942
942
).(* providertypes.ConsumerAdditionProposal ),
943
943
providertypes .NewConsumerAdditionProposal (
944
944
"title" , "spawn time not passed" , "chain3" , clienttypes .NewHeight (3 , 4 ), []byte {}, []byte {},
@@ -950,7 +950,7 @@ func TestBeginBlockInit(t *testing.T) {
950
950
100000000000 ,
951
951
100000000000 ,
952
952
100000000000 ,
953
- 0 ,
953
+ 50 ,
954
954
).(* providertypes.ConsumerAdditionProposal ),
955
955
providertypes .NewConsumerAdditionProposal (
956
956
"title" , "invalid proposal: chain id already exists" , "chain2" , clienttypes .NewHeight (4 , 5 ), []byte {}, []byte {},
@@ -962,46 +962,102 @@ func TestBeginBlockInit(t *testing.T) {
962
962
100000000000 ,
963
963
100000000000 ,
964
964
100000000000 ,
965
+ 50 ,
966
+ ).(* providertypes.ConsumerAdditionProposal ),
967
+ providertypes .NewConsumerAdditionProposal (
968
+ "title" , "opt-in chain with no validator opted in" , "chain4" , clienttypes .NewHeight (3 , 4 ), []byte {}, []byte {},
969
+ now .Add (- time .Hour * 2 ).UTC (),
970
+ "0.75" ,
971
+ 10 ,
972
+ "" ,
973
+ 10000 ,
974
+ 100000000000 ,
975
+ 100000000000 ,
976
+ 100000000000 ,
977
+ 0 ,
978
+ ).(* providertypes.ConsumerAdditionProposal ),
979
+ providertypes .NewConsumerAdditionProposal (
980
+ "title" , "opt-in chain with at least one validator opted in" , "chain5" , clienttypes .NewHeight (3 , 4 ), []byte {}, []byte {},
981
+ now .Add (- time .Hour * 1 ).UTC (),
982
+ "0.75" ,
983
+ 10 ,
984
+ "" ,
985
+ 10000 ,
986
+ 100000000000 ,
987
+ 100000000000 ,
988
+ 100000000000 ,
965
989
0 ,
966
990
).(* providertypes.ConsumerAdditionProposal ),
967
991
}
968
992
969
- // Expect client creation for only for the 1st and second proposals (spawn time already passed and valid)
970
- gomock .InOrder (
971
- append (testkeeper .GetMocksForCreateConsumerClient (ctx , & mocks , "chain1" , clienttypes .NewHeight (3 , 4 )),
972
- testkeeper .GetMocksForCreateConsumerClient (ctx , & mocks , "chain2" , clienttypes .NewHeight (3 , 4 ))... )... ,
973
- )
993
+ // Expect client creation for only the first, second, and sixth proposals (spawn time already passed and valid)
994
+ expects := testkeeper .GetMocksForCreateConsumerClient (ctx , & mocks , "chain1" , clienttypes .NewHeight (3 , 4 ))
995
+ expects = append (expects , testkeeper .GetMocksForCreateConsumerClient (ctx , & mocks , "chain2" , clienttypes .NewHeight (3 , 4 ))... )
996
+ expects = append (expects , testkeeper .GetMocksForCreateConsumerClient (ctx , & mocks , "chain5" , clienttypes .NewHeight (3 , 4 ))... )
997
+
998
+ gomock .InOrder (expects ... )
974
999
975
1000
for _ , prop := range pendingProps {
976
1001
providerKeeper .SetPendingConsumerAdditionProp (ctx , prop )
977
1002
}
978
1003
1004
+ // opt in a sample validator so the chain's proposal can successfully execute
1005
+ providerKeeper .SetOptedIn (ctx , pendingProps [5 ].ChainId , providertypes.OptedInValidator {
1006
+ ProviderAddr : []byte {1 },
1007
+ BlockHeight : int64 (2 ),
1008
+ Power : int64 (3 ),
1009
+ PublicKey : []byte {4 },
1010
+ })
1011
+
979
1012
providerKeeper .BeginBlockInit (ctx )
980
1013
981
- // Only the third proposal is still stored as pending
1014
+ // first proposal is not pending because its spawn time already passed
982
1015
_ , found := providerKeeper .GetPendingConsumerAdditionProp (
983
1016
ctx , pendingProps [0 ].SpawnTime , pendingProps [0 ].ChainId )
984
1017
require .False (t , found )
1018
+ _ , found = providerKeeper .GetConsumerGenesis (ctx , pendingProps [0 ].ChainId )
1019
+ require .True (t , found )
985
1020
986
1021
_ , found = providerKeeper .GetPendingConsumerAdditionProp (
987
1022
ctx , pendingProps [1 ].SpawnTime , pendingProps [1 ].ChainId )
988
1023
require .False (t , found )
1024
+ _ , found = providerKeeper .GetConsumerGenesis (ctx , pendingProps [1 ].ChainId )
1025
+ require .True (t , found )
989
1026
1027
+ // Only the third proposal is still stored as pending
990
1028
_ , found = providerKeeper .GetPendingConsumerAdditionProp (
991
1029
ctx , pendingProps [2 ].SpawnTime , pendingProps [2 ].ChainId )
992
1030
require .True (t , found )
1031
+ _ , found = providerKeeper .GetConsumerGenesis (ctx , pendingProps [2 ].ChainId )
1032
+ require .False (t , found )
993
1033
994
- // check that the invalid proposal was dropped
1034
+ // check that the invalid proposals were dropped
995
1035
_ , found = providerKeeper .GetPendingConsumerAdditionProp (
996
1036
ctx , pendingProps [3 ].SpawnTime , pendingProps [3 ].ChainId )
997
1037
require .False (t , found )
1038
+ // Note that we do not check that `GetConsumerGenesis(ctx, pendingProps[3].ChainId)` returns `false` here because
1039
+ //`pendingProps[3]` is an invalid proposal because the chain id already exists so the consumer genesis also exists
1040
+
1041
+ _ , found = providerKeeper .GetPendingConsumerAdditionProp (
1042
+ ctx , pendingProps [4 ].SpawnTime , pendingProps [4 ].ChainId )
1043
+ require .False (t , found )
1044
+ _ , found = providerKeeper .GetConsumerGenesis (ctx , pendingProps [4 ].ChainId )
1045
+ require .False (t , found )
1046
+
1047
+ // The sixth proposal corresponds to an Opt-In chain with one opted-in validator and hence the proposal gets
1048
+ // successfully executed.
1049
+ _ , found = providerKeeper .GetPendingConsumerAdditionProp (
1050
+ ctx , pendingProps [5 ].SpawnTime , pendingProps [5 ].ChainId )
1051
+ require .False (t , found )
1052
+ _ , found = providerKeeper .GetConsumerGenesis (ctx , pendingProps [5 ].ChainId )
1053
+ require .True (t , found )
998
1054
999
1055
// test that Top N is set correctly
1000
1056
require .True (t , providerKeeper .IsTopN (ctx , "chain1" ))
1001
1057
topN , found := providerKeeper .GetTopN (ctx , "chain1" )
1002
- require .Equal (t , uint32 (67 ), topN )
1058
+ require .Equal (t , uint32 (50 ), topN )
1003
1059
1004
- require .True (t , providerKeeper .IsOptIn (ctx , "chain2 " ))
1060
+ require .True (t , providerKeeper .IsOptIn (ctx , "chain4 " ))
1005
1061
}
1006
1062
1007
1063
// TestBeginBlockCCR tests BeginBlockCCR against the spec.
0 commit comments