-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
tests rpc v1 #78
Open
Cristhian9292
wants to merge
17
commits into
main
Choose a base branch
from
62-rpc-client-tests
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
tests rpc v1 #78
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
79ce6b9
tests rpc v1
Cristhian9292 d0531e7
format
Cristhian9292 932e778
format
Cristhian9292 f66bbb7
asserts improved
Cristhian9292 3fbdefe
refactor
Cristhian9292 0c732e8
prenthesis removed
Cristhian9292 16d8fac
fixes
Cristhian9292 075a965
credo
Cristhian9292 1519a16
Merge branch 'main' of https://github.com/lambdaclass/ethereum_war_ga…
Cristhian9292 47f8757
format
Cristhian9292 6e2d615
rinkeby
Cristhian9292 d3b095c
infura
Cristhian9292 83dde57
test fix
Cristhian9292 d1ff8e5
f
Cristhian9292 488309a
format % fix
Cristhian9292 5feae52
credo
Cristhian9292 3c15362
fix
Cristhian9292 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,123 @@ | ||
defmodule EthClientTest.Rpc do | ||
use ExUnit.Case | ||
alias EthClient | ||
alias EthClient.Context | ||
alias EthClient.Rpc | ||
|
||
@bin_path "../contracts/src/bin/Storage.bin" | ||
|
||
def transaction_deploy do | ||
:ok = EthClient.set_chain("rinkeby") | ||
Context.set_rpc_host("https://rinkeby.infura.io/v3/56725ef0a57448cdb2c5dc36c277460b") | ||
{:ok, data} = File.read(@bin_path) | ||
data = "0x" <> data | ||
|
||
caller = Context.user_account() | ||
caller_address = String.downcase(caller.address) | ||
|
||
%{ | ||
data: data, | ||
caller_address: caller_address | ||
} | ||
end | ||
|
||
setup_all do | ||
transaction_deploy() | ||
end | ||
|
||
describe "Rpc Module" do | ||
test "[SUCCESS] Send raw transaction", state do | ||
caller = Context.user_account() | ||
|
||
raw_tx = | ||
EthClient.build_raw_tx( | ||
0, | ||
EthClient.nonce(caller.address), | ||
EthClient.gas_limit(state[:data], caller.address), | ||
EthClient.gas_price(), | ||
data: state[:data] | ||
) | ||
|
||
tx_hash = EthClient.sign_transaction(raw_tx, Context.user_account().private_key) | ||
|
||
{:ok, tx_hash} = Rpc.send_raw_transaction(tx_hash) | ||
assert tx_hash =~ "0x" | ||
end | ||
|
||
test "[SUCCESS] Estimate Gas", state do | ||
transaction_map = %{data: state[:data], from: state[:caller_address], to: nil} | ||
{:ok, gas} = Rpc.estimate_gas(transaction_map) | ||
assert gas =~ "0x" | ||
end | ||
|
||
test "[SUCCESS] Get Transaction Count", state do | ||
{:ok, count} = Rpc.get_transaction_count(state[:caller_address]) | ||
assert count =~ "0x" | ||
end | ||
|
||
test "[SUCCESS] Gas Price" do | ||
{:ok, gas_price} = Rpc.gas_price() | ||
assert gas_price =~ "0x" | ||
end | ||
|
||
test "[SUCCESS] Get Transaction by Hash" do | ||
{:ok, transaction_map} = | ||
Rpc.get_transaction_by_hash( | ||
"0x3c249fcbb9ac3095cbe8196e6dba5d0aa0d868f2ebc7c857c8a22144fcbad07c" | ||
) | ||
|
||
assert %{ | ||
"blockHash" => _, | ||
"blockNumber" => _, | ||
"from" => _, | ||
"gas" => _, | ||
"gasPrice" => _, | ||
"hash" => _, | ||
"input" => _, | ||
"nonce" => _, | ||
"r" => _, | ||
"s" => _, | ||
"to" => _to, | ||
"transactionIndex" => _, | ||
"type" => _, | ||
"v" => _, | ||
"value" => _ | ||
} = transaction_map | ||
end | ||
|
||
test "[SUCCESS] Get Transaction Receipt" do | ||
{:ok, receipt_map} = | ||
Rpc.get_transaction_receipt( | ||
"0x3c249fcbb9ac3095cbe8196e6dba5d0aa0d868f2ebc7c857c8a22144fcbad07c" | ||
) | ||
|
||
assert %{ | ||
"blockHash" => _blockhash, | ||
"blockNumber" => _blocknumber, | ||
"from" => _from, | ||
"logs" => [], | ||
"status" => _status, | ||
"to" => _to, | ||
"type" => _type | ||
} = receipt_map | ||
end | ||
|
||
test "[SUCCESS] Get Code", state do | ||
assert {:ok, "0x"} == Rpc.get_code(state[:caller_address]) | ||
end | ||
|
||
test "[SUCCESS] Get Call" do | ||
call_map = %{} | ||
assert {:ok, "0x"} == Rpc.call(call_map) | ||
end | ||
|
||
test "[SUCCESS] Get Logs" do | ||
assert {:ok, _log_list} = Rpc.get_logs(%{}) | ||
end | ||
|
||
test "[SUCCESS] Get Balance", state do | ||
{:ok, balance} = Rpc.get_balance(state[:caller_address]) | ||
assert balance =~ "0x" | ||
end | ||
end | ||
end |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that this can be achieved using "EthClient.deploy(bin_path)", as all the variables should have been setted up in env variables, there should not be a need to set them by hand. You can also use 'EthClient,Context.all()" to get all the context configurations. We can discuss this if it is needed.