Skip to content

Commit

Permalink
Fix transaction hex_decode when deploy with local-signer
Browse files Browse the repository at this point in the history
  • Loading branch information
cao7113 committed Oct 18, 2024
1 parent 2811b29 commit c412e04
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/ethers/transaction.ex
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,7 @@ defmodule Ethers.Transaction do

defp do_post_process(_key, {:error, reason}), do: {:error, reason}

defp hex_decode(nil), do: ""
defp hex_decode(""), do: ""
defp hex_decode("0x"), do: ""

Expand Down
18 changes: 18 additions & 0 deletions test/ethers/counter_contract_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ defmodule Ethers.CounterContractTest do
alias Ethers.Contract.Test.CounterContract

@from "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266"
@from_private_key "0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80"

describe "contract deployment" do
test "Can deploy a contract on blockchain" do
Expand All @@ -29,6 +30,23 @@ defmodule Ethers.CounterContractTest do

assert {:ok, _address} = Ethers.deployed_address(tx_hash)
end

test "Can deploy a contract with local signer" do
encoded_constructor = CounterContract.constructor(100)

assert {:ok, tx_hash} =
Ethers.deploy(CounterContract,
encoded_constructor: encoded_constructor,
from: @from,
signer: Ethers.Signer.Local,
signer_opts: [private_key: @from_private_key]
)

wait_for_transaction!(tx_hash)

assert {:ok, address} = Ethers.deployed_address(tx_hash)
assert {:ok, 100} = CounterContract.get() |> Ethers.call(to: address)
end
end

describe "inspecting function calls" do
Expand Down

0 comments on commit c412e04

Please sign in to comment.