@@ -299,11 +299,10 @@ pub async fn process(request: &Transaction<'_>) -> Result<Response, Error> {
299
299
}
300
300
super :: keypath:: warn_unusual_keypath ( & params, params. name , request. keypath ( ) ) . await ?;
301
301
302
- // Show chain confirmation only for known non-mainnet networks
303
- if super :: params:: is_known_non_mainnet ( params. chain_id ) {
302
+ // Show chain confirmation only for known networks
303
+ if super :: params:: is_known_network ( params. chain_id ) {
304
304
confirm:: confirm ( & confirm:: Params {
305
- title : "Confirm Chain" ,
306
- body : & format ! ( "Sign transaction on\n {}" , params. name) ,
305
+ body : & format ! ( "Sign transaction on\n \n {}" , params. name) ,
307
306
accept_is_nextarrow : true ,
308
307
..Default :: default ( )
309
308
} )
@@ -483,6 +482,11 @@ mod tests {
483
482
const KEYPATH : & [ u32 ] = & [ 44 + HARDENED , 60 + HARDENED , 0 + HARDENED , 0 , 0 ] ;
484
483
485
484
mock ( Data {
485
+ ui_confirm_create : Some ( Box :: new ( |params| {
486
+ assert_eq ! ( params. body, "Sign transaction on\n \n Ethereum" ) ;
487
+ assert ! ( params. accept_is_nextarrow) ;
488
+ true
489
+ } ) ) ,
486
490
ui_transaction_address_create : Some ( Box :: new ( |amount, address| {
487
491
assert_eq ! ( amount, "0.530564 ETH" ) ;
488
492
assert_eq ! ( address, "0x04F264Cf34440313B4A0192A352814FBe927b885" ) ;
@@ -557,6 +561,11 @@ mod tests {
557
561
UI_COUNTER
558
562
} {
559
563
1 => {
564
+ assert_eq ! ( params. body, "Sign transaction on\n \n Ethereum" ) ;
565
+ assert ! ( params. accept_is_nextarrow) ;
566
+ true
567
+ }
568
+ 2 => {
560
569
assert_eq ! ( params. title, "High fee" ) ;
561
570
assert_eq ! ( params. body, "The fee is 12.0%\n the send amount.\n Proceed?" ) ;
562
571
assert ! ( params. longtouch) ;
@@ -586,7 +595,7 @@ mod tests {
586
595
address_case: pb:: EthAddressCase :: Mixed as _,
587
596
} ) ) )
588
597
. is_ok( ) ) ;
589
- assert_eq ! ( unsafe { UI_COUNTER } , 1 ) ;
598
+ assert_eq ! ( unsafe { UI_COUNTER } , 2 ) ;
590
599
}
591
600
592
601
/// Test an EIP-1559 transaction with an unusually high fee.
@@ -609,6 +618,11 @@ mod tests {
609
618
UI_COUNTER
610
619
} {
611
620
1 => {
621
+ assert_eq ! ( params. body, "Sign transaction on\n \n Ethereum" ) ;
622
+ assert ! ( params. accept_is_nextarrow) ;
623
+ true
624
+ }
625
+ 2 => {
612
626
assert_eq ! ( params. title, "High fee" ) ;
613
627
assert_eq ! ( params. body, "The fee is 12.0%\n the send amount.\n Proceed?" ) ;
614
628
assert ! ( params. longtouch) ;
@@ -638,7 +652,7 @@ mod tests {
638
652
address_case: pb:: EthAddressCase :: Mixed as _,
639
653
} ) ) )
640
654
. is_ok( ) ) ;
641
- assert_eq ! ( unsafe { UI_COUNTER } , 1 ) ;
655
+ assert_eq ! ( unsafe { UI_COUNTER } , 2 ) ;
642
656
}
643
657
644
658
/// Standard ETH transaction on an unusual keypath (Sepolia on mainnet keypath)
@@ -659,8 +673,7 @@ mod tests {
659
673
true
660
674
}
661
675
2 => {
662
- assert_eq ! ( params. title, "Confirm Chain" ) ;
663
- assert_eq ! ( params. body, "Sign transaction on\n Sepolia" ) ;
676
+ assert_eq ! ( params. body, "Sign transaction on\n \n Sepolia" ) ;
664
677
true
665
678
}
666
679
_ => panic ! ( "too many user confirmations" ) ,
@@ -708,8 +721,12 @@ mod tests {
708
721
mock ( Data {
709
722
ui_confirm_create : Some ( Box :: new ( |params| {
710
723
match unsafe { CONFIRM_COUNTER } {
711
- 0 | 1 => assert_eq ! ( params. title, "Unknown\n contract" ) ,
712
- 2 => {
724
+ 0 => {
725
+ assert_eq ! ( params. body, "Sign transaction on\n \n Ethereum" ) ;
726
+ assert ! ( params. accept_is_nextarrow) ;
727
+ }
728
+ 1 | 2 => assert_eq ! ( params. title, "Unknown\n contract" ) ,
729
+ 3 => {
713
730
assert_eq ! ( params. title, "Transaction\n data" ) ;
714
731
assert_eq ! ( params. body, "666f6f20626172" ) ; // "foo bar" in hex.
715
732
assert ! ( params. scrollable) ;
@@ -764,8 +781,12 @@ mod tests {
764
781
mock ( Data {
765
782
ui_confirm_create : Some ( Box :: new ( |params| {
766
783
match unsafe { CONFIRM_COUNTER } {
767
- 0 | 1 => assert_eq ! ( params. title, "Unknown\n contract" ) ,
768
- 2 => {
784
+ 0 => {
785
+ assert_eq ! ( params. body, "Sign transaction on\n \n Ethereum" ) ;
786
+ assert ! ( params. accept_is_nextarrow) ;
787
+ }
788
+ 1 | 2 => assert_eq ! ( params. title, "Unknown\n contract" ) ,
789
+ 3 => {
769
790
assert_eq ! ( params. title, "Transaction\n data" ) ;
770
791
assert_eq ! ( params. body, "666f6f20626172" ) ; // "foo bar" in hex.
771
792
assert ! ( params. scrollable) ;
@@ -819,6 +840,11 @@ mod tests {
819
840
const KEYPATH : & [ u32 ] = & [ 44 + HARDENED , 60 + HARDENED , 0 + HARDENED , 0 , 0 ] ;
820
841
821
842
mock ( Data {
843
+ ui_confirm_create : Some ( Box :: new ( |params| {
844
+ assert_eq ! ( params. body, "Sign transaction on\n \n Ethereum" ) ;
845
+ assert ! ( params. accept_is_nextarrow) ;
846
+ true
847
+ } ) ) ,
822
848
ui_transaction_address_create : Some ( Box :: new ( |amount, address| {
823
849
assert_eq ! ( amount, "57 USDT" ) ;
824
850
assert_eq ! ( address, "0xE6CE0a092A99700CD4ccCcBb1fEDc39Cf53E6330" ) ;
@@ -879,6 +905,11 @@ mod tests {
879
905
const KEYPATH : & [ u32 ] = & [ 44 + HARDENED , 60 + HARDENED , 0 + HARDENED , 0 , 0 ] ;
880
906
881
907
mock ( Data {
908
+ ui_confirm_create : Some ( Box :: new ( |params| {
909
+ assert_eq ! ( params. body, "Sign transaction on\n \n Ethereum" ) ;
910
+ assert ! ( params. accept_is_nextarrow) ;
911
+ true
912
+ } ) ) ,
882
913
ui_transaction_address_create : Some ( Box :: new ( |amount, address| {
883
914
assert_eq ! ( amount, "Unknown token" ) ;
884
915
assert_eq ! ( address, "0x857B3D969eAcB775a9f79cabc62Ec4bB1D1cd60e" ) ;
@@ -954,6 +985,7 @@ mod tests {
954
985
{
955
986
// Check that the above is valid before making invalid variants.
956
987
mock ( Data {
988
+ ui_confirm_create : Some ( Box :: new ( |_| true ) ) ,
957
989
ui_transaction_address_create : Some ( Box :: new ( |_, _| true ) ) ,
958
990
ui_transaction_fee_create : Some ( Box :: new ( |_, _, _| true ) ) ,
959
991
..Default :: default ( )
@@ -1022,9 +1054,30 @@ mod tests {
1022
1054
) ;
1023
1055
}
1024
1056
1057
+ {
1058
+ // User rejects chain confirmation
1059
+ mock ( Data {
1060
+ ui_confirm_create : Some ( Box :: new ( |params| {
1061
+ assert_eq ! ( params. body, "Sign transaction on\n \n Ethereum" ) ;
1062
+ assert ! ( params. accept_is_nextarrow) ;
1063
+ false
1064
+ } ) ) ,
1065
+ ..Default :: default ( )
1066
+ } ) ;
1067
+ assert_eq ! (
1068
+ block_on( process( & Transaction :: Legacy ( & valid_request) ) ) ,
1069
+ Err ( Error :: UserAbort )
1070
+ ) ;
1071
+ }
1072
+
1025
1073
{
1026
1074
// User rejects recipient/value.
1027
1075
mock ( Data {
1076
+ ui_confirm_create : Some ( Box :: new ( |params| {
1077
+ assert_eq ! ( params. body, "Sign transaction on\n \n Ethereum" ) ;
1078
+ assert ! ( params. accept_is_nextarrow) ;
1079
+ true
1080
+ } ) ) ,
1028
1081
ui_transaction_address_create : Some ( Box :: new ( |amount, address| {
1029
1082
assert_eq ! ( amount, "0.530564 ETH" ) ;
1030
1083
assert_eq ! ( address, "0x04F264Cf34440313B4A0192A352814FBe927b885" ) ;
@@ -1040,6 +1093,11 @@ mod tests {
1040
1093
{
1041
1094
// User rejects total/fee.
1042
1095
mock ( Data {
1096
+ ui_confirm_create : Some ( Box :: new ( |params| {
1097
+ assert_eq ! ( params. body, "Sign transaction on\n \n Ethereum" ) ;
1098
+ assert ! ( params. accept_is_nextarrow) ;
1099
+ true
1100
+ } ) ) ,
1043
1101
ui_transaction_address_create : Some ( Box :: new ( |amount, address| {
1044
1102
assert_eq ! ( amount, "0.530564 ETH" ) ;
1045
1103
assert_eq ! ( address, "0x04F264Cf34440313B4A0192A352814FBe927b885" ) ;
@@ -1061,6 +1119,7 @@ mod tests {
1061
1119
{
1062
1120
// Keystore locked.
1063
1121
mock ( Data {
1122
+ ui_confirm_create : Some ( Box :: new ( |_| true ) ) ,
1064
1123
ui_transaction_address_create : Some ( Box :: new ( |_, _| true ) ) ,
1065
1124
ui_transaction_fee_create : Some ( Box :: new ( |_, _, _| true ) ) ,
1066
1125
..Default :: default ( )
@@ -1093,6 +1152,7 @@ mod tests {
1093
1152
{
1094
1153
// Check that the above is valid before making invalid variants.
1095
1154
mock ( Data {
1155
+ ui_confirm_create : Some ( Box :: new ( |_| true ) ) ,
1096
1156
ui_transaction_address_create : Some ( Box :: new ( |_, _| true ) ) ,
1097
1157
ui_transaction_fee_create : Some ( Box :: new ( |_, _, _| true ) ) ,
1098
1158
..Default :: default ( )
@@ -1194,16 +1254,16 @@ mod tests {
1194
1254
1195
1255
/// Test that the chain confirmation screen appears for known non-mainnet networks.
1196
1256
#[ test]
1197
- pub fn test_chain_confirmation_for_l2_networks ( ) {
1257
+ pub fn test_chain_confirmation ( ) {
1198
1258
const KEYPATH : & [ u32 ] = & [ 44 + HARDENED , 60 + HARDENED , 0 + HARDENED , 0 , 0 ] ;
1199
1259
static mut CONFIRM_COUNTER : u32 = 0 ;
1200
1260
// Test with Arbitrum (chain_id 42161)
1201
1261
mock ( Data {
1202
1262
ui_confirm_create : Some ( Box :: new ( |params| {
1203
1263
unsafe {
1204
1264
if CONFIRM_COUNTER == 0 {
1205
- assert_eq ! ( params. title, "Confirm Chain" ) ;
1206
- assert_eq ! ( params. body, "Sign transaction on\n Arbitrum One" ) ;
1265
+ // assert_eq!(params.title, "Confirm Chain");
1266
+ assert_eq ! ( params. body, "Sign transaction on\n \ n Arbitrum One" ) ;
1207
1267
CONFIRM_COUNTER += 1 ;
1208
1268
}
1209
1269
}
@@ -1235,7 +1295,7 @@ mod tests {
1235
1295
assert_eq ! ( unsafe { CONFIRM_COUNTER } , 1 ) ;
1236
1296
}
1237
1297
1238
- /// Test that EIP-1559 transactions also get the chain confirmation screen for L2 networks
1298
+ /// Test that EIP-1559 transactions also get the chain confirmation screen
1239
1299
#[ test]
1240
1300
pub fn test_chain_confirmation_for_eip1559 ( ) {
1241
1301
const KEYPATH : & [ u32 ] = & [ 44 + HARDENED , 60 + HARDENED , 0 + HARDENED , 0 , 0 ] ;
@@ -1246,8 +1306,8 @@ mod tests {
1246
1306
ui_confirm_create : Some ( Box :: new ( |params| {
1247
1307
unsafe {
1248
1308
if CONFIRM_COUNTER == 0 {
1249
- assert_eq ! ( params. title, "Confirm Chain" ) ;
1250
- assert_eq ! ( params. body, "Sign transaction on\n Polygon" ) ;
1309
+ // assert_eq!(params.title, "Confirm Chain");
1310
+ assert_eq ! ( params. body, "Sign transaction on\n \ n Polygon" ) ;
1251
1311
CONFIRM_COUNTER += 1 ;
1252
1312
}
1253
1313
}
@@ -1278,7 +1338,7 @@ mod tests {
1278
1338
assert_eq ! ( unsafe { CONFIRM_COUNTER } , 1 ) ;
1279
1339
}
1280
1340
1281
- /// Test that unknown networks and mainnet do NOT get the chain confirmation screen
1341
+ /// Test that unknown networks do NOT get the chain confirmation screen
1282
1342
#[ test]
1283
1343
pub fn test_no_chain_confirmation_for_unknown_networks ( ) {
1284
1344
const KEYPATH : & [ u32 ] = & [ 44 + HARDENED , 60 + HARDENED , 0 + HARDENED , 0 , 0 ] ;
@@ -1289,7 +1349,7 @@ mod tests {
1289
1349
ui_confirm_create : Some ( Box :: new ( |params| {
1290
1350
unsafe {
1291
1351
// Only the warning confirmations should appear, not chain confirmation
1292
- if params. title == "Confirm Chain" {
1352
+ if params. body . starts_with ( "Sign transaction on" ) {
1293
1353
CONFIRM_COUNTER += 1 ;
1294
1354
}
1295
1355
}
@@ -1319,43 +1379,5 @@ mod tests {
1319
1379
. unwrap ( ) ;
1320
1380
1321
1381
assert_eq ! ( unsafe { CONFIRM_COUNTER } , 0 ) ;
1322
-
1323
- // Reset counter for mainnet test
1324
- unsafe { CONFIRM_COUNTER = 0 } ;
1325
-
1326
- // Test with Ethereum mainnet (chain_id 1)
1327
- mock ( Data {
1328
- ui_confirm_create : Some ( Box :: new ( |params| {
1329
- unsafe {
1330
- if params. title == "Confirm Chain" {
1331
- CONFIRM_COUNTER += 1 ;
1332
- }
1333
- }
1334
- true
1335
- } ) ) ,
1336
- ui_transaction_address_create : Some ( Box :: new ( |_, _| true ) ) ,
1337
- ui_transaction_fee_create : Some ( Box :: new ( |_, _, _| true ) ) ,
1338
- ..Default :: default ( )
1339
- } ) ;
1340
- mock_unlocked ( ) ;
1341
-
1342
- block_on ( process ( & Transaction :: Legacy ( & pb:: EthSignRequest {
1343
- coin : pb:: EthCoin :: Eth as _ ,
1344
- keypath : KEYPATH . to_vec ( ) ,
1345
- nonce : b"\x1f \xdc " . to_vec ( ) ,
1346
- gas_price : b"\x01 \x65 \xa0 \xbc \x00 " . to_vec ( ) ,
1347
- gas_limit : b"\x52 \x08 " . to_vec ( ) ,
1348
- recipient :
1349
- b"\x04 \xf2 \x64 \xcf \x34 \x44 \x03 \x13 \xb4 \xa0 \x19 \x2a \x35 \x28 \x14 \xfb \xe9 \x27 \xb8 \x85 "
1350
- . to_vec ( ) ,
1351
- value : b"\x07 \x5c \xf1 \x25 \x9e \x9c \x40 \x00 " . to_vec ( ) ,
1352
- data : b"" . to_vec ( ) ,
1353
- host_nonce_commitment : None ,
1354
- chain_id : 1 ,
1355
- address_case : pb:: EthAddressCase :: Mixed as _ ,
1356
- } ) ) )
1357
- . unwrap ( ) ;
1358
-
1359
- assert_eq ! ( unsafe { CONFIRM_COUNTER } , 0 ) ;
1360
1382
}
1361
1383
}
0 commit comments