From 7b82a3442d25aa667bf76251ce28f7516f9dd8c8 Mon Sep 17 00:00:00 2001 From: Stamates Date: Fri, 3 Aug 2018 10:03:53 -0400 Subject: [PATCH] Added test that contract_creadted_address_hash is nil if to_address is not nil --- apps/explorer/test/explorer/import_test.exs | 69 +++++++++++++++++++++ 1 file changed, 69 insertions(+) diff --git a/apps/explorer/test/explorer/import_test.exs b/apps/explorer/test/explorer/import_test.exs index a5d7a2f451..3569daf882 100644 --- a/apps/explorer/test/explorer/import_test.exs +++ b/apps/explorer/test/explorer/import_test.exs @@ -179,5 +179,74 @@ defmodule Explorer.Chain.ImportTest do refute transaction.created_contract_address_hash == nil end + + test "when the transaction has a to_address and an internal transaction with type create it does not populates the denormalized created_contract_address_hash" do + smart_contract_bytecode = + "0x608060405234801561001057600080fd5b5060df8061001f6000396000f3006080604052600436106049576000357c0100000000000000000000000000000000000000000000000000000000900463ffffffff16806360fe47b114604e5780636d4ce63c146078575b600080fd5b348015605957600080fd5b5060766004803603810190808035906020019092919050505060a0565b005b348015608357600080fd5b50608a60aa565b6040518082815260200191505060405180910390f35b8060008190555050565b600080549050905600a165627a7a7230582040d82a7379b1ee1632ad4d8a239954fd940277b25628ead95259a85c5eddb2120029" + + from_address_hash = "0xe8ddc5c7a2d2f0d7a9798459c0104fdf5e987aca" + to_address_hash = "0xf7ddc5c7a2d2f0d7a9798459c0104fdf5e9a7bbb" + created_contract_address_hash = "0x8bf38d4764929064f2d4d3a56520a76ab3df415b" + transaction_hash = "0x3a3eb134e6792ce9403ea4188e5e79693de9e4c94e499db132be086400da79e6" + + options = %{ + addresses: %{ + params: [ + %{hash: from_address_hash}, + %{ + contract_code: smart_contract_bytecode, + hash: created_contract_address_hash + } + ] + }, + transactions: %{ + params: [ + %{ + from_address_hash: from_address_hash, + to_address_hash: from_address_hash, + gas: 4_677_320, + gas_price: 1, + hash: transaction_hash, + input: "0x", + nonce: 0, + r: 0, + s: 0, + v: 0, + value: 0 + } + ], + on_conflict: :replace_all + }, + internal_transactions: %{ + params: [ + %{ + block_number: 35, + call_type: "call", + created_contract_code: smart_contract_bytecode, + created_contract_address_hash: created_contract_address_hash, + from_address_hash: from_address_hash, + gas: 4_677_320, + gas_used: 27770, + index: 0, + init: + "0x6060604052341561000c57fe5b5b6101a68061001c6000396000f300606060405263ffffffff7c01000000000000000000000000000000000000000000000000000000006000350416631d3b9edf811461005b57806366098d4f1461007b578063a12f69e01461009b578063f4f3bdc1146100bb575bfe5b6100696004356024356100db565b60408051918252519081900360200190f35b61006960043560243561010a565b60408051918252519081900360200190f35b610069600435602435610124565b60408051918252519081900360200190f35b610069600435602435610163565b60408051918252519081900360200190f35b60008282028315806100f757508284828115156100f457fe5b04145b15156100ff57fe5b8091505b5092915050565b6000828201838110156100ff57fe5b8091505b5092915050565b60008080831161013057fe5b828481151561013b57fe5b049050828481151561014957fe5b0681840201841415156100ff57fe5b8091505b5092915050565b60008282111561016f57fe5b508082035b929150505600a165627a7a7230582020c944d8375ca14e2c92b14df53c2d044cb99dc30c3ba9f55e2bcde87bd4709b0029", + output: "0x", + trace_address: [], + transaction_hash: transaction_hash, + type: "create", + value: 0 + } + ] + } + } + + assert {:ok, _} = Import.all(options) + + transaction = + Explorer.Repo.one(from(transaction in Explorer.Chain.Transaction, where: transaction.hash == ^transaction_hash)) + + assert transaction.created_contract_address_hash == nil + end end + end