generated from kommitters/.template
-
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add endpoint get_version_info (#157)
- Loading branch information
Showing
7 changed files
with
201 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
defmodule Soroban.RPC.GetVersionInfo do | ||
@moduledoc """ | ||
GetVersionInfo request implementation for Soroban RPC. | ||
""" | ||
@behaviour Soroban.RPC.Endpoint.Spec | ||
|
||
alias Soroban.RPC.{GetVersionInfoResponse, Request} | ||
|
||
@endpoint "getVersionInfo" | ||
|
||
@impl true | ||
def request(server, _params \\ nil) do | ||
server | ||
|> Request.new(@endpoint) | ||
|> Request.add_headers([{"Content-Type", "application/json"}]) | ||
|> Request.perform() | ||
|> Request.results(as: GetVersionInfoResponse) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
defmodule Soroban.RPC.GetVersionInfoResponse do | ||
@moduledoc """ | ||
`GetVersionInfoResponse` struct definition. | ||
""" | ||
@behaviour Soroban.RPC.Response.Spec | ||
|
||
@type version :: String.t() | ||
@type commit_hash :: String.t() | ||
@type build_time_stamp :: String.t() | ||
@type captive_core_version :: String.t() | ||
@type protocol_version :: non_neg_integer() | ||
@type t :: %__MODULE__{ | ||
version: version(), | ||
commit_hash: commit_hash(), | ||
build_time_stamp: build_time_stamp(), | ||
captive_core_version: captive_core_version(), | ||
protocol_version: protocol_version() | ||
} | ||
|
||
defstruct [:version, :commit_hash, :build_time_stamp, :captive_core_version, :protocol_version] | ||
|
||
@impl true | ||
def new(attrs), do: struct(%__MODULE__{}, attrs) | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
defmodule Soroban.RPC.CannedGetVersionInfoClientImpl do | ||
@moduledoc false | ||
@behaviour Soroban.RPC.Client.Spec | ||
|
||
@impl true | ||
def request(_endpoint, _url, _headers, _body, _opts) do | ||
send(self(), {:request, "RESPONSE"}) | ||
|
||
{:ok, | ||
%{ | ||
version: "21.1.0", | ||
commit_hash: "fcd2f0523f04279bae4502f3e3fa00ca627e6f6a", | ||
build_time_stamp: "2024-05-10T11:18:38", | ||
captive_core_version: "stellar-core 21.0.0.rc2 (c6f474133738ae5f6d11b07963ca841909210273)", | ||
protocol_version: 21 | ||
}} | ||
end | ||
end | ||
|
||
defmodule Soroban.RPC.GetVersionInfoTest do | ||
use ExUnit.Case | ||
|
||
alias Soroban.RPC.{ | ||
CannedGetVersionInfoClientImpl, | ||
GetVersionInfo, | ||
GetVersionInfoResponse, | ||
Server | ||
} | ||
|
||
setup do | ||
Application.put_env(:soroban, :http_client_impl, CannedGetVersionInfoClientImpl) | ||
|
||
on_exit(fn -> | ||
Application.delete_env(:soroban, :http_client_impl) | ||
end) | ||
|
||
%{server: Server.testnet()} | ||
end | ||
|
||
test "request/1", %{server: server} do | ||
{:ok, | ||
%GetVersionInfoResponse{ | ||
version: "21.1.0", | ||
commit_hash: "fcd2f0523f04279bae4502f3e3fa00ca627e6f6a", | ||
build_time_stamp: "2024-05-10T11:18:38", | ||
captive_core_version: "stellar-core 21.0.0.rc2 (c6f474133738ae5f6d11b07963ca841909210273)", | ||
protocol_version: 21 | ||
}} = GetVersionInfo.request(server) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
defmodule Soroban.RPC.GetVetsionInfoResponseTest do | ||
use ExUnit.Case | ||
|
||
alias Soroban.RPC.GetVersionInfoResponse | ||
|
||
setup do | ||
%{ | ||
result: %{ | ||
version: "21.1.0", | ||
commit_hash: "fcd2f0523f04279bae4502f3e3fa00ca627e6f6a", | ||
build_time_stamp: "2024-05-10T11:18:38", | ||
captive_core_version: | ||
"stellar-core 21.0.0.rc2 (c6f474133738ae5f6d11b07963ca841909210273)", | ||
protocol_version: 21 | ||
} | ||
} | ||
end | ||
|
||
describe "new/1" do | ||
test "when successful transaction", %{ | ||
result: | ||
%{ | ||
version: version, | ||
commit_hash: commit_hash, | ||
build_time_stamp: build_time_stamp, | ||
captive_core_version: captive_core_version, | ||
protocol_version: protocol_version | ||
} = result | ||
} do | ||
%GetVersionInfoResponse{ | ||
version: ^version, | ||
commit_hash: ^commit_hash, | ||
build_time_stamp: ^build_time_stamp, | ||
captive_core_version: ^captive_core_version, | ||
protocol_version: ^protocol_version | ||
} = GetVersionInfoResponse.new(result) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters