Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[AptosFramework] migrate forge tests #260

Merged
merged 1 commit into from
Mar 22, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions Cargo.lock

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

10 changes: 5 additions & 5 deletions api/src/tests/transactions_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ async fn test_get_transactions_output_user_transaction_with_script_function_payl
"vm_status": "Executed successfully",
"sender": "0xb1e55ed",
"sequence_number": "0",
"max_gas_amount": "1000000",
"max_gas_amount": "1000",
"gas_unit_price": "0",
"gas_currency_code": "XUS",
"expiration_timestamp_secs": txn.expiration_timestamp_secs().to_string(),
Expand Down Expand Up @@ -547,7 +547,7 @@ async fn test_post_bcs_format_transaction() {
"hash": hash.to_hex_literal(),
"sender": "0xb1e55ed",
"sequence_number": "0",
"max_gas_amount": "1000000",
"max_gas_amount": "1000",
"gas_unit_price": "0",
"gas_currency_code": "XUS",
"expiration_timestamp_secs": expiration_timestamp.to_string(),
Expand Down Expand Up @@ -754,9 +754,9 @@ async fn test_multi_ed25519_signed_transaction() {
"0xfe047a766a47719591348a4601afb3f38b0c77fa3f820e0298c064e7cde6763f"
],
"signatures": [
"0xab0ffa0926dd765979c422572b4429d11161a2df6975e223ad4d75c87a117e6c790558e8286caf95550ab97515d2cfa8654365f54524688df91b3b4e91b69d0e",
"0x300774b6dd50658d4b693ad5cc1842944465a92b31f1652b445d36b911d4ca625260c451ab7d998534b61253f3bfcdd6bcb03adf4c048b03bd18678d56cd5a03",
"0x4bac0f0d9dde41196efae43849f8e4427ee142e04e57e7291ecdfb225528b0fe31eff8e17461a220430daea94a14f750a37b5e0360aa1c72cb956c402743c202"
"0x51ba5206ec53806411fb67f67fe9adea1e3c90d3b3bd53985ba72cf9ea096489a489081036db3c91e24b01bed8fa2f0c082293236e3fa512218c910a23f7fe01",
"0xbaabf59869be9a12ef93e156c640cf38bd9a04d720aedb1e64faea259c532c68584fcc5444a90d9485bb3dc024c76bb7ec411ea83287823afc9453c711150a0c",
"0x96bf8311f06610aec340798c7bac2859d0b7778fad0b648b70ff4091f3147040ef5bc3a2fa10114b2593cf58b3100e276460630f37d948abd3214e2d13882604"
],
"threshold": 3,
"bitmap": "0xe0000000"
Expand Down
26 changes: 26 additions & 0 deletions crates/aptos-rest-client/src/aptos.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// Copyright (c) Aptos
// SPDX-License-Identifier: Apache-2.0

use aptos_api_types::U64;
use serde::{Deserialize, Serialize};

#[derive(Debug, Serialize, Deserialize)]
pub struct TestCoin {
pub value: U64,
}

#[derive(Debug, Serialize, Deserialize)]
pub struct Balance {
pub coin: TestCoin,
}

impl Balance {
pub fn get(&self) -> u64 {
*self.coin.value.inner()
}
}

#[derive(Debug, Serialize, Deserialize)]
pub struct AptosVersion {
major: U64,
}
51 changes: 46 additions & 5 deletions crates/aptos-rest-client/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@ pub use aptos_api_types::{MoveModuleBytecode, PendingTransaction, Transaction};
use aptos_crypto::HashValue;
use aptos_types::{account_address::AccountAddress, transaction::SignedTransaction};
use move_core_types::{
ident_str,
identifier::Identifier,
language_storage::{StructTag, TypeTag},
language_storage::{StructTag, TypeTag, CORE_CODE_ADDRESS},
move_resource::MoveStructType,
};
use reqwest::{header::CONTENT_TYPE, Client as ReqwestClient, StatusCode};
Expand All @@ -16,6 +17,8 @@ use std::time::Duration;
use url::Url;

pub use aptos_api_types;
use aptos_types::account_config::aptos_root_address;

pub mod error;
pub mod faucet;
pub use faucet::FaucetClient;
Expand All @@ -24,7 +27,10 @@ pub use response::Response;
mod state;
use state::State;
pub mod types;
pub use types::{DiemAccount, Resource, RestError};
use crate::aptos::{AptosVersion, Balance};
pub use types::{Account, Resource, RestError};

pub mod aptos;

macro_rules! cfg_dpn {
($($item:item)*) => {
Expand Down Expand Up @@ -62,7 +68,7 @@ impl Client {
}

cfg_dpn! {
pub async fn get_account_balances(
pub async fn get_dpn_account_balances(
&self,
address: AccountAddress,
) -> Result<Response<Vec<dpn::AccountBalance>>> {
Expand Down Expand Up @@ -95,7 +101,7 @@ impl Client {
}

// Returns root account DiemAccount::Config<Version> resource
pub async fn get_aptos_version(&self) -> Result<Response<dpn::Reconfiguration<dpn::Version>>> {
pub async fn get_dpn_version(&self) -> Result<Response<dpn::Reconfiguration<dpn::Version>>> {
self.get_resource::<dpn::Reconfiguration<dpn::Version>>(dpn::aptos_root_address(), &dpn::diem_config_struct_tag(dpn::diem_version_identifier())).await
}

Expand All @@ -106,6 +112,41 @@ impl Client {

}

pub async fn get_aptos_version(&self) -> Result<Response<AptosVersion>> {
self.get_resource::<AptosVersion>(
aptos_root_address(),
&StructTag {
address: CORE_CODE_ADDRESS,
name: ident_str!("Version").to_owned(),
module: ident_str!("Version").to_owned(),
type_params: vec![],
},
)
.await
}

pub async fn get_account_balance(&self, address: AccountAddress) -> Result<Response<Balance>> {
let resp = self
.get_account_resources_by_type(
address,
aptos_types::account_config::CORE_CODE_ADDRESS,
&ident_str!("TestCoin").to_owned(),
&ident_str!("Balance").to_owned(),
)
.await?;
resp.and_then(|mut resources| {
let resource = resources.pop();
if !resources.is_empty() {
return Err(anyhow!("More than one data returned"));
}
if let Some(res) = resource {
Ok(serde_json::from_value::<Balance>(res.data)?)
} else {
Err(anyhow!("No data returned"))
}
})
}

pub async fn get_ledger_information(&self) -> Result<Response<State>> {
#[derive(Deserialize)]
struct Response {
Expand Down Expand Up @@ -377,7 +418,7 @@ impl Client {
self.json(response).await
}

pub async fn get_account(&self, address: AccountAddress) -> Result<Response<DiemAccount>> {
pub async fn get_account(&self, address: AccountAddress) -> Result<Response<Account>> {
let url = self.base_url.join(&format!("accounts/{}", address))?;
let response = self.inner.get(url).send().await?;
self.json(response).await
Expand Down
2 changes: 1 addition & 1 deletion crates/aptos-rest-client/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ where
}

#[derive(Clone, Debug, Deserialize)]
pub struct DiemAccount {
pub struct Account {
#[serde(deserialize_with = "deserialize_from_prefixed_hex_string")]
pub authentication_key: AuthenticationKey,
#[serde(deserialize_with = "deserialize_from_string")]
Expand Down
1 change: 1 addition & 0 deletions crates/transaction-emitter/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,4 @@ aptos-crypto = { path = "../aptos-crypto" }
aptos-logger = { path = "../../crates/aptos-logger" }
aptos-sdk = { path = "../../sdk" }
aptos-workspace-hack = { version = "0.1", path = "../aptos-workspace-hack" }
aptos-transaction-builder = { path = "../../sdk/transaction-builder" }
Loading