@@ -628,10 +628,6 @@ pub enum BasicError {
628628 InvalidTokenDistributionTimeIntervalNotMinuteAlignedError ,
629629 ) ,
630630
631- #[ error( transparent) ]
632- InvalidTokenDistributionEpochIntervalTooShortError (
633- InvalidTokenDistributionEpochIntervalTooShortError ,
634- ) ,
635631 #[ error( transparent) ]
636632 RedundantDocumentPaidForByTokenWithContractId ( RedundantDocumentPaidForByTokenWithContractId ) ,
637633
@@ -831,6 +827,14 @@ pub enum BasicError {
831827 // A document breaking a rule of its type's `propertyConstraints` (protocol version 14).
832828 #[ error( transparent) ]
833829 DocumentPropertyConstraintViolatedError ( DocumentPropertyConstraintViolatedError ) ,
830+
831+ // A perpetual distribution with a zero epoch interval (protocol version 14). Appended here:
832+ // it was first inserted mid-enum, which shifted the discriminant of every variant shipped
833+ // after it in 4.1.
834+ #[ error( transparent) ]
835+ InvalidTokenDistributionEpochIntervalTooShortError (
836+ InvalidTokenDistributionEpochIntervalTooShortError ,
837+ ) ,
834838}
835839
836840impl From < BasicError > for ConsensusError {
@@ -865,7 +869,7 @@ mod tests {
865869 discriminant_of( BasicError :: IdentityKeyLimitsUpdateEmptyError (
866870 IdentityKeyLimitsUpdateEmptyError :: new( 1 )
867871 ) ) ,
868- 186
872+ 185
869873 ) ;
870874 // Once-per-identity token distribution (protocol version 14).
871875 assert_eq ! (
@@ -874,47 +878,47 @@ mod tests {
874878 InvalidTokenOncePerIdentityDistributionAmountError :: new( 0 , 1 )
875879 )
876880 ) ,
877- 187
881+ 186
878882 ) ;
879883 // Pre-programmed distribution amounts (protocol version 14).
880884 assert_eq ! (
881885 discriminant_of( BasicError :: PreProgrammedDistributionAmountOverLimitError (
882886 PreProgrammedDistributionAmountOverLimitError :: new( 0 , 100 )
883887 ) ) ,
884- 188
888+ 187
885889 ) ;
886890 // Contract moderation (protocol version 14).
887891 assert_eq ! (
888892 discriminant_of( BasicError :: InvalidContractModerationConfigError (
889893 InvalidContractModerationConfigError :: new( "reason" . to_string( ) )
890894 ) ) ,
891- 189
895+ 188
892896 ) ;
893897 assert_eq ! (
894898 discriminant_of( BasicError :: ContractModerationSelfTargetError (
895899 ContractModerationSelfTargetError :: new( Identifier :: from( [ 1 ; 32 ] ) )
896900 ) ) ,
897- 190
901+ 189
898902 ) ;
899903 assert_eq ! (
900904 discriminant_of( BasicError :: ContractModerationReasonTooLongError (
901905 ContractModerationReasonTooLongError :: new( 1025 , 1024 )
902906 ) ) ,
903- 191
907+ 190
904908 ) ;
905909 // Document action fees (protocol version 14).
906910 assert_eq ! (
907911 discriminant_of( BasicError :: DocumentActionFeesWithoutModerationError (
908912 DocumentActionFeesWithoutModerationError :: new( "post" . to_string( ) )
909913 ) ) ,
910- 192
914+ 191
911915 ) ;
912916 // Documents cited by a contract moderation reason (protocol version 14).
913917 assert_eq ! (
914918 discriminant_of( BasicError :: InvalidContractModerationReasonDocumentsError (
915919 InvalidContractModerationReasonDocumentsError :: new( "x" . to_string( ) )
916920 ) ) ,
917- 193
921+ 192
918922 ) ;
919923 // A `distinctFrom` identifier property equal to what it must differ from (protocol
920924 // version 14).
@@ -926,7 +930,7 @@ mod tests {
926930 "$ownerId" . to_string( ) ,
927931 )
928932 ) ) ,
929- 194
933+ 193
930934 ) ;
931935 // The shape of an `encryptedFor` property's ciphertext (protocol version 14).
932936 assert_eq ! (
@@ -939,7 +943,7 @@ mod tests {
939943 16
940944 )
941945 ) ) ,
942- 195
946+ 194
943947 ) ;
944948 // Moderation charters (protocol version 14).
945949 assert_eq ! (
@@ -949,20 +953,20 @@ mod tests {
949953 "reason" . to_string( )
950954 )
951955 ) ) ,
952- 196
956+ 195
953957 ) ;
954958 assert_eq ! (
955959 discriminant_of( BasicError :: ModerationCharterRewardSplitNotOneHundredError (
956960 ModerationCharterRewardSplitNotOneHundredError :: new( 10 , 40 , 40 )
957961 ) ) ,
958- 197
962+ 196
959963 ) ;
960964 // A string over its property's `maxBytes` (protocol version 14).
961965 assert_eq ! (
962966 discriminant_of( BasicError :: DocumentPropertyMaxBytesExceededError (
963967 DocumentPropertyMaxBytesExceededError :: new( "description" . to_string( ) , 4097 , 4096 )
964968 ) ) ,
965- 198
969+ 197
966970 ) ;
967971 // A document breaking a rule of its type's `propertyConstraints` (protocol version 14).
968972 assert_eq ! (
@@ -973,7 +977,36 @@ mod tests {
973977 PropertyConstraintViolation :: NotMet ,
974978 )
975979 ) ) ,
980+ 198
981+ ) ;
982+ // A perpetual distribution with a zero epoch interval (protocol version 14).
983+ assert_eq ! (
984+ discriminant_of(
985+ BasicError :: InvalidTokenDistributionEpochIntervalTooShortError (
986+ InvalidTokenDistributionEpochIntervalTooShortError :: new( 0 )
987+ )
988+ ) ,
976989 199
977990 ) ;
978991 }
992+
993+ /// The variants that shipped in 4.1 keep the discriminants they were released with, so an
994+ /// SDK built against 4.1 decodes the errors of a newer node as the same variants. A variant
995+ /// inserted anywhere before the tail moves these and fails this test.
996+ #[ test]
997+ fn should_keep_the_discriminants_shipped_in_4_1 ( ) {
998+ assert_eq ! (
999+ discriminant_of( BasicError :: RedundantDocumentPaidForByTokenWithContractId (
1000+ RedundantDocumentPaidForByTokenWithContractId :: new( Identifier :: from( [ 1 ; 32 ] ) )
1001+ ) ) ,
1002+ 140
1003+ ) ;
1004+ // The last variant released in 4.1.
1005+ assert_eq ! (
1006+ discriminant_of( BasicError :: TokenPricingScheduleEmptyError (
1007+ TokenPricingScheduleEmptyError :: new( Identifier :: from( [ 1 ; 32 ] ) )
1008+ ) ) ,
1009+ 172
1010+ ) ;
1011+ }
9791012}
0 commit comments