@@ -257,10 +257,11 @@ async fn _process(request: &pb::CardanoSignTransactionRequest) -> Result<Respons
257
257
} )
258
258
. await ?;
259
259
} else {
260
+ let fee_percentage: f64 = 100. * ( request. fee as f64 ) / ( total as f64 ) ;
260
261
transaction:: verify_total_fee (
261
262
& format_value ( params, total + request. fee ) ,
262
263
& format_value ( params, request. fee ) ,
263
- None ,
264
+ Some ( fee_percentage ) ,
264
265
)
265
266
. await ?;
266
267
}
@@ -566,6 +567,10 @@ mod tests {
566
567
assert_eq ! ( params. body, "Fee\n 0.191681 ADA" ) ;
567
568
true
568
569
}
570
+ 5 => {
571
+ assert_eq ! ( params. title, "High fee" ) ;
572
+ true
573
+ }
569
574
_ => panic ! ( "too many user confirmations" ) ,
570
575
}
571
576
} ) ) ,
@@ -898,6 +903,10 @@ mod tests {
898
903
assert_eq ! ( params. body, "Transaction\n cannot be\n mined" ) ;
899
904
true
900
905
}
906
+ 2 => {
907
+ assert_eq ! ( params. title, "High fee" ) ;
908
+ true
909
+ }
901
910
_ => panic ! ( "too many user confirmations" ) ,
902
911
}
903
912
} ) ) ,
@@ -969,6 +978,10 @@ mod tests {
969
978
assert_eq ! ( params. body, "Can be mined from\n slot 335011 in\n epoch 292" ) ;
970
979
true
971
980
}
981
+ 2 => {
982
+ assert_eq ! ( params. title, "High fee" ) ;
983
+ true
984
+ }
972
985
_ => panic ! ( "too many user confirmations" ) ,
973
986
}
974
987
} ) ) ,
@@ -1030,6 +1043,10 @@ mod tests {
1030
1043
assert_eq ! ( params. body, "Transaction\n cannot be\n mined" ) ;
1031
1044
true
1032
1045
}
1046
+ 2 => {
1047
+ assert_eq ! ( params. title, "High fee" ) ;
1048
+ true
1049
+ }
1033
1050
_ => panic ! ( "too many user confirmations" ) ,
1034
1051
}
1035
1052
} ) ) ,
@@ -1143,6 +1160,10 @@ mod tests {
1143
1160
) ;
1144
1161
true
1145
1162
}
1163
+ 5 => {
1164
+ assert_eq ! ( params. title, "High fee" ) ;
1165
+ true
1166
+ }
1146
1167
_ => panic ! ( "unexpected user confirmation" ) ,
1147
1168
}
1148
1169
} ) ) ,
@@ -1176,6 +1197,76 @@ mod tests {
1176
1197
) ;
1177
1198
}
1178
1199
1200
+ // Test a transaction with an unusually high fee.
1201
+ #[ test]
1202
+ fn test_high_fee_warning ( ) {
1203
+ let tx = pb:: CardanoSignTransactionRequest {
1204
+ network : CardanoNetwork :: CardanoMainnet as _ ,
1205
+ inputs : vec ! [ pb:: cardano_sign_transaction_request:: Input {
1206
+ keypath: vec![ 1852 + HARDENED , 1815 + HARDENED , HARDENED , 0 , 0 ] ,
1207
+ prev_out_hash: b"\x59 \x86 \x4e \xe7 \x3c \xa5 \xd9 \x10 \x98 \xa3 \x2b \x3c \xe9 \x81 \x1b \xac \x19 \x96 \xdc \xba \xef \xa6 \xb6 \x24 \x7d \xca \xaf \xb5 \x77 \x9c \x25 \x38 " . to_vec( ) ,
1208
+ prev_out_index: 0 ,
1209
+ } ] ,
1210
+ outputs : vec ! [
1211
+ pb:: cardano_sign_transaction_request:: Output {
1212
+ encoded_address: "addr1q9qfllpxg2vu4lq6rnpel4pvpp5xnv3kvvgtxk6k6wp4ff89xrhu8jnu3p33vnctc9eklee5dtykzyag5penc6dcmakqsqqgpt" . into( ) ,
1213
+ value: 1000000 ,
1214
+ script_config: None ,
1215
+ asset_groups: vec![ ] ,
1216
+ } ,
1217
+ // change
1218
+ pb:: cardano_sign_transaction_request:: Output {
1219
+ encoded_address: "addr1q90tlskd4mh5kncmul7vx887j30tjtfgvap5n0g0rf9qqc7znmndrdhe7rwvqkw5c7mqnp4a3yflnvu6kff7l5dungvqmvu6hs" . into( ) ,
1220
+ value: 4829501 ,
1221
+ script_config: Some ( CardanoScriptConfig {
1222
+ config: Some ( pb:: cardano_script_config:: Config :: PkhSkh ( pb:: cardano_script_config:: PkhSkh {
1223
+ keypath_payment: vec![ 1852 + HARDENED , 1815 + HARDENED , HARDENED , 0 , 0 ] ,
1224
+ keypath_stake: vec![ 1852 + HARDENED , 1815 + HARDENED , HARDENED , 2 , 0 ] ,
1225
+ } ) )
1226
+ } ) ,
1227
+ asset_groups: vec![ ] ,
1228
+ } ,
1229
+ ] ,
1230
+ fee : 170499 ,
1231
+ ttl : 0 ,
1232
+ allow_zero_ttl : false ,
1233
+ certificates : vec ! [ ] ,
1234
+ withdrawals : vec ! [ ] ,
1235
+ validity_interval_start : 0 ,
1236
+ } ;
1237
+
1238
+ static mut CONFIRM_COUNTER : u32 = 0 ;
1239
+ mock ( Data {
1240
+ ui_confirm_create : Some ( Box :: new ( |params| {
1241
+ match unsafe {
1242
+ CONFIRM_COUNTER += 1 ;
1243
+ CONFIRM_COUNTER
1244
+ } {
1245
+ 1 => {
1246
+ assert_eq ! ( params. title, "High fee" ) ;
1247
+ assert_eq ! ( params. body, "The fee rate\n is 17.0%.\n Proceed?" ) ;
1248
+ assert ! ( params. longtouch) ;
1249
+ true
1250
+ }
1251
+ _ => panic ! ( "unexpected user confirmations" ) ,
1252
+ }
1253
+ } ) ) ,
1254
+
1255
+ ui_transaction_address_create : Some ( Box :: new ( |_amount, _address| true ) ) ,
1256
+ ui_transaction_fee_create : Some ( Box :: new ( |total, fee, longtouch| {
1257
+ assert_eq ! ( total, "1.170499 ADA" ) ;
1258
+ assert_eq ! ( fee, "0.170499 ADA" ) ;
1259
+ assert ! ( !longtouch) ;
1260
+ true
1261
+ } ) ) ,
1262
+ ..Default :: default ( )
1263
+ } ) ;
1264
+ mock_unlocked ( ) ;
1265
+
1266
+ assert ! ( block_on( process( & tx) ) . is_ok( ) ) ;
1267
+ assert_eq ! ( unsafe { CONFIRM_COUNTER } , 1 ) ;
1268
+ }
1269
+
1179
1270
#[ test]
1180
1271
fn test_validate_asset_groups ( ) {
1181
1272
assert ! ( validate_asset_groups( & [ ] ) . is_ok( ) ) ;
0 commit comments