Skip to content

Commit

Permalink
[Gateway] Fix get_owned_objects bug (MystenLabs#1439)
Browse files Browse the repository at this point in the history
  • Loading branch information
666lcz authored Apr 19, 2022
1 parent 4fdb161 commit 50e2c0d
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 22 deletions.
6 changes: 3 additions & 3 deletions sui/src/rest_gateway.rs
Original file line number Diff line number Diff line change
Expand Up @@ -194,13 +194,13 @@ impl GatewayAPI for RestGatewayClient {
.await?)
}

fn get_owned_objects(
async fn get_owned_objects(
&mut self,
account_addr: SuiAddress,
) -> Result<Vec<ObjectRef>, anyhow::Error> {
let url = format!("{}/api/objects?address={}", self.url, account_addr);
let response = reqwest::blocking::get(url)?;
let response: ObjectResponse = response.json()?;
let response = reqwest::get(url).await?;
let response: ObjectResponse = response.json().await?;
let objects = response
.objects
.into_iter()
Expand Down
1 change: 1 addition & 0 deletions sui/src/rest_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,7 @@ async fn get_objects(

let objects = gateway
.get_owned_objects(*address)
.await
.unwrap()
.into_iter()
.map(NamedObjectRef::from)
Expand Down
28 changes: 14 additions & 14 deletions sui/src/unit_tests/cli_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ async fn test_objects_command() -> Result<(), anyhow::Error> {
.await?
.print(true);

let object_refs = context.gateway.get_owned_objects(address)?;
let object_refs = context.gateway.get_owned_objects(address).await?;

// Check log output contains all object ids.
for (object_id, _, _) in object_refs {
Expand Down Expand Up @@ -420,7 +420,7 @@ async fn test_object_info_get_command() -> Result<(), anyhow::Error> {
.await?
.print(true);

let object_refs = context.gateway.get_owned_objects(address)?;
let object_refs = context.gateway.get_owned_objects(address).await?;

// Check log output contains all object ids.
let object_id = object_refs.first().unwrap().0;
Expand Down Expand Up @@ -459,7 +459,7 @@ async fn test_gas_command() -> Result<(), anyhow::Error> {
.execute(&mut context)
.await?;

let object_refs = context.gateway.get_owned_objects(address)?;
let object_refs = context.gateway.get_owned_objects(address).await?;

let object_id = object_refs.first().unwrap().0;
let object_to_send = object_refs.get(1).unwrap().0;
Expand Down Expand Up @@ -666,7 +666,7 @@ async fn test_move_call_args_linter_command() -> Result<(), anyhow::Error> {
.print(true);
tokio::time::sleep(Duration::from_millis(2000)).await;

let object_refs = context.gateway.get_owned_objects(address1)?;
let object_refs = context.gateway.get_owned_objects(address1).await?;

// Check log output contains all object ids.
for (object_id, _, _) in &object_refs {
Expand Down Expand Up @@ -835,7 +835,7 @@ async fn test_package_publish_command() -> Result<(), anyhow::Error> {
.await?
.print(true);

let object_refs = context.gateway.get_owned_objects(address)?;
let object_refs = context.gateway.get_owned_objects(address).await?;

// Check log output contains all object ids.
let gas_obj_id = object_refs.first().unwrap().0;
Expand Down Expand Up @@ -917,7 +917,7 @@ async fn test_native_transfer() -> Result<(), anyhow::Error> {
.await?
.print(true);

let object_refs = context.gateway.get_owned_objects(address)?;
let object_refs = context.gateway.get_owned_objects(address).await?;

// Check log output contains all object ids.
let gas_obj_id = object_refs.first().unwrap().0;
Expand Down Expand Up @@ -1012,7 +1012,7 @@ async fn test_native_transfer() -> Result<(), anyhow::Error> {
.await?
.print(true);

let object_refs = context.gateway.get_owned_objects(address)?;
let object_refs = context.gateway.get_owned_objects(address).await?;

// Check log output contains all object ids.
let obj_id = object_refs.get(1).unwrap().0;
Expand Down Expand Up @@ -1088,7 +1088,7 @@ async fn test_switch_command() -> Result<(), anyhow::Error> {
.execute(&mut context)
.await?;

// Run a command with address ommited
// Run a command with address omitted
let os = WalletCommands::Objects { address: None }
.execute(&mut context)
.await?;
Expand All @@ -1100,7 +1100,7 @@ async fn test_switch_command() -> Result<(), anyhow::Error> {
};

// Check that we indeed fetched for addr1
let mut actual_objs = context.gateway.get_owned_objects(addr1).unwrap();
let mut actual_objs = context.gateway.get_owned_objects(addr1).await.unwrap();
cmd_objs.sort();
actual_objs.sort();
assert_eq!(cmd_objs, actual_objs);
Expand Down Expand Up @@ -1171,7 +1171,7 @@ async fn test_active_address_command() -> Result<(), anyhow::Error> {
.execute(&mut context)
.await?;

// Run a command with address ommited
// Run a command with address omitted
let os = WalletCommands::ActiveAddress {}
.execute(&mut context)
.await?;
Expand Down Expand Up @@ -1233,7 +1233,7 @@ async fn test_merge_coin() -> Result<(), anyhow::Error> {
.await?
.print(true);

let object_refs = context.gateway.get_owned_objects(address)?;
let object_refs = context.gateway.get_owned_objects(address).await?;

// Check log output contains all object ids.
let gas = object_refs.first().unwrap().0;
Expand Down Expand Up @@ -1271,7 +1271,7 @@ async fn test_merge_coin() -> Result<(), anyhow::Error> {
}
.execute(&mut context)
.await?;
let object_refs = context.gateway.get_owned_objects(address)?;
let object_refs = context.gateway.get_owned_objects(address).await?;

let primary_coin = object_refs.get(1).unwrap().0;
let coin_to_merge = object_refs.get(2).unwrap().0;
Expand Down Expand Up @@ -1326,7 +1326,7 @@ async fn test_split_coin() -> Result<(), anyhow::Error> {
.await?
.print(true);

let object_refs = context.gateway.get_owned_objects(address)?;
let object_refs = context.gateway.get_owned_objects(address).await?;

// Check log output contains all object ids.
let gas = object_refs.first().unwrap().0;
Expand Down Expand Up @@ -1362,7 +1362,7 @@ async fn test_split_coin() -> Result<(), anyhow::Error> {
.await?
.print(true);

let object_refs = context.gateway.get_owned_objects(address)?;
let object_refs = context.gateway.get_owned_objects(address).await?;

// Get another coin
for c in object_refs {
Expand Down
4 changes: 2 additions & 2 deletions sui/src/wallet_commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -409,7 +409,7 @@ impl WalletCommands {
Some(a) => *a,
None => context.active_address()?,
};
WalletCommandResult::Objects(context.gateway.get_owned_objects(address)?)
WalletCommandResult::Objects(context.gateway.get_owned_objects(address).await?)
}

WalletCommands::SyncClientState { address } => {
Expand Down Expand Up @@ -586,7 +586,7 @@ impl WalletContext {
&mut self,
address: SuiAddress,
) -> Result<Vec<(u64, Object)>, anyhow::Error> {
let object_refs = self.gateway.get_owned_objects(address)?;
let object_refs = self.gateway.get_owned_objects(address).await?;

// TODO: We should ideally fetch the objects from local cache
let mut values_objects = Vec::new();
Expand Down
4 changes: 2 additions & 2 deletions sui_core/src/gateway_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ pub trait GatewayAPI {
async fn get_object_info(&self, object_id: ObjectID) -> Result<ObjectRead, anyhow::Error>;

/// Get refs of all objects we own from local cache.
fn get_owned_objects(
async fn get_owned_objects(
&mut self,
account_addr: SuiAddress,
) -> Result<Vec<ObjectRef>, anyhow::Error>;
Expand Down Expand Up @@ -733,7 +733,7 @@ where
Ok(result)
}

fn get_owned_objects(
async fn get_owned_objects(
&mut self,
account_addr: SuiAddress,
) -> Result<Vec<ObjectRef>, anyhow::Error> {
Expand Down
2 changes: 1 addition & 1 deletion sui_core/src/unit_tests/gateway_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -773,7 +773,7 @@ async fn test_client_state_sync_with_transferred_object() {
);

// Confirm client 2 received the new object id
assert_eq!(1, client.get_owned_objects(addr2).unwrap().len());
assert_eq!(1, client.get_owned_objects(addr2).await.unwrap().len());
}

#[tokio::test]
Expand Down

0 comments on commit 50e2c0d

Please sign in to comment.