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

chore(walnut): put under walnut feature flag #2407

Merged
merged 2 commits into from
Sep 10, 2024
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
6 changes: 4 additions & 2 deletions bin/sozo/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ serde.workspace = true
serde_json.workspace = true
smol_str.workspace = true
sozo-ops.workspace = true
sozo-walnut.workspace = true
sozo-walnut = { workspace = true, optional = true }
starknet.workspace = true
starknet-crypto.workspace = true
thiserror.workspace = true
Expand All @@ -71,5 +71,7 @@ katana-runner.workspace = true
snapbox = "0.4.6"

[features]
default = [ "controller", "walnut" ]

controller = [ "dep:account_sdk", "dep:reqwest", "dep:slot" ]
default = [ "controller" ]
walnut = [ "dep:sozo-walnut", "sozo-ops/walnut" ]
7 changes: 7 additions & 0 deletions bin/sozo/src/commands/auth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use scarb::core::Config;
use scarb_ui::Ui;
use sozo_ops::auth;
#[cfg(feature = "walnut")]
use sozo_walnut::WalnutDebugger;
use tracing::trace;

Expand Down Expand Up @@ -152,6 +153,7 @@
let world =
utils::world_from_env_metadata(world, account, &starknet, &env_metadata, config).await?;

#[cfg(feature = "walnut")]
let walnut_debugger =
WalnutDebugger::new_from_flag(transaction.walnut, starknet.url(env_metadata.as_ref())?);

Expand All @@ -167,6 +169,7 @@
&models_contracts,
&transaction.into(),
default_namespace,
#[cfg(feature = "walnut")]

Check warning on line 172 in bin/sozo/src/commands/auth.rs

View check run for this annotation

Codecov / codecov/patch

bin/sozo/src/commands/auth.rs#L172

Added line #L172 was not covered by tests
&walnut_debugger,
)
.await
Expand All @@ -182,6 +185,7 @@
&owners_resources,
&transaction.into(),
default_namespace,
#[cfg(feature = "walnut")]

Check warning on line 188 in bin/sozo/src/commands/auth.rs

View check run for this annotation

Codecov / codecov/patch

bin/sozo/src/commands/auth.rs#L188

Added line #L188 was not covered by tests
&walnut_debugger,
)
.await
Expand All @@ -205,6 +209,7 @@
let world =
utils::world_from_env_metadata(world, account, &starknet, &env_metadata, config).await?;

#[cfg(feature = "walnut")]
let walnut_debugger =
WalnutDebugger::new_from_flag(transaction.walnut, starknet.url(env_metadata.as_ref())?);

Expand All @@ -220,6 +225,7 @@
&models_contracts,
&transaction.into(),
default_namespace,
#[cfg(feature = "walnut")]

Check warning on line 228 in bin/sozo/src/commands/auth.rs

View check run for this annotation

Codecov / codecov/patch

bin/sozo/src/commands/auth.rs#L228

Added line #L228 was not covered by tests
&walnut_debugger,
)
.await
Expand All @@ -235,6 +241,7 @@
&owners_resources,
&transaction.into(),
default_namespace,
#[cfg(feature = "walnut")]

Check warning on line 244 in bin/sozo/src/commands/auth.rs

View check run for this annotation

Codecov / codecov/patch

bin/sozo/src/commands/auth.rs#L244

Added line #L244 was not covered by tests
&walnut_debugger,
)
.await
Expand Down
3 changes: 3 additions & 0 deletions bin/sozo/src/commands/execute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
use dojo_world::metadata::get_default_namespace_from_ws;
use scarb::core::Config;
use sozo_ops::execute;
#[cfg(feature = "walnut")]
use sozo_walnut::WalnutDebugger;
use tracing::trace;

Expand Down Expand Up @@ -62,6 +63,7 @@
ensure_namespace(&self.tag_or_address, &default_namespace)
};

#[cfg(feature = "walnut")]
let walnut_debugger = WalnutDebugger::new_from_flag(
self.transaction.walnut,
self.starknet.url(env_metadata.as_ref())?,
Expand Down Expand Up @@ -99,6 +101,7 @@
calldata,
&world,
&tx_config,
#[cfg(feature = "walnut")]

Check warning on line 104 in bin/sozo/src/commands/execute.rs

View check run for this annotation

Codecov / codecov/patch

bin/sozo/src/commands/execute.rs#L104

Added line #L104 was not covered by tests
&walnut_debugger,
)
.await
Expand Down
3 changes: 3 additions & 0 deletions bin/sozo/src/commands/register.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use clap::{Args, Subcommand};
use dojo_world::contracts::WorldContractReader;
use scarb::core::Config;
use sozo_ops::register;
#[cfg(feature = "walnut")]
use sozo_walnut::WalnutDebugger;
use starknet::accounts::ConnectedAccount;
use starknet::core::types::{BlockId, BlockTag, Felt};
Expand Down Expand Up @@ -59,6 +60,7 @@ impl RegisterArgs {
let world_address = world.world_address.unwrap_or_default();
trace!(?world_address, "Using world address.");

#[cfg(feature = "walnut")]
let walnut_debugger =
WalnutDebugger::new_from_flag(transaction.walnut, starknet.url(env_metadata.as_ref())?);

Expand All @@ -77,6 +79,7 @@ impl RegisterArgs {
world_reader,
world_address,
config,
#[cfg(feature = "walnut")]
&walnut_debugger,
)
.await
Expand Down
3 changes: 2 additions & 1 deletion crates/sozo/ops/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,14 @@ serde.workspace = true
serde_json.workspace = true
serde_with.workspace = true
smol_str.workspace = true
sozo-walnut = { workspace = true, optional = true }
starknet.workspace = true
starknet-crypto.workspace = true
thiserror.workspace = true
tokio.workspace = true
toml.workspace = true
tracing.workspace = true
url.workspace = true
sozo-walnut.workspace = true

dojo-test-utils = { workspace = true, features = [ "build-examples" ], optional = true }
katana-runner = { workspace = true, optional = true }
Expand All @@ -64,3 +64,4 @@ tee = "0.1.0"

[features]
test-utils = [ "dep:dojo-test-utils", "dep:katana-runner" ]
walnut = [ "dep:sozo-walnut" ]
13 changes: 9 additions & 4 deletions crates/sozo/ops/src/auth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use dojo_world::contracts::naming::{
use dojo_world::contracts::world::WorldContract;
use dojo_world::contracts::WorldContractReader;
use scarb_ui::Ui;
#[cfg(feature = "walnut")]
use sozo_walnut::WalnutDebugger;
use starknet::accounts::{Account, ConnectedAccount};
use starknet::core::types::{BlockId, BlockTag, Felt};
Expand Down Expand Up @@ -111,7 +112,7 @@ pub async fn grant_writer<'a, A>(
new_writers: &[ResourceWriter],
txn_config: &TxnConfig,
default_namespace: &str,
walnut_debugger: &Option<WalnutDebugger>,
#[cfg(feature = "walnut")] walnut_debugger: &Option<WalnutDebugger>,
) -> Result<()>
where
A: ConnectedAccount + Sync + Send,
Expand Down Expand Up @@ -143,6 +144,7 @@ where
res,
txn_config.wait,
txn_config.receipt,
#[cfg(feature = "walnut")]
walnut_debugger,
)
.await?;
Expand All @@ -157,7 +159,7 @@ pub async fn grant_owner<A>(
new_owners: &[ResourceOwner],
txn_config: &TxnConfig,
default_namespace: &str,
walnut_debugger: &Option<WalnutDebugger>,
#[cfg(feature = "walnut")] walnut_debugger: &Option<WalnutDebugger>,
) -> Result<()>
where
A: ConnectedAccount + Sync + Send + 'static,
Expand Down Expand Up @@ -185,6 +187,7 @@ where
res,
txn_config.wait,
txn_config.receipt,
#[cfg(feature = "walnut")]
walnut_debugger,
)
.await?;
Expand All @@ -198,7 +201,7 @@ pub async fn revoke_writer<A>(
new_writers: &[ResourceWriter],
txn_config: &TxnConfig,
default_namespace: &str,
walnut_debugger: &Option<WalnutDebugger>,
#[cfg(feature = "walnut")] walnut_debugger: &Option<WalnutDebugger>,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

weird why fmt is using only one line in this case.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah im not sure, i dont like the look of it as well but oh well

) -> Result<()>
where
A: ConnectedAccount + Sync + Send + 'static,
Expand Down Expand Up @@ -229,6 +232,7 @@ where
res,
txn_config.wait,
txn_config.receipt,
#[cfg(feature = "walnut")]
walnut_debugger,
)
.await?;
Expand All @@ -243,7 +247,7 @@ pub async fn revoke_owner<A>(
new_owners: &[ResourceOwner],
txn_config: &TxnConfig,
default_namespace: &str,
walnut_debugger: &Option<WalnutDebugger>,
#[cfg(feature = "walnut")] walnut_debugger: &Option<WalnutDebugger>,
) -> Result<()>
where
A: ConnectedAccount + Sync + Send + 'static,
Expand All @@ -269,6 +273,7 @@ where
res,
txn_config.wait,
txn_config.receipt,
#[cfg(feature = "walnut")]
walnut_debugger,
)
.await?;
Expand Down
4 changes: 3 additions & 1 deletion crates/sozo/ops/src/execute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use anyhow::{Context, Result};
use dojo_utils::{TransactionExt, TxnConfig};
use dojo_world::contracts::world::WorldContract;
use scarb_ui::Ui;
#[cfg(feature = "walnut")]
use sozo_walnut::WalnutDebugger;
use starknet::accounts::{Call, ConnectedAccount};
use starknet::core::types::Felt;
Expand All @@ -16,7 +17,7 @@ pub async fn execute<A>(
calldata: Vec<Felt>,
world: &WorldContract<A>,
txn_config: &TxnConfig,
walnut_debugger: &Option<WalnutDebugger>,
#[cfg(feature = "walnut")] walnut_debugger: &Option<WalnutDebugger>,
) -> Result<()>
where
A: ConnectedAccount + Sync + Send + 'static,
Expand All @@ -39,6 +40,7 @@ where
res,
txn_config.wait,
txn_config.receipt,
#[cfg(feature = "walnut")]
walnut_debugger,
)
.await
Expand Down
25 changes: 22 additions & 3 deletions crates/sozo/ops/src/migration/auto_auth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
use dojo_utils::TxnConfig;
use dojo_world::contracts::WorldContract;
use scarb::core::Workspace;
#[cfg(feature = "walnut")]
use sozo_walnut::WalnutDebugger;
use starknet::accounts::ConnectedAccount;

Expand All @@ -14,16 +15,34 @@
default_namespace: &str,
grant: &[ResourceWriter],
revoke: &[ResourceWriter],
walnut_debugger: &Option<WalnutDebugger>,
#[cfg(feature = "walnut")] walnut_debugger: &Option<WalnutDebugger>,
) -> Result<()>
where
A: ConnectedAccount + Sync + Send + 'static,
A::SignError: 'static,
{
let ui = ws.config().ui();

grant_writer(&ui, world, grant, txn_config, default_namespace, walnut_debugger).await?;
revoke_writer(&ui, world, revoke, txn_config, default_namespace, walnut_debugger).await?;
grant_writer(
&ui,
world,
grant,
txn_config,
default_namespace,
#[cfg(feature = "walnut")]
walnut_debugger,
)
.await?;
revoke_writer(
&ui,
world,
revoke,
txn_config,
default_namespace,
#[cfg(feature = "walnut")]
walnut_debugger,
)
.await?;

Check warning on line 45 in crates/sozo/ops/src/migration/auto_auth.rs

View check run for this annotation

Codecov / codecov/patch

crates/sozo/ops/src/migration/auto_auth.rs#L45

Added line #L45 was not covered by tests

Ok(())
}
6 changes: 6 additions & 0 deletions crates/sozo/ops/src/migration/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use dojo_world::metadata::get_default_namespace_from_ws;
use dojo_world::migration::world::WorldDiff;
use dojo_world::migration::{DeployOutput, UpgradeOutput};
use scarb::core::Workspace;
#[cfg(feature = "walnut")]
use sozo_walnut::WalnutDebugger;
use starknet::accounts::{Call, ConnectedAccount, ExecutionEncoding, SingleOwnerAccount};
use starknet::core::types::{BlockId, BlockTag, Felt, InvokeTransactionResult};
Expand Down Expand Up @@ -135,6 +136,8 @@ where
A::SignError: 'static,
{
let ui = ws.config().ui();

#[cfg(feature = "walnut")]
let walnut_debugger =
WalnutDebugger::new_from_flag(txn_config.walnut, Url::parse(&rpc_url).unwrap());

Expand Down Expand Up @@ -219,6 +222,7 @@ where

Ok(None)
} else {
#[cfg(feature = "walnut")]
if txn_config.walnut {
WalnutDebugger::check_api_key()?;
}
Expand Down Expand Up @@ -283,6 +287,7 @@ where
&default_namespace,
&grant,
&revoke,
#[cfg(feature = "walnut")]
&walnut_debugger,
)
.await
Expand Down Expand Up @@ -373,6 +378,7 @@ where
}
}

#[cfg(feature = "walnut")]
if let Some(walnut_debugger) = &walnut_debugger {
walnut_debugger.verify_migration_strategy(ws, &strategy).await?;
}
Expand Down
4 changes: 3 additions & 1 deletion crates/sozo/ops/src/register.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use dojo_world::contracts::{WorldContract, WorldContractReader};
use dojo_world::manifest::DeploymentManifest;
use scarb::core::Config;
#[cfg(feature = "walnut")]
use sozo_walnut::WalnutDebugger;
use starknet::accounts::ConnectedAccount;
use starknet::core::types::Felt;
Expand All @@ -20,7 +21,7 @@
world_reader: WorldContractReader<P>,
world_address: Felt,
config: &Config,
walnut_debugger: &Option<WalnutDebugger>,
#[cfg(feature = "walnut")] walnut_debugger: &Option<WalnutDebugger>,
) -> Result<()>
where
A: ConnectedAccount + Sync + Send + 'static,
Expand Down Expand Up @@ -78,6 +79,7 @@
res,
txn_config.wait,
txn_config.receipt,
#[cfg(feature = "walnut")]

Check warning on line 82 in crates/sozo/ops/src/register.rs

View check run for this annotation

Codecov / codecov/patch

crates/sozo/ops/src/register.rs#L82

Added line #L82 was not covered by tests
walnut_debugger,
)
.await?;
Expand Down
1 change: 1 addition & 0 deletions crates/sozo/ops/src/test_utils/setup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@
&default_namespace,
&grant,
&revoke,
#[cfg(feature = "walnut")]

Check warning on line 158 in crates/sozo/ops/src/test_utils/setup.rs

View check run for this annotation

Codecov / codecov/patch

crates/sozo/ops/src/test_utils/setup.rs#L158

Added line #L158 was not covered by tests
&None,
)
.await?;
Expand Down
Loading
Loading