Skip to content
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
444 changes: 116 additions & 328 deletions Cargo.lock

Large diffs are not rendered by default.

14 changes: 6 additions & 8 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@ resolver = "2"

# This is available as a feature in the alloy crate, however,
# the macro expansion is broken as it doesn't rexport the crate
# name correctly and references `alloy_rlp` directly. Once this
# is fixed, this can be removed and "rlp" can be added to features.
# name correctly and references `alloy_rlp` directly. It doesn't
# seem that they plan to fix it, so this must be locked at the
# version found in the Cargo.toml of the alloy crate to maintain
# compatibility.
#
# https://github.com/alloy-rs/rlp/issues/40
[dependencies.alloy-rlp]
Expand All @@ -34,20 +36,16 @@ dirs = "6.0"
displaydoc = "0.2"
futures = "0.3"
hex = "0.4"
log = "0.4"
serde = { version = "1.0", features = ["derive"] }
thiserror = "2.0"
tokio = { version = "1.45", features = ["full"] }
tokio = { version = "1.45", features = ["macros", "rt-multi-thread"] }
tracing = { version = "0.1" }
url = "2.5"

[workspace.dependencies]
golem-base-sdk = { path = "." }
golem-base-test-utils = { path = "test-utils" }

[dev-dependencies]
clap = { version = "4.5", features = ["derive"] }
env_logger = "0.11"
serde_json = "1.0"
serial_test = "3.2"

golem-base-test-utils = { workspace = true }
8 changes: 4 additions & 4 deletions demo/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
[package]
name = "golem-base-sdk-demo"
version = "0.1.0"
edition = "2021"
edition = "2024"

[dependencies]
dirs = "6.0"
env_logger = "0.11"
futures = "0.3"
golem-base-sdk = { workspace = true }
log = "0.4"
tokio = { version = "1", features = ["full"] }
tokio = { version = "1", features = ["macros", "rt-multi-thread"] }
tracing = { version = "0.1" }
tracing-subscriber = { version = "0.3", features = ["env-filter"] }
9 changes: 7 additions & 2 deletions demo/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use golem_base_sdk::events::EventsClient;
use golem_base_sdk::{
Address, Annotation, GolemBaseClient, GolemBaseRoClient, PrivateKeySigner, Url,
};
use log::info;
use tracing::info;

async fn log_num_of_entities_owned(client: &GolemBaseRoClient, owner_address: Address) {
let n = client
Expand All @@ -20,7 +20,12 @@ async fn log_num_of_entities_owned(client: &GolemBaseRoClient, owner_address: Ad

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
env_logger::Builder::from_env(env_logger::Env::default().default_filter_or("info")).init();
let subscriber = tracing_subscriber::fmt()
.with_env_filter(tracing_subscriber::EnvFilter::from_default_env())
.with_writer(std::io::stdout)
.pretty()
.finish();
tracing::subscriber::set_global_default(subscriber).expect("Could not set up global logger");

let keypath = config_dir()
.ok_or("Failed to get config directory")?
Expand Down
12 changes: 6 additions & 6 deletions src/eth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ impl GolemBaseClient {
nm.base_nonce = on_chain_nonce;
}
Err(e) => {
log::warn!("Failed to fetch on-chain nonce: {e}");
tracing::warn!("Failed to fetch on-chain nonce: {e}");
}
}
nm.next_nonce().await
Expand All @@ -176,9 +176,9 @@ impl GolemBaseClient {
&self,
payload: GolemBaseTransaction,
) -> Result<TransactionReceipt, Error> {
log::debug!("payload: {payload:?}");
tracing::debug!("payload: {payload:?}");
let encoded = payload.encoded();
log::debug!("buffer: {encoded:?}");
tracing::debug!("buffer: {encoded:?}");

let nonce = self.next_nonce().await;

Expand All @@ -194,7 +194,7 @@ impl GolemBaseClient {
nonce: Some(nonce),
..Default::default()
};
log::debug!("transaction: {tx:?}");
tracing::debug!("transaction: {tx:?}");

let gas_limit = if let Some(gas_limit) = payload.gas_limit {
gas_limit
Expand All @@ -219,12 +219,12 @@ impl GolemBaseClient {
.send_transaction(tx.clone())
.await
.map_err(|e| Error::TransactionSendError(e.to_string()))?;
log::debug!("pending transaction: {pending_tx:?}");
tracing::debug!("pending transaction: {pending_tx:?}");
let receipt = pending_tx
.get_receipt()
.await
.map_err(|e| Error::TransactionReceiptError(e.to_string()))?;
log::debug!("receipt: {receipt:?}");
tracing::debug!("receipt: {receipt:?}");
{
let mut nm = self.nonce_manager.lock().await;
nm.complete().await;
Expand Down
4 changes: 2 additions & 2 deletions src/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,14 +126,14 @@ impl EventsClient {
/// Creates a new `EventsClient` by connecting to the given websocket `Url`.
/// Establishes a connection to the blockchain node for event streaming.
pub async fn new(url: Url) -> anyhow::Result<Self> {
log::debug!("Connecting to websocket provider: {url}");
tracing::debug!("Connecting to websocket provider: {url}");

let provider = ProviderBuilder::new()
.connect_ws(WsConnect::new(url.clone()))
.await?
.erased();

log::info!("Connected to websocket provider: {url}");
tracing::info!("Connected to websocket provider: {url}");
Ok(Self { provider })
}

Expand Down
6 changes: 3 additions & 3 deletions src/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,12 +85,12 @@ impl GolemBaseRoClient {
params: S,
) -> Result<R, Error> {
let method = method.into();
log::debug!("RPC Call - Method: {method}, Params: {params:?}");
tracing::debug!("RPC Call - Method: {method}, Params: {params:?}");
self.provider
.client()
.request(method.clone(), params)
.await
.inspect(|res| log::debug!("RPC Response: {res:?}"))
.inspect(|res| tracing::debug!("RPC Response: {res:?}"))
.map_err(|e| match e {
RpcError::ErrorResp(err) => {
anyhow!("Error response from RPC service: {err}")
Expand All @@ -99,7 +99,7 @@ impl GolemBaseRoClient {
anyhow!("Serialization error: {err}")
}
RpcError::DeserError { err, text } => {
log::debug!("Deserialization error: {err}, response text: {text}");
tracing::debug!("Deserialization error: {err}, response text: {text}");
anyhow!("Deserialization error: {err}")
}
_ => anyhow!("{e}"),
Expand Down
11 changes: 7 additions & 4 deletions test-utils/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,15 @@ version = "0.1.0"
edition = "2024"

[dependencies]
alloy = { version = "1.0.24", features = ["full", "json-rpc"] }
alloy = { version = "1.0.24", features = [
"provider-ws",
"json-rpc",
"signer-keystore",
] }
anyhow = "1.0"
bigdecimal = "0.4"
env_logger = "0.11.8"
log = "0.4"

dirs = "6.0.0"
golem-base-sdk = { workspace = true }
tracing = { version = "0.1" }
tracing-subscriber = { version = "0.3", features = ["env-filter"] }
url = "2.5.4"
28 changes: 14 additions & 14 deletions tests/test_entity_operations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ async fn test_create_and_retrieve_entry() -> Result<()> {
let client = get_client()?;

let start_block = client.get_current_block_number().await?;
log::info!("Starting at block: {start_block}");
tracing::info!("Starting at block: {start_block}");

let test_payload = b"test payload".to_vec();
let timestamp = SystemTime::now().duration_since(UNIX_EPOCH)?.as_secs();
Expand All @@ -24,16 +24,16 @@ async fn test_create_and_retrieve_entry() -> Result<()> {

let tx_results = client.create_entities(vec![create_tx]).await?;
let entity_result = &tx_results[0];
log::info!("Entry created with ID: {entity_result:?}");
tracing::info!("Entry created with ID: {entity_result:?}");

let entry_str = client
.get_storage_value::<Bytes>(entity_result.entity_key)
.await?;
log::info!("Retrieved value: {entry_str:?}");
tracing::info!("Retrieved value: {entry_str:?}");
assert_eq!(entry_str, String::from_utf8(test_payload)?);

let metadata = client.get_entity_metadata(entity_result.entity_key).await?;
log::info!("Retrieved metadata: {metadata:?}");
tracing::info!("Retrieved metadata: {metadata:?}");

assert_eq!(metadata.string_annotations[0].value, "Test");
assert_eq!(metadata.numeric_annotations[0].value, timestamp);
Expand All @@ -57,7 +57,7 @@ async fn test_entity_operations() -> Result<()> {

let tx1_results = client.create_entities(vec![create1]).await?;
let entity1_result = &tx1_results[0];
log::info!("Entry created with ID: {entity1_result:?}");
tracing::info!("Entry created with ID: {entity1_result:?}");

// Create second entity
let payload2 = b"second entity".to_vec();
Expand All @@ -68,7 +68,7 @@ async fn test_entity_operations() -> Result<()> {

let tx2_results = client.create_entities(vec![create2]).await?;
let entity2_result = &tx2_results[0];
log::info!("Entry created with ID: {entity1_result:?}");
tracing::info!("Entry created with ID: {entity1_result:?}");

// Verify both entities exist
let entity1_str = String::from_utf8(
Expand All @@ -85,8 +85,8 @@ async fn test_entity_operations() -> Result<()> {
.to_vec(),
)
.unwrap();
log::info!("Retrieved first entry: {entity1_str}");
log::info!("Retrieved second entry: {entity2_str}");
tracing::info!("Retrieved first entry: {entity1_str}");
tracing::info!("Retrieved second entry: {entity2_str}");
assert_eq!(entity1_str, String::from_utf8(payload1)?);
assert_eq!(entity2_str, String::from_utf8(payload2)?);

Expand All @@ -98,7 +98,7 @@ async fn test_entity_operations() -> Result<()> {
.annotate_number("test_timestamp", updated_timestamp);

client.update_entities(vec![update]).await?;
log::info!("First entry updated");
tracing::info!("First entry updated");

// Verify first entity was updated
let updated_str = String::from_utf8(
Expand All @@ -107,14 +107,14 @@ async fn test_entity_operations() -> Result<()> {
.await?,
)
.unwrap();
log::info!("Retrieved updated first entry: {updated_str}");
tracing::info!("Retrieved updated first entry: {updated_str}");
assert_eq!(updated_str, String::from_utf8(updated_payload.clone())?);

// Remove second entity
client
.delete_entities(vec![entity2_result.entity_key])
.await?;
log::info!("Second entry removed");
tracing::info!("Second entry removed");

// Verify second entity was removed
let result = client.get_entity_metadata(entity2_result.entity_key).await;
Expand All @@ -133,7 +133,7 @@ async fn test_entity_operations() -> Result<()> {
.to_vec(),
)
.unwrap();
log::info!("Retrieved final first entry: {final_str}");
tracing::info!("Retrieved final first entry: {final_str}");
assert_eq!(final_str, String::from_utf8(updated_payload)?);

Ok(())
Expand Down Expand Up @@ -214,7 +214,7 @@ async fn test_concurrent_entity_creation_batch() -> Result<()> {
assert_eq!(metadata.numeric_annotations[0].value, i as u64);
}

log::info!(
tracing::info!(
"Successfully verified {} concurrent batch entity creations",
ENTITIES_PER_TASK * 2
);
Expand All @@ -227,7 +227,7 @@ async fn test_failed_tx_explicit_gas() -> Result<()> {
let client = get_client()?;

let start_block = client.get_current_block_number().await?;
log::info!("Starting at block: {start_block}");
tracing::info!("Starting at block: {start_block}");

let create_tx = GolemBaseTransaction::builder()
.extensions(vec![Extend::new(FixedBytes::with_last_byte(1), 1000)])
Expand Down
14 changes: 7 additions & 7 deletions tests/test_query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,42 +25,42 @@ async fn test_query_entities() -> Result<()> {
{
// Test queries
let type_test_entries = client.query_entity_keys("type = \"test\"").await?;
log::info!("Entries with type = \"test\": {type_test_entries:?}");
tracing::info!("Entries with type = \"test\": {type_test_entries:?}");
assert!(type_test_entries.contains(&entity1.entity_key));
assert!(type_test_entries.contains(&entity2.entity_key));

let category_alpha_entries = client.query_entity_keys("category = \"alpha\"").await?;
log::info!("Entries with category = \"alpha\": {category_alpha_entries:?}");
tracing::info!("Entries with category = \"alpha\": {category_alpha_entries:?}");
assert!(category_alpha_entries.contains(&entity1.entity_key));
assert!(category_alpha_entries.contains(&entity3.entity_key));

let type_demo_entries = client.query_entity_keys("type = \"demo\"").await?;
log::info!("Entries with type = \"demo\": {type_demo_entries:?}");
tracing::info!("Entries with type = \"demo\": {type_demo_entries:?}");
assert!(type_demo_entries.contains(&entity3.entity_key));

let combined_and = client
.query_entity_keys("type = \"test\" && category = \"beta\"")
.await?;
log::info!("Entries with type = \"test\" && category = \"beta\": {combined_and:?}");
tracing::info!("Entries with type = \"test\" && category = \"beta\": {combined_and:?}");
assert!(combined_and.contains(&entity2.entity_key));

let combined_or = client
.query_entity_keys("type = \"demo\" || category = \"beta\"")
.await?;
log::info!("Entries with type = \"demo\" || category = \"beta\": {combined_or:?}");
tracing::info!("Entries with type = \"demo\" || category = \"beta\": {combined_or:?}");
assert!(combined_or.contains(&entity2.entity_key));
assert!(combined_or.contains(&entity3.entity_key));

// Test empty result
let no_results = client.query_entity_keys("type = \"nonexistent\"").await?;
log::info!("Entries with type = \"nonexistent\": {no_results:?}");
tracing::info!("Entries with type = \"nonexistent\": {no_results:?}");
assert_eq!(no_results.len(), 0);

// Test selecting all entries
let all_entries = client
.query_entity_keys("type = \"test\" || type = \"demo\"")
.await?;
log::info!("All entries: {all_entries:?}");
tracing::info!("All entries: {all_entries:?}");
assert!(all_entries.contains(&entity1.entity_key));
assert!(all_entries.contains(&entity2.entity_key));
assert!(all_entries.contains(&entity3.entity_key));
Expand Down
Loading