Skip to content

Commit

Permalink
jsonrpc: add test for sorted coin balances
Browse files Browse the repository at this point in the history
  • Loading branch information
bmwill committed Oct 11, 2024
1 parent eccf6e3 commit 37387e2
Showing 1 changed file with 34 additions and 1 deletion.
35 changes: 34 additions & 1 deletion crates/sui-json-rpc-tests/tests/rpc_server_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,9 @@ use sui_json_rpc_types::{
use sui_macros::sim_test;
use sui_move_build::BuildConfig;
use sui_swarm_config::genesis_config::{DEFAULT_GAS_AMOUNT, DEFAULT_NUMBER_OF_OBJECT_PER_ACCOUNT};
use sui_test_transaction_builder::make_transfer_sui_transaction;
use sui_types::balance::Supply;
use sui_types::base_types::ObjectID;
use sui_types::base_types::{ObjectID, SuiAddress};
use sui_types::base_types::SequenceNumber;
use sui_types::coin::{TreasuryCap, COIN_MODULE_NAME};
use sui_types::digests::ObjectDigest;
Expand Down Expand Up @@ -402,6 +403,38 @@ async fn test_get_coins() -> Result<(), anyhow::Error> {
Ok(())
}

#[sim_test]
async fn test_sorted_get_coin_response() {
let cluster = TestClusterBuilder::new().build().await;
let http_client = cluster.rpc_client();

let address = SuiAddress::random_for_testing_only();

// send 5 coins to address `address` with different values
let amounts = [1, 2, 3, 4, 5];
for amount in amounts {
let tx =
make_transfer_sui_transaction(&cluster.wallet, Some(address), Some(amount)).await;
let (tx_bytes, signatures) = tx.to_tx_bytes_and_signatures();

http_client
.execute_transaction_block(tx_bytes, signatures, None, None)
.await
.unwrap();
sleep(Duration::from_millis(1000)).await;
}

sleep(Duration::from_millis(1000)).await;

let coins: CoinPage = http_client.get_coins(address, None, None, None).await.unwrap();
assert_eq!(amounts.len(), coins.data.len());

let balances = coins.data.iter().map(|coin| coin.balance).collect::<Vec<_>>();
let mut sorted_amounts = amounts;
sorted_amounts.reverse();
assert_eq!(sorted_amounts.as_slice(), balances.as_slice());
}

#[sim_test]
async fn test_get_balance() -> Result<(), anyhow::Error> {
let cluster = TestClusterBuilder::new().build().await;
Expand Down

0 comments on commit 37387e2

Please sign in to comment.