Skip to content

Commit

Permalink
Add multiple metadata test
Browse files Browse the repository at this point in the history
  • Loading branch information
lok52 committed Nov 14, 2023
1 parent 2b67796 commit d2435c8
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -231,8 +231,8 @@ message LookupMethodsRequest {
message LookupMethodsResponse {
message Method {
string file_name = 1;
int32 file_offset = 2;
int32 length = 3;
uint32 file_offset = 2;
uint32 length = 3;
}
map<string, Method> methods = 1;
}
Original file line number Diff line number Diff line change
Expand Up @@ -226,10 +226,10 @@ definitions:
type: string
fileOffset:
type: integer
format: int32
format: int64
length:
type: integer
format: int32
format: int64
SourceMatchType:
type: string
enum:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,14 @@ impl From<LookupMethodsResponse> for LookupMethodsResponseWrapper {
Self(proto::LookupMethodsResponse {
methods: response
.methods
.iter()
.into_iter()
.map(|(selector, method)| {
(
selector.clone(),
selector,
proto::lookup_methods_response::Method {
file_name: method.filename.clone(),
file_offset: method.offset as i32,
length: method.length as i32,
file_name: method.filename,
file_offset: method.offset as u32,
length: method.length as u32,
},
)
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use blockscout_service_launcher::{
launcher::ConfigSettings,
test_server::{get_test_server_settings, init_server, send_post_request},
};
use ethers_solc::{CompilerInput, CompilerOutput, EvmVersion, Solc};
use ethers_solc::{artifacts::Severity, CompilerInput, CompilerOutput, EvmVersion, Solc};
use lazy_static::lazy_static;
use rstest::rstest;
use serde::Deserialize;
Expand Down Expand Up @@ -102,6 +102,14 @@ async fn test_lookup_methods(#[files("tests/test_cases_lookup_methods/*")] test_
let inputs = CompilerInput::new(test_dir).expect("failed to read dir");
let input = inputs[0].clone().evm_version(EvmVersion::London);
let output = solc.compile(&input).expect("failed to compile");
let errors = output
.errors
.iter()
.filter(|e| e.severity == Severity::Error)
.collect::<Vec<_>>();
if !errors.is_empty() {
panic!("errors during compilation: {:?}", errors);
}

let (request, methods) = process_compiler_output(&output, &test_case.contract_name).unwrap();
let res: LookupMethodsResponse = send_post_request(&base, ROUTE, &request).await;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// SPDX-License-Identifier: GPL-3.0
pragma solidity =0.8.7;

contract A {
function a() public pure returns (bytes memory) {
return "";
}
}

contract B {
bytes code;

constructor() {
code = type(A).creationCode;
}

function a() public pure returns (bytes memory) {
return type(A).creationCode;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"version": "0.8.7",
"contract_name": "B"
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,11 @@ pub struct LookupMethodsResponse {
pub fn find_methods(request: LookupMethodsRequest) -> LookupMethodsResponse {
let methods = parse_selectors(request.abi);
let opcodes = disassemble_bytecode(&request.bytecode);
let opcodes = opcodes.as_slice();

let methods = methods
.into_iter()
.filter_map(|(func_sig, selector)| {
let func_index = match find_src_map_index(&selector, opcodes) {
let func_index = match find_src_map_index(&selector, &opcodes) {
Some(i) => i,
None => {
tracing::warn!(func_sig, "function not found");
Expand All @@ -49,7 +48,7 @@ pub fn find_methods(request: LookupMethodsRequest) -> LookupMethodsResponse {
};
Some((hex::encode(selector), method))
})
.collect::<BTreeMap<String, Method>>();
.collect();
LookupMethodsResponse { methods }
}

Expand Down

0 comments on commit d2435c8

Please sign in to comment.