Skip to content

Commit

Permalink
chore: update deprecated functions (#1293)
Browse files Browse the repository at this point in the history
  • Loading branch information
hal3e authored Mar 7, 2024
1 parent 5b833de commit fa17c52
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 42 deletions.
5 changes: 2 additions & 3 deletions packages/fuels-core/src/types/wrappers/block.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#![cfg(feature = "std")]

use chrono::{DateTime, NaiveDateTime, Utc};
use chrono::{DateTime, Utc};
use fuel_core_client::client::types::{
block::{Block as ClientBlock, Header as ClientHeader},
primitives::Bytes32,
Expand All @@ -22,8 +22,7 @@ pub struct Header {

impl From<ClientHeader> for Header {
fn from(client_header: ClientHeader) -> Self {
let naive = NaiveDateTime::from_timestamp_opt(client_header.time.to_unix(), 0);
let time = naive.map(|time| DateTime::<Utc>::from_naive_utc_and_offset(time, Utc));
let time = DateTime::from_timestamp(client_header.time.to_unix(), 0);

Self {
id: client_header.id,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

use std::str::FromStr;

use chrono::{DateTime, NaiveDateTime, Utc};
use chrono::{DateTime, Utc};
use fuel_core_client::client::types::{
TransactionResponse as ClientTransactionResponse, TransactionStatus as ClientTransactionStatus,
};
Expand Down Expand Up @@ -38,8 +38,7 @@ impl From<ClientTransactionResponse> for TransactionResponse {
| ClientTransactionStatus::SqueezedOut { .. } => None,
ClientTransactionStatus::Success { time, .. }
| ClientTransactionStatus::Failure { time, .. } => {
let native = NaiveDateTime::from_timestamp_opt(time.to_unix(), 0);
native.map(|time| DateTime::<Utc>::from_naive_utc_and_offset(time, Utc))
DateTime::from_timestamp(time.to_unix(), 0)
}
};

Expand Down
2 changes: 1 addition & 1 deletion packages/fuels-programs/src/call_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -635,7 +635,7 @@ mod test {
const SELECTOR_LEN: usize = WORD_SIZE;
const NUM_CALLS: usize = 3;

let contract_ids = vec![
let contract_ids = [
Bech32ContractId::new("test", Bytes32::new([1u8; 32])),
Bech32ContractId::new("test", Bytes32::new([1u8; 32])),
Bech32ContractId::new("test", Bytes32::new([1u8; 32])),
Expand Down
25 changes: 0 additions & 25 deletions packages/fuels-test-helpers/src/node_types.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use std::{
fmt,
net::{Ipv4Addr, SocketAddr},
path::PathBuf,
time::Duration,
Expand Down Expand Up @@ -98,30 +97,6 @@ impl From<Config> for fuel_core::service::Config {
}
}

pub(crate) struct HexType;

impl<T: AsRef<[u8]>> SerializeAs<T> for HexType {
fn serialize_as<S>(value: &T, serializer: S) -> Result<S::Ok, S::Error>
where
S: Serializer,
{
serde_hex::serialize(value, serializer)
}
}

impl<'de, T, E> DeserializeAs<'de, T> for HexType
where
for<'a> T: TryFrom<&'a [u8], Error = E>,
E: fmt::Display,
{
fn deserialize_as<D>(deserializer: D) -> Result<T, D::Error>
where
D: Deserializer<'de>,
{
serde_hex::deserialize(deserializer)
}
}

pub(crate) mod serde_hex {
use std::{convert::TryFrom, fmt};

Expand Down
18 changes: 8 additions & 10 deletions packages/fuels/tests/providers.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::{ops::Add, str::FromStr};

use chrono::{DateTime, Duration, NaiveDateTime, TimeZone, Utc};
use chrono::{DateTime, Duration, TimeZone, Utc};
use fuels::{
accounts::Account,
client::{PageDirection, PaginationRequest},
Expand Down Expand Up @@ -234,7 +234,7 @@ async fn can_set_custom_block_time() -> Result<()> {
provider.produce_blocks(blocks_to_produce, None).await?;
assert_eq!(provider.latest_block_height().await?, blocks_to_produce);
let expected_latest_block_time = origin_block_time
.checked_add_signed(Duration::seconds((blocks_to_produce * block_time) as i64))
.checked_add_signed(Duration::try_seconds((blocks_to_produce * block_time) as i64).unwrap())
.unwrap();
assert_eq!(
provider.latest_block_time().await?.unwrap(),
Expand Down Expand Up @@ -738,10 +738,7 @@ fn given_a_message(address: Bech32Address, message_amount: u64) -> Message {

fn convert_to_datetime(timestamp: u64) -> DateTime<Utc> {
let unix = tai64::Tai64(timestamp).to_unix();
NaiveDateTime::from_timestamp_opt(unix, 0)
.unwrap()
.and_local_timezone(Utc)
.unwrap()
DateTime::from_timestamp(unix, 0).unwrap()
}

/// This test is here in addition to `can_set_custom_block_time` because even though this test
Expand Down Expand Up @@ -781,7 +778,8 @@ async fn test_sway_timestamp() -> Result<()> {
let methods = contract_instance.methods();

let response = methods.return_timestamp().call().await?;
let mut expected_datetime = origin_timestamp.add(Duration::seconds(block_time as i64));
let mut expected_datetime =
origin_timestamp.add(Duration::try_seconds(block_time as i64).unwrap());
assert_eq!(convert_to_datetime(response.value), expected_datetime);

let blocks_to_produce = 600;
Expand All @@ -790,10 +788,10 @@ async fn test_sway_timestamp() -> Result<()> {
let response = methods.return_timestamp().call().await?;

// `produce_blocks` call
expected_datetime =
expected_datetime.add(Duration::seconds((block_time * blocks_to_produce) as i64));
expected_datetime = expected_datetime
.add(Duration::try_seconds((block_time * blocks_to_produce) as i64).unwrap());
// method call
expected_datetime = expected_datetime.add(Duration::seconds(block_time as i64));
expected_datetime = expected_datetime.add(Duration::try_seconds(block_time as i64).unwrap());

assert_eq!(convert_to_datetime(response.value), expected_datetime);
assert_eq!(
Expand Down

0 comments on commit fa17c52

Please sign in to comment.