diff --git a/test/support/test_token.ex b/test/support/test_token.ex index 7b11b63..0ff0051 100644 --- a/test/support/test_token.ex +++ b/test/support/test_token.ex @@ -1,4 +1,5 @@ defmodule TTEth.TestToken do + @moduledoc false use TTEth.Contract, abi_file: Application.app_dir(:tt_eth, "priv/fixtures/contract_abis/TestToken.abi") end diff --git a/test/tt_eth/transactions/eip1559_transaction_test.exs b/test/tt_eth/transactions/eip1559_transaction_test.exs index 1597a62..a19aad8 100644 --- a/test/tt_eth/transactions/eip1559_transaction_test.exs +++ b/test/tt_eth/transactions/eip1559_transaction_test.exs @@ -5,7 +5,7 @@ defmodule TTEth.Transactions.EIP1559TransactionTest do alias TTEth.Wallet # Polygon Mumbai. - @chain_id 80001 + @chain_id 80_001 @private_key_human "0x62aa6ec41b56439d2c5df352c45a00389cef262b3761e13c6481e35ab027d262" @to_address_human "0x38f153fdd399ff2cf64704c6a4b16d3fd9ddcd69" @@ -113,7 +113,7 @@ defmodule TTEth.Transactions.EIP1559TransactionTest do data: @tx_data, chain_id: @chain_id, nonce: @nonce, - gas_limit: 21000, + gas_limit: 21_000, max_fee_per_gas: 3_000_000_000, max_priority_fee_per_gas: 3_000_000_001, value: 0 diff --git a/test/tt_eth/wallet_test.exs b/test/tt_eth/wallet_test.exs index f56b324..24b3e41 100644 --- a/test/tt_eth/wallet_test.exs +++ b/test/tt_eth/wallet_test.exs @@ -39,6 +39,64 @@ defmodule TTEth.WalletTest do end end + describe "sign/2" do + setup :build_wallet + + test "given a wallet and digest, signs the digest", %{wallet: wallet} do + wallet + |> Wallet.sign("some plaintext" |> TTEth.keccak()) + |> assert_match({:ok, {<<_signature::512>>, recovery_id}} when recovery_id in [0, 1]) + end + + test "returns an error tuple if a failure happens", %{wallet: wallet} do + wallet + |> Wallet.sign("some plaintext") + |> assert_equal({:error, :wrong_message_size}) + end + end + + describe "sign!/2" do + setup :build_wallet + + test "same as sign/2", %{wallet: wallet} do + digest = "some plaintext" |> TTEth.keccak() + + {:ok, compact_signature} = + wallet + |> Wallet.sign(digest) + + wallet + |> Wallet.sign!(digest) + |> assert_match(^compact_signature) + end + end + + describe "personal_sign/2" do + setup :build_wallet + + test "signs a plaintext using the EIP-191 standard", %{wallet: wallet} do + wallet + |> Wallet.personal_sign("some plaintext") + |> assert_match({:ok, {v, _r, _s}} when v in [27, 28]) + end + + test "returns an error tuple if a failure happens" + end + + describe "personal_sign!/2" do + setup :build_wallet + + test "same as personal_sign/2", %{wallet: wallet} do + {:ok, components} = + wallet + |> Wallet.personal_sign("some plaintext") + + wallet + |> Wallet.personal_sign!("some plaintext") + |> assert_match(^components) + end + end + ## Private. defp assert_match_ternary_wallet(wallet) do @@ -65,4 +123,7 @@ defmodule TTEth.WalletTest do } }) end + + defp build_wallet(_), + do: %{wallet: Wallet.new()} end diff --git a/test/tt_eth_test.exs b/test/tt_eth_test.exs index 06c4f0c..1971076 100644 --- a/test/tt_eth_test.exs +++ b/test/tt_eth_test.exs @@ -3,7 +3,7 @@ defmodule TTEthTest do import TTEth, only: [binary_to_hex!: 1] doctest TTEth, import: true - @chain_id 12345 + @chain_id 12_345 describe "new_keypair/0" do test "generates a public and private key" do