From c9c096e1a93d433a6b64114e48df538babf5b7c4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Rold=C3=A1n?= <62166813+Odraxs@users.noreply.github.com> Date: Tue, 18 Jul 2023 11:15:20 -0500 Subject: [PATCH 1/4] Soroban preview 10 (#274) * Preview 10 support files changes * Preview 10 support tests fixes * Revert operations files and change Op files modules --------- Co-authored-by: Edwin Steven Guayacan --- ...fig_setting_contract_execution_lanes_v0.ex | 63 +++++ .../config_setting/config_setting_entry.ex | 13 +- .../config_setting/config_setting_id.ex | 5 +- .../contract_cost_param_entry.ex | 40 ++-- .../config_setting/contract_cost_type.ex | 14 +- .../state_expiration_settings.ex | 220 ++++++++++++++++++ .../contract_executable.ex} | 29 ++- ...or_code.ex => contract_executable_type.ex} | 17 +- lib/xdr/contract/sc_bytes.ex | 22 +- lib/xdr/contract/sc_contract_executable.ex | 67 ------ lib/xdr/contract/sc_contract_instance.ex | 73 ++++++ lib/xdr/contract/sc_error.ex | 73 ++++++ lib/xdr/contract/sc_error_code.ex | 66 ++++++ lib/xdr/contract/sc_error_type.ex | 66 ++++++ .../contract/sc_host_storage_error_code.ex | 57 ----- lib/xdr/contract/sc_host_val_error_code.ex | 63 ----- lib/xdr/contract/sc_map.ex | 39 ++-- lib/xdr/contract/sc_nonce_key.ex | 40 ++-- lib/xdr/contract/sc_status.ex | 93 -------- lib/xdr/contract/sc_status_type.ex | 61 ----- lib/xdr/contract/sc_string.ex | 11 +- lib/xdr/contract/sc_val.ex | 20 +- lib/xdr/contract/sc_val_type.ex | 13 +- lib/xdr/contract/sc_vec.ex | 39 ++-- lib/xdr/contract/sc_vm_error_code.ex | 70 ------ lib/xdr/contract/spec/sc_spec_type.ex | 15 +- lib/xdr/contract/spec/sc_spec_type_def.ex | 53 +++-- lib/xdr/contract/uint64_list.ex | 57 +++++ lib/xdr/ledger_entries/contract_code_entry.ex | 84 +++++-- .../contract_code_entry_body.ex | 73 ++++++ .../contract_data_durability.ex} | 18 +- lib/xdr/ledger_entries/contract_data_entry.ex | 121 ++++++++-- .../contract_data_entry_body.ex | 73 ++++++ .../contract_data_entry_data.ex | 73 ++++++ .../contract_data_flags.ex} | 14 +- .../contract_entry_body_type.ex} | 15 +- lib/xdr/ledger_entries/envelope_type.ex | 13 +- lib/xdr/transactions/address_with_nonce.ex | 55 ----- .../{sc_val_list100.ex => asset_list5.ex} | 14 +- lib/xdr/transactions/authorized_invocation.ex | 120 ---------- .../authorized_invocation_list.ex | 53 ----- ...function_list100.ex => claimant_list10.ex} | 14 +- lib/xdr/transactions/contract_auth.ex | 103 -------- lib/xdr/transactions/contract_auth_list.ex | 53 ----- lib/xdr/transactions/contract_id.ex | 64 ----- lib/xdr/transactions/contract_id_preimage.ex | 73 ++++++ .../contract_id_preimage_from_address.ex | 73 ++++++ .../transactions/contract_id_preimage_type.ex | 58 +++++ .../contract_id_public_key_type.ex | 53 ----- lib/xdr/transactions/contract_id_type.ex | 54 ----- lib/xdr/transactions/create_contract_args.ex | 50 ++-- .../transactions/from_ed25519_public_key.ex | 91 -------- lib/xdr/transactions/hash_id_preimage.ex | 70 +++--- .../hash_id_preimage_contract_auth.ex | 75 ------ .../hash_id_preimage_contract_id.ex | 81 +++++++ .../hash_id_preimage_create_contract_args.ex | 84 ------- .../hash_id_preimage_soroban_authorization.ex | 130 +++++++++++ lib/xdr/transactions/host_function.ex | 77 +++--- .../invoke_host_function_result.ex | 6 +- lib/xdr/transactions/operation_body.ex | 108 ++++++--- lib/xdr/transactions/operation_type.ex | 11 +- .../operations/bump_footprint_expiration.ex | 73 ++++++ .../bump_footprint_expiration_result.ex | 73 ++++++ .../bump_footprint_expiration_result_code.ex | 59 +++++ .../hash_id_preimage_operation_id.ex | 88 +++++++ .../operations/hash_id_preimage_revoke_id.ex | 143 ++++++++++++ .../operations/invoke_host_function.ex | 44 ++-- .../operations/restore_footprint.ex | 61 +++++ .../operations/restore_footprint_result.ex | 72 ++++++ .../restore_footprint_result_code.ex} | 21 +- .../revoke_sponsorship_op_signer.ex | 73 ++++++ .../optional_address_with_nonce.ex | 59 ----- .../soroban_address_credentials.ex | 130 +++++++++++ .../soroban_authorization_entry.ex | 75 ++++++ .../soroban_authorization_entry_list.ex | 57 +++++ .../soroban_authorized_contract_function.ex | 105 +++++++++ .../soroban_authorized_function.ex | 74 ++++++ .../soroban_authorized_function_type.ex | 59 +++++ .../soroban_authorized_invocation.ex | 74 ++++++ .../soroban_authorized_invocation_list.ex | 57 +++++ lib/xdr/transactions/soroban_credentials.ex | 73 ++++++ .../soroban_credentials_type.ex} | 15 +- .../transactions/soroban_transaction_data.ex | 42 ++-- .../transactions/upload_contract_wasm_args.ex | 61 ----- ...ble_opaque256000.ex => variable_opaque.ex} | 16 +- mix.exs | 2 +- mix.lock | 2 +- .../contract_cost_param_entry_test.exs | 14 +- .../contract_cost_params_test.exs | 12 +- .../contract_cost_type_test.exs | 24 +- test/xdr/contract/sc_bytes_test.exs | 10 - .../contract/sc_contract_executable_test.exs | 79 ------- .../sc_contract_executable_type_test.exs | 66 ------ .../contract/sc_host_auth_error_code_test.exs | 49 ---- .../sc_host_context_error_code_test.exs | 49 ---- .../contract/sc_host_fn_error_code_test.exs | 49 ---- .../contract/sc_host_obj_error_code_test.exs | 49 ---- .../sc_host_storage_error_code_test.exs | 49 ---- .../contract/sc_host_val_error_code_test.exs | 49 ---- test/xdr/contract/sc_map_test.exs | 2 +- test/xdr/contract/sc_nonce_key_test.exs | 37 +-- test/xdr/contract/sc_status_test.exs | 117 ---------- test/xdr/contract/sc_status_type_test.exs | 48 ---- test/xdr/contract/sc_string_test.exs | 23 -- .../contract/sc_unknown_error_code_test.exs | 49 ---- test/xdr/contract/sc_val_test.exs | 48 ++-- test/xdr/contract/sc_vec_test.exs | 2 +- test/xdr/contract/sc_vm_error_code_test.exs | 48 ---- .../contract/spec/sc_spec_type_def_test.exs | 4 +- test/xdr/contract/spec/sc_spec_type_test.exs | 2 +- .../contract_code_entry_test.exs | 31 ++- .../contract_data_entry_test.exs | 57 ++++- .../ledger_entries/ledger_entry_data_test.exs | 39 +++- test/xdr/ledger_entries/ledger_entry_test.exs | 40 ++-- .../transactions/address_with_nonce_test.exs | 69 ------ .../authorized_invocation_list_test.exs | 99 -------- .../authorized_invocation_test.exs | 109 --------- .../transactions/contract_auth_list_test.exs | 132 ----------- test/xdr/transactions/contract_auth_test.exs | 145 ------------ .../contract_id_preimage_type_test.exs | 49 ++++ .../contract_id_public_key_type_test.exs | 49 ---- test/xdr/transactions/contract_id_test.exs | 162 ------------- .../transactions/contract_id_type_test.exs | 48 ---- .../create_contract_args_test.exs | 62 +++-- test/xdr/transactions/envelope_type_test.exs | 14 +- .../transactions/fee_bump_inner_tx_test.exs | 1 + .../from_ed25519_public_key_test.exs | 72 ------ ...d_preimage__soroban_authorization_test.exs | 139 +++++++++++ .../hash_id_preimage_contract_auth_test.exs | 116 --------- ..._id_preimage_create_contract_args_test.exs | 89 ------- .../transactions/hash_id_preimage_test.exs | 13 +- .../transactions/host_function_args_test.exs | 150 ------------ .../transactions/host_function_list100.exs | 143 ------------ .../host_function_list100_test.exs | 137 ----------- test/xdr/transactions/host_function_test.exs | 161 +++++++------ .../invoke_host_function_result_test.exs | 19 +- test/xdr/transactions/operation_body_test.exs | 2 +- .../operations/invoke_host_function_test.exs | 104 +++------ .../optional_address_with_nonce_test.exs | 94 -------- test/xdr/transactions/sc_val_list100_test.exs | 72 ------ .../soroban_transaction_data_test.exs | 18 +- .../upload_contract_wasm_args_test.exs | 47 ---- test/xdr/types/variable_opaque256000_test.exs | 51 ---- test/xdr/types/variable_opaque_test.exs | 41 ++++ 144 files changed, 3904 insertions(+), 4610 deletions(-) create mode 100644 lib/xdr/contract/config_setting/config_setting_contract_execution_lanes_v0.ex create mode 100644 lib/xdr/contract/config_setting/state_expiration_settings.ex rename lib/xdr/{transactions/host_function_args.ex => contract/contract_executable.ex} (62%) rename lib/xdr/contract/{sc_host_auth_error_code.ex => contract_executable_type.ex} (70%) delete mode 100644 lib/xdr/contract/sc_contract_executable.ex create mode 100644 lib/xdr/contract/sc_contract_instance.ex create mode 100644 lib/xdr/contract/sc_error.ex create mode 100644 lib/xdr/contract/sc_error_code.ex create mode 100644 lib/xdr/contract/sc_error_type.ex delete mode 100644 lib/xdr/contract/sc_host_storage_error_code.ex delete mode 100644 lib/xdr/contract/sc_host_val_error_code.ex delete mode 100644 lib/xdr/contract/sc_status.ex delete mode 100644 lib/xdr/contract/sc_status_type.ex delete mode 100644 lib/xdr/contract/sc_vm_error_code.ex create mode 100644 lib/xdr/contract/uint64_list.ex create mode 100644 lib/xdr/ledger_entries/contract_code_entry_body.ex rename lib/xdr/{contract/sc_host_fn_error_code.ex => ledger_entries/contract_data_durability.ex} (72%) create mode 100644 lib/xdr/ledger_entries/contract_data_entry_body.ex create mode 100644 lib/xdr/ledger_entries/contract_data_entry_data.ex rename lib/xdr/{contract/sc_unknown_error_code.ex => ledger_entries/contract_data_flags.ex} (74%) rename lib/xdr/{contract/sc_contract_executable_type.ex => ledger_entries/contract_entry_body_type.ex} (72%) delete mode 100644 lib/xdr/transactions/address_with_nonce.ex rename lib/xdr/transactions/{sc_val_list100.ex => asset_list5.ex} (81%) delete mode 100644 lib/xdr/transactions/authorized_invocation.ex delete mode 100644 lib/xdr/transactions/authorized_invocation_list.ex rename lib/xdr/transactions/{host_function_list100.ex => claimant_list10.ex} (79%) delete mode 100644 lib/xdr/transactions/contract_auth.ex delete mode 100644 lib/xdr/transactions/contract_auth_list.ex delete mode 100644 lib/xdr/transactions/contract_id.ex create mode 100644 lib/xdr/transactions/contract_id_preimage.ex create mode 100644 lib/xdr/transactions/contract_id_preimage_from_address.ex create mode 100644 lib/xdr/transactions/contract_id_preimage_type.ex delete mode 100644 lib/xdr/transactions/contract_id_public_key_type.ex delete mode 100644 lib/xdr/transactions/contract_id_type.ex delete mode 100644 lib/xdr/transactions/from_ed25519_public_key.ex delete mode 100644 lib/xdr/transactions/hash_id_preimage_contract_auth.ex create mode 100644 lib/xdr/transactions/hash_id_preimage_contract_id.ex delete mode 100644 lib/xdr/transactions/hash_id_preimage_create_contract_args.ex create mode 100644 lib/xdr/transactions/hash_id_preimage_soroban_authorization.ex create mode 100644 lib/xdr/transactions/operations/bump_footprint_expiration.ex create mode 100644 lib/xdr/transactions/operations/bump_footprint_expiration_result.ex create mode 100644 lib/xdr/transactions/operations/bump_footprint_expiration_result_code.ex create mode 100644 lib/xdr/transactions/operations/hash_id_preimage_operation_id.ex create mode 100644 lib/xdr/transactions/operations/hash_id_preimage_revoke_id.ex create mode 100644 lib/xdr/transactions/operations/restore_footprint.ex create mode 100644 lib/xdr/transactions/operations/restore_footprint_result.ex rename lib/xdr/{contract/sc_host_obj_error_code.ex => transactions/operations/restore_footprint_result_code.ex} (68%) create mode 100644 lib/xdr/transactions/operations/revoke_sponsorship_op_signer.ex delete mode 100644 lib/xdr/transactions/optional_address_with_nonce.ex create mode 100644 lib/xdr/transactions/soroban_address_credentials.ex create mode 100644 lib/xdr/transactions/soroban_authorization_entry.ex create mode 100644 lib/xdr/transactions/soroban_authorization_entry_list.ex create mode 100644 lib/xdr/transactions/soroban_authorized_contract_function.ex create mode 100644 lib/xdr/transactions/soroban_authorized_function.ex create mode 100644 lib/xdr/transactions/soroban_authorized_function_type.ex create mode 100644 lib/xdr/transactions/soroban_authorized_invocation.ex create mode 100644 lib/xdr/transactions/soroban_authorized_invocation_list.ex create mode 100644 lib/xdr/transactions/soroban_credentials.ex rename lib/xdr/{contract/sc_host_context_error_code.ex => transactions/soroban_credentials_type.ex} (69%) delete mode 100644 lib/xdr/transactions/upload_contract_wasm_args.ex rename lib/xdr/types/{variable_opaque256000.ex => variable_opaque.ex} (74%) delete mode 100644 test/xdr/contract/sc_contract_executable_test.exs delete mode 100644 test/xdr/contract/sc_contract_executable_type_test.exs delete mode 100644 test/xdr/contract/sc_host_auth_error_code_test.exs delete mode 100644 test/xdr/contract/sc_host_context_error_code_test.exs delete mode 100644 test/xdr/contract/sc_host_fn_error_code_test.exs delete mode 100644 test/xdr/contract/sc_host_obj_error_code_test.exs delete mode 100644 test/xdr/contract/sc_host_storage_error_code_test.exs delete mode 100644 test/xdr/contract/sc_host_val_error_code_test.exs delete mode 100644 test/xdr/contract/sc_status_test.exs delete mode 100644 test/xdr/contract/sc_status_type_test.exs delete mode 100644 test/xdr/contract/sc_unknown_error_code_test.exs delete mode 100644 test/xdr/contract/sc_vm_error_code_test.exs delete mode 100644 test/xdr/transactions/address_with_nonce_test.exs delete mode 100644 test/xdr/transactions/authorized_invocation_list_test.exs delete mode 100644 test/xdr/transactions/authorized_invocation_test.exs delete mode 100644 test/xdr/transactions/contract_auth_list_test.exs delete mode 100644 test/xdr/transactions/contract_auth_test.exs create mode 100644 test/xdr/transactions/contract_id_preimage_type_test.exs delete mode 100644 test/xdr/transactions/contract_id_public_key_type_test.exs delete mode 100644 test/xdr/transactions/contract_id_test.exs delete mode 100644 test/xdr/transactions/contract_id_type_test.exs delete mode 100644 test/xdr/transactions/from_ed25519_public_key_test.exs create mode 100644 test/xdr/transactions/hash_id_preimage__soroban_authorization_test.exs delete mode 100644 test/xdr/transactions/hash_id_preimage_contract_auth_test.exs delete mode 100644 test/xdr/transactions/hash_id_preimage_create_contract_args_test.exs delete mode 100644 test/xdr/transactions/host_function_args_test.exs delete mode 100644 test/xdr/transactions/host_function_list100.exs delete mode 100644 test/xdr/transactions/host_function_list100_test.exs delete mode 100644 test/xdr/transactions/optional_address_with_nonce_test.exs delete mode 100644 test/xdr/transactions/sc_val_list100_test.exs delete mode 100644 test/xdr/transactions/upload_contract_wasm_args_test.exs delete mode 100644 test/xdr/types/variable_opaque256000_test.exs create mode 100644 test/xdr/types/variable_opaque_test.exs diff --git a/lib/xdr/contract/config_setting/config_setting_contract_execution_lanes_v0.ex b/lib/xdr/contract/config_setting/config_setting_contract_execution_lanes_v0.ex new file mode 100644 index 00000000..7fd4daf5 --- /dev/null +++ b/lib/xdr/contract/config_setting/config_setting_contract_execution_lanes_v0.ex @@ -0,0 +1,63 @@ +defmodule StellarBase.XDR.ConfigSettingContractExecutionLanesV0 do + @moduledoc """ + Automatically generated by xdrgen + DO NOT EDIT or your changes may be overwritten + + Target implementation: elixir_xdr at https://hex.pm/packages/elixir_xdr + + Representation of Stellar `ConfigSettingContractExecutionLanesV0` type. + """ + + @behaviour XDR.Declaration + + alias StellarBase.XDR.UInt32 + + @struct_spec XDR.Struct.new(ledger_max_tx_count: UInt32) + + @type ledger_max_tx_count_type :: UInt32.t() + + @type t :: %__MODULE__{ledger_max_tx_count: ledger_max_tx_count_type()} + + defstruct [:ledger_max_tx_count] + + @spec new(ledger_max_tx_count :: ledger_max_tx_count_type()) :: t() + def new(%UInt32{} = ledger_max_tx_count), + do: %__MODULE__{ledger_max_tx_count: ledger_max_tx_count} + + @impl true + def encode_xdr(%__MODULE__{ledger_max_tx_count: ledger_max_tx_count}) do + [ledger_max_tx_count: ledger_max_tx_count] + |> XDR.Struct.new() + |> XDR.Struct.encode_xdr() + end + + @impl true + def encode_xdr!(%__MODULE__{ledger_max_tx_count: ledger_max_tx_count}) do + [ledger_max_tx_count: ledger_max_tx_count] + |> XDR.Struct.new() + |> XDR.Struct.encode_xdr!() + end + + @impl true + def decode_xdr(bytes, struct \\ @struct_spec) + + def decode_xdr(bytes, struct) do + case XDR.Struct.decode_xdr(bytes, struct) do + {:ok, {%XDR.Struct{components: [ledger_max_tx_count: ledger_max_tx_count]}, rest}} -> + {:ok, {new(ledger_max_tx_count), rest}} + + error -> + error + end + end + + @impl true + def decode_xdr!(bytes, struct \\ @struct_spec) + + def decode_xdr!(bytes, struct) do + {%XDR.Struct{components: [ledger_max_tx_count: ledger_max_tx_count]}, rest} = + XDR.Struct.decode_xdr!(bytes, struct) + + {new(ledger_max_tx_count), rest} + end +end diff --git a/lib/xdr/contract/config_setting/config_setting_entry.ex b/lib/xdr/contract/config_setting/config_setting_entry.ex index 4d9d56db..2783a0d1 100644 --- a/lib/xdr/contract/config_setting/config_setting_entry.ex +++ b/lib/xdr/contract/config_setting/config_setting_entry.ex @@ -18,7 +18,10 @@ defmodule StellarBase.XDR.ConfigSettingEntry do ConfigSettingContractHistoricalDataV0, ConfigSettingContractMetaDataV0, ConfigSettingContractBandwidthV0, - ContractCostParams + ContractCostParams, + StateExpirationSettings, + ConfigSettingContractExecutionLanesV0, + UInt64List } @arms [ @@ -31,7 +34,10 @@ defmodule StellarBase.XDR.ConfigSettingEntry do CONFIG_SETTING_CONTRACT_COST_PARAMS_CPU_INSTRUCTIONS: ContractCostParams, CONFIG_SETTING_CONTRACT_COST_PARAMS_MEMORY_BYTES: ContractCostParams, CONFIG_SETTING_CONTRACT_DATA_KEY_SIZE_BYTES: UInt32, - CONFIG_SETTING_CONTRACT_DATA_ENTRY_SIZE_BYTES: UInt32 + CONFIG_SETTING_CONTRACT_DATA_ENTRY_SIZE_BYTES: UInt32, + CONFIG_SETTING_STATE_EXPIRATION: StateExpirationSettings, + CONFIG_SETTING_CONTRACT_EXECUTION_LANES: ConfigSettingContractExecutionLanesV0, + CONFIG_SETTING_BUCKETLIST_SIZE_WINDOW: UInt64List ] @type value :: @@ -42,6 +48,9 @@ defmodule StellarBase.XDR.ConfigSettingEntry do | ConfigSettingContractMetaDataV0.t() | ConfigSettingContractBandwidthV0.t() | ContractCostParams.t() + | StateExpirationSettings.t() + | ConfigSettingContractExecutionLanesV0.t() + | UInt64List.t() @type t :: %__MODULE__{value: value(), type: ConfigSettingID.t()} diff --git a/lib/xdr/contract/config_setting/config_setting_id.ex b/lib/xdr/contract/config_setting/config_setting_id.ex index 6a205a3b..97a3462c 100644 --- a/lib/xdr/contract/config_setting/config_setting_id.ex +++ b/lib/xdr/contract/config_setting/config_setting_id.ex @@ -20,7 +20,10 @@ defmodule StellarBase.XDR.ConfigSettingID do CONFIG_SETTING_CONTRACT_COST_PARAMS_CPU_INSTRUCTIONS: 6, CONFIG_SETTING_CONTRACT_COST_PARAMS_MEMORY_BYTES: 7, CONFIG_SETTING_CONTRACT_DATA_KEY_SIZE_BYTES: 8, - CONFIG_SETTING_CONTRACT_DATA_ENTRY_SIZE_BYTES: 9 + CONFIG_SETTING_CONTRACT_DATA_ENTRY_SIZE_BYTES: 9, + CONFIG_SETTING_STATE_EXPIRATION: 10, + CONFIG_SETTING_CONTRACT_EXECUTION_LANES: 11, + CONFIG_SETTING_BUCKETLIST_SIZE_WINDOW: 12 ] @enum_spec %XDR.Enum{declarations: @declarations, identifier: nil} diff --git a/lib/xdr/contract/config_setting/contract_cost_param_entry.ex b/lib/xdr/contract/config_setting/contract_cost_param_entry.ex index b5d75de4..d9d50364 100644 --- a/lib/xdr/contract/config_setting/contract_cost_param_entry.ex +++ b/lib/xdr/contract/config_setting/contract_cost_param_entry.ex @@ -11,47 +11,47 @@ defmodule StellarBase.XDR.ContractCostParamEntry do @behaviour XDR.Declaration alias StellarBase.XDR.{ - Int64, - ExtensionPoint + ExtensionPoint, + Int64 } @struct_spec XDR.Struct.new( + ext: ExtensionPoint, const_term: Int64, - linear_term: Int64, - ext: ExtensionPoint + linear_term: Int64 ) + @type ext_type :: ExtensionPoint.t() @type const_term_type :: Int64.t() @type linear_term_type :: Int64.t() - @type ext_type :: ExtensionPoint.t() @type t :: %__MODULE__{ + ext: ext_type(), const_term: const_term_type(), - linear_term: linear_term_type(), - ext: ext_type() + linear_term: linear_term_type() } - defstruct [:const_term, :linear_term, :ext] + defstruct [:ext, :const_term, :linear_term] - @spec new(const_term :: const_term_type(), linear_term :: linear_term_type(), ext :: ext_type()) :: + @spec new(ext :: ext_type(), const_term :: const_term_type(), linear_term :: linear_term_type()) :: t() def new( + %ExtensionPoint{} = ext, %Int64{} = const_term, - %Int64{} = linear_term, - %ExtensionPoint{} = ext + %Int64{} = linear_term ), - do: %__MODULE__{const_term: const_term, linear_term: linear_term, ext: ext} + do: %__MODULE__{ext: ext, const_term: const_term, linear_term: linear_term} @impl true - def encode_xdr(%__MODULE__{const_term: const_term, linear_term: linear_term, ext: ext}) do - [const_term: const_term, linear_term: linear_term, ext: ext] + def encode_xdr(%__MODULE__{ext: ext, const_term: const_term, linear_term: linear_term}) do + [ext: ext, const_term: const_term, linear_term: linear_term] |> XDR.Struct.new() |> XDR.Struct.encode_xdr() end @impl true - def encode_xdr!(%__MODULE__{const_term: const_term, linear_term: linear_term, ext: ext}) do - [const_term: const_term, linear_term: linear_term, ext: ext] + def encode_xdr!(%__MODULE__{ext: ext, const_term: const_term, linear_term: linear_term}) do + [ext: ext, const_term: const_term, linear_term: linear_term] |> XDR.Struct.new() |> XDR.Struct.encode_xdr!() end @@ -62,9 +62,9 @@ defmodule StellarBase.XDR.ContractCostParamEntry do def decode_xdr(bytes, struct) do case XDR.Struct.decode_xdr(bytes, struct) do {:ok, - {%XDR.Struct{components: [const_term: const_term, linear_term: linear_term, ext: ext]}, + {%XDR.Struct{components: [ext: ext, const_term: const_term, linear_term: linear_term]}, rest}} -> - {:ok, {new(const_term, linear_term, ext), rest}} + {:ok, {new(ext, const_term, linear_term), rest}} error -> error @@ -75,9 +75,9 @@ defmodule StellarBase.XDR.ContractCostParamEntry do def decode_xdr!(bytes, struct \\ @struct_spec) def decode_xdr!(bytes, struct) do - {%XDR.Struct{components: [const_term: const_term, linear_term: linear_term, ext: ext]}, rest} = + {%XDR.Struct{components: [ext: ext, const_term: const_term, linear_term: linear_term]}, rest} = XDR.Struct.decode_xdr!(bytes, struct) - {new(const_term, linear_term, ext), rest} + {new(ext, const_term, linear_term), rest} end end diff --git a/lib/xdr/contract/config_setting/contract_cost_type.ex b/lib/xdr/contract/config_setting/contract_cost_type.ex index 184e0871..6b604969 100644 --- a/lib/xdr/contract/config_setting/contract_cost_type.ex +++ b/lib/xdr/contract/config_setting/contract_cost_type.ex @@ -30,8 +30,18 @@ defmodule StellarBase.XDR.ContractCostType do VmMemRead: 16, VmMemWrite: 17, VmInstantiation: 18, - InvokeVmFunction: 19, - ChargeBudget: 20 + VmCachedInstantiation: 19, + InvokeVmFunction: 20, + ChargeBudget: 21, + ComputeKeccak256Hash: 22, + ComputeEcdsaSecp256k1Key: 23, + ComputeEcdsaSecp256k1Sig: 24, + RecoverEcdsaSecp256k1Key: 25, + Int256AddSub: 26, + Int256Mul: 27, + Int256Div: 28, + Int256Pow: 29, + Int256Shift: 30 ] @enum_spec %XDR.Enum{declarations: @declarations, identifier: nil} diff --git a/lib/xdr/contract/config_setting/state_expiration_settings.ex b/lib/xdr/contract/config_setting/state_expiration_settings.ex new file mode 100644 index 00000000..587bc5ea --- /dev/null +++ b/lib/xdr/contract/config_setting/state_expiration_settings.ex @@ -0,0 +1,220 @@ +defmodule StellarBase.XDR.StateExpirationSettings do + @moduledoc """ + Automatically generated by xdrgen + DO NOT EDIT or your changes may be overwritten + + Target implementation: elixir_xdr at https://hex.pm/packages/elixir_xdr + + Representation of Stellar `StateExpirationSettings` type. + """ + + @behaviour XDR.Declaration + + alias StellarBase.XDR.{ + UInt32, + Int64, + UInt64 + } + + @struct_spec XDR.Struct.new( + max_entry_expiration: UInt32, + min_temp_entry_expiration: UInt32, + min_persistent_entry_expiration: UInt32, + auto_bump_ledgers: UInt32, + persistent_rent_rate_denominator: Int64, + temp_rent_rate_denominator: Int64, + max_entries_to_expire: UInt32, + bucket_list_size_window_sample_size: UInt32, + eviction_scan_size: UInt64 + ) + + @type max_entry_expiration_type :: UInt32.t() + @type min_temp_entry_expiration_type :: UInt32.t() + @type min_persistent_entry_expiration_type :: UInt32.t() + @type auto_bump_ledgers_type :: UInt32.t() + @type persistent_rent_rate_denominator_type :: Int64.t() + @type temp_rent_rate_denominator_type :: Int64.t() + @type max_entries_to_expire_type :: UInt32.t() + @type bucket_list_size_window_sample_size_type :: UInt32.t() + @type eviction_scan_size_type :: UInt64.t() + + @type t :: %__MODULE__{ + max_entry_expiration: max_entry_expiration_type(), + min_temp_entry_expiration: min_temp_entry_expiration_type(), + min_persistent_entry_expiration: min_persistent_entry_expiration_type(), + auto_bump_ledgers: auto_bump_ledgers_type(), + persistent_rent_rate_denominator: persistent_rent_rate_denominator_type(), + temp_rent_rate_denominator: temp_rent_rate_denominator_type(), + max_entries_to_expire: max_entries_to_expire_type(), + bucket_list_size_window_sample_size: bucket_list_size_window_sample_size_type(), + eviction_scan_size: eviction_scan_size_type() + } + + defstruct [ + :max_entry_expiration, + :min_temp_entry_expiration, + :min_persistent_entry_expiration, + :auto_bump_ledgers, + :persistent_rent_rate_denominator, + :temp_rent_rate_denominator, + :max_entries_to_expire, + :bucket_list_size_window_sample_size, + :eviction_scan_size + ] + + @spec new( + max_entry_expiration :: max_entry_expiration_type(), + min_temp_entry_expiration :: min_temp_entry_expiration_type(), + min_persistent_entry_expiration :: min_persistent_entry_expiration_type(), + auto_bump_ledgers :: auto_bump_ledgers_type(), + persistent_rent_rate_denominator :: persistent_rent_rate_denominator_type(), + temp_rent_rate_denominator :: temp_rent_rate_denominator_type(), + max_entries_to_expire :: max_entries_to_expire_type(), + bucket_list_size_window_sample_size :: bucket_list_size_window_sample_size_type(), + eviction_scan_size :: eviction_scan_size_type() + ) :: t() + def new( + %UInt32{} = max_entry_expiration, + %UInt32{} = min_temp_entry_expiration, + %UInt32{} = min_persistent_entry_expiration, + %UInt32{} = auto_bump_ledgers, + %Int64{} = persistent_rent_rate_denominator, + %Int64{} = temp_rent_rate_denominator, + %UInt32{} = max_entries_to_expire, + %UInt32{} = bucket_list_size_window_sample_size, + %UInt64{} = eviction_scan_size + ), + do: %__MODULE__{ + max_entry_expiration: max_entry_expiration, + min_temp_entry_expiration: min_temp_entry_expiration, + min_persistent_entry_expiration: min_persistent_entry_expiration, + auto_bump_ledgers: auto_bump_ledgers, + persistent_rent_rate_denominator: persistent_rent_rate_denominator, + temp_rent_rate_denominator: temp_rent_rate_denominator, + max_entries_to_expire: max_entries_to_expire, + bucket_list_size_window_sample_size: bucket_list_size_window_sample_size, + eviction_scan_size: eviction_scan_size + } + + @impl true + def encode_xdr(%__MODULE__{ + max_entry_expiration: max_entry_expiration, + min_temp_entry_expiration: min_temp_entry_expiration, + min_persistent_entry_expiration: min_persistent_entry_expiration, + auto_bump_ledgers: auto_bump_ledgers, + persistent_rent_rate_denominator: persistent_rent_rate_denominator, + temp_rent_rate_denominator: temp_rent_rate_denominator, + max_entries_to_expire: max_entries_to_expire, + bucket_list_size_window_sample_size: bucket_list_size_window_sample_size, + eviction_scan_size: eviction_scan_size + }) do + [ + max_entry_expiration: max_entry_expiration, + min_temp_entry_expiration: min_temp_entry_expiration, + min_persistent_entry_expiration: min_persistent_entry_expiration, + auto_bump_ledgers: auto_bump_ledgers, + persistent_rent_rate_denominator: persistent_rent_rate_denominator, + temp_rent_rate_denominator: temp_rent_rate_denominator, + max_entries_to_expire: max_entries_to_expire, + bucket_list_size_window_sample_size: bucket_list_size_window_sample_size, + eviction_scan_size: eviction_scan_size + ] + |> XDR.Struct.new() + |> XDR.Struct.encode_xdr() + end + + @impl true + def encode_xdr!(%__MODULE__{ + max_entry_expiration: max_entry_expiration, + min_temp_entry_expiration: min_temp_entry_expiration, + min_persistent_entry_expiration: min_persistent_entry_expiration, + auto_bump_ledgers: auto_bump_ledgers, + persistent_rent_rate_denominator: persistent_rent_rate_denominator, + temp_rent_rate_denominator: temp_rent_rate_denominator, + max_entries_to_expire: max_entries_to_expire, + bucket_list_size_window_sample_size: bucket_list_size_window_sample_size, + eviction_scan_size: eviction_scan_size + }) do + [ + max_entry_expiration: max_entry_expiration, + min_temp_entry_expiration: min_temp_entry_expiration, + min_persistent_entry_expiration: min_persistent_entry_expiration, + auto_bump_ledgers: auto_bump_ledgers, + persistent_rent_rate_denominator: persistent_rent_rate_denominator, + temp_rent_rate_denominator: temp_rent_rate_denominator, + max_entries_to_expire: max_entries_to_expire, + bucket_list_size_window_sample_size: bucket_list_size_window_sample_size, + eviction_scan_size: eviction_scan_size + ] + |> XDR.Struct.new() + |> XDR.Struct.encode_xdr!() + end + + @impl true + def decode_xdr(bytes, struct \\ @struct_spec) + + def decode_xdr(bytes, struct) do + case XDR.Struct.decode_xdr(bytes, struct) do + {:ok, + {%XDR.Struct{ + components: [ + max_entry_expiration: max_entry_expiration, + min_temp_entry_expiration: min_temp_entry_expiration, + min_persistent_entry_expiration: min_persistent_entry_expiration, + auto_bump_ledgers: auto_bump_ledgers, + persistent_rent_rate_denominator: persistent_rent_rate_denominator, + temp_rent_rate_denominator: temp_rent_rate_denominator, + max_entries_to_expire: max_entries_to_expire, + bucket_list_size_window_sample_size: bucket_list_size_window_sample_size, + eviction_scan_size: eviction_scan_size + ] + }, rest}} -> + {:ok, + {new( + max_entry_expiration, + min_temp_entry_expiration, + min_persistent_entry_expiration, + auto_bump_ledgers, + persistent_rent_rate_denominator, + temp_rent_rate_denominator, + max_entries_to_expire, + bucket_list_size_window_sample_size, + eviction_scan_size + ), rest}} + + error -> + error + end + end + + @impl true + def decode_xdr!(bytes, struct \\ @struct_spec) + + def decode_xdr!(bytes, struct) do + {%XDR.Struct{ + components: [ + max_entry_expiration: max_entry_expiration, + min_temp_entry_expiration: min_temp_entry_expiration, + min_persistent_entry_expiration: min_persistent_entry_expiration, + auto_bump_ledgers: auto_bump_ledgers, + persistent_rent_rate_denominator: persistent_rent_rate_denominator, + temp_rent_rate_denominator: temp_rent_rate_denominator, + max_entries_to_expire: max_entries_to_expire, + bucket_list_size_window_sample_size: bucket_list_size_window_sample_size, + eviction_scan_size: eviction_scan_size + ] + }, rest} = XDR.Struct.decode_xdr!(bytes, struct) + + {new( + max_entry_expiration, + min_temp_entry_expiration, + min_persistent_entry_expiration, + auto_bump_ledgers, + persistent_rent_rate_denominator, + temp_rent_rate_denominator, + max_entries_to_expire, + bucket_list_size_window_sample_size, + eviction_scan_size + ), rest} + end +end diff --git a/lib/xdr/transactions/host_function_args.ex b/lib/xdr/contract/contract_executable.ex similarity index 62% rename from lib/xdr/transactions/host_function_args.ex rename to lib/xdr/contract/contract_executable.ex index ecebad3b..da324e34 100644 --- a/lib/xdr/transactions/host_function_args.ex +++ b/lib/xdr/contract/contract_executable.ex @@ -1,39 +1,36 @@ -defmodule StellarBase.XDR.HostFunctionArgs do +defmodule StellarBase.XDR.ContractExecutable do @moduledoc """ Automatically generated by xdrgen DO NOT EDIT or your changes may be overwritten Target implementation: elixir_xdr at https://hex.pm/packages/elixir_xdr - Representation of Stellar `HostFunctionArgs` type. + Representation of Stellar `ContractExecutable` type. """ @behaviour XDR.Declaration alias StellarBase.XDR.{ - HostFunctionType, - SCVec, - CreateContractArgs, - UploadContractWasmArgs + ContractExecutableType, + Hash, + Void } @arms [ - HOST_FUNCTION_TYPE_INVOKE_CONTRACT: SCVec, - HOST_FUNCTION_TYPE_CREATE_CONTRACT: CreateContractArgs, - HOST_FUNCTION_TYPE_UPLOAD_CONTRACT_WASM: UploadContractWasmArgs + CONTRACT_EXECUTABLE_WASM: Hash, + CONTRACT_EXECUTABLE_TOKEN: Void ] @type value :: - SCVec.t() - | CreateContractArgs.t() - | UploadContractWasmArgs.t() + Hash.t() + | Void.t() - @type t :: %__MODULE__{value: value(), type: HostFunctionType.t()} + @type t :: %__MODULE__{value: value(), type: ContractExecutableType.t()} defstruct [:value, :type] - @spec new(value :: value(), type :: HostFunctionType.t()) :: t() - def new(value, %HostFunctionType{} = type), do: %__MODULE__{value: value, type: type} + @spec new(value :: value(), type :: ContractExecutableType.t()) :: t() + def new(value, %ContractExecutableType{} = type), do: %__MODULE__{value: value, type: type} @impl true def encode_xdr(%__MODULE__{value: value, type: type}) do @@ -70,7 +67,7 @@ defmodule StellarBase.XDR.HostFunctionArgs do @spec union_spec() :: XDR.Union.t() defp union_spec do nil - |> HostFunctionType.new() + |> ContractExecutableType.new() |> XDR.Union.new(@arms) end end diff --git a/lib/xdr/contract/sc_host_auth_error_code.ex b/lib/xdr/contract/contract_executable_type.ex similarity index 70% rename from lib/xdr/contract/sc_host_auth_error_code.ex rename to lib/xdr/contract/contract_executable_type.ex index 1542aee7..056c1805 100644 --- a/lib/xdr/contract/sc_host_auth_error_code.ex +++ b/lib/xdr/contract/contract_executable_type.ex @@ -1,15 +1,18 @@ -defmodule StellarBase.XDR.SCHostAuthErrorCode do +defmodule StellarBase.XDR.ContractExecutableType do @moduledoc """ - Representation of Stellar `SCHostAuthErrorCode` type. + Automatically generated by xdrgen + DO NOT EDIT or your changes may be overwritten + + Target implementation: elixir_xdr at https://hex.pm/packages/elixir_xdr + + Representation of Stellar `ContractExecutableType` type. """ @behaviour XDR.Declaration @declarations [ - HOST_AUTH_UNKNOWN_ERROR: 0, - HOST_AUTH_NONCE_ERROR: 1, - HOST_AUTH_DUPLICATE_AUTHORIZATION: 2, - HOST_AUTH_NOT_AUTHORIZED: 3 + CONTRACT_EXECUTABLE_WASM: 0, + CONTRACT_EXECUTABLE_TOKEN: 1 ] @enum_spec %XDR.Enum{declarations: @declarations, identifier: nil} @@ -19,7 +22,7 @@ defmodule StellarBase.XDR.SCHostAuthErrorCode do defstruct [:identifier] @spec new(type :: atom()) :: t() - def new(type \\ :HOST_AUTH_UNKNOWN_ERROR), do: %__MODULE__{identifier: type} + def new(type \\ :CONTRACT_EXECUTABLE_WASM), do: %__MODULE__{identifier: type} @impl true def encode_xdr(%__MODULE__{identifier: type}) do diff --git a/lib/xdr/contract/sc_bytes.ex b/lib/xdr/contract/sc_bytes.ex index 3765f5b8..215c6aae 100644 --- a/lib/xdr/contract/sc_bytes.ex +++ b/lib/xdr/contract/sc_bytes.ex @@ -1,11 +1,17 @@ defmodule StellarBase.XDR.SCBytes do @moduledoc """ + Automatically generated by xdrgen + DO NOT EDIT or your changes may be overwritten + + Target implementation: elixir_xdr at https://hex.pm/packages/elixir_xdr + Representation of Stellar `SCBytes` type. """ - alias StellarBase.XDR.VariableOpaque256000 @behaviour XDR.Declaration + alias StellarBase.XDR.VariableOpaque + @type t :: %__MODULE__{value: binary()} defstruct [:value] @@ -16,23 +22,23 @@ defmodule StellarBase.XDR.SCBytes do @impl true def encode_xdr(%__MODULE__{value: value}) do value - |> VariableOpaque256000.new() - |> VariableOpaque256000.encode_xdr() + |> VariableOpaque.new() + |> VariableOpaque.encode_xdr() end @impl true def encode_xdr!(%__MODULE__{value: value}) do value - |> VariableOpaque256000.new() - |> VariableOpaque256000.encode_xdr!() + |> VariableOpaque.new() + |> VariableOpaque.encode_xdr!() end @impl true def decode_xdr(bytes, term \\ nil) def decode_xdr(bytes, _term) do - case VariableOpaque256000.decode_xdr(bytes) do - {:ok, {%VariableOpaque256000{opaque: value}, rest}} -> {:ok, {new(value), rest}} + case VariableOpaque.decode_xdr(bytes) do + {:ok, {%VariableOpaque{opaque: value}, rest}} -> {:ok, {new(value), rest}} error -> error end end @@ -41,7 +47,7 @@ defmodule StellarBase.XDR.SCBytes do def decode_xdr!(bytes, term \\ nil) def decode_xdr!(bytes, _term) do - {%VariableOpaque256000{opaque: value}, rest} = VariableOpaque256000.decode_xdr!(bytes) + {%VariableOpaque{opaque: value}, rest} = VariableOpaque.decode_xdr!(bytes) {new(value), rest} end end diff --git a/lib/xdr/contract/sc_contract_executable.ex b/lib/xdr/contract/sc_contract_executable.ex deleted file mode 100644 index 1bcb6e2d..00000000 --- a/lib/xdr/contract/sc_contract_executable.ex +++ /dev/null @@ -1,67 +0,0 @@ -defmodule StellarBase.XDR.SCContractExecutable do - @moduledoc """ - Representation of Stellar `SCContractExecutable` type. - """ - - alias StellarBase.XDR.{Hash, SCContractExecutableType, Void} - - @behaviour XDR.Declaration - - @arms [ - SCCONTRACT_EXECUTABLE_WASM_REF: Hash, - SCCONTRACT_EXECUTABLE_TOKEN: Void - ] - - @type contract_executable :: Hash.t() | Void.t() - - @type t :: %__MODULE__{ - contract_executable: contract_executable(), - type: SCContractExecutableType.t() - } - - defstruct [:contract_executable, :type] - - @spec new(contract_executable :: contract_executable(), type :: SCContractExecutableType.t()) :: - t() - def new(contract_executable, %SCContractExecutableType{} = type), - do: %__MODULE__{contract_executable: contract_executable, type: type} - - @impl true - def encode_xdr(%__MODULE__{contract_executable: contract_executable, type: type}) do - type - |> XDR.Union.new(@arms, contract_executable) - |> XDR.Union.encode_xdr() - end - - @impl true - def encode_xdr!(%__MODULE__{contract_executable: contract_executable, type: type}) do - type - |> XDR.Union.new(@arms, contract_executable) - |> XDR.Union.encode_xdr!() - end - - @impl true - def decode_xdr(bytes, spec \\ union_spec()) - - def decode_xdr(bytes, spec) do - case XDR.Union.decode_xdr(bytes, spec) do - {:ok, {{type, contract_executable}, rest}} -> {:ok, {new(contract_executable, type), rest}} - error -> error - end - end - - @impl true - def decode_xdr!(bytes, spec \\ union_spec()) - - def decode_xdr!(bytes, spec) do - {{type, contract_executable}, rest} = XDR.Union.decode_xdr!(bytes, spec) - {new(contract_executable, type), rest} - end - - @spec union_spec() :: XDR.Union.t() - defp union_spec do - nil - |> SCContractExecutableType.new() - |> XDR.Union.new(@arms) - end -end diff --git a/lib/xdr/contract/sc_contract_instance.ex b/lib/xdr/contract/sc_contract_instance.ex new file mode 100644 index 00000000..7af37843 --- /dev/null +++ b/lib/xdr/contract/sc_contract_instance.ex @@ -0,0 +1,73 @@ +defmodule StellarBase.XDR.SCContractInstance do + @moduledoc """ + Automatically generated by xdrgen + DO NOT EDIT or your changes may be overwritten + + Target implementation: elixir_xdr at https://hex.pm/packages/elixir_xdr + + Representation of Stellar `SCContractInstance` type. + """ + + @behaviour XDR.Declaration + + alias StellarBase.XDR.{ + ContractExecutable, + OptionalSCMap + } + + @struct_spec XDR.Struct.new( + executable: ContractExecutable, + storage: OptionalSCMap + ) + + @type executable_type :: ContractExecutable.t() + @type storage_type :: OptionalSCMap.t() + + @type t :: %__MODULE__{executable: executable_type(), storage: storage_type()} + + defstruct [:executable, :storage] + + @spec new(executable :: executable_type(), storage :: storage_type()) :: t() + def new( + %ContractExecutable{} = executable, + %OptionalSCMap{} = storage + ), + do: %__MODULE__{executable: executable, storage: storage} + + @impl true + def encode_xdr(%__MODULE__{executable: executable, storage: storage}) do + [executable: executable, storage: storage] + |> XDR.Struct.new() + |> XDR.Struct.encode_xdr() + end + + @impl true + def encode_xdr!(%__MODULE__{executable: executable, storage: storage}) do + [executable: executable, storage: storage] + |> XDR.Struct.new() + |> XDR.Struct.encode_xdr!() + end + + @impl true + def decode_xdr(bytes, struct \\ @struct_spec) + + def decode_xdr(bytes, struct) do + case XDR.Struct.decode_xdr(bytes, struct) do + {:ok, {%XDR.Struct{components: [executable: executable, storage: storage]}, rest}} -> + {:ok, {new(executable, storage), rest}} + + error -> + error + end + end + + @impl true + def decode_xdr!(bytes, struct \\ @struct_spec) + + def decode_xdr!(bytes, struct) do + {%XDR.Struct{components: [executable: executable, storage: storage]}, rest} = + XDR.Struct.decode_xdr!(bytes, struct) + + {new(executable, storage), rest} + end +end diff --git a/lib/xdr/contract/sc_error.ex b/lib/xdr/contract/sc_error.ex new file mode 100644 index 00000000..26100518 --- /dev/null +++ b/lib/xdr/contract/sc_error.ex @@ -0,0 +1,73 @@ +defmodule StellarBase.XDR.SCError do + @moduledoc """ + Automatically generated by xdrgen + DO NOT EDIT or your changes may be overwritten + + Target implementation: elixir_xdr at https://hex.pm/packages/elixir_xdr + + Representation of Stellar `SCError` type. + """ + + @behaviour XDR.Declaration + + alias StellarBase.XDR.{ + SCErrorType, + SCErrorCode + } + + @struct_spec XDR.Struct.new( + type: SCErrorType, + code: SCErrorCode + ) + + @type type_type :: SCErrorType.t() + @type code_type :: SCErrorCode.t() + + @type t :: %__MODULE__{type: type_type(), code: code_type()} + + defstruct [:type, :code] + + @spec new(type :: type_type(), code :: code_type()) :: t() + def new( + %SCErrorType{} = type, + %SCErrorCode{} = code + ), + do: %__MODULE__{type: type, code: code} + + @impl true + def encode_xdr(%__MODULE__{type: type, code: code}) do + [type: type, code: code] + |> XDR.Struct.new() + |> XDR.Struct.encode_xdr() + end + + @impl true + def encode_xdr!(%__MODULE__{type: type, code: code}) do + [type: type, code: code] + |> XDR.Struct.new() + |> XDR.Struct.encode_xdr!() + end + + @impl true + def decode_xdr(bytes, struct \\ @struct_spec) + + def decode_xdr(bytes, struct) do + case XDR.Struct.decode_xdr(bytes, struct) do + {:ok, {%XDR.Struct{components: [type: type, code: code]}, rest}} -> + {:ok, {new(type, code), rest}} + + error -> + error + end + end + + @impl true + def decode_xdr!(bytes, struct \\ @struct_spec) + + def decode_xdr!(bytes, struct) do + {%XDR.Struct{components: [type: type, code: code]}, rest} = + XDR.Struct.decode_xdr!(bytes, struct) + + {new(type, code), rest} + end +end diff --git a/lib/xdr/contract/sc_error_code.ex b/lib/xdr/contract/sc_error_code.ex new file mode 100644 index 00000000..a322d6ec --- /dev/null +++ b/lib/xdr/contract/sc_error_code.ex @@ -0,0 +1,66 @@ +defmodule StellarBase.XDR.SCErrorCode do + @moduledoc """ + Automatically generated by xdrgen + DO NOT EDIT or your changes may be overwritten + + Target implementation: elixir_xdr at https://hex.pm/packages/elixir_xdr + + Representation of Stellar `SCErrorCode` type. + """ + + @behaviour XDR.Declaration + + @declarations [ + SCEC_ARITH_DOMAIN: 0, + SCEC_INDEX_BOUNDS: 1, + SCEC_INVALID_INPUT: 2, + SCEC_MISSING_VALUE: 3, + SCEC_EXISTING_VALUE: 4, + SCEC_EXCEEDED_LIMIT: 5, + SCEC_INVALID_ACTION: 6, + SCEC_INTERNAL_ERROR: 7, + SCEC_UNEXPECTED_TYPE: 8, + SCEC_UNEXPECTED_SIZE: 9 + ] + + @enum_spec %XDR.Enum{declarations: @declarations, identifier: nil} + + @type t :: %__MODULE__{identifier: atom()} + + defstruct [:identifier] + + @spec new(type :: atom()) :: t() + def new(type \\ :SCEC_ARITH_DOMAIN), do: %__MODULE__{identifier: type} + + @impl true + def encode_xdr(%__MODULE__{identifier: type}) do + @declarations + |> XDR.Enum.new(type) + |> XDR.Enum.encode_xdr() + end + + @impl true + def encode_xdr!(%__MODULE__{identifier: type}) do + @declarations + |> XDR.Enum.new(type) + |> XDR.Enum.encode_xdr!() + end + + @impl true + def decode_xdr(bytes, spec \\ @enum_spec) + + def decode_xdr(bytes, spec) do + case XDR.Enum.decode_xdr(bytes, spec) do + {:ok, {%XDR.Enum{identifier: type}, rest}} -> {:ok, {new(type), rest}} + error -> error + end + end + + @impl true + def decode_xdr!(bytes, spec \\ @enum_spec) + + def decode_xdr!(bytes, spec) do + {%XDR.Enum{identifier: type}, rest} = XDR.Enum.decode_xdr!(bytes, spec) + {new(type), rest} + end +end diff --git a/lib/xdr/contract/sc_error_type.ex b/lib/xdr/contract/sc_error_type.ex new file mode 100644 index 00000000..0e26c27f --- /dev/null +++ b/lib/xdr/contract/sc_error_type.ex @@ -0,0 +1,66 @@ +defmodule StellarBase.XDR.SCErrorType do + @moduledoc """ + Automatically generated by xdrgen + DO NOT EDIT or your changes may be overwritten + + Target implementation: elixir_xdr at https://hex.pm/packages/elixir_xdr + + Representation of Stellar `SCErrorType` type. + """ + + @behaviour XDR.Declaration + + @declarations [ + SCE_CONTRACT: 0, + SCE_WASM_VM: 1, + SCE_CONTEXT: 2, + SCE_STORAGE: 3, + SCE_OBJECT: 4, + SCE_CRYPTO: 5, + SCE_EVENTS: 6, + SCE_BUDGET: 7, + SCE_VALUE: 8, + SCE_AUTH: 9 + ] + + @enum_spec %XDR.Enum{declarations: @declarations, identifier: nil} + + @type t :: %__MODULE__{identifier: atom()} + + defstruct [:identifier] + + @spec new(type :: atom()) :: t() + def new(type \\ :SCE_CONTRACT), do: %__MODULE__{identifier: type} + + @impl true + def encode_xdr(%__MODULE__{identifier: type}) do + @declarations + |> XDR.Enum.new(type) + |> XDR.Enum.encode_xdr() + end + + @impl true + def encode_xdr!(%__MODULE__{identifier: type}) do + @declarations + |> XDR.Enum.new(type) + |> XDR.Enum.encode_xdr!() + end + + @impl true + def decode_xdr(bytes, spec \\ @enum_spec) + + def decode_xdr(bytes, spec) do + case XDR.Enum.decode_xdr(bytes, spec) do + {:ok, {%XDR.Enum{identifier: type}, rest}} -> {:ok, {new(type), rest}} + error -> error + end + end + + @impl true + def decode_xdr!(bytes, spec \\ @enum_spec) + + def decode_xdr!(bytes, spec) do + {%XDR.Enum{identifier: type}, rest} = XDR.Enum.decode_xdr!(bytes, spec) + {new(type), rest} + end +end diff --git a/lib/xdr/contract/sc_host_storage_error_code.ex b/lib/xdr/contract/sc_host_storage_error_code.ex deleted file mode 100644 index 98438f58..00000000 --- a/lib/xdr/contract/sc_host_storage_error_code.ex +++ /dev/null @@ -1,57 +0,0 @@ -defmodule StellarBase.XDR.SCHostStorageErrorCode do - @moduledoc """ - Representation of Stellar `SCHostStorageErrorCode` type. - """ - - @behaviour XDR.Declaration - - @declarations [ - HOST_STORAGE_UNKNOWN_ERROR: 0, - HOST_STORAGE_EXPECT_CONTRACT_DATA: 1, - HOST_STORAGE_READWRITE_ACCESS_TO_READONLY_ENTRY: 2, - HOST_STORAGE_ACCESS_TO_UNKNOWN_ENTRY: 3, - HOST_STORAGE_MISSING_KEY_IN_GET: 4, - HOST_STORAGE_GET_ON_DELETED_KEY: 5 - ] - - @enum_spec %XDR.Enum{declarations: @declarations, identifier: nil} - - @type t :: %__MODULE__{identifier: atom()} - - defstruct [:identifier] - - @spec new(type :: atom()) :: t() - def new(type \\ :HOST_STORAGE_UNKNOWN_ERROR), do: %__MODULE__{identifier: type} - - @impl true - def encode_xdr(%__MODULE__{identifier: type}) do - @declarations - |> XDR.Enum.new(type) - |> XDR.Enum.encode_xdr() - end - - @impl true - def encode_xdr!(%__MODULE__{identifier: type}) do - @declarations - |> XDR.Enum.new(type) - |> XDR.Enum.encode_xdr!() - end - - @impl true - def decode_xdr(bytes, spec \\ @enum_spec) - - def decode_xdr(bytes, spec) do - case XDR.Enum.decode_xdr(bytes, spec) do - {:ok, {%XDR.Enum{identifier: type}, rest}} -> {:ok, {new(type), rest}} - error -> error - end - end - - @impl true - def decode_xdr!(bytes, spec \\ @enum_spec) - - def decode_xdr!(bytes, spec) do - {%XDR.Enum{identifier: type}, rest} = XDR.Enum.decode_xdr!(bytes, spec) - {new(type), rest} - end -end diff --git a/lib/xdr/contract/sc_host_val_error_code.ex b/lib/xdr/contract/sc_host_val_error_code.ex deleted file mode 100644 index 9a0fcb9d..00000000 --- a/lib/xdr/contract/sc_host_val_error_code.ex +++ /dev/null @@ -1,63 +0,0 @@ -defmodule StellarBase.XDR.SCHostValErrorCode do - @moduledoc """ - Representation of Stellar `SCHostValErrorCode` type. - """ - - @behaviour XDR.Declaration - - @declarations [ - HOST_VALUE_UNKNOWN_ERROR: 0, - HOST_VALUE_RESERVED_TAG_VALUE: 1, - HOST_VALUE_UNEXPECTED_VAL_TYPE: 2, - HOST_VALUE_U63_OUT_OF_RANGE: 3, - HOST_VALUE_U32_OUT_OF_RANGE: 4, - HOST_VALUE_STATIC_UNKNOWN: 5, - HOST_VALUE_MISSING_OBJECT: 6, - HOST_VALUE_SYMBOL_TOO_LONG: 7, - HOST_VALUE_SYMBOL_BAD_CHAR: 8, - HOST_VALUE_SYMBOL_CONTAINS_NON_UTF8: 9, - HOST_VALUE_BITSET_TOO_MANY_BITS: 10, - HOST_VALUE_STATUS_UNKNOWN: 11 - ] - - @enum_spec %XDR.Enum{declarations: @declarations, identifier: nil} - - @type t :: %__MODULE__{identifier: atom()} - - defstruct [:identifier] - - @spec new(type :: atom()) :: t() - def new(type \\ :HOST_VALUE_UNKNOWN_ERROR), do: %__MODULE__{identifier: type} - - @impl true - def encode_xdr(%__MODULE__{identifier: type}) do - @declarations - |> XDR.Enum.new(type) - |> XDR.Enum.encode_xdr() - end - - @impl true - def encode_xdr!(%__MODULE__{identifier: type}) do - @declarations - |> XDR.Enum.new(type) - |> XDR.Enum.encode_xdr!() - end - - @impl true - def decode_xdr(bytes, spec \\ @enum_spec) - - def decode_xdr(bytes, spec) do - case XDR.Enum.decode_xdr(bytes, spec) do - {:ok, {%XDR.Enum{identifier: type}, rest}} -> {:ok, {new(type), rest}} - error -> error - end - end - - @impl true - def decode_xdr!(bytes, spec \\ @enum_spec) - - def decode_xdr!(bytes, spec) do - {%XDR.Enum{identifier: type}, rest} = XDR.Enum.decode_xdr!(bytes, spec) - {new(type), rest} - end -end diff --git a/lib/xdr/contract/sc_map.ex b/lib/xdr/contract/sc_map.ex index 56ce6653..19d044eb 100644 --- a/lib/xdr/contract/sc_map.ex +++ b/lib/xdr/contract/sc_map.ex @@ -1,36 +1,39 @@ defmodule StellarBase.XDR.SCMap do @moduledoc """ - Representation of a Stellar `SCMap` list. - """ + Automatically generated by xdrgen + DO NOT EDIT or your changes may be overwritten - alias StellarBase.XDR.SCMapEntry + Target implementation: elixir_xdr at https://hex.pm/packages/elixir_xdr + + Representation of Stellar `SCMap` type. + """ @behaviour XDR.Declaration - @max_length 256_000 + alias StellarBase.XDR.SCMapEntry @array_type SCMapEntry - @array_spec %{type: @array_type, max_length: @max_length} + @array_spec %{type: @array_type} - @type t :: %__MODULE__{scmap_entries: list(SCMapEntry.t())} + @type t :: %__MODULE__{items: list(SCMapEntry.t())} - defstruct [:scmap_entries] + defstruct [:items] - @spec new(scmap_entries :: list(SCMapEntry.t())) :: t() - def new(scmap_entries), do: %__MODULE__{scmap_entries: scmap_entries} + @spec new(items :: list(SCMapEntry.t())) :: t() + def new(items), do: %__MODULE__{items: items} @impl true - def encode_xdr(%__MODULE__{scmap_entries: scmap_entries}) do - scmap_entries - |> XDR.VariableArray.new(@array_type, @max_length) + def encode_xdr(%__MODULE__{items: items}) do + items + |> XDR.VariableArray.new(@array_type) |> XDR.VariableArray.encode_xdr() end @impl true - def encode_xdr!(%__MODULE__{scmap_entries: scmap_entries}) do - scmap_entries - |> XDR.VariableArray.new(@array_type, @max_length) + def encode_xdr!(%__MODULE__{items: items}) do + items + |> XDR.VariableArray.new(@array_type) |> XDR.VariableArray.encode_xdr!() end @@ -39,7 +42,7 @@ defmodule StellarBase.XDR.SCMap do def decode_xdr(bytes, spec) do case XDR.VariableArray.decode_xdr(bytes, spec) do - {:ok, {scmap_entries, rest}} -> {:ok, {new(scmap_entries), rest}} + {:ok, {items, rest}} -> {:ok, {new(items), rest}} error -> error end end @@ -48,7 +51,7 @@ defmodule StellarBase.XDR.SCMap do def decode_xdr!(bytes, spec \\ @array_spec) def decode_xdr!(bytes, spec) do - {scmap_entries, rest} = XDR.VariableArray.decode_xdr!(bytes, spec) - {new(scmap_entries), rest} + {items, rest} = XDR.VariableArray.decode_xdr!(bytes, spec) + {new(items), rest} end end diff --git a/lib/xdr/contract/sc_nonce_key.ex b/lib/xdr/contract/sc_nonce_key.ex index 0374d78e..150d567f 100644 --- a/lib/xdr/contract/sc_nonce_key.ex +++ b/lib/xdr/contract/sc_nonce_key.ex @@ -1,31 +1,39 @@ defmodule StellarBase.XDR.SCNonceKey do @moduledoc """ + Automatically generated by xdrgen + DO NOT EDIT or your changes may be overwritten + + Target implementation: elixir_xdr at https://hex.pm/packages/elixir_xdr + Representation of Stellar `SCNonceKey` type. """ - alias StellarBase.XDR.SCAddress @behaviour XDR.Declaration - @struct_spec XDR.Struct.new(nonce_address: SCAddress) + alias StellarBase.XDR.Int64 + + @struct_spec XDR.Struct.new(nonce: Int64) - @type t :: %__MODULE__{nonce_address: SCAddress.t()} + @type nonce_type :: Int64.t() - defstruct [:nonce_address] + @type t :: %__MODULE__{nonce: nonce_type()} - @spec new(nonce_address :: SCAddress.t()) :: t() - def new(%SCAddress{} = nonce_address), - do: %__MODULE__{nonce_address: nonce_address} + defstruct [:nonce] + + @spec new(nonce :: nonce_type()) :: t() + def new(%Int64{} = nonce), + do: %__MODULE__{nonce: nonce} @impl true - def encode_xdr(%__MODULE__{nonce_address: nonce_address}) do - [nonce_address: nonce_address] + def encode_xdr(%__MODULE__{nonce: nonce}) do + [nonce: nonce] |> XDR.Struct.new() |> XDR.Struct.encode_xdr() end @impl true - def encode_xdr!(%__MODULE__{nonce_address: nonce_address}) do - [nonce_address: nonce_address] + def encode_xdr!(%__MODULE__{nonce: nonce}) do + [nonce: nonce] |> XDR.Struct.new() |> XDR.Struct.encode_xdr!() end @@ -35,8 +43,8 @@ defmodule StellarBase.XDR.SCNonceKey do def decode_xdr(bytes, struct) do case XDR.Struct.decode_xdr(bytes, struct) do - {:ok, {%XDR.Struct{components: [nonce_address: nonce_address]}, rest}} -> - {:ok, {new(nonce_address), rest}} + {:ok, {%XDR.Struct{components: [nonce: nonce]}, rest}} -> + {:ok, {new(nonce), rest}} error -> error @@ -47,9 +55,7 @@ defmodule StellarBase.XDR.SCNonceKey do def decode_xdr!(bytes, struct \\ @struct_spec) def decode_xdr!(bytes, struct) do - {%XDR.Struct{components: [nonce_address: nonce_address]}, rest} = - XDR.Struct.decode_xdr!(bytes, struct) - - {new(nonce_address), rest} + {%XDR.Struct{components: [nonce: nonce]}, rest} = XDR.Struct.decode_xdr!(bytes, struct) + {new(nonce), rest} end end diff --git a/lib/xdr/contract/sc_status.ex b/lib/xdr/contract/sc_status.ex deleted file mode 100644 index 131997c0..00000000 --- a/lib/xdr/contract/sc_status.ex +++ /dev/null @@ -1,93 +0,0 @@ -defmodule StellarBase.XDR.SCStatus do - @moduledoc """ - Representation of Stellar `SCStatus` type. - """ - - alias StellarBase.XDR.{ - SCUnknownErrorCode, - SCHostValErrorCode, - SCHostObjErrorCode, - SCHostFnErrorCode, - SCHostStorageErrorCode, - SCHostContextErrorCode, - SCVmErrorCode, - SCHostAuthErrorCode, - SCStatusType, - UInt32, - Void - } - - @behaviour XDR.Declaration - - @arms [ - SST_OK: Void, - SST_UNKNOWN_ERROR: SCUnknownErrorCode, - SST_HOST_VALUE_ERROR: SCHostValErrorCode, - SST_HOST_OBJECT_ERROR: SCHostObjErrorCode, - SST_HOST_FUNCTION_ERROR: SCHostFnErrorCode, - SST_HOST_STORAGE_ERROR: SCHostStorageErrorCode, - SST_HOST_CONTEXT_ERROR: SCHostContextErrorCode, - SST_VM_ERROR: SCVmErrorCode, - SST_CONTRACT_ERROR: UInt32, - SST_HOST_AUTH_ERROR: SCHostAuthErrorCode - ] - - @type code :: - SCUnknownErrorCode.t() - | SCHostValErrorCode.t() - | SCHostObjErrorCode.t() - | SCHostFnErrorCode.t() - | SCHostStorageErrorCode.t() - | SCHostContextErrorCode.t() - | SCVmErrorCode.t() - | SCHostAuthErrorCode.t() - | SCStatusType.t() - | UInt32.t() - | Void.t() - - @type t :: %__MODULE__{code: code(), type: SCStatusType.t()} - - defstruct [:code, :type] - - @spec new(code :: code(), type :: SCStatusType.t()) :: t() - def new(code, %SCStatusType{} = type), do: %__MODULE__{code: code, type: type} - - @impl true - def encode_xdr(%__MODULE__{code: code, type: type}) do - type - |> XDR.Union.new(@arms, code) - |> XDR.Union.encode_xdr() - end - - @impl true - def encode_xdr!(%__MODULE__{code: code, type: type}) do - type - |> XDR.Union.new(@arms, code) - |> XDR.Union.encode_xdr!() - end - - @impl true - def decode_xdr(bytes, spec \\ union_spec()) - - def decode_xdr(bytes, spec) do - case XDR.Union.decode_xdr(bytes, spec) do - {:ok, {{type, code}, rest}} -> {:ok, {new(code, type), rest}} - error -> error - end - end - - @impl true - def decode_xdr!(bytes, spec \\ union_spec()) - - def decode_xdr!(bytes, spec) do - {{type, code}, rest} = XDR.Union.decode_xdr!(bytes, spec) - {new(code, type), rest} - end - - @spec union_spec() :: XDR.Union.t() - defp union_spec do - nil - |> SCStatusType.new() - |> XDR.Union.new(@arms) - end -end diff --git a/lib/xdr/contract/sc_status_type.ex b/lib/xdr/contract/sc_status_type.ex deleted file mode 100644 index 209a17e1..00000000 --- a/lib/xdr/contract/sc_status_type.ex +++ /dev/null @@ -1,61 +0,0 @@ -defmodule StellarBase.XDR.SCStatusType do - @moduledoc """ - Representation of Stellar `SCStatusType` type. - """ - - @behaviour XDR.Declaration - - @declarations [ - SST_OK: 0, - SST_UNKNOWN_ERROR: 1, - SST_HOST_VALUE_ERROR: 2, - SST_HOST_OBJECT_ERROR: 3, - SST_HOST_FUNCTION_ERROR: 4, - SST_HOST_STORAGE_ERROR: 5, - SST_HOST_CONTEXT_ERROR: 6, - SST_VM_ERROR: 7, - SST_CONTRACT_ERROR: 8, - SST_HOST_AUTH_ERROR: 9 - ] - - @enum_spec %XDR.Enum{declarations: @declarations, identifier: nil} - - @type t :: %__MODULE__{identifier: atom()} - - defstruct [:identifier] - - @spec new(type :: atom()) :: t() - def new(type \\ :SST_OK), do: %__MODULE__{identifier: type} - - @impl true - def encode_xdr(%__MODULE__{identifier: type}) do - @declarations - |> XDR.Enum.new(type) - |> XDR.Enum.encode_xdr() - end - - @impl true - def encode_xdr!(%__MODULE__{identifier: type}) do - @declarations - |> XDR.Enum.new(type) - |> XDR.Enum.encode_xdr!() - end - - @impl true - def decode_xdr(bytes, spec \\ @enum_spec) - - def decode_xdr(bytes, spec) do - case XDR.Enum.decode_xdr(bytes, spec) do - {:ok, {%XDR.Enum{identifier: type}, rest}} -> {:ok, {new(type), rest}} - error -> error - end - end - - @impl true - def decode_xdr!(bytes, spec \\ @enum_spec) - - def decode_xdr!(bytes, spec) do - {%XDR.Enum{identifier: type}, rest} = XDR.Enum.decode_xdr!(bytes, spec) - {new(type), rest} - end -end diff --git a/lib/xdr/contract/sc_string.ex b/lib/xdr/contract/sc_string.ex index 4aad8a1f..244aa483 100644 --- a/lib/xdr/contract/sc_string.ex +++ b/lib/xdr/contract/sc_string.ex @@ -1,5 +1,10 @@ defmodule StellarBase.XDR.SCString do @moduledoc """ + Automatically generated by xdrgen + DO NOT EDIT or your changes may be overwritten + + Target implementation: elixir_xdr at https://hex.pm/packages/elixir_xdr + Representation of Stellar `SCString` type. """ @@ -9,22 +14,20 @@ defmodule StellarBase.XDR.SCString do defstruct [:value] - @max_length 256_000 - @spec new(value :: String.t()) :: t() def new(value), do: %__MODULE__{value: value} @impl true def encode_xdr(%__MODULE__{value: value}) do value - |> XDR.String.new(@max_length) + |> XDR.String.new() |> XDR.String.encode_xdr() end @impl true def encode_xdr!(%__MODULE__{value: value}) do value - |> XDR.String.new(@max_length) + |> XDR.String.new() |> XDR.String.encode_xdr!() end diff --git a/lib/xdr/contract/sc_val.ex b/lib/xdr/contract/sc_val.ex index a62257a8..ba448f87 100644 --- a/lib/xdr/contract/sc_val.ex +++ b/lib/xdr/contract/sc_val.ex @@ -14,7 +14,7 @@ defmodule StellarBase.XDR.SCVal do SCValType, Bool, Void, - SCStatus, + SCError, UInt32, Int32, UInt64, @@ -30,15 +30,15 @@ defmodule StellarBase.XDR.SCVal do SCSymbol, OptionalSCVec, OptionalSCMap, - SCContractExecutable, SCAddress, - SCNonceKey + SCNonceKey, + SCContractInstance } @arms [ SCV_BOOL: Bool, SCV_VOID: Void, - SCV_STATUS: SCStatus, + SCV_ERROR: SCError, SCV_U32: UInt32, SCV_I32: Int32, SCV_U64: UInt64, @@ -54,24 +54,22 @@ defmodule StellarBase.XDR.SCVal do SCV_SYMBOL: SCSymbol, SCV_VEC: OptionalSCVec, SCV_MAP: OptionalSCMap, - SCV_CONTRACT_EXECUTABLE: SCContractExecutable, SCV_ADDRESS: SCAddress, - SCV_LEDGER_KEY_CONTRACT_EXECUTABLE: Void, - SCV_LEDGER_KEY_NONCE: SCNonceKey + SCV_LEDGER_KEY_CONTRACT_INSTANCE: Void, + SCV_LEDGER_KEY_NONCE: SCNonceKey, + SCV_CONTRACT_INSTANCE: SCContractInstance ] @type value :: Bool.t() | Void.t() - | SCStatus.t() + | SCError.t() | UInt32.t() | Int32.t() | UInt64.t() | Int64.t() | TimePoint.t() | Duration.t() - | Int128Parts.t() - | Int256Parts.t() | UInt128Parts.t() | UInt256Parts.t() | SCBytes.t() @@ -79,9 +77,9 @@ defmodule StellarBase.XDR.SCVal do | SCSymbol.t() | OptionalSCVec.t() | OptionalSCMap.t() - | SCContractExecutable.t() | SCAddress.t() | SCNonceKey.t() + | SCContractInstance.t() @type t :: %__MODULE__{value: value(), type: SCValType.t()} diff --git a/lib/xdr/contract/sc_val_type.ex b/lib/xdr/contract/sc_val_type.ex index cc6d0d3a..4a5ffe3a 100644 --- a/lib/xdr/contract/sc_val_type.ex +++ b/lib/xdr/contract/sc_val_type.ex @@ -1,5 +1,10 @@ defmodule StellarBase.XDR.SCValType do @moduledoc """ + Automatically generated by xdrgen + DO NOT EDIT or your changes may be overwritten + + Target implementation: elixir_xdr at https://hex.pm/packages/elixir_xdr + Representation of Stellar `SCValType` type. """ @@ -8,7 +13,7 @@ defmodule StellarBase.XDR.SCValType do @declarations [ SCV_BOOL: 0, SCV_VOID: 1, - SCV_STATUS: 2, + SCV_ERROR: 2, SCV_U32: 3, SCV_I32: 4, SCV_U64: 5, @@ -24,9 +29,9 @@ defmodule StellarBase.XDR.SCValType do SCV_SYMBOL: 15, SCV_VEC: 16, SCV_MAP: 17, - SCV_CONTRACT_EXECUTABLE: 18, - SCV_ADDRESS: 19, - SCV_LEDGER_KEY_CONTRACT_EXECUTABLE: 20, + SCV_ADDRESS: 18, + SCV_CONTRACT_INSTANCE: 19, + SCV_LEDGER_KEY_CONTRACT_INSTANCE: 20, SCV_LEDGER_KEY_NONCE: 21 ] diff --git a/lib/xdr/contract/sc_vec.ex b/lib/xdr/contract/sc_vec.ex index 2e4b64f8..883075ef 100644 --- a/lib/xdr/contract/sc_vec.ex +++ b/lib/xdr/contract/sc_vec.ex @@ -1,36 +1,39 @@ defmodule StellarBase.XDR.SCVec do @moduledoc """ - Representation of Stellar `SCVec` list. - """ + Automatically generated by xdrgen + DO NOT EDIT or your changes may be overwritten - alias StellarBase.XDR.SCVal + Target implementation: elixir_xdr at https://hex.pm/packages/elixir_xdr + + Representation of Stellar `SCVec` type. + """ @behaviour XDR.Declaration - @max_length 256_000 + alias StellarBase.XDR.SCVal @array_type SCVal - @array_spec %{type: @array_type, max_length: @max_length} + @array_spec %{type: @array_type} - @type t :: %__MODULE__{sc_vals: list(SCVal.t())} + @type t :: %__MODULE__{items: list(SCVal.t())} - defstruct [:sc_vals] + defstruct [:items] - @spec new(sc_vals :: list(SCVal.t())) :: t() - def new(sc_vals), do: %__MODULE__{sc_vals: sc_vals} + @spec new(items :: list(SCVal.t())) :: t() + def new(items), do: %__MODULE__{items: items} @impl true - def encode_xdr(%__MODULE__{sc_vals: sc_vals}) do - sc_vals - |> XDR.VariableArray.new(@array_type, @max_length) + def encode_xdr(%__MODULE__{items: items}) do + items + |> XDR.VariableArray.new(@array_type) |> XDR.VariableArray.encode_xdr() end @impl true - def encode_xdr!(%__MODULE__{sc_vals: sc_vals}) do - sc_vals - |> XDR.VariableArray.new(@array_type, @max_length) + def encode_xdr!(%__MODULE__{items: items}) do + items + |> XDR.VariableArray.new(@array_type) |> XDR.VariableArray.encode_xdr!() end @@ -39,7 +42,7 @@ defmodule StellarBase.XDR.SCVec do def decode_xdr(bytes, spec) do case XDR.VariableArray.decode_xdr(bytes, spec) do - {:ok, {sc_vals, rest}} -> {:ok, {new(sc_vals), rest}} + {:ok, {items, rest}} -> {:ok, {new(items), rest}} error -> error end end @@ -48,7 +51,7 @@ defmodule StellarBase.XDR.SCVec do def decode_xdr!(bytes, spec \\ @array_spec) def decode_xdr!(bytes, spec) do - {sc_vals, rest} = XDR.VariableArray.decode_xdr!(bytes, spec) - {new(sc_vals), rest} + {items, rest} = XDR.VariableArray.decode_xdr!(bytes, spec) + {new(items), rest} end end diff --git a/lib/xdr/contract/sc_vm_error_code.ex b/lib/xdr/contract/sc_vm_error_code.ex deleted file mode 100644 index 6fdb24db..00000000 --- a/lib/xdr/contract/sc_vm_error_code.ex +++ /dev/null @@ -1,70 +0,0 @@ -defmodule StellarBase.XDR.SCVmErrorCode do - @moduledoc """ - Representation of Stellar `SCVmErrorCode` type. - """ - - @behaviour XDR.Declaration - - @declarations [ - VM_UNKNOWN: 0, - VM_VALIDATION: 1, - VM_INSTANTIATION: 2, - VM_FUNCTION: 3, - VM_TABLE: 4, - VM_MEMORY: 5, - VM_GLOBAL: 6, - VM_VALUE: 7, - VM_TRAP_UNREACHABLE: 8, - VM_TRAP_MEMORY_ACCESS_OUT_OF_BOUNDS: 9, - VM_TRAP_TABLE_ACCESS_OUT_OF_BOUNDS: 10, - VM_TRAP_ELEM_UNINITIALIZED: 11, - VM_TRAP_DIVISION_BY_ZERO: 12, - VM_TRAP_INTEGER_OVERFLOW: 13, - VM_TRAP_INVALID_CONVERSION_TO_INT: 14, - VM_TRAP_STACK_OVERFLOW: 15, - VM_TRAP_UNEXPECTED_SIGNATURE: 16, - VM_TRAP_MEM_LIMIT_EXCEEDED: 17, - VM_TRAP_CPU_LIMIT_EXCEEDED: 18 - ] - - @enum_spec %XDR.Enum{declarations: @declarations, identifier: nil} - - @type t :: %__MODULE__{identifier: atom()} - - defstruct [:identifier] - - @spec new(type :: atom()) :: t() - def new(type \\ :VM_UNKNOWN), do: %__MODULE__{identifier: type} - - @impl true - def encode_xdr(%__MODULE__{identifier: type}) do - @declarations - |> XDR.Enum.new(type) - |> XDR.Enum.encode_xdr() - end - - @impl true - def encode_xdr!(%__MODULE__{identifier: type}) do - @declarations - |> XDR.Enum.new(type) - |> XDR.Enum.encode_xdr!() - end - - @impl true - def decode_xdr(bytes, spec \\ @enum_spec) - - def decode_xdr(bytes, spec) do - case XDR.Enum.decode_xdr(bytes, spec) do - {:ok, {%XDR.Enum{identifier: type}, rest}} -> {:ok, {new(type), rest}} - error -> error - end - end - - @impl true - def decode_xdr!(bytes, spec \\ @enum_spec) - - def decode_xdr!(bytes, spec) do - {%XDR.Enum{identifier: type}, rest} = XDR.Enum.decode_xdr!(bytes, spec) - {new(type), rest} - end -end diff --git a/lib/xdr/contract/spec/sc_spec_type.ex b/lib/xdr/contract/spec/sc_spec_type.ex index 92ab083d..3e35b2f9 100644 --- a/lib/xdr/contract/spec/sc_spec_type.ex +++ b/lib/xdr/contract/spec/sc_spec_type.ex @@ -1,5 +1,10 @@ defmodule StellarBase.XDR.SCSpecType do @moduledoc """ + Automatically generated by xdrgen + DO NOT EDIT or your changes may be overwritten + + Target implementation: elixir_xdr at https://hex.pm/packages/elixir_xdr + Representation of Stellar `SCSpecType` type. """ @@ -7,11 +12,9 @@ defmodule StellarBase.XDR.SCSpecType do @declarations [ SC_SPEC_TYPE_VAL: 0, - - # Types with no parameters. SC_SPEC_TYPE_BOOL: 1, SC_SPEC_TYPE_VOID: 2, - SC_SPEC_TYPE_STATUS: 3, + SC_SPEC_TYPE_ERROR: 3, SC_SPEC_TYPE_U32: 4, SC_SPEC_TYPE_I32: 5, SC_SPEC_TYPE_U64: 6, @@ -26,8 +29,6 @@ defmodule StellarBase.XDR.SCSpecType do SC_SPEC_TYPE_STRING: 16, SC_SPEC_TYPE_SYMBOL: 17, SC_SPEC_TYPE_ADDRESS: 19, - - # Types with parameters. SC_SPEC_TYPE_OPTION: 1000, SC_SPEC_TYPE_RESULT: 1001, SC_SPEC_TYPE_VEC: 1002, @@ -35,8 +36,6 @@ defmodule StellarBase.XDR.SCSpecType do SC_SPEC_TYPE_MAP: 1004, SC_SPEC_TYPE_TUPLE: 1005, SC_SPEC_TYPE_BYTES_N: 1006, - - # User defined types. SC_SPEC_TYPE_UDT: 2000 ] @@ -47,7 +46,7 @@ defmodule StellarBase.XDR.SCSpecType do defstruct [:identifier] @spec new(type :: atom()) :: t() - def new(type), do: %__MODULE__{identifier: type} + def new(type \\ :SC_SPEC_TYPE_VAL), do: %__MODULE__{identifier: type} @impl true def encode_xdr(%__MODULE__{identifier: type}) do diff --git a/lib/xdr/contract/spec/sc_spec_type_def.ex b/lib/xdr/contract/spec/sc_spec_type_def.ex index 0cdaf5ca..f98a44f9 100644 --- a/lib/xdr/contract/spec/sc_spec_type_def.ex +++ b/lib/xdr/contract/spec/sc_spec_type_def.ex @@ -1,28 +1,33 @@ defmodule StellarBase.XDR.SCSpecTypeDef do @moduledoc """ + Automatically generated by xdrgen + DO NOT EDIT or your changes may be overwritten + + Target implementation: elixir_xdr at https://hex.pm/packages/elixir_xdr + Representation of Stellar `SCSpecTypeDef` type. """ + @behaviour XDR.Declaration + alias StellarBase.XDR.{ SCSpecType, + Void, + SCSpecTypeOption, + SCSpecTypeResult, SCSpecTypeVec, SCSpecTypeMap, SCSpecTypeSet, SCSpecTypeTuple, SCSpecTypeBytesN, - SCSpecTypeUDT, - SCSpecTypeOption, - SCSpecTypeResult, - Void + SCSpecTypeUDT } - @behaviour XDR.Declaration - @arms [ SC_SPEC_TYPE_VAL: Void, SC_SPEC_TYPE_BOOL: Void, SC_SPEC_TYPE_VOID: Void, - SC_SPEC_TYPE_STATUS: Void, + SC_SPEC_TYPE_ERROR: Void, SC_SPEC_TYPE_U32: Void, SC_SPEC_TYPE_I32: Void, SC_SPEC_TYPE_U64: Void, @@ -47,37 +52,35 @@ defmodule StellarBase.XDR.SCSpecTypeDef do SC_SPEC_TYPE_UDT: SCSpecTypeUDT ] - @type code :: - SCSpecTypeVec.t() + @type value :: + Void.t() + | SCSpecTypeOption.t() + | SCSpecTypeResult.t() + | SCSpecTypeVec.t() | SCSpecTypeMap.t() | SCSpecTypeSet.t() | SCSpecTypeTuple.t() | SCSpecTypeBytesN.t() | SCSpecTypeUDT.t() - | SCSpecTypeOption.t() - | SCSpecTypeResult.t() - | Void.t() - - @type type :: SCSpecType.t() - @type t :: %__MODULE__{code: code(), type: type()} + @type t :: %__MODULE__{value: value(), type: SCSpecType.t()} - defstruct [:code, :type] + defstruct [:value, :type] - @spec new(code :: code(), type :: type()) :: t() - def new(code, %SCSpecType{} = type), do: %__MODULE__{code: code, type: type} + @spec new(value :: value(), type :: SCSpecType.t()) :: t() + def new(value, %SCSpecType{} = type), do: %__MODULE__{value: value, type: type} @impl true - def encode_xdr(%__MODULE__{code: code, type: type}) do + def encode_xdr(%__MODULE__{value: value, type: type}) do type - |> XDR.Union.new(@arms, code) + |> XDR.Union.new(@arms, value) |> XDR.Union.encode_xdr() end @impl true - def encode_xdr!(%__MODULE__{code: code, type: type}) do + def encode_xdr!(%__MODULE__{value: value, type: type}) do type - |> XDR.Union.new(@arms, code) + |> XDR.Union.new(@arms, value) |> XDR.Union.encode_xdr!() end @@ -86,7 +89,7 @@ defmodule StellarBase.XDR.SCSpecTypeDef do def decode_xdr(bytes, spec) do case XDR.Union.decode_xdr(bytes, spec) do - {:ok, {{type, code}, rest}} -> {:ok, {new(code, type), rest}} + {:ok, {{type, value}, rest}} -> {:ok, {new(value, type), rest}} error -> error end end @@ -95,8 +98,8 @@ defmodule StellarBase.XDR.SCSpecTypeDef do def decode_xdr!(bytes, spec \\ union_spec()) def decode_xdr!(bytes, spec) do - {{type, code}, rest} = XDR.Union.decode_xdr!(bytes, spec) - {new(code, type), rest} + {{type, value}, rest} = XDR.Union.decode_xdr!(bytes, spec) + {new(value, type), rest} end @spec union_spec() :: XDR.Union.t() diff --git a/lib/xdr/contract/uint64_list.ex b/lib/xdr/contract/uint64_list.ex new file mode 100644 index 00000000..3cd3c410 --- /dev/null +++ b/lib/xdr/contract/uint64_list.ex @@ -0,0 +1,57 @@ +defmodule StellarBase.XDR.UInt64List do + @moduledoc """ + Automatically generated by xdrgen + DO NOT EDIT or your changes may be overwritten + + Target implementation: elixir_xdr at https://hex.pm/packages/elixir_xdr + + Representation of Stellar `UInt64List` type. + """ + + @behaviour XDR.Declaration + + alias StellarBase.XDR.UInt64 + + @array_type UInt64 + + @array_spec %{type: @array_type} + + @type t :: %__MODULE__{items: list(UInt64.t())} + + defstruct [:items] + + @spec new(items :: list(UInt64.t())) :: t() + def new(items), do: %__MODULE__{items: items} + + @impl true + def encode_xdr(%__MODULE__{items: items}) do + items + |> XDR.VariableArray.new(@array_type) + |> XDR.VariableArray.encode_xdr() + end + + @impl true + def encode_xdr!(%__MODULE__{items: items}) do + items + |> XDR.VariableArray.new(@array_type) + |> XDR.VariableArray.encode_xdr!() + end + + @impl true + def decode_xdr(bytes, spec \\ @array_spec) + + def decode_xdr(bytes, spec) do + case XDR.VariableArray.decode_xdr(bytes, spec) do + {:ok, {items, rest}} -> {:ok, {new(items), rest}} + error -> error + end + end + + @impl true + def decode_xdr!(bytes, spec \\ @array_spec) + + def decode_xdr!(bytes, spec) do + {items, rest} = XDR.VariableArray.decode_xdr!(bytes, spec) + {new(items), rest} + end +end diff --git a/lib/xdr/ledger_entries/contract_code_entry.ex b/lib/xdr/ledger_entries/contract_code_entry.ex index bad2ef78..ca1827ec 100644 --- a/lib/xdr/ledger_entries/contract_code_entry.ex +++ b/lib/xdr/ledger_entries/contract_code_entry.ex @@ -1,56 +1,82 @@ defmodule StellarBase.XDR.ContractCodeEntry do @moduledoc """ + Automatically generated by xdrgen + DO NOT EDIT or your changes may be overwritten + + Target implementation: elixir_xdr at https://hex.pm/packages/elixir_xdr + Representation of Stellar `ContractCodeEntry` type. """ - alias StellarBase.XDR.{Hash, VariableOpaque256000, ExtensionPoint} - @behaviour XDR.Declaration + alias StellarBase.XDR.{ + ExtensionPoint, + Hash, + ContractCodeEntryBody, + UInt32 + } + @struct_spec XDR.Struct.new( + ext: ExtensionPoint, hash: Hash, - code: VariableOpaque256000, - ext: ExtensionPoint + body: ContractCodeEntryBody, + expiration_ledger_seq: UInt32 ) + @type ext_type :: ExtensionPoint.t() + @type hash_type :: Hash.t() + @type body_type :: ContractCodeEntryBody.t() + @type expiration_ledger_seq_type :: UInt32.t() + @type t :: %__MODULE__{ - hash: Hash.t(), - code: VariableOpaque256000.t(), - ext: ExtensionPoint.t() + ext: ext_type(), + hash: hash_type(), + body: body_type(), + expiration_ledger_seq: expiration_ledger_seq_type() } - defstruct [:hash, :code, :ext] + defstruct [:ext, :hash, :body, :expiration_ledger_seq] @spec new( - hash :: Hash.t(), - code :: VariableOpaque256000.t(), - ext :: ExtensionPoint.t() + ext :: ext_type(), + hash :: hash_type(), + body :: body_type(), + expiration_ledger_seq :: expiration_ledger_seq_type() ) :: t() def new( + %ExtensionPoint{} = ext, %Hash{} = hash, - %VariableOpaque256000{} = code, - %ExtensionPoint{} = ext + %ContractCodeEntryBody{} = body, + %UInt32{} = expiration_ledger_seq ), - do: %__MODULE__{hash: hash, code: code, ext: ext} + do: %__MODULE__{ + ext: ext, + hash: hash, + body: body, + expiration_ledger_seq: expiration_ledger_seq + } @impl true def encode_xdr(%__MODULE__{ + ext: ext, hash: hash, - code: code, - ext: ext + body: body, + expiration_ledger_seq: expiration_ledger_seq }) do - [hash: hash, code: code, ext: ext] + [ext: ext, hash: hash, body: body, expiration_ledger_seq: expiration_ledger_seq] |> XDR.Struct.new() |> XDR.Struct.encode_xdr() end @impl true def encode_xdr!(%__MODULE__{ + ext: ext, hash: hash, - code: code, - ext: ext + body: body, + expiration_ledger_seq: expiration_ledger_seq }) do - [hash: hash, code: code, ext: ext] + [ext: ext, hash: hash, body: body, expiration_ledger_seq: expiration_ledger_seq] |> XDR.Struct.new() |> XDR.Struct.encode_xdr!() end @@ -62,9 +88,14 @@ defmodule StellarBase.XDR.ContractCodeEntry do case XDR.Struct.decode_xdr(bytes, struct) do {:ok, {%XDR.Struct{ - components: [hash: hash, code: code, ext: ext] + components: [ + ext: ext, + hash: hash, + body: body, + expiration_ledger_seq: expiration_ledger_seq + ] }, rest}} -> - {:ok, {new(hash, code, ext), rest}} + {:ok, {new(ext, hash, body, expiration_ledger_seq), rest}} error -> error @@ -76,9 +107,14 @@ defmodule StellarBase.XDR.ContractCodeEntry do def decode_xdr!(bytes, struct) do {%XDR.Struct{ - components: [hash: hash, code: code, ext: ext] + components: [ + ext: ext, + hash: hash, + body: body, + expiration_ledger_seq: expiration_ledger_seq + ] }, rest} = XDR.Struct.decode_xdr!(bytes, struct) - {new(hash, code, ext), rest} + {new(ext, hash, body, expiration_ledger_seq), rest} end end diff --git a/lib/xdr/ledger_entries/contract_code_entry_body.ex b/lib/xdr/ledger_entries/contract_code_entry_body.ex new file mode 100644 index 00000000..fd48e44d --- /dev/null +++ b/lib/xdr/ledger_entries/contract_code_entry_body.ex @@ -0,0 +1,73 @@ +defmodule StellarBase.XDR.ContractCodeEntryBody do + @moduledoc """ + Automatically generated by xdrgen + DO NOT EDIT or your changes may be overwritten + + Target implementation: elixir_xdr at https://hex.pm/packages/elixir_xdr + + Representation of Stellar `ContractCodeEntryBody` type. + """ + + @behaviour XDR.Declaration + + alias StellarBase.XDR.{ + ContractEntryBodyType, + VariableOpaque, + Void + } + + @arms [ + DATA_ENTRY: VariableOpaque, + EXPIRATION_EXTENSION: Void + ] + + @type value :: + VariableOpaque.t() + | Void.t() + + @type t :: %__MODULE__{value: value(), type: ContractEntryBodyType.t()} + + defstruct [:value, :type] + + @spec new(value :: value(), type :: ContractEntryBodyType.t()) :: t() + def new(value, %ContractEntryBodyType{} = type), do: %__MODULE__{value: value, type: type} + + @impl true + def encode_xdr(%__MODULE__{value: value, type: type}) do + type + |> XDR.Union.new(@arms, value) + |> XDR.Union.encode_xdr() + end + + @impl true + def encode_xdr!(%__MODULE__{value: value, type: type}) do + type + |> XDR.Union.new(@arms, value) + |> XDR.Union.encode_xdr!() + end + + @impl true + def decode_xdr(bytes, spec \\ union_spec()) + + def decode_xdr(bytes, spec) do + case XDR.Union.decode_xdr(bytes, spec) do + {:ok, {{type, value}, rest}} -> {:ok, {new(value, type), rest}} + error -> error + end + end + + @impl true + def decode_xdr!(bytes, spec \\ union_spec()) + + def decode_xdr!(bytes, spec) do + {{type, value}, rest} = XDR.Union.decode_xdr!(bytes, spec) + {new(value, type), rest} + end + + @spec union_spec() :: XDR.Union.t() + defp union_spec do + nil + |> ContractEntryBodyType.new() + |> XDR.Union.new(@arms) + end +end diff --git a/lib/xdr/contract/sc_host_fn_error_code.ex b/lib/xdr/ledger_entries/contract_data_durability.ex similarity index 72% rename from lib/xdr/contract/sc_host_fn_error_code.ex rename to lib/xdr/ledger_entries/contract_data_durability.ex index 0516e8e3..323ee556 100644 --- a/lib/xdr/contract/sc_host_fn_error_code.ex +++ b/lib/xdr/ledger_entries/contract_data_durability.ex @@ -1,16 +1,18 @@ -defmodule StellarBase.XDR.SCHostFnErrorCode do +defmodule StellarBase.XDR.ContractDataDurability do @moduledoc """ - Representation of Stellar `SCHostFnErrorCode` type. + Automatically generated by xdrgen + DO NOT EDIT or your changes may be overwritten + + Target implementation: elixir_xdr at https://hex.pm/packages/elixir_xdr + + Representation of Stellar `ContractDataDurability` type. """ @behaviour XDR.Declaration @declarations [ - HOST_FN_UNKNOWN_ERROR: 0, - HOST_FN_UNEXPECTED_HOST_FUNCTION_ACTION: 1, - HOST_FN_INPUT_ARGS_WRONG_LENGTH: 2, - HOST_FN_INPUT_ARGS_WRONG_TYPE: 3, - HOST_FN_INPUT_ARGS_INVALID: 4 + TEMPORARY: 0, + PERSISTENT: 1 ] @enum_spec %XDR.Enum{declarations: @declarations, identifier: nil} @@ -20,7 +22,7 @@ defmodule StellarBase.XDR.SCHostFnErrorCode do defstruct [:identifier] @spec new(type :: atom()) :: t() - def new(type \\ :HOST_FN_UNKNOWN_ERROR), do: %__MODULE__{identifier: type} + def new(type \\ :TEMPORARY), do: %__MODULE__{identifier: type} @impl true def encode_xdr(%__MODULE__{identifier: type}) do diff --git a/lib/xdr/ledger_entries/contract_data_entry.ex b/lib/xdr/ledger_entries/contract_data_entry.ex index 10e89b22..5f0697a9 100644 --- a/lib/xdr/ledger_entries/contract_data_entry.ex +++ b/lib/xdr/ledger_entries/contract_data_entry.ex @@ -1,32 +1,103 @@ defmodule StellarBase.XDR.ContractDataEntry do @moduledoc """ + Automatically generated by xdrgen + DO NOT EDIT or your changes may be overwritten + + Target implementation: elixir_xdr at https://hex.pm/packages/elixir_xdr + Representation of Stellar `ContractDataEntry` type. """ - alias StellarBase.XDR.{Hash, SCVal} - @behaviour XDR.Declaration - @struct_spec XDR.Struct.new(contract_id: Hash, key: SCVal, val: SCVal) + alias StellarBase.XDR.{ + SCAddress, + SCVal, + ContractDataDurability, + ContractDataEntryBody, + UInt32 + } + + @struct_spec XDR.Struct.new( + contract: SCAddress, + key: SCVal, + durability: ContractDataDurability, + body: ContractDataEntryBody, + expiration_ledger_seq: UInt32 + ) + + @type contract_type :: SCAddress.t() + @type key_type :: SCVal.t() + @type durability_type :: ContractDataDurability.t() + @type body_type :: ContractDataEntryBody.t() + @type expiration_ledger_seq_type :: UInt32.t() - @type t :: %__MODULE__{contract_id: Hash.t(), key: SCVal.t(), val: SCVal.t()} + @type t :: %__MODULE__{ + contract: contract_type(), + key: key_type(), + durability: durability_type(), + body: body_type(), + expiration_ledger_seq: expiration_ledger_seq_type() + } - defstruct [:contract_id, :key, :val] + defstruct [:contract, :key, :durability, :body, :expiration_ledger_seq] - @spec new(contract_id :: Hash.t(), key :: SCVal.t(), val :: SCVal.t()) :: t() - def new(%Hash{} = contract_id, %SCVal{} = key, %SCVal{} = val), - do: %__MODULE__{contract_id: contract_id, key: key, val: val} + @spec new( + contract :: contract_type(), + key :: key_type(), + durability :: durability_type(), + body :: body_type(), + expiration_ledger_seq :: expiration_ledger_seq_type() + ) :: t() + def new( + %SCAddress{} = contract, + %SCVal{} = key, + %ContractDataDurability{} = durability, + %ContractDataEntryBody{} = body, + %UInt32{} = expiration_ledger_seq + ), + do: %__MODULE__{ + contract: contract, + key: key, + durability: durability, + body: body, + expiration_ledger_seq: expiration_ledger_seq + } @impl true - def encode_xdr(%__MODULE__{contract_id: contract_id, key: key, val: val}) do - [contract_id: contract_id, key: key, val: val] + def encode_xdr(%__MODULE__{ + contract: contract, + key: key, + durability: durability, + body: body, + expiration_ledger_seq: expiration_ledger_seq + }) do + [ + contract: contract, + key: key, + durability: durability, + body: body, + expiration_ledger_seq: expiration_ledger_seq + ] |> XDR.Struct.new() |> XDR.Struct.encode_xdr() end @impl true - def encode_xdr!(%__MODULE__{contract_id: contract_id, key: key, val: val}) do - [contract_id: contract_id, key: key, val: val] + def encode_xdr!(%__MODULE__{ + contract: contract, + key: key, + durability: durability, + body: body, + expiration_ledger_seq: expiration_ledger_seq + }) do + [ + contract: contract, + key: key, + durability: durability, + body: body, + expiration_ledger_seq: expiration_ledger_seq + ] |> XDR.Struct.new() |> XDR.Struct.encode_xdr!() end @@ -36,8 +107,17 @@ defmodule StellarBase.XDR.ContractDataEntry do def decode_xdr(bytes, struct) do case XDR.Struct.decode_xdr(bytes, struct) do - {:ok, {%XDR.Struct{components: [contract_id: contract_id, key: key, val: val]}, rest}} -> - {:ok, {new(contract_id, key, val), rest}} + {:ok, + {%XDR.Struct{ + components: [ + contract: contract, + key: key, + durability: durability, + body: body, + expiration_ledger_seq: expiration_ledger_seq + ] + }, rest}} -> + {:ok, {new(contract, key, durability, body, expiration_ledger_seq), rest}} error -> error @@ -48,9 +128,16 @@ defmodule StellarBase.XDR.ContractDataEntry do def decode_xdr!(bytes, struct \\ @struct_spec) def decode_xdr!(bytes, struct) do - {%XDR.Struct{components: [contract_id: contract_id, key: key, val: val]}, rest} = - XDR.Struct.decode_xdr!(bytes, struct) + {%XDR.Struct{ + components: [ + contract: contract, + key: key, + durability: durability, + body: body, + expiration_ledger_seq: expiration_ledger_seq + ] + }, rest} = XDR.Struct.decode_xdr!(bytes, struct) - {new(contract_id, key, val), rest} + {new(contract, key, durability, body, expiration_ledger_seq), rest} end end diff --git a/lib/xdr/ledger_entries/contract_data_entry_body.ex b/lib/xdr/ledger_entries/contract_data_entry_body.ex new file mode 100644 index 00000000..a1bb5653 --- /dev/null +++ b/lib/xdr/ledger_entries/contract_data_entry_body.ex @@ -0,0 +1,73 @@ +defmodule StellarBase.XDR.ContractDataEntryBody do + @moduledoc """ + Automatically generated by xdrgen + DO NOT EDIT or your changes may be overwritten + + Target implementation: elixir_xdr at https://hex.pm/packages/elixir_xdr + + Representation of Stellar `ContractDataEntryBody` type. + """ + + @behaviour XDR.Declaration + + alias StellarBase.XDR.{ + ContractEntryBodyType, + ContractDataEntryData, + Void + } + + @arms [ + DATA_ENTRY: ContractDataEntryData, + EXPIRATION_EXTENSION: Void + ] + + @type value :: + ContractDataEntryData.t() + | Void.t() + + @type t :: %__MODULE__{value: value(), type: ContractEntryBodyType.t()} + + defstruct [:value, :type] + + @spec new(value :: value(), type :: ContractEntryBodyType.t()) :: t() + def new(value, %ContractEntryBodyType{} = type), do: %__MODULE__{value: value, type: type} + + @impl true + def encode_xdr(%__MODULE__{value: value, type: type}) do + type + |> XDR.Union.new(@arms, value) + |> XDR.Union.encode_xdr() + end + + @impl true + def encode_xdr!(%__MODULE__{value: value, type: type}) do + type + |> XDR.Union.new(@arms, value) + |> XDR.Union.encode_xdr!() + end + + @impl true + def decode_xdr(bytes, spec \\ union_spec()) + + def decode_xdr(bytes, spec) do + case XDR.Union.decode_xdr(bytes, spec) do + {:ok, {{type, value}, rest}} -> {:ok, {new(value, type), rest}} + error -> error + end + end + + @impl true + def decode_xdr!(bytes, spec \\ union_spec()) + + def decode_xdr!(bytes, spec) do + {{type, value}, rest} = XDR.Union.decode_xdr!(bytes, spec) + {new(value, type), rest} + end + + @spec union_spec() :: XDR.Union.t() + defp union_spec do + nil + |> ContractEntryBodyType.new() + |> XDR.Union.new(@arms) + end +end diff --git a/lib/xdr/ledger_entries/contract_data_entry_data.ex b/lib/xdr/ledger_entries/contract_data_entry_data.ex new file mode 100644 index 00000000..042de179 --- /dev/null +++ b/lib/xdr/ledger_entries/contract_data_entry_data.ex @@ -0,0 +1,73 @@ +defmodule StellarBase.XDR.ContractDataEntryData do + @moduledoc """ + Automatically generated by xdrgen + DO NOT EDIT or your changes may be overwritten + + Target implementation: elixir_xdr at https://hex.pm/packages/elixir_xdr + + Representation of Stellar `ContractDataEntryData` type. + """ + + @behaviour XDR.Declaration + + alias StellarBase.XDR.{ + UInt32, + SCVal + } + + @struct_spec XDR.Struct.new( + flags: UInt32, + val: SCVal + ) + + @type flags_type :: UInt32.t() + @type val_type :: SCVal.t() + + @type t :: %__MODULE__{flags: flags_type(), val: val_type()} + + defstruct [:flags, :val] + + @spec new(flags :: flags_type(), val :: val_type()) :: t() + def new( + %UInt32{} = flags, + %SCVal{} = val + ), + do: %__MODULE__{flags: flags, val: val} + + @impl true + def encode_xdr(%__MODULE__{flags: flags, val: val}) do + [flags: flags, val: val] + |> XDR.Struct.new() + |> XDR.Struct.encode_xdr() + end + + @impl true + def encode_xdr!(%__MODULE__{flags: flags, val: val}) do + [flags: flags, val: val] + |> XDR.Struct.new() + |> XDR.Struct.encode_xdr!() + end + + @impl true + def decode_xdr(bytes, struct \\ @struct_spec) + + def decode_xdr(bytes, struct) do + case XDR.Struct.decode_xdr(bytes, struct) do + {:ok, {%XDR.Struct{components: [flags: flags, val: val]}, rest}} -> + {:ok, {new(flags, val), rest}} + + error -> + error + end + end + + @impl true + def decode_xdr!(bytes, struct \\ @struct_spec) + + def decode_xdr!(bytes, struct) do + {%XDR.Struct{components: [flags: flags, val: val]}, rest} = + XDR.Struct.decode_xdr!(bytes, struct) + + {new(flags, val), rest} + end +end diff --git a/lib/xdr/contract/sc_unknown_error_code.ex b/lib/xdr/ledger_entries/contract_data_flags.ex similarity index 74% rename from lib/xdr/contract/sc_unknown_error_code.ex rename to lib/xdr/ledger_entries/contract_data_flags.ex index 41f84e99..a193b959 100644 --- a/lib/xdr/contract/sc_unknown_error_code.ex +++ b/lib/xdr/ledger_entries/contract_data_flags.ex @@ -1,13 +1,17 @@ -defmodule StellarBase.XDR.SCUnknownErrorCode do +defmodule StellarBase.XDR.ContractDataFlags do @moduledoc """ - Representation of Stellar `SCUnknownErrorCode` type. + Automatically generated by xdrgen + DO NOT EDIT or your changes may be overwritten + + Target implementation: elixir_xdr at https://hex.pm/packages/elixir_xdr + + Representation of Stellar `ContractDataFlags` type. """ @behaviour XDR.Declaration @declarations [ - UNKNOWN_ERROR_GENERAL: 0, - UNKNOWN_ERROR_XDR: 1 + NO_AUTOBUMP: 1 ] @enum_spec %XDR.Enum{declarations: @declarations, identifier: nil} @@ -17,7 +21,7 @@ defmodule StellarBase.XDR.SCUnknownErrorCode do defstruct [:identifier] @spec new(type :: atom()) :: t() - def new(type \\ :UNKNOWN_ERROR_GENERAL), do: %__MODULE__{identifier: type} + def new(type \\ :NO_AUTOBUMP), do: %__MODULE__{identifier: type} @impl true def encode_xdr(%__MODULE__{identifier: type}) do diff --git a/lib/xdr/contract/sc_contract_executable_type.ex b/lib/xdr/ledger_entries/contract_entry_body_type.ex similarity index 72% rename from lib/xdr/contract/sc_contract_executable_type.ex rename to lib/xdr/ledger_entries/contract_entry_body_type.ex index 271e092e..3d8fc188 100644 --- a/lib/xdr/contract/sc_contract_executable_type.ex +++ b/lib/xdr/ledger_entries/contract_entry_body_type.ex @@ -1,13 +1,18 @@ -defmodule StellarBase.XDR.SCContractExecutableType do +defmodule StellarBase.XDR.ContractEntryBodyType do @moduledoc """ - Representation of Stellar `SCContractExecutableType` type. + Automatically generated by xdrgen + DO NOT EDIT or your changes may be overwritten + + Target implementation: elixir_xdr at https://hex.pm/packages/elixir_xdr + + Representation of Stellar `ContractEntryBodyType` type. """ @behaviour XDR.Declaration @declarations [ - SCCONTRACT_EXECUTABLE_WASM_REF: 0, - SCCONTRACT_EXECUTABLE_TOKEN: 1 + DATA_ENTRY: 0, + EXPIRATION_EXTENSION: 1 ] @enum_spec %XDR.Enum{declarations: @declarations, identifier: nil} @@ -17,7 +22,7 @@ defmodule StellarBase.XDR.SCContractExecutableType do defstruct [:identifier] @spec new(type :: atom()) :: t() - def new(type), do: %__MODULE__{identifier: type} + def new(type \\ :DATA_ENTRY), do: %__MODULE__{identifier: type} @impl true def encode_xdr(%__MODULE__{identifier: type}) do diff --git a/lib/xdr/ledger_entries/envelope_type.ex b/lib/xdr/ledger_entries/envelope_type.ex index 7ed586df..a4f29f87 100644 --- a/lib/xdr/ledger_entries/envelope_type.ex +++ b/lib/xdr/ledger_entries/envelope_type.ex @@ -1,5 +1,10 @@ defmodule StellarBase.XDR.EnvelopeType do @moduledoc """ + Automatically generated by xdrgen + DO NOT EDIT or your changes may be overwritten + + Target implementation: elixir_xdr at https://hex.pm/packages/elixir_xdr + Representation of Stellar `EnvelopeType` type. """ @@ -14,12 +19,8 @@ defmodule StellarBase.XDR.EnvelopeType do ENVELOPE_TYPE_TX_FEE_BUMP: 5, ENVELOPE_TYPE_OP_ID: 6, ENVELOPE_TYPE_POOL_REVOKE_OP_ID: 7, - ENVELOPE_TYPE_CONTRACT_ID_FROM_ED25519: 8, - ENVELOPE_TYPE_CONTRACT_ID_FROM_CONTRACT: 9, - ENVELOPE_TYPE_CONTRACT_ID_FROM_ASSET: 10, - ENVELOPE_TYPE_CONTRACT_ID_FROM_SOURCE_ACCOUNT: 11, - ENVELOPE_TYPE_CREATE_CONTRACT_ARGS: 12, - ENVELOPE_TYPE_CONTRACT_AUTH: 13 + ENVELOPE_TYPE_CONTRACT_ID: 8, + ENVELOPE_TYPE_SOROBAN_AUTHORIZATION: 9 ] @enum_spec %XDR.Enum{declarations: @declarations, identifier: nil} diff --git a/lib/xdr/transactions/address_with_nonce.ex b/lib/xdr/transactions/address_with_nonce.ex deleted file mode 100644 index 302e2aad..00000000 --- a/lib/xdr/transactions/address_with_nonce.ex +++ /dev/null @@ -1,55 +0,0 @@ -defmodule StellarBase.XDR.AddressWithNonce do - @moduledoc """ - Representation of Stellar `AddressWithNonce` type. - """ - alias StellarBase.XDR.{SCAddress, UInt64} - - @behaviour XDR.Declaration - - @struct_spec XDR.Struct.new(address: SCAddress, nonce: UInt64) - - @type t :: %__MODULE__{address: SCAddress.t(), nonce: UInt64.t()} - - defstruct [:address, :nonce] - - @spec new(address :: SCAddress.t(), nonce :: UInt64.t()) :: t() - def new(%SCAddress{} = address, %UInt64{} = nonce), - do: %__MODULE__{address: address, nonce: nonce} - - @impl true - def encode_xdr(%__MODULE__{address: address, nonce: nonce}) do - [address: address, nonce: nonce] - |> XDR.Struct.new() - |> XDR.Struct.encode_xdr() - end - - @impl true - def encode_xdr!(%__MODULE__{address: address, nonce: nonce}) do - [address: address, nonce: nonce] - |> XDR.Struct.new() - |> XDR.Struct.encode_xdr!() - end - - @impl true - def decode_xdr(bytes, struct \\ @struct_spec) - - def decode_xdr(bytes, struct) do - case XDR.Struct.decode_xdr(bytes, struct) do - {:ok, {%XDR.Struct{components: [address: address, nonce: nonce]}, rest}} -> - {:ok, {new(address, nonce), rest}} - - error -> - error - end - end - - @impl true - def decode_xdr!(bytes, struct \\ @struct_spec) - - def decode_xdr!(bytes, struct) do - {%XDR.Struct{components: [address: address, nonce: nonce]}, rest} = - XDR.Struct.decode_xdr!(bytes, struct) - - {new(address, nonce), rest} - end -end diff --git a/lib/xdr/transactions/sc_val_list100.ex b/lib/xdr/transactions/asset_list5.ex similarity index 81% rename from lib/xdr/transactions/sc_val_list100.ex rename to lib/xdr/transactions/asset_list5.ex index 55de8d0f..35d81c49 100644 --- a/lib/xdr/transactions/sc_val_list100.ex +++ b/lib/xdr/transactions/asset_list5.ex @@ -1,28 +1,28 @@ -defmodule StellarBase.XDR.SCValList100 do +defmodule StellarBase.XDR.AssetList5 do @moduledoc """ Automatically generated by xdrgen DO NOT EDIT or your changes may be overwritten Target implementation: elixir_xdr at https://hex.pm/packages/elixir_xdr - Representation of Stellar `SCValList100` type. + Representation of Stellar `AssetList5` type. """ @behaviour XDR.Declaration - alias StellarBase.XDR.SCVal + alias StellarBase.XDR.Asset - @max_length 100 + @max_length 5 - @array_type SCVal + @array_type Asset @array_spec %{type: @array_type, max_length: @max_length} - @type t :: %__MODULE__{items: list(SCVal.t())} + @type t :: %__MODULE__{items: list(Asset.t())} defstruct [:items] - @spec new(items :: list(SCVal.t())) :: t() + @spec new(items :: list(Asset.t())) :: t() def new(items), do: %__MODULE__{items: items} @impl true diff --git a/lib/xdr/transactions/authorized_invocation.ex b/lib/xdr/transactions/authorized_invocation.ex deleted file mode 100644 index cd562354..00000000 --- a/lib/xdr/transactions/authorized_invocation.ex +++ /dev/null @@ -1,120 +0,0 @@ -defmodule StellarBase.XDR.AuthorizedInvocation do - @moduledoc """ - Representation of Stellar `AuthorizedInvocation` type. - """ - - alias StellarBase.XDR.{Hash, SCSymbol, SCVec, AuthorizedInvocationList} - - @behaviour XDR.Declaration - - @struct_spec XDR.Struct.new( - contract_id: Hash, - function_name: SCSymbol, - args: SCVec, - sub_invocations: AuthorizedInvocationList - ) - - @type contract_id :: Hash.t() - @type function_name :: SCSymbol.t() - @type args :: SCVec.t() - @type sub_invocations :: AuthorizedInvocationList.t() - - @type t :: %__MODULE__{ - contract_id: contract_id(), - function_name: function_name(), - args: args(), - sub_invocations: sub_invocations() - } - - defstruct [:contract_id, :function_name, :args, :sub_invocations] - - @spec new( - contract_id :: contract_id(), - function_name :: function_name(), - args :: args(), - sub_invocations :: sub_invocations() - ) :: t() - def new( - %Hash{} = contract_id, - %SCSymbol{} = function_name, - %SCVec{} = args, - %AuthorizedInvocationList{} = sub_invocations - ), - do: %__MODULE__{ - contract_id: contract_id, - function_name: function_name, - args: args, - sub_invocations: sub_invocations - } - - @impl true - def encode_xdr(%__MODULE__{ - contract_id: contract_id, - function_name: function_name, - args: args, - sub_invocations: sub_invocations - }) do - [ - contract_id: contract_id, - function_name: function_name, - args: args, - sub_invocations: sub_invocations - ] - |> XDR.Struct.new() - |> XDR.Struct.encode_xdr() - end - - @impl true - def encode_xdr!(%__MODULE__{ - contract_id: contract_id, - function_name: function_name, - args: args, - sub_invocations: sub_invocations - }) do - [ - contract_id: contract_id, - function_name: function_name, - args: args, - sub_invocations: sub_invocations - ] - |> XDR.Struct.new() - |> XDR.Struct.encode_xdr!() - end - - @impl true - def decode_xdr(bytes, struct \\ @struct_spec) - - def decode_xdr(bytes, struct) do - case XDR.Struct.decode_xdr(bytes, struct) do - {:ok, - {%XDR.Struct{ - components: [ - contract_id: contract_id, - function_name: function_name, - args: args, - sub_invocations: sub_invocations - ] - }, rest}} -> - {:ok, {new(contract_id, function_name, args, sub_invocations), rest}} - - error -> - error - end - end - - @impl true - def decode_xdr!(bytes, struct \\ @struct_spec) - - def decode_xdr!(bytes, struct) do - {%XDR.Struct{ - components: [ - contract_id: contract_id, - function_name: function_name, - args: args, - sub_invocations: sub_invocations - ] - }, rest} = XDR.Struct.decode_xdr!(bytes, struct) - - {new(contract_id, function_name, args, sub_invocations), rest} - end -end diff --git a/lib/xdr/transactions/authorized_invocation_list.ex b/lib/xdr/transactions/authorized_invocation_list.ex deleted file mode 100644 index 1b4e239e..00000000 --- a/lib/xdr/transactions/authorized_invocation_list.ex +++ /dev/null @@ -1,53 +0,0 @@ -defmodule StellarBase.XDR.AuthorizedInvocationList do - @moduledoc """ - Representation of a Stellar `AuthorizedInvocationList` list. - """ - alias StellarBase.XDR.AuthorizedInvocation - - @behaviour XDR.Declaration - - @max_length 4_294_967_295 - - @array_type AuthorizedInvocation - - @array_spec %{type: @array_type, max_length: @max_length} - - @type t :: %__MODULE__{sub_invocations: list(AuthorizedInvocation.t())} - - defstruct [:sub_invocations] - - @spec new(sub_invocations :: list(AuthorizedInvocation.t())) :: t() - def new(sub_invocations \\ []), do: %__MODULE__{sub_invocations: sub_invocations} - - @impl true - def encode_xdr(%__MODULE__{sub_invocations: sub_invocations}) do - sub_invocations - |> XDR.VariableArray.new(@array_type, @max_length) - |> XDR.VariableArray.encode_xdr() - end - - @impl true - def encode_xdr!(%__MODULE__{sub_invocations: sub_invocations}) do - sub_invocations - |> XDR.VariableArray.new(@array_type, @max_length) - |> XDR.VariableArray.encode_xdr!() - end - - @impl true - def decode_xdr(bytes, spec \\ @array_spec) - - def decode_xdr(bytes, spec) do - case XDR.VariableArray.decode_xdr(bytes, spec) do - {:ok, {sub_invocations, rest}} -> {:ok, {new(sub_invocations), rest}} - error -> error - end - end - - @impl true - def decode_xdr!(bytes, spec \\ @array_spec) - - def decode_xdr!(bytes, spec) do - {sub_invocations, rest} = XDR.VariableArray.decode_xdr!(bytes, spec) - {new(sub_invocations), rest} - end -end diff --git a/lib/xdr/transactions/host_function_list100.ex b/lib/xdr/transactions/claimant_list10.ex similarity index 79% rename from lib/xdr/transactions/host_function_list100.ex rename to lib/xdr/transactions/claimant_list10.ex index 8732d475..df4cddc6 100644 --- a/lib/xdr/transactions/host_function_list100.ex +++ b/lib/xdr/transactions/claimant_list10.ex @@ -1,28 +1,28 @@ -defmodule StellarBase.XDR.HostFunctionList100 do +defmodule StellarBase.XDR.ClaimantList10 do @moduledoc """ Automatically generated by xdrgen DO NOT EDIT or your changes may be overwritten Target implementation: elixir_xdr at https://hex.pm/packages/elixir_xdr - Representation of Stellar `HostFunctionList100` type. + Representation of Stellar `ClaimantList10` type. """ @behaviour XDR.Declaration - alias StellarBase.XDR.HostFunction + alias StellarBase.XDR.Claimant - @max_length 100 + @max_length 10 - @array_type HostFunction + @array_type Claimant @array_spec %{type: @array_type, max_length: @max_length} - @type t :: %__MODULE__{items: list(HostFunction.t())} + @type t :: %__MODULE__{items: list(Claimant.t())} defstruct [:items] - @spec new(items :: list(HostFunction.t())) :: t() + @spec new(items :: list(Claimant.t())) :: t() def new(items), do: %__MODULE__{items: items} @impl true diff --git a/lib/xdr/transactions/contract_auth.ex b/lib/xdr/transactions/contract_auth.ex deleted file mode 100644 index c3371a0b..00000000 --- a/lib/xdr/transactions/contract_auth.ex +++ /dev/null @@ -1,103 +0,0 @@ -defmodule StellarBase.XDR.ContractAuth do - @moduledoc """ - Representation of Stellar `ContractAuth` type. - """ - alias StellarBase.XDR.{OptionalAddressWithNonce, AuthorizedInvocation, SCVec} - - @behaviour XDR.Declaration - - @struct_spec XDR.Struct.new( - address_with_nonce: OptionalAddressWithNonce, - authorized_invocation: AuthorizedInvocation, - signature_args: SCVec - ) - - @type t :: %__MODULE__{ - address_with_nonce: OptionalAddressWithNonce.t(), - authorized_invocation: AuthorizedInvocation.t(), - signature_args: SCVec.t() - } - - defstruct [:address_with_nonce, :authorized_invocation, :signature_args] - - @spec new( - address_with_nonce :: OptionalAddressWithNonce.t(), - authorized_invocation :: AuthorizedInvocation.t(), - signature_args :: SCVec.t() - ) :: t() - def new( - %OptionalAddressWithNonce{} = address_with_nonce, - %AuthorizedInvocation{} = authorized_invocation, - %SCVec{} = signature_args - ), - do: %__MODULE__{ - address_with_nonce: address_with_nonce, - authorized_invocation: authorized_invocation, - signature_args: signature_args - } - - @impl true - def encode_xdr(%__MODULE__{ - address_with_nonce: address_with_nonce, - authorized_invocation: authorized_invocation, - signature_args: signature_args - }) do - [ - address_with_nonce: address_with_nonce, - authorized_invocation: authorized_invocation, - signature_args: signature_args - ] - |> XDR.Struct.new() - |> XDR.Struct.encode_xdr() - end - - @impl true - def encode_xdr!(%__MODULE__{ - address_with_nonce: address_with_nonce, - authorized_invocation: authorized_invocation, - signature_args: signature_args - }) do - [ - address_with_nonce: address_with_nonce, - authorized_invocation: authorized_invocation, - signature_args: signature_args - ] - |> XDR.Struct.new() - |> XDR.Struct.encode_xdr!() - end - - @impl true - def decode_xdr(bytes, struct \\ @struct_spec) - - def decode_xdr(bytes, struct) do - case XDR.Struct.decode_xdr(bytes, struct) do - {:ok, - {%XDR.Struct{ - components: [ - address_with_nonce: address_with_nonce, - authorized_invocation: authorized_invocation, - signature_args: signature_args - ] - }, rest}} -> - {:ok, {new(address_with_nonce, authorized_invocation, signature_args), rest}} - - error -> - error - end - end - - @impl true - def decode_xdr!(bytes, struct \\ @struct_spec) - - def decode_xdr!(bytes, struct) do - {%XDR.Struct{ - components: [ - address_with_nonce: address_with_nonce, - authorized_invocation: authorized_invocation, - signature_args: signature_args - ] - }, rest} = XDR.Struct.decode_xdr!(bytes, struct) - - {new(address_with_nonce, authorized_invocation, signature_args), rest} - end -end diff --git a/lib/xdr/transactions/contract_auth_list.ex b/lib/xdr/transactions/contract_auth_list.ex deleted file mode 100644 index 60ff5507..00000000 --- a/lib/xdr/transactions/contract_auth_list.ex +++ /dev/null @@ -1,53 +0,0 @@ -defmodule StellarBase.XDR.ContractAuthList do - @moduledoc """ - Representation of a Stellar `ContractAuthList` list. - """ - alias StellarBase.XDR.ContractAuth - - @behaviour XDR.Declaration - - @max_length 4_294_967_295 - - @array_type ContractAuth - - @array_spec %{type: @array_type, max_length: @max_length} - - @type t :: %__MODULE__{auth: list(ContractAuth.t())} - - defstruct [:auth] - - @spec new(auth :: list(ContractAuth.t())) :: t() - def new(auth), do: %__MODULE__{auth: auth} - - @impl true - def encode_xdr(%__MODULE__{auth: auth}) do - auth - |> XDR.VariableArray.new(@array_type, @max_length) - |> XDR.VariableArray.encode_xdr() - end - - @impl true - def encode_xdr!(%__MODULE__{auth: auth}) do - auth - |> XDR.VariableArray.new(@array_type, @max_length) - |> XDR.VariableArray.encode_xdr!() - end - - @impl true - def decode_xdr(bytes, spec \\ @array_spec) - - def decode_xdr(bytes, spec) do - case XDR.VariableArray.decode_xdr(bytes, spec) do - {:ok, {auth, rest}} -> {:ok, {new(auth), rest}} - error -> error - end - end - - @impl true - def decode_xdr!(bytes, spec \\ @array_spec) - - def decode_xdr!(bytes, spec) do - {auth, rest} = XDR.VariableArray.decode_xdr!(bytes, spec) - {new(auth), rest} - end -end diff --git a/lib/xdr/transactions/contract_id.ex b/lib/xdr/transactions/contract_id.ex deleted file mode 100644 index 58c20754..00000000 --- a/lib/xdr/transactions/contract_id.ex +++ /dev/null @@ -1,64 +0,0 @@ -defmodule StellarBase.XDR.ContractID do - @moduledoc """ - Representation of Stellar `ContractID` type. - """ - - alias StellarBase.XDR.{Asset, ContractIDType, UInt256, FromEd25519PublicKey} - - @behaviour XDR.Declaration - - @arms [ - CONTRACT_ID_FROM_SOURCE_ACCOUNT: UInt256, - CONTRACT_ID_FROM_ED25519_PUBLIC_KEY: FromEd25519PublicKey, - CONTRACT_ID_FROM_ASSET: Asset - ] - - @type contract_id :: UInt256.t() | Asset.t() | FromEd25519PublicKey.t() - - @type t :: %__MODULE__{contract_id: contract_id(), type: ContractIDType.t()} - - defstruct [:contract_id, :type] - - @spec new(contract_id :: contract_id(), type :: ContractIDType.t()) :: t() - def new(contract_id, %ContractIDType{} = type), - do: %__MODULE__{contract_id: contract_id, type: type} - - @impl true - def encode_xdr(%__MODULE__{contract_id: contract_id, type: type}) do - type - |> XDR.Union.new(@arms, contract_id) - |> XDR.Union.encode_xdr() - end - - @impl true - def encode_xdr!(%__MODULE__{contract_id: contract_id, type: type}) do - type - |> XDR.Union.new(@arms, contract_id) - |> XDR.Union.encode_xdr!() - end - - @impl true - def decode_xdr(bytes, spec \\ union_spec()) - - def decode_xdr(bytes, spec) do - case XDR.Union.decode_xdr(bytes, spec) do - {:ok, {{type, contract_id}, rest}} -> {:ok, {new(contract_id, type), rest}} - error -> error - end - end - - @impl true - def decode_xdr!(bytes, spec \\ union_spec()) - - def decode_xdr!(bytes, spec) do - {{type, contract_id}, rest} = XDR.Union.decode_xdr!(bytes, spec) - {new(contract_id, type), rest} - end - - @spec union_spec() :: XDR.Union.t() - defp union_spec do - nil - |> ContractIDType.new() - |> XDR.Union.new(@arms) - end -end diff --git a/lib/xdr/transactions/contract_id_preimage.ex b/lib/xdr/transactions/contract_id_preimage.ex new file mode 100644 index 00000000..e1e59e11 --- /dev/null +++ b/lib/xdr/transactions/contract_id_preimage.ex @@ -0,0 +1,73 @@ +defmodule StellarBase.XDR.ContractIDPreimage do + @moduledoc """ + Automatically generated by xdrgen + DO NOT EDIT or your changes may be overwritten + + Target implementation: elixir_xdr at https://hex.pm/packages/elixir_xdr + + Representation of Stellar `ContractIDPreimage` type. + """ + + @behaviour XDR.Declaration + + alias StellarBase.XDR.{ + ContractIDPreimageType, + ContractIDPreimageFromAddress, + Asset + } + + @arms [ + CONTRACT_ID_PREIMAGE_FROM_ADDRESS: ContractIDPreimageFromAddress, + CONTRACT_ID_PREIMAGE_FROM_ASSET: Asset + ] + + @type value :: + ContractIDPreimageFromAddress.t() + | Asset.t() + + @type t :: %__MODULE__{value: value(), type: ContractIDPreimageType.t()} + + defstruct [:value, :type] + + @spec new(value :: value(), type :: ContractIDPreimageType.t()) :: t() + def new(value, %ContractIDPreimageType{} = type), do: %__MODULE__{value: value, type: type} + + @impl true + def encode_xdr(%__MODULE__{value: value, type: type}) do + type + |> XDR.Union.new(@arms, value) + |> XDR.Union.encode_xdr() + end + + @impl true + def encode_xdr!(%__MODULE__{value: value, type: type}) do + type + |> XDR.Union.new(@arms, value) + |> XDR.Union.encode_xdr!() + end + + @impl true + def decode_xdr(bytes, spec \\ union_spec()) + + def decode_xdr(bytes, spec) do + case XDR.Union.decode_xdr(bytes, spec) do + {:ok, {{type, value}, rest}} -> {:ok, {new(value, type), rest}} + error -> error + end + end + + @impl true + def decode_xdr!(bytes, spec \\ union_spec()) + + def decode_xdr!(bytes, spec) do + {{type, value}, rest} = XDR.Union.decode_xdr!(bytes, spec) + {new(value, type), rest} + end + + @spec union_spec() :: XDR.Union.t() + defp union_spec do + nil + |> ContractIDPreimageType.new() + |> XDR.Union.new(@arms) + end +end diff --git a/lib/xdr/transactions/contract_id_preimage_from_address.ex b/lib/xdr/transactions/contract_id_preimage_from_address.ex new file mode 100644 index 00000000..b4a503d0 --- /dev/null +++ b/lib/xdr/transactions/contract_id_preimage_from_address.ex @@ -0,0 +1,73 @@ +defmodule StellarBase.XDR.ContractIDPreimageFromAddress do + @moduledoc """ + Automatically generated by xdrgen + DO NOT EDIT or your changes may be overwritten + + Target implementation: elixir_xdr at https://hex.pm/packages/elixir_xdr + + Representation of Stellar `ContractIDPreimageFromAddress` type. + """ + + @behaviour XDR.Declaration + + alias StellarBase.XDR.{ + SCAddress, + UInt256 + } + + @struct_spec XDR.Struct.new( + address: SCAddress, + salt: UInt256 + ) + + @type address_type :: SCAddress.t() + @type salt_type :: UInt256.t() + + @type t :: %__MODULE__{address: address_type(), salt: salt_type()} + + defstruct [:address, :salt] + + @spec new(address :: address_type(), salt :: salt_type()) :: t() + def new( + %SCAddress{} = address, + %UInt256{} = salt + ), + do: %__MODULE__{address: address, salt: salt} + + @impl true + def encode_xdr(%__MODULE__{address: address, salt: salt}) do + [address: address, salt: salt] + |> XDR.Struct.new() + |> XDR.Struct.encode_xdr() + end + + @impl true + def encode_xdr!(%__MODULE__{address: address, salt: salt}) do + [address: address, salt: salt] + |> XDR.Struct.new() + |> XDR.Struct.encode_xdr!() + end + + @impl true + def decode_xdr(bytes, struct \\ @struct_spec) + + def decode_xdr(bytes, struct) do + case XDR.Struct.decode_xdr(bytes, struct) do + {:ok, {%XDR.Struct{components: [address: address, salt: salt]}, rest}} -> + {:ok, {new(address, salt), rest}} + + error -> + error + end + end + + @impl true + def decode_xdr!(bytes, struct \\ @struct_spec) + + def decode_xdr!(bytes, struct) do + {%XDR.Struct{components: [address: address, salt: salt]}, rest} = + XDR.Struct.decode_xdr!(bytes, struct) + + {new(address, salt), rest} + end +end diff --git a/lib/xdr/transactions/contract_id_preimage_type.ex b/lib/xdr/transactions/contract_id_preimage_type.ex new file mode 100644 index 00000000..47255c05 --- /dev/null +++ b/lib/xdr/transactions/contract_id_preimage_type.ex @@ -0,0 +1,58 @@ +defmodule StellarBase.XDR.ContractIDPreimageType do + @moduledoc """ + Automatically generated by xdrgen + DO NOT EDIT or your changes may be overwritten + + Target implementation: elixir_xdr at https://hex.pm/packages/elixir_xdr + + Representation of Stellar `ContractIDPreimageType` type. + """ + + @behaviour XDR.Declaration + + @declarations [ + CONTRACT_ID_PREIMAGE_FROM_ADDRESS: 0, + CONTRACT_ID_PREIMAGE_FROM_ASSET: 1 + ] + + @enum_spec %XDR.Enum{declarations: @declarations, identifier: nil} + + @type t :: %__MODULE__{identifier: atom()} + + defstruct [:identifier] + + @spec new(type :: atom()) :: t() + def new(type \\ :CONTRACT_ID_PREIMAGE_FROM_ADDRESS), do: %__MODULE__{identifier: type} + + @impl true + def encode_xdr(%__MODULE__{identifier: type}) do + @declarations + |> XDR.Enum.new(type) + |> XDR.Enum.encode_xdr() + end + + @impl true + def encode_xdr!(%__MODULE__{identifier: type}) do + @declarations + |> XDR.Enum.new(type) + |> XDR.Enum.encode_xdr!() + end + + @impl true + def decode_xdr(bytes, spec \\ @enum_spec) + + def decode_xdr(bytes, spec) do + case XDR.Enum.decode_xdr(bytes, spec) do + {:ok, {%XDR.Enum{identifier: type}, rest}} -> {:ok, {new(type), rest}} + error -> error + end + end + + @impl true + def decode_xdr!(bytes, spec \\ @enum_spec) + + def decode_xdr!(bytes, spec) do + {%XDR.Enum{identifier: type}, rest} = XDR.Enum.decode_xdr!(bytes, spec) + {new(type), rest} + end +end diff --git a/lib/xdr/transactions/contract_id_public_key_type.ex b/lib/xdr/transactions/contract_id_public_key_type.ex deleted file mode 100644 index 7dec9b39..00000000 --- a/lib/xdr/transactions/contract_id_public_key_type.ex +++ /dev/null @@ -1,53 +0,0 @@ -defmodule StellarBase.XDR.ContractIDPublicKeyType do - @moduledoc """ - Representation of Stellar `ContractIDPublicKeyType` type. - """ - - @behaviour XDR.Declaration - - @declarations [ - CONTRACT_ID_PUBLIC_KEY_SOURCE_ACCOUNT: 0, - CONTRACT_ID_PUBLIC_KEY_ED25519: 1 - ] - - @enum_spec %XDR.Enum{declarations: @declarations, identifier: nil} - - @type t :: %__MODULE__{identifier: atom()} - - defstruct [:identifier] - - @spec new(type :: atom()) :: t() - def new(type \\ :CONTRACT_ID_PUBLIC_KEY_SOURCE_ACCOUNT), do: %__MODULE__{identifier: type} - - @impl true - def encode_xdr(%__MODULE__{identifier: type}) do - @declarations - |> XDR.Enum.new(type) - |> XDR.Enum.encode_xdr() - end - - @impl true - def encode_xdr!(%__MODULE__{identifier: type}) do - @declarations - |> XDR.Enum.new(type) - |> XDR.Enum.encode_xdr!() - end - - @impl true - def decode_xdr(bytes, spec \\ @enum_spec) - - def decode_xdr(bytes, spec) do - case XDR.Enum.decode_xdr(bytes, spec) do - {:ok, {%XDR.Enum{identifier: type}, rest}} -> {:ok, {new(type), rest}} - error -> error - end - end - - @impl true - def decode_xdr!(bytes, spec \\ @enum_spec) - - def decode_xdr!(bytes, spec) do - {%XDR.Enum{identifier: type}, rest} = XDR.Enum.decode_xdr!(bytes, spec) - {new(type), rest} - end -end diff --git a/lib/xdr/transactions/contract_id_type.ex b/lib/xdr/transactions/contract_id_type.ex deleted file mode 100644 index 29cb1319..00000000 --- a/lib/xdr/transactions/contract_id_type.ex +++ /dev/null @@ -1,54 +0,0 @@ -defmodule StellarBase.XDR.ContractIDType do - @moduledoc """ - Representation of Stellar `ContractIDType` type. - """ - - @behaviour XDR.Declaration - - @declarations [ - CONTRACT_ID_FROM_SOURCE_ACCOUNT: 0, - CONTRACT_ID_FROM_ED25519_PUBLIC_KEY: 1, - CONTRACT_ID_FROM_ASSET: 2 - ] - - @enum_spec %XDR.Enum{declarations: @declarations, identifier: nil} - - @type t :: %__MODULE__{identifier: atom()} - - defstruct [:identifier] - - @spec new(type :: atom()) :: t() - def new(type \\ :CONTRACT_ID_FROM_SOURCE_ACCOUNT), do: %__MODULE__{identifier: type} - - @impl true - def encode_xdr(%__MODULE__{identifier: type}) do - @declarations - |> XDR.Enum.new(type) - |> XDR.Enum.encode_xdr() - end - - @impl true - def encode_xdr!(%__MODULE__{identifier: type}) do - @declarations - |> XDR.Enum.new(type) - |> XDR.Enum.encode_xdr!() - end - - @impl true - def decode_xdr(bytes, spec \\ @enum_spec) - - def decode_xdr(bytes, spec) do - case XDR.Enum.decode_xdr(bytes, spec) do - {:ok, {%XDR.Enum{identifier: type}, rest}} -> {:ok, {new(type), rest}} - error -> error - end - end - - @impl true - def decode_xdr!(bytes, spec \\ @enum_spec) - - def decode_xdr!(bytes, spec) do - {%XDR.Enum{identifier: type}, rest} = XDR.Enum.decode_xdr!(bytes, spec) - {new(type), rest} - end -end diff --git a/lib/xdr/transactions/create_contract_args.ex b/lib/xdr/transactions/create_contract_args.ex index 8df0f3e3..5c40df2c 100644 --- a/lib/xdr/transactions/create_contract_args.ex +++ b/lib/xdr/transactions/create_contract_args.ex @@ -11,39 +11,43 @@ defmodule StellarBase.XDR.CreateContractArgs do @behaviour XDR.Declaration alias StellarBase.XDR.{ - ContractID, - SCContractExecutable + ContractIDPreimage, + ContractExecutable } @struct_spec XDR.Struct.new( - contract_id: ContractID, - executable: SCContractExecutable + contract_id_preimage: ContractIDPreimage, + executable: ContractExecutable ) - @type contract_id_type :: ContractID.t() - @type executable_type :: SCContractExecutable.t() + @type contract_id_preimage_type :: ContractIDPreimage.t() + @type executable_type :: ContractExecutable.t() - @type t :: %__MODULE__{contract_id: contract_id_type(), executable: executable_type()} + @type t :: %__MODULE__{ + contract_id_preimage: contract_id_preimage_type(), + executable: executable_type() + } - defstruct [:contract_id, :executable] + defstruct [:contract_id_preimage, :executable] - @spec new(contract_id :: contract_id_type(), executable :: executable_type()) :: t() + @spec new(contract_id_preimage :: contract_id_preimage_type(), executable :: executable_type()) :: + t() def new( - %ContractID{} = contract_id, - %SCContractExecutable{} = executable + %ContractIDPreimage{} = contract_id_preimage, + %ContractExecutable{} = executable ), - do: %__MODULE__{contract_id: contract_id, executable: executable} + do: %__MODULE__{contract_id_preimage: contract_id_preimage, executable: executable} @impl true - def encode_xdr(%__MODULE__{contract_id: contract_id, executable: executable}) do - [contract_id: contract_id, executable: executable] + def encode_xdr(%__MODULE__{contract_id_preimage: contract_id_preimage, executable: executable}) do + [contract_id_preimage: contract_id_preimage, executable: executable] |> XDR.Struct.new() |> XDR.Struct.encode_xdr() end @impl true - def encode_xdr!(%__MODULE__{contract_id: contract_id, executable: executable}) do - [contract_id: contract_id, executable: executable] + def encode_xdr!(%__MODULE__{contract_id_preimage: contract_id_preimage, executable: executable}) do + [contract_id_preimage: contract_id_preimage, executable: executable] |> XDR.Struct.new() |> XDR.Struct.encode_xdr!() end @@ -53,8 +57,11 @@ defmodule StellarBase.XDR.CreateContractArgs do def decode_xdr(bytes, struct) do case XDR.Struct.decode_xdr(bytes, struct) do - {:ok, {%XDR.Struct{components: [contract_id: contract_id, executable: executable]}, rest}} -> - {:ok, {new(contract_id, executable), rest}} + {:ok, + {%XDR.Struct{ + components: [contract_id_preimage: contract_id_preimage, executable: executable] + }, rest}} -> + {:ok, {new(contract_id_preimage, executable), rest}} error -> error @@ -65,9 +72,10 @@ defmodule StellarBase.XDR.CreateContractArgs do def decode_xdr!(bytes, struct \\ @struct_spec) def decode_xdr!(bytes, struct) do - {%XDR.Struct{components: [contract_id: contract_id, executable: executable]}, rest} = - XDR.Struct.decode_xdr!(bytes, struct) + {%XDR.Struct{ + components: [contract_id_preimage: contract_id_preimage, executable: executable] + }, rest} = XDR.Struct.decode_xdr!(bytes, struct) - {new(contract_id, executable), rest} + {new(contract_id_preimage, executable), rest} end end diff --git a/lib/xdr/transactions/from_ed25519_public_key.ex b/lib/xdr/transactions/from_ed25519_public_key.ex deleted file mode 100644 index eade71eb..00000000 --- a/lib/xdr/transactions/from_ed25519_public_key.ex +++ /dev/null @@ -1,91 +0,0 @@ -defmodule StellarBase.XDR.FromEd25519PublicKey do - @moduledoc """ - Representation of Stellar `FromEd25519PublicKey` type. - """ - alias StellarBase.XDR.{Signature, UInt256} - - @behaviour XDR.Declaration - - @struct_spec XDR.Struct.new( - key: UInt256, - signature: Signature, - salt: UInt256 - ) - - @type t :: %__MODULE__{ - key: UInt256.t(), - signature: Signature.t(), - salt: UInt256.t() - } - - defstruct [:key, :signature, :salt] - - @spec new( - key :: UInt256.t(), - signature :: Signature.t(), - salt :: UInt256.t() - ) :: t() - def new(%UInt256{} = key, %Signature{} = signature, %UInt256{} = salt), - do: %__MODULE__{ - key: key, - signature: signature, - salt: salt - } - - @impl true - def encode_xdr(%__MODULE__{ - key: key, - signature: signature, - salt: salt - }) do - [key: key, signature: signature, salt: salt] - |> XDR.Struct.new() - |> XDR.Struct.encode_xdr() - end - - @impl true - def encode_xdr!(%__MODULE__{ - key: key, - signature: signature, - salt: salt - }) do - [key: key, signature: signature, salt: salt] - |> XDR.Struct.new() - |> XDR.Struct.encode_xdr!() - end - - @impl true - def decode_xdr(bytes, struct \\ @struct_spec) - - def decode_xdr(bytes, struct) do - case XDR.Struct.decode_xdr(bytes, struct) do - {:ok, - {%XDR.Struct{ - components: [ - key: key, - signature: signature, - salt: salt - ] - }, rest}} -> - {:ok, {new(key, signature, salt), rest}} - - error -> - error - end - end - - @impl true - def decode_xdr!(bytes, struct \\ @struct_spec) - - def decode_xdr!(bytes, struct) do - {%XDR.Struct{ - components: [ - key: key, - signature: signature, - salt: salt - ] - }, rest} = XDR.Struct.decode_xdr!(bytes, struct) - - {new(key, signature, salt), rest} - end -end diff --git a/lib/xdr/transactions/hash_id_preimage.ex b/lib/xdr/transactions/hash_id_preimage.ex index 90f1e401..d06ef221 100644 --- a/lib/xdr/transactions/hash_id_preimage.ex +++ b/lib/xdr/transactions/hash_id_preimage.ex @@ -1,60 +1,54 @@ defmodule StellarBase.XDR.HashIDPreimage do @moduledoc """ + Automatically generated by xdrgen + DO NOT EDIT or your changes may be overwritten + + Target implementation: elixir_xdr at https://hex.pm/packages/elixir_xdr + Representation of Stellar `HashIDPreimage` type. """ + + @behaviour XDR.Declaration + alias StellarBase.XDR.{ EnvelopeType, - OperationID, - RevokeID, - Ed25519ContractID, - StructContractID, - FromAsset, - SourceAccountContractID, - HashIDPreimageCreateContractArgs, - HashIDPreimageContractAuth + HashIDPreimageOperationID, + HashIDPreimageRevokeID, + HashIDPreimageContractID, + HashIDPreimageSorobanAuthorization } - @behaviour XDR.Declaration - @arms [ - ENVELOPE_TYPE_OP_ID: OperationID, - ENVELOPE_TYPE_POOL_REVOKE_OP_ID: RevokeID, - ENVELOPE_TYPE_CONTRACT_ID_FROM_ED25519: Ed25519ContractID, - ENVELOPE_TYPE_CONTRACT_ID_FROM_CONTRACT: StructContractID, - ENVELOPE_TYPE_CONTRACT_ID_FROM_ASSET: FromAsset, - ENVELOPE_TYPE_CONTRACT_ID_FROM_SOURCE_ACCOUNT: SourceAccountContractID, - ENVELOPE_TYPE_CREATE_CONTRACT_ARGS: HashIDPreimageCreateContractArgs, - ENVELOPE_TYPE_CONTRACT_AUTH: HashIDPreimageContractAuth + ENVELOPE_TYPE_OP_ID: HashIDPreimageOperationID, + ENVELOPE_TYPE_POOL_REVOKE_OP_ID: HashIDPreimageRevokeID, + ENVELOPE_TYPE_CONTRACT_ID: HashIDPreimageContractID, + ENVELOPE_TYPE_SOROBAN_AUTHORIZATION: HashIDPreimageSorobanAuthorization ] - @type hash_id :: - OperationID.t() - | RevokeID.t() - | Ed25519ContractID.t() - | StructContractID.t() - | FromAsset.t() - | SourceAccountContractID.t() - | HashIDPreimageCreateContractArgs.t() - | HashIDPreimageContractAuth.t() + @type value :: + HashIDPreimageOperationID.t() + | HashIDPreimageRevokeID.t() + | HashIDPreimageContractID.t() + | HashIDPreimageSorobanAuthorization.t() - @type t :: %__MODULE__{hash_id: hash_id(), type: EnvelopeType.t()} + @type t :: %__MODULE__{value: value(), type: EnvelopeType.t()} - defstruct [:hash_id, :type] + defstruct [:value, :type] - @spec new(hash_id :: hash_id(), type :: EnvelopeType.t()) :: t() - def new(hash_id, %EnvelopeType{} = type), do: %__MODULE__{hash_id: hash_id, type: type} + @spec new(value :: value(), type :: EnvelopeType.t()) :: t() + def new(value, %EnvelopeType{} = type), do: %__MODULE__{value: value, type: type} @impl true - def encode_xdr(%__MODULE__{hash_id: hash_id, type: type}) do + def encode_xdr(%__MODULE__{value: value, type: type}) do type - |> XDR.Union.new(@arms, hash_id) + |> XDR.Union.new(@arms, value) |> XDR.Union.encode_xdr() end @impl true - def encode_xdr!(%__MODULE__{hash_id: hash_id, type: type}) do + def encode_xdr!(%__MODULE__{value: value, type: type}) do type - |> XDR.Union.new(@arms, hash_id) + |> XDR.Union.new(@arms, value) |> XDR.Union.encode_xdr!() end @@ -63,7 +57,7 @@ defmodule StellarBase.XDR.HashIDPreimage do def decode_xdr(bytes, spec) do case XDR.Union.decode_xdr(bytes, spec) do - {:ok, {{type, hash_id}, rest}} -> {:ok, {new(hash_id, type), rest}} + {:ok, {{type, value}, rest}} -> {:ok, {new(value, type), rest}} error -> error end end @@ -72,8 +66,8 @@ defmodule StellarBase.XDR.HashIDPreimage do def decode_xdr!(bytes, spec \\ union_spec()) def decode_xdr!(bytes, spec) do - {{type, hash_id}, rest} = XDR.Union.decode_xdr!(bytes, spec) - {new(hash_id, type), rest} + {{type, value}, rest} = XDR.Union.decode_xdr!(bytes, spec) + {new(value, type), rest} end @spec union_spec() :: XDR.Union.t() diff --git a/lib/xdr/transactions/hash_id_preimage_contract_auth.ex b/lib/xdr/transactions/hash_id_preimage_contract_auth.ex deleted file mode 100644 index 20630aa0..00000000 --- a/lib/xdr/transactions/hash_id_preimage_contract_auth.ex +++ /dev/null @@ -1,75 +0,0 @@ -defmodule StellarBase.XDR.HashIDPreimageContractAuth do - @moduledoc """ - Representation of Stellar `HashIDPreimageContractAuth` type. - """ - alias StellarBase.XDR.{Hash, UInt64, AuthorizedInvocation} - - @behaviour XDR.Declaration - - @struct_spec XDR.Struct.new(network_id: Hash, nonce: UInt64, invocation: AuthorizedInvocation) - - @type t :: %__MODULE__{ - network_id: Hash.t(), - nonce: UInt64.t(), - invocation: AuthorizedInvocation.t() - } - - defstruct [:network_id, :nonce, :invocation] - - @spec new( - network_id :: Hash.t(), - nonce :: UInt64.t(), - invocation :: AuthorizedInvocation.t() - ) :: t() - def new(%Hash{} = network_id, %UInt64{} = nonce, %AuthorizedInvocation{} = invocation), - do: %__MODULE__{network_id: network_id, nonce: nonce, invocation: invocation} - - @impl true - def encode_xdr(%__MODULE__{network_id: network_id, nonce: nonce, invocation: invocation}) do - [network_id: network_id, nonce: nonce, invocation: invocation] - |> XDR.Struct.new() - |> XDR.Struct.encode_xdr() - end - - @impl true - def encode_xdr!(%__MODULE__{network_id: network_id, nonce: nonce, invocation: invocation}) do - [network_id: network_id, nonce: nonce, invocation: invocation] - |> XDR.Struct.new() - |> XDR.Struct.encode_xdr!() - end - - @impl true - def decode_xdr(bytes, struct \\ @struct_spec) - - def decode_xdr(bytes, struct) do - case XDR.Struct.decode_xdr(bytes, struct) do - {:ok, - {%XDR.Struct{ - components: [ - network_id: network_id, - nonce: nonce, - invocation: invocation - ] - }, rest}} -> - {:ok, {new(network_id, nonce, invocation), rest}} - - error -> - error - end - end - - @impl true - def decode_xdr!(bytes, struct \\ @struct_spec) - - def decode_xdr!(bytes, struct) do - {%XDR.Struct{ - components: [ - network_id: network_id, - nonce: nonce, - invocation: invocation - ] - }, rest} = XDR.Struct.decode_xdr!(bytes, struct) - - {new(network_id, nonce, invocation), rest} - end -end diff --git a/lib/xdr/transactions/hash_id_preimage_contract_id.ex b/lib/xdr/transactions/hash_id_preimage_contract_id.ex new file mode 100644 index 00000000..bda3ae8a --- /dev/null +++ b/lib/xdr/transactions/hash_id_preimage_contract_id.ex @@ -0,0 +1,81 @@ +defmodule StellarBase.XDR.HashIDPreimageContractID do + @moduledoc """ + Automatically generated by xdrgen + DO NOT EDIT or your changes may be overwritten + + Target implementation: elixir_xdr at https://hex.pm/packages/elixir_xdr + + Representation of Stellar `HashIDPreimageContractID` type. + """ + + @behaviour XDR.Declaration + + alias StellarBase.XDR.{ + Hash, + ContractIDPreimage + } + + @struct_spec XDR.Struct.new( + network_id: Hash, + contract_id_preimage: ContractIDPreimage + ) + + @type network_id_type :: Hash.t() + @type contract_id_preimage_type :: ContractIDPreimage.t() + + @type t :: %__MODULE__{ + network_id: network_id_type(), + contract_id_preimage: contract_id_preimage_type() + } + + defstruct [:network_id, :contract_id_preimage] + + @spec new(network_id :: network_id_type(), contract_id_preimage :: contract_id_preimage_type()) :: + t() + def new( + %Hash{} = network_id, + %ContractIDPreimage{} = contract_id_preimage + ), + do: %__MODULE__{network_id: network_id, contract_id_preimage: contract_id_preimage} + + @impl true + def encode_xdr(%__MODULE__{network_id: network_id, contract_id_preimage: contract_id_preimage}) do + [network_id: network_id, contract_id_preimage: contract_id_preimage] + |> XDR.Struct.new() + |> XDR.Struct.encode_xdr() + end + + @impl true + def encode_xdr!(%__MODULE__{network_id: network_id, contract_id_preimage: contract_id_preimage}) do + [network_id: network_id, contract_id_preimage: contract_id_preimage] + |> XDR.Struct.new() + |> XDR.Struct.encode_xdr!() + end + + @impl true + def decode_xdr(bytes, struct \\ @struct_spec) + + def decode_xdr(bytes, struct) do + case XDR.Struct.decode_xdr(bytes, struct) do + {:ok, + {%XDR.Struct{ + components: [network_id: network_id, contract_id_preimage: contract_id_preimage] + }, rest}} -> + {:ok, {new(network_id, contract_id_preimage), rest}} + + error -> + error + end + end + + @impl true + def decode_xdr!(bytes, struct \\ @struct_spec) + + def decode_xdr!(bytes, struct) do + {%XDR.Struct{ + components: [network_id: network_id, contract_id_preimage: contract_id_preimage] + }, rest} = XDR.Struct.decode_xdr!(bytes, struct) + + {new(network_id, contract_id_preimage), rest} + end +end diff --git a/lib/xdr/transactions/hash_id_preimage_create_contract_args.ex b/lib/xdr/transactions/hash_id_preimage_create_contract_args.ex deleted file mode 100644 index 3cd22313..00000000 --- a/lib/xdr/transactions/hash_id_preimage_create_contract_args.ex +++ /dev/null @@ -1,84 +0,0 @@ -defmodule StellarBase.XDR.HashIDPreimageCreateContractArgs do - @moduledoc """ - Automatically generated by xdrgen - DO NOT EDIT or your changes may be overwritten - - Target implementation: elixir_xdr at https://hex.pm/packages/elixir_xdr - - Representation of Stellar `HashIDPreimageCreateContractArgs` type. - """ - - @behaviour XDR.Declaration - - alias StellarBase.XDR.{ - Hash, - SCContractExecutable, - UInt256 - } - - @struct_spec XDR.Struct.new( - network_id: Hash, - executable: SCContractExecutable, - salt: UInt256 - ) - - @type network_id_type :: Hash.t() - @type executable_type :: SCContractExecutable.t() - @type salt_type :: UInt256.t() - - @type t :: %__MODULE__{ - network_id: network_id_type(), - executable: executable_type(), - salt: salt_type() - } - - defstruct [:network_id, :executable, :salt] - - @spec new(network_id :: network_id_type(), executable :: executable_type(), salt :: salt_type()) :: - t() - def new( - %Hash{} = network_id, - %SCContractExecutable{} = executable, - %UInt256{} = salt - ), - do: %__MODULE__{network_id: network_id, executable: executable, salt: salt} - - @impl true - def encode_xdr(%__MODULE__{network_id: network_id, executable: executable, salt: salt}) do - [network_id: network_id, executable: executable, salt: salt] - |> XDR.Struct.new() - |> XDR.Struct.encode_xdr() - end - - @impl true - def encode_xdr!(%__MODULE__{network_id: network_id, executable: executable, salt: salt}) do - [network_id: network_id, executable: executable, salt: salt] - |> XDR.Struct.new() - |> XDR.Struct.encode_xdr!() - end - - @impl true - def decode_xdr(bytes, struct \\ @struct_spec) - - def decode_xdr(bytes, struct) do - case XDR.Struct.decode_xdr(bytes, struct) do - {:ok, - {%XDR.Struct{components: [network_id: network_id, executable: executable, salt: salt]}, - rest}} -> - {:ok, {new(network_id, executable, salt), rest}} - - error -> - error - end - end - - @impl true - def decode_xdr!(bytes, struct \\ @struct_spec) - - def decode_xdr!(bytes, struct) do - {%XDR.Struct{components: [network_id: network_id, executable: executable, salt: salt]}, rest} = - XDR.Struct.decode_xdr!(bytes, struct) - - {new(network_id, executable, salt), rest} - end -end diff --git a/lib/xdr/transactions/hash_id_preimage_soroban_authorization.ex b/lib/xdr/transactions/hash_id_preimage_soroban_authorization.ex new file mode 100644 index 00000000..3a85379e --- /dev/null +++ b/lib/xdr/transactions/hash_id_preimage_soroban_authorization.ex @@ -0,0 +1,130 @@ +defmodule StellarBase.XDR.HashIDPreimageSorobanAuthorization do + @moduledoc """ + Automatically generated by xdrgen + DO NOT EDIT or your changes may be overwritten + + Target implementation: elixir_xdr at https://hex.pm/packages/elixir_xdr + + Representation of Stellar `HashIDPreimageSorobanAuthorization` type. + """ + + @behaviour XDR.Declaration + + alias StellarBase.XDR.{ + Hash, + Int64, + UInt32, + SorobanAuthorizedInvocation + } + + @struct_spec XDR.Struct.new( + network_id: Hash, + nonce: Int64, + signature_expiration_ledger: UInt32, + invocation: SorobanAuthorizedInvocation + ) + + @type network_id_type :: Hash.t() + @type nonce_type :: Int64.t() + @type signature_expiration_ledger_type :: UInt32.t() + @type invocation_type :: SorobanAuthorizedInvocation.t() + + @type t :: %__MODULE__{ + network_id: network_id_type(), + nonce: nonce_type(), + signature_expiration_ledger: signature_expiration_ledger_type(), + invocation: invocation_type() + } + + defstruct [:network_id, :nonce, :signature_expiration_ledger, :invocation] + + @spec new( + network_id :: network_id_type(), + nonce :: nonce_type(), + signature_expiration_ledger :: signature_expiration_ledger_type(), + invocation :: invocation_type() + ) :: t() + def new( + %Hash{} = network_id, + %Int64{} = nonce, + %UInt32{} = signature_expiration_ledger, + %SorobanAuthorizedInvocation{} = invocation + ), + do: %__MODULE__{ + network_id: network_id, + nonce: nonce, + signature_expiration_ledger: signature_expiration_ledger, + invocation: invocation + } + + @impl true + def encode_xdr(%__MODULE__{ + network_id: network_id, + nonce: nonce, + signature_expiration_ledger: signature_expiration_ledger, + invocation: invocation + }) do + [ + network_id: network_id, + nonce: nonce, + signature_expiration_ledger: signature_expiration_ledger, + invocation: invocation + ] + |> XDR.Struct.new() + |> XDR.Struct.encode_xdr() + end + + @impl true + def encode_xdr!(%__MODULE__{ + network_id: network_id, + nonce: nonce, + signature_expiration_ledger: signature_expiration_ledger, + invocation: invocation + }) do + [ + network_id: network_id, + nonce: nonce, + signature_expiration_ledger: signature_expiration_ledger, + invocation: invocation + ] + |> XDR.Struct.new() + |> XDR.Struct.encode_xdr!() + end + + @impl true + def decode_xdr(bytes, struct \\ @struct_spec) + + def decode_xdr(bytes, struct) do + case XDR.Struct.decode_xdr(bytes, struct) do + {:ok, + {%XDR.Struct{ + components: [ + network_id: network_id, + nonce: nonce, + signature_expiration_ledger: signature_expiration_ledger, + invocation: invocation + ] + }, rest}} -> + {:ok, {new(network_id, nonce, signature_expiration_ledger, invocation), rest}} + + error -> + error + end + end + + @impl true + def decode_xdr!(bytes, struct \\ @struct_spec) + + def decode_xdr!(bytes, struct) do + {%XDR.Struct{ + components: [ + network_id: network_id, + nonce: nonce, + signature_expiration_ledger: signature_expiration_ledger, + invocation: invocation + ] + }, rest} = XDR.Struct.decode_xdr!(bytes, struct) + + {new(network_id, nonce, signature_expiration_ledger, invocation), rest} + end +end diff --git a/lib/xdr/transactions/host_function.ex b/lib/xdr/transactions/host_function.ex index 1f71ef87..539a9b2f 100644 --- a/lib/xdr/transactions/host_function.ex +++ b/lib/xdr/transactions/host_function.ex @@ -11,63 +11,66 @@ defmodule StellarBase.XDR.HostFunction do @behaviour XDR.Declaration alias StellarBase.XDR.{ - HostFunctionArgs, - ContractAuthList + HostFunctionType, + SCVec, + CreateContractArgs, + VariableOpaque } - @struct_spec XDR.Struct.new( - args: HostFunctionArgs, - auth: ContractAuthList - ) + @arms [ + HOST_FUNCTION_TYPE_INVOKE_CONTRACT: SCVec, + HOST_FUNCTION_TYPE_CREATE_CONTRACT: CreateContractArgs, + HOST_FUNCTION_TYPE_UPLOAD_CONTRACT_WASM: VariableOpaque + ] - @type args_type :: HostFunctionArgs.t() - @type auth_type :: ContractAuthList.t() + @type value :: + SCVec.t() + | CreateContractArgs.t() + | VariableOpaque.t() - @type t :: %__MODULE__{args: args_type(), auth: auth_type()} + @type t :: %__MODULE__{value: value(), type: HostFunctionType.t()} - defstruct [:args, :auth] + defstruct [:value, :type] - @spec new(args :: args_type(), auth :: auth_type()) :: t() - def new( - %HostFunctionArgs{} = args, - %ContractAuthList{} = auth - ), - do: %__MODULE__{args: args, auth: auth} + @spec new(value :: value(), type :: HostFunctionType.t()) :: t() + def new(value, %HostFunctionType{} = type), do: %__MODULE__{value: value, type: type} @impl true - def encode_xdr(%__MODULE__{args: args, auth: auth}) do - [args: args, auth: auth] - |> XDR.Struct.new() - |> XDR.Struct.encode_xdr() + def encode_xdr(%__MODULE__{value: value, type: type}) do + type + |> XDR.Union.new(@arms, value) + |> XDR.Union.encode_xdr() end @impl true - def encode_xdr!(%__MODULE__{args: args, auth: auth}) do - [args: args, auth: auth] - |> XDR.Struct.new() - |> XDR.Struct.encode_xdr!() + def encode_xdr!(%__MODULE__{value: value, type: type}) do + type + |> XDR.Union.new(@arms, value) + |> XDR.Union.encode_xdr!() end @impl true - def decode_xdr(bytes, struct \\ @struct_spec) + def decode_xdr(bytes, spec \\ union_spec()) - def decode_xdr(bytes, struct) do - case XDR.Struct.decode_xdr(bytes, struct) do - {:ok, {%XDR.Struct{components: [args: args, auth: auth]}, rest}} -> - {:ok, {new(args, auth), rest}} - - error -> - error + def decode_xdr(bytes, spec) do + case XDR.Union.decode_xdr(bytes, spec) do + {:ok, {{type, value}, rest}} -> {:ok, {new(value, type), rest}} + error -> error end end @impl true - def decode_xdr!(bytes, struct \\ @struct_spec) + def decode_xdr!(bytes, spec \\ union_spec()) - def decode_xdr!(bytes, struct) do - {%XDR.Struct{components: [args: args, auth: auth]}, rest} = - XDR.Struct.decode_xdr!(bytes, struct) + def decode_xdr!(bytes, spec) do + {{type, value}, rest} = XDR.Union.decode_xdr!(bytes, spec) + {new(value, type), rest} + end - {new(args, auth), rest} + @spec union_spec() :: XDR.Union.t() + defp union_spec do + nil + |> HostFunctionType.new() + |> XDR.Union.new(@arms) end end diff --git a/lib/xdr/transactions/invoke_host_function_result.ex b/lib/xdr/transactions/invoke_host_function_result.ex index e3ee1c0b..181cb8b9 100644 --- a/lib/xdr/transactions/invoke_host_function_result.ex +++ b/lib/xdr/transactions/invoke_host_function_result.ex @@ -12,19 +12,19 @@ defmodule StellarBase.XDR.InvokeHostFunctionResult do alias StellarBase.XDR.{ InvokeHostFunctionResultCode, - SCValList100, + Hash, Void } @arms [ - INVOKE_HOST_FUNCTION_SUCCESS: SCValList100, + INVOKE_HOST_FUNCTION_SUCCESS: Hash, INVOKE_HOST_FUNCTION_MALFORMED: Void, INVOKE_HOST_FUNCTION_TRAPPED: Void, INVOKE_HOST_FUNCTION_RESOURCE_LIMIT_EXCEEDED: Void ] @type value :: - SCValList100.t() + Hash.t() | Void.t() @type t :: %__MODULE__{value: value(), type: InvokeHostFunctionResultCode.t()} diff --git a/lib/xdr/transactions/operation_body.ex b/lib/xdr/transactions/operation_body.ex index e2b48e2d..0b320e00 100644 --- a/lib/xdr/transactions/operation_body.ex +++ b/lib/xdr/transactions/operation_body.ex @@ -1,38 +1,48 @@ defmodule StellarBase.XDR.OperationBody do @moduledoc """ + Automatically generated by xdrgen + DO NOT EDIT or your changes may be overwritten + + Target implementation: elixir_xdr at https://hex.pm/packages/elixir_xdr + Representation of Stellar `OperationBody` type. """ - alias StellarBase.XDR.{OperationType, Void} + + @behaviour XDR.Declaration + + alias StellarBase.XDR.{ + OperationType, + MuxedAccount, + Void + } alias StellarBase.XDR.Operations.{ - CreateAccount, - ManageSellOffer, - Payment, - PathPaymentStrictReceive, - PathPaymentStrictSend, - CreateClaimableBalance, - ManageSellOffer, - ManageBuyOffer, - CreatePassiveSellOffer, - SetOptions, - ChangeTrust, AllowTrust, - AccountMerge, - ManageData, - BumpSequence, - ClaimClaimableBalance, BeginSponsoringFutureReserves, - RevokeSponsorship, + BumpFootprintExpiration, + BumpSequence, + ChangeTrust, Clawback, ClawbackClaimableBalance, - SetTrustLineFlags, + ClaimClaimableBalance, + CreateClaimableBalance, + CreateAccount, + CreatePassiveSellOffer, + InvokeHostFunction, LiquidityPoolDeposit, LiquidityPoolWithdraw, - InvokeHostFunction + ManageData, + ManageBuyOffer, + ManageSellOffer, + Payment, + PathPaymentStrictReceive, + PathPaymentStrictSend, + RestoreFootprint, + RevokeSponsorship, + SetOptions, + SetTrustLineFlags } - @behaviour XDR.Declaration - @arms [ CREATE_ACCOUNT: CreateAccount, PAYMENT: Payment, @@ -42,7 +52,7 @@ defmodule StellarBase.XDR.OperationBody do SET_OPTIONS: SetOptions, CHANGE_TRUST: ChangeTrust, ALLOW_TRUST: AllowTrust, - ACCOUNT_MERGE: AccountMerge, + ACCOUNT_MERGE: MuxedAccount, INFLATION: Void, MANAGE_DATA: ManageData, BUMP_SEQUENCE: BumpSequence, @@ -58,29 +68,57 @@ defmodule StellarBase.XDR.OperationBody do SET_TRUST_LINE_FLAGS: SetTrustLineFlags, LIQUIDITY_POOL_DEPOSIT: LiquidityPoolDeposit, LIQUIDITY_POOL_WITHDRAW: LiquidityPoolWithdraw, - INVOKE_HOST_FUNCTION: InvokeHostFunction + INVOKE_HOST_FUNCTION: InvokeHostFunction, + BUMP_FOOTPRINT_EXPIRATION: BumpFootprintExpiration, + RESTORE_FOOTPRINT: RestoreFootprint ] - @type operation :: any() + @type value :: + CreateAccount.t() + | Payment.t() + | PathPaymentStrictReceive.t() + | ManageSellOffer.t() + | CreatePassiveSellOffer.t() + | SetOptions.t() + | ChangeTrust.t() + | AllowTrust.t() + | MuxedAccount.t() + | Void.t() + | ManageData.t() + | BumpSequence.t() + | ManageBuyOffer.t() + | PathPaymentStrictSend.t() + | CreateClaimableBalance.t() + | ClaimClaimableBalance.t() + | BeginSponsoringFutureReserves.t() + | RevokeSponsorship.t() + | Clawback.t() + | ClawbackClaimableBalance.t() + | SetTrustLineFlags.t() + | LiquidityPoolDeposit.t() + | LiquidityPoolWithdraw.t() + | InvokeHostFunction.t() + | BumpFootprintExpiration.t() + | RestoreFootprint.t() - @type t :: %__MODULE__{operation: operation(), type: OperationType.t()} + @type t :: %__MODULE__{value: value(), type: OperationType.t()} - defstruct [:operation, :type] + defstruct [:value, :type] - @spec new(operation :: operation(), type :: OperationType.t()) :: t() - def new(operation, %OperationType{} = type), do: %__MODULE__{operation: operation, type: type} + @spec new(value :: value(), type :: OperationType.t()) :: t() + def new(value, %OperationType{} = type), do: %__MODULE__{value: value, type: type} @impl true - def encode_xdr(%__MODULE__{operation: operation, type: type}) do + def encode_xdr(%__MODULE__{value: value, type: type}) do type - |> XDR.Union.new(@arms, operation) + |> XDR.Union.new(@arms, value) |> XDR.Union.encode_xdr() end @impl true - def encode_xdr!(%__MODULE__{operation: operation, type: type}) do + def encode_xdr!(%__MODULE__{value: value, type: type}) do type - |> XDR.Union.new(@arms, operation) + |> XDR.Union.new(@arms, value) |> XDR.Union.encode_xdr!() end @@ -89,7 +127,7 @@ defmodule StellarBase.XDR.OperationBody do def decode_xdr(bytes, spec) do case XDR.Union.decode_xdr(bytes, spec) do - {:ok, {{type, key}, rest}} -> {:ok, {new(key, type), rest}} + {:ok, {{type, value}, rest}} -> {:ok, {new(value, type), rest}} error -> error end end @@ -98,8 +136,8 @@ defmodule StellarBase.XDR.OperationBody do def decode_xdr!(bytes, spec \\ union_spec()) def decode_xdr!(bytes, spec) do - {{type, key}, rest} = XDR.Union.decode_xdr!(bytes, spec) - {new(key, type), rest} + {{type, value}, rest} = XDR.Union.decode_xdr!(bytes, spec) + {new(value, type), rest} end @spec union_spec() :: XDR.Union.t() diff --git a/lib/xdr/transactions/operation_type.ex b/lib/xdr/transactions/operation_type.ex index b233f652..50e0e8b3 100644 --- a/lib/xdr/transactions/operation_type.ex +++ b/lib/xdr/transactions/operation_type.ex @@ -1,5 +1,10 @@ defmodule StellarBase.XDR.OperationType do @moduledoc """ + Automatically generated by xdrgen + DO NOT EDIT or your changes may be overwritten + + Target implementation: elixir_xdr at https://hex.pm/packages/elixir_xdr + Representation of Stellar `OperationType` type. """ @@ -30,7 +35,9 @@ defmodule StellarBase.XDR.OperationType do SET_TRUST_LINE_FLAGS: 21, LIQUIDITY_POOL_DEPOSIT: 22, LIQUIDITY_POOL_WITHDRAW: 23, - INVOKE_HOST_FUNCTION: 24 + INVOKE_HOST_FUNCTION: 24, + BUMP_FOOTPRINT_EXPIRATION: 25, + RESTORE_FOOTPRINT: 26 ] @enum_spec %XDR.Enum{declarations: @declarations, identifier: nil} @@ -40,7 +47,7 @@ defmodule StellarBase.XDR.OperationType do defstruct [:identifier] @spec new(type :: atom()) :: t() - def new(type), do: %__MODULE__{identifier: type} + def new(type \\ :CREATE_ACCOUNT), do: %__MODULE__{identifier: type} @impl true def encode_xdr(%__MODULE__{identifier: type}) do diff --git a/lib/xdr/transactions/operations/bump_footprint_expiration.ex b/lib/xdr/transactions/operations/bump_footprint_expiration.ex new file mode 100644 index 00000000..53f962fe --- /dev/null +++ b/lib/xdr/transactions/operations/bump_footprint_expiration.ex @@ -0,0 +1,73 @@ +defmodule StellarBase.XDR.Operations.BumpFootprintExpiration do + @moduledoc """ + Automatically generated by xdrgen + DO NOT EDIT or your changes may be overwritten + + Target implementation: elixir_xdr at https://hex.pm/packages/elixir_xdr + + Representation of Stellar `BumpFootprintExpiration` type. + """ + + @behaviour XDR.Declaration + + alias StellarBase.XDR.{ + ExtensionPoint, + UInt32 + } + + @struct_spec XDR.Struct.new( + ext: ExtensionPoint, + ledgers_to_expire: UInt32 + ) + + @type ext_type :: ExtensionPoint.t() + @type ledgers_to_expire_type :: UInt32.t() + + @type t :: %__MODULE__{ext: ext_type(), ledgers_to_expire: ledgers_to_expire_type()} + + defstruct [:ext, :ledgers_to_expire] + + @spec new(ext :: ext_type(), ledgers_to_expire :: ledgers_to_expire_type()) :: t() + def new( + %ExtensionPoint{} = ext, + %UInt32{} = ledgers_to_expire + ), + do: %__MODULE__{ext: ext, ledgers_to_expire: ledgers_to_expire} + + @impl true + def encode_xdr(%__MODULE__{ext: ext, ledgers_to_expire: ledgers_to_expire}) do + [ext: ext, ledgers_to_expire: ledgers_to_expire] + |> XDR.Struct.new() + |> XDR.Struct.encode_xdr() + end + + @impl true + def encode_xdr!(%__MODULE__{ext: ext, ledgers_to_expire: ledgers_to_expire}) do + [ext: ext, ledgers_to_expire: ledgers_to_expire] + |> XDR.Struct.new() + |> XDR.Struct.encode_xdr!() + end + + @impl true + def decode_xdr(bytes, struct \\ @struct_spec) + + def decode_xdr(bytes, struct) do + case XDR.Struct.decode_xdr(bytes, struct) do + {:ok, {%XDR.Struct{components: [ext: ext, ledgers_to_expire: ledgers_to_expire]}, rest}} -> + {:ok, {new(ext, ledgers_to_expire), rest}} + + error -> + error + end + end + + @impl true + def decode_xdr!(bytes, struct \\ @struct_spec) + + def decode_xdr!(bytes, struct) do + {%XDR.Struct{components: [ext: ext, ledgers_to_expire: ledgers_to_expire]}, rest} = + XDR.Struct.decode_xdr!(bytes, struct) + + {new(ext, ledgers_to_expire), rest} + end +end diff --git a/lib/xdr/transactions/operations/bump_footprint_expiration_result.ex b/lib/xdr/transactions/operations/bump_footprint_expiration_result.ex new file mode 100644 index 00000000..fac25344 --- /dev/null +++ b/lib/xdr/transactions/operations/bump_footprint_expiration_result.ex @@ -0,0 +1,73 @@ +defmodule StellarBase.XDR.BumpFootprintExpirationResult do + @moduledoc """ + Automatically generated by xdrgen + DO NOT EDIT or your changes may be overwritten + + Target implementation: elixir_xdr at https://hex.pm/packages/elixir_xdr + + Representation of Stellar `BumpFootprintExpirationResult` type. + """ + + @behaviour XDR.Declaration + + alias StellarBase.XDR.{ + BumpFootprintExpirationResultCode, + Void + } + + @arms [ + BUMP_FOOTPRINT_EXPIRATION_SUCCESS: Void, + BUMP_FOOTPRINT_EXPIRATION_MALFORMED: Void, + BUMP_FOOTPRINT_EXPIRATION_RESOURCE_LIMIT_EXCEEDED: Void + ] + + @type value :: + Void.t() + + @type t :: %__MODULE__{value: value(), type: BumpFootprintExpirationResultCode.t()} + + defstruct [:value, :type] + + @spec new(value :: value(), type :: BumpFootprintExpirationResultCode.t()) :: t() + def new(value, %BumpFootprintExpirationResultCode{} = type), + do: %__MODULE__{value: value, type: type} + + @impl true + def encode_xdr(%__MODULE__{value: value, type: type}) do + type + |> XDR.Union.new(@arms, value) + |> XDR.Union.encode_xdr() + end + + @impl true + def encode_xdr!(%__MODULE__{value: value, type: type}) do + type + |> XDR.Union.new(@arms, value) + |> XDR.Union.encode_xdr!() + end + + @impl true + def decode_xdr(bytes, spec \\ union_spec()) + + def decode_xdr(bytes, spec) do + case XDR.Union.decode_xdr(bytes, spec) do + {:ok, {{type, value}, rest}} -> {:ok, {new(value, type), rest}} + error -> error + end + end + + @impl true + def decode_xdr!(bytes, spec \\ union_spec()) + + def decode_xdr!(bytes, spec) do + {{type, value}, rest} = XDR.Union.decode_xdr!(bytes, spec) + {new(value, type), rest} + end + + @spec union_spec() :: XDR.Union.t() + defp union_spec do + nil + |> BumpFootprintExpirationResultCode.new() + |> XDR.Union.new(@arms) + end +end diff --git a/lib/xdr/transactions/operations/bump_footprint_expiration_result_code.ex b/lib/xdr/transactions/operations/bump_footprint_expiration_result_code.ex new file mode 100644 index 00000000..e29a8d40 --- /dev/null +++ b/lib/xdr/transactions/operations/bump_footprint_expiration_result_code.ex @@ -0,0 +1,59 @@ +defmodule StellarBase.XDR.BumpFootprintExpirationResultCode do + @moduledoc """ + Automatically generated by xdrgen + DO NOT EDIT or your changes may be overwritten + + Target implementation: elixir_xdr at https://hex.pm/packages/elixir_xdr + + Representation of Stellar `BumpFootprintExpirationResultCode` type. + """ + + @behaviour XDR.Declaration + + @declarations [ + BUMP_FOOTPRINT_EXPIRATION_SUCCESS: 0, + BUMP_FOOTPRINT_EXPIRATION_MALFORMED: -1, + BUMP_FOOTPRINT_EXPIRATION_RESOURCE_LIMIT_EXCEEDED: -2 + ] + + @enum_spec %XDR.Enum{declarations: @declarations, identifier: nil} + + @type t :: %__MODULE__{identifier: atom()} + + defstruct [:identifier] + + @spec new(type :: atom()) :: t() + def new(type \\ :BUMP_FOOTPRINT_EXPIRATION_SUCCESS), do: %__MODULE__{identifier: type} + + @impl true + def encode_xdr(%__MODULE__{identifier: type}) do + @declarations + |> XDR.Enum.new(type) + |> XDR.Enum.encode_xdr() + end + + @impl true + def encode_xdr!(%__MODULE__{identifier: type}) do + @declarations + |> XDR.Enum.new(type) + |> XDR.Enum.encode_xdr!() + end + + @impl true + def decode_xdr(bytes, spec \\ @enum_spec) + + def decode_xdr(bytes, spec) do + case XDR.Enum.decode_xdr(bytes, spec) do + {:ok, {%XDR.Enum{identifier: type}, rest}} -> {:ok, {new(type), rest}} + error -> error + end + end + + @impl true + def decode_xdr!(bytes, spec \\ @enum_spec) + + def decode_xdr!(bytes, spec) do + {%XDR.Enum{identifier: type}, rest} = XDR.Enum.decode_xdr!(bytes, spec) + {new(type), rest} + end +end diff --git a/lib/xdr/transactions/operations/hash_id_preimage_operation_id.ex b/lib/xdr/transactions/operations/hash_id_preimage_operation_id.ex new file mode 100644 index 00000000..921f0a33 --- /dev/null +++ b/lib/xdr/transactions/operations/hash_id_preimage_operation_id.ex @@ -0,0 +1,88 @@ +defmodule StellarBase.XDR.HashIDPreimageOperationID do + @moduledoc """ + Automatically generated by xdrgen + DO NOT EDIT or your changes may be overwritten + + Target implementation: elixir_xdr at https://hex.pm/packages/elixir_xdr + + Representation of Stellar `HashIDPreimageOperationID` type. + """ + + @behaviour XDR.Declaration + + alias StellarBase.XDR.{ + AccountID, + SequenceNumber, + UInt32 + } + + @struct_spec XDR.Struct.new( + source_account: AccountID, + seq_num: SequenceNumber, + op_num: UInt32 + ) + + @type source_account_type :: AccountID.t() + @type seq_num_type :: SequenceNumber.t() + @type op_num_type :: UInt32.t() + + @type t :: %__MODULE__{ + source_account: source_account_type(), + seq_num: seq_num_type(), + op_num: op_num_type() + } + + defstruct [:source_account, :seq_num, :op_num] + + @spec new( + source_account :: source_account_type(), + seq_num :: seq_num_type(), + op_num :: op_num_type() + ) :: t() + def new( + %AccountID{} = source_account, + %SequenceNumber{} = seq_num, + %UInt32{} = op_num + ), + do: %__MODULE__{source_account: source_account, seq_num: seq_num, op_num: op_num} + + @impl true + def encode_xdr(%__MODULE__{source_account: source_account, seq_num: seq_num, op_num: op_num}) do + [source_account: source_account, seq_num: seq_num, op_num: op_num] + |> XDR.Struct.new() + |> XDR.Struct.encode_xdr() + end + + @impl true + def encode_xdr!(%__MODULE__{source_account: source_account, seq_num: seq_num, op_num: op_num}) do + [source_account: source_account, seq_num: seq_num, op_num: op_num] + |> XDR.Struct.new() + |> XDR.Struct.encode_xdr!() + end + + @impl true + def decode_xdr(bytes, struct \\ @struct_spec) + + def decode_xdr(bytes, struct) do + case XDR.Struct.decode_xdr(bytes, struct) do + {:ok, + {%XDR.Struct{ + components: [source_account: source_account, seq_num: seq_num, op_num: op_num] + }, rest}} -> + {:ok, {new(source_account, seq_num, op_num), rest}} + + error -> + error + end + end + + @impl true + def decode_xdr!(bytes, struct \\ @struct_spec) + + def decode_xdr!(bytes, struct) do + {%XDR.Struct{components: [source_account: source_account, seq_num: seq_num, op_num: op_num]}, + rest} = XDR.Struct.decode_xdr!(bytes, struct) + + {new(source_account, seq_num, op_num), rest} + end +end diff --git a/lib/xdr/transactions/operations/hash_id_preimage_revoke_id.ex b/lib/xdr/transactions/operations/hash_id_preimage_revoke_id.ex new file mode 100644 index 00000000..4d25a30f --- /dev/null +++ b/lib/xdr/transactions/operations/hash_id_preimage_revoke_id.ex @@ -0,0 +1,143 @@ +defmodule StellarBase.XDR.HashIDPreimageRevokeID do + @moduledoc """ + Automatically generated by xdrgen + DO NOT EDIT or your changes may be overwritten + + Target implementation: elixir_xdr at https://hex.pm/packages/elixir_xdr + + Representation of Stellar `HashIDPreimageRevokeID` type. + """ + + @behaviour XDR.Declaration + + alias StellarBase.XDR.{ + AccountID, + SequenceNumber, + UInt32, + PoolID, + Asset + } + + @struct_spec XDR.Struct.new( + source_account: AccountID, + seq_num: SequenceNumber, + op_num: UInt32, + liquidity_pool_id: PoolID, + asset: Asset + ) + + @type source_account_type :: AccountID.t() + @type seq_num_type :: SequenceNumber.t() + @type op_num_type :: UInt32.t() + @type liquidity_pool_id_type :: PoolID.t() + @type asset_type :: Asset.t() + + @type t :: %__MODULE__{ + source_account: source_account_type(), + seq_num: seq_num_type(), + op_num: op_num_type(), + liquidity_pool_id: liquidity_pool_id_type(), + asset: asset_type() + } + + defstruct [:source_account, :seq_num, :op_num, :liquidity_pool_id, :asset] + + @spec new( + source_account :: source_account_type(), + seq_num :: seq_num_type(), + op_num :: op_num_type(), + liquidity_pool_id :: liquidity_pool_id_type(), + asset :: asset_type() + ) :: t() + def new( + %AccountID{} = source_account, + %SequenceNumber{} = seq_num, + %UInt32{} = op_num, + %PoolID{} = liquidity_pool_id, + %Asset{} = asset + ), + do: %__MODULE__{ + source_account: source_account, + seq_num: seq_num, + op_num: op_num, + liquidity_pool_id: liquidity_pool_id, + asset: asset + } + + @impl true + def encode_xdr(%__MODULE__{ + source_account: source_account, + seq_num: seq_num, + op_num: op_num, + liquidity_pool_id: liquidity_pool_id, + asset: asset + }) do + [ + source_account: source_account, + seq_num: seq_num, + op_num: op_num, + liquidity_pool_id: liquidity_pool_id, + asset: asset + ] + |> XDR.Struct.new() + |> XDR.Struct.encode_xdr() + end + + @impl true + def encode_xdr!(%__MODULE__{ + source_account: source_account, + seq_num: seq_num, + op_num: op_num, + liquidity_pool_id: liquidity_pool_id, + asset: asset + }) do + [ + source_account: source_account, + seq_num: seq_num, + op_num: op_num, + liquidity_pool_id: liquidity_pool_id, + asset: asset + ] + |> XDR.Struct.new() + |> XDR.Struct.encode_xdr!() + end + + @impl true + def decode_xdr(bytes, struct \\ @struct_spec) + + def decode_xdr(bytes, struct) do + case XDR.Struct.decode_xdr(bytes, struct) do + {:ok, + {%XDR.Struct{ + components: [ + source_account: source_account, + seq_num: seq_num, + op_num: op_num, + liquidity_pool_id: liquidity_pool_id, + asset: asset + ] + }, rest}} -> + {:ok, {new(source_account, seq_num, op_num, liquidity_pool_id, asset), rest}} + + error -> + error + end + end + + @impl true + def decode_xdr!(bytes, struct \\ @struct_spec) + + def decode_xdr!(bytes, struct) do + {%XDR.Struct{ + components: [ + source_account: source_account, + seq_num: seq_num, + op_num: op_num, + liquidity_pool_id: liquidity_pool_id, + asset: asset + ] + }, rest} = XDR.Struct.decode_xdr!(bytes, struct) + + {new(source_account, seq_num, op_num, liquidity_pool_id, asset), rest} + end +end diff --git a/lib/xdr/transactions/operations/invoke_host_function.ex b/lib/xdr/transactions/operations/invoke_host_function.ex index 130eccad..fca58268 100644 --- a/lib/xdr/transactions/operations/invoke_host_function.ex +++ b/lib/xdr/transactions/operations/invoke_host_function.ex @@ -5,35 +5,45 @@ defmodule StellarBase.XDR.Operations.InvokeHostFunction do Target implementation: elixir_xdr at https://hex.pm/packages/elixir_xdr - Representation of Stellar `InvokeHostFunctionOp` type. + Representation of Stellar `InvokeHostFunction` type. """ @behaviour XDR.Declaration - alias StellarBase.XDR.HostFunctionList100 + alias StellarBase.XDR.{ + HostFunction, + SorobanAuthorizationEntryList + } - @struct_spec XDR.Struct.new(functions: HostFunctionList100) + @struct_spec XDR.Struct.new( + host_function: HostFunction, + auth: SorobanAuthorizationEntryList + ) - @type functions_type :: HostFunctionList100.t() + @type host_function_type :: HostFunction.t() + @type auth_type :: SorobanAuthorizationEntryList.t() - @type t :: %__MODULE__{functions: functions_type()} + @type t :: %__MODULE__{host_function: host_function_type(), auth: auth_type()} - defstruct [:functions] + defstruct [:host_function, :auth] - @spec new(functions :: functions_type()) :: t() - def new(%HostFunctionList100{} = functions), - do: %__MODULE__{functions: functions} + @spec new(host_function :: host_function_type(), auth :: auth_type()) :: t() + def new( + %HostFunction{} = host_function, + %SorobanAuthorizationEntryList{} = auth + ), + do: %__MODULE__{host_function: host_function, auth: auth} @impl true - def encode_xdr(%__MODULE__{functions: functions}) do - [functions: functions] + def encode_xdr(%__MODULE__{host_function: host_function, auth: auth}) do + [host_function: host_function, auth: auth] |> XDR.Struct.new() |> XDR.Struct.encode_xdr() end @impl true - def encode_xdr!(%__MODULE__{functions: functions}) do - [functions: functions] + def encode_xdr!(%__MODULE__{host_function: host_function, auth: auth}) do + [host_function: host_function, auth: auth] |> XDR.Struct.new() |> XDR.Struct.encode_xdr!() end @@ -43,8 +53,8 @@ defmodule StellarBase.XDR.Operations.InvokeHostFunction do def decode_xdr(bytes, struct) do case XDR.Struct.decode_xdr(bytes, struct) do - {:ok, {%XDR.Struct{components: [functions: functions]}, rest}} -> - {:ok, {new(functions), rest}} + {:ok, {%XDR.Struct{components: [host_function: host_function, auth: auth]}, rest}} -> + {:ok, {new(host_function, auth), rest}} error -> error @@ -55,9 +65,9 @@ defmodule StellarBase.XDR.Operations.InvokeHostFunction do def decode_xdr!(bytes, struct \\ @struct_spec) def decode_xdr!(bytes, struct) do - {%XDR.Struct{components: [functions: functions]}, rest} = + {%XDR.Struct{components: [host_function: host_function, auth: auth]}, rest} = XDR.Struct.decode_xdr!(bytes, struct) - {new(functions), rest} + {new(host_function, auth), rest} end end diff --git a/lib/xdr/transactions/operations/restore_footprint.ex b/lib/xdr/transactions/operations/restore_footprint.ex new file mode 100644 index 00000000..ed27eed3 --- /dev/null +++ b/lib/xdr/transactions/operations/restore_footprint.ex @@ -0,0 +1,61 @@ +defmodule StellarBase.XDR.Operations.RestoreFootprint do + @moduledoc """ + Automatically generated by xdrgen + DO NOT EDIT or your changes may be overwritten + + Target implementation: elixir_xdr at https://hex.pm/packages/elixir_xdr + + Representation of Stellar `RestoreFootprint` type. + """ + + @behaviour XDR.Declaration + + alias StellarBase.XDR.ExtensionPoint + + @struct_spec XDR.Struct.new(ext: ExtensionPoint) + + @type ext_type :: ExtensionPoint.t() + + @type t :: %__MODULE__{ext: ext_type()} + + defstruct [:ext] + + @spec new(ext :: ext_type()) :: t() + def new(%ExtensionPoint{} = ext), + do: %__MODULE__{ext: ext} + + @impl true + def encode_xdr(%__MODULE__{ext: ext}) do + [ext: ext] + |> XDR.Struct.new() + |> XDR.Struct.encode_xdr() + end + + @impl true + def encode_xdr!(%__MODULE__{ext: ext}) do + [ext: ext] + |> XDR.Struct.new() + |> XDR.Struct.encode_xdr!() + end + + @impl true + def decode_xdr(bytes, struct \\ @struct_spec) + + def decode_xdr(bytes, struct) do + case XDR.Struct.decode_xdr(bytes, struct) do + {:ok, {%XDR.Struct{components: [ext: ext]}, rest}} -> + {:ok, {new(ext), rest}} + + error -> + error + end + end + + @impl true + def decode_xdr!(bytes, struct \\ @struct_spec) + + def decode_xdr!(bytes, struct) do + {%XDR.Struct{components: [ext: ext]}, rest} = XDR.Struct.decode_xdr!(bytes, struct) + {new(ext), rest} + end +end diff --git a/lib/xdr/transactions/operations/restore_footprint_result.ex b/lib/xdr/transactions/operations/restore_footprint_result.ex new file mode 100644 index 00000000..d22ec51f --- /dev/null +++ b/lib/xdr/transactions/operations/restore_footprint_result.ex @@ -0,0 +1,72 @@ +defmodule StellarBase.XDR.RestoreFootprintResult do + @moduledoc """ + Automatically generated by xdrgen + DO NOT EDIT or your changes may be overwritten + + Target implementation: elixir_xdr at https://hex.pm/packages/elixir_xdr + + Representation of Stellar `RestoreFootprintResult` type. + """ + + @behaviour XDR.Declaration + + alias StellarBase.XDR.{ + RestoreFootprintResultCode, + Void + } + + @arms [ + RESTORE_FOOTPRINT_SUCCESS: Void, + RESTORE_FOOTPRINT_MALFORMED: Void, + RESTORE_FOOTPRINT_RESOURCE_LIMIT_EXCEEDED: Void + ] + + @type value :: + Void.t() + + @type t :: %__MODULE__{value: value(), type: RestoreFootprintResultCode.t()} + + defstruct [:value, :type] + + @spec new(value :: value(), type :: RestoreFootprintResultCode.t()) :: t() + def new(value, %RestoreFootprintResultCode{} = type), do: %__MODULE__{value: value, type: type} + + @impl true + def encode_xdr(%__MODULE__{value: value, type: type}) do + type + |> XDR.Union.new(@arms, value) + |> XDR.Union.encode_xdr() + end + + @impl true + def encode_xdr!(%__MODULE__{value: value, type: type}) do + type + |> XDR.Union.new(@arms, value) + |> XDR.Union.encode_xdr!() + end + + @impl true + def decode_xdr(bytes, spec \\ union_spec()) + + def decode_xdr(bytes, spec) do + case XDR.Union.decode_xdr(bytes, spec) do + {:ok, {{type, value}, rest}} -> {:ok, {new(value, type), rest}} + error -> error + end + end + + @impl true + def decode_xdr!(bytes, spec \\ union_spec()) + + def decode_xdr!(bytes, spec) do + {{type, value}, rest} = XDR.Union.decode_xdr!(bytes, spec) + {new(value, type), rest} + end + + @spec union_spec() :: XDR.Union.t() + defp union_spec do + nil + |> RestoreFootprintResultCode.new() + |> XDR.Union.new(@arms) + end +end diff --git a/lib/xdr/contract/sc_host_obj_error_code.ex b/lib/xdr/transactions/operations/restore_footprint_result_code.ex similarity index 68% rename from lib/xdr/contract/sc_host_obj_error_code.ex rename to lib/xdr/transactions/operations/restore_footprint_result_code.ex index 69e12423..0bf39fd9 100644 --- a/lib/xdr/contract/sc_host_obj_error_code.ex +++ b/lib/xdr/transactions/operations/restore_footprint_result_code.ex @@ -1,18 +1,19 @@ -defmodule StellarBase.XDR.SCHostObjErrorCode do +defmodule StellarBase.XDR.RestoreFootprintResultCode do @moduledoc """ - Representation of Stellar `SCHostObjErrorCode` type. + Automatically generated by xdrgen + DO NOT EDIT or your changes may be overwritten + + Target implementation: elixir_xdr at https://hex.pm/packages/elixir_xdr + + Representation of Stellar `RestoreFootprintResultCode` type. """ @behaviour XDR.Declaration @declarations [ - HOST_OBJECT_UNKNOWN_ERROR: 0, - HOST_OBJECT_UNKNOWN_REFERENCE: 1, - HOST_OBJECT_UNEXPECTED_TYPE: 2, - HOST_OBJECT_OBJECT_COUNT_EXCEEDS_U32_MAX: 3, - HOST_OBJECT_OBJECT_NOT_EXIST: 4, - HOST_OBJECT_VEC_INDEX_OUT_OF_BOUND: 5, - HOST_OBJECT_CONTRACT_HASH_WRONG_LENGTH: 6 + RESTORE_FOOTPRINT_SUCCESS: 0, + RESTORE_FOOTPRINT_MALFORMED: -1, + RESTORE_FOOTPRINT_RESOURCE_LIMIT_EXCEEDED: -2 ] @enum_spec %XDR.Enum{declarations: @declarations, identifier: nil} @@ -22,7 +23,7 @@ defmodule StellarBase.XDR.SCHostObjErrorCode do defstruct [:identifier] @spec new(type :: atom()) :: t() - def new(type \\ :HOST_OBJECT_UNKNOWN_ERROR), do: %__MODULE__{identifier: type} + def new(type \\ :RESTORE_FOOTPRINT_SUCCESS), do: %__MODULE__{identifier: type} @impl true def encode_xdr(%__MODULE__{identifier: type}) do diff --git a/lib/xdr/transactions/operations/revoke_sponsorship_op_signer.ex b/lib/xdr/transactions/operations/revoke_sponsorship_op_signer.ex new file mode 100644 index 00000000..f6d0fa35 --- /dev/null +++ b/lib/xdr/transactions/operations/revoke_sponsorship_op_signer.ex @@ -0,0 +1,73 @@ +defmodule StellarBase.XDR.RevokeSponsorshipOpSigner do + @moduledoc """ + Automatically generated by xdrgen + DO NOT EDIT or your changes may be overwritten + + Target implementation: elixir_xdr at https://hex.pm/packages/elixir_xdr + + Representation of Stellar `RevokeSponsorshipOpSigner` type. + """ + + @behaviour XDR.Declaration + + alias StellarBase.XDR.{ + AccountID, + SignerKey + } + + @struct_spec XDR.Struct.new( + account_id: AccountID, + signer_key: SignerKey + ) + + @type account_id_type :: AccountID.t() + @type signer_key_type :: SignerKey.t() + + @type t :: %__MODULE__{account_id: account_id_type(), signer_key: signer_key_type()} + + defstruct [:account_id, :signer_key] + + @spec new(account_id :: account_id_type(), signer_key :: signer_key_type()) :: t() + def new( + %AccountID{} = account_id, + %SignerKey{} = signer_key + ), + do: %__MODULE__{account_id: account_id, signer_key: signer_key} + + @impl true + def encode_xdr(%__MODULE__{account_id: account_id, signer_key: signer_key}) do + [account_id: account_id, signer_key: signer_key] + |> XDR.Struct.new() + |> XDR.Struct.encode_xdr() + end + + @impl true + def encode_xdr!(%__MODULE__{account_id: account_id, signer_key: signer_key}) do + [account_id: account_id, signer_key: signer_key] + |> XDR.Struct.new() + |> XDR.Struct.encode_xdr!() + end + + @impl true + def decode_xdr(bytes, struct \\ @struct_spec) + + def decode_xdr(bytes, struct) do + case XDR.Struct.decode_xdr(bytes, struct) do + {:ok, {%XDR.Struct{components: [account_id: account_id, signer_key: signer_key]}, rest}} -> + {:ok, {new(account_id, signer_key), rest}} + + error -> + error + end + end + + @impl true + def decode_xdr!(bytes, struct \\ @struct_spec) + + def decode_xdr!(bytes, struct) do + {%XDR.Struct{components: [account_id: account_id, signer_key: signer_key]}, rest} = + XDR.Struct.decode_xdr!(bytes, struct) + + {new(account_id, signer_key), rest} + end +end diff --git a/lib/xdr/transactions/optional_address_with_nonce.ex b/lib/xdr/transactions/optional_address_with_nonce.ex deleted file mode 100644 index b9fe95e2..00000000 --- a/lib/xdr/transactions/optional_address_with_nonce.ex +++ /dev/null @@ -1,59 +0,0 @@ -defmodule StellarBase.XDR.OptionalAddressWithNonce do - @moduledoc """ - Representation of Stellar `OptionalAddressWithNonce` type. - """ - alias StellarBase.XDR.AddressWithNonce - - @behaviour XDR.Declaration - - @optional_spec XDR.Optional.new(AddressWithNonce) - - @type address_with_nonce :: AddressWithNonce.t() | nil - - @type t :: %__MODULE__{address_with_nonce: address_with_nonce()} - - defstruct [:address_with_nonce] - - @spec new(address_with_nonce :: address_with_nonce()) :: t() - def new(address_with_nonce \\ nil), do: %__MODULE__{address_with_nonce: address_with_nonce} - - @impl true - def encode_xdr(%__MODULE__{address_with_nonce: address_with_nonce}) do - address_with_nonce - |> XDR.Optional.new() - |> XDR.Optional.encode_xdr() - end - - @impl true - def encode_xdr!(%__MODULE__{address_with_nonce: address_with_nonce}) do - address_with_nonce - |> XDR.Optional.new() - |> XDR.Optional.encode_xdr!() - end - - @impl true - def decode_xdr(bytes, optional_spec \\ @optional_spec) - - def decode_xdr(bytes, optional_spec) do - case XDR.Optional.decode_xdr(bytes, optional_spec) do - {:ok, {%XDR.Optional{type: address_with_nonce}, rest}} -> - {:ok, {new(address_with_nonce), rest}} - - {:ok, {nil, rest}} -> - {:ok, {new(), rest}} - - error -> - error - end - end - - @impl true - def decode_xdr!(bytes, optional_spec \\ @optional_spec) - - def decode_xdr!(bytes, optional_spec) do - case XDR.Optional.decode_xdr!(bytes, optional_spec) do - {%XDR.Optional{type: address_with_nonce}, rest} -> {new(address_with_nonce), rest} - {nil, rest} -> {new(), rest} - end - end -end diff --git a/lib/xdr/transactions/soroban_address_credentials.ex b/lib/xdr/transactions/soroban_address_credentials.ex new file mode 100644 index 00000000..dbad7a93 --- /dev/null +++ b/lib/xdr/transactions/soroban_address_credentials.ex @@ -0,0 +1,130 @@ +defmodule StellarBase.XDR.SorobanAddressCredentials do + @moduledoc """ + Automatically generated by xdrgen + DO NOT EDIT or your changes may be overwritten + + Target implementation: elixir_xdr at https://hex.pm/packages/elixir_xdr + + Representation of Stellar `SorobanAddressCredentials` type. + """ + + @behaviour XDR.Declaration + + alias StellarBase.XDR.{ + SCAddress, + Int64, + UInt32, + SCVec + } + + @struct_spec XDR.Struct.new( + address: SCAddress, + nonce: Int64, + signature_expiration_ledger: UInt32, + signature_args: SCVec + ) + + @type address_type :: SCAddress.t() + @type nonce_type :: Int64.t() + @type signature_expiration_ledger_type :: UInt32.t() + @type signature_args_type :: SCVec.t() + + @type t :: %__MODULE__{ + address: address_type(), + nonce: nonce_type(), + signature_expiration_ledger: signature_expiration_ledger_type(), + signature_args: signature_args_type() + } + + defstruct [:address, :nonce, :signature_expiration_ledger, :signature_args] + + @spec new( + address :: address_type(), + nonce :: nonce_type(), + signature_expiration_ledger :: signature_expiration_ledger_type(), + signature_args :: signature_args_type() + ) :: t() + def new( + %SCAddress{} = address, + %Int64{} = nonce, + %UInt32{} = signature_expiration_ledger, + %SCVec{} = signature_args + ), + do: %__MODULE__{ + address: address, + nonce: nonce, + signature_expiration_ledger: signature_expiration_ledger, + signature_args: signature_args + } + + @impl true + def encode_xdr(%__MODULE__{ + address: address, + nonce: nonce, + signature_expiration_ledger: signature_expiration_ledger, + signature_args: signature_args + }) do + [ + address: address, + nonce: nonce, + signature_expiration_ledger: signature_expiration_ledger, + signature_args: signature_args + ] + |> XDR.Struct.new() + |> XDR.Struct.encode_xdr() + end + + @impl true + def encode_xdr!(%__MODULE__{ + address: address, + nonce: nonce, + signature_expiration_ledger: signature_expiration_ledger, + signature_args: signature_args + }) do + [ + address: address, + nonce: nonce, + signature_expiration_ledger: signature_expiration_ledger, + signature_args: signature_args + ] + |> XDR.Struct.new() + |> XDR.Struct.encode_xdr!() + end + + @impl true + def decode_xdr(bytes, struct \\ @struct_spec) + + def decode_xdr(bytes, struct) do + case XDR.Struct.decode_xdr(bytes, struct) do + {:ok, + {%XDR.Struct{ + components: [ + address: address, + nonce: nonce, + signature_expiration_ledger: signature_expiration_ledger, + signature_args: signature_args + ] + }, rest}} -> + {:ok, {new(address, nonce, signature_expiration_ledger, signature_args), rest}} + + error -> + error + end + end + + @impl true + def decode_xdr!(bytes, struct \\ @struct_spec) + + def decode_xdr!(bytes, struct) do + {%XDR.Struct{ + components: [ + address: address, + nonce: nonce, + signature_expiration_ledger: signature_expiration_ledger, + signature_args: signature_args + ] + }, rest} = XDR.Struct.decode_xdr!(bytes, struct) + + {new(address, nonce, signature_expiration_ledger, signature_args), rest} + end +end diff --git a/lib/xdr/transactions/soroban_authorization_entry.ex b/lib/xdr/transactions/soroban_authorization_entry.ex new file mode 100644 index 00000000..75280423 --- /dev/null +++ b/lib/xdr/transactions/soroban_authorization_entry.ex @@ -0,0 +1,75 @@ +defmodule StellarBase.XDR.SorobanAuthorizationEntry do + @moduledoc """ + Automatically generated by xdrgen + DO NOT EDIT or your changes may be overwritten + + Target implementation: elixir_xdr at https://hex.pm/packages/elixir_xdr + + Representation of Stellar `SorobanAuthorizationEntry` type. + """ + + @behaviour XDR.Declaration + + alias StellarBase.XDR.{ + SorobanCredentials, + SorobanAuthorizedInvocation + } + + @struct_spec XDR.Struct.new( + credentials: SorobanCredentials, + root_invocation: SorobanAuthorizedInvocation + ) + + @type credentials_type :: SorobanCredentials.t() + @type root_invocation_type :: SorobanAuthorizedInvocation.t() + + @type t :: %__MODULE__{credentials: credentials_type(), root_invocation: root_invocation_type()} + + defstruct [:credentials, :root_invocation] + + @spec new(credentials :: credentials_type(), root_invocation :: root_invocation_type()) :: t() + def new( + %SorobanCredentials{} = credentials, + %SorobanAuthorizedInvocation{} = root_invocation + ), + do: %__MODULE__{credentials: credentials, root_invocation: root_invocation} + + @impl true + def encode_xdr(%__MODULE__{credentials: credentials, root_invocation: root_invocation}) do + [credentials: credentials, root_invocation: root_invocation] + |> XDR.Struct.new() + |> XDR.Struct.encode_xdr() + end + + @impl true + def encode_xdr!(%__MODULE__{credentials: credentials, root_invocation: root_invocation}) do + [credentials: credentials, root_invocation: root_invocation] + |> XDR.Struct.new() + |> XDR.Struct.encode_xdr!() + end + + @impl true + def decode_xdr(bytes, struct \\ @struct_spec) + + def decode_xdr(bytes, struct) do + case XDR.Struct.decode_xdr(bytes, struct) do + {:ok, + {%XDR.Struct{components: [credentials: credentials, root_invocation: root_invocation]}, + rest}} -> + {:ok, {new(credentials, root_invocation), rest}} + + error -> + error + end + end + + @impl true + def decode_xdr!(bytes, struct \\ @struct_spec) + + def decode_xdr!(bytes, struct) do + {%XDR.Struct{components: [credentials: credentials, root_invocation: root_invocation]}, rest} = + XDR.Struct.decode_xdr!(bytes, struct) + + {new(credentials, root_invocation), rest} + end +end diff --git a/lib/xdr/transactions/soroban_authorization_entry_list.ex b/lib/xdr/transactions/soroban_authorization_entry_list.ex new file mode 100644 index 00000000..f7f1439a --- /dev/null +++ b/lib/xdr/transactions/soroban_authorization_entry_list.ex @@ -0,0 +1,57 @@ +defmodule StellarBase.XDR.SorobanAuthorizationEntryList do + @moduledoc """ + Automatically generated by xdrgen + DO NOT EDIT or your changes may be overwritten + + Target implementation: elixir_xdr at https://hex.pm/packages/elixir_xdr + + Representation of Stellar `SorobanAuthorizationEntryList` type. + """ + + @behaviour XDR.Declaration + + alias StellarBase.XDR.SorobanAuthorizationEntry + + @array_type SorobanAuthorizationEntry + + @array_spec %{type: @array_type} + + @type t :: %__MODULE__{items: list(SorobanAuthorizationEntry.t())} + + defstruct [:items] + + @spec new(items :: list(SorobanAuthorizationEntry.t())) :: t() + def new(items), do: %__MODULE__{items: items} + + @impl true + def encode_xdr(%__MODULE__{items: items}) do + items + |> XDR.VariableArray.new(@array_type) + |> XDR.VariableArray.encode_xdr() + end + + @impl true + def encode_xdr!(%__MODULE__{items: items}) do + items + |> XDR.VariableArray.new(@array_type) + |> XDR.VariableArray.encode_xdr!() + end + + @impl true + def decode_xdr(bytes, spec \\ @array_spec) + + def decode_xdr(bytes, spec) do + case XDR.VariableArray.decode_xdr(bytes, spec) do + {:ok, {items, rest}} -> {:ok, {new(items), rest}} + error -> error + end + end + + @impl true + def decode_xdr!(bytes, spec \\ @array_spec) + + def decode_xdr!(bytes, spec) do + {items, rest} = XDR.VariableArray.decode_xdr!(bytes, spec) + {new(items), rest} + end +end diff --git a/lib/xdr/transactions/soroban_authorized_contract_function.ex b/lib/xdr/transactions/soroban_authorized_contract_function.ex new file mode 100644 index 00000000..50e134e3 --- /dev/null +++ b/lib/xdr/transactions/soroban_authorized_contract_function.ex @@ -0,0 +1,105 @@ +defmodule StellarBase.XDR.SorobanAuthorizedContractFunction do + @moduledoc """ + Automatically generated by xdrgen + DO NOT EDIT or your changes may be overwritten + + Target implementation: elixir_xdr at https://hex.pm/packages/elixir_xdr + + Representation of Stellar `SorobanAuthorizedContractFunction` type. + """ + + @behaviour XDR.Declaration + + alias StellarBase.XDR.{ + SCAddress, + SCSymbol, + SCVec + } + + @struct_spec XDR.Struct.new( + contract_address: SCAddress, + function_name: SCSymbol, + args: SCVec + ) + + @type contract_address_type :: SCAddress.t() + @type function_name_type :: SCSymbol.t() + @type args_type :: SCVec.t() + + @type t :: %__MODULE__{ + contract_address: contract_address_type(), + function_name: function_name_type(), + args: args_type() + } + + defstruct [:contract_address, :function_name, :args] + + @spec new( + contract_address :: contract_address_type(), + function_name :: function_name_type(), + args :: args_type() + ) :: t() + def new( + %SCAddress{} = contract_address, + %SCSymbol{} = function_name, + %SCVec{} = args + ), + do: %__MODULE__{ + contract_address: contract_address, + function_name: function_name, + args: args + } + + @impl true + def encode_xdr(%__MODULE__{ + contract_address: contract_address, + function_name: function_name, + args: args + }) do + [contract_address: contract_address, function_name: function_name, args: args] + |> XDR.Struct.new() + |> XDR.Struct.encode_xdr() + end + + @impl true + def encode_xdr!(%__MODULE__{ + contract_address: contract_address, + function_name: function_name, + args: args + }) do + [contract_address: contract_address, function_name: function_name, args: args] + |> XDR.Struct.new() + |> XDR.Struct.encode_xdr!() + end + + @impl true + def decode_xdr(bytes, struct \\ @struct_spec) + + def decode_xdr(bytes, struct) do + case XDR.Struct.decode_xdr(bytes, struct) do + {:ok, + {%XDR.Struct{ + components: [ + contract_address: contract_address, + function_name: function_name, + args: args + ] + }, rest}} -> + {:ok, {new(contract_address, function_name, args), rest}} + + error -> + error + end + end + + @impl true + def decode_xdr!(bytes, struct \\ @struct_spec) + + def decode_xdr!(bytes, struct) do + {%XDR.Struct{ + components: [contract_address: contract_address, function_name: function_name, args: args] + }, rest} = XDR.Struct.decode_xdr!(bytes, struct) + + {new(contract_address, function_name, args), rest} + end +end diff --git a/lib/xdr/transactions/soroban_authorized_function.ex b/lib/xdr/transactions/soroban_authorized_function.ex new file mode 100644 index 00000000..f4e899a3 --- /dev/null +++ b/lib/xdr/transactions/soroban_authorized_function.ex @@ -0,0 +1,74 @@ +defmodule StellarBase.XDR.SorobanAuthorizedFunction do + @moduledoc """ + Automatically generated by xdrgen + DO NOT EDIT or your changes may be overwritten + + Target implementation: elixir_xdr at https://hex.pm/packages/elixir_xdr + + Representation of Stellar `SorobanAuthorizedFunction` type. + """ + + @behaviour XDR.Declaration + + alias StellarBase.XDR.{ + SorobanAuthorizedFunctionType, + SorobanAuthorizedContractFunction, + CreateContractArgs + } + + @arms [ + SOROBAN_AUTHORIZED_FUNCTION_TYPE_CONTRACT_FN: SorobanAuthorizedContractFunction, + SOROBAN_AUTHORIZED_FUNCTION_TYPE_CREATE_CONTRACT_HOST_FN: CreateContractArgs + ] + + @type value :: + SorobanAuthorizedContractFunction.t() + | CreateContractArgs.t() + + @type t :: %__MODULE__{value: value(), type: SorobanAuthorizedFunctionType.t()} + + defstruct [:value, :type] + + @spec new(value :: value(), type :: SorobanAuthorizedFunctionType.t()) :: t() + def new(value, %SorobanAuthorizedFunctionType{} = type), + do: %__MODULE__{value: value, type: type} + + @impl true + def encode_xdr(%__MODULE__{value: value, type: type}) do + type + |> XDR.Union.new(@arms, value) + |> XDR.Union.encode_xdr() + end + + @impl true + def encode_xdr!(%__MODULE__{value: value, type: type}) do + type + |> XDR.Union.new(@arms, value) + |> XDR.Union.encode_xdr!() + end + + @impl true + def decode_xdr(bytes, spec \\ union_spec()) + + def decode_xdr(bytes, spec) do + case XDR.Union.decode_xdr(bytes, spec) do + {:ok, {{type, value}, rest}} -> {:ok, {new(value, type), rest}} + error -> error + end + end + + @impl true + def decode_xdr!(bytes, spec \\ union_spec()) + + def decode_xdr!(bytes, spec) do + {{type, value}, rest} = XDR.Union.decode_xdr!(bytes, spec) + {new(value, type), rest} + end + + @spec union_spec() :: XDR.Union.t() + defp union_spec do + nil + |> SorobanAuthorizedFunctionType.new() + |> XDR.Union.new(@arms) + end +end diff --git a/lib/xdr/transactions/soroban_authorized_function_type.ex b/lib/xdr/transactions/soroban_authorized_function_type.ex new file mode 100644 index 00000000..681ed01b --- /dev/null +++ b/lib/xdr/transactions/soroban_authorized_function_type.ex @@ -0,0 +1,59 @@ +defmodule StellarBase.XDR.SorobanAuthorizedFunctionType do + @moduledoc """ + Automatically generated by xdrgen + DO NOT EDIT or your changes may be overwritten + + Target implementation: elixir_xdr at https://hex.pm/packages/elixir_xdr + + Representation of Stellar `SorobanAuthorizedFunctionType` type. + """ + + @behaviour XDR.Declaration + + @declarations [ + SOROBAN_AUTHORIZED_FUNCTION_TYPE_CONTRACT_FN: 0, + SOROBAN_AUTHORIZED_FUNCTION_TYPE_CREATE_CONTRACT_HOST_FN: 1 + ] + + @enum_spec %XDR.Enum{declarations: @declarations, identifier: nil} + + @type t :: %__MODULE__{identifier: atom()} + + defstruct [:identifier] + + @spec new(type :: atom()) :: t() + def new(type \\ :SOROBAN_AUTHORIZED_FUNCTION_TYPE_CONTRACT_FN), + do: %__MODULE__{identifier: type} + + @impl true + def encode_xdr(%__MODULE__{identifier: type}) do + @declarations + |> XDR.Enum.new(type) + |> XDR.Enum.encode_xdr() + end + + @impl true + def encode_xdr!(%__MODULE__{identifier: type}) do + @declarations + |> XDR.Enum.new(type) + |> XDR.Enum.encode_xdr!() + end + + @impl true + def decode_xdr(bytes, spec \\ @enum_spec) + + def decode_xdr(bytes, spec) do + case XDR.Enum.decode_xdr(bytes, spec) do + {:ok, {%XDR.Enum{identifier: type}, rest}} -> {:ok, {new(type), rest}} + error -> error + end + end + + @impl true + def decode_xdr!(bytes, spec \\ @enum_spec) + + def decode_xdr!(bytes, spec) do + {%XDR.Enum{identifier: type}, rest} = XDR.Enum.decode_xdr!(bytes, spec) + {new(type), rest} + end +end diff --git a/lib/xdr/transactions/soroban_authorized_invocation.ex b/lib/xdr/transactions/soroban_authorized_invocation.ex new file mode 100644 index 00000000..685b641c --- /dev/null +++ b/lib/xdr/transactions/soroban_authorized_invocation.ex @@ -0,0 +1,74 @@ +defmodule StellarBase.XDR.SorobanAuthorizedInvocation do + @moduledoc """ + Automatically generated by xdrgen + DO NOT EDIT or your changes may be overwritten + + Target implementation: elixir_xdr at https://hex.pm/packages/elixir_xdr + + Representation of Stellar `SorobanAuthorizedInvocation` type. + """ + + @behaviour XDR.Declaration + + alias StellarBase.XDR.{ + SorobanAuthorizedFunction, + SorobanAuthorizedInvocationList + } + + @struct_spec XDR.Struct.new( + function: SorobanAuthorizedFunction, + sub_invocations: SorobanAuthorizedInvocationList + ) + + @type function_type :: SorobanAuthorizedFunction.t() + @type sub_invocations_type :: SorobanAuthorizedInvocationList.t() + + @type t :: %__MODULE__{function: function_type(), sub_invocations: sub_invocations_type()} + + defstruct [:function, :sub_invocations] + + @spec new(function :: function_type(), sub_invocations :: sub_invocations_type()) :: t() + def new( + %SorobanAuthorizedFunction{} = function, + %SorobanAuthorizedInvocationList{} = sub_invocations + ), + do: %__MODULE__{function: function, sub_invocations: sub_invocations} + + @impl true + def encode_xdr(%__MODULE__{function: function, sub_invocations: sub_invocations}) do + [function: function, sub_invocations: sub_invocations] + |> XDR.Struct.new() + |> XDR.Struct.encode_xdr() + end + + @impl true + def encode_xdr!(%__MODULE__{function: function, sub_invocations: sub_invocations}) do + [function: function, sub_invocations: sub_invocations] + |> XDR.Struct.new() + |> XDR.Struct.encode_xdr!() + end + + @impl true + def decode_xdr(bytes, struct \\ @struct_spec) + + def decode_xdr(bytes, struct) do + case XDR.Struct.decode_xdr(bytes, struct) do + {:ok, + {%XDR.Struct{components: [function: function, sub_invocations: sub_invocations]}, rest}} -> + {:ok, {new(function, sub_invocations), rest}} + + error -> + error + end + end + + @impl true + def decode_xdr!(bytes, struct \\ @struct_spec) + + def decode_xdr!(bytes, struct) do + {%XDR.Struct{components: [function: function, sub_invocations: sub_invocations]}, rest} = + XDR.Struct.decode_xdr!(bytes, struct) + + {new(function, sub_invocations), rest} + end +end diff --git a/lib/xdr/transactions/soroban_authorized_invocation_list.ex b/lib/xdr/transactions/soroban_authorized_invocation_list.ex new file mode 100644 index 00000000..a1d6fe3f --- /dev/null +++ b/lib/xdr/transactions/soroban_authorized_invocation_list.ex @@ -0,0 +1,57 @@ +defmodule StellarBase.XDR.SorobanAuthorizedInvocationList do + @moduledoc """ + Automatically generated by xdrgen + DO NOT EDIT or your changes may be overwritten + + Target implementation: elixir_xdr at https://hex.pm/packages/elixir_xdr + + Representation of Stellar `SorobanAuthorizedInvocationList` type. + """ + + @behaviour XDR.Declaration + + alias StellarBase.XDR.SorobanAuthorizedInvocation + + @array_type SorobanAuthorizedInvocation + + @array_spec %{type: @array_type} + + @type t :: %__MODULE__{items: list(SorobanAuthorizedInvocation.t())} + + defstruct [:items] + + @spec new(items :: list(SorobanAuthorizedInvocation.t())) :: t() + def new(items), do: %__MODULE__{items: items} + + @impl true + def encode_xdr(%__MODULE__{items: items}) do + items + |> XDR.VariableArray.new(@array_type) + |> XDR.VariableArray.encode_xdr() + end + + @impl true + def encode_xdr!(%__MODULE__{items: items}) do + items + |> XDR.VariableArray.new(@array_type) + |> XDR.VariableArray.encode_xdr!() + end + + @impl true + def decode_xdr(bytes, spec \\ @array_spec) + + def decode_xdr(bytes, spec) do + case XDR.VariableArray.decode_xdr(bytes, spec) do + {:ok, {items, rest}} -> {:ok, {new(items), rest}} + error -> error + end + end + + @impl true + def decode_xdr!(bytes, spec \\ @array_spec) + + def decode_xdr!(bytes, spec) do + {items, rest} = XDR.VariableArray.decode_xdr!(bytes, spec) + {new(items), rest} + end +end diff --git a/lib/xdr/transactions/soroban_credentials.ex b/lib/xdr/transactions/soroban_credentials.ex new file mode 100644 index 00000000..1631250d --- /dev/null +++ b/lib/xdr/transactions/soroban_credentials.ex @@ -0,0 +1,73 @@ +defmodule StellarBase.XDR.SorobanCredentials do + @moduledoc """ + Automatically generated by xdrgen + DO NOT EDIT or your changes may be overwritten + + Target implementation: elixir_xdr at https://hex.pm/packages/elixir_xdr + + Representation of Stellar `SorobanCredentials` type. + """ + + @behaviour XDR.Declaration + + alias StellarBase.XDR.{ + SorobanCredentialsType, + Void, + SorobanAddressCredentials + } + + @arms [ + SOROBAN_CREDENTIALS_SOURCE_ACCOUNT: Void, + SOROBAN_CREDENTIALS_ADDRESS: SorobanAddressCredentials + ] + + @type value :: + Void.t() + | SorobanAddressCredentials.t() + + @type t :: %__MODULE__{value: value(), type: SorobanCredentialsType.t()} + + defstruct [:value, :type] + + @spec new(value :: value(), type :: SorobanCredentialsType.t()) :: t() + def new(value, %SorobanCredentialsType{} = type), do: %__MODULE__{value: value, type: type} + + @impl true + def encode_xdr(%__MODULE__{value: value, type: type}) do + type + |> XDR.Union.new(@arms, value) + |> XDR.Union.encode_xdr() + end + + @impl true + def encode_xdr!(%__MODULE__{value: value, type: type}) do + type + |> XDR.Union.new(@arms, value) + |> XDR.Union.encode_xdr!() + end + + @impl true + def decode_xdr(bytes, spec \\ union_spec()) + + def decode_xdr(bytes, spec) do + case XDR.Union.decode_xdr(bytes, spec) do + {:ok, {{type, value}, rest}} -> {:ok, {new(value, type), rest}} + error -> error + end + end + + @impl true + def decode_xdr!(bytes, spec \\ union_spec()) + + def decode_xdr!(bytes, spec) do + {{type, value}, rest} = XDR.Union.decode_xdr!(bytes, spec) + {new(value, type), rest} + end + + @spec union_spec() :: XDR.Union.t() + defp union_spec do + nil + |> SorobanCredentialsType.new() + |> XDR.Union.new(@arms) + end +end diff --git a/lib/xdr/contract/sc_host_context_error_code.ex b/lib/xdr/transactions/soroban_credentials_type.ex similarity index 69% rename from lib/xdr/contract/sc_host_context_error_code.ex rename to lib/xdr/transactions/soroban_credentials_type.ex index 7cefddc8..1e569d08 100644 --- a/lib/xdr/contract/sc_host_context_error_code.ex +++ b/lib/xdr/transactions/soroban_credentials_type.ex @@ -1,13 +1,18 @@ -defmodule StellarBase.XDR.SCHostContextErrorCode do +defmodule StellarBase.XDR.SorobanCredentialsType do @moduledoc """ - Representation of Stellar `SCHostContextErrorCode` type. + Automatically generated by xdrgen + DO NOT EDIT or your changes may be overwritten + + Target implementation: elixir_xdr at https://hex.pm/packages/elixir_xdr + + Representation of Stellar `SorobanCredentialsType` type. """ @behaviour XDR.Declaration @declarations [ - HOST_CONTEXT_UNKNOWN_ERROR: 0, - HOST_CONTEXT_NO_CONTRACT_RUNNING: 1 + SOROBAN_CREDENTIALS_SOURCE_ACCOUNT: 0, + SOROBAN_CREDENTIALS_ADDRESS: 1 ] @enum_spec %XDR.Enum{declarations: @declarations, identifier: nil} @@ -17,7 +22,7 @@ defmodule StellarBase.XDR.SCHostContextErrorCode do defstruct [:identifier] @spec new(type :: atom()) :: t() - def new(type \\ :HOST_CONTEXT_UNKNOWN_ERROR), do: %__MODULE__{identifier: type} + def new(type \\ :SOROBAN_CREDENTIALS_SOURCE_ACCOUNT), do: %__MODULE__{identifier: type} @impl true def encode_xdr(%__MODULE__{identifier: type}) do diff --git a/lib/xdr/transactions/soroban_transaction_data.ex b/lib/xdr/transactions/soroban_transaction_data.ex index 9c83042d..abf65bab 100644 --- a/lib/xdr/transactions/soroban_transaction_data.ex +++ b/lib/xdr/transactions/soroban_transaction_data.ex @@ -11,51 +11,51 @@ defmodule StellarBase.XDR.SorobanTransactionData do @behaviour XDR.Declaration alias StellarBase.XDR.{ + ExtensionPoint, SorobanResources, - Int64, - ExtensionPoint + Int64 } @struct_spec XDR.Struct.new( + ext: ExtensionPoint, resources: SorobanResources, - refundable_fee: Int64, - ext: ExtensionPoint + refundable_fee: Int64 ) + @type ext_type :: ExtensionPoint.t() @type resources_type :: SorobanResources.t() @type refundable_fee_type :: Int64.t() - @type ext_type :: ExtensionPoint.t() @type t :: %__MODULE__{ + ext: ext_type(), resources: resources_type(), - refundable_fee: refundable_fee_type(), - ext: ext_type() + refundable_fee: refundable_fee_type() } - defstruct [:resources, :refundable_fee, :ext] + defstruct [:ext, :resources, :refundable_fee] @spec new( + ext :: ext_type(), resources :: resources_type(), - refundable_fee :: refundable_fee_type(), - ext :: ext_type() + refundable_fee :: refundable_fee_type() ) :: t() def new( + %ExtensionPoint{} = ext, %SorobanResources{} = resources, - %Int64{} = refundable_fee, - %ExtensionPoint{} = ext + %Int64{} = refundable_fee ), - do: %__MODULE__{resources: resources, refundable_fee: refundable_fee, ext: ext} + do: %__MODULE__{ext: ext, resources: resources, refundable_fee: refundable_fee} @impl true - def encode_xdr(%__MODULE__{resources: resources, refundable_fee: refundable_fee, ext: ext}) do - [resources: resources, refundable_fee: refundable_fee, ext: ext] + def encode_xdr(%__MODULE__{ext: ext, resources: resources, refundable_fee: refundable_fee}) do + [ext: ext, resources: resources, refundable_fee: refundable_fee] |> XDR.Struct.new() |> XDR.Struct.encode_xdr() end @impl true - def encode_xdr!(%__MODULE__{resources: resources, refundable_fee: refundable_fee, ext: ext}) do - [resources: resources, refundable_fee: refundable_fee, ext: ext] + def encode_xdr!(%__MODULE__{ext: ext, resources: resources, refundable_fee: refundable_fee}) do + [ext: ext, resources: resources, refundable_fee: refundable_fee] |> XDR.Struct.new() |> XDR.Struct.encode_xdr!() end @@ -66,9 +66,9 @@ defmodule StellarBase.XDR.SorobanTransactionData do def decode_xdr(bytes, struct) do case XDR.Struct.decode_xdr(bytes, struct) do {:ok, - {%XDR.Struct{components: [resources: resources, refundable_fee: refundable_fee, ext: ext]}, + {%XDR.Struct{components: [ext: ext, resources: resources, refundable_fee: refundable_fee]}, rest}} -> - {:ok, {new(resources, refundable_fee, ext), rest}} + {:ok, {new(ext, resources, refundable_fee), rest}} error -> error @@ -79,9 +79,9 @@ defmodule StellarBase.XDR.SorobanTransactionData do def decode_xdr!(bytes, struct \\ @struct_spec) def decode_xdr!(bytes, struct) do - {%XDR.Struct{components: [resources: resources, refundable_fee: refundable_fee, ext: ext]}, + {%XDR.Struct{components: [ext: ext, resources: resources, refundable_fee: refundable_fee]}, rest} = XDR.Struct.decode_xdr!(bytes, struct) - {new(resources, refundable_fee, ext), rest} + {new(ext, resources, refundable_fee), rest} end end diff --git a/lib/xdr/transactions/upload_contract_wasm_args.ex b/lib/xdr/transactions/upload_contract_wasm_args.ex deleted file mode 100644 index 52b774b4..00000000 --- a/lib/xdr/transactions/upload_contract_wasm_args.ex +++ /dev/null @@ -1,61 +0,0 @@ -defmodule StellarBase.XDR.UploadContractWasmArgs do - @moduledoc """ - Automatically generated by xdrgen - DO NOT EDIT or your changes may be overwritten - - Target implementation: elixir_xdr at https://hex.pm/packages/elixir_xdr - - Representation of Stellar `UploadContractWasmArgs` type. - """ - - @behaviour XDR.Declaration - - alias StellarBase.XDR.VariableOpaque256000 - - @struct_spec XDR.Struct.new(code: VariableOpaque256000) - - @type code_type :: VariableOpaque256000.t() - - @type t :: %__MODULE__{code: code_type()} - - defstruct [:code] - - @spec new(code :: code_type()) :: t() - def new(%VariableOpaque256000{} = code), - do: %__MODULE__{code: code} - - @impl true - def encode_xdr(%__MODULE__{code: code}) do - [code: code] - |> XDR.Struct.new() - |> XDR.Struct.encode_xdr() - end - - @impl true - def encode_xdr!(%__MODULE__{code: code}) do - [code: code] - |> XDR.Struct.new() - |> XDR.Struct.encode_xdr!() - end - - @impl true - def decode_xdr(bytes, struct \\ @struct_spec) - - def decode_xdr(bytes, struct) do - case XDR.Struct.decode_xdr(bytes, struct) do - {:ok, {%XDR.Struct{components: [code: code]}, rest}} -> - {:ok, {new(code), rest}} - - error -> - error - end - end - - @impl true - def decode_xdr!(bytes, struct \\ @struct_spec) - - def decode_xdr!(bytes, struct) do - {%XDR.Struct{components: [code: code]}, rest} = XDR.Struct.decode_xdr!(bytes, struct) - {new(code), rest} - end -end diff --git a/lib/xdr/types/variable_opaque256000.ex b/lib/xdr/types/variable_opaque.ex similarity index 74% rename from lib/xdr/types/variable_opaque256000.ex rename to lib/xdr/types/variable_opaque.ex index 967c5e60..441357c9 100644 --- a/lib/xdr/types/variable_opaque256000.ex +++ b/lib/xdr/types/variable_opaque.ex @@ -1,6 +1,6 @@ -defmodule StellarBase.XDR.VariableOpaque256000 do +defmodule StellarBase.XDR.VariableOpaque do @moduledoc """ - Representation of Stellar `VariableOpaque256000` type. + Representation of Stellar `VariableOpaque` type. """ @behaviour XDR.Declaration @@ -9,9 +9,8 @@ defmodule StellarBase.XDR.VariableOpaque256000 do defstruct [:opaque] - @max_size 256_000 - - @opaque_spec XDR.VariableOpaque.new(nil, @max_size) + @opaque_spec XDR.VariableOpaque.new(nil) + @max_size 4_294_967_295 @spec new(opaque :: binary()) :: t() def new(opaque), do: %__MODULE__{opaque: opaque} @@ -31,8 +30,11 @@ defmodule StellarBase.XDR.VariableOpaque256000 do def decode_xdr(bytes, spec) do case XDR.VariableOpaque.decode_xdr(bytes, spec) do - {:ok, {%XDR.VariableOpaque{opaque: opaque}, rest}} -> {:ok, {new(opaque), rest}} - error -> error + {:ok, {%XDR.VariableOpaque{opaque: opaque, max_size: @max_size}, rest}} -> + {:ok, {new(opaque), rest}} + + error -> + error end end diff --git a/mix.exs b/mix.exs index 8b835867..c155eb0c 100644 --- a/mix.exs +++ b/mix.exs @@ -36,7 +36,7 @@ defmodule StellarBase.MixProject do # Run "mix help deps" to learn about dependencies. defp deps do [ - {:elixir_xdr, "~> 0.3.0"}, + {:elixir_xdr, "~> 0.3.9"}, {:crc, "~> 0.10.0"}, {:dialyxir, "~> 1.0", only: [:dev, :test], runtime: false}, {:excoveralls, "~> 0.16", only: :test, runtime: false}, diff --git a/mix.lock b/mix.lock index e6e15ed6..dae01ed1 100644 --- a/mix.lock +++ b/mix.lock @@ -7,7 +7,7 @@ "earmark_parser": {:hex, :earmark_parser, "1.4.29", "149d50dcb3a93d9f3d6f3ecf18c918fb5a2d3c001b5d3305c926cddfbd33355b", [:mix], [], "hexpm", "4902af1b3eb139016aed210888748db8070b8125c2342ce3dcae4f38dcc63503"}, "ed25519": {:hex, :ed25519, "1.3.2", "e3a2d4badf57f0799279cf09925bd761ec38df6df3696e266585626280b5c0ad", [:mix], [], "hexpm", "2290e46e0e23717adbe20632c6dd29aa71a46ca6e153ef7ba41fe1204f66f859"}, "elixir_make": {:hex, :elixir_make, "0.6.2", "7dffacd77dec4c37b39af867cedaabb0b59f6a871f89722c25b28fcd4bd70530", [:mix], [], "hexpm", "03e49eadda22526a7e5279d53321d1cced6552f344ba4e03e619063de75348d9"}, - "elixir_xdr": {:hex, :elixir_xdr, "0.3.8", "8b93ecdb67cee1e70529ad9ea69584d1a5107a17445a1d63c4557d12d5421847", [:mix], [], "hexpm", "f601e43f63059383aa9673f540386e8aba10395bc0dbbc4f01b4f1b751fd1fe4"}, + "elixir_xdr": {:hex, :elixir_xdr, "0.3.9", "d9c461a1c04bc31ccb36114b606c750d0ba0bed0a1d7ffc35d206e58faaba0ba", [:mix], [], "hexpm", "30afac1a82fafe11708e14d92532a83a881d1004ec92bf00e3d8a827c6685e3d"}, "erlex": {:hex, :erlex, "0.2.6", "c7987d15e899c7a2f34f5420d2a2ea0d659682c06ac607572df55a43753aa12e", [:mix], [], "hexpm", "2ed2e25711feb44d52b17d2780eabf998452f6efda104877a3881c2f8c0c0c75"}, "ex_doc": {:hex, :ex_doc, "0.29.1", "b1c652fa5f92ee9cf15c75271168027f92039b3877094290a75abcaac82a9f77", [:mix], [{:earmark_parser, "~> 1.4.19", [hex: :earmark_parser, repo: "hexpm", optional: false]}, {:makeup_elixir, "~> 0.14", [hex: :makeup_elixir, repo: "hexpm", optional: false]}, {:makeup_erlang, "~> 0.1", [hex: :makeup_erlang, repo: "hexpm", optional: false]}], "hexpm", "b7745fa6374a36daf484e2a2012274950e084815b936b1319aeebcf7809574f6"}, "excoveralls": {:hex, :excoveralls, "0.16.1", "0bd42ed05c7d2f4d180331a20113ec537be509da31fed5c8f7047ce59ee5a7c5", [:mix], [{:hackney, "~> 1.16", [hex: :hackney, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: false]}], "hexpm", "dae763468e2008cf7075a64cb1249c97cb4bc71e236c5c2b5e5cdf1cfa2bf138"}, diff --git a/test/xdr/contract/config_setting/contract_cost_param_entry_test.exs b/test/xdr/contract/config_setting/contract_cost_param_entry_test.exs index b71a8d8b..dad2de7c 100644 --- a/test/xdr/contract/config_setting/contract_cost_param_entry_test.exs +++ b/test/xdr/contract/config_setting/contract_cost_param_entry_test.exs @@ -10,9 +10,9 @@ defmodule StellarBase.XDR.ContractCostParamEntryTest do contract_cost_param_entry = ContractCostParamEntry.new( + ext, const_term, - linear_term, - ext + linear_term ) %{ @@ -20,7 +20,7 @@ defmodule StellarBase.XDR.ContractCostParamEntryTest do linear_term: linear_term, ext: ext, contract_cost_param_entry: contract_cost_param_entry, - binary: <<0, 0, 0, 0, 0, 0, 0, 10, 0, 0, 0, 0, 0, 0, 0, 10, 0, 0, 0, 0>> + binary: <<0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 10, 0, 0, 0, 0, 0, 0, 0, 10>> } end @@ -30,14 +30,14 @@ defmodule StellarBase.XDR.ContractCostParamEntryTest do ext: ext } do %ContractCostParamEntry{ + ext: ^ext, const_term: ^const_term, - linear_term: ^linear_term, - ext: ^ext + linear_term: ^linear_term } = ContractCostParamEntry.new( + ext, const_term, - linear_term, - ext + linear_term ) end diff --git a/test/xdr/contract/config_setting/contract_cost_params_test.exs b/test/xdr/contract/config_setting/contract_cost_params_test.exs index 13501d1b..b5abedd4 100644 --- a/test/xdr/contract/config_setting/contract_cost_params_test.exs +++ b/test/xdr/contract/config_setting/contract_cost_params_test.exs @@ -10,16 +10,16 @@ defmodule StellarBase.XDR.ContractCostParamsTest do contract_cost_param_entry1 = ContractCostParamEntry.new( + ext, const_term, - linear_term, - ext + linear_term ) contract_cost_param_entry2 = ContractCostParamEntry.new( + ext, const_term, - linear_term, - ext + linear_term ) param_entries = [contract_cost_param_entry1, contract_cost_param_entry2] @@ -29,8 +29,8 @@ defmodule StellarBase.XDR.ContractCostParamsTest do param_entries: param_entries, contract_cost_params: contract_cost_params, binary: - <<0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 10, 0, 0, 0, 0, 0, 0, 0, 10, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 10, 0, 0, 0, 0, 0, 0, 0, 10, 0, 0, 0, 0>> + <<0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 10, 0, 0, 0, 0, 0, 0, 0, 10, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 10, 0, 0, 0, 0, 0, 0, 0, 10>> } end diff --git a/test/xdr/contract/config_setting/contract_cost_type_test.exs b/test/xdr/contract/config_setting/contract_cost_type_test.exs index 462506a2..26a09d19 100644 --- a/test/xdr/contract/config_setting/contract_cost_type_test.exs +++ b/test/xdr/contract/config_setting/contract_cost_type_test.exs @@ -23,8 +23,18 @@ defmodule StellarBase.XDR.ContractCostTypeTest do :VmMemRead, :VmMemWrite, :VmInstantiation, + :VmCachedInstantiation, :InvokeVmFunction, - :ChargeBudget + :ChargeBudget, + :ComputeKeccak256Hash, + :ComputeEcdsaSecp256k1Key, + :ComputeEcdsaSecp256k1Sig, + :RecoverEcdsaSecp256k1Key, + :Int256AddSub, + :Int256Mul, + :Int256Div, + :Int256Pow, + :Int256Shift ] @binaries [ @@ -48,7 +58,17 @@ defmodule StellarBase.XDR.ContractCostTypeTest do <<0, 0, 0, 17>>, <<0, 0, 0, 18>>, <<0, 0, 0, 19>>, - <<0, 0, 0, 20>> + <<0, 0, 0, 20>>, + <<0, 0, 0, 21>>, + <<0, 0, 0, 22>>, + <<0, 0, 0, 23>>, + <<0, 0, 0, 24>>, + <<0, 0, 0, 25>>, + <<0, 0, 0, 26>>, + <<0, 0, 0, 27>>, + <<0, 0, 0, 28>>, + <<0, 0, 0, 29>>, + <<0, 0, 0, 30>> ] describe "ContractCostType" do diff --git a/test/xdr/contract/sc_bytes_test.exs b/test/xdr/contract/sc_bytes_test.exs index fa10ff30..fa40f862 100644 --- a/test/xdr/contract/sc_bytes_test.exs +++ b/test/xdr/contract/sc_bytes_test.exs @@ -37,15 +37,5 @@ defmodule StellarBase.XDR.SCBytesTest do test "decode_xdr!/2", %{sc_bytes: sc_bytes, binary: binary} do {^sc_bytes, ""} = SCBytes.decode_xdr!(binary) end - - test "invalid length" do - bits = 256_001 * 8 - binary = <<0::size(bits)>> - - {:error, :invalid_length} = - SCBytes.encode_xdr(%SCBytes{ - value: binary - }) - end end end diff --git a/test/xdr/contract/sc_contract_executable_test.exs b/test/xdr/contract/sc_contract_executable_test.exs deleted file mode 100644 index bfd42c86..00000000 --- a/test/xdr/contract/sc_contract_executable_test.exs +++ /dev/null @@ -1,79 +0,0 @@ -defmodule StellarBase.XDR.SCContractExecutableTest do - use ExUnit.Case - - alias StellarBase.XDR.{SCContractExecutable, SCContractExecutableType, Hash} - - describe "SCContractExecutable" do - setup do - contract_executable = Hash.new("GCIZ3GSM5XL7OUS4UP64THMDZ7CZ3ZWN") - - sc_contract_executable_type = SCContractExecutableType.new(:SCCONTRACT_EXECUTABLE_WASM_REF) - - %{ - contract_executable: contract_executable, - sc_contract_executable_type: sc_contract_executable_type, - sc_contract_executable: - SCContractExecutable.new(contract_executable, sc_contract_executable_type), - binary: - <<0, 0, 0, 0, 71, 67, 73, 90, 51, 71, 83, 77, 53, 88, 76, 55, 79, 85, 83, 52, 85, 80, - 54, 52, 84, 72, 77, 68, 90, 55, 67, 90, 51, 90, 87, 78>> - } - end - - test "new/1", %{ - contract_executable: contract_executable, - sc_contract_executable_type: sc_contract_executable_type - } do - %SCContractExecutable{ - contract_executable: ^contract_executable, - type: ^sc_contract_executable_type - } = SCContractExecutable.new(contract_executable, sc_contract_executable_type) - end - - test "encode_xdr/1", %{ - sc_contract_executable: sc_contract_executable, - binary: binary - } do - {:ok, ^binary} = SCContractExecutable.encode_xdr(sc_contract_executable) - end - - test "encode_xdr/1 with an invalid type", %{ - contract_executable: contract_executable - } do - sc_contract_executable_type = SCContractExecutableType.new(:NEW_CONTRACT) - - assert_raise XDR.EnumError, - "The key which you try to encode doesn't belong to the current declarations", - fn -> - contract_executable - |> SCContractExecutable.new(sc_contract_executable_type) - |> SCContractExecutable.encode_xdr() - end - end - - test "encode_xdr!/1", %{ - sc_contract_executable: sc_contract_executable, - binary: binary - } do - ^binary = SCContractExecutable.encode_xdr!(sc_contract_executable) - end - - test "decode_xdr/2", %{ - sc_contract_executable: sc_contract_executable, - binary: binary - } do - {:ok, {^sc_contract_executable, ""}} = SCContractExecutable.decode_xdr(binary) - end - - test "decode_xdr/2 with an invalid binary" do - {:error, :not_binary} = SCContractExecutable.decode_xdr(123) - end - - test "decode_xdr!/2", %{ - sc_contract_executable: sc_contract_executable, - binary: binary - } do - {^sc_contract_executable, ^binary} = SCContractExecutable.decode_xdr!(binary <> binary) - end - end -end diff --git a/test/xdr/contract/sc_contract_executable_type_test.exs b/test/xdr/contract/sc_contract_executable_type_test.exs deleted file mode 100644 index 3d427ef6..00000000 --- a/test/xdr/contract/sc_contract_executable_type_test.exs +++ /dev/null @@ -1,66 +0,0 @@ -defmodule StellarBase.XDR.SCContractExecutableTypeTest do - use ExUnit.Case - - alias StellarBase.XDR.SCContractExecutableType - - @codes [ - :SCCONTRACT_EXECUTABLE_WASM_REF, - :SCCONTRACT_EXECUTABLE_TOKEN - ] - - @binaries [ - <<0, 0, 0, 0>>, - <<0, 0, 0, 1>> - ] - - describe "SCContractExecutableType" do - setup do - %{ - codes: @codes, - results: Enum.map(@codes, &SCContractExecutableType.new/1), - binaries: @binaries - } - end - - test "new/1", %{codes: types} do - for type <- types, - do: %SCContractExecutableType{identifier: ^type} = SCContractExecutableType.new(type) - end - - test "encode_xdr/1", %{results: results, binaries: binaries} do - for {result, binary} <- Enum.zip(results, binaries), - do: {:ok, ^binary} = SCContractExecutableType.encode_xdr(result) - end - - test "encode_xdr/1 with an invalid code" do - {:error, :invalid_key} = - SCContractExecutableType.encode_xdr(%SCContractExecutableType{identifier: :TEST}) - end - - test "encode_xdr!/1", %{results: results, binaries: binaries} do - for {result, binary} <- Enum.zip(results, binaries), - do: ^binary = SCContractExecutableType.encode_xdr!(result) - end - - test "decode_xdr/2", %{results: results, binaries: binaries} do - for {result, binary} <- Enum.zip(results, binaries), - do: {:ok, {^result, ""}} = SCContractExecutableType.decode_xdr(binary) - end - - test "decode_xdr/2 with an invalid declaration" do - {:error, :invalid_key} = SCContractExecutableType.decode_xdr(<<1, 0, 0, 1>>) - end - - test "decode_xdr!/2", %{results: results, binaries: binaries} do - for {result, binary} <- Enum.zip(results, binaries), - do: {^result, ^binary} = SCContractExecutableType.decode_xdr!(binary <> binary) - end - - test "decode_xdr!/2 with an error code", %{binaries: binaries} do - for binary <- binaries, - do: - {%SCContractExecutableType{identifier: _}, ""} = - SCContractExecutableType.decode_xdr!(binary) - end - end -end diff --git a/test/xdr/contract/sc_host_auth_error_code_test.exs b/test/xdr/contract/sc_host_auth_error_code_test.exs deleted file mode 100644 index 09f4abf6..00000000 --- a/test/xdr/contract/sc_host_auth_error_code_test.exs +++ /dev/null @@ -1,49 +0,0 @@ -defmodule StellarBase.XDR.SCHostAuthErrorCodeTest do - use ExUnit.Case - - alias StellarBase.XDR.SCHostAuthErrorCode - - describe "SCHostAuthErrorCode" do - setup do - %{ - binary: <<0, 0, 0, 1>>, - identifier: :HOST_AUTH_NONCE_ERROR, - default_identifier: :HOST_AUTH_UNKNOWN_ERROR, - xdr_type: SCHostAuthErrorCode.new(:HOST_AUTH_NONCE_ERROR) - } - end - - test "new/1", %{identifier: type} do - %SCHostAuthErrorCode{identifier: ^type} = SCHostAuthErrorCode.new(type) - end - - test "new/1 with default value", %{default_identifier: type} do - %SCHostAuthErrorCode{identifier: ^type} = SCHostAuthErrorCode.new() - end - - test "encode_xdr/1", %{xdr_type: xdr_type, binary: binary} do - {:ok, ^binary} = SCHostAuthErrorCode.encode_xdr(xdr_type) - end - - test "encode_xdr!/1", %{xdr_type: xdr_type, binary: binary} do - ^binary = SCHostAuthErrorCode.encode_xdr!(xdr_type) - end - - test "decode_xdr/2", %{xdr_type: xdr_type, binary: binary} do - {:ok, {^xdr_type, ""}} = SCHostAuthErrorCode.decode_xdr(binary) - end - - test "decode_xdr/2 with an invalid binary" do - {:error, :not_binary} = SCHostAuthErrorCode.decode_xdr(123) - end - - test "decode_xdr!/2", %{xdr_type: xdr_type, binary: binary} do - {^xdr_type, ^binary} = SCHostAuthErrorCode.decode_xdr!(binary <> binary) - end - - test "invalid identifier" do - {:error, :invalid_key} = - SCHostAuthErrorCode.encode_xdr(%SCHostAuthErrorCode{identifier: :HOST_TEST}) - end - end -end diff --git a/test/xdr/contract/sc_host_context_error_code_test.exs b/test/xdr/contract/sc_host_context_error_code_test.exs deleted file mode 100644 index ba7bf077..00000000 --- a/test/xdr/contract/sc_host_context_error_code_test.exs +++ /dev/null @@ -1,49 +0,0 @@ -defmodule StellarBase.XDR.SCHostContextErrorCodeTest do - use ExUnit.Case - - alias StellarBase.XDR.SCHostContextErrorCode - - describe "SCHostContextErrorCode" do - setup do - %{ - binary: <<0, 0, 0, 1>>, - identifier: :HOST_CONTEXT_NO_CONTRACT_RUNNING, - default_identifier: :HOST_CONTEXT_UNKNOWN_ERROR, - xdr_type: SCHostContextErrorCode.new(:HOST_CONTEXT_NO_CONTRACT_RUNNING) - } - end - - test "new/1", %{identifier: type} do - %SCHostContextErrorCode{identifier: ^type} = SCHostContextErrorCode.new(type) - end - - test "new/1 with default value", %{default_identifier: type} do - %SCHostContextErrorCode{identifier: ^type} = SCHostContextErrorCode.new() - end - - test "encode_xdr/1", %{xdr_type: xdr_type, binary: binary} do - {:ok, ^binary} = SCHostContextErrorCode.encode_xdr(xdr_type) - end - - test "encode_xdr!/1", %{xdr_type: xdr_type, binary: binary} do - ^binary = SCHostContextErrorCode.encode_xdr!(xdr_type) - end - - test "decode_xdr/2", %{xdr_type: xdr_type, binary: binary} do - {:ok, {^xdr_type, ""}} = SCHostContextErrorCode.decode_xdr(binary) - end - - test "decode_xdr/2 with an invalid binary" do - {:error, :not_binary} = SCHostContextErrorCode.decode_xdr(123) - end - - test "decode_xdr!/2", %{xdr_type: xdr_type, binary: binary} do - {^xdr_type, ^binary} = SCHostContextErrorCode.decode_xdr!(binary <> binary) - end - - test "invalid identifier" do - {:error, :invalid_key} = - SCHostContextErrorCode.encode_xdr(%SCHostContextErrorCode{identifier: :HOST_TEST}) - end - end -end diff --git a/test/xdr/contract/sc_host_fn_error_code_test.exs b/test/xdr/contract/sc_host_fn_error_code_test.exs deleted file mode 100644 index e8c84100..00000000 --- a/test/xdr/contract/sc_host_fn_error_code_test.exs +++ /dev/null @@ -1,49 +0,0 @@ -defmodule StellarBase.XDR.SCHostFnErrorCodeTest do - use ExUnit.Case - - alias StellarBase.XDR.SCHostFnErrorCode - - describe "SCHostFnErrorCode" do - setup do - %{ - binary: <<0, 0, 0, 1>>, - identifier: :HOST_FN_UNEXPECTED_HOST_FUNCTION_ACTION, - default_identifier: :HOST_FN_UNKNOWN_ERROR, - xdr_type: SCHostFnErrorCode.new(:HOST_FN_UNEXPECTED_HOST_FUNCTION_ACTION) - } - end - - test "new/1", %{identifier: type} do - %SCHostFnErrorCode{identifier: ^type} = SCHostFnErrorCode.new(type) - end - - test "new/1 with default value", %{default_identifier: type} do - %SCHostFnErrorCode{identifier: ^type} = SCHostFnErrorCode.new() - end - - test "encode_xdr/1", %{xdr_type: xdr_type, binary: binary} do - {:ok, ^binary} = SCHostFnErrorCode.encode_xdr(xdr_type) - end - - test "encode_xdr!/1", %{xdr_type: xdr_type, binary: binary} do - ^binary = SCHostFnErrorCode.encode_xdr!(xdr_type) - end - - test "decode_xdr/2", %{xdr_type: xdr_type, binary: binary} do - {:ok, {^xdr_type, ""}} = SCHostFnErrorCode.decode_xdr(binary) - end - - test "decode_xdr/2 with an invalid binary" do - {:error, :not_binary} = SCHostFnErrorCode.decode_xdr(123) - end - - test "decode_xdr!/2", %{xdr_type: xdr_type, binary: binary} do - {^xdr_type, ^binary} = SCHostFnErrorCode.decode_xdr!(binary <> binary) - end - - test "invalid identifier" do - {:error, :invalid_key} = - SCHostFnErrorCode.encode_xdr(%SCHostFnErrorCode{identifier: :HOST_TEST}) - end - end -end diff --git a/test/xdr/contract/sc_host_obj_error_code_test.exs b/test/xdr/contract/sc_host_obj_error_code_test.exs deleted file mode 100644 index a2195a4b..00000000 --- a/test/xdr/contract/sc_host_obj_error_code_test.exs +++ /dev/null @@ -1,49 +0,0 @@ -defmodule StellarBase.XDR.SCHostObjErrorCodeTest do - use ExUnit.Case - - alias StellarBase.XDR.SCHostObjErrorCode - - describe "SCHostObjErrorCode" do - setup do - %{ - binary: <<0, 0, 0, 1>>, - identifier: :HOST_OBJECT_UNKNOWN_REFERENCE, - default_identifier: :HOST_OBJECT_UNKNOWN_ERROR, - xdr_type: SCHostObjErrorCode.new(:HOST_OBJECT_UNKNOWN_REFERENCE) - } - end - - test "new/1", %{identifier: type} do - %SCHostObjErrorCode{identifier: ^type} = SCHostObjErrorCode.new(type) - end - - test "new/1 with default value", %{default_identifier: type} do - %SCHostObjErrorCode{identifier: ^type} = SCHostObjErrorCode.new() - end - - test "encode_xdr/1", %{xdr_type: xdr_type, binary: binary} do - {:ok, ^binary} = SCHostObjErrorCode.encode_xdr(xdr_type) - end - - test "encode_xdr!/1", %{xdr_type: xdr_type, binary: binary} do - ^binary = SCHostObjErrorCode.encode_xdr!(xdr_type) - end - - test "decode_xdr/2", %{xdr_type: xdr_type, binary: binary} do - {:ok, {^xdr_type, ""}} = SCHostObjErrorCode.decode_xdr(binary) - end - - test "decode_xdr/2 with an invalid binary" do - {:error, :not_binary} = SCHostObjErrorCode.decode_xdr(123) - end - - test "decode_xdr!/2", %{xdr_type: xdr_type, binary: binary} do - {^xdr_type, ^binary} = SCHostObjErrorCode.decode_xdr!(binary <> binary) - end - - test "invalid identifier" do - {:error, :invalid_key} = - SCHostObjErrorCode.encode_xdr(%SCHostObjErrorCode{identifier: :HOST_TEST}) - end - end -end diff --git a/test/xdr/contract/sc_host_storage_error_code_test.exs b/test/xdr/contract/sc_host_storage_error_code_test.exs deleted file mode 100644 index 6e8928f5..00000000 --- a/test/xdr/contract/sc_host_storage_error_code_test.exs +++ /dev/null @@ -1,49 +0,0 @@ -defmodule StellarBase.XDR.SCHostStorageErrorCodeTest do - use ExUnit.Case - - alias StellarBase.XDR.SCHostStorageErrorCode - - describe "SCHostStorageErrorCode" do - setup do - %{ - binary: <<0, 0, 0, 1>>, - identifier: :HOST_STORAGE_EXPECT_CONTRACT_DATA, - default_identifier: :HOST_STORAGE_UNKNOWN_ERROR, - xdr_type: SCHostStorageErrorCode.new(:HOST_STORAGE_EXPECT_CONTRACT_DATA) - } - end - - test "new/1", %{identifier: type} do - %SCHostStorageErrorCode{identifier: ^type} = SCHostStorageErrorCode.new(type) - end - - test "new/1 with default value", %{default_identifier: type} do - %SCHostStorageErrorCode{identifier: ^type} = SCHostStorageErrorCode.new() - end - - test "encode_xdr/1", %{xdr_type: xdr_type, binary: binary} do - {:ok, ^binary} = SCHostStorageErrorCode.encode_xdr(xdr_type) - end - - test "encode_xdr!/1", %{xdr_type: xdr_type, binary: binary} do - ^binary = SCHostStorageErrorCode.encode_xdr!(xdr_type) - end - - test "decode_xdr/2", %{xdr_type: xdr_type, binary: binary} do - {:ok, {^xdr_type, ""}} = SCHostStorageErrorCode.decode_xdr(binary) - end - - test "decode_xdr/2 with an invalid binary" do - {:error, :not_binary} = SCHostStorageErrorCode.decode_xdr(123) - end - - test "decode_xdr!/2", %{xdr_type: xdr_type, binary: binary} do - {^xdr_type, ^binary} = SCHostStorageErrorCode.decode_xdr!(binary <> binary) - end - - test "invalid identifier" do - {:error, :invalid_key} = - SCHostStorageErrorCode.encode_xdr(%SCHostStorageErrorCode{identifier: :HOST_TEST}) - end - end -end diff --git a/test/xdr/contract/sc_host_val_error_code_test.exs b/test/xdr/contract/sc_host_val_error_code_test.exs deleted file mode 100644 index 72493aeb..00000000 --- a/test/xdr/contract/sc_host_val_error_code_test.exs +++ /dev/null @@ -1,49 +0,0 @@ -defmodule StellarBase.XDR.SCHostValErrorCodeTest do - use ExUnit.Case - - alias StellarBase.XDR.SCHostValErrorCode - - describe "SCHostValErrorCode" do - setup do - %{ - binary: <<0, 0, 0, 1>>, - identifier: :HOST_VALUE_RESERVED_TAG_VALUE, - default_identifier: :HOST_VALUE_UNKNOWN_ERROR, - xdr_type: SCHostValErrorCode.new(:HOST_VALUE_RESERVED_TAG_VALUE) - } - end - - test "new/1", %{identifier: type} do - %SCHostValErrorCode{identifier: ^type} = SCHostValErrorCode.new(type) - end - - test "new/1 with default value", %{default_identifier: type} do - %SCHostValErrorCode{identifier: ^type} = SCHostValErrorCode.new() - end - - test "encode_xdr/1", %{xdr_type: xdr_type, binary: binary} do - {:ok, ^binary} = SCHostValErrorCode.encode_xdr(xdr_type) - end - - test "encode_xdr!/1", %{xdr_type: xdr_type, binary: binary} do - ^binary = SCHostValErrorCode.encode_xdr!(xdr_type) - end - - test "decode_xdr/2", %{xdr_type: xdr_type, binary: binary} do - {:ok, {^xdr_type, ""}} = SCHostValErrorCode.decode_xdr(binary) - end - - test "decode_xdr/2 with an invalid binary" do - {:error, :not_binary} = SCHostValErrorCode.decode_xdr(123) - end - - test "decode_xdr!/2", %{xdr_type: xdr_type, binary: binary} do - {^xdr_type, ^binary} = SCHostValErrorCode.decode_xdr!(binary <> binary) - end - - test "invalid identifier" do - {:error, :invalid_key} = - SCHostValErrorCode.encode_xdr(%SCHostValErrorCode{identifier: :HOST_TEST}) - end - end -end diff --git a/test/xdr/contract/sc_map_test.exs b/test/xdr/contract/sc_map_test.exs index 35d2f9ad..cd4c4ce4 100644 --- a/test/xdr/contract/sc_map_test.exs +++ b/test/xdr/contract/sc_map_test.exs @@ -31,7 +31,7 @@ defmodule StellarBase.XDR.SCMapTest do end test "new/1", %{scmap_entries: scmap_entries} do - %SCMap{scmap_entries: ^scmap_entries} = SCMap.new(scmap_entries) + %SCMap{items: ^scmap_entries} = SCMap.new(scmap_entries) end test "encode_xdr/1", %{scmap: scmap, binary: binary} do diff --git a/test/xdr/contract/sc_nonce_key_test.exs b/test/xdr/contract/sc_nonce_key_test.exs index 7da60652..e9bbdfbc 100644 --- a/test/xdr/contract/sc_nonce_key_test.exs +++ b/test/xdr/contract/sc_nonce_key_test.exs @@ -1,45 +1,24 @@ defmodule StellarBase.XDR.SCNonceKeyTest do use ExUnit.Case - alias StellarBase.StrKey - alias StellarBase.XDR.{ - AccountID, - SCNonceKey, - PublicKeyType, - PublicKey, - SCAddressType, - SCAddress, - UInt256 + Int64, + SCNonceKey } describe "SCNonceKey" do setup do - pk_type = PublicKeyType.new(:PUBLIC_KEY_TYPE_ED25519) - - account_id = - "GBZNLMUQMIN3VGUJISKZU7GNY3O3XLMYEHJCKCSMDHKLGSMKALRXOEZD" - |> StrKey.decode!(:ed25519_public_key) - |> UInt256.new() - |> PublicKey.new(pk_type) - |> AccountID.new() - - sc_address_type = SCAddressType.new(:SC_ADDRESS_TYPE_ACCOUNT) - - sc_address = SCAddress.new(account_id, sc_address_type) + nonce = Int64.new(231_385) %{ - sc_address: sc_address, - sc_nonce_key: SCNonceKey.new(sc_address), - binary: - <<0, 0, 0, 0, 0, 0, 0, 0, 114, 213, 178, 144, 98, 27, 186, 154, 137, 68, 149, 154, 124, - 205, 198, 221, 187, 173, 152, 33, 210, 37, 10, 76, 25, 212, 179, 73, 138, 2, 227, - 119>> + nonce: nonce, + sc_nonce_key: SCNonceKey.new(nonce), + binary: <<0, 0, 0, 0, 0, 3, 135, 217>> } end - test "new/1", %{sc_address: sc_address} do - %SCNonceKey{nonce_address: ^sc_address} = SCNonceKey.new(sc_address) + test "new/1", %{nonce: nonce} do + %SCNonceKey{nonce: ^nonce} = SCNonceKey.new(nonce) end test "encode_xdr/1", %{sc_nonce_key: sc_nonce_key, binary: binary} do diff --git a/test/xdr/contract/sc_status_test.exs b/test/xdr/contract/sc_status_test.exs deleted file mode 100644 index 9f787e3a..00000000 --- a/test/xdr/contract/sc_status_test.exs +++ /dev/null @@ -1,117 +0,0 @@ -defmodule StellarBase.XDR.SCStatusTest do - use ExUnit.Case - - alias StellarBase.XDR.SCStatus - alias StellarBase.XDR.SCStatusType - - alias StellarBase.XDR.{ - SCUnknownErrorCode, - SCHostValErrorCode, - SCHostObjErrorCode, - SCHostFnErrorCode, - SCHostStorageErrorCode, - SCHostContextErrorCode, - SCVmErrorCode, - SCHostAuthErrorCode, - SCStatusType, - UInt32, - Void - } - - describe "SCStatus" do - setup do - discriminants = [ - %{ - status_type: SCStatusType.new(:SST_OK), - sc_code: Void.new(), - binary: <<0, 0, 0, 0>> - }, - %{ - status_type: SCStatusType.new(:SST_UNKNOWN_ERROR), - sc_code: SCUnknownErrorCode.new(:UNKNOWN_ERROR_GENERAL), - binary: <<0, 0, 0, 1, 0, 0, 0, 0>> - }, - %{ - status_type: SCStatusType.new(:SST_HOST_VALUE_ERROR), - sc_code: SCHostValErrorCode.new(:HOST_VALUE_UNKNOWN_ERROR), - binary: <<0, 0, 0, 2, 0, 0, 0, 0>> - }, - %{ - status_type: SCStatusType.new(:SST_HOST_OBJECT_ERROR), - sc_code: SCHostObjErrorCode.new(:HOST_OBJECT_UNKNOWN_ERROR), - binary: <<0, 0, 0, 3, 0, 0, 0, 0>> - }, - %{ - status_type: SCStatusType.new(:SST_HOST_FUNCTION_ERROR), - sc_code: SCHostFnErrorCode.new(:HOST_FN_UNKNOWN_ERROR), - binary: <<0, 0, 0, 4, 0, 0, 0, 0>> - }, - %{ - status_type: SCStatusType.new(:SST_HOST_STORAGE_ERROR), - sc_code: SCHostStorageErrorCode.new(:HOST_STORAGE_UNKNOWN_ERROR), - binary: <<0, 0, 0, 5, 0, 0, 0, 0>> - }, - %{ - status_type: SCStatusType.new(:SST_HOST_CONTEXT_ERROR), - sc_code: SCHostContextErrorCode.new(:HOST_CONTEXT_UNKNOWN_ERROR), - binary: <<0, 0, 0, 6, 0, 0, 0, 0>> - }, - %{ - status_type: SCStatusType.new(:SST_VM_ERROR), - sc_code: SCVmErrorCode.new(:VM_UNKNOWN), - binary: <<0, 0, 0, 7, 0, 0, 0, 0>> - }, - %{ - status_type: SCStatusType.new(:SST_CONTRACT_ERROR), - sc_code: UInt32.new(3312), - binary: <<0, 0, 0, 8, 0, 0, 12, 240>> - }, - %{ - status_type: SCStatusType.new(:SST_HOST_AUTH_ERROR), - sc_code: SCHostAuthErrorCode.new(:HOST_AUTH_UNKNOWN_ERROR), - binary: <<0, 0, 0, 9, 0, 0, 0, 0>> - } - ] - - %{discriminants: discriminants} - end - - test "new/1", %{discriminants: discriminants} do - for %{status_type: status_type, sc_code: sc_code} <- discriminants do - %SCStatus{code: ^sc_code, type: ^status_type} = SCStatus.new(sc_code, status_type) - end - end - - test "encode_xdr/1", %{discriminants: discriminants} do - for %{sc_code: sc_code, status_type: status_type, binary: binary} <- discriminants do - xdr = SCStatus.new(sc_code, status_type) - {:ok, ^binary} = SCStatus.encode_xdr(xdr) - end - end - - test "encode_xdr!/1", %{discriminants: discriminants} do - for %{sc_code: sc_code, status_type: status_type, binary: binary} <- discriminants do - xdr = SCStatus.new(sc_code, status_type) - ^binary = SCStatus.encode_xdr!(xdr) - end - end - - test "decode_xdr/2", %{discriminants: discriminants} do - for %{sc_code: sc_code, status_type: status_type, binary: binary} <- discriminants do - xdr = SCStatus.new(sc_code, status_type) - {:ok, {^xdr, ""}} = SCStatus.decode_xdr(binary) - end - end - - test "decode_xdr/2 with an invalid binary" do - {:error, :not_binary} = SCStatus.decode_xdr(123) - end - - test "decode_xdr!/2", %{discriminants: discriminants} do - for %{sc_code: sc_code, status_type: status_type, binary: binary} <- discriminants do - xdr = SCStatus.new(sc_code, status_type) - {^xdr, ""} = SCStatus.decode_xdr!(binary) - end - end - end -end diff --git a/test/xdr/contract/sc_status_type_test.exs b/test/xdr/contract/sc_status_type_test.exs deleted file mode 100644 index 37cb2f9a..00000000 --- a/test/xdr/contract/sc_status_type_test.exs +++ /dev/null @@ -1,48 +0,0 @@ -defmodule StellarBase.XDR.SCStatusTypeTest do - use ExUnit.Case - - alias StellarBase.XDR.SCStatusType - - describe "SCStatusType" do - setup do - %{ - binary: <<0, 0, 0, 1>>, - identifier: :SST_UNKNOWN_ERROR, - default_identifier: :SST_OK, - xdr_type: SCStatusType.new(:SST_UNKNOWN_ERROR) - } - end - - test "new/1", %{identifier: type} do - %SCStatusType{identifier: ^type} = SCStatusType.new(type) - end - - test "new/1 with default value", %{default_identifier: type} do - %SCStatusType{identifier: ^type} = SCStatusType.new() - end - - test "encode_xdr/1", %{xdr_type: xdr_type, binary: binary} do - {:ok, ^binary} = SCStatusType.encode_xdr(xdr_type) - end - - test "encode_xdr!/1", %{xdr_type: xdr_type, binary: binary} do - ^binary = SCStatusType.encode_xdr!(xdr_type) - end - - test "decode_xdr/2", %{xdr_type: xdr_type, binary: binary} do - {:ok, {^xdr_type, ""}} = SCStatusType.decode_xdr(binary) - end - - test "decode_xdr/2 with an invalid binary" do - {:error, :not_binary} = SCStatusType.decode_xdr(123) - end - - test "decode_xdr!/2", %{xdr_type: xdr_type, binary: binary} do - {^xdr_type, ^binary} = SCStatusType.decode_xdr!(binary <> binary) - end - - test "invalid identifier" do - {:error, :invalid_key} = SCStatusType.encode_xdr(%SCStatusType{identifier: :SST_TEST}) - end - end -end diff --git a/test/xdr/contract/sc_string_test.exs b/test/xdr/contract/sc_string_test.exs index 8542b3ac..6dced43e 100644 --- a/test/xdr/contract/sc_string_test.exs +++ b/test/xdr/contract/sc_string_test.exs @@ -26,33 +26,10 @@ defmodule StellarBase.XDR.SCStringTest do |> SCString.encode_xdr() end - test "encode_xdr/1 an invalid string length" do - bits = 256_001 * 8 - large_string = <<64::size(bits)>> - - {:error, :invalid_length} = - large_string - |> SCString.new() - |> SCString.encode_xdr() - end - test "encode_xdr!/1", %{sc_symbol: sc_symbol, binary: binary} do ^binary = SCString.encode_xdr!(sc_symbol) end - test "encode_xdr!/1 a string longer than 256000-bytes" do - bits = 256_001 * 8 - large_string = <<64::size(bits)>> - - assert_raise XDR.StringError, - "The length of the string exceeds the max length allowed", - fn -> - large_string - |> SCString.new() - |> SCString.encode_xdr!() - end - end - test "decode_xdr/2", %{sc_symbol: sc_symbol, binary: binary} do {:ok, {^sc_symbol, ""}} = SCString.decode_xdr(binary) end diff --git a/test/xdr/contract/sc_unknown_error_code_test.exs b/test/xdr/contract/sc_unknown_error_code_test.exs deleted file mode 100644 index d4afda07..00000000 --- a/test/xdr/contract/sc_unknown_error_code_test.exs +++ /dev/null @@ -1,49 +0,0 @@ -defmodule StellarBase.XDR.SCUnknownErrorCodeTest do - use ExUnit.Case - - alias StellarBase.XDR.SCUnknownErrorCode - - describe "SCUnknownErrorCode" do - setup do - %{ - binary: <<0, 0, 0, 1>>, - identifier: :UNKNOWN_ERROR_XDR, - default_identifier: :UNKNOWN_ERROR_GENERAL, - xdr_type: SCUnknownErrorCode.new(:UNKNOWN_ERROR_XDR) - } - end - - test "new/1", %{identifier: type} do - %SCUnknownErrorCode{identifier: ^type} = SCUnknownErrorCode.new(type) - end - - test "new/1 with default value", %{default_identifier: type} do - %SCUnknownErrorCode{identifier: ^type} = SCUnknownErrorCode.new() - end - - test "encode_xdr/1", %{xdr_type: xdr_type, binary: binary} do - {:ok, ^binary} = SCUnknownErrorCode.encode_xdr(xdr_type) - end - - test "encode_xdr!/1", %{xdr_type: xdr_type, binary: binary} do - ^binary = SCUnknownErrorCode.encode_xdr!(xdr_type) - end - - test "decode_xdr/2", %{xdr_type: xdr_type, binary: binary} do - {:ok, {^xdr_type, ""}} = SCUnknownErrorCode.decode_xdr(binary) - end - - test "decode_xdr/2 with an invalid binary" do - {:error, :not_binary} = SCUnknownErrorCode.decode_xdr(123) - end - - test "decode_xdr!/2", %{xdr_type: xdr_type, binary: binary} do - {^xdr_type, ^binary} = SCUnknownErrorCode.decode_xdr!(binary <> binary) - end - - test "invalid identifier" do - {:error, :invalid_key} = - SCUnknownErrorCode.encode_xdr(%SCUnknownErrorCode{identifier: :UNKNOWN_ERROR_TEST}) - end - end -end diff --git a/test/xdr/contract/sc_val_test.exs b/test/xdr/contract/sc_val_test.exs index ad69a158..d55cdc0a 100644 --- a/test/xdr/contract/sc_val_test.exs +++ b/test/xdr/contract/sc_val_test.exs @@ -1,6 +1,7 @@ defmodule StellarBase.XDR.SCValTest do use ExUnit.Case + alias StellarBase.XDR.SCContractInstance alias StellarBase.StrKey alias StellarBase.XDR.{ @@ -19,15 +20,15 @@ defmodule StellarBase.XDR.SCValTest do PublicKey, SCBytes, SCNonceKey, - SCContractExecutable, - SCContractExecutableType, + ContractExecutable, + ContractExecutableType, SCVal, SCValType, - SCStatus, - SCStatusType, + SCError, + SCErrorCode, SCString, SCSymbol, - SCUnknownErrorCode, + SCErrorType, TimePoint, UInt32, UInt64, @@ -54,13 +55,15 @@ defmodule StellarBase.XDR.SCValTest do sc_address_type = SCAddressType.new(:SC_ADDRESS_TYPE_ACCOUNT) sc_address = SCAddress.new(account_id, sc_address_type) - # SCContractExecutable - sc_contract_executable_type = SCContractExecutableType.new(:SCCONTRACT_EXECUTABLE_WASM_REF) + # ContractExecutable + sc_contract_executable_type = ContractExecutableType.new(:CONTRACT_EXECUTABLE_WASM) sc_contract_executable = "GCIZ3GSM5XL7OUS4UP64THMDZ7CZ3ZWN" |> Hash.new() - |> SCContractExecutable.new(sc_contract_executable_type) + |> ContractExecutable.new(sc_contract_executable_type) + + sc_contract_instance = SCContractInstance.new(sc_contract_executable, OptionalSCMap.new()) discriminants = [ %{ @@ -74,13 +77,13 @@ defmodule StellarBase.XDR.SCValTest do binary: <<0, 0, 0, 1>> }, %{ - val_type: SCValType.new(:SCV_STATUS), + val_type: SCValType.new(:SCV_ERROR), value: - SCStatus.new( - SCUnknownErrorCode.new(:UNKNOWN_ERROR_GENERAL), - SCStatusType.new(:SST_UNKNOWN_ERROR) + SCError.new( + SCErrorType.new(), + SCErrorCode.new() ), - binary: <<0, 0, 0, 2, 0, 0, 0, 1, 0, 0, 0, 0>> + binary: <<0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0>> }, %{ val_type: SCValType.new(:SCV_U32), @@ -169,32 +172,29 @@ defmodule StellarBase.XDR.SCValTest do binary: <<0, 0, 0, 17, 0, 0, 0, 0>> }, %{ - val_type: SCValType.new(:SCV_CONTRACT_EXECUTABLE), - value: sc_contract_executable, + val_type: SCValType.new(:SCV_CONTRACT_INSTANCE), + value: sc_contract_instance, binary: - <<0, 0, 0, 18, 0, 0, 0, 0, 71, 67, 73, 90, 51, 71, 83, 77, 53, 88, 76, 55, 79, 85, 83, - 52, 85, 80, 54, 52, 84, 72, 77, 68, 90, 55, 67, 90, 51, 90, 87, 78>> + <<0, 0, 0, 19, 0, 0, 0, 0, 71, 67, 73, 90, 51, 71, 83, 77, 53, 88, 76, 55, 79, 85, 83, + 52, 85, 80, 54, 52, 84, 72, 77, 68, 90, 55, 67, 90, 51, 90, 87, 78, 0, 0, 0, 0>> }, %{ val_type: SCValType.new(:SCV_ADDRESS), value: sc_address, binary: - <<0, 0, 0, 19, 0, 0, 0, 0, 0, 0, 0, 0, 114, 213, 178, 144, 98, 27, 186, 154, 137, 68, + <<0, 0, 0, 18, 0, 0, 0, 0, 0, 0, 0, 0, 114, 213, 178, 144, 98, 27, 186, 154, 137, 68, 149, 154, 124, 205, 198, 221, 187, 173, 152, 33, 210, 37, 10, 76, 25, 212, 179, 73, 138, 2, 227, 119>> }, %{ - val_type: SCValType.new(:SCV_LEDGER_KEY_CONTRACT_EXECUTABLE), + val_type: SCValType.new(:SCV_LEDGER_KEY_CONTRACT_INSTANCE), value: Void.new(), binary: <<0, 0, 0, 20>> }, %{ val_type: SCValType.new(:SCV_LEDGER_KEY_NONCE), - value: SCNonceKey.new(sc_address), - binary: - <<0, 0, 0, 21, 0, 0, 0, 0, 0, 0, 0, 0, 114, 213, 178, 144, 98, 27, 186, 154, 137, 68, - 149, 154, 124, 205, 198, 221, 187, 173, 152, 33, 210, 37, 10, 76, 25, 212, 179, 73, - 138, 2, 227, 119>> + value: SCNonceKey.new(Int64.new(21_658)), + binary: <<0, 0, 0, 21, 0, 0, 0, 0, 0, 0, 84, 154>> } ] diff --git a/test/xdr/contract/sc_vec_test.exs b/test/xdr/contract/sc_vec_test.exs index e5cbb4bf..90c1b6be 100644 --- a/test/xdr/contract/sc_vec_test.exs +++ b/test/xdr/contract/sc_vec_test.exs @@ -24,7 +24,7 @@ defmodule StellarBase.XDR.SCVecTest do end test "new/1", %{sc_vals: sc_vals} do - %SCVec{sc_vals: ^sc_vals} = SCVec.new(sc_vals) + %SCVec{items: ^sc_vals} = SCVec.new(sc_vals) end test "encode_xdr/1", %{scvec: scvec, binary: binary} do diff --git a/test/xdr/contract/sc_vm_error_code_test.exs b/test/xdr/contract/sc_vm_error_code_test.exs deleted file mode 100644 index 7718ba50..00000000 --- a/test/xdr/contract/sc_vm_error_code_test.exs +++ /dev/null @@ -1,48 +0,0 @@ -defmodule StellarBase.XDR.SCVmErrorCodeTest do - use ExUnit.Case - - alias StellarBase.XDR.SCVmErrorCode - - describe "SCVmErrorCode" do - setup do - %{ - binary: <<0, 0, 0, 1>>, - identifier: :VM_VALIDATION, - default_identifier: :VM_UNKNOWN, - xdr_type: SCVmErrorCode.new(:VM_VALIDATION) - } - end - - test "new/1", %{identifier: type} do - %SCVmErrorCode{identifier: ^type} = SCVmErrorCode.new(type) - end - - test "new/1 with default value", %{default_identifier: type} do - %SCVmErrorCode{identifier: ^type} = SCVmErrorCode.new() - end - - test "encode_xdr/1", %{xdr_type: xdr_type, binary: binary} do - {:ok, ^binary} = SCVmErrorCode.encode_xdr(xdr_type) - end - - test "encode_xdr!/1", %{xdr_type: xdr_type, binary: binary} do - ^binary = SCVmErrorCode.encode_xdr!(xdr_type) - end - - test "decode_xdr/2", %{xdr_type: xdr_type, binary: binary} do - {:ok, {^xdr_type, ""}} = SCVmErrorCode.decode_xdr(binary) - end - - test "decode_xdr/2 with an invalid binary" do - {:error, :not_binary} = SCVmErrorCode.decode_xdr(123) - end - - test "decode_xdr!/2", %{xdr_type: xdr_type, binary: binary} do - {^xdr_type, ^binary} = SCVmErrorCode.decode_xdr!(binary <> binary) - end - - test "invalid identifier" do - {:error, :invalid_key} = SCVmErrorCode.encode_xdr(%SCVmErrorCode{identifier: :VM_TEST}) - end - end -end diff --git a/test/xdr/contract/spec/sc_spec_type_def_test.exs b/test/xdr/contract/spec/sc_spec_type_def_test.exs index babf6835..4e387d5a 100644 --- a/test/xdr/contract/spec/sc_spec_type_def_test.exs +++ b/test/xdr/contract/spec/sc_spec_type_def_test.exs @@ -43,7 +43,7 @@ defmodule StellarBase.XDR.SCSpecTypeDefTest do binary: <<0, 0, 0, 2>> }, %{ - status_type: SCSpecType.new(:SC_SPEC_TYPE_STATUS), + status_type: SCSpecType.new(:SC_SPEC_TYPE_ERROR), sc_code: Void.new(), binary: <<0, 0, 0, 3>> }, @@ -181,7 +181,7 @@ defmodule StellarBase.XDR.SCSpecTypeDefTest do test "new/2", %{discriminants: discriminants} do for %{status_type: status_type, sc_code: sc_code} <- discriminants do - %SCSpecTypeDef{code: ^sc_code, type: ^status_type} = + %SCSpecTypeDef{value: ^sc_code, type: ^status_type} = SCSpecTypeDef.new(sc_code, status_type) end end diff --git a/test/xdr/contract/spec/sc_spec_type_test.exs b/test/xdr/contract/spec/sc_spec_type_test.exs index 4b8799ea..726249a8 100644 --- a/test/xdr/contract/spec/sc_spec_type_test.exs +++ b/test/xdr/contract/spec/sc_spec_type_test.exs @@ -7,7 +7,7 @@ defmodule StellarBase.XDR.SCSpecTypeTest do :SC_SPEC_TYPE_VAL, :SC_SPEC_TYPE_BOOL, :SC_SPEC_TYPE_VOID, - :SC_SPEC_TYPE_STATUS, + :SC_SPEC_TYPE_ERROR, :SC_SPEC_TYPE_U32, :SC_SPEC_TYPE_I32, :SC_SPEC_TYPE_U64, diff --git a/test/xdr/ledger_entries/contract_code_entry_test.exs b/test/xdr/ledger_entries/contract_code_entry_test.exs index 4dd0f23a..42f1b036 100644 --- a/test/xdr/ledger_entries/contract_code_entry_test.exs +++ b/test/xdr/ledger_entries/contract_code_entry_test.exs @@ -3,9 +3,12 @@ defmodule StellarBase.XDR.ContractCodeEntryTest do alias StellarBase.XDR.{ ContractCodeEntry, + ContractCodeEntryBody, + ContractEntryBodyType, ExtensionPoint, Hash, - VariableOpaque256000, + UInt32, + VariableOpaque, Void } @@ -13,30 +16,36 @@ defmodule StellarBase.XDR.ContractCodeEntryTest do setup do ext = ExtensionPoint.new(Void.new(), 0) hash = Hash.new("GCIZ3GSM5XL7OUS4UP64THMDZ7CZ3ZWN") - code = VariableOpaque256000.new("GCIZ3GSM5") + code = VariableOpaque.new("GCIZ3GSM5") + type = ContractEntryBodyType.new() + body = ContractCodeEntryBody.new(code, type) + expiration_ledger_seq = UInt32.new(123) %{ ext: ext, hash: hash, - code: code, - contract_code_entry: ContractCodeEntry.new(hash, code, ext), + body: body, + expiration_ledger_seq: expiration_ledger_seq, + contract_code_entry: ContractCodeEntry.new(ext, hash, body, expiration_ledger_seq), binary: - <<71, 67, 73, 90, 51, 71, 83, 77, 53, 88, 76, 55, 79, 85, 83, 52, 85, 80, 54, 52, 84, - 72, 77, 68, 90, 55, 67, 90, 51, 90, 87, 78, 0, 0, 0, 9, 71, 67, 73, 90, 51, 71, 83, - 77, 53, 0, 0, 0, 0, 0, 0, 0>> + <<0, 0, 0, 0, 71, 67, 73, 90, 51, 71, 83, 77, 53, 88, 76, 55, 79, 85, 83, 52, 85, 80, + 54, 52, 84, 72, 77, 68, 90, 55, 67, 90, 51, 90, 87, 78, 0, 0, 0, 0, 0, 0, 0, 9, 71, + 67, 73, 90, 51, 71, 83, 77, 53, 0, 0, 0, 0, 0, 0, 123>> } end test "new/1", %{ ext: ext, hash: hash, - code: code + body: body, + expiration_ledger_seq: expiration_ledger_seq } do %ContractCodeEntry{ hash: ^hash, - code: ^code, - ext: ^ext - } = ContractCodeEntry.new(hash, code, ext) + body: ^body, + ext: ^ext, + expiration_ledger_seq: ^expiration_ledger_seq + } = ContractCodeEntry.new(ext, hash, body, expiration_ledger_seq) end test "encode_xdr/1", %{contract_code_entry: contract_code_entry, binary: binary} do diff --git a/test/xdr/ledger_entries/contract_data_entry_test.exs b/test/xdr/ledger_entries/contract_data_entry_test.exs index 60774df6..3979c0ec 100644 --- a/test/xdr/ledger_entries/contract_data_entry_test.exs +++ b/test/xdr/ledger_entries/contract_data_entry_test.exs @@ -1,29 +1,62 @@ defmodule StellarBase.XDR.ContractDataEntryTest do use ExUnit.Case - alias StellarBase.XDR.{ContractDataEntry, SCVal, SCValType, Int64, Hash} + alias StellarBase.XDR.{ + ContractDataEntry, + ContractDataEntryBody, + ContractDataDurability, + ContractEntryBodyType, + Hash, + Int64, + SCAddress, + SCAddressType, + SCVal, + SCValType, + UInt32, + Void + } describe "ContractDataEntry" do setup do - contract_id = Hash.new("GCIZ3GSM5XL7OUS4UP64THMDZ7CZ3ZWN") + address = Hash.new("CAWIIZPXNRY7X3FKFO4CWJT5DQOSEXQK") + durability = ContractDataDurability.new() + + body = + ContractDataEntryBody.new(Void.new(), ContractEntryBodyType.new(:EXPIRATION_EXTENSION)) + + expiration_ledger_seq = UInt32.new(132) + contract = SCAddress.new(address, SCAddressType.new(:SC_ADDRESS_TYPE_CONTRACT)) key = SCVal.new(Int64.new(1), SCValType.new(:SCV_I64)) - val = SCVal.new(Int64.new(2), SCValType.new(:SCV_I64)) %{ - contract_id: contract_id, + contract: contract, key: key, - val: val, - contract_data_entry: ContractDataEntry.new(contract_id, key, val), + durability: durability, + body: body, + expiration_ledger_seq: expiration_ledger_seq, + contract_data_entry: + ContractDataEntry.new(contract, key, durability, body, expiration_ledger_seq), binary: - <<71, 67, 73, 90, 51, 71, 83, 77, 53, 88, 76, 55, 79, 85, 83, 52, 85, 80, 54, 52, 84, - 72, 77, 68, 90, 55, 67, 90, 51, 90, 87, 78, 0, 0, 0, 6, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, - 0, 6, 0, 0, 0, 0, 0, 0, 0, 2>> + <<0, 0, 0, 1, 67, 65, 87, 73, 73, 90, 80, 88, 78, 82, 89, 55, 88, 51, 70, 75, 70, 79, + 52, 67, 87, 74, 84, 53, 68, 81, 79, 83, 69, 88, 81, 75, 0, 0, 0, 6, 0, 0, 0, 0, 0, 0, + 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 132>> } end - test "new/1", %{contract_id: contract_id, key: key, val: val} do - %ContractDataEntry{contract_id: ^contract_id, key: ^key, val: ^val} = - ContractDataEntry.new(contract_id, key, val) + test "new/1", %{ + contract: contract, + key: key, + durability: durability, + body: body, + expiration_ledger_seq: expiration_ledger_seq + } do + %ContractDataEntry{ + contract: ^contract, + key: ^key, + durability: ^durability, + body: ^body, + expiration_ledger_seq: ^expiration_ledger_seq + } = ContractDataEntry.new(contract, key, durability, body, expiration_ledger_seq) end test "encode_xdr/1", %{contract_data_entry: contract_data_entry, binary: binary} do diff --git a/test/xdr/ledger_entries/ledger_entry_data_test.exs b/test/xdr/ledger_entries/ledger_entry_data_test.exs index 9274647e..dd2f50b9 100644 --- a/test/xdr/ledger_entries/ledger_entry_data_test.exs +++ b/test/xdr/ledger_entries/ledger_entry_data_test.exs @@ -7,6 +7,12 @@ defmodule StellarBase.XDR.LedgerEntryDataTest do AssetCode4, AssetType, AlphaNum4, + ContractCodeEntry, + ContractCodeEntry, + ContractCodeEntryBody, + ContractEntryBodyType, + ContractDataEntryBody, + ContractDataDurability, TrustLineAsset, Int64, LedgerEntryType, @@ -34,8 +40,10 @@ defmodule StellarBase.XDR.LedgerEntryDataTest do DataEntry, ExtensionPoint, Hash, - VariableOpaque256000, + VariableOpaque, ContractCodeEntry, + SCAddress, + SCAddressType, SCVal, SCValType, ContractDataEntry, @@ -117,13 +125,18 @@ defmodule StellarBase.XDR.LedgerEntryDataTest do extension_point = ExtensionPoint.new(Void.new(), 0) hash = Hash.new("GCIZ3GSM5XL7OUS4UP64THMDZ7CZ3ZWN") - code = VariableOpaque256000.new("GCIZ3GSM5") + code = ContractCodeEntryBody.new(VariableOpaque.new("GCIZ3GSM5"), ContractEntryBodyType.new()) ## ContractDataEntry - contract_id = Hash.new("GCIZ3GSM5XL7OUS4UP64THMDZ7CZ3ZWN") + address = Hash.new("CAWIIZPXNRY7X3FKFO4CWJT5DQOSEXQK") + durability = ContractDataDurability.new() + + body = ContractDataEntryBody.new(Void.new(), ContractEntryBodyType.new(:EXPIRATION_EXTENSION)) + + expiration_ledger_seq = UInt32.new(132) + contract = SCAddress.new(address, SCAddressType.new(:SC_ADDRESS_TYPE_CONTRACT)) key = SCVal.new(Int64.new(1), SCValType.new(:SCV_I64)) - val = SCVal.new(Int64.new(2), SCValType.new(:SCV_I64)) discriminants = [ %{ @@ -189,19 +202,21 @@ defmodule StellarBase.XDR.LedgerEntryDataTest do }, %{ type: LedgerEntryType.new(:CONTRACT_DATA), - ledger_entry_data: ContractDataEntry.new(contract_id, key, val), + ledger_entry_data: + ContractDataEntry.new(contract, key, durability, body, expiration_ledger_seq), binary: - <<0, 0, 0, 6, 71, 67, 73, 90, 51, 71, 83, 77, 53, 88, 76, 55, 79, 85, 83, 52, 85, 80, - 54, 52, 84, 72, 77, 68, 90, 55, 67, 90, 51, 90, 87, 78, 0, 0, 0, 6, 0, 0, 0, 0, 0, 0, - 0, 1, 0, 0, 0, 6, 0, 0, 0, 0, 0, 0, 0, 2>> + <<0, 0, 0, 6, 0, 0, 0, 1, 67, 65, 87, 73, 73, 90, 80, 88, 78, 82, 89, 55, 88, 51, 70, + 75, 70, 79, 52, 67, 87, 74, 84, 53, 68, 81, 79, 83, 69, 88, 81, 75, 0, 0, 0, 6, 0, 0, + 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 132>> }, %{ type: LedgerEntryType.new(:CONTRACT_CODE), - ledger_entry_data: ContractCodeEntry.new(hash, code, extension_point), + ledger_entry_data: + ContractCodeEntry.new(extension_point, hash, code, expiration_ledger_seq), binary: - <<0, 0, 0, 7, 71, 67, 73, 90, 51, 71, 83, 77, 53, 88, 76, 55, 79, 85, 83, 52, 85, 80, - 54, 52, 84, 72, 77, 68, 90, 55, 67, 90, 51, 90, 87, 78, 0, 0, 0, 9, 71, 67, 73, 90, - 51, 71, 83, 77, 53, 0, 0, 0, 0, 0, 0, 0>> + <<0, 0, 0, 7, 0, 0, 0, 0, 71, 67, 73, 90, 51, 71, 83, 77, 53, 88, 76, 55, 79, 85, 83, + 52, 85, 80, 54, 52, 84, 72, 77, 68, 90, 55, 67, 90, 51, 90, 87, 78, 0, 0, 0, 0, 0, 0, + 0, 9, 71, 67, 73, 90, 51, 71, 83, 77, 53, 0, 0, 0, 0, 0, 0, 132>> } ] diff --git a/test/xdr/ledger_entries/ledger_entry_test.exs b/test/xdr/ledger_entries/ledger_entry_test.exs index 26091a38..95ffed7b 100644 --- a/test/xdr/ledger_entries/ledger_entry_test.exs +++ b/test/xdr/ledger_entries/ledger_entry_test.exs @@ -4,20 +4,26 @@ defmodule StellarBase.XDR.LedgerEntryTest do import StellarBase.Test.Utils alias StellarBase.XDR.{ + ContractDataEntry, + ContractDataEntry, + ContractDataEntryBody, + ContractEntryBodyType, + ContractDataDurability, + Ext, LedgerEntry, OptionalAccountID, SponsorshipDescriptor, LedgerEntryExtensionV1, UInt32, Int64, + SCAddress, + SCAddressType, SCVal, SCValType, LedgerEntryType, - ContractDataEntry, LedgerEntryExt, LedgerEntryData, Hash, - Ext, Void } @@ -32,11 +38,18 @@ defmodule StellarBase.XDR.LedgerEntryTest do sponsoring_id = SponsorshipDescriptor.new(account_id) last_modified_ledger_seq = UInt32.new(5) - contract_id = Hash.new("GCIZ3GSM5XL7OUS4UP64THMDZ7CZ3ZWN") + address = Hash.new("CAWIIZPXNRY7X3FKFO4CWJT5DQOSEXQK") + contract = SCAddress.new(address, SCAddressType.new(:SC_ADDRESS_TYPE_CONTRACT)) + durability = ContractDataDurability.new() key = SCVal.new(Int64.new(1), SCValType.new(:SCV_I64)) - val = SCVal.new(Int64.new(2), SCValType.new(:SCV_I64)) ledger_entry_type = LedgerEntryType.new(:CONTRACT_DATA) - ledger_entry_data = ContractDataEntry.new(contract_id, key, val) + expiration_ledger_seq = UInt32.new(132) + + body = + ContractDataEntryBody.new(Void.new(), ContractEntryBodyType.new(:EXPIRATION_EXTENSION)) + + ledger_entry_data = + ContractDataEntry.new(contract, key, durability, body, expiration_ledger_seq) data = LedgerEntryData.new(ledger_entry_data, ledger_entry_type) @@ -68,14 +81,15 @@ defmodule StellarBase.XDR.LedgerEntryTest do ledger_entry_ext_list: ledger_entry_ext_list, ledger_entry_list: ledger_entry_list, binaries: [ - <<0, 0, 0, 5, 0, 0, 0, 6, 71, 67, 73, 90, 51, 71, 83, 77, 53, 88, 76, 55, 79, 85, 83, - 52, 85, 80, 54, 52, 84, 72, 77, 68, 90, 55, 67, 90, 51, 90, 87, 78, 0, 0, 0, 6, 0, 0, - 0, 0, 0, 0, 0, 1, 0, 0, 0, 6, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0>>, - <<0, 0, 0, 5, 0, 0, 0, 6, 71, 67, 73, 90, 51, 71, 83, 77, 53, 88, 76, 55, 79, 85, 83, - 52, 85, 80, 54, 52, 84, 72, 77, 68, 90, 55, 67, 90, 51, 90, 87, 78, 0, 0, 0, 6, 0, 0, - 0, 0, 0, 0, 0, 1, 0, 0, 0, 6, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, - 0, 155, 142, 186, 248, 150, 56, 85, 29, 207, 158, 164, 247, 67, 32, 113, 16, 107, 135, - 171, 14, 45, 179, 214, 155, 117, 165, 56, 34, 114, 247, 89, 216, 0, 0, 0, 0>> + <<0, 0, 0, 5, 0, 0, 0, 6, 0, 0, 0, 1, 67, 65, 87, 73, 73, 90, 80, 88, 78, 82, 89, 55, + 88, 51, 70, 75, 70, 79, 52, 67, 87, 74, 84, 53, 68, 81, 79, 83, 69, 88, 81, 75, 0, 0, + 0, 6, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 132, 0, 0, 0, 0>>, + <<0, 0, 0, 5, 0, 0, 0, 6, 0, 0, 0, 1, 67, 65, 87, 73, 73, 90, 80, 88, 78, 82, 89, 55, + 88, 51, 70, 75, 70, 79, 52, 67, 87, 74, 84, 53, 68, 81, 79, 83, 69, 88, 81, 75, 0, 0, + 0, 6, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 132, 0, 0, 0, 1, 0, 0, + 0, 1, 0, 0, 0, 0, 155, 142, 186, 248, 150, 56, 85, 29, 207, 158, 164, 247, 67, 32, + 113, 16, 107, 135, 171, 14, 45, 179, 214, 155, 117, 165, 56, 34, 114, 247, 89, 216, 0, + 0, 0, 0>> ] } end diff --git a/test/xdr/transactions/address_with_nonce_test.exs b/test/xdr/transactions/address_with_nonce_test.exs deleted file mode 100644 index 25b1fe2b..00000000 --- a/test/xdr/transactions/address_with_nonce_test.exs +++ /dev/null @@ -1,69 +0,0 @@ -defmodule StellarBase.XDR.AddressWithNonceTest do - use ExUnit.Case - - alias StellarBase.XDR.{ - AccountID, - AddressWithNonce, - PublicKey, - PublicKeyType, - SCAddress, - SCAddressType, - UInt64, - UInt256 - } - - alias StellarBase.StrKey - - describe "AddressWithNonce" do - setup do - sc_address_type = SCAddressType.new(:SC_ADDRESS_TYPE_ACCOUNT) - pk_type = PublicKeyType.new(:PUBLIC_KEY_TYPE_ED25519) - - account_id = - "GBZNLMUQMIN3VGUJISKZU7GNY3O3XLMYEHJCKCSMDHKLGSMKALRXOEZD" - |> StrKey.decode!(:ed25519_public_key) - |> UInt256.new() - |> PublicKey.new(pk_type) - |> AccountID.new() - - sc_address = SCAddress.new(account_id, sc_address_type) - - nonce = UInt64.new(123) - - %{ - sc_address: sc_address, - nonce: nonce, - address_with_nonce: AddressWithNonce.new(sc_address, nonce), - binary: - <<0, 0, 0, 0, 0, 0, 0, 0, 114, 213, 178, 144, 98, 27, 186, 154, 137, 68, 149, 154, 124, - 205, 198, 221, 187, 173, 152, 33, 210, 37, 10, 76, 25, 212, 179, 73, 138, 2, 227, 119, - 0, 0, 0, 0, 0, 0, 0, 123>> - } - end - - test "new/1", %{sc_address: sc_address, nonce: nonce} do - %AddressWithNonce{address: ^sc_address, nonce: ^nonce} = - AddressWithNonce.new(sc_address, nonce) - end - - test "encode_xdr/1", %{address_with_nonce: address_with_nonce, binary: binary} do - {:ok, ^binary} = AddressWithNonce.encode_xdr(address_with_nonce) - end - - test "encode_xdr!/1", %{address_with_nonce: address_with_nonce, binary: binary} do - ^binary = AddressWithNonce.encode_xdr!(address_with_nonce) - end - - test "decode_xdr/2", %{address_with_nonce: address_with_nonce, binary: binary} do - {:ok, {^address_with_nonce, ""}} = AddressWithNonce.decode_xdr(binary) - end - - test "decode_xdr/2 with an invalid binary" do - {:error, :not_binary} = AddressWithNonce.decode_xdr(1234) - end - - test "decode_xdr!/2", %{address_with_nonce: address_with_nonce, binary: binary} do - {^address_with_nonce, ^binary} = AddressWithNonce.decode_xdr!(binary <> binary) - end - end -end diff --git a/test/xdr/transactions/authorized_invocation_list_test.exs b/test/xdr/transactions/authorized_invocation_list_test.exs deleted file mode 100644 index 24f460db..00000000 --- a/test/xdr/transactions/authorized_invocation_list_test.exs +++ /dev/null @@ -1,99 +0,0 @@ -defmodule StellarBase.XDR.AuthorizedInvocationListTest do - use ExUnit.Case - - alias StellarBase.XDR.{ - AuthorizedInvocationList, - AuthorizedInvocation, - Hash, - SCSymbol, - SCVec, - SCVal, - SCValType, - Int64 - } - - describe "AuthorizedInvocationList" do - setup do - contract_id = Hash.new("GCIZ3GSM5XL7OUS4UP64THMDZ7CZ3ZWN") - function_name = SCSymbol.new("Hello") - scval1 = SCVal.new(Int64.new(3), SCValType.new(:SCV_I64)) - scval2 = SCVal.new(Int64.new(2), SCValType.new(:SCV_I64)) - sc_vals = [scval1, scval2] - args = SCVec.new(sc_vals) - - call_sub_invocation = - AuthorizedInvocation.new( - contract_id, - function_name, - args, - AuthorizedInvocationList.new([]) - ) - - sub_invocations = - AuthorizedInvocationList.new([ - call_sub_invocation, - call_sub_invocation, - call_sub_invocation - ]) - - %{ - sub_invocations: sub_invocations, - authorized_invocation_list: sub_invocations, - binary: - <<0, 0, 0, 3, 71, 67, 73, 90, 51, 71, 83, 77, 53, 88, 76, 55, 79, 85, 83, 52, 85, 80, - 54, 52, 84, 72, 77, 68, 90, 55, 67, 90, 51, 90, 87, 78, 0, 0, 0, 5, 72, 101, 108, 108, - 111, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 6, 0, 0, 0, 0, 0, 0, 0, 3, 0, 0, 0, 6, 0, 0, 0, 0, - 0, 0, 0, 2, 0, 0, 0, 0, 71, 67, 73, 90, 51, 71, 83, 77, 53, 88, 76, 55, 79, 85, 83, - 52, 85, 80, 54, 52, 84, 72, 77, 68, 90, 55, 67, 90, 51, 90, 87, 78, 0, 0, 0, 5, 72, - 101, 108, 108, 111, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 6, 0, 0, 0, 0, 0, 0, 0, 3, 0, 0, 0, - 6, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 71, 67, 73, 90, 51, 71, 83, 77, 53, 88, 76, 55, - 79, 85, 83, 52, 85, 80, 54, 52, 84, 72, 77, 68, 90, 55, 67, 90, 51, 90, 87, 78, 0, 0, - 0, 5, 72, 101, 108, 108, 111, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 6, 0, 0, 0, 0, 0, 0, 0, 3, - 0, 0, 0, 6, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0>> - } - end - - test "new/1", %{sub_invocations: sub_invocations} do - %AuthorizedInvocationList{sub_invocations: ^sub_invocations} = - AuthorizedInvocationList.new(sub_invocations) - end - - test "encode_xdr/1", %{ - authorized_invocation_list: authorized_invocation_list, - binary: binary - } do - {:ok, ^binary} = AuthorizedInvocationList.encode_xdr(authorized_invocation_list) - end - - test "encode_xdr!/1", %{ - authorized_invocation_list: authorized_invocation_list, - binary: binary - } do - ^binary = AuthorizedInvocationList.encode_xdr!(authorized_invocation_list) - end - - test "decode_xdr/1", %{ - authorized_invocation_list: authorized_invocation_list, - binary: binary - } do - {:ok, {^authorized_invocation_list, ""}} = AuthorizedInvocationList.decode_xdr(binary) - end - - test "decode_xdr/1 with an invalid binary" do - {:error, :not_binary} = AuthorizedInvocationList.decode_xdr(123) - end - - test "decode_xdr!/1", %{ - authorized_invocation_list: authorized_invocation_list, - binary: binary - } do - {^authorized_invocation_list, ""} = AuthorizedInvocationList.decode_xdr!(binary) - end - - test "decode_xdr!/1 with an invalid binary" do - assert_raise XDR.VariableArrayError, - "The value which you pass through parameters must be a binary value, for example: <<0, 0, 0, 5>>", - fn -> AuthorizedInvocationList.decode_xdr!(123) end - end - end -end diff --git a/test/xdr/transactions/authorized_invocation_test.exs b/test/xdr/transactions/authorized_invocation_test.exs deleted file mode 100644 index afe766f6..00000000 --- a/test/xdr/transactions/authorized_invocation_test.exs +++ /dev/null @@ -1,109 +0,0 @@ -defmodule StellarBase.XDR.AuthorizedInvocationTest do - use ExUnit.Case - - alias StellarBase.XDR.{ - AuthorizedInvocation, - AuthorizedInvocationList, - Hash, - SCSymbol, - SCVec, - SCVal, - SCValType, - Int64 - } - - describe "AuthorizedInvocation" do - setup do - contract_id = Hash.new("GCIZ3GSM5XL7OUS4UP64THMDZ7CZ3ZWN") - function_name = SCSymbol.new("Hello") - scval1 = SCVal.new(Int64.new(3), SCValType.new(:SCV_I64)) - scval2 = SCVal.new(Int64.new(2), SCValType.new(:SCV_I64)) - sc_vals = [scval1, scval2] - args = SCVec.new(sc_vals) - - auth_sub_invocation = - AuthorizedInvocation.new( - contract_id, - function_name, - args, - AuthorizedInvocationList.new([]) - ) - - sub_invocations = - AuthorizedInvocationList.new([ - auth_sub_invocation, - auth_sub_invocation, - auth_sub_invocation - ]) - - %{ - contract_id: contract_id, - function_name: function_name, - args: args, - sub_invocations: sub_invocations, - authorized_invocation: - AuthorizedInvocation.new(contract_id, function_name, args, sub_invocations), - binary: - <<71, 67, 73, 90, 51, 71, 83, 77, 53, 88, 76, 55, 79, 85, 83, 52, 85, 80, 54, 52, 84, - 72, 77, 68, 90, 55, 67, 90, 51, 90, 87, 78, 0, 0, 0, 5, 72, 101, 108, 108, 111, 0, 0, - 0, 0, 0, 0, 2, 0, 0, 0, 6, 0, 0, 0, 0, 0, 0, 0, 3, 0, 0, 0, 6, 0, 0, 0, 0, 0, 0, 0, 2, - 0, 0, 0, 3, 71, 67, 73, 90, 51, 71, 83, 77, 53, 88, 76, 55, 79, 85, 83, 52, 85, 80, - 54, 52, 84, 72, 77, 68, 90, 55, 67, 90, 51, 90, 87, 78, 0, 0, 0, 5, 72, 101, 108, 108, - 111, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 6, 0, 0, 0, 0, 0, 0, 0, 3, 0, 0, 0, 6, 0, 0, 0, 0, - 0, 0, 0, 2, 0, 0, 0, 0, 71, 67, 73, 90, 51, 71, 83, 77, 53, 88, 76, 55, 79, 85, 83, - 52, 85, 80, 54, 52, 84, 72, 77, 68, 90, 55, 67, 90, 51, 90, 87, 78, 0, 0, 0, 5, 72, - 101, 108, 108, 111, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 6, 0, 0, 0, 0, 0, 0, 0, 3, 0, 0, 0, - 6, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 71, 67, 73, 90, 51, 71, 83, 77, 53, 88, 76, 55, - 79, 85, 83, 52, 85, 80, 54, 52, 84, 72, 77, 68, 90, 55, 67, 90, 51, 90, 87, 78, 0, 0, - 0, 5, 72, 101, 108, 108, 111, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 6, 0, 0, 0, 0, 0, 0, 0, 3, - 0, 0, 0, 6, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0>> - } - end - - test "new/1", %{ - contract_id: contract_id, - function_name: function_name, - args: args, - sub_invocations: sub_invocations - } do - %AuthorizedInvocation{ - contract_id: ^contract_id, - function_name: ^function_name, - args: ^args, - sub_invocations: ^sub_invocations - } = AuthorizedInvocation.new(contract_id, function_name, args, sub_invocations) - end - - test "encode_xdr/1", %{ - authorized_invocation: authorized_invocation, - binary: binary - } do - {:ok, ^binary} = AuthorizedInvocation.encode_xdr(authorized_invocation) - end - - test "encode_xdr!/1", %{ - authorized_invocation: authorized_invocation, - binary: binary - } do - ^binary = AuthorizedInvocation.encode_xdr!(authorized_invocation) - end - - test "decode_xdr/2", %{ - authorized_invocation: authorized_invocation, - binary: binary - } do - {:ok, {^authorized_invocation, ""}} = AuthorizedInvocation.decode_xdr(binary) - end - - test "decode_xdr/2 with an invalid binary" do - {:error, :not_binary} = AuthorizedInvocation.decode_xdr(123) - end - - test "decode_xdr!/2", %{ - authorized_invocation: authorized_invocation, - binary: binary - } do - {^authorized_invocation, ^binary} = AuthorizedInvocation.decode_xdr!(binary <> binary) - end - end -end diff --git a/test/xdr/transactions/contract_auth_list_test.exs b/test/xdr/transactions/contract_auth_list_test.exs deleted file mode 100644 index 2353ecbe..00000000 --- a/test/xdr/transactions/contract_auth_list_test.exs +++ /dev/null @@ -1,132 +0,0 @@ -defmodule StellarBase.XDR.ContractAuthListTest do - use ExUnit.Case - - alias StellarBase.XDR.{ - AuthorizedInvocation, - AuthorizedInvocationList, - AccountID, - AddressWithNonce, - ContractAuth, - Hash, - Int64, - PublicKey, - PublicKeyType, - SCAddress, - SCAddressType, - SCSymbol, - SCVal, - SCValType, - SCVec, - OptionalAddressWithNonce, - UInt64, - UInt256, - ContractAuthList - } - - alias StellarBase.StrKey - - describe "ContractAuthList" do - setup do - # AddressWithNonce - sc_address_type = SCAddressType.new(:SC_ADDRESS_TYPE_ACCOUNT) - pk_type = PublicKeyType.new(:PUBLIC_KEY_TYPE_ED25519) - - account_id = - "GBZNLMUQMIN3VGUJISKZU7GNY3O3XLMYEHJCKCSMDHKLGSMKALRXOEZD" - |> StrKey.decode!(:ed25519_public_key) - |> UInt256.new() - |> PublicKey.new(pk_type) - |> AccountID.new() - - sc_address = SCAddress.new(account_id, sc_address_type) - nonce = UInt64.new(123) - - address_with_nonce = - sc_address |> AddressWithNonce.new(nonce) |> OptionalAddressWithNonce.new() - - # SCVec - scval1 = SCVal.new(Int64.new(3), SCValType.new(:SCV_I64)) - scval2 = SCVal.new(Int64.new(2), SCValType.new(:SCV_I64)) - sc_vals = [scval1, scval2] - sc_vec = SCVec.new(sc_vals) - - # AuthorizedInvocation - contract_id = Hash.new("GCIZ3GSM5XL7OUS4UP64THMDZ7CZ3ZWN") - function_name = SCSymbol.new("Hello") - - authorized_invocation = - AuthorizedInvocation.new( - contract_id, - function_name, - sc_vec, - AuthorizedInvocationList.new([]) - ) - - # ContractAuthList - auth = ContractAuth.new(address_with_nonce, authorized_invocation, sc_vec) - auth_list = ContractAuthList.new([auth, auth]) - - %{ - auth: auth, - auth_list: auth_list, - binary: - <<0, 0, 0, 2, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 114, 213, 178, 144, 98, 27, 186, 154, - 137, 68, 149, 154, 124, 205, 198, 221, 187, 173, 152, 33, 210, 37, 10, 76, 25, 212, - 179, 73, 138, 2, 227, 119, 0, 0, 0, 0, 0, 0, 0, 123, 71, 67, 73, 90, 51, 71, 83, 77, - 53, 88, 76, 55, 79, 85, 83, 52, 85, 80, 54, 52, 84, 72, 77, 68, 90, 55, 67, 90, 51, - 90, 87, 78, 0, 0, 0, 5, 72, 101, 108, 108, 111, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 6, 0, 0, - 0, 0, 0, 0, 0, 3, 0, 0, 0, 6, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, - 6, 0, 0, 0, 0, 0, 0, 0, 3, 0, 0, 0, 6, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 1, 0, 0, 0, 0, - 0, 0, 0, 0, 114, 213, 178, 144, 98, 27, 186, 154, 137, 68, 149, 154, 124, 205, 198, - 221, 187, 173, 152, 33, 210, 37, 10, 76, 25, 212, 179, 73, 138, 2, 227, 119, 0, 0, 0, - 0, 0, 0, 0, 123, 71, 67, 73, 90, 51, 71, 83, 77, 53, 88, 76, 55, 79, 85, 83, 52, 85, - 80, 54, 52, 84, 72, 77, 68, 90, 55, 67, 90, 51, 90, 87, 78, 0, 0, 0, 5, 72, 101, 108, - 108, 111, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 6, 0, 0, 0, 0, 0, 0, 0, 3, 0, 0, 0, 6, 0, 0, - 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 6, 0, 0, 0, 0, 0, 0, 0, 3, 0, 0, 0, - 6, 0, 0, 0, 0, 0, 0, 0, 2>> - } - end - - test "new/1", %{auth: auth} do - %ContractAuthList{auth: ^auth} = ContractAuthList.new(auth) - end - - test "encode_xdr/1", %{ - auth_list: auth_list, - binary: binary - } do - {:ok, ^binary} = ContractAuthList.encode_xdr(auth_list) - end - - test "encode_xdr!/1", %{ - auth_list: auth_list, - binary: binary - } do - ^binary = ContractAuthList.encode_xdr!(auth_list) - end - - test "decode_xdr/1", %{ - auth_list: auth_list, - binary: binary - } do - {:ok, {^auth_list, ""}} = ContractAuthList.decode_xdr(binary) - end - - test "decode_xdr/1 with an invalid binary" do - {:error, :not_binary} = ContractAuthList.decode_xdr(123) - end - - test "decode_xdr!/1", %{ - auth_list: auth_list, - binary: binary - } do - {^auth_list, ""} = ContractAuthList.decode_xdr!(binary) - end - - test "decode_xdr!/1 with an invalid binary" do - assert_raise XDR.VariableArrayError, - "The value which you pass through parameters must be a binary value, for example: <<0, 0, 0, 5>>", - fn -> ContractAuthList.decode_xdr!(123) end - end - end -end diff --git a/test/xdr/transactions/contract_auth_test.exs b/test/xdr/transactions/contract_auth_test.exs deleted file mode 100644 index 069c652a..00000000 --- a/test/xdr/transactions/contract_auth_test.exs +++ /dev/null @@ -1,145 +0,0 @@ -defmodule StellarBase.XDR.ContractAuthTest do - use ExUnit.Case - - alias StellarBase.XDR.{ - AuthorizedInvocation, - AuthorizedInvocationList, - AccountID, - AddressWithNonce, - ContractAuth, - Hash, - Int64, - PublicKey, - PublicKeyType, - SCAddress, - SCAddressType, - SCSymbol, - SCVal, - SCValType, - SCVec, - OptionalAddressWithNonce, - UInt64, - UInt256 - } - - alias StellarBase.StrKey - - describe "ContractAuthTest" do - setup do - # AddressWithNonce - sc_address_type = SCAddressType.new(:SC_ADDRESS_TYPE_ACCOUNT) - pk_type = PublicKeyType.new(:PUBLIC_KEY_TYPE_ED25519) - - account_id = - "GBZNLMUQMIN3VGUJISKZU7GNY3O3XLMYEHJCKCSMDHKLGSMKALRXOEZD" - |> StrKey.decode!(:ed25519_public_key) - |> UInt256.new() - |> PublicKey.new(pk_type) - |> AccountID.new() - - sc_address = SCAddress.new(account_id, sc_address_type) - nonce = UInt64.new(123) - - address_with_nonce = - sc_address |> AddressWithNonce.new(nonce) |> OptionalAddressWithNonce.new() - - address_with_nonce_nil = OptionalAddressWithNonce.new() - - # SCVec - scval1 = SCVal.new(Int64.new(3), SCValType.new(:SCV_I64)) - scval2 = SCVal.new(Int64.new(2), SCValType.new(:SCV_I64)) - sc_vals = [scval1, scval2] - sc_vec = SCVec.new(sc_vals) - - # AuthorizedInvocation - contract_id = Hash.new("GCIZ3GSM5XL7OUS4UP64THMDZ7CZ3ZWN") - function_name = SCSymbol.new("Hello") - - authorized_invocation = - AuthorizedInvocation.new( - contract_id, - function_name, - sc_vec, - AuthorizedInvocationList.new([]) - ) - - discriminants = [ - %{ - address_with_nonce: address_with_nonce, - authorized_invocation: authorized_invocation, - sc_vec: sc_vec, - contract_auth: ContractAuth.new(address_with_nonce, authorized_invocation, sc_vec), - binary: - <<0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 114, 213, 178, 144, 98, 27, 186, 154, 137, 68, - 149, 154, 124, 205, 198, 221, 187, 173, 152, 33, 210, 37, 10, 76, 25, 212, 179, 73, - 138, 2, 227, 119, 0, 0, 0, 0, 0, 0, 0, 123, 71, 67, 73, 90, 51, 71, 83, 77, 53, 88, - 76, 55, 79, 85, 83, 52, 85, 80, 54, 52, 84, 72, 77, 68, 90, 55, 67, 90, 51, 90, 87, - 78, 0, 0, 0, 5, 72, 101, 108, 108, 111, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 6, 0, 0, 0, 0, - 0, 0, 0, 3, 0, 0, 0, 6, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 6, - 0, 0, 0, 0, 0, 0, 0, 3, 0, 0, 0, 6, 0, 0, 0, 0, 0, 0, 0, 2>> - }, - %{ - address_with_nonce: address_with_nonce_nil, - authorized_invocation: authorized_invocation, - sc_vec: sc_vec, - contract_auth: ContractAuth.new(address_with_nonce_nil, authorized_invocation, sc_vec), - binary: - <<0, 0, 0, 0, 71, 67, 73, 90, 51, 71, 83, 77, 53, 88, 76, 55, 79, 85, 83, 52, 85, 80, - 54, 52, 84, 72, 77, 68, 90, 55, 67, 90, 51, 90, 87, 78, 0, 0, 0, 5, 72, 101, 108, - 108, 111, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 6, 0, 0, 0, 0, 0, 0, 0, 3, 0, 0, 0, 6, 0, 0, - 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 6, 0, 0, 0, 0, 0, 0, 0, 3, 0, 0, - 0, 6, 0, 0, 0, 0, 0, 0, 0, 2>> - } - ] - - %{discriminants: discriminants} - end - - test "new/1", %{discriminants: discriminants} do - for %{ - address_with_nonce: address_with_nonce, - authorized_invocation: authorized_invocation, - sc_vec: sc_vec - } <- - discriminants do - %ContractAuth{ - address_with_nonce: ^address_with_nonce, - authorized_invocation: ^authorized_invocation, - signature_args: ^sc_vec - } = ContractAuth.new(address_with_nonce, authorized_invocation, sc_vec) - end - end - - test "encode_xdr/1", %{discriminants: discriminants} do - for %{contract_auth: contract_auth, binary: binary} <- - discriminants do - {:ok, ^binary} = ContractAuth.encode_xdr(contract_auth) - end - end - - test "encode_xdr!/1", %{discriminants: discriminants} do - for %{contract_auth: contract_auth, binary: binary} <- - discriminants do - ^binary = ContractAuth.encode_xdr!(contract_auth) - end - end - - test "decode_xdr/2", %{discriminants: discriminants} do - for %{contract_auth: contract_auth, binary: binary} <- - discriminants do - {:ok, {^contract_auth, ""}} = ContractAuth.decode_xdr(binary) - end - end - - test "decode_xdr/2 with an invalid binary" do - {:error, :not_binary} = ContractAuth.decode_xdr(1234) - end - - test "decode_xdr!/2", %{discriminants: discriminants} do - for %{contract_auth: contract_auth, binary: binary} <- - discriminants do - {^contract_auth, ""} = ContractAuth.decode_xdr!(binary) - end - end - end -end diff --git a/test/xdr/transactions/contract_id_preimage_type_test.exs b/test/xdr/transactions/contract_id_preimage_type_test.exs new file mode 100644 index 00000000..af4c2136 --- /dev/null +++ b/test/xdr/transactions/contract_id_preimage_type_test.exs @@ -0,0 +1,49 @@ +defmodule StellarBase.XDR.ContractIDPreimageTypeTest do + use ExUnit.Case + + alias StellarBase.XDR.ContractIDPreimageType + + describe "ContractIDPreimageType" do + setup do + %{ + binary: <<0, 0, 0, 1>>, + identifier: :CONTRACT_ID_PREIMAGE_FROM_ASSET, + default_identifier: :CONTRACT_ID_PREIMAGE_FROM_ADDRESS, + xdr_type: ContractIDPreimageType.new(:CONTRACT_ID_PREIMAGE_FROM_ASSET) + } + end + + test "new/1", %{identifier: type} do + %ContractIDPreimageType{identifier: ^type} = ContractIDPreimageType.new(type) + end + + test "new/1 with default value", %{default_identifier: type} do + %ContractIDPreimageType{identifier: ^type} = ContractIDPreimageType.new() + end + + test "encode_xdr/1", %{xdr_type: xdr_type, binary: binary} do + {:ok, ^binary} = ContractIDPreimageType.encode_xdr(xdr_type) + end + + test "encode_xdr!/1", %{xdr_type: xdr_type, binary: binary} do + ^binary = ContractIDPreimageType.encode_xdr!(xdr_type) + end + + test "decode_xdr/2", %{xdr_type: xdr_type, binary: binary} do + {:ok, {^xdr_type, ""}} = ContractIDPreimageType.decode_xdr(binary) + end + + test "decode_xdr/2 with an invalid binary" do + {:error, :not_binary} = ContractIDPreimageType.decode_xdr(123) + end + + test "decode_xdr!/2", %{xdr_type: xdr_type, binary: binary} do + {^xdr_type, ^binary} = ContractIDPreimageType.decode_xdr!(binary <> binary) + end + + test "invalid identifier" do + {:error, :invalid_key} = + ContractIDPreimageType.encode_xdr(%ContractIDPreimageType{identifier: :SCV_TEST}) + end + end +end diff --git a/test/xdr/transactions/contract_id_public_key_type_test.exs b/test/xdr/transactions/contract_id_public_key_type_test.exs deleted file mode 100644 index 312d4027..00000000 --- a/test/xdr/transactions/contract_id_public_key_type_test.exs +++ /dev/null @@ -1,49 +0,0 @@ -defmodule StellarBase.XDR.ContractIDPublicKeyTypeTest do - use ExUnit.Case - - alias StellarBase.XDR.ContractIDPublicKeyType - - describe "ContractIDPublicKeyType" do - setup do - %{ - binary: <<0, 0, 0, 1>>, - identifier: :CONTRACT_ID_PUBLIC_KEY_ED25519, - default_identifier: :CONTRACT_ID_PUBLIC_KEY_SOURCE_ACCOUNT, - xdr_type: ContractIDPublicKeyType.new(:CONTRACT_ID_PUBLIC_KEY_ED25519) - } - end - - test "new/1", %{identifier: type} do - %ContractIDPublicKeyType{identifier: ^type} = ContractIDPublicKeyType.new(type) - end - - test "new/1 with default value", %{default_identifier: type} do - %ContractIDPublicKeyType{identifier: ^type} = ContractIDPublicKeyType.new() - end - - test "encode_xdr/1", %{xdr_type: xdr_type, binary: binary} do - {:ok, ^binary} = ContractIDPublicKeyType.encode_xdr(xdr_type) - end - - test "encode_xdr!/1", %{xdr_type: xdr_type, binary: binary} do - ^binary = ContractIDPublicKeyType.encode_xdr!(xdr_type) - end - - test "decode_xdr/2", %{xdr_type: xdr_type, binary: binary} do - {:ok, {^xdr_type, ""}} = ContractIDPublicKeyType.decode_xdr(binary) - end - - test "decode_xdr/2 with an invalid binary" do - {:error, :not_binary} = ContractIDPublicKeyType.decode_xdr(123) - end - - test "decode_xdr!/2", %{xdr_type: xdr_type, binary: binary} do - {^xdr_type, ^binary} = ContractIDPublicKeyType.decode_xdr!(binary <> binary) - end - - test "invalid identifier" do - {:error, :invalid_key} = - ContractIDPublicKeyType.encode_xdr(%ContractIDPublicKeyType{identifier: :SCV_TEST}) - end - end -end diff --git a/test/xdr/transactions/contract_id_test.exs b/test/xdr/transactions/contract_id_test.exs deleted file mode 100644 index dc30c6b5..00000000 --- a/test/xdr/transactions/contract_id_test.exs +++ /dev/null @@ -1,162 +0,0 @@ -defmodule StellarBase.XDR.ContractIDTest do - use ExUnit.Case - - alias StellarBase.XDR.{ - Asset, - ContractIDType, - ContractID, - UInt256, - PublicKey, - AccountID, - AssetType, - AssetCode4, - AlphaNum4, - Signature, - FromEd25519PublicKey, - PublicKeyType - } - - alias StellarBase.StrKey - - describe "ContractID" do - setup do - ## Asset - key_type = PublicKeyType.new(:PUBLIC_KEY_TYPE_ED25519) - - issuer = - "GCNY5OXYSY4FKHOPT2SPOQZAOEIGXB5LBYW3HVU3OWSTQITS65M5RCNY" - |> StrKey.decode!(:ed25519_public_key) - |> UInt256.new() - |> PublicKey.new(key_type) - |> AccountID.new() - - asset_type = AssetType.new(:ASSET_TYPE_CREDIT_ALPHANUM4) - - alpha_num4 = "BTCN" |> AssetCode4.new() |> AlphaNum4.new(issuer) - - asset = Asset.new(alpha_num4, asset_type) - - ## FromEd25519PublicKey - key = - "GCVILYTXYXYHZIBYEF4BSLATAP3CPZMW23NE6DUL7I6LCCDUNFBQFAVR" - |> StrKey.decode!(:ed25519_public_key) - |> UInt256.new() - - signature = Signature.new("SAPVVUQ2G755KGQOOY5A3AGTMWCCQQTJMGSXAUKMFT45OFCL7NCSTRWI") - - salt = - UInt256.new( - <<72, 101, 108, 108, 111, 32, 119, 111, 114, 108, 100, 0, 21, 0, 1, 0, 72, 101, 108, - 108, 111, 32, 119, 111, 114, 108, 100, 0, 21, 0, 1, 0>> - ) - - from_ed25519_public_key = FromEd25519PublicKey.new(key, signature, salt) - - ## UInt256 - salt_case = - "GCJCFK7GZEOXVAWWOWYFTR5C5IZAQBYV5HIJUGVZPUBDJNRFVXXZEHHV" - |> StrKey.decode!(:ed25519_public_key) - |> UInt256.new() - - discriminants = [ - %{ - contract_id_type: ContractIDType.new(:CONTRACT_ID_FROM_SOURCE_ACCOUNT), - contract_id: salt_case, - binary: - <<0, 0, 0, 0, 146, 34, 171, 230, 201, 29, 122, 130, 214, 117, 176, 89, 199, 162, 234, - 50, 8, 7, 21, 233, 208, 154, 26, 185, 125, 2, 52, 182, 37, 173, 239, 146>> - }, - %{ - contract_id_type: ContractIDType.new(:CONTRACT_ID_FROM_ED25519_PUBLIC_KEY), - contract_id: from_ed25519_public_key, - binary: - <<0, 0, 0, 1, 170, 133, 226, 119, 197, 240, 124, 160, 56, 33, 120, 25, 44, 19, 3, 246, - 39, 229, 150, 214, 218, 79, 14, 139, 250, 60, 177, 8, 116, 105, 67, 2, 0, 0, 0, 56, - 83, 65, 80, 86, 86, 85, 81, 50, 71, 55, 53, 53, 75, 71, 81, 79, 79, 89, 53, 65, 51, - 65, 71, 84, 77, 87, 67, 67, 81, 81, 84, 74, 77, 71, 83, 88, 65, 85, 75, 77, 70, 84, - 52, 53, 79, 70, 67, 76, 55, 78, 67, 83, 84, 82, 87, 73, 72, 101, 108, 108, 111, 32, - 119, 111, 114, 108, 100, 0, 21, 0, 1, 0, 72, 101, 108, 108, 111, 32, 119, 111, 114, - 108, 100, 0, 21, 0, 1, 0>> - }, - %{ - contract_id_type: ContractIDType.new(:CONTRACT_ID_FROM_ASSET), - contract_id: asset, - binary: - <<0, 0, 0, 2, 0, 0, 0, 1, 66, 84, 67, 78, 0, 0, 0, 0, 155, 142, 186, 248, 150, 56, 85, - 29, 207, 158, 164, 247, 67, 32, 113, 16, 107, 135, 171, 14, 45, 179, 214, 155, 117, - 165, 56, 34, 114, 247, 89, 216>> - } - ] - - %{discriminants: discriminants} - end - - test "new/1", %{discriminants: discriminants} do - for %{contract_id_type: contract_id_type, contract_id: contract_id} <- - discriminants do - %ContractID{contract_id: ^contract_id, type: ^contract_id_type} = - ContractID.new(contract_id, contract_id_type) - end - end - - test "encode_xdr/1", %{discriminants: discriminants} do - for %{ - contract_id: contract_id, - contract_id_type: contract_id_type, - binary: binary - } <- discriminants do - xdr = ContractID.new(contract_id, contract_id_type) - {:ok, ^binary} = ContractID.encode_xdr(xdr) - end - end - - test "encode_xdr!/1", %{discriminants: discriminants} do - for %{ - contract_id: contract_id, - contract_id_type: contract_id_type, - binary: binary - } <- discriminants do - xdr = ContractID.new(contract_id, contract_id_type) - ^binary = ContractID.encode_xdr!(xdr) - end - end - - test "encode_xdr/1 with an invalid type", %{discriminants: [contract_id | _rest]} do - contract_id_type = ContractIDType.new(:NEW_ADDRESS) - - assert_raise XDR.EnumError, - "The key which you try to encode doesn't belong to the current declarations", - fn -> - contract_id - |> ContractID.new(contract_id_type) - |> ContractID.encode_xdr() - end - end - - test "decode_xdr/2", %{discriminants: discriminants} do - for %{ - contract_id: contract_id, - contract_id_type: contract_id_type, - binary: binary - } <- discriminants do - xdr = ContractID.new(contract_id, contract_id_type) - {:ok, {^xdr, ""}} = ContractID.decode_xdr(binary) - end - end - - test "decode_xdr/2 with an invalid binary" do - {:error, :not_binary} = ContractID.decode_xdr(123) - end - - test "decode_xdr!/2", %{discriminants: discriminants} do - for %{ - contract_id: contract_id, - contract_id_type: contract_id_type, - binary: binary - } <- discriminants do - xdr = ContractID.new(contract_id, contract_id_type) - {^xdr, ""} = ContractID.decode_xdr!(binary) - end - end - end -end diff --git a/test/xdr/transactions/contract_id_type_test.exs b/test/xdr/transactions/contract_id_type_test.exs deleted file mode 100644 index 83ff107b..00000000 --- a/test/xdr/transactions/contract_id_type_test.exs +++ /dev/null @@ -1,48 +0,0 @@ -defmodule StellarBase.XDR.ContractIDTypeTest do - use ExUnit.Case - - alias StellarBase.XDR.ContractIDType - - describe "ContractIDType" do - setup do - %{ - binary: <<0, 0, 0, 2>>, - identifier: :CONTRACT_ID_FROM_ASSET, - default_identifier: :CONTRACT_ID_FROM_SOURCE_ACCOUNT, - xdr_type: ContractIDType.new(:CONTRACT_ID_FROM_ASSET) - } - end - - test "new/1", %{identifier: type} do - %ContractIDType{identifier: ^type} = ContractIDType.new(type) - end - - test "new/1 with default value", %{default_identifier: type} do - %ContractIDType{identifier: ^type} = ContractIDType.new() - end - - test "encode_xdr/1", %{xdr_type: xdr_type, binary: binary} do - {:ok, ^binary} = ContractIDType.encode_xdr(xdr_type) - end - - test "encode_xdr!/1", %{xdr_type: xdr_type, binary: binary} do - ^binary = ContractIDType.encode_xdr!(xdr_type) - end - - test "decode_xdr/2", %{xdr_type: xdr_type, binary: binary} do - {:ok, {^xdr_type, ""}} = ContractIDType.decode_xdr(binary) - end - - test "decode_xdr/2 with an invalid binary" do - {:error, :not_binary} = ContractIDType.decode_xdr(123) - end - - test "decode_xdr!/2", %{xdr_type: xdr_type, binary: binary} do - {^xdr_type, ^binary} = ContractIDType.decode_xdr!(binary <> binary) - end - - test "invalid identifier" do - {:error, :invalid_key} = ContractIDType.encode_xdr(%ContractIDType{identifier: :SCV_TEST}) - end - end -end diff --git a/test/xdr/transactions/create_contract_args_test.exs b/test/xdr/transactions/create_contract_args_test.exs index 3443da3e..d01d0e15 100644 --- a/test/xdr/transactions/create_contract_args_test.exs +++ b/test/xdr/transactions/create_contract_args_test.exs @@ -2,12 +2,15 @@ defmodule StellarBase.XDR.CreateContractArgsTest do use ExUnit.Case alias StellarBase.XDR.{ - ContractID, - ContractIDType, + ContractIDPreimage, + ContractIDPreimageFromAddress, + ContractIDPreimageType, CreateContractArgs, - SCContractExecutable, - SCContractExecutableType, + ContractExecutable, + ContractExecutableType, Hash, + SCAddress, + SCAddressType, UInt256 } @@ -15,37 +18,52 @@ defmodule StellarBase.XDR.CreateContractArgsTest do describe "CreateContractArgs" do setup do - # SCContractExecutable - contract_executable = Hash.new("GCIZ3GSM5XL7OUS4UP64THMDZ7CZ3ZWN") - sc_contract_executable_type = SCContractExecutableType.new(:SCCONTRACT_EXECUTABLE_WASM_REF) + # ContractExecutable + address = Hash.new("CAWIIZPXNRY7X3FKFO4CWJT5DQOSEXQK") + sc_address = SCAddress.new(address, SCAddressType.new(:SC_ADDRESS_TYPE_CONTRACT)) - sc_contract_executable = - SCContractExecutable.new(contract_executable, sc_contract_executable_type) - - # ContractID salt = "GCJCFK7GZEOXVAWWOWYFTR5C5IZAQBYV5HIJUGVZPUBDJNRFVXXZEHHV" |> StrKey.decode!(:ed25519_public_key) |> UInt256.new() - contract_id_type = ContractIDType.new(:CONTRACT_ID_FROM_SOURCE_ACCOUNT) - contract_id = ContractID.new(salt, contract_id_type) + id_preimage_address = + ContractIDPreimageFromAddress.new( + sc_address, + salt + ) + + # ContractID + contract_id_preimage = + ContractIDPreimage.new(id_preimage_address, ContractIDPreimageType.new()) + + sc_contract_executable_type = ContractExecutableType.new(:CONTRACT_EXECUTABLE_WASM) + + sc_contract_executable = ContractExecutable.new(address, sc_contract_executable_type) %{ sc_contract_executable: sc_contract_executable, - contract_id: contract_id, - create_contract_args: CreateContractArgs.new(contract_id, sc_contract_executable), + contract_id_preimage: contract_id_preimage, + create_contract_args: + CreateContractArgs.new(contract_id_preimage, sc_contract_executable), binary: - <<0, 0, 0, 0, 146, 34, 171, 230, 201, 29, 122, 130, 214, 117, 176, 89, 199, 162, 234, - 50, 8, 7, 21, 233, 208, 154, 26, 185, 125, 2, 52, 182, 37, 173, 239, 146, 0, 0, 0, 0, - 71, 67, 73, 90, 51, 71, 83, 77, 53, 88, 76, 55, 79, 85, 83, 52, 85, 80, 54, 52, 84, - 72, 77, 68, 90, 55, 67, 90, 51, 90, 87, 78>> + <<0, 0, 0, 0, 0, 0, 0, 1, 67, 65, 87, 73, 73, 90, 80, 88, 78, 82, 89, 55, 88, 51, 70, + 75, 70, 79, 52, 67, 87, 74, 84, 53, 68, 81, 79, 83, 69, 88, 81, 75, 146, 34, 171, 230, + 201, 29, 122, 130, 214, 117, 176, 89, 199, 162, 234, 50, 8, 7, 21, 233, 208, 154, 26, + 185, 125, 2, 52, 182, 37, 173, 239, 146, 0, 0, 0, 0, 67, 65, 87, 73, 73, 90, 80, 88, + 78, 82, 89, 55, 88, 51, 70, 75, 70, 79, 52, 67, 87, 74, 84, 53, 68, 81, 79, 83, 69, + 88, 81, 75>> } end - test "new/1", %{contract_id: contract_id, sc_contract_executable: sc_contract_executable} do - %CreateContractArgs{contract_id: ^contract_id, executable: ^sc_contract_executable} = - CreateContractArgs.new(contract_id, sc_contract_executable) + test "new/1", %{ + contract_id_preimage: contract_id_preimage, + sc_contract_executable: sc_contract_executable + } do + %CreateContractArgs{ + contract_id_preimage: ^contract_id_preimage, + executable: ^sc_contract_executable + } = CreateContractArgs.new(contract_id_preimage, sc_contract_executable) end test "encode_xdr/1", %{create_contract_args: create_contract_args, binary: binary} do diff --git a/test/xdr/transactions/envelope_type_test.exs b/test/xdr/transactions/envelope_type_test.exs index 80f40bc5..afbb7920 100644 --- a/test/xdr/transactions/envelope_type_test.exs +++ b/test/xdr/transactions/envelope_type_test.exs @@ -12,12 +12,8 @@ defmodule StellarBase.XDR.EnvelopeTypeTest do :ENVELOPE_TYPE_TX_FEE_BUMP, :ENVELOPE_TYPE_OP_ID, :ENVELOPE_TYPE_POOL_REVOKE_OP_ID, - :ENVELOPE_TYPE_CONTRACT_ID_FROM_ED25519, - :ENVELOPE_TYPE_CONTRACT_ID_FROM_CONTRACT, - :ENVELOPE_TYPE_CONTRACT_ID_FROM_ASSET, - :ENVELOPE_TYPE_CONTRACT_ID_FROM_SOURCE_ACCOUNT, - :ENVELOPE_TYPE_CREATE_CONTRACT_ARGS, - :ENVELOPE_TYPE_CONTRACT_AUTH + :ENVELOPE_TYPE_CONTRACT_ID, + :ENVELOPE_TYPE_SOROBAN_AUTHORIZATION ] @binaries [ @@ -30,11 +26,7 @@ defmodule StellarBase.XDR.EnvelopeTypeTest do <<0, 0, 0, 6>>, <<0, 0, 0, 7>>, <<0, 0, 0, 8>>, - <<0, 0, 0, 9>>, - <<0, 0, 0, 10>>, - <<0, 0, 0, 11>>, - <<0, 0, 0, 12>>, - <<0, 0, 0, 13>> + <<0, 0, 0, 9>> ] describe "EnvelopeType" do diff --git a/test/xdr/transactions/fee_bump_inner_tx_test.exs b/test/xdr/transactions/fee_bump_inner_tx_test.exs index 56be99a7..cd1d1f25 100644 --- a/test/xdr/transactions/fee_bump_inner_tx_test.exs +++ b/test/xdr/transactions/fee_bump_inner_tx_test.exs @@ -159,6 +159,7 @@ defmodule StellarBase.XDR.Operations.FeeBumpInnerTxTest do ) payment_operation = payment_op_body(destination, asset, Int64.new(5_000_000_000)) + clawback_operation = clawback_op_body(asset, destination, Int64.new(1_000_000_000)) [payment_operation, clawback_operation] diff --git a/test/xdr/transactions/from_ed25519_public_key_test.exs b/test/xdr/transactions/from_ed25519_public_key_test.exs deleted file mode 100644 index 7f326bf5..00000000 --- a/test/xdr/transactions/from_ed25519_public_key_test.exs +++ /dev/null @@ -1,72 +0,0 @@ -defmodule StellarBase.XDR.FromEd25519PublicKeyTest do - use ExUnit.Case - - alias StellarBase.XDR.{Signature, UInt256, FromEd25519PublicKey} - - alias StellarBase.StrKey - - describe "FromEd25519PublicKey" do - setup do - key = - "GCVILYTXYXYHZIBYEF4BSLATAP3CPZMW23NE6DUL7I6LCCDUNFBQFAVR" - |> StrKey.decode!(:ed25519_public_key) - |> UInt256.new() - - signature = Signature.new("SAPVVUQ2G755KGQOOY5A3AGTMWCCQQTJMGSXAUKMFT45OFCL7NCSTRWI") - - salt = - UInt256.new( - <<72, 101, 108, 108, 111, 32, 119, 111, 114, 108, 100, 0, 21, 0, 1, 0, 72, 101, 108, - 108, 111, 32, 119, 111, 114, 108, 100, 0, 21, 0, 1, 0>> - ) - - from_ed25519_public_key = FromEd25519PublicKey.new(key, signature, salt) - - %{ - key: key, - signature: signature, - salt: salt, - from_ed25519_public_key: from_ed25519_public_key, - binary: - <<170, 133, 226, 119, 197, 240, 124, 160, 56, 33, 120, 25, 44, 19, 3, 246, 39, 229, 150, - 214, 218, 79, 14, 139, 250, 60, 177, 8, 116, 105, 67, 2, 0, 0, 0, 56, 83, 65, 80, 86, - 86, 85, 81, 50, 71, 55, 53, 53, 75, 71, 81, 79, 79, 89, 53, 65, 51, 65, 71, 84, 77, - 87, 67, 67, 81, 81, 84, 74, 77, 71, 83, 88, 65, 85, 75, 77, 70, 84, 52, 53, 79, 70, - 67, 76, 55, 78, 67, 83, 84, 82, 87, 73, 72, 101, 108, 108, 111, 32, 119, 111, 114, - 108, 100, 0, 21, 0, 1, 0, 72, 101, 108, 108, 111, 32, 119, 111, 114, 108, 100, 0, 21, - 0, 1, 0>> - } - end - - test "new/2", %{key: key, signature: signature, salt: salt} do - %FromEd25519PublicKey{key: ^key, signature: ^signature, salt: ^salt} = - FromEd25519PublicKey.new(key, signature, salt) - end - - test "encode_xdr/1", %{from_ed25519_public_key: from_ed25519_public_key, binary: binary} do - {:ok, ^binary} = FromEd25519PublicKey.encode_xdr(from_ed25519_public_key) - end - - test "encode_xdr!/1", %{ - from_ed25519_public_key: from_ed25519_public_key, - binary: binary - } do - ^binary = FromEd25519PublicKey.encode_xdr!(from_ed25519_public_key) - end - - test "decode_xdr/2", %{from_ed25519_public_key: from_ed25519_public_key, binary: binary} do - {:ok, {^from_ed25519_public_key, ""}} = FromEd25519PublicKey.decode_xdr(binary) - end - - test "decode_xdr/2 with an invalid binary" do - {:error, :not_binary} = FromEd25519PublicKey.decode_xdr(123) - end - - test "decode_xdr!/2", %{ - from_ed25519_public_key: from_ed25519_public_key, - binary: binary - } do - {^from_ed25519_public_key, ""} = FromEd25519PublicKey.decode_xdr!(binary) - end - end -end diff --git a/test/xdr/transactions/hash_id_preimage__soroban_authorization_test.exs b/test/xdr/transactions/hash_id_preimage__soroban_authorization_test.exs new file mode 100644 index 00000000..4c3bdd82 --- /dev/null +++ b/test/xdr/transactions/hash_id_preimage__soroban_authorization_test.exs @@ -0,0 +1,139 @@ +defmodule StellarBase.XDR.HashIDPreimageSorobanAuthorizationTest do + use ExUnit.Case + + alias StellarBase.XDR.{ + HashIDPreimageSorobanAuthorization, + Hash, + Int64, + UInt32, + SCAddress, + SCAddressType, + SCSymbol, + SCVal, + SCValType, + SCVec, + SorobanAuthorizedContractFunction, + SorobanAuthorizedFunction, + SorobanAuthorizedFunctionType, + SorobanAuthorizedInvocation, + SorobanAuthorizedInvocationList + } + + describe "HashIDPreimageSorobanAuthorization" do + setup do + network_id = Hash.new("GCIZ3GSM5XL7OUS4UP64THMDZ7CZ3ZWN") + + nonce = Int64.new(9_223_372_036_854_775_806) + signature_expiration_ledger = UInt32.new(123_154) + function_name = SCSymbol.new("Hello") + scval1 = SCVal.new(Int64.new(3), SCValType.new(:SCV_I64)) + scval2 = SCVal.new(Int64.new(2), SCValType.new(:SCV_I64)) + sc_vals = [scval1, scval2] + args = SCVec.new(sc_vals) + + address = Hash.new("CAWIIZPXNRY7X3FKFO4CWJT5DQOSEXQK") + sc_address = SCAddress.new(address, SCAddressType.new(:SC_ADDRESS_TYPE_CONTRACT)) + + contract_function = SorobanAuthorizedContractFunction.new(sc_address, function_name, args) + + auth_function = + SorobanAuthorizedFunction.new(contract_function, SorobanAuthorizedFunctionType.new()) + + auth_sub_invocation = + contract_function + |> SorobanAuthorizedFunction.new(SorobanAuthorizedFunctionType.new()) + |> SorobanAuthorizedInvocation.new(SorobanAuthorizedInvocationList.new([])) + + sub_invocations = + SorobanAuthorizedInvocationList.new([ + auth_sub_invocation, + auth_sub_invocation + ]) + + invocation = SorobanAuthorizedInvocation.new(auth_function, sub_invocations) + + %{ + network_id: network_id, + nonce: nonce, + invocation: invocation, + signature_expiration_ledger: signature_expiration_ledger, + hash_id_preimage_contract_auth: + HashIDPreimageSorobanAuthorization.new( + network_id, + nonce, + signature_expiration_ledger, + invocation + ), + binary: + <<71, 67, 73, 90, 51, 71, 83, 77, 53, 88, 76, 55, 79, 85, 83, 52, 85, 80, 54, 52, 84, + 72, 77, 68, 90, 55, 67, 90, 51, 90, 87, 78, 127, 255, 255, 255, 255, 255, 255, 254, 0, + 1, 225, 18, 0, 0, 0, 0, 0, 0, 0, 1, 67, 65, 87, 73, 73, 90, 80, 88, 78, 82, 89, 55, + 88, 51, 70, 75, 70, 79, 52, 67, 87, 74, 84, 53, 68, 81, 79, 83, 69, 88, 81, 75, 0, 0, + 0, 5, 72, 101, 108, 108, 111, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 6, 0, 0, 0, 0, 0, 0, 0, 3, + 0, 0, 0, 6, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 1, 67, 65, 87, + 73, 73, 90, 80, 88, 78, 82, 89, 55, 88, 51, 70, 75, 70, 79, 52, 67, 87, 74, 84, 53, + 68, 81, 79, 83, 69, 88, 81, 75, 0, 0, 0, 5, 72, 101, 108, 108, 111, 0, 0, 0, 0, 0, 0, + 2, 0, 0, 0, 6, 0, 0, 0, 0, 0, 0, 0, 3, 0, 0, 0, 6, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 1, 67, 65, 87, 73, 73, 90, 80, 88, 78, 82, 89, 55, 88, 51, 70, + 75, 70, 79, 52, 67, 87, 74, 84, 53, 68, 81, 79, 83, 69, 88, 81, 75, 0, 0, 0, 5, 72, + 101, 108, 108, 111, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 6, 0, 0, 0, 0, 0, 0, 0, 3, 0, 0, 0, + 6, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0>> + } + end + + test "new/1", %{ + network_id: network_id, + nonce: nonce, + signature_expiration_ledger: signature_expiration_ledger, + invocation: invocation + } do + %HashIDPreimageSorobanAuthorization{ + network_id: ^network_id, + nonce: ^nonce, + signature_expiration_ledger: ^signature_expiration_ledger, + invocation: ^invocation + } = + HashIDPreimageSorobanAuthorization.new( + network_id, + nonce, + signature_expiration_ledger, + invocation + ) + end + + test "encode_xdr/1", %{ + hash_id_preimage_contract_auth: hash_id_preimage_contract_auth, + binary: binary + } do + {:ok, ^binary} = + HashIDPreimageSorobanAuthorization.encode_xdr(hash_id_preimage_contract_auth) + end + + test "encode_xdr!/1", %{ + hash_id_preimage_contract_auth: hash_id_preimage_contract_auth, + binary: binary + } do + ^binary = HashIDPreimageSorobanAuthorization.encode_xdr!(hash_id_preimage_contract_auth) + end + + test "decode_xdr/2", %{ + hash_id_preimage_contract_auth: hash_id_preimage_contract_auth, + binary: binary + } do + {:ok, {^hash_id_preimage_contract_auth, ""}} = + HashIDPreimageSorobanAuthorization.decode_xdr(binary) + end + + test "decode_xdr/2 with an invalid binary" do + {:error, :not_binary} = HashIDPreimageSorobanAuthorization.decode_xdr(123) + end + + test "decode_xdr!/2", %{ + hash_id_preimage_contract_auth: hash_id_preimage_contract_auth, + binary: binary + } do + {^hash_id_preimage_contract_auth, ""} = + HashIDPreimageSorobanAuthorization.decode_xdr!(binary) + end + end +end diff --git a/test/xdr/transactions/hash_id_preimage_contract_auth_test.exs b/test/xdr/transactions/hash_id_preimage_contract_auth_test.exs deleted file mode 100644 index cb619b3e..00000000 --- a/test/xdr/transactions/hash_id_preimage_contract_auth_test.exs +++ /dev/null @@ -1,116 +0,0 @@ -defmodule StellarBase.XDR.HashIDPreimageContractAuthTest do - use ExUnit.Case - - alias StellarBase.XDR.{ - HashIDPreimageContractAuth, - Hash, - UInt64, - AuthorizedInvocation, - AuthorizedInvocationList, - SCSymbol, - SCVal, - SCValType, - SCVec, - Int64 - } - - describe "HashIDPreimageContractAuth" do - setup do - network_id = Hash.new("GCIZ3GSM5XL7OUS4UP64THMDZ7CZ3ZWN") - - nonce = UInt64.new(18_446_744_073_709_551_615) - - contract_id = Hash.new("GCIZ3GSM5XL7OUS4UP64THMDZ7CZ3ZWK") - function_name = SCSymbol.new("Hello") - scval1 = SCVal.new(Int64.new(3), SCValType.new(:SCV_I64)) - scval2 = SCVal.new(Int64.new(2), SCValType.new(:SCV_I64)) - sc_vals = [scval1, scval2] - args = SCVec.new(sc_vals) - - auth_sub_invocation = - AuthorizedInvocation.new( - contract_id, - function_name, - args, - AuthorizedInvocationList.new() - ) - - sub_invocations = - AuthorizedInvocationList.new([ - auth_sub_invocation, - auth_sub_invocation, - auth_sub_invocation - ]) - - invocation = AuthorizedInvocation.new(contract_id, function_name, args, sub_invocations) - - %{ - network_id: network_id, - nonce: nonce, - invocation: invocation, - hash_id_preimage_contract_auth: - HashIDPreimageContractAuth.new(network_id, nonce, invocation), - binary: - <<71, 67, 73, 90, 51, 71, 83, 77, 53, 88, 76, 55, 79, 85, 83, 52, 85, 80, 54, 52, 84, - 72, 77, 68, 90, 55, 67, 90, 51, 90, 87, 78, 255, 255, 255, 255, 255, 255, 255, 255, - 71, 67, 73, 90, 51, 71, 83, 77, 53, 88, 76, 55, 79, 85, 83, 52, 85, 80, 54, 52, 84, - 72, 77, 68, 90, 55, 67, 90, 51, 90, 87, 75, 0, 0, 0, 5, 72, 101, 108, 108, 111, 0, 0, - 0, 0, 0, 0, 2, 0, 0, 0, 6, 0, 0, 0, 0, 0, 0, 0, 3, 0, 0, 0, 6, 0, 0, 0, 0, 0, 0, 0, 2, - 0, 0, 0, 3, 71, 67, 73, 90, 51, 71, 83, 77, 53, 88, 76, 55, 79, 85, 83, 52, 85, 80, - 54, 52, 84, 72, 77, 68, 90, 55, 67, 90, 51, 90, 87, 75, 0, 0, 0, 5, 72, 101, 108, 108, - 111, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 6, 0, 0, 0, 0, 0, 0, 0, 3, 0, 0, 0, 6, 0, 0, 0, 0, - 0, 0, 0, 2, 0, 0, 0, 0, 71, 67, 73, 90, 51, 71, 83, 77, 53, 88, 76, 55, 79, 85, 83, - 52, 85, 80, 54, 52, 84, 72, 77, 68, 90, 55, 67, 90, 51, 90, 87, 75, 0, 0, 0, 5, 72, - 101, 108, 108, 111, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 6, 0, 0, 0, 0, 0, 0, 0, 3, 0, 0, 0, - 6, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 71, 67, 73, 90, 51, 71, 83, 77, 53, 88, 76, 55, - 79, 85, 83, 52, 85, 80, 54, 52, 84, 72, 77, 68, 90, 55, 67, 90, 51, 90, 87, 75, 0, 0, - 0, 5, 72, 101, 108, 108, 111, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 6, 0, 0, 0, 0, 0, 0, 0, 3, - 0, 0, 0, 6, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0>> - } - end - - test "new/1", %{ - network_id: network_id, - nonce: nonce, - invocation: invocation - } do - %HashIDPreimageContractAuth{ - network_id: ^network_id, - nonce: ^nonce, - invocation: ^invocation - } = HashIDPreimageContractAuth.new(network_id, nonce, invocation) - end - - test "encode_xdr/1", %{ - hash_id_preimage_contract_auth: hash_id_preimage_contract_auth, - binary: binary - } do - {:ok, ^binary} = HashIDPreimageContractAuth.encode_xdr(hash_id_preimage_contract_auth) - end - - test "encode_xdr!/1", %{ - hash_id_preimage_contract_auth: hash_id_preimage_contract_auth, - binary: binary - } do - ^binary = HashIDPreimageContractAuth.encode_xdr!(hash_id_preimage_contract_auth) - end - - test "decode_xdr/2", %{ - hash_id_preimage_contract_auth: hash_id_preimage_contract_auth, - binary: binary - } do - {:ok, {^hash_id_preimage_contract_auth, ""}} = HashIDPreimageContractAuth.decode_xdr(binary) - end - - test "decode_xdr/2 with an invalid binary" do - {:error, :not_binary} = HashIDPreimageContractAuth.decode_xdr(123) - end - - test "decode_xdr!/2", %{ - hash_id_preimage_contract_auth: hash_id_preimage_contract_auth, - binary: binary - } do - {^hash_id_preimage_contract_auth, ""} = HashIDPreimageContractAuth.decode_xdr!(binary) - end - end -end diff --git a/test/xdr/transactions/hash_id_preimage_create_contract_args_test.exs b/test/xdr/transactions/hash_id_preimage_create_contract_args_test.exs deleted file mode 100644 index 9af55d2b..00000000 --- a/test/xdr/transactions/hash_id_preimage_create_contract_args_test.exs +++ /dev/null @@ -1,89 +0,0 @@ -defmodule StellarBase.XDR.HashIDPreimageCreateContractArgsTest do - use ExUnit.Case - - alias StellarBase.XDR.{ - HashIDPreimageCreateContractArgs, - Hash, - UInt256, - SCContractExecutable, - SCContractExecutableType - } - - describe "HashIDPreimageCreateContractArgs" do - setup do - network_id = Hash.new("GCIZ3GSM5XL7OUS4UP64THMDZ7CZ3ZWN") - - contract_executable = Hash.new("GCIZ3GSM5XL7OUS4UP64THMDZ7CZ3ZWK") - sc_contract_executable_type = SCContractExecutableType.new(:SCCONTRACT_EXECUTABLE_WASM_REF) - executable = SCContractExecutable.new(contract_executable, sc_contract_executable_type) - - salt = - UInt256.new( - <<72, 101, 108, 108, 111, 32, 119, 111, 114, 108, 100, 0, 21, 0, 1, 0, 72, 101, 108, - 108, 111, 32, 119, 111, 114, 108, 100, 0, 21, 0, 1, 0>> - ) - - %{ - network_id: network_id, - executable: executable, - salt: salt, - hash_id_preimage_create_contract_args: - HashIDPreimageCreateContractArgs.new(network_id, executable, salt), - binary: - <<71, 67, 73, 90, 51, 71, 83, 77, 53, 88, 76, 55, 79, 85, 83, 52, 85, 80, 54, 52, 84, - 72, 77, 68, 90, 55, 67, 90, 51, 90, 87, 78, 0, 0, 0, 0, 71, 67, 73, 90, 51, 71, 83, - 77, 53, 88, 76, 55, 79, 85, 83, 52, 85, 80, 54, 52, 84, 72, 77, 68, 90, 55, 67, 90, - 51, 90, 87, 75, 72, 101, 108, 108, 111, 32, 119, 111, 114, 108, 100, 0, 21, 0, 1, 0, - 72, 101, 108, 108, 111, 32, 119, 111, 114, 108, 100, 0, 21, 0, 1, 0>> - } - end - - test "new/1", %{ - network_id: network_id, - executable: executable, - salt: salt - } do - %HashIDPreimageCreateContractArgs{ - network_id: ^network_id, - executable: ^executable, - salt: ^salt - } = HashIDPreimageCreateContractArgs.new(network_id, executable, salt) - end - - test "encode_xdr/1", %{ - hash_id_preimage_create_contract_args: hash_id_preimage_create_contract_args, - binary: binary - } do - {:ok, ^binary} = - HashIDPreimageCreateContractArgs.encode_xdr(hash_id_preimage_create_contract_args) - end - - test "encode_xdr!/1", %{ - hash_id_preimage_create_contract_args: hash_id_preimage_create_contract_args, - binary: binary - } do - ^binary = - HashIDPreimageCreateContractArgs.encode_xdr!(hash_id_preimage_create_contract_args) - end - - test "decode_xdr/2", %{ - hash_id_preimage_create_contract_args: hash_id_preimage_create_contract_args, - binary: binary - } do - {:ok, {^hash_id_preimage_create_contract_args, ""}} = - HashIDPreimageCreateContractArgs.decode_xdr(binary) - end - - test "decode_xdr/2 with an invalid binary" do - {:error, :not_binary} = HashIDPreimageCreateContractArgs.decode_xdr(123) - end - - test "decode_xdr!/2", %{ - hash_id_preimage_create_contract_args: hash_id_preimage_create_contract_args, - binary: binary - } do - {^hash_id_preimage_create_contract_args, ""} = - HashIDPreimageCreateContractArgs.decode_xdr!(binary) - end - end -end diff --git a/test/xdr/transactions/hash_id_preimage_test.exs b/test/xdr/transactions/hash_id_preimage_test.exs index 25008375..2702b29f 100644 --- a/test/xdr/transactions/hash_id_preimage_test.exs +++ b/test/xdr/transactions/hash_id_preimage_test.exs @@ -6,9 +6,9 @@ defmodule StellarBase.XDR.HashIDPreimageTest do alias StellarBase.XDR.{ EnvelopeType, HashIDPreimage, - OperationID, + HashIDPreimageOperationID, PoolID, - RevokeID, + HashIDPreimageRevokeID, SequenceNumber, UInt32 } @@ -29,7 +29,7 @@ defmodule StellarBase.XDR.HashIDPreimageTest do describe "OperationID" do setup %{account_id: account_id, seq_number: seq_number, op_num: op_num} do envelope_type = EnvelopeType.new(:ENVELOPE_TYPE_OP_ID) - operation_id = OperationID.new(account_id, seq_number, op_num) + operation_id = HashIDPreimageOperationID.new(account_id, seq_number, op_num) %{ envelope_type: envelope_type, @@ -43,7 +43,7 @@ defmodule StellarBase.XDR.HashIDPreimageTest do end test "new/1", %{operation_id: operation_id, envelope_type: envelope_type} do - %HashIDPreimage{hash_id: ^operation_id, type: ^envelope_type} = + %HashIDPreimage{value: ^operation_id, type: ^envelope_type} = HashIDPreimage.new(operation_id, envelope_type) end @@ -79,7 +79,8 @@ defmodule StellarBase.XDR.HashIDPreimageTest do issuer: "GBZNLMUQMIN3VGUJISKZU7GNY3O3XLMYEHJCKCSMDHKLGSMKALRXOEZD" ) - revoke_id = RevokeID.new(account_id, seq_number, op_num, liquidity_pool_id, asset) + revoke_id = + HashIDPreimageRevokeID.new(account_id, seq_number, op_num, liquidity_pool_id, asset) %{ envelope_type: envelope_type, @@ -97,7 +98,7 @@ defmodule StellarBase.XDR.HashIDPreimageTest do end test "new/1", %{revoke_id: revoke_id, envelope_type: envelope_type} do - %HashIDPreimage{hash_id: ^revoke_id, type: ^envelope_type} = + %HashIDPreimage{value: ^revoke_id, type: ^envelope_type} = HashIDPreimage.new(revoke_id, envelope_type) end diff --git a/test/xdr/transactions/host_function_args_test.exs b/test/xdr/transactions/host_function_args_test.exs deleted file mode 100644 index bdca8d54..00000000 --- a/test/xdr/transactions/host_function_args_test.exs +++ /dev/null @@ -1,150 +0,0 @@ -defmodule StellarBase.XDR.HostFunctionArgsTest do - use ExUnit.Case - - alias StellarBase.XDR.{ - HostFunctionType, - HostFunctionArgs, - SCVal, - Int64, - SCValType, - VariableOpaque256000, - CreateContractArgs, - SCVec, - UploadContractWasmArgs, - Hash, - SCContractExecutableType, - SCContractExecutable, - UInt256, - ContractIDType, - ContractID - } - - alias StellarBase.StrKey - - describe "HostFunctionArgs" do - setup do - ## SCVec - scval1 = SCVal.new(Int64.new(3), SCValType.new(:SCV_I64)) - scval2 = SCVal.new(Int64.new(2), SCValType.new(:SCV_I64)) - sc_vals = [scval1, scval2] - sc_vec = SCVec.new(sc_vals) - - ## CreateContractArgs - # SCContractExecutable - contract_executable = Hash.new("GCIZ3GSM5XL7OUS4UP64THMDZ7CZ3ZWN") - sc_contract_executable_type = SCContractExecutableType.new(:SCCONTRACT_EXECUTABLE_WASM_REF) - - sc_contract_executable = - SCContractExecutable.new(contract_executable, sc_contract_executable_type) - - # ContractID - salt = - "GCJCFK7GZEOXVAWWOWYFTR5C5IZAQBYV5HIJUGVZPUBDJNRFVXXZEHHV" - |> StrKey.decode!(:ed25519_public_key) - |> UInt256.new() - - contract_id_type = ContractIDType.new(:CONTRACT_ID_FROM_SOURCE_ACCOUNT) - contract_id = ContractID.new(salt, contract_id_type) - - create_contract_args = CreateContractArgs.new(contract_id, sc_contract_executable) - - ## UploadContractWasmArgs - code = VariableOpaque256000.new("GCIZ3GSM5") - install_contract_code_args = UploadContractWasmArgs.new(code) - - discriminants = [ - %{ - host_function_type: HostFunctionType.new(:HOST_FUNCTION_TYPE_INVOKE_CONTRACT), - value: sc_vec, - binary: - <<0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 6, 0, 0, 0, 0, 0, 0, 0, 3, 0, 0, 0, 6, 0, 0, 0, 0, - 0, 0, 0, 2>> - }, - %{ - host_function_type: HostFunctionType.new(:HOST_FUNCTION_TYPE_CREATE_CONTRACT), - value: create_contract_args, - binary: - <<0, 0, 0, 1, 0, 0, 0, 0, 146, 34, 171, 230, 201, 29, 122, 130, 214, 117, 176, 89, - 199, 162, 234, 50, 8, 7, 21, 233, 208, 154, 26, 185, 125, 2, 52, 182, 37, 173, 239, - 146, 0, 0, 0, 0, 71, 67, 73, 90, 51, 71, 83, 77, 53, 88, 76, 55, 79, 85, 83, 52, 85, - 80, 54, 52, 84, 72, 77, 68, 90, 55, 67, 90, 51, 90, 87, 78>> - }, - %{ - host_function_type: HostFunctionType.new(:HOST_FUNCTION_TYPE_UPLOAD_CONTRACT_WASM), - value: install_contract_code_args, - binary: <<0, 0, 0, 2, 0, 0, 0, 9, 71, 67, 73, 90, 51, 71, 83, 77, 53, 0, 0, 0>> - } - ] - - %{discriminants: discriminants} - end - - test "new/1", %{discriminants: discriminants} do - for %{host_function_type: host_function_type, value: host_function} <- - discriminants do - %HostFunctionArgs{value: ^host_function, type: ^host_function_type} = - HostFunctionArgs.new(host_function, host_function_type) - end - end - - test "encode_xdr/1", %{discriminants: discriminants} do - for %{ - value: host_function, - host_function_type: host_function_type, - binary: binary - } <- discriminants do - xdr = HostFunctionArgs.new(host_function, host_function_type) - {:ok, ^binary} = HostFunctionArgs.encode_xdr(xdr) - end - end - - test "encode_xdr!/1", %{discriminants: discriminants} do - for %{ - value: host_function, - host_function_type: host_function_type, - binary: binary - } <- discriminants do - xdr = HostFunctionArgs.new(host_function, host_function_type) - ^binary = HostFunctionArgs.encode_xdr!(xdr) - end - end - - test "encode_xdr/1 with an invalid type", %{discriminants: [host_function | _rest]} do - host_function_type = HostFunctionType.new(:NEW_ADDRESS) - - assert_raise XDR.EnumError, - "The key which you try to encode doesn't belong to the current declarations", - fn -> - host_function - |> HostFunctionArgs.new(host_function_type) - |> HostFunctionArgs.encode_xdr() - end - end - - test "decode_xdr/2", %{discriminants: discriminants} do - for %{ - value: host_function, - host_function_type: host_function_type, - binary: binary - } <- discriminants do - xdr = HostFunctionArgs.new(host_function, host_function_type) - {:ok, {^xdr, ""}} = HostFunctionArgs.decode_xdr(binary) - end - end - - test "decode_xdr/2 with an invalid binary" do - {:error, :not_binary} = HostFunctionArgs.decode_xdr(123) - end - - test "decode_xdr!/2", %{discriminants: discriminants} do - for %{ - value: host_function, - host_function_type: host_function_type, - binary: binary - } <- discriminants do - xdr = HostFunctionArgs.new(host_function, host_function_type) - {^xdr, ""} = HostFunctionArgs.decode_xdr!(binary) - end - end - end -end diff --git a/test/xdr/transactions/host_function_list100.exs b/test/xdr/transactions/host_function_list100.exs deleted file mode 100644 index a5451dfd..00000000 --- a/test/xdr/transactions/host_function_list100.exs +++ /dev/null @@ -1,143 +0,0 @@ -defmodule StellarBase.XDR.HostFunctionList100 do - use ExUnit.Case - - alias StellarBase.XDR.{ - SCVal, - SCValType, - SCVec, - Int64, - HostFunctionType, - HostFunctionArgs, - HostFunction, - PublicKeyType, - UInt256, - PublicKey, - ContractAuthList, - AccountID, - AuthorizedInvocation, - AuthorizedInvocationList, - AccountID, - AddressWithNonce, - ContractAuth, - Hash, - Int64, - PublicKey, - PublicKeyType, - SCAddress, - SCAddressType, - SCSymbol, - SCVal, - SCValType, - SCVec, - OptionalAddressWithNonce, - UInt64 - } - - alias StellarBase.StrKey - - describe "HostFunction" do - setup do - ## HostFunction - scval1 = SCVal.new(Int64.new(3), SCValType.new(:SCV_I64)) - scval2 = SCVal.new(Int64.new(2), SCValType.new(:SCV_I64)) - sc_vals = [scval1, scval2] - sc_vec = SCVec.new(sc_vals) - host_function_type = HostFunctionType.new(:HOST_FUNCTION_TYPE_INVOKE_CONTRACT) - host_function_args = HostFunctionArgs.new(sc_vec, host_function_type) - - ## LedgerFootprint - pk_type = PublicKeyType.new(:PUBLIC_KEY_TYPE_ED25519) - - account_id = - "GBZNLMUQMIN3VGUJISKZU7GNY3O3XLMYEHJCKCSMDHKLGSMKALRXOEZD" - |> StrKey.decode!(:ed25519_public_key) - |> UInt256.new() - |> PublicKey.new(pk_type) - |> AccountID.new() - - ## ContractAuthList - # AddressWithNonce - sc_address_type = SCAddressType.new(:SC_ADDRESS_TYPE_ACCOUNT) - sc_address = SCAddress.new(account_id, sc_address_type) - nonce = UInt64.new(123) - - address_with_nonce = - sc_address |> AddressWithNonce.new(nonce) |> OptionalAddressWithNonce.new() - - # AuthorizedInvocation - contract_id = Hash.new("GCIZ3GSM5XL7OUS4UP64THMDZ7CZ3ZWN") - function_name = SCSymbol.new("Hello") - - authorized_invocation = - AuthorizedInvocation.new( - contract_id, - function_name, - sc_vec, - AuthorizedInvocationList.new() - ) - - auth = ContractAuth.new(address_with_nonce, authorized_invocation, sc_vec) - auth_list = ContractAuthList.new([auth, auth]) - host_function = HostFunction.new(host_function_args, auth_list) - - %{ - host_function_args: host_function_args, - auth_list: auth_list, - host_function: host_function, - binary: - <<0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 6, 0, 0, 0, 0, 0, 0, 0, 3, 0, 0, 0, 6, 0, 0, 0, 0, 0, - 0, 0, 2, 0, 0, 0, 2, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 114, 213, 178, 144, 98, 27, - 186, 154, 137, 68, 149, 154, 124, 205, 198, 221, 187, 173, 152, 33, 210, 37, 10, 76, - 25, 212, 179, 73, 138, 2, 227, 119, 0, 0, 0, 0, 0, 0, 0, 123, 71, 67, 73, 90, 51, 71, - 83, 77, 53, 88, 76, 55, 79, 85, 83, 52, 85, 80, 54, 52, 84, 72, 77, 68, 90, 55, 67, - 90, 51, 90, 87, 78, 0, 0, 0, 5, 72, 101, 108, 108, 111, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, - 6, 0, 0, 0, 0, 0, 0, 0, 3, 0, 0, 0, 6, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 2, - 0, 0, 0, 6, 0, 0, 0, 0, 0, 0, 0, 3, 0, 0, 0, 6, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 1, 0, - 0, 0, 0, 0, 0, 0, 0, 114, 213, 178, 144, 98, 27, 186, 154, 137, 68, 149, 154, 124, - 205, 198, 221, 187, 173, 152, 33, 210, 37, 10, 76, 25, 212, 179, 73, 138, 2, 227, 119, - 0, 0, 0, 0, 0, 0, 0, 123, 71, 67, 73, 90, 51, 71, 83, 77, 53, 88, 76, 55, 79, 85, 83, - 52, 85, 80, 54, 52, 84, 72, 77, 68, 90, 55, 67, 90, 51, 90, 87, 78, 0, 0, 0, 5, 72, - 101, 108, 108, 111, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 6, 0, 0, 0, 0, 0, 0, 0, 3, 0, 0, 0, - 6, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 6, 0, 0, 0, 0, 0, 0, 0, 3, - 0, 0, 0, 6, 0, 0, 0, 0, 0, 0, 0, 2>> - } - end - - test "new/1", %{host_function_args: host_function_args, auth_list: auth_list} do - %HostFunction{args: ^host_function_args, auth: ^auth_list} = - HostFunction.new(host_function_args, auth_list) - end - - test "encode_xdr/1", %{ - host_function: host_function, - binary: binary - } do - {:ok, ^binary} = HostFunction.encode_xdr(host_function) - end - - test "encode_xdr!/1", %{ - host_function: host_function, - binary: binary - } do - ^binary = HostFunction.encode_xdr!(host_function) - end - - test "decode_xdr/2", %{ - host_function: host_function, - binary: binary - } do - {:ok, {^host_function, ""}} = HostFunction.decode_xdr(binary) - end - - test "decode_xdr/2 with an invalid binary" do - {:error, :not_binary} = HostFunction.decode_xdr(123) - end - - test "decode_xdr!/2", %{ - host_function: host_function, - binary: binary - } do - {^host_function, ^binary} = HostFunction.decode_xdr!(binary <> binary) - end - end -end diff --git a/test/xdr/transactions/host_function_list100_test.exs b/test/xdr/transactions/host_function_list100_test.exs deleted file mode 100644 index 19c27067..00000000 --- a/test/xdr/transactions/host_function_list100_test.exs +++ /dev/null @@ -1,137 +0,0 @@ -defmodule StellarBase.XDR.HostFunctionList100Test do - use ExUnit.Case - - alias StellarBase.XDR.{ - SCVal, - SCValType, - SCVec, - Int64, - HostFunctionType, - HostFunctionArgs, - HostFunctionList100, - HostFunction, - PublicKeyType, - UInt256, - PublicKey, - ContractAuthList, - AccountID, - AuthorizedInvocation, - AuthorizedInvocationList, - AddressWithNonce, - ContractAuth, - Hash, - Int64, - SCAddress, - SCAddressType, - SCSymbol, - OptionalAddressWithNonce, - UInt64 - } - - alias StellarBase.StrKey - - describe "HostFunction" do - setup do - ## HostFunction - scval1 = SCVal.new(Int64.new(3), SCValType.new(:SCV_I64)) - scval2 = SCVal.new(Int64.new(2), SCValType.new(:SCV_I64)) - sc_vals = [scval1, scval2] - sc_vec = SCVec.new(sc_vals) - host_function_type = HostFunctionType.new(:HOST_FUNCTION_TYPE_INVOKE_CONTRACT) - host_function_args = HostFunctionArgs.new(sc_vec, host_function_type) - - ## LedgerFootprint - pk_type = PublicKeyType.new(:PUBLIC_KEY_TYPE_ED25519) - - account_id = - "GBZNLMUQMIN3VGUJISKZU7GNY3O3XLMYEHJCKCSMDHKLGSMKALRXOEZD" - |> StrKey.decode!(:ed25519_public_key) - |> UInt256.new() - |> PublicKey.new(pk_type) - |> AccountID.new() - - ## ContractAuthList - # AddressWithNonce - sc_address_type = SCAddressType.new(:SC_ADDRESS_TYPE_ACCOUNT) - sc_address = SCAddress.new(account_id, sc_address_type) - nonce = UInt64.new(123) - - address_with_nonce = - sc_address |> AddressWithNonce.new(nonce) |> OptionalAddressWithNonce.new() - - # AuthorizedInvocation - contract_id = Hash.new("GCIZ3GSM5XL7OUS4UP64THMDZ7CZ3ZWN") - function_name = SCSymbol.new("Hello") - - authorized_invocation = - AuthorizedInvocation.new( - contract_id, - function_name, - sc_vec, - AuthorizedInvocationList.new() - ) - - auth = ContractAuth.new(address_with_nonce, authorized_invocation, sc_vec) - auth_list = ContractAuthList.new([auth, auth]) - host_function = [HostFunction.new(host_function_args, auth_list)] - host_function_list = HostFunctionList100.new(host_function) - - %{ - host_function_list: host_function_list, - host_function: host_function, - binary: - <<0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 6, 0, 0, 0, 0, 0, 0, 0, 3, 0, 0, 0, 6, 0, - 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 2, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 114, 213, 178, - 144, 98, 27, 186, 154, 137, 68, 149, 154, 124, 205, 198, 221, 187, 173, 152, 33, 210, - 37, 10, 76, 25, 212, 179, 73, 138, 2, 227, 119, 0, 0, 0, 0, 0, 0, 0, 123, 71, 67, 73, - 90, 51, 71, 83, 77, 53, 88, 76, 55, 79, 85, 83, 52, 85, 80, 54, 52, 84, 72, 77, 68, - 90, 55, 67, 90, 51, 90, 87, 78, 0, 0, 0, 5, 72, 101, 108, 108, 111, 0, 0, 0, 0, 0, 0, - 2, 0, 0, 0, 6, 0, 0, 0, 0, 0, 0, 0, 3, 0, 0, 0, 6, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, - 0, 0, 0, 2, 0, 0, 0, 6, 0, 0, 0, 0, 0, 0, 0, 3, 0, 0, 0, 6, 0, 0, 0, 0, 0, 0, 0, 2, 0, - 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 114, 213, 178, 144, 98, 27, 186, 154, 137, 68, 149, - 154, 124, 205, 198, 221, 187, 173, 152, 33, 210, 37, 10, 76, 25, 212, 179, 73, 138, 2, - 227, 119, 0, 0, 0, 0, 0, 0, 0, 123, 71, 67, 73, 90, 51, 71, 83, 77, 53, 88, 76, 55, - 79, 85, 83, 52, 85, 80, 54, 52, 84, 72, 77, 68, 90, 55, 67, 90, 51, 90, 87, 78, 0, 0, - 0, 5, 72, 101, 108, 108, 111, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 6, 0, 0, 0, 0, 0, 0, 0, 3, - 0, 0, 0, 6, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 6, 0, 0, 0, 0, 0, - 0, 0, 3, 0, 0, 0, 6, 0, 0, 0, 0, 0, 0, 0, 2>> - } - end - - test "new/1", %{host_function: host_function} do - %HostFunctionList100{items: ^host_function} = HostFunctionList100.new(host_function) - end - - test "encode_xdr/1", %{ - host_function_list: host_function_list, - binary: binary - } do - {:ok, ^binary} = HostFunctionList100.encode_xdr(host_function_list) - end - - test "encode_xdr!/1", %{ - host_function_list: host_function_list, - binary: binary - } do - ^binary = HostFunctionList100.encode_xdr!(host_function_list) - end - - test "decode_xdr/2", %{ - host_function_list: host_function_list, - binary: binary - } do - {:ok, {^host_function_list, ""}} = HostFunctionList100.decode_xdr(binary) - end - - test "decode_xdr/2 with an invalid binary" do - {:error, :not_binary} = HostFunctionList100.decode_xdr(123) - end - - test "decode_xdr!/2", %{ - host_function_list: host_function_list, - binary: binary - } do - {^host_function_list, ^binary} = HostFunctionList100.decode_xdr!(binary <> binary) - end - end -end diff --git a/test/xdr/transactions/host_function_test.exs b/test/xdr/transactions/host_function_test.exs index 00227d5c..1d95d7f0 100644 --- a/test/xdr/transactions/host_function_test.exs +++ b/test/xdr/transactions/host_function_test.exs @@ -2,35 +2,26 @@ defmodule StellarBase.XDR.Operations.HostFunctionTest do use ExUnit.Case alias StellarBase.XDR.{ + ContractIDPreimage, + ContractIDPreimageFromAddress, + ContractIDPreimageType, + CreateContractArgs, + ContractExecutable, + ContractExecutableType, + SCAddress, + SCAddressType, SCVal, SCValType, SCVec, Int64, + Hash, HostFunctionType, - HostFunctionArgs, HostFunction, - PublicKeyType, - UInt256, - PublicKey, - ContractAuthList, - AccountID, - AuthorizedInvocation, - AuthorizedInvocationList, - AccountID, - AddressWithNonce, - ContractAuth, - Hash, Int64, - PublicKey, - PublicKeyType, - SCAddress, - SCAddressType, - SCSymbol, SCVal, SCValType, SCVec, - OptionalAddressWithNonce, - UInt64 + UInt256 } alias StellarBase.StrKey @@ -42,70 +33,73 @@ defmodule StellarBase.XDR.Operations.HostFunctionTest do scval2 = SCVal.new(Int64.new(2), SCValType.new(:SCV_I64)) sc_vals = [scval1, scval2] sc_vec = SCVec.new(sc_vals) - host_function_type = HostFunctionType.new(:HOST_FUNCTION_TYPE_INVOKE_CONTRACT) - host_function_args = HostFunctionArgs.new(sc_vec, host_function_type) + host_function_type = HostFunctionType.new() + host_function = HostFunction.new(sc_vec, host_function_type) + + host_function_create_type = HostFunctionType.new(:HOST_FUNCTION_TYPE_CREATE_CONTRACT) - ## LedgerFootprint - pk_type = PublicKeyType.new(:PUBLIC_KEY_TYPE_ED25519) + # ContractExecutable + address = Hash.new("CAWIIZPXNRY7X3FKFO4CWJT5DQOSEXQK") + sc_address = SCAddress.new(address, SCAddressType.new(:SC_ADDRESS_TYPE_CONTRACT)) - account_id = - "GBZNLMUQMIN3VGUJISKZU7GNY3O3XLMYEHJCKCSMDHKLGSMKALRXOEZD" + salt = + "GCJCFK7GZEOXVAWWOWYFTR5C5IZAQBYV5HIJUGVZPUBDJNRFVXXZEHHV" |> StrKey.decode!(:ed25519_public_key) |> UInt256.new() - |> PublicKey.new(pk_type) - |> AccountID.new() - - ## ContractAuthList - # AddressWithNonce - sc_address_type = SCAddressType.new(:SC_ADDRESS_TYPE_ACCOUNT) - sc_address = SCAddress.new(account_id, sc_address_type) - nonce = UInt64.new(123) - - address_with_nonce = - sc_address |> AddressWithNonce.new(nonce) |> OptionalAddressWithNonce.new() - - # AuthorizedInvocation - contract_id = Hash.new("GCIZ3GSM5XL7OUS4UP64THMDZ7CZ3ZWN") - function_name = SCSymbol.new("Hello") - - authorized_invocation = - AuthorizedInvocation.new( - contract_id, - function_name, - sc_vec, - AuthorizedInvocationList.new() + + id_preimage_address = + ContractIDPreimageFromAddress.new( + sc_address, + salt ) - auth = ContractAuth.new(address_with_nonce, authorized_invocation, sc_vec) - auth_list = ContractAuthList.new([auth, auth]) - host_function = HostFunction.new(host_function_args, auth_list) + contract_id_preimage = + ContractIDPreimage.new(id_preimage_address, ContractIDPreimageType.new()) + + sc_contract_executable_type = ContractExecutableType.new(:CONTRACT_EXECUTABLE_WASM) + + sc_contract_executable = ContractExecutable.new(address, sc_contract_executable_type) + + host_function_create_value = + CreateContractArgs.new(contract_id_preimage, sc_contract_executable) + + host_function_create_contract = + HostFunction.new(host_function_create_value, host_function_create_type) %{ - host_function_args: host_function_args, - auth_list: auth_list, + host_function_args: sc_vals, + host_function_create_type: host_function_create_type, + host_function_create_value: host_function_create_value, + host_function_create_contract: host_function_create_contract, + host_function_type: host_function_type, host_function: host_function, binary: <<0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 6, 0, 0, 0, 0, 0, 0, 0, 3, 0, 0, 0, 6, 0, 0, 0, 0, 0, - 0, 0, 2, 0, 0, 0, 2, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 114, 213, 178, 144, 98, 27, - 186, 154, 137, 68, 149, 154, 124, 205, 198, 221, 187, 173, 152, 33, 210, 37, 10, 76, - 25, 212, 179, 73, 138, 2, 227, 119, 0, 0, 0, 0, 0, 0, 0, 123, 71, 67, 73, 90, 51, 71, - 83, 77, 53, 88, 76, 55, 79, 85, 83, 52, 85, 80, 54, 52, 84, 72, 77, 68, 90, 55, 67, - 90, 51, 90, 87, 78, 0, 0, 0, 5, 72, 101, 108, 108, 111, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, - 6, 0, 0, 0, 0, 0, 0, 0, 3, 0, 0, 0, 6, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 2, - 0, 0, 0, 6, 0, 0, 0, 0, 0, 0, 0, 3, 0, 0, 0, 6, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 1, 0, - 0, 0, 0, 0, 0, 0, 0, 114, 213, 178, 144, 98, 27, 186, 154, 137, 68, 149, 154, 124, - 205, 198, 221, 187, 173, 152, 33, 210, 37, 10, 76, 25, 212, 179, 73, 138, 2, 227, 119, - 0, 0, 0, 0, 0, 0, 0, 123, 71, 67, 73, 90, 51, 71, 83, 77, 53, 88, 76, 55, 79, 85, 83, - 52, 85, 80, 54, 52, 84, 72, 77, 68, 90, 55, 67, 90, 51, 90, 87, 78, 0, 0, 0, 5, 72, - 101, 108, 108, 111, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 6, 0, 0, 0, 0, 0, 0, 0, 3, 0, 0, 0, - 6, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 6, 0, 0, 0, 0, 0, 0, 0, 3, - 0, 0, 0, 6, 0, 0, 0, 0, 0, 0, 0, 2>> + 0, 0, 2>>, + create_contact_binary: + <<0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 67, 65, 87, 73, 73, 90, 80, 88, 78, 82, 89, 55, + 88, 51, 70, 75, 70, 79, 52, 67, 87, 74, 84, 53, 68, 81, 79, 83, 69, 88, 81, 75, 146, + 34, 171, 230, 201, 29, 122, 130, 214, 117, 176, 89, 199, 162, 234, 50, 8, 7, 21, 233, + 208, 154, 26, 185, 125, 2, 52, 182, 37, 173, 239, 146, 0, 0, 0, 0, 67, 65, 87, 73, 73, + 90, 80, 88, 78, 82, 89, 55, 88, 51, 70, 75, 70, 79, 52, 67, 87, 74, 84, 53, 68, 81, + 79, 83, 69, 88, 81, 75>> } end - test "new/1", %{host_function_args: host_function_args, auth_list: auth_list} do - %HostFunction{args: ^host_function_args, auth: ^auth_list} = - HostFunction.new(host_function_args, auth_list) + test "new/1", %{ + host_function_args: host_function_args, + host_function_type: host_function_type + } do + %HostFunction{value: ^host_function_args, type: ^host_function_type} = + HostFunction.new(host_function_args, host_function_type) + end + + test "new create contract /1", %{ + host_function_create_value: host_function_create_value, + host_function_create_type: host_function_create_type + } do + %HostFunction{value: ^host_function_create_value, type: ^host_function_create_type} = + HostFunction.new(host_function_create_value, host_function_create_type) end test "encode_xdr/1", %{ @@ -115,6 +109,13 @@ defmodule StellarBase.XDR.Operations.HostFunctionTest do {:ok, ^binary} = HostFunction.encode_xdr(host_function) end + test "encode_xdr/1 with create contract type", %{ + host_function_create_contract: host_function_create_contract, + create_contact_binary: create_contact_binary + } do + {:ok, ^create_contact_binary} = HostFunction.encode_xdr(host_function_create_contract) + end + test "encode_xdr!/1", %{ host_function: host_function, binary: binary @@ -122,6 +123,13 @@ defmodule StellarBase.XDR.Operations.HostFunctionTest do ^binary = HostFunction.encode_xdr!(host_function) end + test "encode_xdr!/1 with create contract type", %{ + host_function_create_contract: host_function_create_contract, + create_contact_binary: create_contact_binary + } do + ^create_contact_binary = HostFunction.encode_xdr!(host_function_create_contract) + end + test "decode_xdr/2", %{ host_function: host_function, binary: binary @@ -129,6 +137,13 @@ defmodule StellarBase.XDR.Operations.HostFunctionTest do {:ok, {^host_function, ""}} = HostFunction.decode_xdr(binary) end + test "decode_xdr/2 with create contract type", %{ + host_function_create_contract: host_function_create_contract, + create_contact_binary: create_contact_binary + } do + {:ok, {^host_function_create_contract, ""}} = HostFunction.decode_xdr(create_contact_binary) + end + test "decode_xdr/2 with an invalid binary" do {:error, :not_binary} = HostFunction.decode_xdr(123) end @@ -139,5 +154,13 @@ defmodule StellarBase.XDR.Operations.HostFunctionTest do } do {^host_function, ^binary} = HostFunction.decode_xdr!(binary <> binary) end + + test "decode_xdr!/2 with create contract type", %{ + host_function_create_contract: host_function_create_contract, + create_contact_binary: create_contact_binary + } do + {^host_function_create_contract, ^create_contact_binary} = + HostFunction.decode_xdr!(create_contact_binary <> create_contact_binary) + end end end diff --git a/test/xdr/transactions/invoke_host_function_result_test.exs b/test/xdr/transactions/invoke_host_function_result_test.exs index 9ef3132b..b5581efa 100644 --- a/test/xdr/transactions/invoke_host_function_result_test.exs +++ b/test/xdr/transactions/invoke_host_function_result_test.exs @@ -1,13 +1,11 @@ defmodule StellarBase.XDR.InvokeHostFunctionResultTest do use ExUnit.Case + alias StellarBase.XDR.Hash + alias StellarBase.XDR.{ InvokeHostFunctionResult, - Int64, InvokeHostFunctionResultCode, - SCVal, - SCValType, - SCValList100, Void } @@ -24,18 +22,17 @@ defmodule StellarBase.XDR.InvokeHostFunctionResultTest do void = Void.new() - int_64 = Int64.new(3) - scval_type = SCValType.new(:SCV_I64) - scval = SCVal.new(int_64, scval_type) - scval_list = SCValList100.new([scval]) + hash = Hash.new("CAWIIZPXNRY7X3FKFO4CWJT5DQOSEXQK") discriminants = [ %{ - value: scval_list, + value: hash, invoke_host_function_result_type: invoke_host_function_result_success, invoke_host_function_result: - InvokeHostFunctionResult.new(scval_list, invoke_host_function_result_success), - binary: <<0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 6, 0, 0, 0, 0, 0, 0, 0, 3>> + InvokeHostFunctionResult.new(hash, invoke_host_function_result_success), + binary: + <<0, 0, 0, 0, 67, 65, 87, 73, 73, 90, 80, 88, 78, 82, 89, 55, 88, 51, 70, 75, 70, 79, + 52, 67, 87, 74, 84, 53, 68, 81, 79, 83, 69, 88, 81, 75>> }, %{ value: void, diff --git a/test/xdr/transactions/operation_body_test.exs b/test/xdr/transactions/operation_body_test.exs index 2cf4ca65..08ec9220 100644 --- a/test/xdr/transactions/operation_body_test.exs +++ b/test/xdr/transactions/operation_body_test.exs @@ -46,7 +46,7 @@ defmodule StellarBase.XDR.OperationBodyTest do end test "new/1", %{operation: operation, operation_type: operation_type} do - %OperationBody{operation: ^operation, type: ^operation_type} = + %OperationBody{value: ^operation, type: ^operation_type} = OperationBody.new(operation, operation_type) end diff --git a/test/xdr/transactions/operations/invoke_host_function_test.exs b/test/xdr/transactions/operations/invoke_host_function_test.exs index 273ec9a3..74505dc4 100644 --- a/test/xdr/transactions/operations/invoke_host_function_test.exs +++ b/test/xdr/transactions/operations/invoke_host_function_test.exs @@ -7,102 +7,70 @@ defmodule StellarBase.XDR.Operations.InvokeHostFunctionTest do SCVec, Int64, HostFunction, - HostFunctionArgs, HostFunctionType, - PublicKey, - PublicKeyType, - UInt256, - ContractAuth, - ContractAuthList, - AccountID, - AuthorizedInvocation, - AuthorizedInvocationList, - AddressWithNonce, Hash, - HostFunctionList100, SCAddress, SCAddressType, SCSymbol, - OptionalAddressWithNonce, - UInt64 + SorobanAuthorizedContractFunction, + SorobanAuthorizationEntryList, + SorobanAuthorizationEntry, + SorobanAuthorizedFunction, + SorobanAuthorizedFunctionType, + SorobanAuthorizedInvocation, + SorobanAuthorizedInvocationList, + SorobanCredentials, + SorobanCredentialsType, + Void } alias StellarBase.XDR.Operations.InvokeHostFunction - alias StellarBase.StrKey - describe "InvokeHostFunction" do setup do ## HostFunction scval1 = SCVal.new(Int64.new(3), SCValType.new(:SCV_I64)) scval2 = SCVal.new(Int64.new(2), SCValType.new(:SCV_I64)) sc_vals = [scval1, scval2] - sc_vec = SCVec.new(sc_vals) - - host_function_type = HostFunctionType.new(:HOST_FUNCTION_TYPE_INVOKE_CONTRACT) - host_function_args = HostFunctionArgs.new(sc_vec, host_function_type) + args = SCVec.new(sc_vals) - ## LedgerFootprint - pk_type = PublicKeyType.new(:PUBLIC_KEY_TYPE_ED25519) + function_name = SCSymbol.new("Hello") - account_id = - "GBZNLMUQMIN3VGUJISKZU7GNY3O3XLMYEHJCKCSMDHKLGSMKALRXOEZD" - |> StrKey.decode!(:ed25519_public_key) - |> UInt256.new() - |> PublicKey.new(pk_type) - |> AccountID.new() + sc_address = + "CAWIIZPXNRY7X3FKFO4CWJT5DQOSEXQK" + |> Hash.new() + |> SCAddress.new(SCAddressType.new(:SC_ADDRESS_TYPE_CONTRACT)) - ## ContractAuthList - # AddressWithNonce - sc_address_type = SCAddressType.new(:SC_ADDRESS_TYPE_ACCOUNT) - sc_address = SCAddress.new(account_id, sc_address_type) - nonce = UInt64.new(123) + contract_function = SorobanAuthorizedContractFunction.new(sc_address, function_name, args) - address_with_nonce = - sc_address |> AddressWithNonce.new(nonce) |> OptionalAddressWithNonce.new() + auth_function = + SorobanAuthorizedFunction.new(contract_function, SorobanAuthorizedFunctionType.new()) - # AuthorizedInvocation - contract_id = Hash.new("GCIZ3GSM5XL7OUS4UP64THMDZ7CZ3ZWN") - function_name = SCSymbol.new("Hello") + host_function = HostFunction.new(args, HostFunctionType.new()) - authorized_invocation = - AuthorizedInvocation.new( - contract_id, - function_name, - sc_vec, - AuthorizedInvocationList.new() - ) + invocation = + SorobanAuthorizedInvocation.new(auth_function, SorobanAuthorizedInvocationList.new([])) - auth = ContractAuth.new(address_with_nonce, authorized_invocation, sc_vec) - auth_list = ContractAuthList.new([auth, auth]) - host_function = HostFunction.new(host_function_args, auth_list) - host_function_list = HostFunctionList100.new([host_function]) + credentials = SorobanCredentials.new(Void.new(), SorobanCredentialsType.new()) + entry = SorobanAuthorizationEntry.new(credentials, invocation) + auth = SorobanAuthorizationEntryList.new([entry]) %{ - host_function_list: host_function_list, - invoke_host_function_op: InvokeHostFunction.new(host_function_list), + host_function: host_function, + auth: auth, + invoke_host_function_op: InvokeHostFunction.new(host_function, auth), binary: - <<0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 6, 0, 0, 0, 0, 0, 0, 0, 3, 0, 0, 0, 6, 0, - 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 2, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 114, 213, 178, - 144, 98, 27, 186, 154, 137, 68, 149, 154, 124, 205, 198, 221, 187, 173, 152, 33, 210, - 37, 10, 76, 25, 212, 179, 73, 138, 2, 227, 119, 0, 0, 0, 0, 0, 0, 0, 123, 71, 67, 73, - 90, 51, 71, 83, 77, 53, 88, 76, 55, 79, 85, 83, 52, 85, 80, 54, 52, 84, 72, 77, 68, - 90, 55, 67, 90, 51, 90, 87, 78, 0, 0, 0, 5, 72, 101, 108, 108, 111, 0, 0, 0, 0, 0, 0, - 2, 0, 0, 0, 6, 0, 0, 0, 0, 0, 0, 0, 3, 0, 0, 0, 6, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, - 0, 0, 0, 2, 0, 0, 0, 6, 0, 0, 0, 0, 0, 0, 0, 3, 0, 0, 0, 6, 0, 0, 0, 0, 0, 0, 0, 2, 0, - 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 114, 213, 178, 144, 98, 27, 186, 154, 137, 68, 149, - 154, 124, 205, 198, 221, 187, 173, 152, 33, 210, 37, 10, 76, 25, 212, 179, 73, 138, 2, - 227, 119, 0, 0, 0, 0, 0, 0, 0, 123, 71, 67, 73, 90, 51, 71, 83, 77, 53, 88, 76, 55, - 79, 85, 83, 52, 85, 80, 54, 52, 84, 72, 77, 68, 90, 55, 67, 90, 51, 90, 87, 78, 0, 0, - 0, 5, 72, 101, 108, 108, 111, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 6, 0, 0, 0, 0, 0, 0, 0, 3, - 0, 0, 0, 6, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 6, 0, 0, 0, 0, 0, - 0, 0, 3, 0, 0, 0, 6, 0, 0, 0, 0, 0, 0, 0, 2>> + <<0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 6, 0, 0, 0, 0, 0, 0, 0, 3, 0, 0, 0, 6, 0, 0, 0, 0, 0, + 0, 0, 2, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 67, 65, 87, 73, 73, 90, 80, + 88, 78, 82, 89, 55, 88, 51, 70, 75, 70, 79, 52, 67, 87, 74, 84, 53, 68, 81, 79, 83, + 69, 88, 81, 75, 0, 0, 0, 5, 72, 101, 108, 108, 111, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 6, + 0, 0, 0, 0, 0, 0, 0, 3, 0, 0, 0, 6, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0>> } end - test "new/1", %{host_function_list: host_function_list} do - %InvokeHostFunction{functions: ^host_function_list} = - InvokeHostFunction.new(host_function_list) + test "new/1", %{host_function: host_function, auth: auth} do + %InvokeHostFunction{host_function: ^host_function, auth: ^auth} = + InvokeHostFunction.new(host_function, auth) end test "encode_xdr/1", %{ diff --git a/test/xdr/transactions/optional_address_with_nonce_test.exs b/test/xdr/transactions/optional_address_with_nonce_test.exs deleted file mode 100644 index 2fe44e17..00000000 --- a/test/xdr/transactions/optional_address_with_nonce_test.exs +++ /dev/null @@ -1,94 +0,0 @@ -defmodule StellarBase.XDR.OptionalAddressWithNonceTest do - use ExUnit.Case - - alias StellarBase.XDR.{ - AccountID, - AddressWithNonce, - PublicKey, - PublicKeyType, - SCAddress, - SCAddressType, - OptionalAddressWithNonce, - UInt64, - UInt256 - } - - alias StellarBase.StrKey - - describe "OptionalAddressWithNonce" do - setup do - sc_address_type = SCAddressType.new(:SC_ADDRESS_TYPE_ACCOUNT) - pk_type = PublicKeyType.new(:PUBLIC_KEY_TYPE_ED25519) - - account_id = - "GBZNLMUQMIN3VGUJISKZU7GNY3O3XLMYEHJCKCSMDHKLGSMKALRXOEZD" - |> StrKey.decode!(:ed25519_public_key) - |> UInt256.new() - |> PublicKey.new(pk_type) - |> AccountID.new() - - sc_address = SCAddress.new(account_id, sc_address_type) - nonce = UInt64.new(123) - - address_with_nonce = AddressWithNonce.new(sc_address, nonce) - - discriminants = [ - %{ - address_with_nonce: address_with_nonce, - optional_address_with_nonce: OptionalAddressWithNonce.new(address_with_nonce), - binary: - <<0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 114, 213, 178, 144, 98, 27, 186, 154, 137, 68, - 149, 154, 124, 205, 198, 221, 187, 173, 152, 33, 210, 37, 10, 76, 25, 212, 179, 73, - 138, 2, 227, 119, 0, 0, 0, 0, 0, 0, 0, 123>> - }, - %{ - address_with_nonce: nil, - optional_address_with_nonce: OptionalAddressWithNonce.new(), - binary: <<0, 0, 0, 0>> - } - ] - - %{discriminants: discriminants} - end - - test "new/1", %{discriminants: discriminants} do - for %{address_with_nonce: address_with_nonce} <- - discriminants do - %OptionalAddressWithNonce{address_with_nonce: ^address_with_nonce} = - OptionalAddressWithNonce.new(address_with_nonce) - end - end - - test "encode_xdr/1", %{discriminants: discriminants} do - for %{optional_address_with_nonce: optional_address_with_nonce, binary: binary} <- - discriminants do - {:ok, ^binary} = OptionalAddressWithNonce.encode_xdr(optional_address_with_nonce) - end - end - - test "encode_xdr!/1", %{discriminants: discriminants} do - for %{optional_address_with_nonce: optional_address_with_nonce, binary: binary} <- - discriminants do - ^binary = OptionalAddressWithNonce.encode_xdr!(optional_address_with_nonce) - end - end - - test "decode_xdr/2", %{discriminants: discriminants} do - for %{optional_address_with_nonce: optional_address_with_nonce, binary: binary} <- - discriminants do - {:ok, {^optional_address_with_nonce, ""}} = OptionalAddressWithNonce.decode_xdr(binary) - end - end - - test "decode_xdr/2 with an invalid binary" do - {:error, :not_binary} = OptionalAddressWithNonce.decode_xdr(1234) - end - - test "decode_xdr!/2", %{discriminants: discriminants} do - for %{optional_address_with_nonce: optional_address_with_nonce, binary: binary} <- - discriminants do - {^optional_address_with_nonce, ""} = OptionalAddressWithNonce.decode_xdr!(binary) - end - end - end -end diff --git a/test/xdr/transactions/sc_val_list100_test.exs b/test/xdr/transactions/sc_val_list100_test.exs deleted file mode 100644 index 47a6f28a..00000000 --- a/test/xdr/transactions/sc_val_list100_test.exs +++ /dev/null @@ -1,72 +0,0 @@ -defmodule StellarBase.XDR.SCValList100Test do - use ExUnit.Case - - alias StellarBase.XDR.{ - SCValList100, - SCVal, - SCValType, - SCString, - Bool - } - - describe "SCValList100" do - setup do - scval_type1 = SCValType.new(:SCV_BOOL) - scval1 = true |> Bool.new() |> SCVal.new(scval_type1) - - scval_type2 = SCValType.new(:SCV_STRING) - scval2 = "hello" |> SCString.new() |> SCVal.new(scval_type2) - items = [scval1, scval2] - - %{ - items: items, - scval_list: SCValList100.new(items), - binary: - <<0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 14, 0, 0, 0, 5, 104, 101, 108, 108, 111, - 0, 0, 0>> - } - end - - test "new/1", %{items: items} do - %SCValList100{items: ^items} = SCValList100.new(items) - end - - test "encode_xdr/1", %{ - scval_list: scval_list, - binary: binary - } do - {:ok, ^binary} = SCValList100.encode_xdr(scval_list) - end - - test "encode_xdr!/1", %{ - scval_list: scval_list, - binary: binary - } do - ^binary = SCValList100.encode_xdr!(scval_list) - end - - test "decode_xdr/1", %{ - scval_list: scval_list, - binary: binary - } do - {:ok, {^scval_list, ""}} = SCValList100.decode_xdr(binary) - end - - test "decode_xdr/1 with an invalid binary" do - {:error, :not_binary} = SCValList100.decode_xdr(123) - end - - test "decode_xdr!/1", %{ - scval_list: scval_list, - binary: binary - } do - {^scval_list, ""} = SCValList100.decode_xdr!(binary) - end - - test "decode_xdr!/1 with an invalid binary" do - assert_raise XDR.VariableArrayError, - "The value which you pass through parameters must be a binary value, for example: <<0, 0, 0, 5>>", - fn -> SCValList100.decode_xdr!(123) end - end - end -end diff --git a/test/xdr/transactions/soroban_transaction_data_test.exs b/test/xdr/transactions/soroban_transaction_data_test.exs index 1fabb582..01f5490a 100644 --- a/test/xdr/transactions/soroban_transaction_data_test.exs +++ b/test/xdr/transactions/soroban_transaction_data_test.exs @@ -42,7 +42,7 @@ defmodule StellarBase.XDR.SorobanTransactionDataTest do extended_meta_data_size_bytes ) - soroban_transaction_data = SorobanTransactionData.new(resources, refundable_fee, ext) + soroban_transaction_data = SorobanTransactionData.new(ext, resources, refundable_fee) %{ resources: resources, @@ -50,11 +50,11 @@ defmodule StellarBase.XDR.SorobanTransactionDataTest do ext: ext, soroban_transaction_data: soroban_transaction_data, binary: - <<0, 0, 0, 1, 0, 0, 0, 7, 71, 67, 73, 90, 51, 71, 83, 77, 53, 88, 76, 55, 79, 85, 83, - 52, 85, 80, 54, 52, 84, 72, 77, 68, 90, 55, 67, 90, 51, 90, 87, 78, 0, 0, 0, 1, 0, 0, - 0, 7, 71, 67, 73, 90, 51, 71, 83, 77, 53, 88, 76, 55, 79, 85, 83, 52, 85, 80, 54, 52, - 84, 72, 77, 68, 90, 55, 67, 90, 51, 90, 87, 78, 0, 0, 0, 10, 0, 0, 0, 10, 0, 0, 0, 10, - 0, 0, 0, 10, 0, 0, 0, 0, 0, 0, 0, 10, 0, 0, 0, 0>> + <<0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 7, 71, 67, 73, 90, 51, 71, 83, 77, 53, 88, 76, 55, + 79, 85, 83, 52, 85, 80, 54, 52, 84, 72, 77, 68, 90, 55, 67, 90, 51, 90, 87, 78, 0, 0, + 0, 1, 0, 0, 0, 7, 71, 67, 73, 90, 51, 71, 83, 77, 53, 88, 76, 55, 79, 85, 83, 52, 85, + 80, 54, 52, 84, 72, 77, 68, 90, 55, 67, 90, 51, 90, 87, 78, 0, 0, 0, 10, 0, 0, 0, 10, + 0, 0, 0, 10, 0, 0, 0, 10, 0, 0, 0, 0, 0, 0, 0, 10>> } end @@ -64,10 +64,10 @@ defmodule StellarBase.XDR.SorobanTransactionDataTest do ext: ext } do %SorobanTransactionData{ + ext: ^ext, resources: ^resources, - refundable_fee: ^refundable_fee, - ext: ^ext - } = SorobanTransactionData.new(resources, refundable_fee, ext) + refundable_fee: ^refundable_fee + } = SorobanTransactionData.new(ext, resources, refundable_fee) end test "encode_xdr/1", %{soroban_transaction_data: soroban_transaction_data, binary: binary} do diff --git a/test/xdr/transactions/upload_contract_wasm_args_test.exs b/test/xdr/transactions/upload_contract_wasm_args_test.exs deleted file mode 100644 index 0972ed51..00000000 --- a/test/xdr/transactions/upload_contract_wasm_args_test.exs +++ /dev/null @@ -1,47 +0,0 @@ -defmodule StellarBase.XDR.UploadContractWasmArgsTest do - use ExUnit.Case - - alias StellarBase.XDR.{UploadContractWasmArgs, VariableOpaque256000} - - describe "UploadContractWasmArgs" do - setup do - code = VariableOpaque256000.new("GCIZ3GSM5") - - %{ - code: code, - upload_contract_wasm_args: UploadContractWasmArgs.new(code), - binary: <<0, 0, 0, 9, 71, 67, 73, 90, 51, 71, 83, 77, 53, 0, 0, 0>> - } - end - - test "new/1", %{code: code} do - %UploadContractWasmArgs{code: ^code} = UploadContractWasmArgs.new(code) - end - - test "encode_xdr/1", %{upload_contract_wasm_args: upload_contract_wasm_args, binary: binary} do - {:ok, ^binary} = UploadContractWasmArgs.encode_xdr(upload_contract_wasm_args) - end - - test "encode_xdr!/1", %{ - upload_contract_wasm_args: upload_contract_wasm_args, - binary: binary - } do - ^binary = UploadContractWasmArgs.encode_xdr!(upload_contract_wasm_args) - end - - test "decode_xdr/2", %{upload_contract_wasm_args: upload_contract_wasm_args, binary: binary} do - {:ok, {^upload_contract_wasm_args, ""}} = UploadContractWasmArgs.decode_xdr(binary) - end - - test "decode_xdr/2 with an invalid binary" do - {:error, :not_binary} = UploadContractWasmArgs.decode_xdr(123) - end - - test "decode_xdr!/2", %{ - upload_contract_wasm_args: upload_contract_wasm_args, - binary: binary - } do - {^upload_contract_wasm_args, ^binary} = UploadContractWasmArgs.decode_xdr!(binary <> binary) - end - end -end diff --git a/test/xdr/types/variable_opaque256000_test.exs b/test/xdr/types/variable_opaque256000_test.exs deleted file mode 100644 index cab1df6b..00000000 --- a/test/xdr/types/variable_opaque256000_test.exs +++ /dev/null @@ -1,51 +0,0 @@ -defmodule StellarBase.XDR.VariableOpaque256000Test do - use ExUnit.Case - - alias StellarBase.XDR.VariableOpaque256000 - - describe "VariableOpaque256000" do - setup do - %{ - variable_opaque256000: VariableOpaque256000.new("GCIZ3GSM5"), - binary: <<0, 0, 0, 9, 71, 67, 73, 90, 51, 71, 83, 77, 53, 0, 0, 0>> - } - end - - test "new/1" do - %VariableOpaque256000{opaque: variable_opaque256000} = - VariableOpaque256000.new(<<0, 0, 0, 9, 71, 67, 73, 90, 51, 71, 83, 77, 53, 0, 0, 0>>) - - 16 = String.length(variable_opaque256000) - end - - test "encode_xdr/1", %{variable_opaque256000: variable_opaque256000, binary: binary} do - {:ok, ^binary} = VariableOpaque256000.encode_xdr(variable_opaque256000) - end - - test "encode_xdr!/1", %{variable_opaque256000: variable_opaque256000, binary: binary} do - ^binary = VariableOpaque256000.encode_xdr!(variable_opaque256000) - end - - test "decode_xdr/2", %{variable_opaque256000: variable_opaque256000, binary: binary} do - {:ok, {^variable_opaque256000, ""}} = VariableOpaque256000.decode_xdr(binary) - end - - test "decode_xdr/2 with an invalid binary" do - {:error, :not_binary} = VariableOpaque256000.decode_xdr(123) - end - - test "decode_xdr!/2", %{variable_opaque256000: variable_opaque256000, binary: binary} do - {^variable_opaque256000, ""} = VariableOpaque256000.decode_xdr!(binary) - end - - test "invalid length" do - bits = 256_001 * 8 - binary = <<0::size(bits)>> - - {:error, :invalid_length} = - VariableOpaque256000.encode_xdr(%VariableOpaque256000{ - opaque: binary - }) - end - end -end diff --git a/test/xdr/types/variable_opaque_test.exs b/test/xdr/types/variable_opaque_test.exs new file mode 100644 index 00000000..a6f5d90b --- /dev/null +++ b/test/xdr/types/variable_opaque_test.exs @@ -0,0 +1,41 @@ +defmodule StellarBase.XDR.VariableOpaqueTest do + use ExUnit.Case + + alias StellarBase.XDR.VariableOpaque + + describe "VariableOpaque" do + setup do + %{ + variable_opaque256000: VariableOpaque.new("GCIZ3GSM5"), + binary: <<0, 0, 0, 9, 71, 67, 73, 90, 51, 71, 83, 77, 53, 0, 0, 0>> + } + end + + test "new/1" do + %VariableOpaque{opaque: variable_opaque256000} = + VariableOpaque.new(<<0, 0, 0, 9, 71, 67, 73, 90, 51, 71, 83, 77, 53, 0, 0, 0>>) + + 16 = String.length(variable_opaque256000) + end + + test "encode_xdr/1", %{variable_opaque256000: variable_opaque256000, binary: binary} do + {:ok, ^binary} = VariableOpaque.encode_xdr(variable_opaque256000) + end + + test "encode_xdr!/1", %{variable_opaque256000: variable_opaque256000, binary: binary} do + ^binary = VariableOpaque.encode_xdr!(variable_opaque256000) + end + + test "decode_xdr/2", %{variable_opaque256000: variable_opaque256000, binary: binary} do + {:ok, {^variable_opaque256000, ""}} = VariableOpaque.decode_xdr(binary) + end + + test "decode_xdr/2 with an invalid binary" do + {:error, :not_binary} = VariableOpaque.decode_xdr(123) + end + + test "decode_xdr!/2", %{variable_opaque256000: variable_opaque256000, binary: binary} do + {^variable_opaque256000, ""} = VariableOpaque.decode_xdr!(binary) + end + end +end From 2faabf4f34d9154beeb55c989ab0561849ac2dfd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Rold=C3=A1n?= <62166813+Odraxs@users.noreply.github.com> Date: Fri, 21 Jul 2023 12:33:28 -0500 Subject: [PATCH 2/4] Preview 10 files fixes (#275) * Remove redundant files and update sc_val value types * Update contract_code and contract_data files --------- Co-authored-by: Edwin Steven Guayacan --- lib/xdr/contract/sc_val.ex | 2 + lib/xdr/ledger_entries/contract_code.ex | 54 --------- lib/xdr/ledger_entries/contract_data.ex | 56 ---------- lib/xdr/ledger_entries/ledger_key.ex | 12 +- .../ledger_key_contract_code.ex | 73 ++++++++++++ .../ledger_key_contract_data.ex | 105 ++++++++++++++++++ .../xdr/ledger_entries/contract_code_test.exs | 47 -------- .../xdr/ledger_entries/contract_data_test.exs | 45 -------- test/xdr/ledger_entries/ledger_key_test.exs | 7 +- .../hash_id_preimage_operation_id_test.exs | 56 ++++++++++ .../hash_id_preimage_revoke_id_test.exs | 76 +++++++++++++ .../transactions/hash_id_preimage_test.exs | 4 +- .../transactions/soroban_resources_test.exs | 13 ++- .../soroban_transaction_data_test.exs | 11 +- 14 files changed, 337 insertions(+), 224 deletions(-) delete mode 100644 lib/xdr/ledger_entries/contract_code.ex delete mode 100644 lib/xdr/ledger_entries/contract_data.ex create mode 100644 lib/xdr/ledger_entries/ledger_key_contract_code.ex create mode 100644 lib/xdr/ledger_entries/ledger_key_contract_data.ex delete mode 100644 test/xdr/ledger_entries/contract_code_test.exs delete mode 100644 test/xdr/ledger_entries/contract_data_test.exs create mode 100644 test/xdr/transactions/hash_id_preimage_operation_id_test.exs create mode 100644 test/xdr/transactions/hash_id_preimage_revoke_id_test.exs diff --git a/lib/xdr/contract/sc_val.ex b/lib/xdr/contract/sc_val.ex index ba448f87..2f3d0cdf 100644 --- a/lib/xdr/contract/sc_val.ex +++ b/lib/xdr/contract/sc_val.ex @@ -70,7 +70,9 @@ defmodule StellarBase.XDR.SCVal do | Int64.t() | TimePoint.t() | Duration.t() + | Int128Parts.t() | UInt128Parts.t() + | Int256Parts.t() | UInt256Parts.t() | SCBytes.t() | SCString.t() diff --git a/lib/xdr/ledger_entries/contract_code.ex b/lib/xdr/ledger_entries/contract_code.ex deleted file mode 100644 index d85d1431..00000000 --- a/lib/xdr/ledger_entries/contract_code.ex +++ /dev/null @@ -1,54 +0,0 @@ -defmodule StellarBase.XDR.ContractCode do - @moduledoc """ - Representation of Stellar `ContractCode` type. - """ - - alias StellarBase.XDR.Hash - - @behaviour XDR.Declaration - - @struct_spec XDR.Struct.new(hash: Hash) - - @type t :: %__MODULE__{hash: Hash.t()} - - defstruct [:hash] - - @spec new(hash :: Hash.t()) :: t() - def new(%Hash{} = hash), do: %__MODULE__{hash: hash} - - @impl true - def encode_xdr(%__MODULE__{hash: hash}) do - [hash: hash] - |> XDR.Struct.new() - |> XDR.Struct.encode_xdr() - end - - @impl true - def encode_xdr!(%__MODULE__{hash: hash}) do - [hash: hash] - |> XDR.Struct.new() - |> XDR.Struct.encode_xdr!() - end - - @impl true - def decode_xdr(bytes, struct \\ @struct_spec) - - def decode_xdr(bytes, struct) do - case XDR.Struct.decode_xdr(bytes, struct) do - {:ok, {%XDR.Struct{components: [hash: hash]}, rest}} -> - {:ok, {new(hash), rest}} - - error -> - error - end - end - - @impl true - def decode_xdr!(bytes, struct \\ @struct_spec) - - def decode_xdr!(bytes, struct) do - {%XDR.Struct{components: [hash: hash]}, rest} = XDR.Struct.decode_xdr!(bytes, struct) - - {new(hash), rest} - end -end diff --git a/lib/xdr/ledger_entries/contract_data.ex b/lib/xdr/ledger_entries/contract_data.ex deleted file mode 100644 index 74dd7a52..00000000 --- a/lib/xdr/ledger_entries/contract_data.ex +++ /dev/null @@ -1,56 +0,0 @@ -defmodule StellarBase.XDR.ContractData do - @moduledoc """ - Representation of Stellar `ContractData` type. - """ - - alias StellarBase.XDR.{Hash, SCVal} - - @behaviour XDR.Declaration - - @struct_spec XDR.Struct.new(contract_id: Hash, key: SCVal) - - @type t :: %__MODULE__{contract_id: Hash.t(), key: SCVal.t()} - - defstruct [:contract_id, :key] - - @spec new(contract_id :: Hash.t(), key :: SCVal.t()) :: t() - def new(%Hash{} = contract_id, %SCVal{} = key), - do: %__MODULE__{contract_id: contract_id, key: key} - - @impl true - def encode_xdr(%__MODULE__{contract_id: contract_id, key: key}) do - [contract_id: contract_id, key: key] - |> XDR.Struct.new() - |> XDR.Struct.encode_xdr() - end - - @impl true - def encode_xdr!(%__MODULE__{contract_id: contract_id, key: key}) do - [contract_id: contract_id, key: key] - |> XDR.Struct.new() - |> XDR.Struct.encode_xdr!() - end - - @impl true - def decode_xdr(bytes, struct \\ @struct_spec) - - def decode_xdr(bytes, struct) do - case XDR.Struct.decode_xdr(bytes, struct) do - {:ok, {%XDR.Struct{components: [contract_id: contract_id, key: key]}, rest}} -> - {:ok, {new(contract_id, key), rest}} - - error -> - error - end - end - - @impl true - def decode_xdr!(bytes, struct \\ @struct_spec) - - def decode_xdr!(bytes, struct) do - {%XDR.Struct{components: [contract_id: contract_id, key: key]}, rest} = - XDR.Struct.decode_xdr!(bytes, struct) - - {new(contract_id, key), rest} - end -end diff --git a/lib/xdr/ledger_entries/ledger_key.ex b/lib/xdr/ledger_entries/ledger_key.ex index cc917860..91e36c76 100644 --- a/lib/xdr/ledger_entries/ledger_key.ex +++ b/lib/xdr/ledger_entries/ledger_key.ex @@ -12,8 +12,8 @@ defmodule StellarBase.XDR.LedgerKey do Data, ClaimableBalance, LiquidityPool, - ContractData, - ContractCode, + LedgerKeyContractData, + LedgerKeyContractCode, LedgerKeyConfigSetting } @@ -26,8 +26,8 @@ defmodule StellarBase.XDR.LedgerKey do DATA: Data, CLAIMABLE_BALANCE: ClaimableBalance, LIQUIDITY_POOL: LiquidityPool, - CONTRACT_DATA: ContractData, - CONTRACT_CODE: ContractCode, + CONTRACT_DATA: LedgerKeyContractData, + CONTRACT_CODE: LedgerKeyContractCode, CONFIG_SETTING: LedgerKeyConfigSetting ] @@ -38,8 +38,8 @@ defmodule StellarBase.XDR.LedgerKey do | Data.t() | ClaimableBalance.t() | LiquidityPool.t() - | ContractData.t() - | ContractCode.t() + | LedgerKeyContractData.t() + | LedgerKeyContractCode.t() | LedgerKeyConfigSetting.t() @type t :: %__MODULE__{entry: entry(), type: LedgerEntryType.t()} diff --git a/lib/xdr/ledger_entries/ledger_key_contract_code.ex b/lib/xdr/ledger_entries/ledger_key_contract_code.ex new file mode 100644 index 00000000..62aa9081 --- /dev/null +++ b/lib/xdr/ledger_entries/ledger_key_contract_code.ex @@ -0,0 +1,73 @@ +defmodule StellarBase.XDR.LedgerKeyContractCode do + @moduledoc """ + Automatically generated by xdrgen + DO NOT EDIT or your changes may be overwritten + + Target implementation: elixir_xdr at https://hex.pm/packages/elixir_xdr + + Representation of Stellar `LedgerKeyContractCode` type. + """ + + @behaviour XDR.Declaration + + alias StellarBase.XDR.{ + Hash, + ContractEntryBodyType + } + + @struct_spec XDR.Struct.new( + hash: Hash, + body_type: ContractEntryBodyType + ) + + @type hash_type :: Hash.t() + @type body_type_type :: ContractEntryBodyType.t() + + @type t :: %__MODULE__{hash: hash_type(), body_type: body_type_type()} + + defstruct [:hash, :body_type] + + @spec new(hash :: hash_type(), body_type :: body_type_type()) :: t() + def new( + %Hash{} = hash, + %ContractEntryBodyType{} = body_type + ), + do: %__MODULE__{hash: hash, body_type: body_type} + + @impl true + def encode_xdr(%__MODULE__{hash: hash, body_type: body_type}) do + [hash: hash, body_type: body_type] + |> XDR.Struct.new() + |> XDR.Struct.encode_xdr() + end + + @impl true + def encode_xdr!(%__MODULE__{hash: hash, body_type: body_type}) do + [hash: hash, body_type: body_type] + |> XDR.Struct.new() + |> XDR.Struct.encode_xdr!() + end + + @impl true + def decode_xdr(bytes, struct \\ @struct_spec) + + def decode_xdr(bytes, struct) do + case XDR.Struct.decode_xdr(bytes, struct) do + {:ok, {%XDR.Struct{components: [hash: hash, body_type: body_type]}, rest}} -> + {:ok, {new(hash, body_type), rest}} + + error -> + error + end + end + + @impl true + def decode_xdr!(bytes, struct \\ @struct_spec) + + def decode_xdr!(bytes, struct) do + {%XDR.Struct{components: [hash: hash, body_type: body_type]}, rest} = + XDR.Struct.decode_xdr!(bytes, struct) + + {new(hash, body_type), rest} + end +end diff --git a/lib/xdr/ledger_entries/ledger_key_contract_data.ex b/lib/xdr/ledger_entries/ledger_key_contract_data.ex new file mode 100644 index 00000000..10c9f279 --- /dev/null +++ b/lib/xdr/ledger_entries/ledger_key_contract_data.ex @@ -0,0 +1,105 @@ +defmodule StellarBase.XDR.LedgerKeyContractData do + @moduledoc """ + Automatically generated by xdrgen + DO NOT EDIT or your changes may be overwritten + + Target implementation: elixir_xdr at https://hex.pm/packages/elixir_xdr + + Representation of Stellar `LedgerKeyContractData` type. + """ + + @behaviour XDR.Declaration + + alias StellarBase.XDR.{ + SCAddress, + SCVal, + ContractDataDurability, + ContractEntryBodyType + } + + @struct_spec XDR.Struct.new( + contract: SCAddress, + key: SCVal, + durability: ContractDataDurability, + body_type: ContractEntryBodyType + ) + + @type contract_type :: SCAddress.t() + @type key_type :: SCVal.t() + @type durability_type :: ContractDataDurability.t() + @type body_type_type :: ContractEntryBodyType.t() + + @type t :: %__MODULE__{ + contract: contract_type(), + key: key_type(), + durability: durability_type(), + body_type: body_type_type() + } + + defstruct [:contract, :key, :durability, :body_type] + + @spec new( + contract :: contract_type(), + key :: key_type(), + durability :: durability_type(), + body_type :: body_type_type() + ) :: t() + def new( + %SCAddress{} = contract, + %SCVal{} = key, + %ContractDataDurability{} = durability, + %ContractEntryBodyType{} = body_type + ), + do: %__MODULE__{contract: contract, key: key, durability: durability, body_type: body_type} + + @impl true + def encode_xdr(%__MODULE__{ + contract: contract, + key: key, + durability: durability, + body_type: body_type + }) do + [contract: contract, key: key, durability: durability, body_type: body_type] + |> XDR.Struct.new() + |> XDR.Struct.encode_xdr() + end + + @impl true + def encode_xdr!(%__MODULE__{ + contract: contract, + key: key, + durability: durability, + body_type: body_type + }) do + [contract: contract, key: key, durability: durability, body_type: body_type] + |> XDR.Struct.new() + |> XDR.Struct.encode_xdr!() + end + + @impl true + def decode_xdr(bytes, struct \\ @struct_spec) + + def decode_xdr(bytes, struct) do + case XDR.Struct.decode_xdr(bytes, struct) do + {:ok, + {%XDR.Struct{ + components: [contract: contract, key: key, durability: durability, body_type: body_type] + }, rest}} -> + {:ok, {new(contract, key, durability, body_type), rest}} + + error -> + error + end + end + + @impl true + def decode_xdr!(bytes, struct \\ @struct_spec) + + def decode_xdr!(bytes, struct) do + {%XDR.Struct{ + components: [contract: contract, key: key, durability: durability, body_type: body_type] + }, rest} = XDR.Struct.decode_xdr!(bytes, struct) + + {new(contract, key, durability, body_type), rest} + end +end diff --git a/test/xdr/ledger_entries/contract_code_test.exs b/test/xdr/ledger_entries/contract_code_test.exs deleted file mode 100644 index 5a0a4f58..00000000 --- a/test/xdr/ledger_entries/contract_code_test.exs +++ /dev/null @@ -1,47 +0,0 @@ -defmodule StellarBase.XDR.ContractCodeTest do - use ExUnit.Case - - alias StellarBase.XDR.{ContractCode, Hash} - - describe "ContractCode" do - setup do - hash = Hash.new("GCIZ3GSM5XL7OUS4UP64THMDZ7CZ3ZWN") - - %{ - hash: hash, - contract_code_entry: ContractCode.new(hash), - binary: "GCIZ3GSM5XL7OUS4UP64THMDZ7CZ3ZWN" - } - end - - test "new/1", %{hash: hash} do - %ContractCode{hash: ^hash} = ContractCode.new(hash) - end - - test "encode_xdr/1", %{contract_code_entry: contract_code_entry, binary: binary} do - {:ok, ^binary} = ContractCode.encode_xdr(contract_code_entry) - end - - test "encode_xdr!/1", %{ - contract_code_entry: contract_code_entry, - binary: binary - } do - ^binary = ContractCode.encode_xdr!(contract_code_entry) - end - - test "decode_xdr/2", %{contract_code_entry: contract_code_entry, binary: binary} do - {:ok, {^contract_code_entry, ""}} = ContractCode.decode_xdr(binary) - end - - test "decode_xdr/2 with an invalid binary" do - {:error, :not_binary} = ContractCode.decode_xdr(123) - end - - test "decode_xdr!/2", %{ - contract_code_entry: contract_code_entry, - binary: binary - } do - {^contract_code_entry, ^binary} = ContractCode.decode_xdr!(binary <> binary) - end - end -end diff --git a/test/xdr/ledger_entries/contract_data_test.exs b/test/xdr/ledger_entries/contract_data_test.exs deleted file mode 100644 index f3208c56..00000000 --- a/test/xdr/ledger_entries/contract_data_test.exs +++ /dev/null @@ -1,45 +0,0 @@ -defmodule StellarBase.XDR.ContractDataTest do - use ExUnit.Case - - alias StellarBase.XDR.{ContractData, SCVal, SCValType, Int64, Hash} - - describe "ContractData" do - setup do - contract_id = Hash.new("GCIZ3GSM5XL7OUS4UP64THMDZ7CZ3ZWN") - key = SCVal.new(Int64.new(1), SCValType.new(:SCV_I64)) - - %{ - contract_id: contract_id, - key: key, - contract_data_entry: ContractData.new(contract_id, key), - binary: - <<71, 67, 73, 90, 51, 71, 83, 77, 53, 88, 76, 55, 79, 85, 83, 52, 85, 80, 54, 52, 84, - 72, 77, 68, 90, 55, 67, 90, 51, 90, 87, 78, 0, 0, 0, 6, 0, 0, 0, 0, 0, 0, 0, 1>> - } - end - - test "new/1", %{contract_id: contract_id, key: key} do - %ContractData{contract_id: ^contract_id, key: ^key} = ContractData.new(contract_id, key) - end - - test "encode_xdr/1", %{contract_data_entry: contract_data_entry, binary: binary} do - {:ok, ^binary} = ContractData.encode_xdr(contract_data_entry) - end - - test "encode_xdr!/1", %{contract_data_entry: contract_data_entry, binary: binary} do - ^binary = ContractData.encode_xdr!(contract_data_entry) - end - - test "decode_xdr/2", %{contract_data_entry: contract_data_entry, binary: binary} do - {:ok, {^contract_data_entry, ""}} = ContractData.decode_xdr(binary) - end - - test "decode_xdr/2 with an invalid binary" do - {:error, :not_binary} = ContractData.decode_xdr(123) - end - - test "decode_xdr!/2", %{contract_data_entry: contract_data_entry, binary: binary} do - {^contract_data_entry, ^binary} = ContractData.decode_xdr!(binary <> binary) - end - end -end diff --git a/test/xdr/ledger_entries/ledger_key_test.exs b/test/xdr/ledger_entries/ledger_key_test.exs index 8afafd5f..2bbb07b4 100644 --- a/test/xdr/ledger_entries/ledger_key_test.exs +++ b/test/xdr/ledger_entries/ledger_key_test.exs @@ -3,11 +3,12 @@ defmodule StellarBase.XDR.LedgerKeyTest do alias StellarBase.XDR.{ AccountID, - ContractCode, + ContractEntryBodyType, Hash, Int64, LedgerEntryType, LedgerKey, + LedgerKeyContractCode, PublicKey, PublicKeyType, String64, @@ -59,10 +60,10 @@ defmodule StellarBase.XDR.LedgerKeyTest do }, %{ type: LedgerEntryType.new(:CONTRACT_CODE), - ledger_key_data: ContractCode.new(hash), + ledger_key_data: LedgerKeyContractCode.new(hash, ContractEntryBodyType.new()), binary: <<0, 0, 0, 7, 71, 67, 73, 90, 51, 71, 83, 77, 53, 88, 76, 55, 79, 85, 83, 52, 85, 80, - 54, 52, 84, 72, 77, 68, 90, 55, 67, 90, 51, 90, 87, 78>> + 54, 52, 84, 72, 77, 68, 90, 55, 67, 90, 51, 90, 87, 78, 0, 0, 0, 0>> } ] diff --git a/test/xdr/transactions/hash_id_preimage_operation_id_test.exs b/test/xdr/transactions/hash_id_preimage_operation_id_test.exs new file mode 100644 index 00000000..7a7bc755 --- /dev/null +++ b/test/xdr/transactions/hash_id_preimage_operation_id_test.exs @@ -0,0 +1,56 @@ +defmodule StellarBase.XDR.HashIDPreimageOperationIDTest do + use ExUnit.Case + + import StellarBase.Test.Utils + + alias StellarBase.XDR.{HashIDPreimageOperationID, SequenceNumber, UInt32} + + describe "HashIDPreimageOperationID" do + setup do + source_account = + create_account_id("GCNY5OXYSY4FKHOPT2SPOQZAOEIGXB5LBYW3HVU3OWSTQITS65M5RCNY") + + seq_num = SequenceNumber.new(123_456) + op_num = UInt32.new(123_456) + + %{ + source_account: source_account, + seq_num: seq_num, + op_num: op_num, + operation_id: HashIDPreimageOperationID.new(source_account, seq_num, op_num), + binary: + <<0, 0, 0, 0, 155, 142, 186, 248, 150, 56, 85, 29, 207, 158, 164, 247, 67, 32, 113, 16, + 107, 135, 171, 14, 45, 179, 214, 155, 117, 165, 56, 34, 114, 247, 89, 216, 0, 0, 0, 0, + 0, 1, 226, 64, 0, 1, 226, 64>> + } + end + + test "new/3", %{source_account: source_account, seq_num: seq_num, op_num: op_num} do + %HashIDPreimageOperationID{ + source_account: ^source_account, + seq_num: ^seq_num, + op_num: ^op_num + } = HashIDPreimageOperationID.new(source_account, seq_num, op_num) + end + + test "encode_xdr/1", %{operation_id: operation_id, binary: binary} do + {:ok, ^binary} = HashIDPreimageOperationID.encode_xdr(operation_id) + end + + test "encode_xdr!/1", %{operation_id: operation_id, binary: binary} do + ^binary = HashIDPreimageOperationID.encode_xdr!(operation_id) + end + + test "decode_xdr/2", %{operation_id: operation_id, binary: binary} do + {:ok, {^operation_id, ""}} = HashIDPreimageOperationID.decode_xdr(binary) + end + + test "decode_xdr/2 with an invalid binary" do + {:error, :not_binary} = HashIDPreimageOperationID.decode_xdr(123) + end + + test "decode_xdr!/2", %{operation_id: operation_id, binary: binary} do + {^operation_id, ""} = HashIDPreimageOperationID.decode_xdr!(binary) + end + end +end diff --git a/test/xdr/transactions/hash_id_preimage_revoke_id_test.exs b/test/xdr/transactions/hash_id_preimage_revoke_id_test.exs new file mode 100644 index 00000000..0d8238bf --- /dev/null +++ b/test/xdr/transactions/hash_id_preimage_revoke_id_test.exs @@ -0,0 +1,76 @@ +defmodule StellarBase.XDR.HashIDPreimageRevokeIDTest do + use ExUnit.Case + + import StellarBase.Test.Utils + + alias StellarBase.XDR.{HashIDPreimageRevokeID, PoolID, SequenceNumber, UInt32} + + describe "OperationID" do + setup do + source_account = + create_account_id("GCNY5OXYSY4FKHOPT2SPOQZAOEIGXB5LBYW3HVU3OWSTQITS65M5RCNY") + + seq_num = SequenceNumber.new(123_456) + op_num = UInt32.new(123_456) + pool_id = PoolID.new("GCIZ3GSM5XL7OUS4UP64THMDZ7CZ3ZWN") + + asset = + create_asset(:alpha_num4, + code: "BTCN", + issuer: "GBZNLMUQMIN3VGUJISKZU7GNY3O3XLMYEHJCKCSMDHKLGSMKALRXOEZD" + ) + + %{ + source_account: source_account, + seq_num: seq_num, + op_num: op_num, + pool_id: pool_id, + asset: asset, + revoke_id: HashIDPreimageRevokeID.new(source_account, seq_num, op_num, pool_id, asset), + binary: + <<0, 0, 0, 0, 155, 142, 186, 248, 150, 56, 85, 29, 207, 158, 164, 247, 67, 32, 113, 16, + 107, 135, 171, 14, 45, 179, 214, 155, 117, 165, 56, 34, 114, 247, 89, 216, 0, 0, 0, 0, + 0, 1, 226, 64, 0, 1, 226, 64, 71, 67, 73, 90, 51, 71, 83, 77, 53, 88, 76, 55, 79, 85, + 83, 52, 85, 80, 54, 52, 84, 72, 77, 68, 90, 55, 67, 90, 51, 90, 87, 78, 0, 0, 0, 1, + 66, 84, 67, 78, 0, 0, 0, 0, 114, 213, 178, 144, 98, 27, 186, 154, 137, 68, 149, 154, + 124, 205, 198, 221, 187, 173, 152, 33, 210, 37, 10, 76, 25, 212, 179, 73, 138, 2, 227, + 119>> + } + end + + test "new/3", %{ + source_account: source_account, + seq_num: seq_num, + op_num: op_num, + pool_id: pool_id, + asset: asset + } do + %HashIDPreimageRevokeID{ + source_account: ^source_account, + seq_num: ^seq_num, + liquidity_pool_id: ^pool_id, + asset: ^asset + } = HashIDPreimageRevokeID.new(source_account, seq_num, op_num, pool_id, asset) + end + + test "encode_xdr/1", %{revoke_id: revoke_id, binary: binary} do + {:ok, ^binary} = HashIDPreimageRevokeID.encode_xdr(revoke_id) + end + + test "encode_xdr!/1", %{revoke_id: revoke_id, binary: binary} do + ^binary = HashIDPreimageRevokeID.encode_xdr!(revoke_id) + end + + test "decode_xdr/2", %{revoke_id: revoke_id, binary: binary} do + {:ok, {^revoke_id, ""}} = HashIDPreimageRevokeID.decode_xdr(binary) + end + + test "decode_xdr/2 with an invalid binary" do + {:error, :not_binary} = HashIDPreimageRevokeID.decode_xdr(123) + end + + test "decode_xdr!/2", %{revoke_id: revoke_id, binary: binary} do + {^revoke_id, ""} = HashIDPreimageRevokeID.decode_xdr!(binary) + end + end +end diff --git a/test/xdr/transactions/hash_id_preimage_test.exs b/test/xdr/transactions/hash_id_preimage_test.exs index 2702b29f..acc88d6c 100644 --- a/test/xdr/transactions/hash_id_preimage_test.exs +++ b/test/xdr/transactions/hash_id_preimage_test.exs @@ -26,7 +26,7 @@ defmodule StellarBase.XDR.HashIDPreimageTest do }} end - describe "OperationID" do + describe "HashIDPreimageOperationID" do setup %{account_id: account_id, seq_number: seq_number, op_num: op_num} do envelope_type = EnvelopeType.new(:ENVELOPE_TYPE_OP_ID) operation_id = HashIDPreimageOperationID.new(account_id, seq_number, op_num) @@ -68,7 +68,7 @@ defmodule StellarBase.XDR.HashIDPreimageTest do end end - describe "RevokeID" do + describe "HashIDPreimageRevokeID" do setup %{account_id: account_id, seq_number: seq_number, op_num: op_num} do envelope_type = EnvelopeType.new(:ENVELOPE_TYPE_POOL_REVOKE_OP_ID) liquidity_pool_id = PoolID.new("GCIZ3GSM5XL7OUS4UP64THMDZ7CZ3ZWN") diff --git a/test/xdr/transactions/soroban_resources_test.exs b/test/xdr/transactions/soroban_resources_test.exs index 76884a7c..c5af4cd5 100644 --- a/test/xdr/transactions/soroban_resources_test.exs +++ b/test/xdr/transactions/soroban_resources_test.exs @@ -4,12 +4,13 @@ defmodule StellarBase.XDR.SorobanResourcesTest do alias StellarBase.XDR.LedgerFootprint alias StellarBase.XDR.{ - ContractCode, + ContractEntryBodyType, Hash, UInt32, SorobanResources, LedgerEntryType, LedgerKey, + LedgerKeyContractCode, LedgerKeyList, LedgerFootprint } @@ -18,7 +19,7 @@ defmodule StellarBase.XDR.SorobanResourcesTest do setup do hash = Hash.new("GCIZ3GSM5XL7OUS4UP64THMDZ7CZ3ZWN") type = LedgerEntryType.new(:CONTRACT_CODE) - ledger_key_data = ContractCode.new(hash) + ledger_key_data = LedgerKeyContractCode.new(hash, ContractEntryBodyType.new()) ledger_key1 = LedgerKey.new(ledger_key_data, type) ledger_key2 = LedgerKey.new(ledger_key_data, type) ledger_key_list_read = LedgerKeyList.new([ledger_key1]) @@ -47,10 +48,10 @@ defmodule StellarBase.XDR.SorobanResourcesTest do soroban_resources: soroban_resources, binary: <<0, 0, 0, 1, 0, 0, 0, 7, 71, 67, 73, 90, 51, 71, 83, 77, 53, 88, 76, 55, 79, 85, 83, - 52, 85, 80, 54, 52, 84, 72, 77, 68, 90, 55, 67, 90, 51, 90, 87, 78, 0, 0, 0, 1, 0, 0, - 0, 7, 71, 67, 73, 90, 51, 71, 83, 77, 53, 88, 76, 55, 79, 85, 83, 52, 85, 80, 54, 52, - 84, 72, 77, 68, 90, 55, 67, 90, 51, 90, 87, 78, 0, 0, 0, 10, 0, 0, 0, 10, 0, 0, 0, 10, - 0, 0, 0, 10>> + 52, 85, 80, 54, 52, 84, 72, 77, 68, 90, 55, 67, 90, 51, 90, 87, 78, 0, 0, 0, 0, 0, 0, + 0, 1, 0, 0, 0, 7, 71, 67, 73, 90, 51, 71, 83, 77, 53, 88, 76, 55, 79, 85, 83, 52, 85, + 80, 54, 52, 84, 72, 77, 68, 90, 55, 67, 90, 51, 90, 87, 78, 0, 0, 0, 0, 0, 0, 0, 10, + 0, 0, 0, 10, 0, 0, 0, 10, 0, 0, 0, 10>> } end diff --git a/test/xdr/transactions/soroban_transaction_data_test.exs b/test/xdr/transactions/soroban_transaction_data_test.exs index 01f5490a..15ba1a5a 100644 --- a/test/xdr/transactions/soroban_transaction_data_test.exs +++ b/test/xdr/transactions/soroban_transaction_data_test.exs @@ -2,7 +2,7 @@ defmodule StellarBase.XDR.SorobanTransactionDataTest do use ExUnit.Case alias StellarBase.XDR.{ - ContractCode, + ContractEntryBodyType, Hash, Int64, SorobanTransactionData, @@ -10,6 +10,7 @@ defmodule StellarBase.XDR.SorobanTransactionDataTest do SorobanResources, LedgerEntryType, LedgerKey, + LedgerKeyContractCode, LedgerKeyList, LedgerFootprint, Void, @@ -22,7 +23,7 @@ defmodule StellarBase.XDR.SorobanTransactionDataTest do ext = ExtensionPoint.new(Void.new(), 0) hash = Hash.new("GCIZ3GSM5XL7OUS4UP64THMDZ7CZ3ZWN") type = LedgerEntryType.new(:CONTRACT_CODE) - ledger_key_data = ContractCode.new(hash) + ledger_key_data = LedgerKeyContractCode.new(hash, ContractEntryBodyType.new()) ledger_key1 = LedgerKey.new(ledger_key_data, type) ledger_key2 = LedgerKey.new(ledger_key_data, type) ledger_key_list_read = LedgerKeyList.new([ledger_key1]) @@ -52,9 +53,9 @@ defmodule StellarBase.XDR.SorobanTransactionDataTest do binary: <<0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 7, 71, 67, 73, 90, 51, 71, 83, 77, 53, 88, 76, 55, 79, 85, 83, 52, 85, 80, 54, 52, 84, 72, 77, 68, 90, 55, 67, 90, 51, 90, 87, 78, 0, 0, - 0, 1, 0, 0, 0, 7, 71, 67, 73, 90, 51, 71, 83, 77, 53, 88, 76, 55, 79, 85, 83, 52, 85, - 80, 54, 52, 84, 72, 77, 68, 90, 55, 67, 90, 51, 90, 87, 78, 0, 0, 0, 10, 0, 0, 0, 10, - 0, 0, 0, 10, 0, 0, 0, 10, 0, 0, 0, 0, 0, 0, 0, 10>> + 0, 0, 0, 0, 0, 1, 0, 0, 0, 7, 71, 67, 73, 90, 51, 71, 83, 77, 53, 88, 76, 55, 79, 85, + 83, 52, 85, 80, 54, 52, 84, 72, 77, 68, 90, 55, 67, 90, 51, 90, 87, 78, 0, 0, 0, 0, 0, + 0, 0, 10, 0, 0, 0, 10, 0, 0, 0, 10, 0, 0, 0, 10, 0, 0, 0, 0, 0, 0, 0, 10>> } end From aeeb4e50e91cd0750e45a54eba5a15c74402c0bb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Rold=C3=A1n?= <62166813+Odraxs@users.noreply.github.com> Date: Mon, 24 Jul 2023 08:46:23 -0500 Subject: [PATCH 3/4] Prepare for release v0.12.0 (#276) --- CHANGELOG.md | 3 +++ README.md | 2 +- mix.exs | 2 +- 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 86babdb9..2c89eaff 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,8 @@ # Changelog +## 0.12.0 (24.07.2023) + +* [Soroban Preview 10 support](https://github.com/kommitters/stellar_base/issues/273). ## 0.11.1 (01.06.2023) * [Add missing value types in SCVal](https://github.com/kommitters/stellar_base/pull/270). diff --git a/README.md b/README.md index 3944eba5..b765b7cd 100644 --- a/README.md +++ b/README.md @@ -26,7 +26,7 @@ You should only use **`stellar_base`** if you are planning to build on top of it ```elixir def deps do [ - {:stellar_base, "~> 0.11.1"} + {:stellar_base, "~> 0.12.0"} ] end ``` diff --git a/mix.exs b/mix.exs index c155eb0c..4ecf0bf8 100644 --- a/mix.exs +++ b/mix.exs @@ -2,7 +2,7 @@ defmodule StellarBase.MixProject do use Mix.Project @github_url "https://github.com/kommitters/stellar_base" - @version "0.11.1" + @version "0.12.0" def project do [ From e50f1c15035cf13f0eea693c5b05b1dc425f5267 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Rold=C3=A1n?= <62166813+Odraxs@users.noreply.github.com> Date: Mon, 24 Jul 2023 18:00:09 -0500 Subject: [PATCH 4/4] Add missing tests for preview 10 files (#278) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * WIP tests * Add missing tests * Remove account_merge module --------- Co-authored-by: EdwinGuayacan Co-authored-by: David Roldán --- lib/xdr/transactions/asset_list5.ex | 59 ------- lib/xdr/transactions/claimant_list10.ex | 59 ------- .../transactions/operations/account_merge.ex | 39 ----- ...tting_contract_execution_lanes_v0_test.exs | 47 ++++++ .../state_expiration_settings_test.exs | 154 ++++++++++++++++++ .../xdr/contract/contract_executable_test.exs | 117 +++++++++++++ .../contract_executable_type_test.exs | 71 ++++++++ test/xdr/contract/sc_address_test.exs | 5 +- .../contract/sc_contract_instance_test.exs | 145 +++++++++++++++++ test/xdr/contract/sc_error_code_test.exs | 39 +++++ test/xdr/contract/sc_error_test.exs | 46 ++++++ test/xdr/contract/sc_error_type_test.exs | 39 +++++ test/xdr/contract/uint64_list_test.exs | 46 ++++++ .../contract_code_entry_body_test.exs | 114 +++++++++++++ .../contract_data_durability_test.exs | 70 ++++++++ .../contract_data_entry_body_test.exs | 59 +++++++ .../contract_data_entry_data_test.exs | 41 +++++ .../contract_data_flags_test.exs | 39 +++++ .../contract_entry_body_type_test.exs | 41 +++++ .../ledger_key_contract_code_test.exs | 67 ++++++++ .../ledger_key_contract_data_test.exs | 95 +++++++++++ ...contract_id_preimage_from_address_test.exs | 88 ++++++++++ .../contract_id_preimage_test.exs | 99 +++++++++++ .../hash_id_preimage_contract_id_test.exs | 110 +++++++++++++ ...d_preimage_soroban_authorization_test.exs} | 0 .../operations/account_merge_test.exs | 51 ------ ..._footprint_expiration_result_code_test.exs | 72 ++++++++ .../bump_footprint_expiration_result_test.exs | 57 +++++++ .../bump_footprint_expiration_test.exs | 51 ++++++ .../restore_footprint_result_code_test.exs | 71 ++++++++ .../restore_footprint_result_test.exs | 55 +++++++ .../operations/restore_footprint_test.exs | 47 ++++++ .../revoke_sponsorship_op_signer_test.exs | 89 ++++++++++ .../soroban_address_credentials_test.exs | 115 +++++++++++++ .../soroban_authorization_entry_list_test.exs | 130 +++++++++++++++ .../soroban_authorization_entry_test.exs | 130 +++++++++++++++ ...oban_authorized_contract_function_test.exs | 112 +++++++++++++ .../soroban_authorized_function_test.exs | 99 +++++++++++ .../soroban_authorized_function_type_test.exs | 53 ++++++ ...oroban_authorized_invocation_list_test.exs | 110 +++++++++++++ .../soroban_authorized_invocation_test.exs | 110 +++++++++++++ .../transactions/soroban_credentials_test.exs | 62 +++++++ .../soroban_credentials_type_test.exs | 49 ++++++ 43 files changed, 2941 insertions(+), 211 deletions(-) delete mode 100644 lib/xdr/transactions/asset_list5.ex delete mode 100644 lib/xdr/transactions/claimant_list10.ex delete mode 100644 lib/xdr/transactions/operations/account_merge.ex create mode 100644 test/xdr/contract/config_setting/config_setting_contract_execution_lanes_v0_test.exs create mode 100644 test/xdr/contract/config_setting/state_expiration_settings_test.exs create mode 100644 test/xdr/contract/contract_executable_test.exs create mode 100644 test/xdr/contract/contract_executable_type_test.exs create mode 100644 test/xdr/contract/sc_contract_instance_test.exs create mode 100644 test/xdr/contract/sc_error_code_test.exs create mode 100644 test/xdr/contract/sc_error_test.exs create mode 100644 test/xdr/contract/sc_error_type_test.exs create mode 100644 test/xdr/contract/uint64_list_test.exs create mode 100644 test/xdr/ledger_entries/contract_code_entry_body_test.exs create mode 100644 test/xdr/ledger_entries/contract_data_durability_test.exs create mode 100644 test/xdr/ledger_entries/contract_data_entry_body_test.exs create mode 100644 test/xdr/ledger_entries/contract_data_entry_data_test.exs create mode 100644 test/xdr/ledger_entries/contract_data_flags_test.exs create mode 100644 test/xdr/ledger_entries/contract_entry_body_type_test.exs create mode 100644 test/xdr/ledger_entries/ledger_key_contract_code_test.exs create mode 100644 test/xdr/ledger_entries/ledger_key_contract_data_test.exs create mode 100644 test/xdr/transactions/contract_id_preimage_from_address_test.exs create mode 100644 test/xdr/transactions/contract_id_preimage_test.exs create mode 100644 test/xdr/transactions/hash_id_preimage_contract_id_test.exs rename test/xdr/transactions/{hash_id_preimage__soroban_authorization_test.exs => hash_id_preimage_soroban_authorization_test.exs} (100%) delete mode 100644 test/xdr/transactions/operations/account_merge_test.exs create mode 100644 test/xdr/transactions/operations/bump_footprint_expiration_result_code_test.exs create mode 100644 test/xdr/transactions/operations/bump_footprint_expiration_result_test.exs create mode 100644 test/xdr/transactions/operations/bump_footprint_expiration_test.exs create mode 100644 test/xdr/transactions/operations/restore_footprint_result_code_test.exs create mode 100644 test/xdr/transactions/operations/restore_footprint_result_test.exs create mode 100644 test/xdr/transactions/operations/restore_footprint_test.exs create mode 100644 test/xdr/transactions/operations/revoke_sponsorship_op_signer_test.exs create mode 100644 test/xdr/transactions/soroban_address_credentials_test.exs create mode 100644 test/xdr/transactions/soroban_authorization_entry_list_test.exs create mode 100644 test/xdr/transactions/soroban_authorization_entry_test.exs create mode 100644 test/xdr/transactions/soroban_authorized_contract_function_test.exs create mode 100644 test/xdr/transactions/soroban_authorized_function_test.exs create mode 100644 test/xdr/transactions/soroban_authorized_function_type_test.exs create mode 100644 test/xdr/transactions/soroban_authorized_invocation_list_test.exs create mode 100644 test/xdr/transactions/soroban_authorized_invocation_test.exs create mode 100644 test/xdr/transactions/soroban_credentials_test.exs create mode 100644 test/xdr/transactions/soroban_credentials_type_test.exs diff --git a/lib/xdr/transactions/asset_list5.ex b/lib/xdr/transactions/asset_list5.ex deleted file mode 100644 index 35d81c49..00000000 --- a/lib/xdr/transactions/asset_list5.ex +++ /dev/null @@ -1,59 +0,0 @@ -defmodule StellarBase.XDR.AssetList5 do - @moduledoc """ - Automatically generated by xdrgen - DO NOT EDIT or your changes may be overwritten - - Target implementation: elixir_xdr at https://hex.pm/packages/elixir_xdr - - Representation of Stellar `AssetList5` type. - """ - - @behaviour XDR.Declaration - - alias StellarBase.XDR.Asset - - @max_length 5 - - @array_type Asset - - @array_spec %{type: @array_type, max_length: @max_length} - - @type t :: %__MODULE__{items: list(Asset.t())} - - defstruct [:items] - - @spec new(items :: list(Asset.t())) :: t() - def new(items), do: %__MODULE__{items: items} - - @impl true - def encode_xdr(%__MODULE__{items: items}) do - items - |> XDR.VariableArray.new(@array_type, @max_length) - |> XDR.VariableArray.encode_xdr() - end - - @impl true - def encode_xdr!(%__MODULE__{items: items}) do - items - |> XDR.VariableArray.new(@array_type, @max_length) - |> XDR.VariableArray.encode_xdr!() - end - - @impl true - def decode_xdr(bytes, spec \\ @array_spec) - - def decode_xdr(bytes, spec) do - case XDR.VariableArray.decode_xdr(bytes, spec) do - {:ok, {items, rest}} -> {:ok, {new(items), rest}} - error -> error - end - end - - @impl true - def decode_xdr!(bytes, spec \\ @array_spec) - - def decode_xdr!(bytes, spec) do - {items, rest} = XDR.VariableArray.decode_xdr!(bytes, spec) - {new(items), rest} - end -end diff --git a/lib/xdr/transactions/claimant_list10.ex b/lib/xdr/transactions/claimant_list10.ex deleted file mode 100644 index df4cddc6..00000000 --- a/lib/xdr/transactions/claimant_list10.ex +++ /dev/null @@ -1,59 +0,0 @@ -defmodule StellarBase.XDR.ClaimantList10 do - @moduledoc """ - Automatically generated by xdrgen - DO NOT EDIT or your changes may be overwritten - - Target implementation: elixir_xdr at https://hex.pm/packages/elixir_xdr - - Representation of Stellar `ClaimantList10` type. - """ - - @behaviour XDR.Declaration - - alias StellarBase.XDR.Claimant - - @max_length 10 - - @array_type Claimant - - @array_spec %{type: @array_type, max_length: @max_length} - - @type t :: %__MODULE__{items: list(Claimant.t())} - - defstruct [:items] - - @spec new(items :: list(Claimant.t())) :: t() - def new(items), do: %__MODULE__{items: items} - - @impl true - def encode_xdr(%__MODULE__{items: items}) do - items - |> XDR.VariableArray.new(@array_type, @max_length) - |> XDR.VariableArray.encode_xdr() - end - - @impl true - def encode_xdr!(%__MODULE__{items: items}) do - items - |> XDR.VariableArray.new(@array_type, @max_length) - |> XDR.VariableArray.encode_xdr!() - end - - @impl true - def decode_xdr(bytes, spec \\ @array_spec) - - def decode_xdr(bytes, spec) do - case XDR.VariableArray.decode_xdr(bytes, spec) do - {:ok, {items, rest}} -> {:ok, {new(items), rest}} - error -> error - end - end - - @impl true - def decode_xdr!(bytes, spec \\ @array_spec) - - def decode_xdr!(bytes, spec) do - {items, rest} = XDR.VariableArray.decode_xdr!(bytes, spec) - {new(items), rest} - end -end diff --git a/lib/xdr/transactions/operations/account_merge.ex b/lib/xdr/transactions/operations/account_merge.ex deleted file mode 100644 index 99630c68..00000000 --- a/lib/xdr/transactions/operations/account_merge.ex +++ /dev/null @@ -1,39 +0,0 @@ -defmodule StellarBase.XDR.Operations.AccountMerge do - @moduledoc """ - Representation of Stellar `AccountMerge` type. - """ - alias StellarBase.XDR.MuxedAccount - - @behaviour XDR.Declaration - - @type t :: %__MODULE__{account: MuxedAccount.t()} - - defstruct [:account] - - @spec new(account :: MuxedAccount.t()) :: t() - def new(%MuxedAccount{} = account), do: %__MODULE__{account: account} - - @impl true - def encode_xdr(%__MODULE__{account: account}), do: MuxedAccount.encode_xdr(account) - - @impl true - def encode_xdr!(%__MODULE__{account: account}), do: MuxedAccount.encode_xdr!(account) - - @impl true - def decode_xdr(bytes, term \\ nil) - - def decode_xdr(bytes, _term) do - case MuxedAccount.decode_xdr(bytes) do - {:ok, {%MuxedAccount{} = account, rest}} -> {:ok, {new(account), rest}} - error -> error - end - end - - @impl true - def decode_xdr!(bytes, term \\ nil) - - def decode_xdr!(bytes, _term) do - {%MuxedAccount{} = account, rest} = MuxedAccount.decode_xdr!(bytes) - {new(account), rest} - end -end diff --git a/test/xdr/contract/config_setting/config_setting_contract_execution_lanes_v0_test.exs b/test/xdr/contract/config_setting/config_setting_contract_execution_lanes_v0_test.exs new file mode 100644 index 00000000..1726dc4f --- /dev/null +++ b/test/xdr/contract/config_setting/config_setting_contract_execution_lanes_v0_test.exs @@ -0,0 +1,47 @@ +defmodule StellarBase.XDR.ConfigSettingContractExecutionLanesV0Test do + use ExUnit.Case + + alias StellarBase.XDR.{ConfigSettingContractExecutionLanesV0, UInt32} + + setup do + %{ + ledger_max_tx_count: UInt32.new(100), + binary: <<0, 0, 0, 100>> + } + end + + test "new/1", %{ledger_max_tx_count: ledger_max_tx_count} do + %ConfigSettingContractExecutionLanesV0{ + ledger_max_tx_count: ^ledger_max_tx_count + } = ConfigSettingContractExecutionLanesV0.new(ledger_max_tx_count) + end + + test "encode_xdr/1", %{ledger_max_tx_count: ledger_max_tx_count, binary: binary} do + {:ok, ^binary} = + ConfigSettingContractExecutionLanesV0.new(ledger_max_tx_count) + |> ConfigSettingContractExecutionLanesV0.encode_xdr() + end + + test "encode_xdr!/1", %{ledger_max_tx_count: ledger_max_tx_count, binary: binary} do + ^binary = + ConfigSettingContractExecutionLanesV0.new(ledger_max_tx_count) + |> ConfigSettingContractExecutionLanesV0.encode_xdr!() + end + + test "decode_xdr/2", %{ledger_max_tx_count: ledger_max_tx_count} do + {:ok, {%ConfigSettingContractExecutionLanesV0{ledger_max_tx_count: ^ledger_max_tx_count}, ""}} = + ConfigSettingContractExecutionLanesV0.decode_xdr(<<0, 0, 0, 100>>) + end + + test "decode_xdr/2 with an invalid binary" do + {:error, :not_binary} = ConfigSettingContractExecutionLanesV0.decode_xdr(123) + end + + test "decode_xdr!/2", %{ledger_max_tx_count: ledger_max_tx_count} do + {decoded, _rest} = + ConfigSettingContractExecutionLanesV0.decode_xdr!(<<0, 0, 0, 100>> <> <<0, 0, 0, 50>>) + + assert %ConfigSettingContractExecutionLanesV0{ledger_max_tx_count: ^ledger_max_tx_count} = + decoded + end +end diff --git a/test/xdr/contract/config_setting/state_expiration_settings_test.exs b/test/xdr/contract/config_setting/state_expiration_settings_test.exs new file mode 100644 index 00000000..db748253 --- /dev/null +++ b/test/xdr/contract/config_setting/state_expiration_settings_test.exs @@ -0,0 +1,154 @@ +defmodule StellarBase.XDR.StateExpirationSettingsTest do + use ExUnit.Case + + alias StellarBase.XDR.{ + StateExpirationSettings, + UInt32, + Int64, + UInt64 + } + + setup do + max_entry_expiration = UInt32.new(100) + min_temp_entry_expiration = UInt32.new(50) + min_persistent_entry_expiration = UInt32.new(60) + auto_bump_ledgers = UInt32.new(5) + persistent_rent_rate_denominator = Int64.new(100) + temp_rent_rate_denominator = Int64.new(200) + max_entries_to_expire = UInt32.new(500) + bucket_list_size_window_sample_size = UInt32.new(1000) + eviction_scan_size = UInt64.new(5000) + + binary = + <<0, 0, 0, 100, 0, 0, 0, 50, 0, 0, 0, 60, 0, 0, 0, 5, 0, 0, 0, 0, 0, 0, 0, 100, 0, 0, 0, 0, + 0, 0, 0, 200, 0, 0, 1, 244, 0, 0, 3, 232, 0, 0, 0, 0, 0, 0, 19, 136>> + + state_expiration_settings = + StateExpirationSettings.new( + max_entry_expiration, + min_temp_entry_expiration, + min_persistent_entry_expiration, + auto_bump_ledgers, + persistent_rent_rate_denominator, + temp_rent_rate_denominator, + max_entries_to_expire, + bucket_list_size_window_sample_size, + eviction_scan_size + ) + + %{ + max_entry_expiration: max_entry_expiration, + min_temp_entry_expiration: min_temp_entry_expiration, + min_persistent_entry_expiration: min_persistent_entry_expiration, + auto_bump_ledgers: auto_bump_ledgers, + persistent_rent_rate_denominator: persistent_rent_rate_denominator, + temp_rent_rate_denominator: temp_rent_rate_denominator, + max_entries_to_expire: max_entries_to_expire, + bucket_list_size_window_sample_size: bucket_list_size_window_sample_size, + eviction_scan_size: eviction_scan_size, + binary: binary, + state_expiration_settings: state_expiration_settings + } + end + + test "new/1", %{ + max_entry_expiration: max_entry_expiration, + min_temp_entry_expiration: min_temp_entry_expiration, + min_persistent_entry_expiration: min_persistent_entry_expiration, + auto_bump_ledgers: auto_bump_ledgers, + persistent_rent_rate_denominator: persistent_rent_rate_denominator, + temp_rent_rate_denominator: temp_rent_rate_denominator, + max_entries_to_expire: max_entries_to_expire, + bucket_list_size_window_sample_size: bucket_list_size_window_sample_size, + eviction_scan_size: eviction_scan_size + } do + %StateExpirationSettings{ + max_entry_expiration: ^max_entry_expiration, + min_temp_entry_expiration: ^min_temp_entry_expiration, + min_persistent_entry_expiration: ^min_persistent_entry_expiration, + auto_bump_ledgers: ^auto_bump_ledgers, + persistent_rent_rate_denominator: ^persistent_rent_rate_denominator, + temp_rent_rate_denominator: ^temp_rent_rate_denominator, + max_entries_to_expire: ^max_entries_to_expire, + bucket_list_size_window_sample_size: ^bucket_list_size_window_sample_size, + eviction_scan_size: ^eviction_scan_size + } = + StateExpirationSettings.new( + max_entry_expiration, + min_temp_entry_expiration, + min_persistent_entry_expiration, + auto_bump_ledgers, + persistent_rent_rate_denominator, + temp_rent_rate_denominator, + max_entries_to_expire, + bucket_list_size_window_sample_size, + eviction_scan_size + ) + end + + test "encode_xdr/1", %{ + binary: binary, + max_entry_expiration: max_entry_expiration, + min_temp_entry_expiration: min_temp_entry_expiration, + min_persistent_entry_expiration: min_persistent_entry_expiration, + auto_bump_ledgers: auto_bump_ledgers, + persistent_rent_rate_denominator: persistent_rent_rate_denominator, + temp_rent_rate_denominator: temp_rent_rate_denominator, + max_entries_to_expire: max_entries_to_expire, + bucket_list_size_window_sample_size: bucket_list_size_window_sample_size, + eviction_scan_size: eviction_scan_size + } do + {:ok, ^binary} = + StateExpirationSettings.new( + max_entry_expiration, + min_temp_entry_expiration, + min_persistent_entry_expiration, + auto_bump_ledgers, + persistent_rent_rate_denominator, + temp_rent_rate_denominator, + max_entries_to_expire, + bucket_list_size_window_sample_size, + eviction_scan_size + ) + |> StateExpirationSettings.encode_xdr() + end + + test "encode_xdr!/1", %{ + binary: binary, + max_entry_expiration: max_entry_expiration, + min_temp_entry_expiration: min_temp_entry_expiration, + min_persistent_entry_expiration: min_persistent_entry_expiration, + auto_bump_ledgers: auto_bump_ledgers, + persistent_rent_rate_denominator: persistent_rent_rate_denominator, + temp_rent_rate_denominator: temp_rent_rate_denominator, + max_entries_to_expire: max_entries_to_expire, + bucket_list_size_window_sample_size: bucket_list_size_window_sample_size, + eviction_scan_size: eviction_scan_size + } do + ^binary = + StateExpirationSettings.new( + max_entry_expiration, + min_temp_entry_expiration, + min_persistent_entry_expiration, + auto_bump_ledgers, + persistent_rent_rate_denominator, + temp_rent_rate_denominator, + max_entries_to_expire, + bucket_list_size_window_sample_size, + eviction_scan_size + ) + |> StateExpirationSettings.encode_xdr!() + end + + test "decode_xdr/2", %{binary: binary, state_expiration_settings: state_expiration_settings} do + {:ok, {^state_expiration_settings, ""}} = StateExpirationSettings.decode_xdr(binary) + end + + test "decode_xdr/2 with an invalid binary" do + {:error, :not_binary} = StateExpirationSettings.decode_xdr(123) + end + + test "decode_xdr!/2", %{binary: binary, state_expiration_settings: state_expiration_settings} do + {^state_expiration_settings, ^binary} = StateExpirationSettings.decode_xdr!(binary <> binary) + end +end diff --git a/test/xdr/contract/contract_executable_test.exs b/test/xdr/contract/contract_executable_test.exs new file mode 100644 index 00000000..6a1839d3 --- /dev/null +++ b/test/xdr/contract/contract_executable_test.exs @@ -0,0 +1,117 @@ +defmodule StellarBase.XDR.ContractExecutableTest do + use ExUnit.Case + + alias StellarBase.XDR.{ + ContractExecutable, + ContractExecutableType, + Hash, + Void + } + + setup do + binary_wasm = + <<86, 32, 6, 9, 172, 4, 212, 185, 249, 87, 184, 164, 58, 34, 167, 183, 226, 117, 205, 116, + 11, 130, 119, 172, 224, 51, 12, 148, 90, 251, 17, 12>> + + binary_wasm_result = + <<0, 0, 0, 0, 86, 32, 6, 9, 172, 4, 212, 185, 249, 87, 184, 164, 58, 34, 167, 183, 226, 117, + 205, 116, 11, 130, 119, 172, 224, 51, 12, 148, 90, 251, 17, 12>> + + binary_token = <<0, 0, 0, 1>> + wasm_value = Hash.new(binary_wasm) + token_value = Void.new() + wasm_type = %ContractExecutableType{identifier: :CONTRACT_EXECUTABLE_WASM} + token_type = %ContractExecutableType{identifier: :CONTRACT_EXECUTABLE_TOKEN} + contract_executable_wasm = ContractExecutable.new(wasm_value, wasm_type) + contract_executable_token = ContractExecutable.new(token_value, token_type) + + %{ + binary_wasm: binary_wasm, + binary_token: binary_token, + wasm_value: wasm_value, + token_value: token_value, + wasm_type: wasm_type, + token_type: token_type, + binary_wasm_result: binary_wasm_result, + contract_executable_token: contract_executable_token, + contract_executable_wasm: contract_executable_wasm + } + end + + test "new/1 with wasm value", %{wasm_value: wasm_value, wasm_type: wasm_type} do + %ContractExecutable{value: ^wasm_value, type: ^wasm_type} = + ContractExecutable.new(wasm_value, wasm_type) + end + + test "new/1 with token value", %{token_value: token_value, token_type: token_type} do + %ContractExecutable{value: ^token_value, type: ^token_type} = + ContractExecutable.new(token_value, token_type) + end + + test "encode_xdr/1 with token value", %{ + binary_token: binary_token, + token_value: token_value, + token_type: token_type + } do + {:ok, ^binary_token} = + token_value + |> ContractExecutable.new(token_type) + |> ContractExecutable.encode_xdr() + end + + test "encode_xdr!/1 with token value", %{ + binary_token: binary_token, + token_value: token_value, + token_type: token_type + } do + ^binary_token = + token_value + |> ContractExecutable.new(token_type) + |> ContractExecutable.encode_xdr!() + end + + test "encode_xdr/1 with wasm value", %{ + wasm_value: wasm_value, + wasm_type: wasm_type, + binary_wasm_result: binary_wasm_result + } do + {:ok, ^binary_wasm_result} = + wasm_value + |> ContractExecutable.new(wasm_type) + |> ContractExecutable.encode_xdr() + end + + test "decode_xdr/2 with wasm value", %{ + binary_wasm_result: binary_wasm_result, + contract_executable_wasm: contract_executable_wasm + } do + {:ok, {^contract_executable_wasm, ""}} = ContractExecutable.decode_xdr(binary_wasm_result) + end + + test "decode_xdr/2 with token value", %{ + binary_token: binary_token, + contract_executable_token: contract_executable_token + } do + {:ok, {^contract_executable_token, ""}} = ContractExecutable.decode_xdr(binary_token) + end + + test "decode_xdr!/2 with wasm value", %{ + binary_wasm_result: binary_wasm_result, + contract_executable_wasm: contract_executable_wasm + } do + {^contract_executable_wasm, ^binary_wasm_result} = + ContractExecutable.decode_xdr!(binary_wasm_result <> binary_wasm_result) + end + + test "decode_xdr!/2 with token value", %{ + binary_token: binary_token, + contract_executable_token: contract_executable_token + } do + {^contract_executable_token, ^binary_token} = + ContractExecutable.decode_xdr!(binary_token <> binary_token) + end + + test "decode_xdr/2 with an invalid binary" do + {:error, :not_binary} = ContractExecutable.decode_xdr(123) + end +end diff --git a/test/xdr/contract/contract_executable_type_test.exs b/test/xdr/contract/contract_executable_type_test.exs new file mode 100644 index 00000000..8f06207b --- /dev/null +++ b/test/xdr/contract/contract_executable_type_test.exs @@ -0,0 +1,71 @@ +defmodule StellarBase.XDR.ContractExecutableTypeTest do + use ExUnit.Case + + alias StellarBase.XDR.ContractExecutableType + + setup do + %{ + wasm: :CONTRACT_EXECUTABLE_WASM, + token: :CONTRACT_EXECUTABLE_TOKEN, + binary_wasm: <<0, 0, 0, 0>>, + binary_token: <<0, 0, 0, 1>>, + wasm_identifier: :CONTRACT_EXECUTABLE_WASM, + token_identifier: :CONTRACT_EXECUTABLE_TOKEN, + wasm_type: %ContractExecutableType{identifier: :CONTRACT_EXECUTABLE_WASM}, + token_type: %ContractExecutableType{identifier: :CONTRACT_EXECUTABLE_TOKEN} + } + end + + test "new/1 with wasm identifier", %{wasm_identifier: wasm_identifier} do + %ContractExecutableType{identifier: ^wasm_identifier} = + ContractExecutableType.new(:CONTRACT_EXECUTABLE_WASM) + end + + test "new/1 with token identifier", %{token_identifier: token_identifier} do + %ContractExecutableType{identifier: ^token_identifier} = + ContractExecutableType.new(:CONTRACT_EXECUTABLE_TOKEN) + end + + test "encode_xdr/1 with wasm identifier", %{binary_wasm: binary_wasm, wasm_type: wasm_type} do + {:ok, ^binary_wasm} = ContractExecutableType.encode_xdr(wasm_type) + end + + test "encode_xdr/1 with token identifier", %{binary_token: binary_token, token_type: token_type} do + {:ok, ^binary_token} = ContractExecutableType.encode_xdr(token_type) + end + + test "encode_xdr!/1 with wasm identifier", %{binary_wasm: binary_wasm, wasm_type: wasm_type} do + ^binary_wasm = ContractExecutableType.encode_xdr!(wasm_type) + end + + test "encode_xdr!/1 with token identifier", %{ + binary_token: binary_token, + token_type: token_type + } do + ^binary_token = ContractExecutableType.encode_xdr!(token_type) + end + + test "decode_xdr/2 with wasm identifier", %{binary_wasm: binary_wasm, wasm_type: wasm_type} do + {:ok, {^wasm_type, ""}} = ContractExecutableType.decode_xdr(binary_wasm) + end + + test "decode_xdr/2 with token identifier", %{binary_token: binary_token, token_type: token_type} do + {:ok, {^token_type, ""}} = ContractExecutableType.decode_xdr(binary_token) + end + + test "decode_xdr/2 with an invalid binary" do + {:error, :not_binary} = ContractExecutableType.decode_xdr(123) + end + + test "decode_xdr!/2 with wasm identifier", %{binary_wasm: binary_wasm, wasm_type: wasm_type} do + {^wasm_type, ^binary_wasm} = ContractExecutableType.decode_xdr!(binary_wasm <> binary_wasm) + end + + test "decode_xdr!/2 with token identifier", %{ + binary_token: binary_token, + token_type: token_type + } do + {^token_type, ^binary_token} = + ContractExecutableType.decode_xdr!(binary_token <> binary_token) + end +end diff --git a/test/xdr/contract/sc_address_test.exs b/test/xdr/contract/sc_address_test.exs index e71424a4..b587bf6b 100644 --- a/test/xdr/contract/sc_address_test.exs +++ b/test/xdr/contract/sc_address_test.exs @@ -1,13 +1,12 @@ defmodule StellarBase.XDR.SCAddressTest do use ExUnit.Case - alias StellarBase.XDR.SCAddress - alias StellarBase.XDR.SCAddressType - alias StellarBase.XDR.{ AccountID, PublicKey, PublicKeyType, + SCAddress, + SCAddressType, UInt256 } diff --git a/test/xdr/contract/sc_contract_instance_test.exs b/test/xdr/contract/sc_contract_instance_test.exs new file mode 100644 index 00000000..b1c26252 --- /dev/null +++ b/test/xdr/contract/sc_contract_instance_test.exs @@ -0,0 +1,145 @@ +defmodule StellarBase.XDR.SCContractInstanceTest do + use ExUnit.Case + + alias StellarBase.XDR.{ + ContractExecutable, + ContractExecutableType, + SCContractInstance, + OptionalSCMap, + Hash, + Void + } + + setup do + binary_wasm = + <<86, 32, 6, 9, 172, 4, 212, 185, 249, 87, 184, 164, 58, 34, 167, 183, 226, 117, 205, 116, + 11, 130, 119, 172, 224, 51, 12, 148, 90, 251, 17, 12>> + + binary_wasm_result = + <<0, 0, 0, 0, 86, 32, 6, 9, 172, 4, 212, 185, 249, 87, 184, 164, 58, 34, 167, 183, 226, 117, + 205, 116, 11, 130, 119, 172, 224, 51, 12, 148, 90, 251, 17, 12, 0, 0, 0, 0>> + + binary_token = <<0, 0, 0, 1, 0, 0, 0, 0>> + wasm_value = Hash.new(binary_wasm) + token_value = Void.new() + wasm_type = %ContractExecutableType{identifier: :CONTRACT_EXECUTABLE_WASM} + token_type = %ContractExecutableType{identifier: :CONTRACT_EXECUTABLE_TOKEN} + contract_executable_wasm = ContractExecutable.new(wasm_value, wasm_type) + contract_executable_token = ContractExecutable.new(token_value, token_type) + + optional_map = OptionalSCMap.new() + SCContractInstance.new(contract_executable_wasm, optional_map) + + sc_contract_instance_with_wasm = + SCContractInstance.new(contract_executable_wasm, optional_map) + + sc_contract_instance_with_token = + SCContractInstance.new(contract_executable_token, optional_map) + + %{ + binary_wasm: binary_wasm, + binary_token: binary_token, + binary_wasm_result: binary_wasm_result, + wasm_value: wasm_value, + token_value: token_value, + wasm_type: wasm_type, + token_type: token_type, + contract_executable_wasm: contract_executable_wasm, + contract_executable_token: contract_executable_token, + optional_map: optional_map, + sc_contract_instance_with_token: sc_contract_instance_with_token, + sc_contract_instance_with_wasm: sc_contract_instance_with_wasm + } + end + + test "new/2 with wasm value", %{ + contract_executable_wasm: contract_executable_wasm, + optional_map: optional_map + } do + %SCContractInstance{executable: ^contract_executable_wasm, storage: ^optional_map} = + SCContractInstance.new(contract_executable_wasm, optional_map) + end + + test "new/2 with token value", %{ + contract_executable_token: contract_executable_token, + optional_map: optional_map + } do + %SCContractInstance{executable: ^contract_executable_token, storage: ^optional_map} = + SCContractInstance.new(contract_executable_token, optional_map) + end + + test "encode_xdr/1 with wasm value", %{ + binary_wasm_result: binary_wasm_result, + contract_executable_wasm: contract_executable_wasm, + optional_map: optional_map + } do + {:ok, ^binary_wasm_result} = + contract_executable_wasm + |> SCContractInstance.new(optional_map) + |> SCContractInstance.encode_xdr() + end + + test "encode_xdr/1 with token value", %{ + binary_token: binary_token, + contract_executable_token: contract_executable_token, + optional_map: optional_map + } do + {:ok, ^binary_token} = + SCContractInstance.new(contract_executable_token, optional_map) + |> SCContractInstance.encode_xdr() + end + + test "encode_xdr!/1 with wasm value", %{ + binary_wasm_result: binary_wasm_result, + contract_executable_wasm: contract_executable_wasm, + optional_map: optional_map + } do + ^binary_wasm_result = + contract_executable_wasm + |> SCContractInstance.new(optional_map) + |> SCContractInstance.encode_xdr!() + end + + test "encode_xdr!/1 with token value", %{ + binary_token: binary_token, + contract_executable_token: contract_executable_token, + optional_map: optional_map + } do + ^binary_token = + SCContractInstance.new(contract_executable_token, optional_map) + |> SCContractInstance.encode_xdr!() + end + + test "decode_xdr/2 with wasm value", %{ + binary_wasm_result: binary_wasm_result, + sc_contract_instance_with_wasm: sc_contract_instance_with_wasm + } do + {:ok, {^sc_contract_instance_with_wasm, ""}} = + SCContractInstance.decode_xdr(binary_wasm_result) + end + + test "decode_xdr/2 with token value", %{ + binary_token: binary_token, + sc_contract_instance_with_token: sc_contract_instance_with_token + } do + {:ok, {^sc_contract_instance_with_token, ""}} = SCContractInstance.decode_xdr(binary_token) + end + + test "decode_xdr!/2 with wasm value", %{ + binary_wasm_result: binary_wasm_result, + sc_contract_instance_with_wasm: sc_contract_instance_with_wasm + } do + {^sc_contract_instance_with_wasm, ""} = SCContractInstance.decode_xdr!(binary_wasm_result) + end + + test "decode_xdr!/2 with token value", %{ + binary_token: binary_token, + sc_contract_instance_with_token: sc_contract_instance_with_token + } do + {^sc_contract_instance_with_token, ""} = SCContractInstance.decode_xdr!(binary_token) + end + + test "decode_xdr!/2 with an invalid binary" do + {:error, :not_binary} = SCContractInstance.decode_xdr(123) + end +end diff --git a/test/xdr/contract/sc_error_code_test.exs b/test/xdr/contract/sc_error_code_test.exs new file mode 100644 index 00000000..5f213704 --- /dev/null +++ b/test/xdr/contract/sc_error_code_test.exs @@ -0,0 +1,39 @@ +defmodule StellarBase.XDR.SCErrorCodeTest do + use ExUnit.Case + + alias StellarBase.XDR.SCErrorCode + + setup do + type = :SCEC_ARITH_DOMAIN + sc_error_code = SCErrorCode.new(type) + + %{ + type: type, + sc_error_code: sc_error_code + } + end + + test "new/1", %{type: type} do + %SCErrorCode{identifier: ^type} = SCErrorCode.new(type) + end + + test "encode_xdr/1", %{type: type} do + {:ok, <<0, 0, 0, 0>>} = type |> SCErrorCode.new() |> SCErrorCode.encode_xdr() + end + + test "encode_xdr!/1", %{type: type} do + <<0, 0, 0, 0>> = type |> SCErrorCode.new() |> SCErrorCode.encode_xdr!() + end + + test "decode_xdr/2", %{sc_error_code: sc_error_code} do + {:ok, {^sc_error_code, ""}} = SCErrorCode.decode_xdr(SCErrorCode.encode_xdr!(sc_error_code)) + end + + test "decode_xdr!/2", %{sc_error_code: sc_error_code} do + {^sc_error_code, ""} = SCErrorCode.decode_xdr!(SCErrorCode.encode_xdr!(sc_error_code)) + end + + test "decode_xdr!/2 with an invalid binary" do + {:error, :not_binary} = SCErrorCode.decode_xdr(123) + end +end diff --git a/test/xdr/contract/sc_error_test.exs b/test/xdr/contract/sc_error_test.exs new file mode 100644 index 00000000..daf649b8 --- /dev/null +++ b/test/xdr/contract/sc_error_test.exs @@ -0,0 +1,46 @@ +defmodule StellarBase.XDR.SCErrorTest do + use ExUnit.Case + + alias StellarBase.XDR.{ + SCError, + SCErrorType, + SCErrorCode + } + + setup do + type = %SCErrorType{identifier: :SCE_CONTRACT} + code = %SCErrorCode{identifier: :SCEC_INVALID_ACTION} + sc_error = SCError.new(type, code) + + %{ + type: type, + code: code, + sc_error: sc_error, + binary: <<0, 0, 0, 0, 0, 0, 0, 6>> + } + end + + test "new/2", %{type: type, code: code} do + %SCError{type: ^type, code: ^code} = SCError.new(type, code) + end + + test "encode_xdr/1", %{sc_error: sc_error, binary: binary} do + {:ok, ^binary} = SCError.encode_xdr(sc_error) + end + + test "encode_xdr!/1", %{sc_error: sc_error, binary: binary} do + ^binary = SCError.encode_xdr!(sc_error) + end + + test "decode_xdr/2", %{sc_error: sc_error, binary: binary} do + {:ok, {^sc_error, ""}} = SCError.decode_xdr(binary) + end + + test "decode_xdr/2 with an invalid binary" do + {:error, :not_binary} = SCError.decode_xdr(123) + end + + test "decode_xdr!/2", %{sc_error: sc_error, binary: binary} do + {^sc_error, ^binary} = SCError.decode_xdr!(binary <> binary) + end +end diff --git a/test/xdr/contract/sc_error_type_test.exs b/test/xdr/contract/sc_error_type_test.exs new file mode 100644 index 00000000..a34b4c90 --- /dev/null +++ b/test/xdr/contract/sc_error_type_test.exs @@ -0,0 +1,39 @@ +defmodule StellarBase.XDR.SCErrorTypeTest do + use ExUnit.Case + + alias StellarBase.XDR.SCErrorType + + setup do + type = :SCE_CONTRACT + sc_error_type = SCErrorType.new(type) + + %{ + type: type, + sc_error_type: sc_error_type + } + end + + test "new/1", %{type: type} do + %SCErrorType{identifier: ^type} = SCErrorType.new(type) + end + + test "encode_xdr/1", %{type: type} do + {:ok, <<0, 0, 0, 0>>} = type |> SCErrorType.new() |> SCErrorType.encode_xdr() + end + + test "encode_xdr!/1", %{type: type} do + <<0, 0, 0, 0>> = type |> SCErrorType.new() |> SCErrorType.encode_xdr!() + end + + test "decode_xdr/2", %{sc_error_type: sc_error_type} do + {:ok, {^sc_error_type, ""}} = SCErrorType.decode_xdr(SCErrorType.encode_xdr!(sc_error_type)) + end + + test "decode_xdr!/2", %{sc_error_type: sc_error_type} do + {^sc_error_type, ""} = SCErrorType.decode_xdr!(SCErrorType.encode_xdr!(sc_error_type)) + end + + test "decode_xdr!/2 with an invalid binary" do + {:error, :not_binary} = SCErrorType.decode_xdr(123) + end +end diff --git a/test/xdr/contract/uint64_list_test.exs b/test/xdr/contract/uint64_list_test.exs new file mode 100644 index 00000000..f5aabdc0 --- /dev/null +++ b/test/xdr/contract/uint64_list_test.exs @@ -0,0 +1,46 @@ +defmodule StellarBase.XDR.UInt64ListTest do + use ExUnit.Case + + alias StellarBase.XDR.{UInt64, UInt64List} + + setup do + list_items = [123, 456, 789] + + encoded_result = + <<0, 0, 0, 3, 0, 0, 0, 0, 0, 0, 0, 123, 0, 0, 0, 0, 0, 0, 1, 200, 0, 0, 0, 0, 0, 0, 3, 21>> + + uint64_items = Enum.map(list_items, &UInt64.new/1) + uint64_list = UInt64List.new(uint64_items) + + %{ + list_items: list_items, + uint64_items: uint64_items, + uint64_list: uint64_list, + encoded_result: encoded_result + } + end + + test "new/1", %{uint64_items: uint64_items} do + %UInt64List{items: ^uint64_items} = UInt64List.new(uint64_items) + end + + test "encode_xdr/1", %{uint64_list: uint64_list, encoded_result: encoded_result} do + {:ok, ^encoded_result} = UInt64List.encode_xdr(uint64_list) + end + + test "encode_xdr!/1", %{uint64_list: uint64_list, encoded_result: encoded_result} do + ^encoded_result = UInt64List.encode_xdr!(uint64_list) + end + + test "decode_xdr/2", %{uint64_list: uint64_list} do + {:ok, {^uint64_list, ""}} = UInt64List.decode_xdr(UInt64List.encode_xdr!(uint64_list)) + end + + test "decode_xdr!/2", %{uint64_list: uint64_list} do + {^uint64_list, ""} = UInt64List.decode_xdr!(UInt64List.encode_xdr!(uint64_list)) + end + + test "decode_xdr!/2 with an invalid binary" do + {:error, :not_binary} = UInt64List.decode_xdr(123) + end +end diff --git a/test/xdr/ledger_entries/contract_code_entry_body_test.exs b/test/xdr/ledger_entries/contract_code_entry_body_test.exs new file mode 100644 index 00000000..6fd88ec3 --- /dev/null +++ b/test/xdr/ledger_entries/contract_code_entry_body_test.exs @@ -0,0 +1,114 @@ +defmodule StellarBase.XDR.ContractCodeEntryBodyTest do + use ExUnit.Case + + alias StellarBase.XDR.{ContractCodeEntryBody, ContractEntryBodyType, VariableOpaque, Void} + + setup do + data = <<1, 2, 3, 4, 5>> + expiration_extension = Void.new() + data_entry_type = %ContractEntryBodyType{identifier: :DATA_ENTRY} + expiration_extension_type = %ContractEntryBodyType{identifier: :EXPIRATION_EXTENSION} + + expiration_extension_body = + ContractCodeEntryBody.new(expiration_extension, expiration_extension_type) + + variable_opaque = + VariableOpaque.new(<<0, 0, 0, 9, 71, 67, 73, 90, 51, 71, 83, 77, 53, 0, 0, 0>>) + + encoded_result_data_entry = + <<0, 0, 0, 0, 0, 0, 0, 16, 0, 0, 0, 9, 71, 67, 73, 90, 51, 71, 83, 77, 53, 0, 0, 0>> + + encoded_result_expiration_extension = <<0, 0, 0, 1>> + data_entry_body = ContractCodeEntryBody.new(variable_opaque, data_entry_type) + + %{ + data: data, + data_entry_type: data_entry_type, + expiration_extension: expiration_extension, + expiration_extension_type: expiration_extension_type, + data_entry_body: data_entry_body, + expiration_extension_body: expiration_extension_body, + variable_opaque: variable_opaque, + encoded_result_data_entry: encoded_result_data_entry, + encoded_result_expiration_extension: encoded_result_expiration_extension + } + end + + test "new/2 with data entry", %{ + data_entry_type: data_entry_type, + variable_opaque: variable_opaque + } do + %ContractCodeEntryBody{value: ^variable_opaque, type: ^data_entry_type} = + ContractCodeEntryBody.new(variable_opaque, data_entry_type) + end + + test "new/2 with expiration extension", %{ + expiration_extension: expiration_extension, + expiration_extension_type: expiration_extension_type + } do + %ContractCodeEntryBody{value: %Void{}, type: ^expiration_extension_type} = + ContractCodeEntryBody.new(expiration_extension, expiration_extension_type) + end + + test "encode_xdr/1 with data entry", %{ + data_entry_body: data_entry_body, + encoded_result_data_entry: encoded_result_data_entry + } do + {:ok, ^encoded_result_data_entry} = ContractCodeEntryBody.encode_xdr(data_entry_body) + end + + test "encode_xdr/1 with expiration extension", %{ + expiration_extension_body: expiration_extension_body, + encoded_result_expiration_extension: encoded_result_expiration_extension + } do + {:ok, ^encoded_result_expiration_extension} = + ContractCodeEntryBody.encode_xdr(expiration_extension_body) + end + + test "encode_xdr!/1 with data entry", %{ + data_entry_body: data_entry_body, + encoded_result_data_entry: encoded_result_data_entry + } do + ^encoded_result_data_entry = ContractCodeEntryBody.encode_xdr!(data_entry_body) + end + + test "encode_xdr!/1 with expiration extension", %{ + expiration_extension_body: expiration_extension_body, + encoded_result_expiration_extension: encoded_result_expiration_extension + } do + ^encoded_result_expiration_extension = + ContractCodeEntryBody.encode_xdr!(expiration_extension_body) + end + + test "decode_xdr/2 with data entry", %{data_entry_body: data_entry_body} do + {:ok, {^data_entry_body, ""}} = + ContractCodeEntryBody.decode_xdr(ContractCodeEntryBody.encode_xdr!(data_entry_body)) + end + + test "decode_xdr/2 with expiration extension", %{ + expiration_extension_body: expiration_extension_body + } do + {:ok, {^expiration_extension_body, ""}} = + ContractCodeEntryBody.decode_xdr( + ContractCodeEntryBody.encode_xdr!(expiration_extension_body) + ) + end + + test "decode_xdr!/2 with data entry", %{data_entry_body: data_entry_body} do + {^data_entry_body, ""} = + ContractCodeEntryBody.decode_xdr!(ContractCodeEntryBody.encode_xdr!(data_entry_body)) + end + + test "decode_xdr!/2 with expiration extension", %{ + expiration_extension_body: expiration_extension_body + } do + {^expiration_extension_body, ""} = + ContractCodeEntryBody.decode_xdr!( + ContractCodeEntryBody.encode_xdr!(expiration_extension_body) + ) + end + + test "decode_xdr!/2 with an invalid binary" do + {:error, :not_binary} = ContractCodeEntryBody.decode_xdr(123) + end +end diff --git a/test/xdr/ledger_entries/contract_data_durability_test.exs b/test/xdr/ledger_entries/contract_data_durability_test.exs new file mode 100644 index 00000000..f7e8e506 --- /dev/null +++ b/test/xdr/ledger_entries/contract_data_durability_test.exs @@ -0,0 +1,70 @@ +defmodule StellarBase.XDR.ContractDataDurabilityTest do + use ExUnit.Case + + alias StellarBase.XDR.ContractDataDurability + + setup do + temporary_durability = :TEMPORARY + persistent_durability = :PERSISTENT + + temporary = ContractDataDurability.new(temporary_durability) + persistent = ContractDataDurability.new(persistent_durability) + + %{ + temporary_durability: temporary_durability, + persistent_durability: persistent_durability, + temporary: temporary, + persistent: persistent + } + end + + test "new/1 with temporary durability", %{temporary_durability: temporary_durability} do + %ContractDataDurability{identifier: ^temporary_durability} = + ContractDataDurability.new(temporary_durability) + end + + test "new/1 with persistent durability", %{persistent_durability: persistent_durability} do + %ContractDataDurability{identifier: ^persistent_durability} = + ContractDataDurability.new(persistent_durability) + end + + test "encode_xdr/1 with temporary durability", %{temporary: temporary} do + {:ok, <<0, 0, 0, 0>>} = ContractDataDurability.encode_xdr(temporary) + end + + test "encode_xdr/1 with persistent durability", %{persistent: persistent} do + {:ok, <<0, 0, 0, 1>>} = ContractDataDurability.encode_xdr(persistent) + end + + test "encode_xdr!/1 with temporary durability", %{temporary: temporary} do + <<0, 0, 0, 0>> = ContractDataDurability.encode_xdr!(temporary) + end + + test "encode_xdr!/1 with persistent durability", %{persistent: persistent} do + <<0, 0, 0, 1>> = ContractDataDurability.encode_xdr!(persistent) + end + + test "decode_xdr/2 with temporary durability", %{temporary: temporary} do + {:ok, {^temporary, ""}} = + ContractDataDurability.decode_xdr(ContractDataDurability.encode_xdr!(temporary)) + end + + test "decode_xdr/2 with persistent durability", %{persistent: persistent} do + {:ok, {^persistent, ""}} = + ContractDataDurability.decode_xdr(ContractDataDurability.encode_xdr!(persistent)) + end + + test "decode_xdr!/2 with temporary durability", %{temporary: temporary} do + {^temporary, ""} = + ContractDataDurability.decode_xdr!(ContractDataDurability.encode_xdr!(temporary)) + end + + test "decode_xdr!/2 with persistent durability", %{persistent: persistent} do + {^persistent, ""} = + ContractDataDurability.decode_xdr!(ContractDataDurability.encode_xdr!(persistent)) + end + + test "decode_xdr!/2 with an invalid binary" do + {:error, :not_binary} = ContractDataDurability.decode_xdr(123) + end +end diff --git a/test/xdr/ledger_entries/contract_data_entry_body_test.exs b/test/xdr/ledger_entries/contract_data_entry_body_test.exs new file mode 100644 index 00000000..325365a5 --- /dev/null +++ b/test/xdr/ledger_entries/contract_data_entry_body_test.exs @@ -0,0 +1,59 @@ +defmodule StellarBase.XDR.ContractDataEntryBodyTest do + use ExUnit.Case + + alias StellarBase.XDR.{ + ContractDataEntryBody, + ContractEntryBodyType, + ContractDataEntryData, + UInt32, + SCVal, + SCValType, + Int32 + } + + setup do + flags = UInt32.new(123) + + sc_val = SCVal.new(Int32.new(42), SCValType.new(:SCV_I32)) + + data_entry_data = %ContractDataEntryData{flags: flags, val: sc_val} + type = ContractEntryBodyType.new(:DATA_ENTRY) + data_entry_body = %ContractDataEntryBody{value: data_entry_data, type: type} + + binary = <<0, 0, 0, 0, 0, 0, 0, 123, 0, 0, 0, 4, 0, 0, 0, 42>> + + %{ + data_entry_data: data_entry_data, + type: type, + data_entry_body: data_entry_body, + binary: binary + } + end + + test "new/2", %{data_entry_data: data_entry_data, type: type} do + %ContractDataEntryBody{value: ^data_entry_data, type: ^type} = + ContractDataEntryBody.new(data_entry_data, type) + end + + test "encode_xdr/1", %{data_entry_body: data_entry_body, binary: binary} do + {:ok, ^binary} = ContractDataEntryBody.encode_xdr(data_entry_body) + end + + test "encode_xdr!/1", %{data_entry_body: data_entry_body, binary: binary} do + ^binary = ContractDataEntryBody.encode_xdr!(data_entry_body) + end + + test "decode_xdr/2", %{data_entry_body: data_entry_body} do + {:ok, {^data_entry_body, ""}} = + ContractDataEntryBody.decode_xdr(ContractDataEntryBody.encode_xdr!(data_entry_body)) + end + + test "decode_xdr!/2", %{data_entry_body: data_entry_body} do + {^data_entry_body, ""} = + ContractDataEntryBody.decode_xdr!(ContractDataEntryBody.encode_xdr!(data_entry_body)) + end + + test "decode_xdr!/2 with an invalid binary" do + {:error, :not_binary} = ContractDataEntryBody.decode_xdr(123) + end +end diff --git a/test/xdr/ledger_entries/contract_data_entry_data_test.exs b/test/xdr/ledger_entries/contract_data_entry_data_test.exs new file mode 100644 index 00000000..856ab7aa --- /dev/null +++ b/test/xdr/ledger_entries/contract_data_entry_data_test.exs @@ -0,0 +1,41 @@ +defmodule StellarBase.XDR.ContractDataEntryDataTest do + use ExUnit.Case + + alias StellarBase.XDR.{ContractDataEntryData, Int32, SCVal, SCValType, UInt32} + + setup do + flags = UInt32.new(123) + sc_val = SCVal.new(Int32.new(42), SCValType.new(:SCV_I32)) + + %{ + flags: flags, + sc_val: sc_val, + data_entry_data: ContractDataEntryData.new(flags, sc_val), + binary: <<0, 0, 0, 123, 0, 0, 0, 4, 0, 0, 0, 42>> + } + end + + test "new/2", %{flags: flags, sc_val: sc_val} do + %ContractDataEntryData{flags: ^flags, val: ^sc_val} = ContractDataEntryData.new(flags, sc_val) + end + + test "encode_xdr/1", %{data_entry_data: data_entry_data, binary: binary} do + {:ok, ^binary} = ContractDataEntryData.encode_xdr(data_entry_data) + end + + test "encode_xdr!/1", %{data_entry_data: data_entry_data, binary: binary} do + ^binary = ContractDataEntryData.encode_xdr!(data_entry_data) + end + + test "decode_xdr/2", %{data_entry_data: data_entry_data, binary: binary} do + {:ok, {^data_entry_data, ""}} = ContractDataEntryData.decode_xdr(binary) + end + + test "decode_xdr!/2", %{data_entry_data: data_entry_data, binary: binary} do + {^data_entry_data, ""} = ContractDataEntryData.decode_xdr!(binary) + end + + test "decode_xdr!/2 with an invalid binary" do + {:error, :not_binary} = ContractDataEntryData.decode_xdr(123) + end +end diff --git a/test/xdr/ledger_entries/contract_data_flags_test.exs b/test/xdr/ledger_entries/contract_data_flags_test.exs new file mode 100644 index 00000000..ec78b791 --- /dev/null +++ b/test/xdr/ledger_entries/contract_data_flags_test.exs @@ -0,0 +1,39 @@ +defmodule StellarBase.XDR.ContractDataFlagsTest do + use ExUnit.Case + + alias StellarBase.XDR.ContractDataFlags + + setup do + %{ + identifier: :NO_AUTOBUMP, + contract_data_flags: ContractDataFlags.new(), + binary: <<0, 0, 0, 1>> + } + end + + test "new/2", %{identifier: identifier} do + %ContractDataFlags{identifier: ^identifier} = ContractDataFlags.new() + end + + test "encode_xdr/1", %{contract_data_flags: contract_data_flags, binary: binary} do + {:ok, ^binary} = ContractDataFlags.encode_xdr(contract_data_flags) + end + + test "encode_xdr!/1", %{contract_data_flags: contract_data_flags, binary: binary} do + ^binary = ContractDataFlags.encode_xdr!(contract_data_flags) + end + + test "decode_xdr/2", %{contract_data_flags: contract_data_flags} do + {:ok, {^contract_data_flags, ""}} = + ContractDataFlags.decode_xdr(ContractDataFlags.encode_xdr!(contract_data_flags)) + end + + test "decode_xdr!/2", %{contract_data_flags: contract_data_flags} do + {^contract_data_flags, ""} = + ContractDataFlags.decode_xdr!(ContractDataFlags.encode_xdr!(contract_data_flags)) + end + + test "decode_xdr!/2 with an invalid binary" do + {:error, :not_binary} = ContractDataFlags.decode_xdr(123) + end +end diff --git a/test/xdr/ledger_entries/contract_entry_body_type_test.exs b/test/xdr/ledger_entries/contract_entry_body_type_test.exs new file mode 100644 index 00000000..53625f5e --- /dev/null +++ b/test/xdr/ledger_entries/contract_entry_body_type_test.exs @@ -0,0 +1,41 @@ +defmodule StellarBase.XDR.ContractEntryBodyTypeTest do + use ExUnit.Case + + alias StellarBase.XDR.ContractEntryBodyType + + setup do + type = :DATA_ENTRY + contract_entry_body_type = ContractEntryBodyType.new(type) + binary = <<0, 0, 0, 0>> + + %{ + type: type, + contract_entry_body_type: contract_entry_body_type, + binary: binary + } + end + + test "new/1", %{type: type} do + %ContractEntryBodyType{identifier: ^type} = ContractEntryBodyType.new(type) + end + + test "encode_xdr/1", %{type: type, binary: binary} do + {:ok, ^binary} = type |> ContractEntryBodyType.new() |> ContractEntryBodyType.encode_xdr() + end + + test "encode_xdr!/1", %{type: type, binary: binary} do + ^binary = type |> ContractEntryBodyType.new() |> ContractEntryBodyType.encode_xdr!() + end + + test "decode_xdr/2", %{contract_entry_body_type: contract_entry_body_type, binary: binary} do + {:ok, {^contract_entry_body_type, ""}} = ContractEntryBodyType.decode_xdr(binary) + end + + test "decode_xdr!/2", %{contract_entry_body_type: contract_entry_body_type, binary: binary} do + {^contract_entry_body_type, ""} = ContractEntryBodyType.decode_xdr!(binary) + end + + test "decode_xdr!/2 with an invalid binary" do + {:error, :not_binary} = ContractEntryBodyType.decode_xdr(123) + end +end diff --git a/test/xdr/ledger_entries/ledger_key_contract_code_test.exs b/test/xdr/ledger_entries/ledger_key_contract_code_test.exs new file mode 100644 index 00000000..24382982 --- /dev/null +++ b/test/xdr/ledger_entries/ledger_key_contract_code_test.exs @@ -0,0 +1,67 @@ +defmodule StellarBase.XDR.LedgerKeyContractCodeTest do + use ExUnit.Case + + alias StellarBase.XDR.{ + ContractEntryBodyType, + Hash, + LedgerKeyContractCode + } + + describe "LedgerKeyContractCode" do + setup do + hash = Hash.new("CBT6AP4HS575FETHYO6CMIZ2NUFPLKC7") + body_type = ContractEntryBodyType.new(:DATA_ENTRY) + + %{ + hash: hash, + body_type: body_type, + ledger_key_contract_code: LedgerKeyContractCode.new(hash, body_type), + binary: + <<67, 66, 84, 54, 65, 80, 52, 72, 83, 53, 55, 53, 70, 69, 84, 72, 89, 79, 54, 67, 77, + 73, 90, 50, 78, 85, 70, 80, 76, 75, 67, 55, 0, 0, 0, 0>> + } + end + + test "new/3", %{ + hash: hash, + body_type: body_type + } do + %LedgerKeyContractCode{ + hash: ^hash, + body_type: ^body_type + } = LedgerKeyContractCode.new(hash, body_type) + end + + test "encode_xdr/1", %{ + ledger_key_contract_code: ledger_key_contract_code, + binary: binary + } do + {:ok, ^binary} = LedgerKeyContractCode.encode_xdr(ledger_key_contract_code) + end + + test "encode_xdr!/1", %{ + ledger_key_contract_code: ledger_key_contract_code, + binary: binary + } do + ^binary = LedgerKeyContractCode.encode_xdr!(ledger_key_contract_code) + end + + test "decode_xdr/2", %{ + ledger_key_contract_code: ledger_key_contract_code, + binary: binary + } do + {:ok, {^ledger_key_contract_code, ""}} = LedgerKeyContractCode.decode_xdr(binary) + end + + test "decode_xdr/2 with an invalid binary" do + {:error, :not_binary} = LedgerKeyContractCode.decode_xdr(123) + end + + test "decode_xdr!/2", %{ + ledger_key_contract_code: ledger_key_contract_code, + binary: binary + } do + {^ledger_key_contract_code, ""} = LedgerKeyContractCode.decode_xdr!(binary) + end + end +end diff --git a/test/xdr/ledger_entries/ledger_key_contract_data_test.exs b/test/xdr/ledger_entries/ledger_key_contract_data_test.exs new file mode 100644 index 00000000..ae9cf4b0 --- /dev/null +++ b/test/xdr/ledger_entries/ledger_key_contract_data_test.exs @@ -0,0 +1,95 @@ +defmodule StellarBase.XDR.LedgerKeyContractDataTest do + use ExUnit.Case + + alias StellarBase.XDR.{ + ContractDataDurability, + ContractEntryBodyType, + Hash, + Int64, + LedgerKeyContractData, + SCAddress, + SCAddressType, + SCVal, + SCValType + } + + describe "LedgerKeyContractData" do + setup do + address_type = SCAddressType.new(:SC_ADDRESS_TYPE_CONTRACT) + + contract_address = + "CBT6AP4HS575FETHYO6CMIZ2NUFPLKC7" + |> Hash.new() + |> SCAddress.new(address_type) + + key = SCVal.new(Int64.new(1), SCValType.new(:SCV_I64)) + durability = ContractDataDurability.new(:TEMPORARY) + body_type = ContractEntryBodyType.new(:DATA_ENTRY) + + %{ + contract_address: contract_address, + key: key, + durability: durability, + body_type: body_type, + ledger_key_contract_data: + LedgerKeyContractData.new(contract_address, key, durability, body_type), + binary: + <<0, 0, 0, 1, 67, 66, 84, 54, 65, 80, 52, 72, 83, 53, 55, 53, 70, 69, 84, 72, 89, 79, + 54, 67, 77, 73, 90, 50, 78, 85, 70, 80, 76, 75, 67, 55, 0, 0, 0, 6, 0, 0, 0, 0, 0, 0, + 0, 1, 0, 0, 0, 0, 0, 0, 0, 0>> + } + end + + test "new/3", %{ + contract_address: contract_address, + key: key, + durability: durability, + body_type: body_type + } do + %LedgerKeyContractData{ + contract: ^contract_address, + key: ^key, + durability: ^durability, + body_type: ^body_type + } = + LedgerKeyContractData.new( + contract_address, + key, + durability, + body_type + ) + end + + test "encode_xdr/1", %{ + ledger_key_contract_data: ledger_key_contract_data, + binary: binary + } do + {:ok, ^binary} = LedgerKeyContractData.encode_xdr(ledger_key_contract_data) + end + + test "encode_xdr!/1", %{ + ledger_key_contract_data: ledger_key_contract_data, + binary: binary + } do + ^binary = LedgerKeyContractData.encode_xdr!(ledger_key_contract_data) + end + + test "decode_xdr/2", %{ + ledger_key_contract_data: ledger_key_contract_data, + binary: binary + } do + {:ok, {^ledger_key_contract_data, ""}} = LedgerKeyContractData.decode_xdr(binary) + end + + test "decode_xdr/2 with an invalid binary" do + {:error, :not_binary} = LedgerKeyContractData.decode_xdr(123) + end + + test "decode_xdr!/2", %{ + ledger_key_contract_data: ledger_key_contract_data, + binary: binary + } do + {^ledger_key_contract_data, ""} = LedgerKeyContractData.decode_xdr!(binary) + end + end +end diff --git a/test/xdr/transactions/contract_id_preimage_from_address_test.exs b/test/xdr/transactions/contract_id_preimage_from_address_test.exs new file mode 100644 index 00000000..c754e2d9 --- /dev/null +++ b/test/xdr/transactions/contract_id_preimage_from_address_test.exs @@ -0,0 +1,88 @@ +defmodule StellarBase.XDR.ContractIDPreimageFromAddressTest do + use ExUnit.Case + + alias StellarBase.XDR.{ + AccountID, + ContractIDPreimageFromAddress, + PublicKey, + PublicKeyType, + SCAddress, + SCAddressType, + UInt256 + } + + alias StellarBase.StrKey + + describe "ContractIDPreimageFromAddress" do + setup do + pk_type = PublicKeyType.new(:PUBLIC_KEY_TYPE_ED25519) + + account_id = + "GBZNLMUQMIN3VGUJISKZU7GNY3O3XLMYEHJCKCSMDHKLGSMKALRXOEZD" + |> StrKey.decode!(:ed25519_public_key) + |> UInt256.new() + |> PublicKey.new(pk_type) + |> AccountID.new() + + sc_address_type = SCAddressType.new(:SC_ADDRESS_TYPE_ACCOUNT) + address = SCAddress.new(account_id, sc_address_type) + + salt = + UInt256.new( + <<72, 101, 108, 108, 111, 32, 119, 111, 114, 108, 100, 0, 21, 0, 1, 0, 72, 101, 108, + 108, 111, 32, 119, 111, 114, 108, 100, 0, 21, 0, 1, 0>> + ) + + %{ + address: address, + salt: salt, + contract_id_preimage_from_address: ContractIDPreimageFromAddress.new(address, salt), + binary: + <<0, 0, 0, 0, 0, 0, 0, 0, 114, 213, 178, 144, 98, 27, 186, 154, 137, 68, 149, 154, 124, + 205, 198, 221, 187, 173, 152, 33, 210, 37, 10, 76, 25, 212, 179, 73, 138, 2, 227, 119, + 72, 101, 108, 108, 111, 32, 119, 111, 114, 108, 100, 0, 21, 0, 1, 0, 72, 101, 108, + 108, 111, 32, 119, 111, 114, 108, 100, 0, 21, 0, 1, 0>> + } + end + + test "new/3", %{address: address, salt: salt} do + %ContractIDPreimageFromAddress{ + address: ^address, + salt: ^salt + } = ContractIDPreimageFromAddress.new(address, salt) + end + + test "encode_xdr/1", %{ + contract_id_preimage_from_address: contract_id_preimage_from_address, + binary: binary + } do + {:ok, ^binary} = ContractIDPreimageFromAddress.encode_xdr(contract_id_preimage_from_address) + end + + test "encode_xdr!/1", %{ + contract_id_preimage_from_address: contract_id_preimage_from_address, + binary: binary + } do + ^binary = ContractIDPreimageFromAddress.encode_xdr!(contract_id_preimage_from_address) + end + + test "decode_xdr/2", %{ + contract_id_preimage_from_address: contract_id_preimage_from_address, + binary: binary + } do + {:ok, {^contract_id_preimage_from_address, ""}} = + ContractIDPreimageFromAddress.decode_xdr(binary) + end + + test "decode_xdr/2 with an invalid binary" do + {:error, :not_binary} = ContractIDPreimageFromAddress.decode_xdr(123) + end + + test "decode_xdr!/2", %{ + contract_id_preimage_from_address: contract_id_preimage_from_address, + binary: binary + } do + {^contract_id_preimage_from_address, ""} = ContractIDPreimageFromAddress.decode_xdr!(binary) + end + end +end diff --git a/test/xdr/transactions/contract_id_preimage_test.exs b/test/xdr/transactions/contract_id_preimage_test.exs new file mode 100644 index 00000000..53044c80 --- /dev/null +++ b/test/xdr/transactions/contract_id_preimage_test.exs @@ -0,0 +1,99 @@ +defmodule StellarBase.XDR.ContractIDPreimageTest do + use ExUnit.Case + + alias StellarBase.XDR.{ + AccountID, + ContractIDPreimage, + ContractIDPreimageType, + ContractIDPreimageFromAddress, + PublicKey, + PublicKeyType, + SCAddress, + SCAddressType, + UInt256 + } + + alias StellarBase.StrKey + + describe "ContractIDPreimage" do + setup do + pk_type = PublicKeyType.new(:PUBLIC_KEY_TYPE_ED25519) + + account_id = + "GBZNLMUQMIN3VGUJISKZU7GNY3O3XLMYEHJCKCSMDHKLGSMKALRXOEZD" + |> StrKey.decode!(:ed25519_public_key) + |> UInt256.new() + |> PublicKey.new(pk_type) + |> AccountID.new() + + sc_address_type = SCAddressType.new(:SC_ADDRESS_TYPE_ACCOUNT) + address = SCAddress.new(account_id, sc_address_type) + + salt = + UInt256.new( + <<72, 101, 108, 108, 111, 32, 119, 111, 114, 108, 100, 0, 21, 0, 1, 0, 72, 101, 108, + 108, 111, 32, 119, 111, 114, 108, 100, 0, 21, 0, 1, 0>> + ) + + contract_id_preimage_from_address = ContractIDPreimageFromAddress.new(address, salt) + type = ContractIDPreimageType.new(:CONTRACT_ID_PREIMAGE_FROM_ADDRESS) + + %{ + contract_id_preimage_from_address: contract_id_preimage_from_address, + type: type, + contract_id_preimage: ContractIDPreimage.new(contract_id_preimage_from_address, type), + binary: + <<0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 114, 213, 178, 144, 98, 27, 186, 154, 137, 68, + 149, 154, 124, 205, 198, 221, 187, 173, 152, 33, 210, 37, 10, 76, 25, 212, 179, 73, + 138, 2, 227, 119, 72, 101, 108, 108, 111, 32, 119, 111, 114, 108, 100, 0, 21, 0, 1, 0, + 72, 101, 108, 108, 111, 32, 119, 111, 114, 108, 100, 0, 21, 0, 1, 0>> + } + end + + test "new/3", %{ + contract_id_preimage_from_address: contract_id_preimage_from_address, + type: type + } do + %ContractIDPreimage{ + value: ^contract_id_preimage_from_address, + type: ^type + } = + ContractIDPreimage.new( + contract_id_preimage_from_address, + type + ) + end + + test "encode_xdr/1", %{ + contract_id_preimage: contract_id_preimage, + binary: binary + } do + {:ok, ^binary} = ContractIDPreimage.encode_xdr(contract_id_preimage) + end + + test "encode_xdr!/1", %{ + contract_id_preimage: contract_id_preimage, + binary: binary + } do + ^binary = ContractIDPreimage.encode_xdr!(contract_id_preimage) + end + + test "decode_xdr/2", %{ + contract_id_preimage: contract_id_preimage, + binary: binary + } do + {:ok, {^contract_id_preimage, ""}} = ContractIDPreimage.decode_xdr(binary) + end + + test "decode_xdr/2 with an invalid binary" do + {:error, :not_binary} = ContractIDPreimage.decode_xdr(123) + end + + test "decode_xdr!/2", %{ + contract_id_preimage: contract_id_preimage, + binary: binary + } do + {^contract_id_preimage, ""} = ContractIDPreimage.decode_xdr!(binary) + end + end +end diff --git a/test/xdr/transactions/hash_id_preimage_contract_id_test.exs b/test/xdr/transactions/hash_id_preimage_contract_id_test.exs new file mode 100644 index 00000000..93e10bd5 --- /dev/null +++ b/test/xdr/transactions/hash_id_preimage_contract_id_test.exs @@ -0,0 +1,110 @@ +defmodule StellarBase.XDR.HashIDPreimageContractIDTest do + use ExUnit.Case + + alias StellarBase.XDR.{ + AccountID, + AlphaNum4, + Asset, + AssetCode4, + AssetType, + ContractIDPreimage, + ContractIDPreimageType, + Hash, + HashIDPreimageContractID, + PublicKey, + PublicKeyType, + UInt256 + } + + alias StellarBase.StrKey + + describe "HashIDPreimageContractID" do + setup do + key_type = PublicKeyType.new(:PUBLIC_KEY_TYPE_ED25519) + + issuer = + "GCNY5OXYSY4FKHOPT2SPOQZAOEIGXB5LBYW3HVU3OWSTQITS65M5RCNY" + |> StrKey.decode!(:ed25519_public_key) + |> UInt256.new() + |> PublicKey.new(key_type) + |> AccountID.new() + + asset_type = AssetType.new(:ASSET_TYPE_CREDIT_ALPHANUM4) + + alpha_num4 = + "BTCN" + |> AssetCode4.new() + |> AlphaNum4.new(issuer) + + asset = Asset.new(alpha_num4, asset_type) + + network_id = + Hash.new( + <<163, 161, 198, 167, 130, 134, 113, 62, 41, 190, 14, 151, 133, 103, 15, 168, 56, 209, + 57, 23, 205, 142, 174, 180, 163, 87, 159, 241, 222, 188, 127, 213>> + ) + + contract_id_preimage = + ContractIDPreimage.new( + asset, + ContractIDPreimageType.new(:CONTRACT_ID_PREIMAGE_FROM_ASSET) + ) + + %{ + network_id: network_id, + contract_id_preimage: contract_id_preimage, + hash_id_preimage_contract_id: + HashIDPreimageContractID.new(network_id, contract_id_preimage), + binary: + <<163, 161, 198, 167, 130, 134, 113, 62, 41, 190, 14, 151, 133, 103, 15, 168, 56, 209, + 57, 23, 205, 142, 174, 180, 163, 87, 159, 241, 222, 188, 127, 213, 0, 0, 0, 1, 0, 0, + 0, 1, 66, 84, 67, 78, 0, 0, 0, 0, 155, 142, 186, 248, 150, 56, 85, 29, 207, 158, 164, + 247, 67, 32, 113, 16, 107, 135, 171, 14, 45, 179, 214, 155, 117, 165, 56, 34, 114, + 247, 89, 216>> + } + end + + test "new/3", %{network_id: network_id, contract_id_preimage: contract_id_preimage} do + %HashIDPreimageContractID{ + network_id: ^network_id, + contract_id_preimage: ^contract_id_preimage + } = + HashIDPreimageContractID.new( + network_id, + contract_id_preimage + ) + end + + test "encode_xdr/1", %{ + hash_id_preimage_contract_id: hash_id_preimage_contract_id, + binary: binary + } do + {:ok, ^binary} = HashIDPreimageContractID.encode_xdr(hash_id_preimage_contract_id) + end + + test "encode_xdr!/1", %{ + hash_id_preimage_contract_id: hash_id_preimage_contract_id, + binary: binary + } do + ^binary = HashIDPreimageContractID.encode_xdr!(hash_id_preimage_contract_id) + end + + test "decode_xdr/2", %{ + hash_id_preimage_contract_id: hash_id_preimage_contract_id, + binary: binary + } do + {:ok, {^hash_id_preimage_contract_id, ""}} = HashIDPreimageContractID.decode_xdr(binary) + end + + test "decode_xdr/2 with an invalid binary" do + {:error, :not_binary} = HashIDPreimageContractID.decode_xdr(123) + end + + test "decode_xdr!/2", %{ + hash_id_preimage_contract_id: hash_id_preimage_contract_id, + binary: binary + } do + {^hash_id_preimage_contract_id, ""} = HashIDPreimageContractID.decode_xdr!(binary) + end + end +end diff --git a/test/xdr/transactions/hash_id_preimage__soroban_authorization_test.exs b/test/xdr/transactions/hash_id_preimage_soroban_authorization_test.exs similarity index 100% rename from test/xdr/transactions/hash_id_preimage__soroban_authorization_test.exs rename to test/xdr/transactions/hash_id_preimage_soroban_authorization_test.exs diff --git a/test/xdr/transactions/operations/account_merge_test.exs b/test/xdr/transactions/operations/account_merge_test.exs deleted file mode 100644 index 4da2590d..00000000 --- a/test/xdr/transactions/operations/account_merge_test.exs +++ /dev/null @@ -1,51 +0,0 @@ -defmodule StellarBase.XDR.Operations.AccountMergeTest do - use ExUnit.Case - - alias StellarBase.XDR.{CryptoKeyType, MuxedAccount, UInt256} - alias StellarBase.XDR.Operations.AccountMerge - alias StellarBase.StrKey - - describe "AccountMerge Operation" do - setup do - muxed_account = - "GCNY5OXYSY4FKHOPT2SPOQZAOEIGXB5LBYW3HVU3OWSTQITS65M5RCNY" - |> StrKey.decode!(:ed25519_public_key) - |> UInt256.new() - |> MuxedAccount.new(CryptoKeyType.new(:KEY_TYPE_ED25519)) - - account_merge = AccountMerge.new(muxed_account) - - %{ - account: muxed_account, - account_merge: account_merge, - binary: - <<0, 0, 0, 0, 155, 142, 186, 248, 150, 56, 85, 29, 207, 158, 164, 247, 67, 32, 113, 16, - 107, 135, 171, 14, 45, 179, 214, 155, 117, 165, 56, 34, 114, 247, 89, 216>> - } - end - - test "new/1", %{account: muxed_account} do - %AccountMerge{account: ^muxed_account} = AccountMerge.new(muxed_account) - end - - test "encode_xdr/1", %{account_merge: account_merge, binary: binary} do - {:ok, ^binary} = AccountMerge.encode_xdr(account_merge) - end - - test "encode_xdr!/1", %{account_merge: account_merge, binary: binary} do - ^binary = AccountMerge.encode_xdr!(account_merge) - end - - test "decode_xdr/2", %{account_merge: account_merge, binary: binary} do - {:ok, {^account_merge, ""}} = AccountMerge.decode_xdr(binary) - end - - test "decode_xdr/2 with an invalid binary" do - {:error, :not_binary} = AccountMerge.decode_xdr(123) - end - - test "decode_xdr!/2", %{account_merge: account_merge, binary: binary} do - {^account_merge, ^binary} = AccountMerge.decode_xdr!(binary <> binary) - end - end -end diff --git a/test/xdr/transactions/operations/bump_footprint_expiration_result_code_test.exs b/test/xdr/transactions/operations/bump_footprint_expiration_result_code_test.exs new file mode 100644 index 00000000..048b3ee1 --- /dev/null +++ b/test/xdr/transactions/operations/bump_footprint_expiration_result_code_test.exs @@ -0,0 +1,72 @@ +defmodule StellarBase.XDR.BumpFootprintExpirationResultCodeTest do + use ExUnit.Case + + alias StellarBase.XDR.BumpFootprintExpirationResultCode + + @codes [ + :BUMP_FOOTPRINT_EXPIRATION_SUCCESS, + :BUMP_FOOTPRINT_EXPIRATION_MALFORMED, + :BUMP_FOOTPRINT_EXPIRATION_RESOURCE_LIMIT_EXCEEDED + ] + + @binaries [ + <<0, 0, 0, 0>>, + <<255, 255, 255, 255>>, + <<255, 255, 255, 254>> + ] + + describe "BumpFootprintExpirationResultCode" do + setup do + %{ + codes: @codes, + results: @codes |> Enum.map(fn code -> BumpFootprintExpirationResultCode.new(code) end), + binaries: @binaries + } + end + + test "new/1", %{codes: types} do + for type <- types, + do: + %BumpFootprintExpirationResultCode{identifier: ^type} = + BumpFootprintExpirationResultCode.new(type) + end + + test "encode_xdr/1", %{results: results, binaries: binaries} do + for {result, binary} <- Enum.zip(results, binaries), + do: {:ok, ^binary} = BumpFootprintExpirationResultCode.encode_xdr(result) + end + + test "encode_xdr/1 with an invalid code" do + {:error, :invalid_key} = + BumpFootprintExpirationResultCode.encode_xdr(%BumpFootprintExpirationResultCode{ + identifier: :TEST + }) + end + + test "encode_xdr!/1", %{results: results, binaries: binaries} do + for {result, binary} <- Enum.zip(results, binaries), + do: ^binary = BumpFootprintExpirationResultCode.encode_xdr!(result) + end + + test "decode_xdr/2", %{results: results, binaries: binaries} do + for {result, binary} <- Enum.zip(results, binaries), + do: {:ok, {^result, ""}} = BumpFootprintExpirationResultCode.decode_xdr(binary) + end + + test "decode_xdr/2 with an invalid declaration" do + {:error, :invalid_key} = BumpFootprintExpirationResultCode.decode_xdr(<<1, 0, 0, 1>>) + end + + test "decode_xdr!/2", %{results: results, binaries: binaries} do + for {result, binary} <- Enum.zip(results, binaries), + do: {^result, ^binary} = BumpFootprintExpirationResultCode.decode_xdr!(binary <> binary) + end + + test "decode_xdr!/2 with an error code", %{binaries: binaries} do + for binary <- binaries, + do: + {%BumpFootprintExpirationResultCode{identifier: _}, ""} = + BumpFootprintExpirationResultCode.decode_xdr!(binary) + end + end +end diff --git a/test/xdr/transactions/operations/bump_footprint_expiration_result_test.exs b/test/xdr/transactions/operations/bump_footprint_expiration_result_test.exs new file mode 100644 index 00000000..b2f2dc9f --- /dev/null +++ b/test/xdr/transactions/operations/bump_footprint_expiration_result_test.exs @@ -0,0 +1,57 @@ +defmodule StellarBase.XDR.BumpFootprintExpirationResultTest do + use ExUnit.Case + + alias StellarBase.XDR.Void + alias StellarBase.XDR.{BumpFootprintExpirationResult, BumpFootprintExpirationResultCode} + + describe "BumpFootprintExpirationResult" do + setup do + type = BumpFootprintExpirationResultCode.new(:BUMP_FOOTPRINT_EXPIRATION_SUCCESS) + + %{ + type: type, + value: Void.new(), + result: BumpFootprintExpirationResult.new(Void.new(), type), + binary: <<0, 0, 0, 0>> + } + end + + test "new/1", %{type: type, value: value} do + %BumpFootprintExpirationResult{type: ^type, value: ^value} = + BumpFootprintExpirationResult.new(value, type) + end + + test "encode_xdr/1", %{result: result, binary: binary} do + {:ok, ^binary} = BumpFootprintExpirationResult.encode_xdr(result) + end + + test "encode_xdr!/1", %{result: result, binary: binary} do + ^binary = BumpFootprintExpirationResult.encode_xdr!(result) + end + + test "encode_xdr!/1 with a default value", %{type: type, binary: binary} do + result = BumpFootprintExpirationResult.new("TEST", type) + ^binary = BumpFootprintExpirationResult.encode_xdr!(result) + end + + test "decode_xdr/2", %{result: result, binary: binary} do + {:ok, {^result, ""}} = BumpFootprintExpirationResult.decode_xdr(binary) + end + + test "decode_xdr!/2", %{result: result, binary: binary} do + {^result, ^binary} = BumpFootprintExpirationResult.decode_xdr!(binary <> binary) + end + + test "decode_xdr!/2 an error type" do + {%BumpFootprintExpirationResult{ + type: %BumpFootprintExpirationResultCode{ + identifier: :BUMP_FOOTPRINT_EXPIRATION_MALFORMED + } + }, ""} = BumpFootprintExpirationResult.decode_xdr!(<<255, 255, 255, 255>>) + end + + test "decode_xdr/2 with an invalid binary" do + {:error, :not_binary} = BumpFootprintExpirationResult.decode_xdr(123) + end + end +end diff --git a/test/xdr/transactions/operations/bump_footprint_expiration_test.exs b/test/xdr/transactions/operations/bump_footprint_expiration_test.exs new file mode 100644 index 00000000..c773d64c --- /dev/null +++ b/test/xdr/transactions/operations/bump_footprint_expiration_test.exs @@ -0,0 +1,51 @@ +defmodule StellarBase.XDR.Operations.BumpFootprintExpirationTest do + use ExUnit.Case + + alias StellarBase.XDR.{ + ExtensionPoint, + Operations.BumpFootprintExpiration, + UInt32, + Void + } + + describe "BumpFootprintExpiration Operation" do + setup do + ext = ExtensionPoint.new(Void.new(), 0) + ledgers_to_expire = UInt32.new(105_255) + + %{ + ext: ext, + ledgers_to_expire: ledgers_to_expire, + bump_footprint_exp: BumpFootprintExpiration.new(ext, ledgers_to_expire), + binary: <<0, 0, 0, 0, 0, 1, 155, 39>> + } + end + + test "new/1", %{ext: ext, ledgers_to_expire: ledgers_to_expire} do + %BumpFootprintExpiration{ + ext: ^ext, + ledgers_to_expire: ^ledgers_to_expire + } = BumpFootprintExpiration.new(ext, ledgers_to_expire) + end + + test "encode_xdr/1", %{bump_footprint_exp: bump_footprint_exp, binary: binary} do + {:ok, ^binary} = BumpFootprintExpiration.encode_xdr(bump_footprint_exp) + end + + test "encode_xdr!/1", %{bump_footprint_exp: bump_footprint_exp, binary: binary} do + ^binary = BumpFootprintExpiration.encode_xdr!(bump_footprint_exp) + end + + test "decode_xdr/2", %{bump_footprint_exp: bump_footprint_exp, binary: binary} do + {:ok, {^bump_footprint_exp, ""}} = BumpFootprintExpiration.decode_xdr(binary) + end + + test "decode_xdr/2 with an invalid binary" do + {:error, :not_binary} = BumpFootprintExpiration.decode_xdr(123) + end + + test "decode_xdr!/2", %{bump_footprint_exp: bump_footprint_exp, binary: binary} do + {^bump_footprint_exp, ^binary} = BumpFootprintExpiration.decode_xdr!(binary <> binary) + end + end +end diff --git a/test/xdr/transactions/operations/restore_footprint_result_code_test.exs b/test/xdr/transactions/operations/restore_footprint_result_code_test.exs new file mode 100644 index 00000000..1e64c9d7 --- /dev/null +++ b/test/xdr/transactions/operations/restore_footprint_result_code_test.exs @@ -0,0 +1,71 @@ +defmodule StellarBase.XDR.RestoreFootprintResultCodeTest do + use ExUnit.Case + + alias StellarBase.XDR.RestoreFootprintResultCode + + @codes [ + :RESTORE_FOOTPRINT_SUCCESS, + :RESTORE_FOOTPRINT_MALFORMED, + :RESTORE_FOOTPRINT_RESOURCE_LIMIT_EXCEEDED + ] + + @binaries [ + <<0, 0, 0, 0>>, + <<255, 255, 255, 255>>, + <<255, 255, 255, 254>> + ] + + describe "RestoreFootprintResultCode" do + setup do + %{ + codes: @codes, + results: @codes |> Enum.map(fn code -> RestoreFootprintResultCode.new(code) end), + binaries: @binaries + } + end + + test "new/1", %{codes: types} do + for type <- types, + do: + %RestoreFootprintResultCode{identifier: ^type} = RestoreFootprintResultCode.new(type) + end + + test "encode_xdr/1", %{results: results, binaries: binaries} do + for {result, binary} <- Enum.zip(results, binaries), + do: {:ok, ^binary} = RestoreFootprintResultCode.encode_xdr(result) + end + + test "encode_xdr/1 with an invalid code" do + {:error, :invalid_key} = + RestoreFootprintResultCode.encode_xdr(%RestoreFootprintResultCode{ + identifier: :TEST + }) + end + + test "encode_xdr!/1", %{results: results, binaries: binaries} do + for {result, binary} <- Enum.zip(results, binaries), + do: ^binary = RestoreFootprintResultCode.encode_xdr!(result) + end + + test "decode_xdr/2", %{results: results, binaries: binaries} do + for {result, binary} <- Enum.zip(results, binaries), + do: {:ok, {^result, ""}} = RestoreFootprintResultCode.decode_xdr(binary) + end + + test "decode_xdr/2 with an invalid declaration" do + {:error, :invalid_key} = RestoreFootprintResultCode.decode_xdr(<<1, 0, 0, 1>>) + end + + test "decode_xdr!/2", %{results: results, binaries: binaries} do + for {result, binary} <- Enum.zip(results, binaries), + do: {^result, ^binary} = RestoreFootprintResultCode.decode_xdr!(binary <> binary) + end + + test "decode_xdr!/2 with an error code", %{binaries: binaries} do + for binary <- binaries, + do: + {%RestoreFootprintResultCode{identifier: _}, ""} = + RestoreFootprintResultCode.decode_xdr!(binary) + end + end +end diff --git a/test/xdr/transactions/operations/restore_footprint_result_test.exs b/test/xdr/transactions/operations/restore_footprint_result_test.exs new file mode 100644 index 00000000..bb825a89 --- /dev/null +++ b/test/xdr/transactions/operations/restore_footprint_result_test.exs @@ -0,0 +1,55 @@ +defmodule StellarBase.XDR.RestoreFootprintResultTest do + use ExUnit.Case + + alias StellarBase.XDR.Void + alias StellarBase.XDR.{RestoreFootprintResult, RestoreFootprintResultCode} + + describe "RestoreFootprintResult" do + setup do + type = RestoreFootprintResultCode.new(:RESTORE_FOOTPRINT_SUCCESS) + + %{ + type: type, + value: Void.new(), + result: RestoreFootprintResult.new(Void.new(), type), + binary: <<0, 0, 0, 0>> + } + end + + test "new/1", %{type: type, value: value} do + %RestoreFootprintResult{type: ^type, value: ^value} = + RestoreFootprintResult.new(value, type) + end + + test "encode_xdr/1", %{result: result, binary: binary} do + {:ok, ^binary} = RestoreFootprintResult.encode_xdr(result) + end + + test "encode_xdr!/1", %{result: result, binary: binary} do + ^binary = RestoreFootprintResult.encode_xdr!(result) + end + + test "encode_xdr!/1 with a default value", %{type: type, binary: binary} do + result = RestoreFootprintResult.new("TEST", type) + ^binary = RestoreFootprintResult.encode_xdr!(result) + end + + test "decode_xdr/2", %{result: result, binary: binary} do + {:ok, {^result, ""}} = RestoreFootprintResult.decode_xdr(binary) + end + + test "decode_xdr!/2", %{result: result, binary: binary} do + {^result, ^binary} = RestoreFootprintResult.decode_xdr!(binary <> binary) + end + + test "decode_xdr!/2 an error type" do + {%RestoreFootprintResult{ + type: %RestoreFootprintResultCode{identifier: :RESTORE_FOOTPRINT_MALFORMED} + }, ""} = RestoreFootprintResult.decode_xdr!(<<255, 255, 255, 255>>) + end + + test "decode_xdr/2 with an invalid binary" do + {:error, :not_binary} = RestoreFootprintResult.decode_xdr(123) + end + end +end diff --git a/test/xdr/transactions/operations/restore_footprint_test.exs b/test/xdr/transactions/operations/restore_footprint_test.exs new file mode 100644 index 00000000..9ea812b9 --- /dev/null +++ b/test/xdr/transactions/operations/restore_footprint_test.exs @@ -0,0 +1,47 @@ +defmodule StellarBase.XDR.Operations.RestoreFootprintTest do + use ExUnit.Case + + alias StellarBase.XDR.{ + ExtensionPoint, + Operations.RestoreFootprint, + Void + } + + describe "RestoreFootprint Operation" do + setup do + ext = ExtensionPoint.new(Void.new(), 0) + + %{ + ext: ext, + restore_footprint: RestoreFootprint.new(ext), + binary: <<0, 0, 0, 0>> + } + end + + test "new/1", %{ext: ext} do + %RestoreFootprint{ + ext: ^ext + } = RestoreFootprint.new(ext) + end + + test "encode_xdr/1", %{restore_footprint: restore_footprint, binary: binary} do + {:ok, ^binary} = RestoreFootprint.encode_xdr(restore_footprint) + end + + test "encode_xdr!/1", %{restore_footprint: restore_footprint, binary: binary} do + ^binary = RestoreFootprint.encode_xdr!(restore_footprint) + end + + test "decode_xdr/2", %{restore_footprint: restore_footprint, binary: binary} do + {:ok, {^restore_footprint, ""}} = RestoreFootprint.decode_xdr(binary) + end + + test "decode_xdr/2 with an invalid binary" do + {:error, :not_binary} = RestoreFootprint.decode_xdr(123) + end + + test "decode_xdr!/2", %{restore_footprint: restore_footprint, binary: binary} do + {^restore_footprint, ^binary} = RestoreFootprint.decode_xdr!(binary <> binary) + end + end +end diff --git a/test/xdr/transactions/operations/revoke_sponsorship_op_signer_test.exs b/test/xdr/transactions/operations/revoke_sponsorship_op_signer_test.exs new file mode 100644 index 00000000..51ed676b --- /dev/null +++ b/test/xdr/transactions/operations/revoke_sponsorship_op_signer_test.exs @@ -0,0 +1,89 @@ +defmodule StellarBase.XDR.RevokeSponsorshipOpSignerTest do + use ExUnit.Case + + alias StellarBase.XDR.{ + AccountID, + RevokeSponsorshipOpSigner, + PublicKey, + PublicKeyType, + SignerKey, + SignerKeyType, + UInt256 + } + + describe "RevokeSponsorshipOpSigner" do + setup do + signer_key = %UInt256{ + datum: + <<18, 27, 249, 51, 160, 215, 152, 50, 153, 222, 53, 177, 115, 224, 92, 243, 51, 242, + 249, 40, 118, 78, 128, 109, 86, 239, 171, 232, 42, 171, 210, 35>> + } + + public_key = %PublicKey{ + public_key: signer_key, + type: %PublicKeyType{ + identifier: :PUBLIC_KEY_TYPE_ED25519 + } + } + + key_type = SignerKeyType.new(:SIGNER_KEY_TYPE_PRE_AUTH_TX) + account_id = AccountID.new(public_key) + signer_key = SignerKey.new(signer_key, key_type) + + %{ + account_id: account_id, + signer_key: signer_key, + revoke_sponsorship_op_signer: RevokeSponsorshipOpSigner.new(account_id, signer_key), + binary: + <<0, 0, 0, 0, 18, 27, 249, 51, 160, 215, 152, 50, 153, 222, 53, 177, 115, 224, 92, 243, + 51, 242, 249, 40, 118, 78, 128, 109, 86, 239, 171, 232, 42, 171, 210, 35, 0, 0, 0, 1, + 18, 27, 249, 51, 160, 215, 152, 50, 153, 222, 53, 177, 115, 224, 92, 243, 51, 242, + 249, 40, 118, 78, 128, 109, 86, 239, 171, 232, 42, 171, 210, 35>> + } + end + + test "new/1", %{account_id: account_id, signer_key: signer_key} do + %RevokeSponsorshipOpSigner{ + account_id: ^account_id, + signer_key: ^signer_key + } = + RevokeSponsorshipOpSigner.new( + account_id, + signer_key + ) + end + + test "encode_xdr/1", %{ + revoke_sponsorship_op_signer: revoke_sponsorship_op_signer, + binary: binary + } do + {:ok, ^binary} = RevokeSponsorshipOpSigner.encode_xdr(revoke_sponsorship_op_signer) + end + + test "encode_xdr!/1", %{ + revoke_sponsorship_op_signer: revoke_sponsorship_op_signer, + binary: binary + } do + ^binary = RevokeSponsorshipOpSigner.encode_xdr!(revoke_sponsorship_op_signer) + end + + test "decode_xdr/2", %{ + revoke_sponsorship_op_signer: revoke_sponsorship_op_signer, + binary: binary + } do + {:ok, {^revoke_sponsorship_op_signer, ""}} = RevokeSponsorshipOpSigner.decode_xdr(binary) + end + + test "decode_xdr/2 with an invalid binary" do + {:error, :not_binary} = RevokeSponsorshipOpSigner.decode_xdr(123) + end + + test "decode_xdr!/2", %{ + revoke_sponsorship_op_signer: revoke_sponsorship_op_signer, + binary: binary + } do + {^revoke_sponsorship_op_signer, ^binary} = + RevokeSponsorshipOpSigner.decode_xdr!(binary <> binary) + end + end +end diff --git a/test/xdr/transactions/soroban_address_credentials_test.exs b/test/xdr/transactions/soroban_address_credentials_test.exs new file mode 100644 index 00000000..ac9143bc --- /dev/null +++ b/test/xdr/transactions/soroban_address_credentials_test.exs @@ -0,0 +1,115 @@ +defmodule StellarBase.XDR.SorobanAddressCredentialsTest do + use ExUnit.Case + + alias StellarBase.XDR.{ + AccountID, + Int64, + PublicKey, + PublicKeyType, + SCAddress, + SCAddressType, + SCVal, + SCValType, + SCVec, + SorobanAddressCredentials, + UInt32, + UInt256 + } + + alias StellarBase.StrKey + + describe "SorobanAddressCredentials" do + setup do + pk_type = PublicKeyType.new(:PUBLIC_KEY_TYPE_ED25519) + + account_id = + "GBZNLMUQMIN3VGUJISKZU7GNY3O3XLMYEHJCKCSMDHKLGSMKALRXOEZD" + |> StrKey.decode!(:ed25519_public_key) + |> UInt256.new() + |> PublicKey.new(pk_type) + |> AccountID.new() + + sc_address_type = SCAddressType.new(:SC_ADDRESS_TYPE_ACCOUNT) + + scval1 = SCVal.new(Int64.new(3), SCValType.new(:SCV_I64)) + scval2 = SCVal.new(Int64.new(2), SCValType.new(:SCV_I64)) + + sc_vals = [scval1, scval2] + + address = SCAddress.new(account_id, sc_address_type) + nonce = Int64.new(123_155) + signature_expiration_ledger = UInt32.new(4_646_545) + + signature_args = SCVec.new(sc_vals) + + soroban_address_credentials = + SorobanAddressCredentials.new(address, nonce, signature_expiration_ledger, signature_args) + + %{ + address: address, + nonce: nonce, + signature_expiration_ledger: signature_expiration_ledger, + signature_args: signature_args, + soroban_address_credentials: soroban_address_credentials, + binary: + <<0, 0, 0, 0, 0, 0, 0, 0, 114, 213, 178, 144, 98, 27, 186, 154, 137, 68, 149, 154, 124, + 205, 198, 221, 187, 173, 152, 33, 210, 37, 10, 76, 25, 212, 179, 73, 138, 2, 227, 119, + 0, 0, 0, 0, 0, 1, 225, 19, 0, 70, 230, 145, 0, 0, 0, 2, 0, 0, 0, 6, 0, 0, 0, 0, 0, 0, + 0, 3, 0, 0, 0, 6, 0, 0, 0, 0, 0, 0, 0, 2>> + } + end + + test "new/1", %{ + address: address, + nonce: nonce, + signature_expiration_ledger: signature_expiration_ledger, + signature_args: signature_args + } do + %SorobanAddressCredentials{ + address: ^address, + nonce: ^nonce, + signature_expiration_ledger: ^signature_expiration_ledger, + signature_args: ^signature_args + } = + SorobanAddressCredentials.new( + address, + nonce, + signature_expiration_ledger, + signature_args + ) + end + + test "encode_xdr/1", %{ + soroban_address_credentials: soroban_address_credentials, + binary: binary + } do + {:ok, ^binary} = SorobanAddressCredentials.encode_xdr(soroban_address_credentials) + end + + test "encode_xdr!/1", %{ + soroban_address_credentials: soroban_address_credentials, + binary: binary + } do + ^binary = SorobanAddressCredentials.encode_xdr!(soroban_address_credentials) + end + + test "decode_xdr/2", %{ + soroban_address_credentials: soroban_address_credentials, + binary: binary + } do + {:ok, {^soroban_address_credentials, ""}} = SorobanAddressCredentials.decode_xdr(binary) + end + + test "decode_xdr/2 with an invalid binary" do + {:error, :not_binary} = SorobanAddressCredentials.decode_xdr(123) + end + + test "decode_xdr!/2", %{ + soroban_address_credentials: soroban_address_credentials, + binary: binary + } do + {^soroban_address_credentials, ^binary} = + SorobanAddressCredentials.decode_xdr!(binary <> binary) + end + end +end diff --git a/test/xdr/transactions/soroban_authorization_entry_list_test.exs b/test/xdr/transactions/soroban_authorization_entry_list_test.exs new file mode 100644 index 00000000..4739a45d --- /dev/null +++ b/test/xdr/transactions/soroban_authorization_entry_list_test.exs @@ -0,0 +1,130 @@ +defmodule StellarBase.XDR.SorobanAuthorizationEntryListTest do + use ExUnit.Case + + alias StellarBase.XDR.{ + AccountID, + Int64, + PublicKey, + PublicKeyType, + SCAddress, + SCAddressType, + SCAddress, + SCSymbol, + SCVal, + SCValType, + SCVec, + SorobanAuthorizedInvocation, + SorobanAuthorizedInvocationList, + SorobanAuthorizationEntry, + SorobanAuthorizationEntryList, + SorobanAuthorizedFunction, + SorobanAuthorizedFunctionType, + SorobanAuthorizedContractFunction, + SorobanCredentials, + SorobanCredentialsType, + UInt256, + Void + } + + alias StellarBase.StrKey + + describe "SorobanAuthorizationEntry" do + setup do + pk_type = PublicKeyType.new(:PUBLIC_KEY_TYPE_ED25519) + + account_id = + "GBZNLMUQMIN3VGUJISKZU7GNY3O3XLMYEHJCKCSMDHKLGSMKALRXOEZD" + |> StrKey.decode!(:ed25519_public_key) + |> UInt256.new() + |> PublicKey.new(pk_type) + |> AccountID.new() + + sc_address_type = SCAddressType.new(:SC_ADDRESS_TYPE_ACCOUNT) + + contract_address = SCAddress.new(account_id, sc_address_type) + function_name = SCSymbol.new("Hello") + scval1 = SCVal.new(Int64.new(3), SCValType.new(:SCV_I64)) + scval2 = SCVal.new(Int64.new(2), SCValType.new(:SCV_I64)) + + sc_vals = [scval1, scval2] + + args = SCVec.new(sc_vals) + + soroban_auth_contract_function = + SorobanAuthorizedContractFunction.new(contract_address, function_name, args) + + function = + SorobanAuthorizedFunction.new( + soroban_auth_contract_function, + SorobanAuthorizedFunctionType.new(:SOROBAN_AUTHORIZED_FUNCTION_TYPE_CONTRACT_FN) + ) + + sub_invocations = SorobanAuthorizedInvocationList.new([]) + root_invocation = SorobanAuthorizedInvocation.new(function, sub_invocations) + + soroban_credentials = + SorobanCredentials.new( + Void.new(), + SorobanCredentialsType.new(:SOROBAN_CREDENTIALS_SOURCE_ACCOUNT) + ) + + soroban_authorization_entries = [ + SorobanAuthorizationEntry.new(soroban_credentials, root_invocation) + ] + + %{ + soroban_authorization_entries: soroban_authorization_entries, + soroban_authorization_entry_list: + SorobanAuthorizationEntryList.new(soroban_authorization_entries), + binary: + <<0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 114, 213, 178, 144, 98, + 27, 186, 154, 137, 68, 149, 154, 124, 205, 198, 221, 187, 173, 152, 33, 210, 37, 10, + 76, 25, 212, 179, 73, 138, 2, 227, 119, 0, 0, 0, 5, 72, 101, 108, 108, 111, 0, 0, 0, + 0, 0, 0, 2, 0, 0, 0, 6, 0, 0, 0, 0, 0, 0, 0, 3, 0, 0, 0, 6, 0, 0, 0, 0, 0, 0, 0, 2, 0, + 0, 0, 0>> + } + end + + test "new/1", %{ + soroban_authorization_entries: soroban_authorization_entries + } do + %SorobanAuthorizationEntryList{ + items: ^soroban_authorization_entries + } = SorobanAuthorizationEntryList.new(soroban_authorization_entries) + end + + test "encode_xdr/1", %{ + soroban_authorization_entry_list: soroban_authorization_entry_list, + binary: binary + } do + {:ok, ^binary} = SorobanAuthorizationEntryList.encode_xdr(soroban_authorization_entry_list) + end + + test "encode_xdr!/1", %{ + soroban_authorization_entry_list: soroban_authorization_entry_list, + binary: binary + } do + ^binary = SorobanAuthorizationEntryList.encode_xdr!(soroban_authorization_entry_list) + end + + test "decode_xdr/2", %{ + soroban_authorization_entry_list: soroban_authorization_entry_list, + binary: binary + } do + {:ok, {^soroban_authorization_entry_list, ""}} = + SorobanAuthorizationEntryList.decode_xdr(binary) + end + + test "decode_xdr/2 with an invalid binary" do + {:error, :not_binary} = SorobanAuthorizationEntryList.decode_xdr(123) + end + + test "decode_xdr!/2", %{ + soroban_authorization_entry_list: soroban_authorization_entry_list, + binary: binary + } do + {^soroban_authorization_entry_list, ^binary} = + SorobanAuthorizationEntryList.decode_xdr!(binary <> binary) + end + end +end diff --git a/test/xdr/transactions/soroban_authorization_entry_test.exs b/test/xdr/transactions/soroban_authorization_entry_test.exs new file mode 100644 index 00000000..be78949b --- /dev/null +++ b/test/xdr/transactions/soroban_authorization_entry_test.exs @@ -0,0 +1,130 @@ +defmodule StellarBase.XDR.SorobanAuthorizationEntryTest do + use ExUnit.Case + + alias StellarBase.XDR.{ + AccountID, + Int64, + PublicKey, + PublicKeyType, + SCAddress, + SCAddressType, + SCAddress, + SCSymbol, + SCVal, + SCValType, + SCVec, + SorobanAuthorizedInvocation, + SorobanAuthorizedInvocationList, + SorobanAuthorizationEntry, + SorobanAuthorizedFunction, + SorobanAuthorizedFunctionType, + SorobanAuthorizedContractFunction, + SorobanCredentials, + SorobanCredentialsType, + UInt256, + Void + } + + alias StellarBase.StrKey + + describe "SorobanAuthorizationEntry" do + setup do + pk_type = PublicKeyType.new(:PUBLIC_KEY_TYPE_ED25519) + + account_id = + "GBZNLMUQMIN3VGUJISKZU7GNY3O3XLMYEHJCKCSMDHKLGSMKALRXOEZD" + |> StrKey.decode!(:ed25519_public_key) + |> UInt256.new() + |> PublicKey.new(pk_type) + |> AccountID.new() + + sc_address_type = SCAddressType.new(:SC_ADDRESS_TYPE_ACCOUNT) + + contract_address = SCAddress.new(account_id, sc_address_type) + function_name = SCSymbol.new("Hello") + scval1 = SCVal.new(Int64.new(3), SCValType.new(:SCV_I64)) + scval2 = SCVal.new(Int64.new(2), SCValType.new(:SCV_I64)) + + sc_vals = [scval1, scval2] + + args = SCVec.new(sc_vals) + + soroban_auth_contract_function = + SorobanAuthorizedContractFunction.new(contract_address, function_name, args) + + function = + SorobanAuthorizedFunction.new( + soroban_auth_contract_function, + SorobanAuthorizedFunctionType.new(:SOROBAN_AUTHORIZED_FUNCTION_TYPE_CONTRACT_FN) + ) + + sub_invocations = SorobanAuthorizedInvocationList.new([]) + root_invocation = SorobanAuthorizedInvocation.new(function, sub_invocations) + + soroban_credentials = + SorobanCredentials.new( + Void.new(), + SorobanCredentialsType.new(:SOROBAN_CREDENTIALS_SOURCE_ACCOUNT) + ) + + %{ + soroban_credentials: soroban_credentials, + root_invocation: root_invocation, + soroban_authorization_entry: + SorobanAuthorizationEntry.new(soroban_credentials, root_invocation), + binary: + <<0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 114, 213, 178, 144, 98, 27, 186, 154, + 137, 68, 149, 154, 124, 205, 198, 221, 187, 173, 152, 33, 210, 37, 10, 76, 25, 212, + 179, 73, 138, 2, 227, 119, 0, 0, 0, 5, 72, 101, 108, 108, 111, 0, 0, 0, 0, 0, 0, 2, 0, + 0, 0, 6, 0, 0, 0, 0, 0, 0, 0, 3, 0, 0, 0, 6, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0>> + } + end + + test "new/1", %{ + soroban_credentials: soroban_credentials, + root_invocation: root_invocation + } do + %SorobanAuthorizationEntry{ + credentials: ^soroban_credentials, + root_invocation: ^root_invocation + } = + SorobanAuthorizationEntry.new( + soroban_credentials, + root_invocation + ) + end + + test "encode_xdr/1", %{ + soroban_authorization_entry: soroban_authorization_entry, + binary: binary + } do + {:ok, ^binary} = SorobanAuthorizationEntry.encode_xdr(soroban_authorization_entry) + end + + test "encode_xdr!/1", %{ + soroban_authorization_entry: soroban_authorization_entry, + binary: binary + } do + ^binary = SorobanAuthorizationEntry.encode_xdr!(soroban_authorization_entry) + end + + test "decode_xdr/2", %{ + soroban_authorization_entry: soroban_authorization_entry, + binary: binary + } do + {:ok, {^soroban_authorization_entry, ""}} = SorobanAuthorizationEntry.decode_xdr(binary) + end + + test "decode_xdr/2 with an invalid binary" do + {:error, :not_binary} = SorobanAuthorizationEntry.decode_xdr(123) + end + + test "decode_xdr!/2", %{ + soroban_authorization_entry: soroban_authorization_entry, + binary: binary + } do + {^soroban_authorization_entry, ^binary} = + SorobanAuthorizationEntry.decode_xdr!(binary <> binary) + end + end +end diff --git a/test/xdr/transactions/soroban_authorized_contract_function_test.exs b/test/xdr/transactions/soroban_authorized_contract_function_test.exs new file mode 100644 index 00000000..8d85658a --- /dev/null +++ b/test/xdr/transactions/soroban_authorized_contract_function_test.exs @@ -0,0 +1,112 @@ +defmodule StellarBase.XDR.SorobanAuthorizedContractFunctionTest do + use ExUnit.Case + + alias StellarBase.XDR.{ + AccountID, + Int64, + PublicKey, + PublicKeyType, + SCAddress, + SCAddressType, + SCAddress, + SCSymbol, + SCVal, + SCValType, + SCVec, + SorobanAuthorizedContractFunction, + SorobanAuthorizedContractFunction, + UInt256 + } + + alias StellarBase.StrKey + + describe "SorobanAuthorizedContractFunction" do + setup do + pk_type = PublicKeyType.new(:PUBLIC_KEY_TYPE_ED25519) + + account_id = + "GBZNLMUQMIN3VGUJISKZU7GNY3O3XLMYEHJCKCSMDHKLGSMKALRXOEZD" + |> StrKey.decode!(:ed25519_public_key) + |> UInt256.new() + |> PublicKey.new(pk_type) + |> AccountID.new() + + sc_address_type = SCAddressType.new(:SC_ADDRESS_TYPE_ACCOUNT) + + contract_address = SCAddress.new(account_id, sc_address_type) + function_name = SCSymbol.new("Hello") + scval1 = SCVal.new(Int64.new(3), SCValType.new(:SCV_I64)) + scval2 = SCVal.new(Int64.new(2), SCValType.new(:SCV_I64)) + + sc_vals = [scval1, scval2] + + args = SCVec.new(sc_vals) + + %{ + contract_address: contract_address, + function_name: function_name, + args: args, + soroban_authorized_contract_function: + SorobanAuthorizedContractFunction.new(contract_address, function_name, args), + binary: + <<0, 0, 0, 0, 0, 0, 0, 0, 114, 213, 178, 144, 98, 27, 186, 154, 137, 68, 149, 154, 124, + 205, 198, 221, 187, 173, 152, 33, 210, 37, 10, 76, 25, 212, 179, 73, 138, 2, 227, 119, + 0, 0, 0, 5, 72, 101, 108, 108, 111, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 6, 0, 0, 0, 0, 0, 0, + 0, 3, 0, 0, 0, 6, 0, 0, 0, 0, 0, 0, 0, 2>> + } + end + + test "new/1", %{ + contract_address: contract_address, + function_name: function_name, + args: args + } do + %SorobanAuthorizedContractFunction{ + contract_address: ^contract_address, + function_name: ^function_name, + args: ^args + } = + SorobanAuthorizedContractFunction.new( + contract_address, + function_name, + args + ) + end + + test "encode_xdr/1", %{ + soroban_authorized_contract_function: soroban_authorized_contract_function, + binary: binary + } do + {:ok, ^binary} = + SorobanAuthorizedContractFunction.encode_xdr(soroban_authorized_contract_function) + end + + test "encode_xdr!/1", %{ + soroban_authorized_contract_function: soroban_authorized_contract_function, + binary: binary + } do + ^binary = + SorobanAuthorizedContractFunction.encode_xdr!(soroban_authorized_contract_function) + end + + test "decode_xdr/2", %{ + soroban_authorized_contract_function: soroban_authorized_contract_function, + binary: binary + } do + {:ok, {^soroban_authorized_contract_function, ""}} = + SorobanAuthorizedContractFunction.decode_xdr(binary) + end + + test "decode_xdr/2 with an invalid binary" do + {:error, :not_binary} = SorobanAuthorizedContractFunction.decode_xdr(123) + end + + test "decode_xdr!/2", %{ + soroban_authorized_contract_function: soroban_authorized_contract_function, + binary: binary + } do + {^soroban_authorized_contract_function, ^binary} = + SorobanAuthorizedContractFunction.decode_xdr!(binary <> binary) + end + end +end diff --git a/test/xdr/transactions/soroban_authorized_function_test.exs b/test/xdr/transactions/soroban_authorized_function_test.exs new file mode 100644 index 00000000..4a5b43f3 --- /dev/null +++ b/test/xdr/transactions/soroban_authorized_function_test.exs @@ -0,0 +1,99 @@ +defmodule StellarBase.XDR.SorobanAuthorizedFunctionTest do + use ExUnit.Case + + alias StellarBase.XDR.{ + AccountID, + Int64, + PublicKey, + PublicKeyType, + SCAddress, + SCAddressType, + SCAddress, + SCSymbol, + SCVal, + SCValType, + SCVec, + SorobanAuthorizedContractFunction, + SorobanAuthorizedFunction, + SorobanAuthorizedFunctionType, + UInt256 + } + + alias StellarBase.StrKey + + describe "SorobanAuthorizedFunction" do + setup do + pk_type = PublicKeyType.new(:PUBLIC_KEY_TYPE_ED25519) + + account_id = + "GBZNLMUQMIN3VGUJISKZU7GNY3O3XLMYEHJCKCSMDHKLGSMKALRXOEZD" + |> StrKey.decode!(:ed25519_public_key) + |> UInt256.new() + |> PublicKey.new(pk_type) + |> AccountID.new() + + sc_address_type = SCAddressType.new(:SC_ADDRESS_TYPE_ACCOUNT) + + contract_address = SCAddress.new(account_id, sc_address_type) + function_name = SCSymbol.new("Hello") + scval1 = SCVal.new(Int64.new(3), SCValType.new(:SCV_I64)) + scval2 = SCVal.new(Int64.new(2), SCValType.new(:SCV_I64)) + + sc_vals = [scval1, scval2] + + args = SCVec.new(sc_vals) + value = SorobanAuthorizedContractFunction.new(contract_address, function_name, args) + type = SorobanAuthorizedFunctionType.new(:SOROBAN_AUTHORIZED_FUNCTION_TYPE_CONTRACT_FN) + + %{ + value: value, + type: type, + soroban_credentials: SorobanAuthorizedFunction.new(value, type), + binary: + <<0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 114, 213, 178, 144, 98, 27, 186, 154, 137, 68, + 149, 154, 124, 205, 198, 221, 187, 173, 152, 33, 210, 37, 10, 76, 25, 212, 179, 73, + 138, 2, 227, 119, 0, 0, 0, 5, 72, 101, 108, 108, 111, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 6, + 0, 0, 0, 0, 0, 0, 0, 3, 0, 0, 0, 6, 0, 0, 0, 0, 0, 0, 0, 2>> + } + end + + test "new/1", %{value: value, type: type} do + %SorobanAuthorizedFunction{ + value: ^value, + type: ^type + } = SorobanAuthorizedFunction.new(value, type) + end + + test "encode_xdr/1", %{ + soroban_credentials: soroban_credentials, + binary: binary + } do + {:ok, ^binary} = SorobanAuthorizedFunction.encode_xdr(soroban_credentials) + end + + test "encode_xdr!/1", %{ + soroban_credentials: soroban_credentials, + binary: binary + } do + ^binary = SorobanAuthorizedFunction.encode_xdr!(soroban_credentials) + end + + test "decode_xdr/2", %{ + soroban_credentials: soroban_credentials, + binary: binary + } do + {:ok, {^soroban_credentials, ""}} = SorobanAuthorizedFunction.decode_xdr(binary) + end + + test "decode_xdr/2 with an invalid binary" do + {:error, :not_binary} = SorobanAuthorizedFunction.decode_xdr(123) + end + + test "decode_xdr!/2", %{ + soroban_credentials: soroban_credentials, + binary: binary + } do + {^soroban_credentials, ^binary} = SorobanAuthorizedFunction.decode_xdr!(binary <> binary) + end + end +end diff --git a/test/xdr/transactions/soroban_authorized_function_type_test.exs b/test/xdr/transactions/soroban_authorized_function_type_test.exs new file mode 100644 index 00000000..eb81a8f6 --- /dev/null +++ b/test/xdr/transactions/soroban_authorized_function_type_test.exs @@ -0,0 +1,53 @@ +defmodule StellarBase.XDR.SorobanAuthorizedFunctionTypeTest do + use ExUnit.Case + + alias StellarBase.XDR.SorobanAuthorizedFunctionType + + describe "SorobanAuthorizedFunctionType" do + setup do + %{ + identifier: :SOROBAN_AUTHORIZED_FUNCTION_TYPE_CONTRACT_FN, + soroban_credentials_type: + SorobanAuthorizedFunctionType.new(:SOROBAN_AUTHORIZED_FUNCTION_TYPE_CONTRACT_FN), + binary: <<0, 0, 0, 0>> + } + end + + test "new/1", %{identifier: type} do + %SorobanAuthorizedFunctionType{identifier: ^type} = SorobanAuthorizedFunctionType.new(type) + end + + test "new/1 with a default type" do + %SorobanAuthorizedFunctionType{identifier: :SOROBAN_AUTHORIZED_FUNCTION_TYPE_CONTRACT_FN} = + SorobanAuthorizedFunctionType.new() + end + + test "encode_xdr/1", %{soroban_credentials_type: soroban_credentials_type, binary: binary} do + {:ok, ^binary} = SorobanAuthorizedFunctionType.encode_xdr(soroban_credentials_type) + end + + test "encode_xdr/1 with an invalid identifier" do + {:error, :invalid_key} = + SorobanAuthorizedFunctionType.encode_xdr(%SorobanAuthorizedFunctionType{ + identifier: TEST + }) + end + + test "encode_xdr!/1", %{soroban_credentials_type: soroban_credentials_type, binary: binary} do + ^binary = SorobanAuthorizedFunctionType.encode_xdr!(soroban_credentials_type) + end + + test "decode_xdr/2", %{soroban_credentials_type: soroban_credentials_type, binary: binary} do + {:ok, {^soroban_credentials_type, ""}} = SorobanAuthorizedFunctionType.decode_xdr(binary) + end + + test "decode_xdr/2 with an invalid declaration" do + {:error, :invalid_key} = SorobanAuthorizedFunctionType.decode_xdr(<<1, 0, 0, 1>>) + end + + test "decode_xdr!/2", %{soroban_credentials_type: soroban_credentials_type, binary: binary} do + {^soroban_credentials_type, ^binary} = + SorobanAuthorizedFunctionType.decode_xdr!(binary <> binary) + end + end +end diff --git a/test/xdr/transactions/soroban_authorized_invocation_list_test.exs b/test/xdr/transactions/soroban_authorized_invocation_list_test.exs new file mode 100644 index 00000000..731e282c --- /dev/null +++ b/test/xdr/transactions/soroban_authorized_invocation_list_test.exs @@ -0,0 +1,110 @@ +defmodule StellarBase.XDR.SorobanAuthorizedInvocationListTest do + use ExUnit.Case + + alias StellarBase.XDR.{ + AccountID, + Int64, + PublicKey, + PublicKeyType, + SCAddress, + SCAddressType, + SCAddress, + SCSymbol, + SCVal, + SCValType, + SCVec, + SorobanAuthorizedContractFunction, + SorobanAuthorizedInvocation, + SorobanAuthorizedInvocationList, + SorobanAuthorizedFunction, + SorobanAuthorizedFunctionType, + UInt256 + } + + alias StellarBase.StrKey + + describe "SorobanAuthorizedInvocation" do + setup do + pk_type = PublicKeyType.new(:PUBLIC_KEY_TYPE_ED25519) + + account_id = + "GBZNLMUQMIN3VGUJISKZU7GNY3O3XLMYEHJCKCSMDHKLGSMKALRXOEZD" + |> StrKey.decode!(:ed25519_public_key) + |> UInt256.new() + |> PublicKey.new(pk_type) + |> AccountID.new() + + sc_address_type = SCAddressType.new(:SC_ADDRESS_TYPE_ACCOUNT) + + contract_address = SCAddress.new(account_id, sc_address_type) + function_name = SCSymbol.new("Hello") + scval1 = SCVal.new(Int64.new(3), SCValType.new(:SCV_I64)) + scval2 = SCVal.new(Int64.new(2), SCValType.new(:SCV_I64)) + + sc_vals = [scval1, scval2] + + args = SCVec.new(sc_vals) + value = SorobanAuthorizedContractFunction.new(contract_address, function_name, args) + type = SorobanAuthorizedFunctionType.new(:SOROBAN_AUTHORIZED_FUNCTION_TYPE_CONTRACT_FN) + + soroban_auth_function = SorobanAuthorizedFunction.new(value, type) + + soroban_auth_invocation_list = SorobanAuthorizedInvocationList.new([]) + + soroban_auth_invocations = [ + SorobanAuthorizedInvocation.new(soroban_auth_function, soroban_auth_invocation_list) + ] + + %{ + soroban_auth_invocations: soroban_auth_invocations, + soroban_auth_invocation_list: + SorobanAuthorizedInvocationList.new(soroban_auth_invocations), + binary: + <<0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 114, 213, 178, 144, 98, 27, 186, 154, + 137, 68, 149, 154, 124, 205, 198, 221, 187, 173, 152, 33, 210, 37, 10, 76, 25, 212, + 179, 73, 138, 2, 227, 119, 0, 0, 0, 5, 72, 101, 108, 108, 111, 0, 0, 0, 0, 0, 0, 2, 0, + 0, 0, 6, 0, 0, 0, 0, 0, 0, 0, 3, 0, 0, 0, 6, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0>> + } + end + + test "new/1", %{soroban_auth_invocations: soroban_auth_invocations} do + %SorobanAuthorizedInvocationList{ + items: ^soroban_auth_invocations + } = SorobanAuthorizedInvocationList.new(soroban_auth_invocations) + end + + test "encode_xdr/1", %{ + soroban_auth_invocation_list: soroban_auth_invocation_list, + binary: binary + } do + {:ok, ^binary} = SorobanAuthorizedInvocationList.encode_xdr(soroban_auth_invocation_list) + end + + test "encode_xdr!/1", %{ + soroban_auth_invocation_list: soroban_auth_invocation_list, + binary: binary + } do + ^binary = SorobanAuthorizedInvocationList.encode_xdr!(soroban_auth_invocation_list) + end + + test "decode_xdr/2", %{ + soroban_auth_invocation_list: soroban_auth_invocation_list, + binary: binary + } do + {:ok, {^soroban_auth_invocation_list, ""}} = + SorobanAuthorizedInvocationList.decode_xdr(binary) + end + + test "decode_xdr/2 with an invalid binary" do + {:error, :not_binary} = SorobanAuthorizedInvocationList.decode_xdr(123) + end + + test "decode_xdr!/2", %{ + soroban_auth_invocation_list: soroban_auth_invocation_list, + binary: binary + } do + {^soroban_auth_invocation_list, ^binary} = + SorobanAuthorizedInvocationList.decode_xdr!(binary <> binary) + end + end +end diff --git a/test/xdr/transactions/soroban_authorized_invocation_test.exs b/test/xdr/transactions/soroban_authorized_invocation_test.exs new file mode 100644 index 00000000..865ca8f2 --- /dev/null +++ b/test/xdr/transactions/soroban_authorized_invocation_test.exs @@ -0,0 +1,110 @@ +defmodule StellarBase.XDR.SorobanAuthorizedInvocationTest do + use ExUnit.Case + + alias StellarBase.XDR.{ + AccountID, + Int64, + PublicKey, + PublicKeyType, + SCAddress, + SCAddressType, + SCAddress, + SCSymbol, + SCVal, + SCValType, + SCVec, + SorobanAuthorizedContractFunction, + SorobanAuthorizedInvocation, + SorobanAuthorizedInvocationList, + SorobanAuthorizedFunction, + SorobanAuthorizedFunctionType, + UInt256 + } + + alias StellarBase.StrKey + + describe "SorobanAuthorizedInvocation" do + setup do + pk_type = PublicKeyType.new(:PUBLIC_KEY_TYPE_ED25519) + + account_id = + "GBZNLMUQMIN3VGUJISKZU7GNY3O3XLMYEHJCKCSMDHKLGSMKALRXOEZD" + |> StrKey.decode!(:ed25519_public_key) + |> UInt256.new() + |> PublicKey.new(pk_type) + |> AccountID.new() + + sc_address_type = SCAddressType.new(:SC_ADDRESS_TYPE_ACCOUNT) + + contract_address = SCAddress.new(account_id, sc_address_type) + function_name = SCSymbol.new("Hello") + scval1 = SCVal.new(Int64.new(3), SCValType.new(:SCV_I64)) + scval2 = SCVal.new(Int64.new(2), SCValType.new(:SCV_I64)) + + sc_vals = [scval1, scval2] + + args = SCVec.new(sc_vals) + value = SorobanAuthorizedContractFunction.new(contract_address, function_name, args) + type = SorobanAuthorizedFunctionType.new(:SOROBAN_AUTHORIZED_FUNCTION_TYPE_CONTRACT_FN) + + soroban_auth_function = SorobanAuthorizedFunction.new(value, type) + + soroban_auth_invocation_list = SorobanAuthorizedInvocationList.new([]) + + %{ + soroban_auth_function: soroban_auth_function, + soroban_auth_invocation_list: soroban_auth_invocation_list, + soroban_auth_invocation: + SorobanAuthorizedInvocation.new(soroban_auth_function, soroban_auth_invocation_list), + binary: + <<0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 114, 213, 178, 144, 98, 27, 186, 154, 137, 68, + 149, 154, 124, 205, 198, 221, 187, 173, 152, 33, 210, 37, 10, 76, 25, 212, 179, 73, + 138, 2, 227, 119, 0, 0, 0, 5, 72, 101, 108, 108, 111, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 6, + 0, 0, 0, 0, 0, 0, 0, 3, 0, 0, 0, 6, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0>> + } + end + + test "new/1", %{ + soroban_auth_function: soroban_auth_function, + soroban_auth_invocation_list: soroban_auth_invocation_list + } do + %SorobanAuthorizedInvocation{ + function: ^soroban_auth_function, + sub_invocations: ^soroban_auth_invocation_list + } = SorobanAuthorizedInvocation.new(soroban_auth_function, soroban_auth_invocation_list) + end + + test "encode_xdr/1", %{ + soroban_auth_invocation: soroban_auth_invocation, + binary: binary + } do + {:ok, ^binary} = SorobanAuthorizedInvocation.encode_xdr(soroban_auth_invocation) + end + + test "encode_xdr!/1", %{ + soroban_auth_invocation: soroban_auth_invocation, + binary: binary + } do + ^binary = SorobanAuthorizedInvocation.encode_xdr!(soroban_auth_invocation) + end + + test "decode_xdr/2", %{ + soroban_auth_invocation: soroban_auth_invocation, + binary: binary + } do + {:ok, {^soroban_auth_invocation, ""}} = SorobanAuthorizedInvocation.decode_xdr(binary) + end + + test "decode_xdr/2 with an invalid binary" do + {:error, :not_binary} = SorobanAuthorizedInvocation.decode_xdr(123) + end + + test "decode_xdr!/2", %{ + soroban_auth_invocation: soroban_auth_invocation, + binary: binary + } do + {^soroban_auth_invocation, ^binary} = + SorobanAuthorizedInvocation.decode_xdr!(binary <> binary) + end + end +end diff --git a/test/xdr/transactions/soroban_credentials_test.exs b/test/xdr/transactions/soroban_credentials_test.exs new file mode 100644 index 00000000..7f239cb9 --- /dev/null +++ b/test/xdr/transactions/soroban_credentials_test.exs @@ -0,0 +1,62 @@ +defmodule StellarBase.XDR.SorobanCredentialsTest do + use ExUnit.Case + + alias StellarBase.XDR.{ + SorobanCredentials, + SorobanCredentialsType, + Void + } + + describe "SorobanCredentials" do + setup do + value = Void.new() + type = SorobanCredentialsType.new(:SOROBAN_CREDENTIALS_SOURCE_ACCOUNT) + + %{ + value: value, + type: type, + soroban_credentials: SorobanCredentials.new(value, type), + binary: <<0, 0, 0, 0>> + } + end + + test "new/1", %{value: value, type: type} do + %SorobanCredentials{ + value: ^value, + type: ^type + } = SorobanCredentials.new(value, type) + end + + test "encode_xdr/1", %{ + soroban_credentials: soroban_credentials, + binary: binary + } do + {:ok, ^binary} = SorobanCredentials.encode_xdr(soroban_credentials) + end + + test "encode_xdr!/1", %{ + soroban_credentials: soroban_credentials, + binary: binary + } do + ^binary = SorobanCredentials.encode_xdr!(soroban_credentials) + end + + test "decode_xdr/2", %{ + soroban_credentials: soroban_credentials, + binary: binary + } do + {:ok, {^soroban_credentials, ""}} = SorobanCredentials.decode_xdr(binary) + end + + test "decode_xdr/2 with an invalid binary" do + {:error, :not_binary} = SorobanCredentials.decode_xdr(123) + end + + test "decode_xdr!/2", %{ + soroban_credentials: soroban_credentials, + binary: binary + } do + {^soroban_credentials, ^binary} = SorobanCredentials.decode_xdr!(binary <> binary) + end + end +end diff --git a/test/xdr/transactions/soroban_credentials_type_test.exs b/test/xdr/transactions/soroban_credentials_type_test.exs new file mode 100644 index 00000000..5ba20f5b --- /dev/null +++ b/test/xdr/transactions/soroban_credentials_type_test.exs @@ -0,0 +1,49 @@ +defmodule StellarBase.XDR.SorobanCredentialsTypeTest do + use ExUnit.Case + + alias StellarBase.XDR.SorobanCredentialsType + + describe "SorobanCredentialsType" do + setup do + %{ + identifier: :SOROBAN_CREDENTIALS_SOURCE_ACCOUNT, + soroban_credentials_type: SorobanCredentialsType.new(:SOROBAN_CREDENTIALS_SOURCE_ACCOUNT), + binary: <<0, 0, 0, 0>> + } + end + + test "new/1", %{identifier: type} do + %SorobanCredentialsType{identifier: ^type} = SorobanCredentialsType.new(type) + end + + test "new/1 with a default type" do + %SorobanCredentialsType{identifier: :SOROBAN_CREDENTIALS_SOURCE_ACCOUNT} = + SorobanCredentialsType.new() + end + + test "encode_xdr/1", %{soroban_credentials_type: soroban_credentials_type, binary: binary} do + {:ok, ^binary} = SorobanCredentialsType.encode_xdr(soroban_credentials_type) + end + + test "encode_xdr/1 with an invalid identifier" do + {:error, :invalid_key} = + SorobanCredentialsType.encode_xdr(%SorobanCredentialsType{identifier: CREDENTIAL_TEST}) + end + + test "encode_xdr!/1", %{soroban_credentials_type: soroban_credentials_type, binary: binary} do + ^binary = SorobanCredentialsType.encode_xdr!(soroban_credentials_type) + end + + test "decode_xdr/2", %{soroban_credentials_type: soroban_credentials_type, binary: binary} do + {:ok, {^soroban_credentials_type, ""}} = SorobanCredentialsType.decode_xdr(binary) + end + + test "decode_xdr/2 with an invalid declaration" do + {:error, :invalid_key} = SorobanCredentialsType.decode_xdr(<<1, 0, 0, 1>>) + end + + test "decode_xdr!/2", %{soroban_credentials_type: soroban_credentials_type, binary: binary} do + {^soroban_credentials_type, ^binary} = SorobanCredentialsType.decode_xdr!(binary <> binary) + end + end +end