-
Notifications
You must be signed in to change notification settings - Fork 182
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
Walnut: Enable multi-class verification via single API request #2456
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change | ||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -5,7 +5,6 @@ | |||||||||||||||
use console::{pad_str, Alignment, Style, StyledObject}; | ||||||||||||||||
use dojo_world::metadata::get_default_namespace_from_ws; | ||||||||||||||||
use dojo_world::migration::strategy::MigrationStrategy; | ||||||||||||||||
use futures::future::join_all; | ||||||||||||||||
use reqwest::StatusCode; | ||||||||||||||||
use scarb::core::Workspace; | ||||||||||||||||
use serde::Serialize; | ||||||||||||||||
|
@@ -61,50 +60,32 @@ | |||||||||||||||
// Collect source code | ||||||||||||||||
let source_code = collect_source_code(root_dir)?; | ||||||||||||||||
|
||||||||||||||||
// Prepare verification payloads | ||||||||||||||||
let mut verification_tasks = Vec::new(); | ||||||||||||||||
let mut class_tags = Vec::new(); | ||||||||||||||||
let mut class_names = Vec::new(); | ||||||||||||||||
let mut class_hashes = Vec::new(); | ||||||||||||||||
|
||||||||||||||||
for contract_migration in &migration_strategy.contracts { | ||||||||||||||||
let class_name = get_class_name_from_artifact_path( | ||||||||||||||||
&contract_migration.artifact_path, | ||||||||||||||||
&default_namespace, | ||||||||||||||||
)?; | ||||||||||||||||
let verification_payload = VerificationPayload { | ||||||||||||||||
class_name: class_name.clone(), | ||||||||||||||||
class_hash: contract_migration.diff.local_class_hash.to_hex_string(), | ||||||||||||||||
rpc_url: rpc_url.clone(), | ||||||||||||||||
source_code: source_code.clone(), | ||||||||||||||||
}; | ||||||||||||||||
class_tags.push(contract_migration.diff.tag.clone()); | ||||||||||||||||
verification_tasks.push(verify_class(verification_payload, &api_url, &api_key)); | ||||||||||||||||
class_names.push(class_name); | ||||||||||||||||
class_hashes.push(contract_migration.diff.local_class_hash.to_hex_string()); | ||||||||||||||||
} | ||||||||||||||||
|
||||||||||||||||
for class_migration in &migration_strategy.models { | ||||||||||||||||
let class_name = | ||||||||||||||||
get_class_name_from_artifact_path(&class_migration.artifact_path, &default_namespace)?; | ||||||||||||||||
let verification_payload = VerificationPayload { | ||||||||||||||||
class_name: class_name.clone(), | ||||||||||||||||
class_hash: class_migration.diff.local_class_hash.to_hex_string(), | ||||||||||||||||
rpc_url: rpc_url.clone(), | ||||||||||||||||
source_code: source_code.clone(), | ||||||||||||||||
}; | ||||||||||||||||
class_tags.push(class_migration.diff.tag.clone()); | ||||||||||||||||
verification_tasks.push(verify_class(verification_payload, &api_url, &api_key)); | ||||||||||||||||
class_names.push(class_name); | ||||||||||||||||
class_hashes.push(class_migration.diff.local_class_hash.to_hex_string()); | ||||||||||||||||
} | ||||||||||||||||
|
||||||||||||||||
// Run all verification tasks | ||||||||||||||||
let results = join_all(verification_tasks).await; | ||||||||||||||||
let verification_payload = | ||||||||||||||||
VerificationPayload { class_names, class_hashes, rpc_url, source_code }; | ||||||||||||||||
|
||||||||||||||||
for (i, result) in results.into_iter().enumerate() { | ||||||||||||||||
match result { | ||||||||||||||||
Ok(message) => { | ||||||||||||||||
ui.print(subtitle(format!("{}: {}", class_tags[i], message))); | ||||||||||||||||
} | ||||||||||||||||
Err(e) => { | ||||||||||||||||
ui.print(subtitle(format!("{}: {}", class_tags[i], e))); | ||||||||||||||||
} | ||||||||||||||||
} | ||||||||||||||||
// Send verification request | ||||||||||||||||
match verify_classes(verification_payload, &api_url, &api_key).await { | ||||||||||||||||
Ok(message) => ui.print(subtitle(message)), | ||||||||||||||||
Err(e) => ui.print(subtitle(e.to_string())), | ||||||||||||||||
Comment on lines
+85
to
+88
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Propagate errors from the verification request Ohayo, sensei! Currently, if Apply this diff to propagate the error: -match verify_classes(verification_payload, &api_url, &api_key).await {
- Ok(message) => ui.print(subtitle(message)),
- Err(e) => ui.print(subtitle(e.to_string())),
-}
+let message = verify_classes(verification_payload, &api_url, &api_key).await?;
+ui.print(subtitle(message)); Committable suggestion
Suggested change
ToolsGitHub Check: codecov/patch
|
||||||||||||||||
} | ||||||||||||||||
|
||||||||||||||||
Ok(()) | ||||||||||||||||
|
@@ -118,18 +99,18 @@ | |||||||||||||||
|
||||||||||||||||
#[derive(Debug, Serialize)] | ||||||||||||||||
struct VerificationPayload { | ||||||||||||||||
/// The name of the class we want to verify together with the selector. | ||||||||||||||||
pub class_name: String, | ||||||||||||||||
/// The hash of the Sierra class. | ||||||||||||||||
pub class_hash: String, | ||||||||||||||||
/// The RPC URL of the network where this class is declared (can only be a hosted network). | ||||||||||||||||
/// The names of the classes we want to verify together with the selector. | ||||||||||||||||
pub class_names: Vec<String>, | ||||||||||||||||
/// The hashes of the Sierra classes. | ||||||||||||||||
pub class_hashes: Vec<String>, | ||||||||||||||||
Comment on lines
+102
to
+105
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Update documentation for Ohayo, sensei! The |
||||||||||||||||
/// The RPC URL of the network where these classes are declared (can only be a hosted network). | ||||||||||||||||
pub rpc_url: String, | ||||||||||||||||
/// JSON that contains a map where the key is the path to the file and the value is the content | ||||||||||||||||
/// of the file. It should contain all files required to build the Dojo project with Sozo. | ||||||||||||||||
pub source_code: Value, | ||||||||||||||||
} | ||||||||||||||||
|
||||||||||||||||
async fn verify_class( | ||||||||||||||||
async fn verify_classes( | ||||||||||||||||
payload: VerificationPayload, | ||||||||||||||||
api_url: &str, | ||||||||||||||||
api_key: &str, | ||||||||||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add unit tests for the initialization of class vectors
Ohayo, sensei! The new vectors
class_names
andclass_hashes
are essential for the multi-class verification process. Please consider adding tests to ensure they are initialized and populated correctly.Tools
GitHub Check: codecov/patch