diff --git a/aptos-move/framework/aptos-framework/doc/coin.md b/aptos-move/framework/aptos-framework/doc/coin.md
index 054a7ffd57a301..98f56f007e8b3d 100644
--- a/aptos-move/framework/aptos-framework/doc/coin.md
+++ b/aptos-move/framework/aptos-framework/doc/coin.md
@@ -73,7 +73,7 @@ This module provides the foundation for typesafe Coins.
- [Function `burn`](#0x1_coin_burn)
- [Function `burn_from`](#0x1_coin_burn_from)
- [Function `deposit`](#0x1_coin_deposit)
-- [Function `migrated_primary_fungible_store_exists`](#0x1_coin_migrated_primary_fungible_store_exists)
+- [Function `can_receive_paired_fungible_asset`](#0x1_coin_can_receive_paired_fungible_asset)
- [Function `force_deposit`](#0x1_coin_force_deposit)
- [Function `destroy_zero`](#0x1_coin_destroy_zero)
- [Function `extract`](#0x1_coin_extract)
@@ -2344,7 +2344,7 @@ Returns true
if account_addr
is registered to r
let paired_metadata_opt = paired_metadata<CoinType>();
(option::is_some(
&paired_metadata_opt
- ) && migrated_primary_fungible_store_exists(account_addr, option::destroy_some(paired_metadata_opt)))
+ ) && can_receive_paired_fungible_asset(account_addr, option::destroy_some(paired_metadata_opt)))
}
}
@@ -2620,7 +2620,7 @@ Deposit the coin balance into the recipient's account and emit an event.
merge(&mut coin_store.coin, coin);
} else {
let metadata = paired_metadata<CoinType>();
- if (option::is_some(&metadata) && migrated_primary_fungible_store_exists(
+ if (option::is_some(&metadata) && can_receive_paired_fungible_asset(
account_addr,
option::destroy_some(metadata)
)) {
@@ -2636,13 +2636,13 @@ Deposit the coin balance into the recipient's account and emit an event.
-
+
-## Function `migrated_primary_fungible_store_exists`
+## Function `can_receive_paired_fungible_asset`
-
fun migrated_primary_fungible_store_exists(account_address: address, metadata: object::Object<fungible_asset::Metadata>): bool
+fun can_receive_paired_fungible_asset(account_address: address, metadata: object::Object<fungible_asset::Metadata>): bool
@@ -2651,11 +2651,11 @@ Deposit the coin balance into the recipient's account and emit an event.
Implementation
-inline fun migrated_primary_fungible_store_exists(
+inline fun can_receive_paired_fungible_asset(
account_address: address,
metadata: Object<Metadata>
): bool {
- features::new_accounts_default_to_fa_apt_store_enabled() || {
+ (features::new_accounts_default_to_fa_apt_store_enabled() && object::object_address(&metadata) == @0xa) || {
let primary_store_address = primary_fungible_store::primary_store_address<Metadata>(
account_address,
metadata
@@ -2695,7 +2695,7 @@ This is for internal use only and doesn't emit an DepositEvent.
merge(&mut coin_store.coin, coin);
} else {
let metadata = paired_metadata<CoinType>();
- if (option::is_some(&metadata) && migrated_primary_fungible_store_exists(
+ if (option::is_some(&metadata) && can_receive_paired_fungible_asset(
account_addr,
option::destroy_some(metadata)
)) {
diff --git a/aptos-move/framework/aptos-framework/sources/coin.move b/aptos-move/framework/aptos-framework/sources/coin.move
index a7fda35ce3eeb4..2ea6aca5762ec0 100644
--- a/aptos-move/framework/aptos-framework/sources/coin.move
+++ b/aptos-move/framework/aptos-framework/sources/coin.move
@@ -695,7 +695,7 @@ module aptos_framework::coin {
let paired_metadata_opt = paired_metadata();
(option::is_some(
&paired_metadata_opt
- ) && migrated_primary_fungible_store_exists(account_addr, option::destroy_some(paired_metadata_opt)))
+ ) && can_receive_paired_fungible_asset(account_addr, option::destroy_some(paired_metadata_opt)))
}
}
@@ -814,7 +814,7 @@ module aptos_framework::coin {
merge(&mut coin_store.coin, coin);
} else {
let metadata = paired_metadata();
- if (option::is_some(&metadata) && migrated_primary_fungible_store_exists(
+ if (option::is_some(&metadata) && can_receive_paired_fungible_asset(
account_addr,
option::destroy_some(metadata)
)) {
@@ -825,11 +825,11 @@ module aptos_framework::coin {
}
}
- inline fun migrated_primary_fungible_store_exists(
+ inline fun can_receive_paired_fungible_asset(
account_address: address,
metadata: Object
): bool {
- features::new_accounts_default_to_fa_apt_store_enabled() || {
+ (features::new_accounts_default_to_fa_apt_store_enabled() && object::object_address(&metadata) == @0xa) || {
let primary_store_address = primary_fungible_store::primary_store_address(
account_address,
metadata
@@ -849,7 +849,7 @@ module aptos_framework::coin {
merge(&mut coin_store.coin, coin);
} else {
let metadata = paired_metadata();
- if (option::is_some(&metadata) && migrated_primary_fungible_store_exists(
+ if (option::is_some(&metadata) && can_receive_paired_fungible_asset(
account_addr,
option::destroy_some(metadata)
)) {
@@ -1924,6 +1924,7 @@ module aptos_framework::coin {
account::create_account_for_test(bob_addr);
let (burn_cap, freeze_cap, mint_cap) = initialize_and_register_fake_money(account, 1, true);
maybe_convert_to_fungible_store(aaron_addr);
+ maybe_convert_to_fungible_store(bob_addr);
deposit(aaron_addr, mint(1, &mint_cap));
force_deposit(account_addr, mint(100, &mint_cap));
@@ -1991,7 +1992,7 @@ module aptos_framework::coin {
});
}
- #[test(account = @aptos_framework, aaron = @0xaa10)]
+ #[test(account = @aptos_framework)]
fun test_migration_with_existing_primary_fungible_store(
account: &signer,
) acquires CoinConversionMap, CoinInfo, CoinStore, PairedCoinType {
@@ -2004,7 +2005,7 @@ module aptos_framework::coin {
assert!(coin_balance(account_addr) == 0, 0);
assert!(balance(account_addr) == 100, 0);
let coin = withdraw(account, 50);
- assert!(migrated_primary_fungible_store_exists(account_addr, ensure_paired_metadata()), 0);
+ assert!(can_receive_paired_fungible_asset(account_addr, ensure_paired_metadata()), 0);
maybe_convert_to_fungible_store(account_addr);
deposit(account_addr, coin);
assert!(coin_balance(account_addr) == 0, 0);
diff --git a/aptos-move/framework/aptos-framework/sources/vesting.move b/aptos-move/framework/aptos-framework/sources/vesting.move
index 47616b5f63d6b4..cf5521136cd65e 100644
--- a/aptos-move/framework/aptos-framework/sources/vesting.move
+++ b/aptos-move/framework/aptos-framework/sources/vesting.move
@@ -1190,6 +1190,8 @@ module aptos_framework::vesting {
use aptos_framework::stake::with_rewards;
use aptos_std::math64::min;
+ #[test_only]
+ use aptos_framework::account::create_account_for_test;
#[test_only]
const MIN_STAKE: u64 = 100000000000000; // 1M APT coins with 8 decimals.
@@ -1449,7 +1451,6 @@ module aptos_framework::vesting {
}
#[test(aptos_framework = @0x1, admin = @0x123)]
- #[expected_failure(abort_code = 0x10005, location = Self)]
public entry fun test_create_vesting_contract_with_mistmaching_shareholders_should_fail(
aptos_framework: &signer,
admin: &signer,
@@ -1459,6 +1460,37 @@ module aptos_framework::vesting {
setup_vesting_contract(admin, &vector[@1, @2], &vector[1], admin_address, 0);
}
+ #[test(aptos_framework = @0x1, admin = @0x123)]
+ public entry fun test_create_vesting_contract_with_invalid_withdrawal_address(
+ aptos_framework: &signer,
+ admin: &signer,
+ ) acquires AdminStore {
+ let admin_address = signer::address_of(admin);
+ setup(aptos_framework, &vector[admin_address]);
+ setup_vesting_contract(admin, &vector[@1, @2], &vector[1], @5, 0);
+ }
+
+ #[test(aptos_framework = @0x1, admin = @0x123)]
+ public entry fun test_create_vesting_contract_with_missing_withdrawal_account(
+ aptos_framework: &signer,
+ admin: &signer,
+ ) acquires AdminStore {
+ let admin_address = signer::address_of(admin);
+ setup(aptos_framework, &vector[admin_address]);
+ setup_vesting_contract(admin, &vector[@1, @2], &vector[1], @11, 0);
+ }
+
+ #[test(aptos_framework = @0x1, admin = @0x123)]
+ public entry fun test_create_vesting_contract_with_unregistered_withdrawal_account(
+ aptos_framework: &signer,
+ admin: &signer,
+ ) acquires AdminStore {
+ let admin_address = signer::address_of(admin);
+ setup(aptos_framework, &vector[admin_address]);
+ create_account_for_test(@11);
+ setup_vesting_contract(admin, &vector[@1, @2], &vector[1], @11, 0);
+ }
+
#[test(aptos_framework = @0x1)]
#[expected_failure(abort_code = 0x10002, location = Self)]
public entry fun test_create_empty_vesting_schedule_should_fail(aptos_framework: &signer) {
@@ -1994,6 +2026,19 @@ module aptos_framework::vesting {
set_beneficiary(admin, contract_address, @1, @11);
}
+ #[test(aptos_framework = @0x1, admin = @0x123)]
+ public entry fun test_set_beneficiary_with_unregistered_account(
+ aptos_framework: &signer,
+ admin: &signer,
+ ) acquires AdminStore, VestingContract {
+ let admin_address = signer::address_of(admin);
+ setup(aptos_framework, &vector[admin_address]);
+ let contract_address = setup_vesting_contract(
+ admin, &vector[@1, @2], &vector[GRANT_AMOUNT, GRANT_AMOUNT], admin_address, 0);
+ create_account_for_test(@11);
+ set_beneficiary(admin, contract_address, @1, @11);
+ }
+
#[test(aptos_framework = @0x1, admin = @0x123)]
public entry fun test_set_beneficiary_should_send_distribution(
aptos_framework: &signer,
diff --git a/execution/executor-benchmark/src/db_access.rs b/execution/executor-benchmark/src/db_access.rs
index a5eecba9251a87..02824455d97bd7 100644
--- a/execution/executor-benchmark/src/db_access.rs
+++ b/execution/executor-benchmark/src/db_access.rs
@@ -10,7 +10,7 @@ use aptos_types::{
FungibleStoreResource, ObjectCoreResource, ObjectGroupResource, TypeInfoResource,
},
event::{EventHandle, EventKey},
- state_store::{state_key::StateKey, StateView},
+ state_store::{state_key::StateKey, StateView, TStateView},
write_set::TOTAL_SUPPLY_STATE_KEY,
AptosCoinType, CoinType,
};
@@ -22,7 +22,6 @@ use move_core_types::{
};
use serde::de::DeserializeOwned;
use std::{collections::BTreeMap, str::FromStr};
-use aptos_types::state_store::TStateView;
pub struct CommonStructTags {
pub account: StructTag,
@@ -130,7 +129,7 @@ impl DbAccessUtil {
&ObjectGroupResource::struct_tag(),
),
)
- .expect("account must exist in data store");
+ .expect("account must exist in data store");
let group: Option>> = bytes_opt
.map(|bytes| bcs::from_bytes(&bytes))
.transpose()
diff --git a/execution/executor-benchmark/src/db_reliable_submitter.rs b/execution/executor-benchmark/src/db_reliable_submitter.rs
index f716b77516c8c5..5dc8237081a30c 100644
--- a/execution/executor-benchmark/src/db_reliable_submitter.rs
+++ b/execution/executor-benchmark/src/db_reliable_submitter.rs
@@ -31,10 +31,13 @@ pub struct DbReliableTransactionSubmitter {
impl ReliableTransactionSubmitter for DbReliableTransactionSubmitter {
async fn get_account_balance(&self, account_address: AccountAddress) -> Result {
let db_state_view = self.db.reader.latest_state_checkpoint_view().unwrap();
- let sender_coin_store_key = DbAccessUtil::new_state_key_aptos_coin(account_address);
- let coin = DbAccessUtil::get_db_value::>(&sender_coin_store_key, &db_state_view)?
- .map(|x| x.coin)
- .unwrap_or(0);
+ let sender_coin_store_key = DbAccessUtil::new().new_state_key_aptos_coin(&account_address);
+ let coin = DbAccessUtil::get_value::>(
+ &sender_coin_store_key,
+ &db_state_view,
+ )?
+ .map(|x| x.coin())
+ .unwrap_or(0);
let fa = DbAccessUtil::get_fa_store(account_address, &db_state_view)
.map(|x| x.balance())
.unwrap_or(0);
diff --git a/execution/executor/tests/db_bootstrapper_test.rs b/execution/executor/tests/db_bootstrapper_test.rs
index 81514fd7e178fc..d050e0b059ef38 100644
--- a/execution/executor/tests/db_bootstrapper_test.rs
+++ b/execution/executor/tests/db_bootstrapper_test.rs
@@ -183,29 +183,29 @@ fn get_balance(account: &AccountAddress, db: &DbReaderWriter) -> u64 {
.map(|x| x.coin())
.unwrap_or(0)
+ {
- let bytes_opt = TStateView::get_state_value_bytes(
- &db_state_view,
- &StateKey::resource_group(
- &get_apt_primary_store_address(*account),
- &ObjectGroupResource::struct_tag(),
- ),
- )
+ let bytes_opt = TStateView::get_state_value_bytes(
+ &db_state_view,
+ &StateKey::resource_group(
+ &get_apt_primary_store_address(*account),
+ &ObjectGroupResource::struct_tag(),
+ ),
+ )
.expect("account must exist in data store");
- let group: Option>> = bytes_opt
- .map(|bytes| bcs::from_bytes(&bytes))
- .transpose()
- .unwrap();
- group
- .and_then(|g| {
- g.get(&FungibleStoreResource::struct_tag())
- .map(|b| bcs::from_bytes(b))
- })
- .transpose()
- .unwrap()
- .map(|x: FungibleStoreResource| x.balance())
- .unwrap_or(0)
- }
+ let group: Option>> = bytes_opt
+ .map(|bytes| bcs::from_bytes(&bytes))
+ .transpose()
+ .unwrap();
+ group
+ .and_then(|g| {
+ g.get(&FungibleStoreResource::struct_tag())
+ .map(|b| bcs::from_bytes(b))
+ })
+ .transpose()
+ .unwrap()
+ .map(|x: FungibleStoreResource| x.balance())
+ .unwrap_or(0)
+ }
}
fn get_configuration(db: &DbReaderWriter) -> ConfigurationResource {