Skip to content

Commit

Permalink
[AptosFramework] migrate api tests
Browse files Browse the repository at this point in the history
  • Loading branch information
zekun000 authored and aptos-bot committed Mar 25, 2022
1 parent 07cd912 commit 4c08ffa
Show file tree
Hide file tree
Showing 7 changed files with 99 additions and 445 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion api/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ aptos-mempool = { path = "../mempool", features = ["fuzzing"] }
aptos-secure-storage = { path = "../secure/storage" }
aptos-temppath = { path = "../crates/aptos-temppath" }
aptos-genesis-tool = {path = "../config/management/genesis", features = ["testing"] }
diem-framework-releases = { path = "../aptos-move/framework/DPN/releases" }
aptos-framework-releases = { path = "../aptos-move/framework/aptos-framework/releases" }
aptos-sdk = { path = "../sdk" }
vm-validator = { path = "../vm-validator" }
aptos-vm = { path = "../aptos-move/aptos-vm" }
Expand Down
18 changes: 9 additions & 9 deletions api/src/tests/accounts_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -474,12 +474,12 @@ async fn test_account_modules_structs() {
async fn test_get_account_resources_by_ledger_version() {
let mut context = new_test_context();
let account = context.gen_account();
let txn = context.create_parent_vasp(&account);
let txn = context.create_user_account(&account);
context.commit_block(&vec![txn.clone()]).await;

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

let ledger_version_0_resources = context
.get(&account_resources_with_ledger_version(
&context.tc_account().address().to_hex_literal(),
&context.root_account().address().to_hex_literal(),
0,
))
.await;
Expand All @@ -505,7 +505,7 @@ async fn test_get_account_resources_by_ledger_version_is_too_large() {
let resp = context
.expect_status_code(404)
.get(&account_resources_with_ledger_version(
&context.tc_account().address().to_hex_literal(),
&context.root_account().address().to_hex_literal(),
1000000000000000000,
))
.await;
Expand All @@ -525,7 +525,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.tc_account().address().to_hex_literal(),
&context.root_account().address().to_hex_literal(),
-1,
))
.await;
Expand All @@ -542,7 +542,7 @@ async fn test_get_account_resources_by_invalid_ledger_version() {
async fn test_get_account_modules_by_ledger_version() {
let context = new_test_context();
let code = "a11ceb0b0300000006010002030205050703070a0c0816100c260900000001000100000102084d794d6f64756c650269640000000000000000000000000b1e55ed00010000000231010200";
let mut tc_account = context.tc_account();
let mut tc_account = context.root_account();
let txn = tc_account.sign_with_transaction_builder(
context
.transaction_factory()
Expand All @@ -552,14 +552,14 @@ async fn test_get_account_modules_by_ledger_version() {

let modules = context
.get(&account_modules(
&context.tc_account().address().to_hex_literal(),
&context.root_account().address().to_hex_literal(),
))
.await;
assert_ne!(modules, json!([]));

let modules = context
.get(&account_modules_with_ledger_version(
&context.tc_account().address().to_hex_literal(),
&context.root_account().address().to_hex_literal(),
0,
))
.await;
Expand All @@ -569,7 +569,7 @@ async fn test_get_account_modules_by_ledger_version() {
#[tokio::test]
async fn test_get_core_account_data() {
let context = new_test_context();
let auth_key = context.dd_account().authentication_key();
let auth_key = context.root_account().authentication_key();
let resp = context.get("/accounts/0xdd").await;
assert_eq!(
json!({
Expand Down
2 changes: 1 addition & 1 deletion 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 context = new_test_context();
let mut account = init_test_account();
let txn = context.create_parent_vasp(&account);
let txn = context.create_user_account(&account);
context.commit_block(&vec![txn]).await;

// module 0x87342d91af60c3a883a2812c9294c2f8::Message {
Expand Down
54 changes: 16 additions & 38 deletions api/src/tests/test_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,10 @@ use aptos_genesis_tool::validator_builder::{RootKeys, ValidatorBuilder};
use aptos_global_constants::OWNER_ACCOUNT;
use aptos_mempool::mocks::MockSharedMempool;
use aptos_sdk::{
transaction_builder::{Currency, TransactionFactory},
transaction_builder::TransactionFactory,
types::{
account_config::{aptos_root_address, treasury_compliance_account_address},
transaction::SignedTransaction,
AccountKey, LocalAccount,
account_config::aptos_root_address, transaction::SignedTransaction, AccountKey,
LocalAccount,
},
};
use aptos_secure_storage::KVStorage;
Expand Down Expand Up @@ -54,9 +53,10 @@ pub fn new_test_context() -> TestContext {
let mut rng = ::rand::rngs::StdRng::from_seed(rand::rngs::OsRng.gen());
let builder = ValidatorBuilder::new(
&tmp_dir,
diem_framework_releases::current_module_blobs().to_vec(),
aptos_framework_releases::current_module_blobs().to_vec(),
)
.publishing_option(VMPublishingOption::open());
.publishing_option(VMPublishingOption::open())
.min_price_per_gas_unit(0);

let (root_keys, genesis, genesis_waypoint, validators) = builder.build(&mut rng).unwrap();
let validator_owner = validators[0].storage().get(OWNER_ACCOUNT).unwrap().value;
Expand Down Expand Up @@ -127,22 +127,6 @@ impl TestContext {
TransactionFactory::new(self.context.chain_id())
}

pub fn tc_account(&self) -> LocalAccount {
LocalAccount::new(
treasury_compliance_account_address(),
self.root_keys.root_key.clone(),
0,
)
}

pub fn dd_account(&self) -> LocalAccount {
LocalAccount::new(
testnet_dd_account_address(),
self.root_keys.root_key.clone(),
0,
)
}

pub fn root_account(&self) -> LocalAccount {
LocalAccount::new(aptos_root_address(), self.root_keys.root_key.clone(), 0)
}
Expand All @@ -151,36 +135,30 @@ impl TestContext {
LocalAccount::generate(self.rng())
}

pub fn create_parent_vasp(&self, account: &LocalAccount) -> SignedTransaction {
let mut tc = self.tc_account();
self.create_parent_vasp_by_account(&mut tc, account)
pub fn create_user_account(&self, account: &LocalAccount) -> SignedTransaction {
let mut tc = self.root_account();
self.create_user_account_by(&mut tc, account)
}

pub fn create_parent_vasp_by_account(
pub fn create_user_account_by(
&self,
creator: &mut LocalAccount,
account: &LocalAccount,
) -> SignedTransaction {
let factory = self.transaction_factory();
creator.sign_with_transaction_builder(factory.create_parent_vasp_account(
Currency::XUS,
0,
account.authentication_key(),
"vasp",
true,
))
creator.sign_with_transaction_builder(factory.create_user_account(account.public_key()))
}

pub fn create_invalid_signature_transaction(&mut self) -> SignedTransaction {
let factory = self.transaction_factory();
let tc_account = self.tc_account();
let root_account = self.root_account();
let txn = factory
.create_recovery_address()
.sender(tc_account.address())
.sequence_number(tc_account.sequence_number())
.transfer(root_account.address(), 1)
.sender(root_account.address())
.sequence_number(root_account.sequence_number())
.build();
let invalid_key = AccountKey::generate(self.rng());
txn.sign(invalid_key.private_key(), tc_account.public_key().clone())
txn.sign(invalid_key.private_key(), root_account.public_key().clone())
.unwrap()
.into_inner()
}
Expand Down
Loading

0 comments on commit 4c08ffa

Please sign in to comment.