@@ -3,8 +3,8 @@ use ic_base_types::PrincipalId;
33use ic_btc_checker:: {
44 blocklist, get_tx_cycle_cost, BtcNetwork , CheckAddressArgs , CheckAddressResponse , CheckArg ,
55 CheckMode , CheckTransactionArgs , CheckTransactionIrrecoverableError , CheckTransactionResponse ,
6- CheckTransactionRetriable , CheckTransactionStatus , InitArg , UpgradeArg ,
7- CHECK_TRANSACTION_CYCLES_REQUIRED , CHECK_TRANSACTION_CYCLES_SERVICE_FEE ,
6+ CheckTransactionRetriable , CheckTransactionStatus , CheckTransactionStrArgs , InitArg ,
7+ UpgradeArg , CHECK_TRANSACTION_CYCLES_REQUIRED , CHECK_TRANSACTION_CYCLES_SERVICE_FEE ,
88 INITIAL_MAX_RESPONSE_BYTES ,
99} ;
1010use ic_btc_interface:: Txid ;
@@ -29,11 +29,11 @@ const TEST_SUBNET_NODES: u16 = 34;
2929// by a small margin. Namely, the universal_canister itself would consume
3030// some cycle for decoding args and sending the call.
3131//
32- // The number 42_000_000 is obtained empirically by running tests with pocket-ic
32+ // The number 43_000_000 is obtained empirically by running tests with pocket-ic
3333// and checking the actual consumptions. It is both big enough to allow tests to
3434// succeed, and small enough not to interfere with the expected cycle cost we
3535// are testing for.
36- const UNIVERSAL_CANISTER_CYCLE_MARGIN : u128 = 42_000_000 ;
36+ const UNIVERSAL_CANISTER_CYCLE_MARGIN : u128 = 43_000_000 ;
3737
3838struct Setup {
3939 // Owner of canisters created for the setup.
@@ -274,20 +274,21 @@ fn test_check_transaction_passed() {
274274 let txid =
275275 Txid :: from_str ( "c80763842edc9a697a2114517cf0c138c5403a761ef63cfad1fa6993fa3475ed" ) . unwrap ( ) ;
276276 let env = & setup. env ;
277+ let check_transaction_args = Encode ! ( & CheckTransactionArgs {
278+ txid: txid. as_ref( ) . to_vec( )
279+ } )
280+ . unwrap ( ) ;
281+ let check_transaction_str_args = Encode ! ( & CheckTransactionStrArgs {
282+ txid: txid. to_string( )
283+ } )
284+ . unwrap ( ) ;
277285
278286 // Normal operation requires making http outcalls.
279287 // We'll run this again after testing other CheckMode.
280- let test_normal_operation = || {
288+ let test_normal_operation = |method , arg | {
281289 let cycles_before = setup. env . cycle_balance ( setup. caller ) ;
282290 let call_id = setup
283- . submit_btc_checker_call (
284- "check_transaction" ,
285- Encode ! ( & CheckTransactionArgs {
286- txid: txid. as_ref( ) . to_vec( )
287- } )
288- . unwrap ( ) ,
289- CHECK_TRANSACTION_CYCLES_REQUIRED ,
290- )
291+ . submit_btc_checker_call ( method, arg, CHECK_TRANSACTION_CYCLES_REQUIRED )
291292 . expect ( "submit_call failed to return call id" ) ;
292293 // The response body used for testing below is generated from the output of
293294 //
@@ -375,7 +376,7 @@ fn test_check_transaction_passed() {
375376 } ;
376377
377378 // With default installation
378- test_normal_operation ( ) ;
379+ test_normal_operation ( "check_transaction" , check_transaction_args . clone ( ) ) ;
379380
380381 // Test CheckMode::RejectAll
381382 env. tick ( ) ;
@@ -470,7 +471,7 @@ fn test_check_transaction_passed() {
470471 )
471472 . unwrap ( ) ;
472473
473- test_normal_operation ( ) ;
474+ test_normal_operation ( "check_transaction_str" , check_transaction_str_args ) ;
474475}
475476
476477#[ test]
@@ -669,6 +670,37 @@ fn test_check_transaction_error() {
669670 let actual_cost = cycles_before - cycles_after;
670671 assert ! ( actual_cost > expected_cost) ;
671672 assert ! ( actual_cost - expected_cost < UNIVERSAL_CANISTER_CYCLE_MARGIN ) ;
673+
674+ // Test for malformatted txid in string form
675+ let cycles_before = setup. env . cycle_balance ( setup. caller ) ;
676+ let too_short_txid =
677+ "a80763842edc9a697a2114517cf0c138c5403a761ef63cfad1fa6993fa3475" . to_string ( ) ;
678+ let call_id = setup
679+ . submit_btc_checker_call (
680+ "check_transaction_str" ,
681+ Encode ! ( & CheckTransactionStrArgs {
682+ txid: too_short_txid
683+ } )
684+ . unwrap ( ) ,
685+ CHECK_TRANSACTION_CYCLES_REQUIRED ,
686+ )
687+ . expect ( "submit_call failed to return call id" ) ;
688+ let result = setup
689+ . env
690+ . await_call ( call_id)
691+ . expect ( "the fetch request didn't finish" ) ;
692+ assert ! ( matches!(
693+ decode:: <CheckTransactionResponse >( & result) ,
694+ CheckTransactionResponse :: Unknown ( CheckTransactionStatus :: Error (
695+ CheckTransactionIrrecoverableError :: InvalidTransactionId ( _)
696+ ) )
697+ ) ) ;
698+
699+ let cycles_after = setup. env . cycle_balance ( setup. caller ) ;
700+ let expected_cost = CHECK_TRANSACTION_CYCLES_SERVICE_FEE ;
701+ let actual_cost = cycles_before - cycles_after;
702+ assert ! ( actual_cost > expected_cost) ;
703+ assert ! ( actual_cost - expected_cost < UNIVERSAL_CANISTER_CYCLE_MARGIN ) ;
672704}
673705
674706fn tick_until_next_request ( env : & PocketIc ) -> Vec < CanisterHttpRequest > {
0 commit comments