Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
ngkuru committed Aug 11, 2023
1 parent b6fec42 commit bbbb245
Show file tree
Hide file tree
Showing 8 changed files with 60 additions and 57 deletions.
2 changes: 1 addition & 1 deletion crates/aptos-api-tester/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@

mod consts;
mod counters;
mod fail_message;
mod persistent_check;
mod strings;
mod tests;
mod token_client;
mod utils;
Expand Down
2 changes: 1 addition & 1 deletion crates/aptos-api-tester/src/persistent_check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

use crate::{
consts::{PERSISTENCY_TIMEOUT, SLEEP_PER_CYCLE},
fail_message::ERROR_COULD_NOT_CHECK,
strings::ERROR_COULD_NOT_CHECK,
token_client::TokenClient,
utils::TestFailure,
};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
// Copyright © Aptos Foundation

// Fail messages

pub const FAIL_WRONG_ACCOUNT_DATA: &str = "wrong account data";
pub const FAIL_WRONG_BALANCE: &str = "wrong balance";
pub const FAIL_WRONG_BALANCE_AT_VERSION: &str = "wrong balance at version";
Expand All @@ -8,6 +10,9 @@ pub const FAIL_WRONG_MESSAGE: &str = "wrong message";
pub const FAIL_WRONG_MODULE: &str = "wrong module";
pub const FAIL_WRONG_TOKEN_BALANCE: &str = "wrong token balance";
pub const FAIL_WRONG_TOKEN_DATA: &str = "wrong token data";

// Error messages

pub const ERROR_COULD_NOT_BUILD_PACKAGE: &str = "failed to build package";
pub const ERROR_COULD_NOT_CHECK: &str = "persistency check never started";
pub const ERROR_COULD_NOT_CREATE_ACCOUNT: &str = "failed to create account";
Expand All @@ -25,3 +30,25 @@ pub const ERROR_NO_MODULE: &str = "can't find module";
pub const ERROR_NO_TOKEN_BALANCE: &str = "can't find token balance";
pub const ERROR_NO_TOKEN_DATA: &str = "can't find token data";
pub const ERROR_NO_VERSION: &str = "can't find transaction version";

// Step names

pub const SETUP: &str = "setup";
pub const CHECK_ACCOUNT_DATA: &str = "check_account_data";
pub const FUND: &str = "fund";
pub const CHECK_ACCOUNT_BALANCE: &str = "check_account_balance";
pub const TRANSFER_COINS: &str = "transfer_coins";
pub const CHECK_ACCOUNT_BALANCE_AT_VERSION: &str = "check_account_balance_at_version";
pub const CREATE_COLLECTION: &str = "create_collection";
pub const CHECK_COLLECTION_METADATA: &str = "check_collection_metadata";
pub const CREATE_TOKEN: &str = "create_token";
pub const CHECK_TOKEN_METADATA: &str = "check_token_metadata";
pub const CHECK_SENDER_BALANCE: &str = "check_sender_balance";
pub const OFFER_TOKEN: &str = "offer_token";
pub const CLAIM_TOKEN: &str = "claim_token";
pub const CHECK_RECEIVER_BALANCE: &str = "check_receiver_balance";
pub const BUILD_MODULE: &str = "build_module";
pub const PUBLISH_MODULE: &str = "publish_module";
pub const CHECK_MODULE_DATA: &str = "check_module_data";
pub const SET_MESSAGE: &str = "set_message";
pub const CHECK_MESSAGE: &str = "check_message";
16 changes: 6 additions & 10 deletions crates/aptos-api-tester/src/tests/coin_transfer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,17 @@

use crate::{
consts::FUND_AMOUNT,
fail_message::{
persistent_check,
strings::{
CHECK_ACCOUNT_BALANCE, CHECK_ACCOUNT_BALANCE_AT_VERSION, CHECK_ACCOUNT_DATA,
ERROR_COULD_NOT_CREATE_ACCOUNT, ERROR_COULD_NOT_CREATE_TRANSACTION,
ERROR_COULD_NOT_FINISH_TRANSACTION, ERROR_COULD_NOT_FUND_ACCOUNT, ERROR_NO_BALANCE,
ERROR_NO_VERSION, FAIL_WRONG_BALANCE, FAIL_WRONG_BALANCE_AT_VERSION,
ERROR_NO_VERSION, FAIL_WRONG_BALANCE, FAIL_WRONG_BALANCE_AT_VERSION, SETUP, TRANSFER_COINS,
},
persistent_check, time_fn,
time_fn,
utils::{
check_balance, create_account, create_and_fund_account, emit_step_metrics, get_client,
get_faucet_client, NetworkName, TestFailure, TestName, CHECK_ACCOUNT_DATA, SETUP,
get_faucet_client, NetworkName, TestFailure, TestName,
},
};
use anyhow::{anyhow, Result};
Expand All @@ -20,14 +22,8 @@ use aptos_rest_client::Client;
use aptos_sdk::{coin_client::CoinClient, types::LocalAccount};
use aptos_types::account_address::AccountAddress;

// variables
const TRANSFER_AMOUNT: u64 = 1_000;

// step names
const TRANSFER_COINS: &str = "TRANSFER_COINS";
const CHECK_ACCOUNT_BALANCE: &str = "CHECK_ACCOUNT_BALANCE";
const CHECK_ACCOUNT_BALANCE_AT_VERSION: &str = "CHECK_ACCOUNT_BALANCE_AT_VERSION";

/// Tests coin transfer. Checks that:
/// - receiver balance reflects transferred amount
/// - receiver balance shows correct amount at the previous version
Expand Down
15 changes: 6 additions & 9 deletions crates/aptos-api-tester/src/tests/new_account.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@

use crate::{
consts::FUND_AMOUNT,
fail_message::{
ERROR_COULD_NOT_CREATE_ACCOUNT, ERROR_COULD_NOT_FUND_ACCOUNT, ERROR_NO_ACCOUNT_DATA,
FAIL_WRONG_ACCOUNT_DATA,
persistent_check,
strings::{
CHECK_ACCOUNT_BALANCE, CHECK_ACCOUNT_DATA, ERROR_COULD_NOT_CREATE_ACCOUNT,
ERROR_COULD_NOT_FUND_ACCOUNT, ERROR_NO_ACCOUNT_DATA, FAIL_WRONG_ACCOUNT_DATA, FUND, SETUP,
},
persistent_check, time_fn,
time_fn,
utils::{
check_balance, create_account, emit_step_metrics, get_client, get_faucet_client,
NetworkName, TestFailure, TestName, CHECK_ACCOUNT_DATA, SETUP,
NetworkName, TestFailure, TestName,
},
};
use aptos_api_types::U64;
Expand All @@ -18,10 +19,6 @@ use aptos_rest_client::{Account, Client, FaucetClient};
use aptos_sdk::types::LocalAccount;
use aptos_types::account_address::AccountAddress;

// Step names
const FUND: &str = "FUND";
const CHECK_ACCOUNT_BALANCE: &str = "CHECK_ACCOUNT_BALANCE";

/// Tests new account creation. Checks that:
/// - account data exists
/// - account balance reflects funded amount
Expand Down
22 changes: 7 additions & 15 deletions crates/aptos-api-tester/src/tests/nft_transfer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,23 @@

use crate::{
consts::FUND_AMOUNT,
fail_message::{
persistent_check,
strings::{
CHECK_ACCOUNT_DATA, CHECK_COLLECTION_METADATA, CHECK_RECEIVER_BALANCE,
CHECK_SENDER_BALANCE, CHECK_TOKEN_METADATA, CLAIM_TOKEN, CREATE_COLLECTION, CREATE_TOKEN,
ERROR_COULD_NOT_CREATE_TRANSACTION, ERROR_COULD_NOT_FINISH_TRANSACTION,
ERROR_COULD_NOT_FUND_ACCOUNT, ERROR_NO_COLLECTION_DATA, ERROR_NO_TOKEN_BALANCE,
ERROR_NO_TOKEN_DATA, FAIL_WRONG_COLLECTION_DATA, FAIL_WRONG_TOKEN_BALANCE,
FAIL_WRONG_TOKEN_DATA,
FAIL_WRONG_TOKEN_DATA, OFFER_TOKEN, SETUP,
},
persistent_check, time_fn,
time_fn,
token_client::{
CollectionData, CollectionMutabilityConfig, RoyaltyOptions, TokenClient, TokenData,
TokenMutabilityConfig,
},
utils::{
check_balance, create_and_fund_account, emit_step_metrics, get_client, get_faucet_client,
NetworkName, TestFailure, TestName, CHECK_ACCOUNT_DATA, SETUP,
NetworkName, TestFailure, TestName,
},
};
use aptos_api_types::U64;
Expand All @@ -24,22 +27,11 @@ use aptos_rest_client::Client;
use aptos_sdk::types::LocalAccount;
use aptos_types::account_address::AccountAddress;

// variables
const COLLECTION_NAME: &str = "test collection";
const TOKEN_NAME: &str = "test token";
const TOKEN_SUPPLY: u64 = 10;
const OFFER_AMOUNT: u64 = 2;

// step names
const CREATE_COLLECTION: &str = "CREATE_COLLECTION";
const CHECK_COLLECTION_METADATA: &str = "CHECK_COLLECTION_METADATA";
const CREATE_TOKEN: &str = "CREATE_TOKEN";
const CHECK_TOKEN_METADATA: &str = "CHECK_TOKEN_METADATA";
const CHECK_SENDER_BALANCE: &str = "CHECK_SENDER_BALANCE";
const OFFER_TOKEN: &str = "OFFER_TOKEN";
const CLAIM_TOKEN: &str = "CLAIM_TOKEN";
const CHECK_RECEIVER_BALANCE: &str = "CHECK_RECEIVER_BALANCE";

/// Tests nft transfer. Checks that:
/// - collection data exists
/// - token data exists
Expand Down
18 changes: 6 additions & 12 deletions crates/aptos-api-tester/src/tests/publish_module.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,19 @@

use crate::{
consts::FUND_AMOUNT,
fail_message::{
persistent_check,
strings::{
BUILD_MODULE, CHECK_ACCOUNT_DATA, CHECK_MESSAGE, CHECK_MODULE_DATA,
ERROR_COULD_NOT_BUILD_PACKAGE, ERROR_COULD_NOT_CREATE_TRANSACTION,
ERROR_COULD_NOT_FINISH_TRANSACTION, ERROR_COULD_NOT_FUND_ACCOUNT,
ERROR_COULD_NOT_SERIALIZE, ERROR_NO_BYTECODE, ERROR_NO_MESSAGE, ERROR_NO_METADATA,
ERROR_NO_MODULE, FAIL_WRONG_MESSAGE, FAIL_WRONG_MODULE,
ERROR_NO_MODULE, FAIL_WRONG_MESSAGE, FAIL_WRONG_MODULE, PUBLISH_MODULE, SETUP, SET_MESSAGE,
},
persistent_check, time_fn,
time_fn,
token_client::{build_and_submit_transaction, TransactionOptions},
utils::{
check_balance, create_and_fund_account, emit_step_metrics, get_client, get_faucet_client,
NetworkName, TestFailure, TestName, CHECK_ACCOUNT_DATA, SETUP,
NetworkName, TestFailure, TestName,
},
};
use anyhow::{anyhow, Result};
Expand All @@ -29,17 +31,9 @@ use aptos_types::{
use move_core_types::{ident_str, language_storage::ModuleId};
use std::{collections::BTreeMap, path::PathBuf};

// variables
static MODULE_NAME: &str = "message";
static MESSAGE: &str = "test message";

// step names
const BUILD_MODULE: &str = "BUILD_MODULE";
const PUBLISH_MODULE: &str = "PUBLISH_MODULE";
const CHECK_MODULE_DATA: &str = "CHECK_MODULE_DATA";
const SET_MESSAGE: &str = "SET_MESSAGE";
const CHECK_MESSAGE: &str = "CHECK_MESSAGE";

/// Tests nft transfer. Checks that:
/// - can publish module
/// - module data exists
Expand Down
15 changes: 6 additions & 9 deletions crates/aptos-api-tester/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use crate::{
DEVNET_FAUCET_URL, DEVNET_NODE_URL, FUND_AMOUNT, TESTNET_FAUCET_URL, TESTNET_NODE_URL,
},
counters::{test_error, test_fail, test_latency, test_step_latency, test_success},
fail_message::{ERROR_NO_BALANCE, FAIL_WRONG_BALANCE},
strings::{ERROR_NO_BALANCE, FAIL_WRONG_BALANCE},
tests::{coin_transfer, new_account, nft_transfer, publish_module},
time_fn,
};
Expand All @@ -17,7 +17,7 @@ use aptos_sdk::types::LocalAccount;
use aptos_types::account_address::AccountAddress;
use std::env;

// test failure
// Test failure

#[derive(Debug)]
pub enum TestFailure {
Expand All @@ -37,7 +37,7 @@ impl From<anyhow::Error> for TestFailure {
}
}

// test name
// Test name

#[derive(Clone, Copy)]
pub enum TestName {
Expand Down Expand Up @@ -71,7 +71,7 @@ impl ToString for TestName {
}
}

// network name
// Network name

#[derive(Clone, Copy)]
pub enum NetworkName {
Expand All @@ -88,10 +88,7 @@ impl ToString for NetworkName {
}
}

// setup helpers

pub const SETUP: &str = "SETUP";
pub const CHECK_ACCOUNT_DATA: &str = "CHECK_ACCOUNT_DATA";
// Setup helpers

/// Create a REST client.
pub fn get_client(network_name: NetworkName) -> Client {
Expand Down Expand Up @@ -170,7 +167,7 @@ pub async fn check_balance(
Ok(())
}

// metrics helpers
// Metrics helpers

/// Emit metrics based on test result.
pub fn emit_test_metrics(
Expand Down

0 comments on commit bbbb245

Please sign in to comment.