|
|
|
@ -28,6 +28,34 @@ defmodule Explorer.SmartContract.VerifierTest do |
|
|
|
|
assert abi != nil |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
test "verifies the generated bytecode with external libraries" do |
|
|
|
|
contract_data = |
|
|
|
|
"#{System.cwd!()}/test/support/fixture/smart_contract/compiler_tests.json" |
|
|
|
|
|> File.read!() |
|
|
|
|
|> Jason.decode!() |
|
|
|
|
|> List.first() |
|
|
|
|
|
|
|
|
|
compiler_version = contract_data["compiler_version"] |
|
|
|
|
external_libraries = contract_data["external_libraries"] |
|
|
|
|
name = contract_data["name"] |
|
|
|
|
optimize = contract_data["optimize"] |
|
|
|
|
contract = contract_data["contract"] |
|
|
|
|
expected_bytecode = contract_data["expected_bytecode"] |
|
|
|
|
|
|
|
|
|
contract_address = insert(:contract_address, contract_code: "0x" <> expected_bytecode) |
|
|
|
|
|
|
|
|
|
params = %{ |
|
|
|
|
"contract_source_code" => contract, |
|
|
|
|
"compiler_version" => compiler_version, |
|
|
|
|
"name" => name, |
|
|
|
|
"optimization" => optimize, |
|
|
|
|
"external_libraries" => external_libraries |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
assert {:ok, %{abi: abi}} = Verifier.evaluate_authenticity(contract_address.hash, params) |
|
|
|
|
assert abi != nil |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
test "returns error when bytecode doesn't match", %{contract_code_info: contract_code_info} do |
|
|
|
|
contract_address = insert(:contract_address, contract_code: contract_code_info.bytecode) |
|
|
|
|
|
|
|
|
|