Skip to content

Commit fa17c52

Browse files
authored
chore: update deprecated functions (#1293)
1 parent 5b833de commit fa17c52

File tree

5 files changed

+13
-42
lines changed

5 files changed

+13
-42
lines changed

packages/fuels-core/src/types/wrappers/block.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#![cfg(feature = "std")]
22

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

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

2827
Self {
2928
id: client_header.id,

packages/fuels-core/src/types/wrappers/transaction_response.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
use std::str::FromStr;
44

5-
use chrono::{DateTime, NaiveDateTime, Utc};
5+
use chrono::{DateTime, Utc};
66
use fuel_core_client::client::types::{
77
TransactionResponse as ClientTransactionResponse, TransactionStatus as ClientTransactionStatus,
88
};
@@ -38,8 +38,7 @@ impl From<ClientTransactionResponse> for TransactionResponse {
3838
| ClientTransactionStatus::SqueezedOut { .. } => None,
3939
ClientTransactionStatus::Success { time, .. }
4040
| ClientTransactionStatus::Failure { time, .. } => {
41-
let native = NaiveDateTime::from_timestamp_opt(time.to_unix(), 0);
42-
native.map(|time| DateTime::<Utc>::from_naive_utc_and_offset(time, Utc))
41+
DateTime::from_timestamp(time.to_unix(), 0)
4342
}
4443
};
4544

packages/fuels-programs/src/call_utils.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -635,7 +635,7 @@ mod test {
635635
const SELECTOR_LEN: usize = WORD_SIZE;
636636
const NUM_CALLS: usize = 3;
637637

638-
let contract_ids = vec![
638+
let contract_ids = [
639639
Bech32ContractId::new("test", Bytes32::new([1u8; 32])),
640640
Bech32ContractId::new("test", Bytes32::new([1u8; 32])),
641641
Bech32ContractId::new("test", Bytes32::new([1u8; 32])),

packages/fuels-test-helpers/src/node_types.rs

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
use std::{
2-
fmt,
32
net::{Ipv4Addr, SocketAddr},
43
path::PathBuf,
54
time::Duration,
@@ -98,30 +97,6 @@ impl From<Config> for fuel_core::service::Config {
9897
}
9998
}
10099

101-
pub(crate) struct HexType;
102-
103-
impl<T: AsRef<[u8]>> SerializeAs<T> for HexType {
104-
fn serialize_as<S>(value: &T, serializer: S) -> Result<S::Ok, S::Error>
105-
where
106-
S: Serializer,
107-
{
108-
serde_hex::serialize(value, serializer)
109-
}
110-
}
111-
112-
impl<'de, T, E> DeserializeAs<'de, T> for HexType
113-
where
114-
for<'a> T: TryFrom<&'a [u8], Error = E>,
115-
E: fmt::Display,
116-
{
117-
fn deserialize_as<D>(deserializer: D) -> Result<T, D::Error>
118-
where
119-
D: Deserializer<'de>,
120-
{
121-
serde_hex::deserialize(deserializer)
122-
}
123-
}
124-
125100
pub(crate) mod serde_hex {
126101
use std::{convert::TryFrom, fmt};
127102

packages/fuels/tests/providers.rs

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use std::{ops::Add, str::FromStr};
22

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

739739
fn convert_to_datetime(timestamp: u64) -> DateTime<Utc> {
740740
let unix = tai64::Tai64(timestamp).to_unix();
741-
NaiveDateTime::from_timestamp_opt(unix, 0)
742-
.unwrap()
743-
.and_local_timezone(Utc)
744-
.unwrap()
741+
DateTime::from_timestamp(unix, 0).unwrap()
745742
}
746743

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

783780
let response = methods.return_timestamp().call().await?;
784-
let mut expected_datetime = origin_timestamp.add(Duration::seconds(block_time as i64));
781+
let mut expected_datetime =
782+
origin_timestamp.add(Duration::try_seconds(block_time as i64).unwrap());
785783
assert_eq!(convert_to_datetime(response.value), expected_datetime);
786784

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

792790
// `produce_blocks` call
793-
expected_datetime =
794-
expected_datetime.add(Duration::seconds((block_time * blocks_to_produce) as i64));
791+
expected_datetime = expected_datetime
792+
.add(Duration::try_seconds((block_time * blocks_to_produce) as i64).unwrap());
795793
// method call
796-
expected_datetime = expected_datetime.add(Duration::seconds(block_time as i64));
794+
expected_datetime = expected_datetime.add(Duration::try_seconds(block_time as i64).unwrap());
797795

798796
assert_eq!(convert_to_datetime(response.value), expected_datetime);
799797
assert_eq!(

0 commit comments

Comments
 (0)