diff --git a/etherlink/bin_node/lib_dev/tezlink/tezos_services.ml b/etherlink/bin_node/lib_dev/tezlink/tezos_services.ml index ae1455631dbed0ef15f09a9bfe5e6de4af6ea6fd..e5acaf25565c0ba21cb305377a4467abd342c6be 100644 --- a/etherlink/bin_node/lib_dev/tezlink/tezos_services.ml +++ b/etherlink/bin_node/lib_dev/tezlink/tezos_services.ml @@ -221,6 +221,20 @@ module Protocol_types = struct ~dst:encoding ~src:Data_encoding.z end + + module Contract = struct + let make_info (contract_balance, counter_z) = + let open Result_syntax in + let open Imported_protocol_plugin.Contract_services in + let* counter = Counter.of_z counter_z in + return + { + balance = contract_balance; + delegate = None; + counter = Some counter; + script = None; + } + end end (** [wrap conversion service_implementation] changes the output type @@ -438,6 +452,17 @@ module Imported_services = struct Tezos_rpc.Service.t = import_service Tezos_shell_services.Shell_services.Blocks.S.protocols + (* Queries will be ignored for now. *) + let contract_info : + ( [`GET], + tezlink_rpc_context, + tezlink_rpc_context * Tezos_types.Contract.t, + Imported_protocol_plugin.Contract_services.S.normalize_types_query, + unit, + Imported_protocol_plugin.Contract_services.info ) + Tezos_rpc.Service.t = + Tezos_rpc.Service.subst1 Imported_protocol_plugin.Contract_services.S.info + let balance : ( [`GET], tezlink_rpc_context, @@ -631,6 +656,15 @@ let register_block_services ~l2_chain_id let*? `Main = check_chain chain in let*? _block = check_block block in protocols ()) + |> register_with_conversion + ~service:Imported_services.contract_info + ~impl:(fun ({block; chain}, contract) _query () -> + let*? chain = check_chain chain in + let*? block = check_block block in + let* balance = Backend.balance chain block contract in + let* counter = Backend.counter chain block contract in + return (balance, counter)) + ~convert_output:Protocol_types.Contract.make_info |> register ~service:Imported_services.balance ~impl:(fun ({chain; block}, contract) _ _ -> diff --git a/etherlink/tezt/tests/evm_sequencer.ml b/etherlink/tezt/tests/evm_sequencer.ml index eb9c0c8119860419bc9923c29726afc8718102d4..6145a40d3bb656cb2533a86a67205163f50c2632 100644 --- a/etherlink/tezt/tests/evm_sequencer.ml +++ b/etherlink/tezt/tests/evm_sequencer.ml @@ -664,6 +664,21 @@ let account_rpc sequencer account key = in return @@ JSON.parse ~origin:"curl_protocols" res +let test_tezlink_contract_info = + register_tezlink_test + ~title:"Test of the contract info rpc" + ~tags:["rpc"; "contract"; "info"] + ~tez_bootstrap_accounts:[Constant.bootstrap1] + @@ fun {sequencer; _} _protocol -> + (* call the balance rpc and check the result *) + let* valid_info = account_rpc sequencer Constant.bootstrap1 "" in + let balance = JSON.(valid_info |-> "balance" |> as_int) in + let counter = JSON.(valid_info |-> "counter" |> as_int) in + + Check.((balance = 3800000000000) int ~error_msg:"Expected %R but got %L") ; + Check.((counter = 0) int ~error_msg:"Expected %R but got %L") ; + unit + let test_tezlink_manager_key = register_tezlink_test ~title:"Test of the manager_key rpc" @@ -13835,6 +13850,7 @@ let () = test_block_producer_validation [Alpha] ; test_durable_storage_consistency [Alpha] ; test_tezlink_current_level [Alpha] ; + test_tezlink_contract_info [Alpha] ; test_tezlink_balance [Alpha] ; test_tezlink_manager_key [Alpha] ; test_tezlink_counter [Alpha] ;