@@ -866,7 +866,7 @@ mod tests {
866
866
fn f12( _origin, _a: u32 , _eb: u32 ) { unimplemented!( ) ; }
867
867
868
868
#[ weight = T :: DbWeight :: get( ) . reads( 3 ) + T :: DbWeight :: get( ) . writes( 2 ) + 10_000 ]
869
- fn f2 ( _origin) { unimplemented!( ) ; }
869
+ fn f20 ( _origin) { unimplemented!( ) ; }
870
870
871
871
#[ weight = T :: DbWeight :: get( ) . reads_writes( 6 , 5 ) + 40_000 ]
872
872
fn f21( _origin) { unimplemented!( ) ; }
@@ -900,13 +900,29 @@ mod tests {
900
900
assert_eq ! ( info. class, DispatchClass :: Operational ) ;
901
901
assert_eq ! ( info. pays_fee, Pays :: No ) ;
902
902
903
- assert_eq ! ( Call :: <TraitImpl >:: f11( 10 , 20 ) . get_dispatch_info( ) . weight, 120 ) ;
904
- assert_eq ! ( Call :: <TraitImpl >:: f11( 10 , 20 ) . get_dispatch_info( ) . class, DispatchClass :: Normal ) ;
905
- assert_eq ! ( Call :: <TraitImpl >:: f12( 10 , 20 ) . get_dispatch_info( ) . weight, 0 ) ;
906
- assert_eq ! ( Call :: <TraitImpl >:: f12( 10 , 20 ) . get_dispatch_info( ) . class, DispatchClass :: Operational ) ;
907
- assert_eq ! ( Call :: <TraitImpl >:: f2( ) . get_dispatch_info( ) . weight, 12300 ) ;
908
- assert_eq ! ( Call :: <TraitImpl >:: f21( ) . get_dispatch_info( ) . weight, 45600 ) ;
909
- assert_eq ! ( Call :: <TraitImpl >:: f2( ) . get_dispatch_info( ) . class, DispatchClass :: Normal ) ;
903
+ // #[weight = ((_a * 10 + _eb * 1) as Weight, DispatchClass::Normal, Pays::Yes)]
904
+ let info = Call :: < TraitImpl > :: f11 ( 13 , 20 ) . get_dispatch_info ( ) ;
905
+ assert_eq ! ( info. weight, 150 ) ; // 13*10 + 20
906
+ assert_eq ! ( info. class, DispatchClass :: Normal ) ;
907
+ assert_eq ! ( info. pays_fee, Pays :: Yes ) ;
908
+
909
+ // #[weight = (0, DispatchClass::Operational, Pays::Yes)]
910
+ let info = Call :: < TraitImpl > :: f12 ( 10 , 20 ) . get_dispatch_info ( ) ;
911
+ assert_eq ! ( info. weight, 0 ) ;
912
+ assert_eq ! ( info. class, DispatchClass :: Operational ) ;
913
+ assert_eq ! ( info. pays_fee, Pays :: Yes ) ;
914
+
915
+ // #[weight = T::DbWeight::get().reads(3) + T::DbWeight::get().writes(2) + 10_000]
916
+ let info = Call :: < TraitImpl > :: f20 ( ) . get_dispatch_info ( ) ;
917
+ assert_eq ! ( info. weight, 12300 ) ; // 100*3 + 1000*2 + 10_1000
918
+ assert_eq ! ( info. class, DispatchClass :: Normal ) ;
919
+ assert_eq ! ( info. pays_fee, Pays :: Yes ) ;
920
+
921
+ // #[weight = T::DbWeight::get().reads_writes(6, 5) + 40_000]
922
+ let info = Call :: < TraitImpl > :: f21 ( ) . get_dispatch_info ( ) ;
923
+ assert_eq ! ( info. weight, 45600 ) ; // 100*6 + 1000*5 + 40_1000
924
+ assert_eq ! ( info. class, DispatchClass :: Normal ) ;
925
+ assert_eq ! ( info. pays_fee, Pays :: Yes ) ;
910
926
}
911
927
912
928
#[ test]
@@ -938,7 +954,7 @@ mod tests {
938
954
939
955
type Balance = u64 ;
940
956
941
- // 0.5x^3 + 2.333x2 + 7x - 10_000
957
+ // 0.5x^3 + 2.333x^2 + 7x - 10_000
942
958
struct Poly ;
943
959
impl WeightToFeePolynomial for Poly {
944
960
type Balance = Balance ;
@@ -975,13 +991,16 @@ mod tests {
975
991
976
992
#[ test]
977
993
fn polynomial_works ( ) {
994
+ // 100^3/2=500000 100^2*(2+1/3)=23333 700 -10000
978
995
assert_eq ! ( Poly :: calc( & 100 ) , 514033 ) ;
996
+ // 10123^3/2=518677865433 10123^2*(2+1/3)=239108634 70861 -10000
979
997
assert_eq ! ( Poly :: calc( & 10_123 ) , 518917034928 ) ;
980
998
}
981
999
982
1000
#[ test]
983
1001
fn polynomial_does_not_underflow ( ) {
984
1002
assert_eq ! ( Poly :: calc( & 0 ) , 0 ) ;
1003
+ assert_eq ! ( Poly :: calc( & 10 ) , 0 ) ;
985
1004
}
986
1005
987
1006
#[ test]
0 commit comments