Skip to content

Commit

Permalink
refactor root_account and make it async base on #5894
Browse files Browse the repository at this point in the history
  • Loading branch information
angieyth committed Feb 10, 2023
1 parent 015261e commit 35d4056
Show file tree
Hide file tree
Showing 7 changed files with 85 additions and 67 deletions.
16 changes: 8 additions & 8 deletions api/src/tests/accounts_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,12 +111,12 @@ async fn test_account_modules_structs() {
async fn test_get_account_resources_by_ledger_version() {
let mut context = new_test_context(current_function_name!());
let account = context.gen_account();
let txn = context.create_user_account(&account);
let txn = context.create_user_account(&account).await;
context.commit_block(&vec![txn.clone()]).await;

let ledger_version_1_resources = context
.get(&account_resources(
&context.root_account().address().to_hex_literal(),
&context.root_account().await.address().to_hex_literal(),
))
.await;
let root_account = find_value(&ledger_version_1_resources, |f| {
Expand All @@ -126,7 +126,7 @@ async fn test_get_account_resources_by_ledger_version() {

let ledger_version_0_resources = context
.get(&account_resources_with_ledger_version(
&context.root_account().address().to_hex_literal(),
&context.root_account().await.address().to_hex_literal(),
0,
))
.await;
Expand All @@ -142,7 +142,7 @@ async fn test_get_account_resources_by_too_large_ledger_version() {
let resp = context
.expect_status_code(404)
.get(&account_resources_with_ledger_version(
&context.root_account().address().to_hex_literal(),
&context.root_account().await.address().to_hex_literal(),
1000000000000000000,
))
.await;
Expand All @@ -155,7 +155,7 @@ async fn test_get_account_resources_by_invalid_ledger_version() {
let resp = context
.expect_status_code(400)
.get(&account_resources_with_ledger_version(
&context.root_account().address().to_hex_literal(),
&context.root_account().await.address().to_hex_literal(),
-1,
))
.await;
Expand All @@ -168,7 +168,7 @@ async fn test_get_account_resources_by_invalid_ledger_version() {
async fn test_get_account_modules_by_ledger_version() {
let mut context = new_test_context(current_function_name!());
let code = "a11ceb0b0300000006010002030205050703070a0c0816100c260900000001000100000102084d794d6f64756c650269640000000000000000000000000b1e55ed00010000000231010200";
let mut root_account = context.root_account();
let mut root_account = context.root_account().await;
let txn = root_account.sign_with_transaction_builder(
context
.transaction_factory()
Expand All @@ -177,15 +177,15 @@ async fn test_get_account_modules_by_ledger_version() {
context.commit_block(&vec![txn.clone()]).await;
let modules = context
.get(&account_modules(
&context.root_account().address().to_hex_literal(),
&context.root_account().await.address().to_hex_literal(),
))
.await;

assert_ne!(modules, json!([]));

let modules = context
.get(&account_modules_with_ledger_version(
&context.root_account().address().to_hex_literal(),
&context.root_account().await.address().to_hex_literal(),
0,
))
.await;
Expand Down
7 changes: 3 additions & 4 deletions api/src/tests/resource_groups.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,9 @@ async fn test_read_resource_group() {
let mut context = new_test_context(current_function_name!());

// Prepare accounts
let mut root = context.root_account();
let mut admin0 = context.create_account(&mut root).await;
let mut admin1 = context.create_account(&mut root).await;
let mut user = context.create_account(&mut root).await;
let mut admin0 = context.create_account().await;
let mut admin1 = context.create_account().await;
let mut user = context.create_account().await;

// Publish packages
let named_addresses = vec![
Expand Down
6 changes: 3 additions & 3 deletions api/src/tests/state_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ async fn test_merkle_leaves_with_nft_transfer() {
let ctx = &mut context;
let creator = &mut ctx.gen_account();
let owner = &mut ctx.gen_account();
let txn1 = ctx.mint_user_account(creator);
let txn1 = ctx.mint_user_account(creator).await;
let txn2 = ctx.account_transfer(creator, owner, 100_000);

let collection_name = "collection name".to_owned().into_bytes();
Expand Down Expand Up @@ -222,14 +222,14 @@ async fn test_get_table_item() {
let ctx = &mut context;
let mut account = ctx.gen_account();
let acc = &mut account;
let txn = ctx.create_user_account(acc);
let txn = ctx.create_user_account(acc).await;
ctx.commit_block(&vec![txn.clone()]).await;
make_test_tables(ctx, acc).await;

// get the TestTables instance
let tt = ctx
.api_get_account_resource(
acc,
acc.address(),
&acc.address().to_hex_literal(),
"TableTestData",
"TestTables",
Expand Down
4 changes: 2 additions & 2 deletions api/src/tests/string_resource_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use std::convert::TryInto;
async fn test_renders_move_acsii_string_into_utf8_string() {
let mut context = new_test_context(current_function_name!());
let mut account = init_test_account();
let txn = context.create_user_account(&account);
let txn = context.create_user_account(&account).await;
context.commit_block(&vec![txn]).await;

// module 0x87342d91af60c3a883a2812c9294c2f8::Message {
Expand Down Expand Up @@ -45,7 +45,7 @@ async fn test_renders_move_acsii_string_into_utf8_string() {

let message = context
.api_get_account_resource(
&account,
account.address(),
&account.address().to_hex_literal(),
"Message",
"MessageHolder",
Expand Down
Loading

0 comments on commit 35d4056

Please sign in to comment.