parent
9570cd46de
commit
46ab151333
@ -0,0 +1,14 @@ |
||||
defmodule Explorer.Workers.ImportTransaction do |
||||
@moduledoc "Imports transaction by web3 conventions." |
||||
|
||||
alias Explorer.TransactionImporter |
||||
|
||||
@dialyzer {:nowarn_function, perform: 1} |
||||
def perform(hash) do |
||||
TransactionImporter.import(hash) |
||||
end |
||||
|
||||
def perform_later(hash) do |
||||
Exq.enqueue(Exq.Enqueuer, "default", __MODULE__, [hash]) |
||||
end |
||||
end |
@ -0,0 +1,28 @@ |
||||
defmodule Explorer.Workers.ImportTransactionTest do |
||||
use Explorer.DataCase |
||||
|
||||
alias Explorer.Repo |
||||
alias Explorer.Transaction |
||||
alias Explorer.Workers.ImportTransaction |
||||
|
||||
describe "perform/1" do |
||||
test "imports the requested transaction hash" do |
||||
use_cassette "import_transaction_perform_1" do |
||||
ImportTransaction.perform("0xf9a0959d5ccde33ec5221ddba1c6d7eaf9580a8d3512c7a1a60301362a98f926") |
||||
transaction = Transaction |> Repo.one |
||||
|
||||
assert transaction.hash == "0xf9a0959d5ccde33ec5221ddba1c6d7eaf9580a8d3512c7a1a60301362a98f926" |
||||
end |
||||
end |
||||
|
||||
test "when there is already a transaction with the requested hash" do |
||||
use_cassette "import_transaction_perform_1_duplicate" do |
||||
insert(:transaction, hash: "0xdc3a0dfd0bbffd5eabbe40fb13afbe35ac5f5c030bff148f3e50afe32974b291") |
||||
ImportTransaction.perform("0xdc3a0dfd0bbffd5eabbe40fb13afbe35ac5f5c030bff148f3e50afe32974b291") |
||||
transaction_count = Transaction |> Repo.all |> Enum.count |
||||
|
||||
assert transaction_count == 1 |
||||
end |
||||
end |
||||
end |
||||
end |
@ -0,0 +1,30 @@ |
||||
[ |
||||
{ |
||||
"request": { |
||||
"body": "{\"params\":[\"0xf9a0959d5ccde33ec5221ddba1c6d7eaf9580a8d3512c7a1a60301362a98f926\"],\"method\":\"eth_getTransactionByHash\",\"jsonrpc\":\"2.0\",\"id\":0}", |
||||
"headers": { |
||||
"Content-Type": "application/json" |
||||
}, |
||||
"method": "post", |
||||
"options": [], |
||||
"request_body": "", |
||||
"url": "https://sokol.poa.network" |
||||
}, |
||||
"response": { |
||||
"binary": false, |
||||
"body": "{\"jsonrpc\":\"2.0\",\"result\":{\"blockHash\":\"0x456ffeb893cac75274175b57bb3f12d3b6a3b7882ac9d60145d20861c4b03b7b\",\"blockNumber\":\"0xc4567\",\"chainId\":null,\"condition\":null,\"creates\":\"0x2265f9193ec79d072f3a617a22b27866968b88a6\",\"from\":\"0xdc55206f4a3acc56a603f31995676a6490824740\",\"gas\":\"0x370a2\",\"gasPrice\":\"0x12a05f200\",\"hash\":\"0xf9a0959d5ccde33ec5221ddba1c6d7eaf9580a8d3512c7a1a60301362a98f926\",\"input\":\"0x6060604052341561000f57600080fd5b7fb94ae47ec9f4248692e2ecf9740b67ab493f3dcc8452bedc7d9cd911c28d1ca5426040518082815260200191505060405180910390a1609e806100546000396000f300606060405260043610603f576000357c0100000000000000000000000000000000000000000000000000000000900463ffffffff168063557ed1ba146044575b600080fd5b3415604e57600080fd5b6054606a565b6040518082815260200191505060405180910390f35b6000429050905600a165627a7a7230582053883c0c39da080adc15a91094921659c200b3bb60aed9e49b79b0274da3f4010029\",\"nonce\":\"0x8225\",\"publicKey\":\"0x461e8f868e1e8cf9a85502d02f8ec9df3bae3f6f112bf44d3834d0c17881b309e494fcbbf9736cf2269fd5cdbb723de6d23ff81ecaae783eb629168aac5922c6\",\"r\":\"0x338c023600f50506a2ce04cec348f2ea8b1763822b3d97ae4ec3c1e9d726c0d\",\"raw\":\"0xf9014682822585012a05f200830370a28080b8f26060604052341561000f57600080fd5b7fb94ae47ec9f4248692e2ecf9740b67ab493f3dcc8452bedc7d9cd911c28d1ca5426040518082815260200191505060405180910390a1609e806100546000396000f300606060405260043610603f576000357c0100000000000000000000000000000000000000000000000000000000900463ffffffff168063557ed1ba146044575b600080fd5b3415604e57600080fd5b6054606a565b6040518082815260200191505060405180910390f35b6000429050905600a165627a7a7230582053883c0c39da080adc15a91094921659c200b3bb60aed9e49b79b0274da3f40100291ca00338c023600f50506a2ce04cec348f2ea8b1763822b3d97ae4ec3c1e9d726c0da05741c90b80bf15cb47031e24b92e7e37c46a98f73cb0971d35f2007085b32255\",\"s\":\"0x5741c90b80bf15cb47031e24b92e7e37c46a98f73cb0971d35f2007085b32255\",\"standardV\":\"0x1\",\"to\":null,\"transactionIndex\":\"0x0\",\"v\":\"0x1c\",\"value\":\"0x0\"},\"id\":0}\n", |
||||
"headers": { |
||||
"Date": "Tue, 06 Feb 2018 19:29:40 GMT", |
||||
"Content-Type": "application/json", |
||||
"Transfer-Encoding": "chunked", |
||||
"Connection": "keep-alive", |
||||
"Set-Cookie": "__cfduid=d960b03d6d06a976589ee2db667abee481517945380; expires=Wed, 06-Feb-19 19:29:40 GMT; path=/; domain=.poa.network; HttpOnly; Secure", |
||||
"Expect-CT": "max-age=604800, report-uri=\"https://report-uri.cloudflare.com/cdn-cgi/beacon/expect-ct\"", |
||||
"Server": "cloudflare", |
||||
"CF-RAY": "3e908501cdff6e2c-SJC" |
||||
}, |
||||
"status_code": 200, |
||||
"type": "ok" |
||||
} |
||||
} |
||||
] |
@ -0,0 +1,30 @@ |
||||
[ |
||||
{ |
||||
"request": { |
||||
"body": "{\"params\":[\"0xdc3a0dfd0bbffd5eabbe40fb13afbe35ac5f5c030bff148f3e50afe32974b291\"],\"method\":\"eth_getTransactionByHash\",\"jsonrpc\":\"2.0\",\"id\":5}", |
||||
"headers": { |
||||
"Content-Type": "application/json" |
||||
}, |
||||
"method": "post", |
||||
"options": [], |
||||
"request_body": "", |
||||
"url": "https://sokol.poa.network:443" |
||||
}, |
||||
"response": { |
||||
"binary": false, |
||||
"body": "{\"jsonrpc\":\"2.0\",\"result\":{\"blockHash\":\"0x8663df28453934be1e0fc59995d8b5295e83e4db689ade8b0244525f8f7c118a\",\"blockNumber\":\"0xc10ab\",\"chainId\":null,\"condition\":null,\"creates\":\"0x353fe3ffbf77edef7f9c352c47965a38c07e837c\",\"from\":\"0x8a35723e64a47764b9acfec5e647b39a4e5d635c\",\"gas\":\"0x381ae\",\"gasPrice\":\"0x77359400\",\"hash\":\"0xdc3a0dfd0bbffd5eabbe40fb13afbe35ac5f5c030bff148f3e50afe32974b291\",\"input\":\"0x6060604052341561000f57600080fd5b7fb94ae47ec9f4248692e2ecf9740b67ab493f3dcc8452bedc7d9cd911c28d1ca5426040518082815260200191505060405180910390a1609e806100546000396000f300606060405260043610603f576000357c0100000000000000000000000000000000000000000000000000000000900463ffffffff168063557ed1ba146044575b600080fd5b3415604e57600080fd5b6054606a565b6040518082815260200191505060405180910390f35b6000429050905600a165627a7a7230582053883c0c39da080adc15a91094921659c200b3bb60aed9e49b79b0274da3f4010029\",\"nonce\":\"0x9b62\",\"publicKey\":\"0xbd2c35eb20bfab52e22b8b9fbcfc3f5f8a927f7d6b800960026921929eeb0976a304639c785ce1a509900922d6ef8fd1222b7b48cdcb38c97b49c0f37c59c0f7\",\"r\":\"0x380bb4c084a241ffbf69ad1f52cd8689aeb986db451bf85d715b4d9afdd89b0d\",\"raw\":\"0xf90145829b628477359400830381ae8080b8f26060604052341561000f57600080fd5b7fb94ae47ec9f4248692e2ecf9740b67ab493f3dcc8452bedc7d9cd911c28d1ca5426040518082815260200191505060405180910390a1609e806100546000396000f300606060405260043610603f576000357c0100000000000000000000000000000000000000000000000000000000900463ffffffff168063557ed1ba146044575b600080fd5b3415604e57600080fd5b6054606a565b6040518082815260200191505060405180910390f35b6000429050905600a165627a7a7230582053883c0c39da080adc15a91094921659c200b3bb60aed9e49b79b0274da3f40100291ba0380bb4c084a241ffbf69ad1f52cd8689aeb986db451bf85d715b4d9afdd89b0da01b1b1cca94b24cabba08bcc5d4fb99f2fdcb4f1f76d80091c061771040af3432\",\"s\":\"0x1b1b1cca94b24cabba08bcc5d4fb99f2fdcb4f1f76d80091c061771040af3432\",\"standardV\":\"0x0\",\"to\":null,\"transactionIndex\":\"0x0\",\"v\":\"0x1b\",\"value\":\"0x0\"},\"id\":5}\n", |
||||
"headers": { |
||||
"Date": "Tue, 06 Feb 2018 03:41:44 GMT", |
||||
"Content-Type": "application/json", |
||||
"Transfer-Encoding": "chunked", |
||||
"Connection": "keep-alive", |
||||
"Set-Cookie": "__cfduid=db1f077d751ae0ba2508cbbe43d8047de1517888504; expires=Wed, 06-Feb-19 03:41:44 GMT; path=/; domain=.poa.network; HttpOnly; Secure", |
||||
"Expect-CT": "max-age=604800, report-uri=\"https://report-uri.cloudflare.com/cdn-cgi/beacon/expect-ct\"", |
||||
"Server": "cloudflare", |
||||
"CF-RAY": "3e8b1871fa3d6d42-SJC" |
||||
}, |
||||
"status_code": 200, |
||||
"type": "ok" |
||||
} |
||||
} |
||||
] |
Loading…
Reference in new issue