forked from aptos-labs/aptos-core
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Closes: aptos-labs#713
- Loading branch information
Showing
20 changed files
with
450 additions
and
195 deletions.
There are no files selected for viewing
55 changes: 41 additions & 14 deletions
55
api/goldens/aptos_api__tests__accounts_test__test_account_modules.json
Large diffs are not rendered by default.
Oops, something went wrong.
55 changes: 41 additions & 14 deletions
55
api/goldens/aptos_api__tests__accounts_test__test_account_modules_structs.json
Large diffs are not rendered by default.
Oops, something went wrong.
55 changes: 41 additions & 14 deletions
55
api/goldens/aptos_api__tests__accounts_test__test_get_module_aptos_config.json
Large diffs are not rendered by default.
Oops, something went wrong.
55 changes: 41 additions & 14 deletions
55
api/goldens/aptos_api__tests__accounts_test__test_get_module_with_script_functions.json
Large diffs are not rendered by default.
Oops, something went wrong.
116 changes: 85 additions & 31 deletions
116
...ptos_api__tests__transactions_test__test_get_transactions_output_genesis_transaction.json
Large diffs are not rendered by default.
Oops, something went wrong.
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
100 changes: 50 additions & 50 deletions
100
...ns_test__test_get_transactions_returns_last_page_when_start_version_is_not_specified.json
Large diffs are not rendered by default.
Oops, something went wrong.
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
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
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
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
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
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,101 @@ | ||
// Copyright (c) Aptos | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
use aptos_transaction_builder::aptos_stdlib; | ||
use aptos_types::{account_address::AccountAddress, account_config::aptos_root_address}; | ||
use forge::{AptosContext, AptosTest, Result, Test}; | ||
|
||
pub struct Staking; | ||
|
||
impl Test for Staking { | ||
fn name(&self) -> &'static str { | ||
"smoke-test::aptos::staking" | ||
} | ||
} | ||
|
||
#[async_trait::async_trait] | ||
impl AptosTest for Staking { | ||
async fn run<'t>(&self, ctx: &mut AptosContext<'t>) -> Result<()> { | ||
// created by root account | ||
let mut accounts = vec![]; | ||
for _ in 0..10 { | ||
let local_account = ctx.random_account(); | ||
ctx.create_user_account(local_account.public_key()).await?; | ||
ctx.mint(local_account.address(), 10000).await?; | ||
accounts.push(local_account); | ||
} | ||
let validator_addr = AccountAddress::from_hex_literal( | ||
validator_set(ctx).await["active_validators"][0]["addr"] | ||
.as_str() | ||
.unwrap(), | ||
) | ||
.unwrap(); | ||
let txn_factory = ctx.aptos_transaction_factory(); | ||
let locked_period = 86400 * 2; | ||
let current_time = std::time::SystemTime::now() | ||
.duration_since(std::time::UNIX_EPOCH) | ||
.unwrap() | ||
.as_secs() | ||
+ locked_period; | ||
for account in &mut accounts { | ||
let txn = account.sign_with_transaction_builder(txn_factory.payload( | ||
aptos_stdlib::encode_delegate_stake_script_function( | ||
validator_addr, | ||
100, | ||
current_time, | ||
), | ||
)); | ||
ctx.client().submit_and_wait(&txn).await?; | ||
} | ||
let stake_pool = stake_pool_from_addr(ctx, validator_addr).await; | ||
assert_eq!( | ||
stake_pool["pending_active"].as_array().unwrap().len(), | ||
accounts.len() | ||
); | ||
// force epoch change to make pending changes take effect | ||
let txn = ctx.root_account().sign_with_transaction_builder( | ||
txn_factory.payload(aptos_stdlib::encode_force_reconfigure_script_function()), | ||
); | ||
ctx.client().submit_and_wait(&txn).await?; | ||
let stake_pool = stake_pool_from_addr(ctx, validator_addr).await; | ||
assert_eq!( | ||
stake_pool["active"].as_array().unwrap().len(), | ||
accounts.len() + 1 | ||
); | ||
assert_eq!( | ||
stake_pool["current_stake"] | ||
.as_str() | ||
.unwrap() | ||
.parse::<u64>() | ||
.unwrap(), | ||
accounts.len() as u64 * 100 + 1 | ||
); | ||
let voting_power = validator_set(ctx).await["active_validators"][0]["voting_power"] | ||
.as_str() | ||
.unwrap() | ||
.parse::<u64>() | ||
.unwrap(); | ||
assert_eq!(voting_power, accounts.len() as u64 * 100 + 1); | ||
Ok(()) | ||
} | ||
} | ||
|
||
async fn stake_pool_from_addr(ctx: &AptosContext<'_>, addr: AccountAddress) -> serde_json::Value { | ||
ctx.client() | ||
.get_account_resource(addr, "0x1::Stake::StakePool") | ||
.await | ||
.unwrap() | ||
.into_inner() | ||
.unwrap() | ||
.data | ||
} | ||
|
||
async fn validator_set(ctx: &AptosContext<'_>) -> serde_json::Value { | ||
ctx.client() | ||
.get_account_resource(aptos_root_address(), "0x1::Stake::ValidatorSet") | ||
.await | ||
.unwrap() | ||
.into_inner() | ||
.unwrap() | ||
.data | ||
} |
Oops, something went wrong.