From 819081e1a1b6def6016fca0687e547448d0c1b8c Mon Sep 17 00:00:00 2001 From: Brandon Vrooman Date: Wed, 31 May 2023 16:37:14 -0400 Subject: [PATCH] feat: Use ID types in client api (#1191) Related issues: - Closes #1121 This PR update the `FuelClient` API to use ID types in place of string serialized IDs. Now, consumers of the API must directly pass a client type when performing a method call. Internally, these ID types are then converted to GraphQL types to be used in the GraphQL API. This API update represents a breaking change. --- bin/e2e-test-client/src/test_context.rs | 23 +-- bin/e2e-test-client/src/tests/script.rs | 8 +- bin/e2e-test-client/src/tests/transfers.rs | 8 +- bin/fuel-core-client/src/main.rs | 11 +- crates/client/src/client.rs | 149 ++++++++------ crates/client/src/client/schema/coins.rs | 13 +- crates/client/src/client/schema/primitives.rs | 6 + crates/client/src/client/types.rs | 2 +- crates/client/src/client/types/balance.rs | 2 +- crates/client/src/client/types/block.rs | 2 +- crates/client/src/client/types/coins.rs | 2 +- crates/client/src/client/types/contract.rs | 2 +- .../client/src/client/types/merkle_proof.rs | 2 +- crates/client/src/client/types/message.rs | 2 +- tests/tests/balances.rs | 26 +-- tests/tests/blocks.rs | 21 +- tests/tests/coin.rs | 14 +- tests/tests/coins.rs | 183 +++++------------- tests/tests/contract.rs | 13 +- tests/tests/messages.rs | 24 +-- tests/tests/metrics.rs | 8 +- tests/tests/tx.rs | 34 ++-- tests/tests/tx/predicates.rs | 2 +- tests/tests/tx/tx_pointer.rs | 8 +- tests/tests/tx/txn_status_subscription.rs | 2 +- tests/tests/tx/utxo_validation.rs | 5 +- tests/tests/tx_gossip.rs | 3 +- 27 files changed, 227 insertions(+), 348 deletions(-) diff --git a/bin/e2e-test-client/src/test_context.rs b/bin/e2e-test-client/src/test_context.rs index 72f5a52e880..41cb0240a7c 100644 --- a/bin/e2e-test-client/src/test_context.rs +++ b/bin/e2e-test-client/src/test_context.rs @@ -100,10 +100,7 @@ impl Wallet { /// returns the balance associated with a wallet pub async fn balance(&self, asset_id: Option) -> anyhow::Result { self.client - .balance( - &self.address.to_string(), - Some(asset_id.unwrap_or_default().to_string().as_str()), - ) + .balance(&self.address, Some(&asset_id.unwrap_or_default())) .await .context("failed to retrieve balance") } @@ -118,7 +115,7 @@ impl Wallet { results = self .client .coins( - &self.address.to_string(), + &self.address, None, PaginationRequest { cursor: None, @@ -145,17 +142,11 @@ impl Wallet { asset_id: Option, ) -> anyhow::Result { let asset_id = asset_id.unwrap_or_default(); - let asset_id_string = asset_id.to_string(); - let asset_id_str = asset_id_string.as_str(); let total_amount = transfer_amount + BASE_AMOUNT; // select coins let coins = &self .client - .coins_to_spend( - self.address.to_string().as_str(), - vec![(asset_id_str, total_amount, None)], - None, - ) + .coins_to_spend(&self.address, vec![(asset_id, total_amount, None)], None) .await?[0]; // build transaction @@ -217,17 +208,11 @@ impl Wallet { pub async fn deploy_contract(&self, config: ContractConfig) -> anyhow::Result<()> { let asset_id = AssetId::zeroed(); - let asset_id_string = asset_id.to_string(); - let asset_id_str = asset_id_string.as_str(); let total_amount = BASE_AMOUNT; // select coins let coins = &self .client - .coins_to_spend( - self.address.to_string().as_str(), - vec![(asset_id_str, total_amount, None)], - None, - ) + .coins_to_spend(&self.address, vec![(asset_id, total_amount, None)], None) .await?[0]; let ContractConfig { diff --git a/bin/e2e-test-client/src/tests/script.rs b/bin/e2e-test-client/src/tests/script.rs index 18ca5be5a9f..c95b92da658 100644 --- a/bin/e2e-test-client/src/tests/script.rs +++ b/bin/e2e-test-client/src/tests/script.rs @@ -31,8 +31,8 @@ pub async fn receipts(ctx: &TestContext) -> Result<(), Failed> { let mut queries = vec![]; for i in 0..100 { - let tx_id = result.tx_id.to_string(); - queries.push(async move { (ctx.alice.client.receipts(tx_id.as_str()).await, i) }); + let tx_id = result.tx_id; + queries.push(async move { (ctx.alice.client.receipts(&tx_id).await, i) }); } let queries = futures::future::join_all(queries).await; @@ -80,11 +80,11 @@ pub async fn run_contract_large_state(ctx: &TestContext) -> Result<(), Failed> { // `0xc8ca903bfaba051c55d827c3bd957a325a3f80bceeb87c6e49d308ad39cf48d7` in the // `test_data/large_state/contract.json`. // contract_config.calculate_contract_id(); - let contract_id = contract_config.contract_id.to_string(); + let contract_id = contract_config.contract_id; println!("\nThe `contract_id` of the contract with large state: {contract_id}"); // if the contract is not deployed yet, let's deploy it - let result = ctx.bob.client.contract(contract_id.as_str()).await; + let result = ctx.bob.client.contract(&contract_id).await; if result?.is_none() { let deployment_request = ctx.bob.deploy_contract(contract_config); diff --git a/bin/e2e-test-client/src/tests/transfers.rs b/bin/e2e-test-client/src/tests/transfers.rs index f3bb98f9a76..b9619453649 100644 --- a/bin/e2e-test-client/src/tests/transfers.rs +++ b/bin/e2e-test-client/src/tests/transfers.rs @@ -18,9 +18,7 @@ pub async fn basic_transfer(ctx: &TestContext) -> Result<(), Failed> { // wait until bob sees the transaction timeout( ctx.config.sync_timeout(), - ctx.bob - .client - .await_transaction_commit(&result.tx_id.to_string()), + ctx.bob.client.await_transaction_commit(&result.tx_id), ) .await??; println!("\nThe tx id of the transfer: {}", result.tx_id); @@ -52,9 +50,7 @@ pub async fn transfer_back(ctx: &TestContext) -> Result<(), Failed> { // wait until alice sees the transaction timeout( ctx.config.sync_timeout(), - ctx.alice - .client - .await_transaction_commit(&result.tx_id.to_string()), + ctx.alice.client.await_transaction_commit(&result.tx_id), ) .await??; diff --git a/bin/fuel-core-client/src/main.rs b/bin/fuel-core-client/src/main.rs index c89c4526334..d0d238a7f72 100644 --- a/bin/fuel-core-client/src/main.rs +++ b/bin/fuel-core-client/src/main.rs @@ -1,7 +1,10 @@ #![deny(unused_crate_dependencies)] use clap::Parser; use fuel_core_client::client::FuelClient; -use fuel_core_types::fuel_tx::Transaction; +use fuel_core_types::fuel_tx::{ + Transaction, + TxId, +}; use serde_json::json; #[derive(Parser)] @@ -53,11 +56,13 @@ impl CliArgs { println!("{:?}", result.unwrap()); } TransactionCommands::Get { id } => { - let tx = client.transaction(id.as_str()).await.unwrap(); + let tx_id = id.parse::().expect("invalid transaction id"); + let tx = client.transaction(&tx_id).await.unwrap(); println!("{:?}", json!(tx).to_string()) } TransactionCommands::Receipts { id } => { - let receipts = client.receipts(id.as_str()).await.unwrap().unwrap(); + let tx_id = id.parse::().expect("invalid transaction id"); + let receipts = client.receipts(&tx_id).await.unwrap().unwrap(); println!("{:?}", json!(receipts).to_string()) } }, diff --git a/crates/client/src/client.rs b/crates/client/src/client.rs index faaa5c4838d..e636eac80b8 100644 --- a/crates/client/src/client.rs +++ b/crates/client/src/client.rs @@ -1,12 +1,22 @@ -use crate::client::schema::{ - block::BlockByHeightArgs, - coins::{ - ExcludeInput, - SpendQueryElementInput, +use crate::client::{ + schema::{ + block::BlockByHeightArgs, + coins::{ + ExcludeInput, + SpendQueryElementInput, + }, + contract::ContractBalanceQueryArgs, + tx::DryRunArg, + Tai64Timestamp, + TransactionId, + }, + types::primitives::{ + Address, + AssetId, + BlockId, + ContractId, + UtxoId, }, - contract::ContractBalanceQueryArgs, - tx::DryRunArg, - Tai64Timestamp, }; use anyhow::Context; #[cfg(feature = "subscriptions")] @@ -28,11 +38,14 @@ use fuel_core_types::{ fuel_tx::{ Receipt, Transaction, + TxId, }, fuel_types, fuel_types::{ bytes::SerializableVec, BlockHeight, + MessageId, + Nonce, }, }; #[cfg(feature = "subscriptions")] @@ -342,7 +355,7 @@ impl FuelClient { pub async fn submit( &self, tx: &Transaction, - ) -> io::Result { + ) -> io::Result { let tx = tx.clone().to_bytes(); let query = schema::tx::Submit::build(TxArg { tx: HexString(Bytes(tx)), @@ -492,8 +505,11 @@ impl FuelClient { Ok(response) } - pub async fn transaction(&self, id: &str) -> io::Result> { - let query = schema::tx::TransactionQuery::build(TxIdArgs { id: id.parse()? }); + pub async fn transaction( + &self, + id: &TxId, + ) -> io::Result> { + let query = schema::tx::TransactionQuery::build(TxIdArgs { id: (*id).into() }); let transaction = self.query(query).await?.transaction; @@ -501,8 +517,8 @@ impl FuelClient { } /// Get the status of a transaction - pub async fn transaction_status(&self, id: &str) -> io::Result { - let query = schema::tx::TransactionQuery::build(TxIdArgs { id: id.parse()? }); + pub async fn transaction_status(&self, id: &TxId) -> io::Result { + let query = schema::tx::TransactionQuery::build(TxIdArgs { id: (*id).into() }); let tx = self.query(query).await?.transaction.ok_or_else(|| { io::Error::new( @@ -528,10 +544,11 @@ impl FuelClient { /// Subscribe to the status of a transaction pub async fn subscribe_transaction_status( &self, - id: &str, + id: &TxId, ) -> io::Result>> { use cynic::SubscriptionBuilder; - let s = schema::tx::StatusChangeSubscription::build(TxIdArgs { id: id.parse()? }); + let tx_id: TransactionId = (*id).into(); + let s = schema::tx::StatusChangeSubscription::build(TxIdArgs { id: tx_id }); tracing::debug!("subscribing"); let stream = self.subscribe(s).await?.map(|tx| { @@ -551,7 +568,7 @@ impl FuelClient { /// with a `tokio::time::timeout`. pub async fn await_transaction_commit( &self, - id: &str, + id: &TxId, ) -> io::Result { // skip until we've reached a final status and then stop consuming the stream // to avoid an EOF which the eventsource client considers as an error. @@ -587,18 +604,18 @@ impl FuelClient { /// Returns a paginated set of transactions associated with a txo owner address. pub async fn transactions_by_owner( &self, - owner: &str, + owner: &Address, request: PaginationRequest, ) -> io::Result> { - let owner: schema::Address = owner.parse()?; + let owner: schema::Address = (*owner).into(); let query = schema::tx::TransactionsByOwnerQuery::build((owner, request).into()); let transactions = self.query(query).await?.transactions_by_owner.try_into()?; Ok(transactions) } - pub async fn receipts(&self, id: &str) -> io::Result>> { - let query = schema::tx::TransactionQuery::build(TxIdArgs { id: id.parse()? }); + pub async fn receipts(&self, id: &TxId) -> io::Result>> { + let query = schema::tx::TransactionQuery::build(TxIdArgs { id: (*id).into() }); let tx = self.query(query).await?.transaction.ok_or_else(|| { io::Error::new(ErrorKind::NotFound, format!("transaction {id} not found")) @@ -632,9 +649,9 @@ impl FuelClient { Ok(new_height.into()) } - pub async fn block(&self, id: &str) -> io::Result> { + pub async fn block(&self, id: &BlockId) -> io::Result> { let query = schema::block::BlockByIdQuery::build(BlockByIdArgs { - id: Some(id.parse()?), + id: Some((*id).into()), }); let block = self.query(query).await?.block.map(Into::into); @@ -664,9 +681,9 @@ impl FuelClient { Ok(blocks) } - pub async fn coin(&self, id: &str) -> io::Result> { + pub async fn coin(&self, id: &UtxoId) -> io::Result> { let query = schema::coins::CoinByIdQuery::build(CoinByIdArgs { - utxo_id: id.parse()?, + utxo_id: (*id).into(), }); let coin = self.query(query).await?.coin.map(Into::into); Ok(coin) @@ -675,13 +692,13 @@ impl FuelClient { /// Retrieve a page of coins by their owner pub async fn coins( &self, - owner: &str, - asset_id: Option<&str>, + owner: &Address, + asset_id: Option<&AssetId>, request: PaginationRequest, ) -> io::Result> { - let owner: schema::Address = owner.parse()?; + let owner: schema::Address = (*owner).into(); let asset_id: schema::AssetId = match asset_id { - Some(asset_id) => asset_id.parse()?, + Some(asset_id) => (*asset_id).into(), None => schema::AssetId::default(), }; let query = schema::coins::CoinsQuery::build((owner, asset_id, request).into()); @@ -693,24 +710,32 @@ impl FuelClient { /// Retrieve coins to spend in a transaction pub async fn coins_to_spend( &self, - owner: &str, - spend_query: Vec<(&str, u64, Option)>, + owner: &Address, + spend_query: Vec<(AssetId, u64, Option)>, // (Utxos, Messages Nonce) - excluded_ids: Option<(Vec<&str>, Vec<&str>)>, + excluded_ids: Option<(Vec, Vec)>, ) -> io::Result>> { - let owner: schema::Address = owner.parse()?; + let owner: schema::Address = (*owner).into(); let spend_query: Vec = spend_query .iter() .map(|(asset_id, amount, max)| -> Result<_, ConversionError> { Ok(SpendQueryElementInput { - asset_id: asset_id.parse()?, + asset_id: (*asset_id).into(), amount: (*amount).into(), max: (*max).map(|max| max.into()), }) }) .try_collect()?; - let excluded_ids: Option = - excluded_ids.map(ExcludeInput::from_tuple).transpose()?; + let excluded_ids: Option = excluded_ids + .map( + |(utxos, nonces)| -> (Vec, Vec) { + ( + utxos.into_iter().map(Into::into).collect(), + nonces.into_iter().map(Into::into).collect(), + ) + }, + ) + .map(Into::into); let query = schema::coins::CoinsToSpendQuery::build( (owner, spend_query, excluded_ids).into(), ); @@ -725,9 +750,9 @@ impl FuelClient { Ok(coins_per_asset) } - pub async fn contract(&self, id: &str) -> io::Result> { + pub async fn contract(&self, id: &ContractId) -> io::Result> { let query = schema::contract::ContractByIdQuery::build(ContractByIdArgs { - id: id.parse()?, + id: (*id).into(), }); let contract = self.query(query).await?.contract.map(Into::into); Ok(contract) @@ -735,17 +760,17 @@ impl FuelClient { pub async fn contract_balance( &self, - id: &str, - asset: Option<&str>, + id: &ContractId, + asset: Option<&AssetId>, ) -> io::Result { let asset_id: schema::AssetId = match asset { - Some(asset) => asset.parse()?, + Some(asset) => (*asset).into(), None => schema::AssetId::default(), }; let query = schema::contract::ContractBalanceQuery::build(ContractBalanceQueryArgs { - id: id.parse()?, + id: (*id).into(), asset: asset_id, }); @@ -754,10 +779,14 @@ impl FuelClient { Ok(balance.amount) } - pub async fn balance(&self, owner: &str, asset_id: Option<&str>) -> io::Result { - let owner: schema::Address = owner.parse()?; + pub async fn balance( + &self, + owner: &Address, + asset_id: Option<&AssetId>, + ) -> io::Result { + let owner: schema::Address = (*owner).into(); let asset_id: schema::AssetId = match asset_id { - Some(asset_id) => asset_id.parse()?, + Some(asset_id) => (*asset_id).into(), None => schema::AssetId::default(), }; let query = schema::balance::BalanceQuery::build(BalanceArgs { owner, asset_id }); @@ -768,10 +797,10 @@ impl FuelClient { // Retrieve a page of balances by their owner pub async fn balances( &self, - owner: &str, + owner: &Address, request: PaginationRequest, ) -> io::Result> { - let owner: schema::Address = owner.parse()?; + let owner: schema::Address = (*owner).into(); let query = schema::balance::BalancesQuery::build((owner, request).into()); let balances = self.query(query).await?.balances.into(); @@ -780,10 +809,10 @@ impl FuelClient { pub async fn contract_balances( &self, - contract: &str, + contract: &ContractId, request: PaginationRequest, ) -> io::Result> { - let contract_id: schema::ContractId = contract.parse()?; + let contract_id: schema::ContractId = (*contract).into(); let query = schema::contract::ContractBalancesQuery::build((contract_id, request).into()); @@ -794,11 +823,10 @@ impl FuelClient { pub async fn messages( &self, - owner: Option<&str>, + owner: Option<&Address>, request: PaginationRequest, ) -> io::Result> { - let owner: Option = - owner.map(|owner| owner.parse()).transpose()?; + let owner: Option = owner.map(|owner| (*owner).into()); let query = schema::message::OwnedMessageQuery::build((owner, request).into()); let messages = self.query(query).await?.messages.into(); @@ -809,16 +837,15 @@ impl FuelClient { /// Request a merkle proof of an output message. pub async fn message_proof( &self, - transaction_id: &str, - message_id: &str, - commit_block_id: Option<&str>, + transaction_id: &TxId, + message_id: &MessageId, + commit_block_id: Option<&BlockId>, commit_block_height: Option, ) -> io::Result> { - let transaction_id: schema::TransactionId = transaction_id.parse()?; - let message_id: schema::MessageId = message_id.parse()?; - let commit_block_id: Option = commit_block_id - .map(|commit_block_id| commit_block_id.parse()) - .transpose()?; + let transaction_id: schema::TransactionId = (*transaction_id).into(); + let message_id: schema::MessageId = (*message_id).into(); + let commit_block_id: Option = + commit_block_id.map(|commit_block_id| (*commit_block_id).into()); let commit_block_height = commit_block_height.map(Into::into); let query = schema::message::MessageProofQuery::build(MessageProofArgs { transaction_id, @@ -837,9 +864,9 @@ impl FuelClient { impl FuelClient { pub async fn transparent_transaction( &self, - id: &str, + id: &TxId, ) -> io::Result> { - let query = schema::tx::TransactionQuery::build(TxIdArgs { id: id.parse()? }); + let query = schema::tx::TransactionQuery::build(TxIdArgs { id: (*id).into() }); let transaction = self.query(query).await?.transaction; diff --git a/crates/client/src/client/schema/coins.rs b/crates/client/src/client/schema/coins.rs index abf917fcfbf..debfa67e5d3 100644 --- a/crates/client/src/client/schema/coins.rs +++ b/crates/client/src/client/schema/coins.rs @@ -3,7 +3,6 @@ use crate::client::{ schema, Address, AssetId, - ConversionError, Nonce, PageInfo, UtxoId, @@ -13,8 +12,6 @@ use crate::client::{ PageDirection, PaginationRequest, }; -use itertools::Itertools; -use std::str::FromStr; #[derive(cynic::QueryVariables, Debug)] pub struct CoinByIdArgs { @@ -134,12 +131,10 @@ pub struct ExcludeInput { messages: Vec, } -impl ExcludeInput { - pub fn from_tuple(tuple: (Vec<&str>, Vec<&str>)) -> Result { - let utxos = tuple.0.into_iter().map(UtxoId::from_str).try_collect()?; - let messages = tuple.1.into_iter().map(Nonce::from_str).try_collect()?; - - Ok(Self { utxos, messages }) +impl From<(Vec, Vec)> for ExcludeInput { + fn from(value: (Vec, Vec)) -> Self { + let (utxos, messages) = value; + Self { utxos, messages } } } diff --git a/crates/client/src/client/schema/primitives.rs b/crates/client/src/client/schema/primitives.rs index 3341b233dae..eb86b1fb573 100644 --- a/crates/client/src/client/schema/primitives.rs +++ b/crates/client/src/client/schema/primitives.rs @@ -140,6 +140,12 @@ impl From for ::fuel_core_types::fuel_tx::UtxoId { } } +impl From for UtxoId { + fn from(value: fuel_core_types::fuel_tx::UtxoId) -> Self { + Self(HexFormatted(value)) + } +} + impl LowerHex for UtxoId { fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { LowerHex::fmt(&self.0 .0, f) diff --git a/crates/client/src/client/types.rs b/crates/client/src/client/types.rs index 922cf88cfad..b737731f397 100644 --- a/crates/client/src/client/types.rs +++ b/crates/client/src/client/types.rs @@ -49,7 +49,7 @@ use serde::{ }; use tai64::Tai64; -pub mod scalars { +pub mod primitives { pub use fuel_core_types::{ fuel_crypto::{ PublicKey, diff --git a/crates/client/src/client/types/balance.rs b/crates/client/src/client/types/balance.rs index a8f90f6a48f..ee317695e66 100644 --- a/crates/client/src/client/types/balance.rs +++ b/crates/client/src/client/types/balance.rs @@ -1,6 +1,6 @@ use crate::client::{ schema, - types::scalars::{ + types::primitives::{ Address, AssetId, }, diff --git a/crates/client/src/client/types/block.rs b/crates/client/src/client/types/block.rs index f3705b233d5..1249cc43b82 100644 --- a/crates/client/src/client/types/block.rs +++ b/crates/client/src/client/types/block.rs @@ -1,6 +1,6 @@ use crate::client::{ schema, - types::scalars::{ + types::primitives::{ BlockId, Hash, MerkleRoot, diff --git a/crates/client/src/client/types/coins.rs b/crates/client/src/client/types/coins.rs index 991c70fc36a..5b069c07ae7 100644 --- a/crates/client/src/client/types/coins.rs +++ b/crates/client/src/client/types/coins.rs @@ -1,6 +1,6 @@ use crate::client::{ schema, - types::scalars::{ + types::primitives::{ Address, AssetId, Nonce, diff --git a/crates/client/src/client/types/contract.rs b/crates/client/src/client/types/contract.rs index 2f48e62a5a1..4edab9f9ad6 100644 --- a/crates/client/src/client/types/contract.rs +++ b/crates/client/src/client/types/contract.rs @@ -1,6 +1,6 @@ use crate::client::{ schema, - types::scalars::{ + types::primitives::{ AssetId, Bytes, ContractId, diff --git a/crates/client/src/client/types/merkle_proof.rs b/crates/client/src/client/types/merkle_proof.rs index c07a033b83e..ab16daa3b21 100644 --- a/crates/client/src/client/types/merkle_proof.rs +++ b/crates/client/src/client/types/merkle_proof.rs @@ -1,6 +1,6 @@ use crate::client::{ schema, - types::scalars::MerkleRoot, + types::primitives::MerkleRoot, }; #[derive(Debug)] diff --git a/crates/client/src/client/types/message.rs b/crates/client/src/client/types/message.rs index ea213a0be12..1bc89846b5d 100644 --- a/crates/client/src/client/types/message.rs +++ b/crates/client/src/client/types/message.rs @@ -2,7 +2,7 @@ use crate::client::{ schema, types::{ block::Header, - scalars::{ + primitives::{ Address, Bytes, Nonce, diff --git a/tests/tests/balances.rs b/tests/tests/balances.rs index 50c11de96f6..06e11c833cc 100644 --- a/tests/tests/balances.rs +++ b/tests/tests/balances.rs @@ -15,7 +15,7 @@ use fuel_core_client::client::{ PaginationRequest, }, types::{ - scalars::{ + primitives::{ Address, AssetId, }, @@ -82,22 +82,12 @@ async fn balance() { let client = FuelClient::from(srv.bound_address); // run test - let balance = client - .balance( - format!("{owner:#x}").as_str(), - Some(format!("{asset_id:#x}").as_str()), - ) - .await - .unwrap(); + let balance = client.balance(&owner, Some(&asset_id)).await.unwrap(); assert_eq!(balance, 450); // spend some coins and check again let coins_per_asset = client - .coins_to_spend( - format!("{owner:#x}").as_str(), - vec![(format!("{asset_id:#x}").as_str(), 1, None)], - None, - ) + .coins_to_spend(&owner, vec![(asset_id, 1, None)], None) .await .unwrap(); @@ -145,13 +135,7 @@ async fn balance() { client.submit_and_await_commit(&tx).await.unwrap(); - let balance = client - .balance( - format!("{owner:#x}").as_str(), - Some(format!("{asset_id:#x}").as_str()), - ) - .await - .unwrap(); + let balance = client.balance(&owner, Some(&asset_id)).await.unwrap(); assert_eq!(balance, 449); } @@ -232,7 +216,7 @@ async fn first_5_balances() { // run test let balances = client .balances( - format!("{owner:#x}").as_str(), + &owner, PaginationRequest { cursor: None, results: 5, diff --git a/tests/tests/blocks.rs b/tests/tests/blocks.rs index 6ccbd0c29f7..ab81cf7b160 100644 --- a/tests/tests/blocks.rs +++ b/tests/tests/blocks.rs @@ -1,6 +1,5 @@ use fuel_core::{ database::Database, - schema::scalars::BlockId, service::{ Config, FuelService, @@ -59,11 +58,7 @@ async fn block() { .unwrap(); // run test - let id_bytes: Bytes32 = id.into(); - let block = client - .block(BlockId::from(id_bytes).to_string().as_str()) - .await - .unwrap(); + let block = client.block(&id.into()).await.unwrap(); assert!(block.is_some()); } @@ -101,18 +96,15 @@ async fn produce_block() { client.submit_and_await_commit(&tx).await.unwrap(); let transaction_response = client - .transaction(&format!("{:#x}", tx.id(&ConsensusParameters::DEFAULT))) + .transaction(&tx.id(&ConsensusParameters::DEFAULT)) .await .unwrap(); if let TransactionStatus::Success { block_id, .. } = transaction_response.unwrap().status { - let block = client - .block(block_id.to_string().as_str()) - .await - .unwrap() - .unwrap(); + let block_id = block_id.parse().unwrap(); + let block = client.block(&block_id).await.unwrap().unwrap(); let actual_pub_key = block.block_producer().unwrap(); let block_height: u32 = block.header.height; let expected_pub_key = config @@ -179,15 +171,16 @@ async fn produce_block_negative() { client.submit_and_await_commit(&tx).await.unwrap(); let transaction_response = client - .transaction(&format!("{:#x}", tx.id(&ConsensusParameters::DEFAULT))) + .transaction(&tx.id(&ConsensusParameters::DEFAULT)) .await .unwrap(); if let TransactionStatus::Success { block_id, .. } = transaction_response.unwrap().status { + let block_id = block_id.parse().unwrap(); let block_height: u32 = client - .block(block_id.to_string().as_str()) + .block(&block_id) .await .unwrap() .unwrap() diff --git a/tests/tests/coin.rs b/tests/tests/coin.rs index fdc5bc5ae94..a18339bc003 100644 --- a/tests/tests/coin.rs +++ b/tests/tests/coin.rs @@ -10,7 +10,7 @@ use fuel_core_client::client::{ PageDirection, PaginationRequest, }, - types::scalars::{ + types::primitives::{ Address, AssetId, UtxoId, @@ -39,7 +39,7 @@ async fn coin() { let client = FuelClient::from(srv.bound_address); // run test - let coin = client.coin(format!("{utxo_id:#x}").as_str()).await.unwrap(); + let coin = client.coin(&utxo_id).await.unwrap(); assert!(coin.is_some()); } @@ -79,7 +79,7 @@ async fn first_5_coins( // run test let coins = client .coins( - format!("{owner:#x}").as_str(), + &owner, None, PaginationRequest { cursor: None, @@ -126,8 +126,8 @@ async fn only_asset_id_filtered_coins() { // run test let coins = client .coins( - format!("{owner:#x}").as_str(), - Some(format!("{asset_id:#x}").as_str()), + &owner, + Some(&asset_id), PaginationRequest { cursor: None, results: 10, @@ -175,8 +175,8 @@ async fn get_coins_forwards_backwards( // run test let coins = client .coins( - format!("{owner:#x}").as_str(), - Some(format!("{asset_id:#x}").as_str()), + &owner, + Some(&asset_id), PaginationRequest { cursor: None, results: 10, diff --git a/tests/tests/coins.rs b/tests/tests/coins.rs index af3e21d800f..4cec5902f6c 100644 --- a/tests/tests/coins.rs +++ b/tests/tests/coins.rs @@ -101,11 +101,8 @@ mod coin { let coins_per_asset = context .client .coins_to_spend( - format!("{owner:#x}").as_str(), - vec![ - (format!("{asset_id_a:#x}").as_str(), 300, None), - (format!("{asset_id_b:#x}").as_str(), 300, None), - ], + &owner, + vec![(asset_id_a, 300, None), (asset_id_b, 300, None)], None, ) .await @@ -138,11 +135,7 @@ mod coin { // select all available asset a coins to spend let remaining_coins_a = context .client - .coins_to_spend( - format!("{owner:#x}").as_str(), - vec![(format!("{asset_id_a:#x}").as_str(), 1, None)], - None, - ) + .coins_to_spend(&owner, vec![(asset_id_a, 1, None)], None) .await; // there should be none left assert!(remaining_coins_a.is_err()); @@ -150,11 +143,7 @@ mod coin { // select all available asset a coins to spend let remaining_coins_b = context .client - .coins_to_spend( - format!("{owner:#x}").as_str(), - vec![(format!("{asset_id_b:#x}").as_str(), 1, None)], - None, - ) + .coins_to_spend(&owner, vec![(asset_id_b, 1, None)], None) .await; // there should be none left assert!(remaining_coins_b.is_err()) @@ -167,11 +156,8 @@ mod coin { let coins_per_asset = context .client .coins_to_spend( - format!("{owner:#x}").as_str(), - vec![ - (format!("{asset_id_a:#x}").as_str(), 1, None), - (format!("{asset_id_b:#x}").as_str(), 1, None), - ], + &owner, + vec![(asset_id_a, 1, None), (asset_id_b, 1, None)], None, ) .await @@ -190,11 +176,8 @@ mod coin { let coins_per_asset = context .client .coins_to_spend( - format!("{owner:#x}").as_str(), - vec![ - (format!("{asset_id_a:#x}").as_str(), 300, None), - (format!("{asset_id_b:#x}").as_str(), 300, None), - ], + &owner, + vec![(asset_id_a, 300, None), (asset_id_b, 300, None)], None, ) .await @@ -213,37 +196,30 @@ mod coin { let coins_per_asset = context .client .coins_to_spend( - format!("{owner:#x}").as_str(), - vec![ - (format!("{asset_id_a:#x}").as_str(), 300, None), - (format!("{asset_id_b:#x}").as_str(), 300, None), - ], + &owner, + vec![(asset_id_a, 300, None), (asset_id_b, 300, None)], None, ) .await .unwrap(); // spend_query for 1 a and 1 b, but with all coins excluded - let all_utxos: Vec = coins_per_asset + let all_utxos = coins_per_asset .iter() .flat_map(|coins| { coins.iter().filter_map(|b| match b { - CoinType::Coin(c) => Some(format!("{:#x}", c.utxo_id)), + CoinType::Coin(c) => Some(c.utxo_id), CoinType::MessageCoin(_) => None, CoinType::Unknown => None, }) }) .collect(); - let all_utxo_ids = all_utxos.iter().map(String::as_str).collect(); let coins_per_asset = context .client .coins_to_spend( - format!("{owner:#x}").as_str(), - vec![ - (format!("{asset_id_a:#x}").as_str(), 1, None), - (format!("{asset_id_b:#x}").as_str(), 1, None), - ], - Some((all_utxo_ids, vec![])), + &owner, + vec![(asset_id_a, 1, None), (asset_id_b, 1, None)], + Some((all_utxos, vec![])), ) .await; assert!(coins_per_asset.is_err()); @@ -268,11 +244,8 @@ mod coin { let coins_per_asset = context .client .coins_to_spend( - format!("{owner:#x}").as_str(), - vec![ - (format!("{asset_id_a:#x}").as_str(), 301, None), - (format!("{asset_id_b:#x}").as_str(), 301, None), - ], + &owner, + vec![(asset_id_a, 301, None), (asset_id_b, 301, None)], None, ) .await; @@ -294,11 +267,8 @@ mod coin { let coins_per_asset = context .client .coins_to_spend( - format!("{owner:#x}").as_str(), - vec![ - (format!("{asset_id_a:#x}").as_str(), 300, Some(2)), - (format!("{asset_id_b:#x}").as_str(), 300, Some(2)), - ], + &owner, + vec![(asset_id_a, 300, Some(2)), (asset_id_b, 300, Some(2))], None, ) .await; @@ -381,11 +351,7 @@ mod message_coin { // select all available coins to spend let coins_per_asset = context .client - .coins_to_spend( - format!("{owner:#x}").as_str(), - vec![(format!("{base_asset_id:#x}").as_str(), 300, None)], - None, - ) + .coins_to_spend(&owner, vec![(base_asset_id, 300, None)], None) .await .unwrap(); @@ -412,11 +378,7 @@ mod message_coin { // select all available coins to spend let remaining_coins = context .client - .coins_to_spend( - format!("{owner:#x}").as_str(), - vec![(format!("{base_asset_id:#x}").as_str(), 1, None)], - None, - ) + .coins_to_spend(&owner, vec![(base_asset_id, 1, None)], None) .await; // there should be none left assert!(remaining_coins.is_err()) @@ -428,11 +390,7 @@ mod message_coin { // query coins for `base_asset_id` and target 1 let coins_per_asset = context .client - .coins_to_spend( - format!("{owner:#x}").as_str(), - vec![(format!("{base_asset_id:#x}").as_str(), 1, None)], - None, - ) + .coins_to_spend(&owner, vec![(base_asset_id, 1, None)], None) .await .unwrap(); assert_eq!(coins_per_asset.len(), 1); @@ -444,11 +402,7 @@ mod message_coin { // query for 300 base assets let coins_per_asset = context .client - .coins_to_spend( - format!("{owner:#x}").as_str(), - vec![(format!("{base_asset_id:#x}").as_str(), 300, None)], - None, - ) + .coins_to_spend(&owner, vec![(base_asset_id, 300, None)], None) .await .unwrap(); assert_eq!(coins_per_asset.len(), 1); @@ -461,31 +415,26 @@ mod message_coin { // query for 300 base assets let coins_per_asset = context .client - .coins_to_spend( - format!("{owner:#x}").as_str(), - vec![(format!("{base_asset_id:#x}").as_str(), 300, None)], - None, - ) + .coins_to_spend(&owner, vec![(base_asset_id, 300, None)], None) .await .unwrap(); // query base assets, but with all coins excluded - let all_message_ids: Vec = coins_per_asset + let all_message_ids = coins_per_asset .iter() .flat_map(|coins| { coins.iter().filter_map(|b| match b { CoinType::Coin(_) => None, - CoinType::MessageCoin(m) => Some(format!("{:#x}", m.nonce)), + CoinType::MessageCoin(m) => Some(m.nonce), CoinType::Unknown => None, }) }) .collect(); - let all_message_ids = all_message_ids.iter().map(String::as_str).collect(); let coins_per_asset = context .client .coins_to_spend( - format!("{owner:#x}").as_str(), - vec![(format!("{base_asset_id:#x}").as_str(), 1, None)], + &owner, + vec![(base_asset_id, 1, None)], Some((vec![], all_message_ids)), ) .await; @@ -506,11 +455,7 @@ mod message_coin { // max coins reached let coins_per_asset = context .client - .coins_to_spend( - format!("{owner:#x}").as_str(), - vec![(format!("{base_asset_id:#x}").as_str(), 301, None)], - None, - ) + .coins_to_spend(&owner, vec![(base_asset_id, 301, None)], None) .await; assert!(coins_per_asset.is_err()); assert_eq!( @@ -529,11 +474,7 @@ mod message_coin { // not enough inputs let coins_per_asset = context .client - .coins_to_spend( - format!("{owner:#x}").as_str(), - vec![(format!("{base_asset_id:#x}").as_str(), 300, Some(2))], - None, - ) + .coins_to_spend(&owner, vec![(base_asset_id, 300, Some(2))], None) .await; assert!(coins_per_asset.is_err()); assert_eq!( @@ -627,11 +568,8 @@ mod all_coins { let coins_per_asset = context .client .coins_to_spend( - format!("{owner:#x}").as_str(), - vec![ - (format!("{asset_id_a:#x}").as_str(), 1, None), - (format!("{asset_id_b:#x}").as_str(), 1, None), - ], + &owner, + vec![(asset_id_a, 1, None), (asset_id_b, 1, None)], None, ) .await @@ -650,11 +588,8 @@ mod all_coins { let coins_per_asset = context .client .coins_to_spend( - format!("{owner:#x}").as_str(), - vec![ - (format!("{asset_id_a:#x}").as_str(), 300, None), - (format!("{asset_id_b:#x}").as_str(), 300, None), - ], + &owner, + vec![(asset_id_a, 300, None), (asset_id_b, 300, None)], None, ) .await @@ -673,42 +608,35 @@ mod all_coins { let coins_per_asset = context .client .coins_to_spend( - format!("{owner:#x}").as_str(), - vec![ - (format!("{asset_id_a:#x}").as_str(), 300, None), - (format!("{asset_id_b:#x}").as_str(), 300, None), - ], + &owner, + vec![(asset_id_a, 300, None), (asset_id_b, 300, None)], None, ) .await .unwrap(); // query base assets, but with all coins excluded - let all_message_ids: Vec = coins_per_asset + let all_message_ids: Vec<_> = coins_per_asset .iter() .flat_map(|coins| { coins.iter().filter_map(|b| match b { CoinType::Coin(_) => None, - CoinType::MessageCoin(m) => Some(format!("{:#x}", m.nonce)), + CoinType::MessageCoin(m) => Some(m.nonce), CoinType::Unknown => None, }) }) .collect(); - let all_utxo_ids: Vec = coins_per_asset + let all_utxo_ids: Vec<_> = coins_per_asset .iter() .flat_map(|coins| { coins.iter().filter_map(|b| match b { - CoinType::Coin(c) => Some(format!("{:#x}", c.utxo_id)), + CoinType::Coin(c) => Some(c.utxo_id), CoinType::MessageCoin(_) => None, CoinType::Unknown => None, }) }) .collect(); - let all_message_ids: Vec<_> = - all_message_ids.iter().map(String::as_str).collect(); - let all_utxo_ids: Vec<_> = all_utxo_ids.iter().map(String::as_str).collect(); - // After setup we have 4 `Coin`s and 2 `Message`s assert_eq!(all_utxo_ids.len(), 4); assert_eq!(all_message_ids.len(), 2); @@ -716,11 +644,8 @@ mod all_coins { let coins_per_asset = context .client .coins_to_spend( - format!("{owner:#x}").as_str(), - vec![ - (format!("{asset_id_a:#x}").as_str(), 1, None), - (format!("{asset_id_b:#x}").as_str(), 1, None), - ], + &owner, + vec![(asset_id_a, 1, None), (asset_id_b, 1, None)], Some((all_utxo_ids, all_message_ids)), ) .await; @@ -742,11 +667,8 @@ mod all_coins { let coins_per_asset = context .client .coins_to_spend( - format!("{owner:#x}").as_str(), - vec![ - (format!("{asset_id_a:#x}").as_str(), 301, None), - (format!("{asset_id_b:#x}").as_str(), 301, None), - ], + &owner, + vec![(asset_id_a, 301, None), (asset_id_b, 301, None)], None, ) .await; @@ -768,11 +690,8 @@ mod all_coins { let coins_per_asset = context .client .coins_to_spend( - format!("{owner:#x}").as_str(), - vec![ - (format!("{asset_id_a:#x}").as_str(), 300, Some(2)), - (format!("{asset_id_b:#x}").as_str(), 300, Some(2)), - ], + &owner, + vec![(asset_id_a, 300, Some(2)), (asset_id_b, 300, Some(2))], None, ) .await; @@ -816,7 +735,7 @@ async fn coins_to_spend_empty( // empty spend_query let coins_per_asset = context .client - .coins_to_spend(format!("{owner:#x}").as_str(), vec![], None) + .coins_to_spend(&owner, vec![], None) .await .unwrap(); assert!(coins_per_asset.is_empty()); @@ -835,11 +754,11 @@ async fn coins_to_spend_error_duplicate_asset_query( let coins_per_asset = context .client .coins_to_spend( - format!("{owner:#x}").as_str(), + &owner, vec![ - (format!("{asset_id:#x}").as_str(), 1, None), - (format!("{asset_id:#x}").as_str(), 2, None), - (format!("{asset_id:#x}").as_str(), 3, None), + (asset_id, 1, None), + (asset_id, 2, None), + (asset_id, 3, None), ], None, ) diff --git a/tests/tests/contract.rs b/tests/tests/contract.rs index dabcf85f385..5e8a3254a56 100644 --- a/tests/tests/contract.rs +++ b/tests/tests/contract.rs @@ -47,10 +47,7 @@ async fn test_contract_balance( } = test_builder.finalize().await; let balance = client - .contract_balance( - format!("{contract_id:#x}").as_str(), - Some(format!("{asset:#x}").as_str()), - ) + .contract_balance(&contract_id, Some(&asset)) .await .unwrap(); @@ -87,7 +84,7 @@ async fn test_5_contract_balances( let contract_balances = client .contract_balances( - format!("{contract_id:#x}").as_str(), + &contract_id, PaginationRequest { cursor: None, results: 3, @@ -275,11 +272,7 @@ async fn can_get_message_proof() { ); // Get the receipts from the contract call. - let receipts = client - .receipts(transaction_id.to_string().as_str()) - .await - .unwrap() - .unwrap(); + let receipts = client.receipts(&transaction_id).await.unwrap().unwrap(); let logd = receipts .iter() .find(|f| matches!(f, Receipt::LogData { .. })) diff --git a/tests/tests/messages.rs b/tests/tests/messages.rs index dc291955363..5dec867a6c1 100644 --- a/tests/tests/messages.rs +++ b/tests/tests/messages.rs @@ -124,7 +124,7 @@ async fn messages_by_owner_returns_messages_for_the_given_owner() { // get the messages from Owner A let result = client - .messages(Some(&owner_a.to_string()), request.clone()) + .messages(Some(&owner_a), request.clone()) .await .unwrap(); @@ -138,7 +138,7 @@ async fn messages_by_owner_returns_messages_for_the_given_owner() { // get the messages from Owner B let result = client - .messages(Some(&owner_b.to_string()), request.clone()) + .messages(Some(&owner_b), request.clone()) .await .unwrap(); @@ -150,7 +150,7 @@ async fn messages_by_owner_returns_messages_for_the_given_owner() { // get the messages from Owner C let result = client - .messages(Some(&owner_c.to_string()), request.clone()) + .messages(Some(&owner_c), request.clone()) .await .unwrap(); @@ -175,10 +175,7 @@ async fn messages_empty_results_for_owner_with_no_messages( direction, }; - let result = client - .messages(Some(&owner.to_string()), request) - .await - .unwrap(); + let result = client.messages(Some(&owner), request).await.unwrap(); assert_eq!(result.results.len(), 0); } @@ -361,11 +358,7 @@ async fn can_get_message_proof() { let last_height = client.produce_blocks(1, None).await.unwrap(); // Get the receipts from the contract call. - let receipts = client - .receipts(transaction_id.to_string().as_str()) - .await - .unwrap() - .unwrap(); + let receipts = client.receipts(&transaction_id).await.unwrap().unwrap(); // Get the message id from the receipts. let message_ids: Vec<_> = @@ -377,12 +370,7 @@ async fn can_get_message_proof() { for message_id in message_ids.clone() { // Request the proof. let result = client - .message_proof( - transaction_id.to_string().as_str(), - message_id.to_string().as_str(), - None, - Some(last_height), - ) + .message_proof(&transaction_id, &message_id, None, Some(last_height)) .await .unwrap() .unwrap(); diff --git a/tests/tests/metrics.rs b/tests/tests/metrics.rs index 504bafcecdf..5c01e1d72fe 100644 --- a/tests/tests/metrics.rs +++ b/tests/tests/metrics.rs @@ -24,13 +24,7 @@ async fn test_metrics_endpoint() { let owner = Address::default(); let asset_id = AssetId::new([1u8; 32]); // Should generate some database reads - client - .balance( - format!("{owner:#x}").as_str(), - Some(format!("{asset_id:#x}").as_str()), - ) - .await - .unwrap(); + client.balance(&owner, Some(&asset_id)).await.unwrap(); let script = vec![ op::addi(0x10, RegId::ZERO, 0xca), diff --git a/tests/tests/tx.rs b/tests/tests/tx.rs index d8dec1c6450..e9d52a1f789 100644 --- a/tests/tests/tx.rs +++ b/tests/tests/tx.rs @@ -110,10 +110,7 @@ async fn dry_run_script() { // ensure the tx isn't available in the blockchain history let err = client - .transaction_status(&format!( - "{:#x}", - tx.id(&fuel_tx::ConsensusParameters::DEFAULT) - )) + .transaction_status(&tx.id(&fuel_tx::ConsensusParameters::DEFAULT)) .await .unwrap_err(); assert_eq!(err.kind(), NotFound); @@ -150,10 +147,7 @@ async fn dry_run_create() { // ensure the tx isn't available in the blockchain history let err = client - .transaction_status(&format!( - "{:#x}", - tx.id(&fuel_tx::ConsensusParameters::DEFAULT) - )) + .transaction_status(&tx.id(&fuel_tx::ConsensusParameters::DEFAULT)) .await .unwrap_err(); assert_eq!(err.kind(), NotFound); @@ -194,7 +188,7 @@ async fn submit() { client.submit_and_await_commit(&tx).await.unwrap(); // verify that the tx returned from the api matches the submitted tx let ret_tx = client - .transaction(&tx.id(&ConsensusParameters::DEFAULT).to_string()) + .transaction(&tx.id(&ConsensusParameters::DEFAULT)) .await .unwrap() .unwrap() @@ -229,7 +223,7 @@ async fn receipts() { .await .expect("transaction should insert"); // run test - let receipts = client.receipts(&format!("{id:#x}")).await.unwrap(); + let receipts = client.receipts(&id).await.unwrap(); assert!(receipts.is_some()); } @@ -246,7 +240,7 @@ async fn get_transaction_by_id() { client.submit_and_await_commit(&transaction).await.unwrap(); // run test - let transaction_response = client.transaction(&format!("{id:#x}")).await.unwrap(); + let transaction_response = client.transaction(&id).await.unwrap(); assert!(transaction_response.is_some()); if let Some(transaction_response) = transaction_response { assert!(matches!( @@ -270,7 +264,7 @@ async fn get_transparent_transaction_by_id() { assert!(result.is_ok()); let opaque_tx = client - .transaction(&format!("{id:#x}")) + .transaction(&id) .await .unwrap() .expect("expected some result") @@ -278,7 +272,7 @@ async fn get_transparent_transaction_by_id() { // run test let transparent_transaction = client - .transparent_transaction(&format!("{id:#x}")) + .transparent_transaction(&id) .await .unwrap() .expect("expected some value"); @@ -419,7 +413,7 @@ async fn get_transactions_by_owner_forward_and_backward_iterations() { direction: PageDirection::Forward, }; let response = client - .transactions_by_owner(bob.to_string().as_str(), all_transactions_forward) + .transactions_by_owner(&bob, all_transactions_forward) .await .unwrap(); let transactions_forward = response @@ -438,7 +432,7 @@ async fn get_transactions_by_owner_forward_and_backward_iterations() { direction: PageDirection::Backward, }; let response = client - .transactions_by_owner(bob.to_string().as_str(), all_transactions_backward) + .transactions_by_owner(&bob, all_transactions_backward) .await; // Backward request is not supported right now. assert!(response.is_err()); @@ -451,7 +445,7 @@ async fn get_transactions_by_owner_forward_and_backward_iterations() { direction: PageDirection::Forward, }; let response_after_iter_three = client - .transactions_by_owner(bob.to_string().as_str(), forward_iter_three) + .transactions_by_owner(&bob, forward_iter_three) .await .unwrap(); let transactions_forward_iter_three = response_after_iter_three @@ -473,7 +467,7 @@ async fn get_transactions_by_owner_forward_and_backward_iterations() { direction: PageDirection::Forward, }; let response = client - .transactions_by_owner(bob.to_string().as_str(), forward_iter_next_two) + .transactions_by_owner(&bob, forward_iter_next_two) .await .unwrap(); let transactions_forward_iter_next_two = response @@ -634,7 +628,7 @@ async fn get_owned_transactions() { direction: PageDirection::Forward, }; let alice_txs = client - .transactions_by_owner(&format!("{alice:#x}"), page_request.clone()) + .transactions_by_owner(&alice, page_request.clone()) .await .unwrap() .results @@ -643,7 +637,7 @@ async fn get_owned_transactions() { .collect_vec(); let bob_txs = client - .transactions_by_owner(&format!("{bob:#x}"), page_request.clone()) + .transactions_by_owner(&bob, page_request.clone()) .await .unwrap() .results @@ -652,7 +646,7 @@ async fn get_owned_transactions() { .collect_vec(); let charlie_txs = client - .transactions_by_owner(&format!("{charlie:#x}"), page_request.clone()) + .transactions_by_owner(&charlie, page_request.clone()) .await .unwrap() .results diff --git a/tests/tests/tx/predicates.rs b/tests/tests/tx/predicates.rs index ec40443e53f..d15010f91f3 100644 --- a/tests/tests/tx/predicates.rs +++ b/tests/tests/tx/predicates.rs @@ -56,7 +56,7 @@ async fn transaction_with_valid_predicate_is_executed() { // check transaction change amount to see if predicate was spent let transaction = context .client - .transaction(&predicate_tx.id(&ConsensusParameters::DEFAULT).to_string()) + .transaction(&predicate_tx.id(&ConsensusParameters::DEFAULT)) .await .unwrap() .unwrap() diff --git a/tests/tests/tx/tx_pointer.rs b/tests/tests/tx/tx_pointer.rs index 895337928ec..430aea82723 100644 --- a/tests/tests/tx/tx_pointer.rs +++ b/tests/tests/tx/tx_pointer.rs @@ -83,7 +83,7 @@ async fn tx_pointer_set_from_genesis_for_coin_and_contract_inputs() { // verify that the tx returned from the api has tx pointers set matching the genesis config let ret_tx = client - .transaction(&tx.id(&fuel_tx::ConsensusParameters::DEFAULT).to_string()) + .transaction(&tx.id(&fuel_tx::ConsensusParameters::DEFAULT)) .await .unwrap() .unwrap() @@ -137,7 +137,7 @@ async fn tx_pointer_set_from_previous_block() { let tx1 = tx1.into(); client.submit_and_await_commit(&tx1).await.unwrap(); let ret_tx1 = client - .transaction(&tx1.id(&fuel_tx::ConsensusParameters::DEFAULT).to_string()) + .transaction(&tx1.id(&fuel_tx::ConsensusParameters::DEFAULT)) .await .unwrap() .unwrap() @@ -156,7 +156,7 @@ async fn tx_pointer_set_from_previous_block() { client.submit_and_await_commit(&tx2).await.unwrap(); let ret_tx2 = client - .transaction(&tx2.id(&fuel_tx::ConsensusParameters::DEFAULT).to_string()) + .transaction(&tx2.id(&fuel_tx::ConsensusParameters::DEFAULT)) .await .unwrap() .unwrap() @@ -205,7 +205,7 @@ async fn tx_pointer_unset_when_utxo_validation_disabled() { client.submit_and_await_commit(&tx).await.unwrap(); let ret_tx = client - .transaction(&tx.id(&fuel_tx::ConsensusParameters::DEFAULT).to_string()) + .transaction(&tx.id(&fuel_tx::ConsensusParameters::DEFAULT)) .await .unwrap() .unwrap() diff --git a/tests/tests/tx/txn_status_subscription.rs b/tests/tests/tx/txn_status_subscription.rs index 482d521609e..08af6b39816 100644 --- a/tests/tests/tx/txn_status_subscription.rs +++ b/tests/tests/tx/txn_status_subscription.rs @@ -80,7 +80,7 @@ async fn subscribe_txn_status() { for (txn_idx, id) in txns .iter() - .map(|t| t.id(&ConsensusParameters::DEFAULT).to_string()) + .map(|t| t.id(&ConsensusParameters::DEFAULT)) .enumerate() { let jh = tokio::spawn({ diff --git a/tests/tests/tx/utxo_validation.rs b/tests/tests/tx/utxo_validation.rs index 6024168d214..5d16d267632 100644 --- a/tests/tests/tx/utxo_validation.rs +++ b/tests/tests/tx/utxo_validation.rs @@ -76,19 +76,20 @@ async fn submit_utxo_verified_tx_with_min_gas_price() { client.submit_and_await_commit(&tx).await.unwrap(); // verify that the tx returned from the api matches the submitted tx let ret_tx = client - .transaction(&tx.id(&ConsensusParameters::DEFAULT).to_string()) + .transaction(&tx.id(&ConsensusParameters::DEFAULT)) .await .unwrap() .unwrap() .transaction; let transaction_result = client - .transaction_status(&ret_tx.id(&ConsensusParameters::DEFAULT).to_string()) + .transaction_status(&ret_tx.id(&ConsensusParameters::DEFAULT)) .await .ok() .unwrap(); if let TransactionStatus::Success { block_id, .. } = transaction_result.clone() { + let block_id = block_id.parse().unwrap(); let block_exists = client.block(&block_id).await.unwrap(); assert!(block_exists.is_some()); diff --git a/tests/tests/tx_gossip.rs b/tests/tests/tx_gossip.rs index 2020732aff6..9fefa79dded 100644 --- a/tests/tests/tx_gossip.rs +++ b/tests/tests/tx_gossip.rs @@ -104,8 +104,7 @@ async fn test_tx_gossiping() { let wait_time = Duration::from_secs(10); tokio::time::sleep(wait_time).await; - let tx_id = tx.id(¶ms).to_string(); - + let tx_id = tx.id(¶ms); let tx = tx.into(); client_one.submit_and_await_commit(&tx).await.unwrap();