-
Notifications
You must be signed in to change notification settings - Fork 3.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[api] Add support for strictness level for consistency on API tests (#…
…9444) Description This commit builds threads and run ID on top of the consistent API testing introduced here. See proposal for more high level information. One problem we saw in the dashboard is that the problems we observed were regarding eventual consistency. We added support for adjusting the strictness level for such errors. Changes: Refactor of tests into tests module and decomposing into steps (setting up for next PR, individual step timing). Persistent checks for information retrieval. Added token support for Testnet faucet.
- Loading branch information
Showing
14 changed files
with
1,404 additions
and
614 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
// Copyright © Aptos Foundation | ||
|
||
pub static FAIL_WRONG_ACCOUNT_DATA: &str = "wrong account data"; | ||
pub static FAIL_WRONG_BALANCE: &str = "wrong balance"; | ||
pub static FAIL_WRONG_BALANCE_AT_VERSION: &str = "wrong balance at version"; | ||
pub static FAIL_WRONG_COLLECTION_DATA: &str = "wrong collection data"; | ||
pub static FAIL_WRONG_MESSAGE: &str = "wrong message"; | ||
pub static FAIL_WRONG_MODULE: &str = "wrong module"; | ||
pub static FAIL_WRONG_TOKEN_BALANCE: &str = "wrong token balance"; | ||
pub static FAIL_WRONG_TOKEN_DATA: &str = "wrong token data"; | ||
pub static ERROR_COULD_NOT_BUILD_PACKAGE: &str = "failed to build package"; | ||
pub static ERROR_COULD_NOT_CHECK: &str = "persistency check never started"; | ||
pub static ERROR_COULD_NOT_CREATE_ACCOUNT: &str = "failed to create account"; | ||
pub static ERROR_COULD_NOT_CREATE_TRANSACTION: &str = "failed to create transaction"; | ||
pub static ERROR_COULD_NOT_FINISH_TRANSACTION: &str = "failed to finish transaction"; | ||
pub static ERROR_COULD_NOT_FUND_ACCOUNT: &str = "failed to fund account"; | ||
pub static ERROR_COULD_NOT_SERIALIZE: &str = "failed to serialize"; | ||
pub static ERROR_NO_ACCOUNT_DATA: &str = "can't find account data"; | ||
pub static ERROR_NO_BALANCE: &str = "can't find account balance"; | ||
pub static ERROR_NO_BYTECODE: &str = "can't find bytecode"; | ||
pub static ERROR_NO_COLLECTION_DATA: &str = "can't find collection data"; | ||
pub static ERROR_NO_MESSAGE: &str = "can't find message"; | ||
pub static ERROR_NO_METADATA: &str = "can't find metadata"; | ||
pub static ERROR_NO_MODULE: &str = "can't find module"; | ||
pub static ERROR_NO_TOKEN_BALANCE: &str = "can't find token balance"; | ||
pub static ERROR_NO_TOKEN_DATA: &str = "can't find token data"; | ||
pub static ERROR_NO_VERSION: &str = "can't find transaction version"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,178 @@ | ||
// Copyright © Aptos Foundation | ||
|
||
use crate::{fail_message::ERROR_COULD_NOT_CHECK, utils::TestFailure}; | ||
use anyhow::anyhow; | ||
use aptos_api_types::HexEncodedBytes; | ||
use aptos_rest_client::Client; | ||
use aptos_sdk::{token_client::TokenClient, types::LocalAccount}; | ||
use aptos_types::account_address::AccountAddress; | ||
use futures::Future; | ||
use std::time::Duration; | ||
use tokio::time::Instant; | ||
|
||
static PERSISTENCY_TIMEOUT: Duration = Duration::from_secs(30); | ||
|
||
pub async fn account<'a, 'b, F, Fut>( | ||
step: &str, | ||
f: F, | ||
client: &'a Client, | ||
account: &'b LocalAccount, | ||
) -> Result<(), TestFailure> | ||
where | ||
F: Fn(&'a Client, &'b LocalAccount) -> Fut, | ||
Fut: Future<Output = Result<(), TestFailure>>, | ||
{ | ||
// set a default error in case checks never start | ||
let mut result: Result<(), TestFailure> = Err(could_not_check(step)); | ||
let timer = Instant::now(); | ||
|
||
// try to get a good result | ||
while Instant::now().duration_since(timer) < PERSISTENCY_TIMEOUT { | ||
result = f(client, account).await; | ||
if result.is_ok() { | ||
break; | ||
} | ||
} | ||
|
||
// return last failure if no good result occurs | ||
result | ||
} | ||
|
||
pub async fn address<'a, F, Fut>( | ||
step: &str, | ||
f: F, | ||
client: &'a Client, | ||
address: AccountAddress, | ||
) -> Result<(), TestFailure> | ||
where | ||
F: Fn(&'a Client, AccountAddress) -> Fut, | ||
Fut: Future<Output = Result<(), TestFailure>>, | ||
{ | ||
// set a default error in case checks never start | ||
let mut result: Result<(), TestFailure> = Err(could_not_check(step)); | ||
let timer = Instant::now(); | ||
|
||
// try to get a good result | ||
while Instant::now().duration_since(timer) < PERSISTENCY_TIMEOUT { | ||
result = f(client, address).await; | ||
if result.is_ok() { | ||
break; | ||
} | ||
} | ||
|
||
// return last failure if no good result occurs | ||
result | ||
} | ||
|
||
pub async fn address_bytes<'a, 'b, F, Fut>( | ||
step: &str, | ||
f: F, | ||
client: &'a Client, | ||
address: AccountAddress, | ||
bytes: &'b HexEncodedBytes, | ||
) -> Result<(), TestFailure> | ||
where | ||
F: Fn(&'a Client, AccountAddress, &'b HexEncodedBytes) -> Fut, | ||
Fut: Future<Output = Result<(), TestFailure>>, | ||
{ | ||
// set a default error in case checks never start | ||
let mut result: Result<(), TestFailure> = Err(could_not_check(step)); | ||
let timer = Instant::now(); | ||
|
||
// try to get a good result | ||
while Instant::now().duration_since(timer) < PERSISTENCY_TIMEOUT { | ||
result = f(client, address, bytes).await; | ||
if result.is_ok() { | ||
break; | ||
} | ||
} | ||
|
||
// return last failure if no good result occurs | ||
result | ||
} | ||
|
||
pub async fn address_version<'a, F, Fut>( | ||
step: &str, | ||
f: F, | ||
client: &'a Client, | ||
address: AccountAddress, | ||
version: u64, | ||
) -> Result<(), TestFailure> | ||
where | ||
F: Fn(&'a Client, AccountAddress, u64) -> Fut, | ||
Fut: Future<Output = Result<(), TestFailure>>, | ||
{ | ||
// set a default error in case checks never start | ||
let mut result: Result<(), TestFailure> = Err(could_not_check(step)); | ||
let timer = Instant::now(); | ||
|
||
// try to get a good result | ||
while Instant::now().duration_since(timer) < PERSISTENCY_TIMEOUT { | ||
result = f(client, address, version).await; | ||
if result.is_ok() { | ||
break; | ||
} | ||
} | ||
|
||
// return last failure if no good result occurs | ||
result | ||
} | ||
|
||
pub async fn token_address<'a, F, Fut>( | ||
step: &str, | ||
f: F, | ||
token_client: &'a TokenClient<'a>, | ||
address: AccountAddress, | ||
) -> Result<(), TestFailure> | ||
where | ||
F: Fn(&'a TokenClient<'a>, AccountAddress) -> Fut, | ||
Fut: Future<Output = Result<(), TestFailure>>, | ||
{ | ||
// set a default error in case checks never start | ||
let mut result: Result<(), TestFailure> = Err(could_not_check(step)); | ||
let timer = Instant::now(); | ||
|
||
// try to get a good result | ||
while Instant::now().duration_since(timer) < PERSISTENCY_TIMEOUT { | ||
result = f(token_client, address).await; | ||
if result.is_ok() { | ||
break; | ||
} | ||
} | ||
|
||
// return last failure if no good result occurs | ||
result | ||
} | ||
|
||
pub async fn token_address_address<'a, F, Fut>( | ||
step: &str, | ||
f: F, | ||
token_client: &'a TokenClient<'a>, | ||
address: AccountAddress, | ||
address2: AccountAddress, | ||
) -> Result<(), TestFailure> | ||
where | ||
F: Fn(&'a TokenClient<'a>, AccountAddress, AccountAddress) -> Fut, | ||
Fut: Future<Output = Result<(), TestFailure>>, | ||
{ | ||
// set a default error in case checks never start | ||
let mut result: Result<(), TestFailure> = Err(could_not_check(step)); | ||
let timer = Instant::now(); | ||
|
||
// try to get a good result | ||
while Instant::now().duration_since(timer) < PERSISTENCY_TIMEOUT { | ||
result = f(token_client, address, address2).await; | ||
if result.is_ok() { | ||
break; | ||
} | ||
} | ||
|
||
// return last failure if no good result occurs | ||
result | ||
} | ||
|
||
// Utils | ||
|
||
fn could_not_check(step: &str) -> TestFailure { | ||
anyhow!(format!("{} in step: {}", ERROR_COULD_NOT_CHECK, step)).into() | ||
} |
Oops, something went wrong.