Skip to content

Commit

Permalink
Fix test failure
Browse files Browse the repository at this point in the history
  • Loading branch information
lxfind committed Sep 5, 2024
1 parent 817f157 commit 3feeae9
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/gas_pool/gas_pool_core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ impl GasPool {
);
#[cfg(test)]
{
self.sui_client.wait_for_object(new_gas_coin).await;
assert_eq!(
self.get_total_gas_coin_balance(payment).await,
new_balance as u64
Expand Down
25 changes: 24 additions & 1 deletion src/sui_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,14 @@ use futures_util::stream::FuturesUnordered;
use futures_util::StreamExt;
use itertools::Itertools;
use std::collections::HashMap;
use std::time::Duration;
use sui_json_rpc_types::SuiTransactionBlockEffectsAPI;
use sui_json_rpc_types::{
SuiData, SuiObjectDataOptions, SuiObjectResponse, SuiTransactionBlockEffects,
SuiTransactionBlockResponseOptions,
};
use sui_sdk::SuiClientBuilder;
use sui_types::base_types::{ObjectID, SuiAddress};
use sui_types::base_types::{ObjectID, ObjectRef, SuiAddress};
use sui_types::coin::{PAY_MODULE_NAME, PAY_SPLIT_N_FUNC_NAME};
use sui_types::gas_coin::GAS;
use sui_types::programmable_transaction_builder::ProgrammableTransactionBuilder;
Expand Down Expand Up @@ -224,6 +225,28 @@ impl SuiClient {
response
}

/// Wait for a known valid object version to be available on the fullnode.
pub async fn wait_for_object(&self, obj_ref: ObjectRef) {
loop {
let response = self
.sui_client
.read_api()
.get_object_with_options(obj_ref.0, SuiObjectDataOptions::default())
.await;
match response {
Ok(SuiObjectResponse {
data: Some(data), ..
}) => {
if data.version == obj_ref.1 {
break;
}
}
_ => (),
}
tokio::time::sleep(Duration::from_millis(200)).await;
}
}

fn try_get_sui_coin_balance(object: &SuiObjectResponse) -> Option<GasCoin> {
let data = object.data.as_ref()?;
let object_ref = data.object_ref();
Expand Down

0 comments on commit 3feeae9

Please sign in to comment.