Skip to content

Commit

Permalink
Add Signer 'new' method for keywordlist input (#219)
Browse files Browse the repository at this point in the history
Co-authored-by: Jhonatan Hidalgo <[email protected]>

Co-authored-by: Jhonatan Hidalgo <[email protected]>
  • Loading branch information
FelipeGuzmanSierra and jhonatan-kmt authored Sep 5, 2022
1 parent e58b0e2 commit a8c5789
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/tx_build/signer.ex
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ defmodule Stellar.TxBuild.Signer do
@impl true
def new(args, opts \\ [])

def new([{_key_type, signer_key}, {:weight, weight}], _opts), do: new({signer_key, weight})

def new({signer_key, weight}, _opts) do
with {:ok, signer_key} <- validate_signer_key(signer_key),
{:ok, weight} <- validate_signer_weight(weight) do
Expand Down
35 changes: 35 additions & 0 deletions test/tx_build/signer_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,14 @@ defmodule Stellar.TxBuild.SignerTest do
%Signer{signer_key: ^signer_key, weight: ^weight} = Signer.new({ed25519, 2})
end

test "new/2 ed25519 with_input_as_keywordlist", %{
ed25519: ed25519,
ed25519_signer_key: signer_key,
weight: weight
} do
%Signer{signer_key: ^signer_key, weight: ^weight} = Signer.new(ed25519: ed25519, weight: 2)
end

test "new/2 sha256_hash", %{
sha256_hash: sha256_hash,
sha256_hash_signer_key: signer_key,
Expand All @@ -41,6 +49,15 @@ defmodule Stellar.TxBuild.SignerTest do
%Signer{signer_key: ^signer_key, weight: ^weight} = Signer.new({sha256_hash, 2})
end

test "new/2 sha256_hash with_input_as_keywordlist", %{
sha256_hash: sha256_hash,
sha256_hash_signer_key: signer_key,
weight: weight
} do
%Signer{signer_key: ^signer_key, weight: ^weight} =
Signer.new(sha256_hash: sha256_hash, weight: 2)
end

test "new/2 pre_auth_tx", %{
pre_auth_tx: pre_auth_tx,
pre_auth_tx_signer_key: signer_key,
Expand All @@ -49,6 +66,15 @@ defmodule Stellar.TxBuild.SignerTest do
%Signer{signer_key: ^signer_key, weight: ^weight} = Signer.new({pre_auth_tx, 2})
end

test "new/2 pre_auth_tx with_input_as_keywordlist", %{
pre_auth_tx: pre_auth_tx,
pre_auth_tx_signer_key: signer_key,
weight: weight
} do
%Signer{signer_key: ^signer_key, weight: ^weight} =
Signer.new(pre_auth_tx: pre_auth_tx, weight: 2)
end

test "new/2 signed_payload", %{
signed_payload: signed_payload,
signed_payload_signer_key: signer_key,
Expand All @@ -57,6 +83,15 @@ defmodule Stellar.TxBuild.SignerTest do
%Signer{signer_key: ^signer_key, weight: ^weight} = Signer.new({signed_payload, 2})
end

test "new/2 signed_payload with_input_as_keywordlist", %{
signed_payload: signed_payload,
signed_payload_signer_key: signer_key,
weight: weight
} do
%Signer{signer_key: ^signer_key, weight: ^weight} =
Signer.new(signed_payload: signed_payload, weight: 2)
end

test "new/2 with_invalid_signer_key" do
{:error, :invalid_signer_key} = Signer.new({"XCTP2Y5GZ7TTGHLM3JJKDIPR36", 2})
end
Expand Down

0 comments on commit a8c5789

Please sign in to comment.