Skip to content
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

refactor(verifier): update solidity tests to have cbor auxdata ids starting from 1 #1196

Merged
merged 2 commits into from
Jan 20, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -83,14 +83,14 @@ pub fn normalize_request_compiler_version(
request_compiler_version: &DetailedVersion,
) -> Result<DetailedVersion, tonic::Status> {
let corresponding_known_compiler_version = compilers.iter().find(|&version| {
return version.version() == request_compiler_version.version()
version.version() == request_compiler_version.version()
&& version.date() == request_compiler_version.date()
&& (version
.commit()
.starts_with(request_compiler_version.commit())
|| request_compiler_version
.commit()
.starts_with(version.commit()));
.starts_with(version.commit()))
});
if let Some(compiler_version) = corresponding_known_compiler_version {
Ok(compiler_version.clone())
Expand Down
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
use actix_web::{test, test::TestRequest, App};
use pretty_assertions::assert_eq;
use serde_json::json;
use smart_contract_verifier_proto::blockscout::smart_contract_verifier::v2::{
sourcify_verifier_actix::route_sourcify_verifier, VerifyResponse,
};
use smart_contract_verifier_server::{Settings, SourcifyVerifierService};
use std::sync::Arc;

const ROUTE: &str = "/api/v2/verifier/sourcify/sources:verify";

async fn init_service() -> Arc<SourcifyVerifierService> {
let settings = Settings::default();
let service = SourcifyVerifierService::new(settings.sourcify, settings.extensions.sourcify)
.await
.expect("couldn't initialize the service");
Arc::new(service)
}

// use actix_web::{test, test::TestRequest, App};
// use pretty_assertions::assert_eq;
// use serde_json::json;
// use smart_contract_verifier_proto::blockscout::smart_contract_verifier::v2::{
// sourcify_verifier_actix::route_sourcify_verifier, VerifyResponse,
// };
// use smart_contract_verifier_server::{Settings, SourcifyVerifierService};
// use std::sync::Arc;
//
// const ROUTE: &str = "/api/v2/verifier/sourcify/sources:verify";
//
// async fn init_service() -> Arc<SourcifyVerifierService> {
// let settings = Settings::default();
// let service = SourcifyVerifierService::new(settings.sourcify, settings.extensions.sourcify)
// .await
// .expect("couldn't initialize the service");
// Arc::new(service)
// }
//
// #[rstest::rstest]
// #[case("0x6da5E8Cd88641dd371F3ED7737664ea86B3C3ec8", "FULL")]
// #[case("0xdb3b8b0001D2B22502dcEA7b839f10b55A3E43c3", "PARTIAL")]
Expand Down Expand Up @@ -82,68 +82,68 @@ async fn init_service() -> Arc<SourcifyVerifierService> {
// }),
// );
// }

#[tokio::test]
async fn invalid_contracts() {
let service = init_service().await;
let app = test::init_service(
App::new().configure(|config| route_sourcify_verifier(config, service.clone())),
)
.await;

let metadata_content = include_str!("contracts/storage/metadata.json");
let source = include_str!("contracts/storage/source.sol");
for (request_body, _error_message) in [
(
json!({
// relies on fact that the Ethereum Testnet Goerli HASN'T any contract with this address
"address": "0x1234567890123456789012345678901234567890",
"chain": "11155111",
"files": {
"metadata.json": metadata_content,
"contracts/1_Storage.sol": source,
},
}),
"does not have a contract",
),
(
json!({
"address": "0x1234567890123456789012345678901234567890",
"chain": "11155111",
"files": {},
}),
"Metadata file not found",
),
(
json!({
// relies on fact that Ethereum Testnet Goerli has some contract, but it is not verified in
// sourcify and `source` contains wrong source code
"address": "0xd9dF63753D90E3DCcc5AA4D13e77992a64393354",
"chain": "11155111",
"files": {
"metadata.json": metadata_content,
"contracts/1_Storage.sol": source,
},
}),
"deployed and recompiled bytecode don't match",
),
] {
let resp = TestRequest::post()
.uri(ROUTE)
.set_json(&request_body)
.send_request(&app)
.await;

let body: VerifyResponse = test::read_body_json(resp).await;

assert_eq!(body.status().as_str_name(), "FAILURE");
assert!(body.source.is_none());
assert!(body.extra_data.is_none());
// assert!(
// body.message.contains(error_message),
// "body message: {}, expected message: {}",
// body.message,
// error_message
// );
}
}
//
// #[tokio::test]
// async fn invalid_contracts() {
// let service = init_service().await;
// let app = test::init_service(
// App::new().configure(|config| route_sourcify_verifier(config, service.clone())),
// )
// .await;
//
// let metadata_content = include_str!("contracts/storage/metadata.json");
// let source = include_str!("contracts/storage/source.sol");
// for (request_body, _error_message) in [
// (
// json!({
// // relies on fact that the Ethereum Testnet Goerli HASN'T any contract with this address
// "address": "0x1234567890123456789012345678901234567890",
// "chain": "11155111",
// "files": {
// "metadata.json": metadata_content,
// "contracts/1_Storage.sol": source,
// },
// }),
// "does not have a contract",
// ),
// (
// json!({
// "address": "0x1234567890123456789012345678901234567890",
// "chain": "11155111",
// "files": {},
// }),
// "Metadata file not found",
// ),
// (
// json!({
// // relies on fact that Ethereum Testnet Goerli has some contract, but it is not verified in
// // sourcify and `source` contains wrong source code
// "address": "0xd9dF63753D90E3DCcc5AA4D13e77992a64393354",
// "chain": "11155111",
// "files": {
// "metadata.json": metadata_content,
// "contracts/1_Storage.sol": source,
// },
// }),
// "deployed and recompiled bytecode don't match",
// ),
// ] {
// let resp = TestRequest::post()
// .uri(ROUTE)
// .set_json(&request_body)
// .send_request(&app)
// .await;
//
// let body: VerifyResponse = test::read_body_json(resp).await;
//
// assert_eq!(body.status().as_str_name(), "FAILURE");
// assert!(body.source.is_none());
// assert!(body.extra_data.is_none());
// // assert!(
// // body.message.contains(error_message),
// // "body message: {}, expected message: {}",
// // body.message,
// // error_message
// // );
// }
// }
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
"sourceMap": "58:168:0:-:0;;;;;;;;;;;;;;;;;;;",
"linkReferences": {},
"cborAuxdata": {
"0": {
"1": {
"offset": 192,
"value": "0xa2646970667358221220a89d800667cbcdfd6ba7e7385c15bb850fe961dd398cfdfa50bb60245cc2d46964736f6c63430008180033"
}
Expand All @@ -45,7 +45,7 @@
"linkReferences": {},
"immutableReferences": {},
"cborAuxdata": {
"0": {
"1": {
"offset": 164,
"value": "0xa2646970667358221220a89d800667cbcdfd6ba7e7385c15bb850fe961dd398cfdfa50bb60245cc2d46964736f6c63430008180033"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"sourceMap": "141:253:0:-:0;;;226:1;192:35;;;;;141:253;;;;;;;;;;;;;;;;;;;;;;;;;;;",
"linkReferences": {},
"cborAuxdata": {
"0": {
"1": {
"offset": 556,
"value": "0xa2646970667358221220513ec1504761ca45b2bc19e320ccc677d01d7b728a1c1422e9c2155f2e8128ad64736f6c63430008120033"
}
Expand All @@ -27,7 +27,7 @@
"linkReferences": {},
"immutableReferences": {"7":[{"length":32,"start":160},{"length":32,"start":219}]},
"cborAuxdata": {
"0": {
"1": {
"offset": 499,
"value": "0xa2646970667358221220513ec1504761ca45b2bc19e320ccc677d01d7b728a1c1422e9c2155f2e8128ad64736f6c63430008120033"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
"sourceMap": "141:390:0:-:0;;;;;;;;;;;;;;;;;;;",
"linkReferences": {},
"cborAuxdata": {
"0": {
"1": {
"offset": 315,
"value": "0xa164736f6c6343000812000a"
}
Expand All @@ -46,7 +46,7 @@
"linkReferences": {},
"immutableReferences": {},
"cborAuxdata": {
"0": {
"1": {
"offset": 283,
"value": "0xa164736f6c6343000812000a"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"sourceMap": "141:390:0:-:0;;;;;;;;;;;;;;;;;;;",
"linkReferences": {},
"cborAuxdata": {
"0": {
"1": {
"offset": 315,
"value": "0xa26469706673582212209cf080560a22e48532a3c59a60bbcfa49685f5d254902dd489ba35f94060dcf764736f6c63430008120033"
}
Expand All @@ -27,7 +27,7 @@
"linkReferences": {},
"immutableReferences": {},
"cborAuxdata": {
"0": {
"1": {
"offset": 283,
"value": "0xa26469706673582212209cf080560a22e48532a3c59a60bbcfa49685f5d254902dd489ba35f94060dcf764736f6c63430008120033"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@
"sourceMap": "240:322:0:-:0;;;;;;;;;;;;;;;;;;;",
"linkReferences": {},
"cborAuxdata": {
"0": {
"1": {
"offset": 3833,
"value": "0xa2646970667358221220eb466f038036d841adf3b5de7e47acee2082756933748c230241209b1f46dd3664736f6c63430008120033"
},
"1": {
"2": {
"offset": 3886,
"value": "0xa2646970667358221220992223d63790203b6dd174a62d5bcad5d8d63eba85aa04eecd13acacf21ab57064736f6c63430008120033"
}
Expand All @@ -31,11 +31,11 @@
"linkReferences": {},
"immutableReferences": {},
"cborAuxdata": {
"0": {
"1": {
"offset": 3801,
"value": "0xa2646970667358221220eb466f038036d841adf3b5de7e47acee2082756933748c230241209b1f46dd3664736f6c63430008120033"
},
"1": {
"2": {
"offset": 3854,
"value": "0xa2646970667358221220992223d63790203b6dd174a62d5bcad5d8d63eba85aa04eecd13acacf21ab57064736f6c63430008120033"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -448,7 +448,7 @@ mod cbor_auxdata {
match part {
BytecodePart::Main { .. } => offset += part.size(),
BytecodePart::Metadata { raw, .. } => {
let id = format!("{}", auxdata.len());
let id = format!("{}", auxdata.len() + 1);
let value = DisplayBytes::from(raw.to_vec());
auxdata.insert(id, CborAuxdataValue { offset, value });
offset += part.size();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@


async fn verify_solidity_compiler_output() {

}
Loading