From 00b2ee21e06365eb4a25f2a1885d4b28172730fa Mon Sep 17 00:00:00 2001 From: Alisina Bahadori Date: Wed, 1 Jan 2025 22:43:58 -0500 Subject: [PATCH 1/2] Support Ethers 0.6.0+ --- lib/aws/signer.ex | 29 ++++++------ mix.exs | 2 +- mix.lock | 13 +++--- test/aws/signer_test.exs | 96 +++++++++++++++++++++------------------- 4 files changed, 73 insertions(+), 67 deletions(-) diff --git a/lib/aws/signer.ex b/lib/aws/signer.ex index cde59b7..ddafe2c 100644 --- a/lib/aws/signer.ex +++ b/lib/aws/signer.ex @@ -8,7 +8,9 @@ defmodule EthersKMS.AWS.Signer do @behaviour Ethers.Signer import Ethers + alias Ethers.Transaction + alias Ethers.Transaction.Signed alias Ethers.Utils, as: EthersUtils alias EthersKMS.AWS.Utils @@ -16,30 +18,29 @@ defmodule EthersKMS.AWS.Signer do @secp256_k1_n 115_792_089_237_316_195_423_570_985_008_687_907_852_837_564_279_074_904_382_605_163_141_518_161_494_337 @impl true - def sign_transaction(%Transaction{} = tx, opts) do + def sign_transaction(transaction, opts) do with {:ok, key_id} <- get_kms_key(opts), {:ok, %{"PublicKey" => pem}} <- ExAws.KMS.get_public_key(key_id) |> ExAws.request(), {:ok, public_key} <- Utils.public_key_from_pem(pem), - :ok <- validate_public_key(public_key, tx.from) do + :ok <- validate_public_key(public_key, Keyword.get(opts, :from)) do {:ok, {r, s, recovery_id}} = - Transaction.encode(tx) + transaction + |> Transaction.encode() |> keccak_module().hash_256() |> Base.encode64() |> sign(key_id, public_key) - y_parity_or_v = Transaction.calculate_y_parity_or_v(tx, recovery_id) - - signed = - %Ethers.Transaction{ - tx - | signature_r: EthersUtils.hex_encode(r), - signature_s: EthersUtils.hex_encode(s), - signature_y_parity_or_v: EthersUtils.integer_to_hex(y_parity_or_v) + signed_transaction = + %Signed{ + payload: transaction, + signature_r: r, + signature_s: s, + signature_y_parity_or_v: Signed.calculate_y_parity_or_v(transaction, recovery_id) } - |> Transaction.encode() - |> EthersUtils.hex_encode() - {:ok, signed} + encoded_signed_transaction = Transaction.encode(signed_transaction) + + {:ok, EthersUtils.hex_encode(encoded_signed_transaction)} end end diff --git a/mix.exs b/mix.exs index d401b82..882f148 100644 --- a/mix.exs +++ b/mix.exs @@ -69,7 +69,7 @@ defmodule EthersKMS.MixProject do {:configparser_ex, "~> 4.0"}, {:credo, "~> 1.7", only: [:dev, :test], runtime: false}, {:dialyxir, "~> 1.3", only: [:dev, :test], runtime: false}, - {:ethers, "~> 0.5.2"}, + {:ethers, "~> 0.6.0"}, {:excoveralls, "~> 0.10", only: :test}, {:ex_aws, "~> 2.5.1"}, {:ex_aws_kms, "~> 2.3.2"}, diff --git a/mix.lock b/mix.lock index 642b22a..5b08597 100644 --- a/mix.lock +++ b/mix.lock @@ -1,14 +1,14 @@ %{ "bunt": {:hex, :bunt, "1.0.0", "081c2c665f086849e6d57900292b3a161727ab40431219529f13c4ddcf3e7a44", [:mix], [], "hexpm", "dc5f86aa08a5f6fa6b8096f0735c4e76d54ae5c9fa2c143e5a1fc7c1cd9bb6b5"}, - "castore": {:hex, :castore, "1.0.8", "dedcf20ea746694647f883590b82d9e96014057aff1d44d03ec90f36a5c0dc6e", [:mix], [], "hexpm", "0b2b66d2ee742cb1d9cb8c8be3b43c3a70ee8651f37b75a8b982e036752983f1"}, + "castore": {:hex, :castore, "1.0.11", "4bbd584741601eb658007339ea730b082cc61f3554cf2e8f39bf693a11b49073", [:mix], [], "hexpm", "e03990b4db988df56262852f20de0f659871c35154691427a5047f4967a16a62"}, "configparser_ex": {:hex, :configparser_ex, "4.0.0", "17e2b831cfa33a08c56effc610339b2986f0d82a9caa0ed18880a07658292ab6", [:mix], [], "hexpm", "02e6d1a559361a063cba7b75bc3eb2d6ad7e62730c551cc4703541fd11e65e5b"}, "credo": {:hex, :credo, "1.7.5", "643213503b1c766ec0496d828c90c424471ea54da77c8a168c725686377b9545", [:mix], [{:bunt, "~> 0.2.1 or ~> 1.0", [hex: :bunt, repo: "hexpm", optional: false]}, {:file_system, "~> 0.2 or ~> 1.0", [hex: :file_system, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: false]}], "hexpm", "f799e9b5cd1891577d8c773d245668aa74a2fcd15eb277f51a0131690ebfb3fd"}, "dialyxir": {:hex, :dialyxir, "1.4.3", "edd0124f358f0b9e95bfe53a9fcf806d615d8f838e2202a9f430d59566b6b53b", [:mix], [{:erlex, ">= 0.2.6", [hex: :erlex, repo: "hexpm", optional: false]}], "hexpm", "bf2cfb75cd5c5006bec30141b131663299c661a864ec7fbbc72dfa557487a986"}, "earmark_parser": {:hex, :earmark_parser, "1.4.39", "424642f8335b05bb9eb611aa1564c148a8ee35c9c8a8bba6e129d51a3e3c6769", [:mix], [], "hexpm", "06553a88d1f1846da9ef066b87b57c6f605552cfbe40d20bd8d59cc6bde41944"}, "erlex": {:hex, :erlex, "0.2.6", "c7987d15e899c7a2f34f5420d2a2ea0d659682c06ac607572df55a43753aa12e", [:mix], [], "hexpm", "2ed2e25711feb44d52b17d2780eabf998452f6efda104877a3881c2f8c0c0c75"}, "ethereumex": {:hex, :ethereumex, "0.10.6", "6d75cac39b5b7a720b064fe48563f205d3d9784e5bde25f983dd07cf306c2a6d", [:make, :mix], [{:finch, "~> 0.16", [hex: :finch, repo: "hexpm", optional: false]}, {:jason, "~> 1.4", [hex: :jason, repo: "hexpm", optional: false]}, {:poolboy, "~> 1.5", [hex: :poolboy, repo: "hexpm", optional: false]}, {:telemetry, "~> 0.4 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "58cf926239dabf8bd1fc6cf50a37b926274240b7f58ba5b235a20b5500a9a7e1"}, - "ethers": {:hex, :ethers, "0.5.2", "997a0bf7cdb6ee66ea4ec73eef943a4c154e028bf4a0492b131f0605e7867d76", [:mix], [{:ethereumex, "~> 0.10.6", [hex: :ethereumex, repo: "hexpm", optional: false]}, {:ex_abi, "~> 0.8.0", [hex: :ex_abi, repo: "hexpm", optional: false]}, {:ex_keccak, "~> 0.7.5", [hex: :ex_keccak, repo: "hexpm", optional: false]}, {:ex_rlp, "~> 0.6.0", [hex: :ex_rlp, repo: "hexpm", optional: false]}, {:ex_secp256k1, "~> 0.7.2", [hex: :ex_secp256k1, repo: "hexpm", optional: true]}, {:idna, "~> 6.1", [hex: :idna, repo: "hexpm", optional: false]}, {:jason, "~> 1.4", [hex: :jason, repo: "hexpm", optional: false]}], "hexpm", "46fa224e94fe472b6f28ac1caf77123b1e9ef6e24bd20b3e6093e1c643070d9b"}, - "ex_abi": {:hex, :ex_abi, "0.8.0", "bb08827bd8d71dbb311c69ac55a008669dfabe2ce5b58d65f97c08c0aba60ec6", [:mix], [{:ex_keccak, "~> 0.7.5", [hex: :ex_keccak, repo: "hexpm", optional: true]}, {:jason, "~> 1.4", [hex: :jason, repo: "hexpm", optional: false]}], "hexpm", "bbdae12c186aeeb4c53dd7c7c57f457923602db315aa1f66d7427467c8ad77af"}, + "ethers": {:hex, :ethers, "0.6.0", "aea0147dd10911b98efd1359f95b413f5aaac0a7ba8f8de63ae102a0e4e325d7", [:mix], [{:ethereumex, "~> 0.10.6", [hex: :ethereumex, repo: "hexpm", optional: false]}, {:ex_abi, "~> 0.8.0", [hex: :ex_abi, repo: "hexpm", optional: false]}, {:ex_keccak, "~> 0.7.5", [hex: :ex_keccak, repo: "hexpm", optional: false]}, {:ex_rlp, "~> 0.6.0", [hex: :ex_rlp, repo: "hexpm", optional: false]}, {:ex_secp256k1, "~> 0.7.2", [hex: :ex_secp256k1, repo: "hexpm", optional: true]}, {:idna, "~> 6.1", [hex: :idna, repo: "hexpm", optional: false]}, {:jason, "~> 1.4", [hex: :jason, repo: "hexpm", optional: false]}, {:req, "~> 0.5", [hex: :req, repo: "hexpm", optional: false]}], "hexpm", "596cd90373e00a98d3d3bf4138c9bdfd4021f099844e1809b8aa443b35350c49"}, + "ex_abi": {:hex, :ex_abi, "0.8.1", "451fa960ddc4dfbb350e13509f3dd64ca586b8484a77aad9f7d778161b5eab79", [:mix], [{:ex_keccak, "~> 0.7.5", [hex: :ex_keccak, repo: "hexpm", optional: true]}, {:jason, "~> 1.4", [hex: :jason, repo: "hexpm", optional: false]}], "hexpm", "abcf53d556c2948e5c1241340afd4a72cdf93ab6daef16fc200c16ca1183cdca"}, "ex_aws": {:hex, :ex_aws, "2.5.3", "9c2d05ba0c057395b12c7b5ca6267d14cdaec1d8e65bdf6481fe1fd245accfb4", [:mix], [{:configparser_ex, "~> 4.0", [hex: :configparser_ex, repo: "hexpm", optional: true]}, {:hackney, "~> 1.16", [hex: :hackney, repo: "hexpm", optional: true]}, {:jason, "~> 1.1", [hex: :jason, repo: "hexpm", optional: true]}, {:jsx, "~> 2.8 or ~> 3.0", [hex: :jsx, repo: "hexpm", optional: true]}, {:mime, "~> 1.2 or ~> 2.0", [hex: :mime, repo: "hexpm", optional: false]}, {:sweet_xml, "~> 0.7", [hex: :sweet_xml, repo: "hexpm", optional: true]}, {:telemetry, "~> 0.4.3 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "67115f1d399d7ec4d191812ee565c6106cb4b1bbf19a9d4db06f265fd87da97e"}, "ex_aws_kms": {:hex, :ex_aws_kms, "2.3.2", "0a397bd4eb807dcb519dc738ef3ab4f89f371cbcb5880c4f94bbd3612b364446", [:mix], [{:ex_aws, "~> 2.1", [hex: :ex_aws, repo: "hexpm", optional: false]}], "hexpm", "1f2adcc51a3f160f27d0c4d2acab93dd1d7e75b3809d06477bf433b99b03f616"}, "ex_aws_sts": {:hex, :ex_aws_sts, "2.3.0", "ce48c4cba7f1595a7d544458d0202ca313124026dba7b1a0021bbb1baa3d66d0", [:mix], [{:ex_aws, "~> 2.2", [hex: :ex_aws, repo: "hexpm", optional: false]}], "hexpm", "f14e4c7da3454514bf253b331e9422d25825485c211896ab3b81d2a4bdbf62f5"}, @@ -18,8 +18,8 @@ "ex_secp256k1": {:hex, :ex_secp256k1, "0.7.3", "489b6fd57fab5a7259ace927d8cb5171aad835e9c7279c2a859a0483cb069415", [:mix], [{:rustler, ">= 0.0.0", [hex: :rustler, repo: "hexpm", optional: true]}, {:rustler_precompiled, "~> 0.7", [hex: :rustler_precompiled, repo: "hexpm", optional: false]}], "hexpm", "ea63159442f4d8143166cd1507da03edc43216d6e7c6bac4b416bdce04f0daa8"}, "excoveralls": {:hex, :excoveralls, "0.18.0", "b92497e69465dc51bc37a6422226ee690ab437e4c06877e836f1c18daeb35da9", [:mix], [{:castore, "~> 1.0", [hex: :castore, repo: "hexpm", optional: true]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: false]}], "hexpm", "1109bb911f3cb583401760be49c02cbbd16aed66ea9509fc5479335d284da60b"}, "file_system": {:hex, :file_system, "1.0.0", "b689cc7dcee665f774de94b5a832e578bd7963c8e637ef940cd44327db7de2cd", [:mix], [], "hexpm", "6752092d66aec5a10e662aefeed8ddb9531d79db0bc145bb8c40325ca1d8536d"}, - "finch": {:hex, :finch, "0.18.0", "944ac7d34d0bd2ac8998f79f7a811b21d87d911e77a786bc5810adb75632ada4", [:mix], [{:castore, "~> 0.1 or ~> 1.0", [hex: :castore, repo: "hexpm", optional: false]}, {:mime, "~> 1.0 or ~> 2.0", [hex: :mime, repo: "hexpm", optional: false]}, {:mint, "~> 1.3", [hex: :mint, repo: "hexpm", optional: false]}, {:nimble_options, "~> 0.4 or ~> 1.0", [hex: :nimble_options, repo: "hexpm", optional: false]}, {:nimble_pool, "~> 0.2.6 or ~> 1.0", [hex: :nimble_pool, repo: "hexpm", optional: false]}, {:telemetry, "~> 0.4 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "69f5045b042e531e53edc2574f15e25e735b522c37e2ddb766e15b979e03aa65"}, - "hpax": {:hex, :hpax, "1.0.0", "28dcf54509fe2152a3d040e4e3df5b265dcb6cb532029ecbacf4ce52caea3fd2", [:mix], [], "hexpm", "7f1314731d711e2ca5fdc7fd361296593fc2542570b3105595bb0bc6d0fad601"}, + "finch": {:hex, :finch, "0.19.0", "c644641491ea854fc5c1bbaef36bfc764e3f08e7185e1f084e35e0672241b76d", [:mix], [{:mime, "~> 1.0 or ~> 2.0", [hex: :mime, repo: "hexpm", optional: false]}, {:mint, "~> 1.6.2 or ~> 1.7", [hex: :mint, repo: "hexpm", optional: false]}, {:nimble_options, "~> 0.4 or ~> 1.0", [hex: :nimble_options, repo: "hexpm", optional: false]}, {:nimble_pool, "~> 1.1", [hex: :nimble_pool, repo: "hexpm", optional: false]}, {:telemetry, "~> 0.4 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "fc5324ce209125d1e2fa0fcd2634601c52a787aff1cd33ee833664a5af4ea2b6"}, + "hpax": {:hex, :hpax, "1.0.2", "762df951b0c399ff67cc57c3995ec3cf46d696e41f0bba17da0518d94acd4aac", [:mix], [], "hexpm", "2f09b4c1074e0abd846747329eaa26d535be0eb3d189fa69d812bfb8bfefd32f"}, "idna": {:hex, :idna, "6.1.1", "8a63070e9f7d0c62eb9d9fcb360a7de382448200fbbd1b106cc96d3d8099df8d", [:rebar3], [{:unicode_util_compat, "~> 0.7.0", [hex: :unicode_util_compat, repo: "hexpm", optional: false]}], "hexpm", "92376eb7894412ed19ac475e4a86f7b413c1b9fbb5bd16dccd57934157944cea"}, "jason": {:hex, :jason, "1.4.4", "b9226785a9aa77b6857ca22832cffa5d5011a667207eb2a0ad56adb5db443b8a", [:mix], [{:decimal, "~> 1.0 or ~> 2.0", [hex: :decimal, repo: "hexpm", optional: true]}], "hexpm", "c5eb0cab91f094599f94d55bc63409236a8ec69a21a67814529e8d5f6cc90b3b"}, "makeup": {:hex, :makeup, "1.1.1", "fa0bc768698053b2b3869fa8a62616501ff9d11a562f3ce39580d60860c3a55e", [:mix], [{:nimble_parsec, "~> 1.2.2 or ~> 1.3", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm", "5dc62fbdd0de44de194898b6710692490be74baa02d9d108bc29f007783b0b48"}, @@ -32,7 +32,8 @@ "nimble_parsec": {:hex, :nimble_parsec, "1.4.0", "51f9b613ea62cfa97b25ccc2c1b4216e81df970acd8e16e8d1bdc58fef21370d", [:mix], [], "hexpm", "9c565862810fb383e9838c1dd2d7d2c437b3d13b267414ba6af33e50d2d1cf28"}, "nimble_pool": {:hex, :nimble_pool, "1.1.0", "bf9c29fbdcba3564a8b800d1eeb5a3c58f36e1e11d7b7fb2e084a643f645f06b", [:mix], [], "hexpm", "af2e4e6b34197db81f7aad230c1118eac993acc0dae6bc83bac0126d4ae0813a"}, "poolboy": {:hex, :poolboy, "1.5.2", "392b007a1693a64540cead79830443abf5762f5d30cf50bc95cb2c1aaafa006b", [:rebar3], [], "hexpm", "dad79704ce5440f3d5a3681c8590b9dc25d1a561e8f5a9c995281012860901e3"}, - "rustler_precompiled": {:hex, :rustler_precompiled, "0.7.2", "097f657e401f02e7bc1cab808cfc6abdc1f7b9dc5e5adee46bf2fd8fdcce9ecf", [:mix], [{:castore, "~> 0.1 or ~> 1.0", [hex: :castore, repo: "hexpm", optional: false]}, {:rustler, "~> 0.23", [hex: :rustler, repo: "hexpm", optional: true]}], "hexpm", "7663faaeadc9e93e605164dcf9e69168e35f2f8b7f2b9eb4e400d1a8e0fe2999"}, + "req": {:hex, :req, "0.5.8", "50d8d65279d6e343a5e46980ac2a70e97136182950833a1968b371e753f6a662", [:mix], [{:brotli, "~> 0.3.1", [hex: :brotli, repo: "hexpm", optional: true]}, {:ezstd, "~> 1.0", [hex: :ezstd, repo: "hexpm", optional: true]}, {:finch, "~> 0.17", [hex: :finch, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: false]}, {:mime, "~> 2.0.6 or ~> 2.1", [hex: :mime, repo: "hexpm", optional: false]}, {:nimble_csv, "~> 1.0", [hex: :nimble_csv, repo: "hexpm", optional: true]}, {:plug, "~> 1.0", [hex: :plug, repo: "hexpm", optional: true]}], "hexpm", "d7fc5898a566477e174f26887821a3c5082b243885520ee4b45555f5d53f40ef"}, + "rustler_precompiled": {:hex, :rustler_precompiled, "0.8.2", "5f25cbe220a8fac3e7ad62e6f950fcdca5a5a5f8501835d2823e8c74bf4268d5", [:mix], [{:castore, "~> 0.1 or ~> 1.0", [hex: :castore, repo: "hexpm", optional: false]}, {:rustler, "~> 0.23", [hex: :rustler, repo: "hexpm", optional: true]}], "hexpm", "63d1bd5f8e23096d1ff851839923162096364bac8656a4a3c00d1fff8e83ee0a"}, "sweet_xml": {:hex, :sweet_xml, "0.7.4", "a8b7e1ce7ecd775c7e8a65d501bc2cd933bff3a9c41ab763f5105688ef485d08", [:mix], [], "hexpm", "e7c4b0bdbf460c928234951def54fe87edf1a170f6896675443279e2dbeba167"}, "telemetry": {:hex, :telemetry, "1.3.0", "fedebbae410d715cf8e7062c96a1ef32ec22e764197f70cda73d82778d61e7a2", [:rebar3], [], "hexpm", "7015fc8919dbe63764f4b4b87a95b7c0996bd539e0d499be6ec9d7f3875b79e6"}, "unicode_util_compat": {:hex, :unicode_util_compat, "0.7.0", "bc84380c9ab48177092f43ac89e4dfa2c6d62b40b8bd132b1059ecc7232f9a78", [:rebar3], [], "hexpm", "25eee6d67df61960cf6a794239566599b09e17e668d3700247bc498638152521"}, diff --git a/test/aws/signer_test.exs b/test/aws/signer_test.exs index 09f5406..6f95a60 100644 --- a/test/aws/signer_test.exs +++ b/test/aws/signer_test.exs @@ -15,40 +15,49 @@ defmodule EthersKMS.AWS.SignerTest do KMSFixtures.kms_sign_response() end) - transaction = %Ethers.Transaction{ - type: :eip1559, - chain_id: "0x539", - nonce: "0xb66", - gas: "0x5A82", - from: "0x4eed49289Ac2876C9c966FC16b22F6eC5bf0817c", + # transaction = %Ethers.Transaction{ + # type: :eip1559, + # chain_id: "0x539", + # nonce: "0xb66", + # gas: "0x5A82", + # from: "0x4eed49289Ac2876C9c966FC16b22F6eC5bf0817c", + # to: "0xFFcf8FDEE72ac11b5c542428B35EEF5769C409f0", + # value: "0x0", + # data: "0x06fdde03", + # gas_price: "0x10e7467522", + # max_fee_per_gas: "0x1448BAF2F5", + # max_priority_fee_per_gas: "0x0" + # } + + transaction = %Ethers.Transaction.Eip1559{ + chain_id: 1337, + nonce: 2918, + gas: 23170, to: "0xFFcf8FDEE72ac11b5c542428B35EEF5769C409f0", - value: "0x0", - data: "0x06fdde03", - gas_price: "0x10e7467522", - max_fee_per_gas: "0x1448BAF2F5", - max_priority_fee_per_gas: "0x0" + value: 0, + input: Ethers.Utils.hex_decode!("0x06fdde03"), + max_fee_per_gas: 87_119_557_365, + max_priority_fee_per_gas: 0 } assert {:ok, "0x02f86f820539820b6680851448baf2f5825a8294ffcf8fdee72ac11b5c542428b35eef5769c409f0808406fdde03c001a032ba3398b3223445b858849e275d6dbb1a6708f305bb2b8c427143f9239bb9bea053fa0a993614ed279496088147827086767088e33a587e3c18b5978f8ac018e5"} == Signer.sign_transaction(transaction, - kms_key_id: "ddb1aedd-77d1-4b90-a3a8-d77fb82ba533" + kms_key_id: "ddb1aedd-77d1-4b90-a3a8-d77fb82ba533", + from: "0x4eed49289Ac2876C9c966FC16b22F6eC5bf0817c" ) end test "fails if no kms key id is given" do - transaction = %Ethers.Transaction{ - type: :eip1559, - chain_id: "0x539", - nonce: "0xb66", - gas: "0x5A82", - from: "0x4eed49289Ac2876C9c966FC16b22F6eC5bf0817c", + transaction = %Ethers.Transaction.Eip1559{ + chain_id: 1337, + nonce: 2918, + gas: 23170, to: "0xFFcf8FDEE72ac11b5c542428B35EEF5769C409f0", - value: "0x0", - data: "0x06fdde03", - gas_price: "0x10e7467522", - max_fee_per_gas: "0x1448BAF2F5", - max_priority_fee_per_gas: "0x0" + value: 0, + input: Ethers.Utils.hex_decode!("0x06fdde03"), + max_fee_per_gas: 87_119_557_365, + max_priority_fee_per_gas: 0 } assert {:error, :kms_key_not_found} == @@ -62,18 +71,15 @@ defmodule EthersKMS.AWS.SignerTest do KMSFixtures.kms_public_key_response() end) - transaction = %Ethers.Transaction{ - type: :eip1559, - chain_id: "0x539", - nonce: "0xb66", - gas: "0x5A82", - from: nil, + transaction = %Ethers.Transaction.Eip1559{ + chain_id: 1337, + nonce: 2918, + gas: 23170, to: "0xFFcf8FDEE72ac11b5c542428B35EEF5769C409f0", - value: "0x0", - data: "0x06fdde03", - gas_price: "0x10e7467522", - max_fee_per_gas: "0x1448BAF2F5", - max_priority_fee_per_gas: "0x0" + value: 0, + input: Ethers.Utils.hex_decode!("0x06fdde03"), + max_fee_per_gas: 87_119_557_365, + max_priority_fee_per_gas: 0 } assert {:error, :no_from_address} == @@ -87,23 +93,21 @@ defmodule EthersKMS.AWS.SignerTest do KMSFixtures.kms_public_key_response() end) - transaction = %Ethers.Transaction{ - type: :eip1559, - chain_id: "0x539", - nonce: "0xb66", - gas: "0x5A82", - from: "0xFFcf8FDEE72ac11b5c542428B35EEF5769C409f0", + transaction = %Ethers.Transaction.Eip1559{ + chain_id: 1337, + nonce: 2918, + gas: 23170, to: "0xFFcf8FDEE72ac11b5c542428B35EEF5769C409f0", - value: "0x0", - data: "0x06fdde03", - gas_price: "0x10e7467522", - max_fee_per_gas: "0x1448BAF2F5", - max_priority_fee_per_gas: "0x0" + value: 0, + input: Ethers.Utils.hex_decode!("0x06fdde03"), + max_fee_per_gas: 87_119_557_365, + max_priority_fee_per_gas: 0 } assert {:error, :wrong_public_key} == Signer.sign_transaction(transaction, - kms_key_id: "ddb1aedd-77d1-4b90-a3a8-d77fb82ba533" + kms_key_id: "ddb1aedd-77d1-4b90-a3a8-d77fb82ba533", + from: "0x3aad49289Ac2876C9c966FC16b22F6eC5bf081aa" ) end end From f61c402008853f4063fd221c20c16d60a390e05a Mon Sep 17 00:00:00 2001 From: Alisina Bahadori Date: Wed, 1 Jan 2025 22:54:15 -0500 Subject: [PATCH 2/2] Fix credo warning --- test/aws/signer_test.exs | 22 ++++------------------ 1 file changed, 4 insertions(+), 18 deletions(-) diff --git a/test/aws/signer_test.exs b/test/aws/signer_test.exs index 6f95a60..4dcd42f 100644 --- a/test/aws/signer_test.exs +++ b/test/aws/signer_test.exs @@ -15,24 +15,10 @@ defmodule EthersKMS.AWS.SignerTest do KMSFixtures.kms_sign_response() end) - # transaction = %Ethers.Transaction{ - # type: :eip1559, - # chain_id: "0x539", - # nonce: "0xb66", - # gas: "0x5A82", - # from: "0x4eed49289Ac2876C9c966FC16b22F6eC5bf0817c", - # to: "0xFFcf8FDEE72ac11b5c542428B35EEF5769C409f0", - # value: "0x0", - # data: "0x06fdde03", - # gas_price: "0x10e7467522", - # max_fee_per_gas: "0x1448BAF2F5", - # max_priority_fee_per_gas: "0x0" - # } - transaction = %Ethers.Transaction.Eip1559{ chain_id: 1337, nonce: 2918, - gas: 23170, + gas: 23_170, to: "0xFFcf8FDEE72ac11b5c542428B35EEF5769C409f0", value: 0, input: Ethers.Utils.hex_decode!("0x06fdde03"), @@ -52,7 +38,7 @@ defmodule EthersKMS.AWS.SignerTest do transaction = %Ethers.Transaction.Eip1559{ chain_id: 1337, nonce: 2918, - gas: 23170, + gas: 23_170, to: "0xFFcf8FDEE72ac11b5c542428B35EEF5769C409f0", value: 0, input: Ethers.Utils.hex_decode!("0x06fdde03"), @@ -74,7 +60,7 @@ defmodule EthersKMS.AWS.SignerTest do transaction = %Ethers.Transaction.Eip1559{ chain_id: 1337, nonce: 2918, - gas: 23170, + gas: 23_170, to: "0xFFcf8FDEE72ac11b5c542428B35EEF5769C409f0", value: 0, input: Ethers.Utils.hex_decode!("0x06fdde03"), @@ -96,7 +82,7 @@ defmodule EthersKMS.AWS.SignerTest do transaction = %Ethers.Transaction.Eip1559{ chain_id: 1337, nonce: 2918, - gas: 23170, + gas: 23_170, to: "0xFFcf8FDEE72ac11b5c542428B35EEF5769C409f0", value: 0, input: Ethers.Utils.hex_decode!("0x06fdde03"),