Skip to content

Commit

Permalink
reorganizing files a bit
Browse files Browse the repository at this point in the history
fixing unit test failure
  • Loading branch information
igor-aptos committed Nov 6, 2024
1 parent dd432e4 commit b905dd7
Show file tree
Hide file tree
Showing 17 changed files with 234 additions and 126 deletions.
8 changes: 4 additions & 4 deletions aptos-move/e2e-tests/src/executor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ use aptos_keygen::KeyGen;
use aptos_types::{
account_config::{
new_block_event_key, AccountResource, CoinInfoResource, CoinStoreResource,
ConcurrentSupply, NewBlockEvent, ObjectGroupResource, CORE_CODE_ADDRESS,
ConcurrentSupplyResource, NewBlockEvent, ObjectGroupResource, CORE_CODE_ADDRESS,
},
block_executor::config::{
BlockExecutorConfig, BlockExecutorConfigFromOnchain, BlockExecutorLocalConfig,
Expand Down Expand Up @@ -438,10 +438,10 @@ impl FakeExecutor {
let mut fa_resource_group = self
.read_resource_group::<ObjectGroupResource>(&AccountAddress::TEN)
.expect("resource group must exist in data store");
let mut supply = bcs::from_bytes::<ConcurrentSupply>(
let mut supply = bcs::from_bytes::<ConcurrentSupplyResource>(
fa_resource_group
.group
.get(&ConcurrentSupply::struct_tag())
.get(&ConcurrentSupplyResource::struct_tag())
.unwrap(),
)
.unwrap();
Expand All @@ -451,7 +451,7 @@ impl FakeExecutor {
fa_resource_group
.group
.insert(
ConcurrentSupply::struct_tag(),
ConcurrentSupplyResource::struct_tag(),
bcs::to_bytes(&supply).unwrap(),
)
.unwrap();
Expand Down
2 changes: 1 addition & 1 deletion execution/executor-benchmark/src/native_executor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use aptos_executor_types::execution_output::ExecutionOutput;
use aptos_storage_interface::cached_state_view::CachedStateView;
use aptos_types::{
account_address::AccountAddress,
account_config::{deposit::DepositEvent, withdraw::WithdrawEvent},
account_config::{DepositEvent, WithdrawEvent},
block_executor::{
config::BlockExecutorConfigFromOnchain,
partitioner::{ExecutableTransactions, PartitionedTransactions},
Expand Down
113 changes: 113 additions & 0 deletions types/src/account_config/events/coin.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
// Copyright © Aptos Foundation
// SPDX-License-Identifier: Apache-2.0

use crate::{
account_config::TypeInfoResource,
move_utils::{move_event_v1::MoveEventV1Type, move_event_v2::MoveEventV2Type},
};
use anyhow::Result;
use move_core_types::{
account_address::AccountAddress, ident_str, identifier::IdentStr, move_resource::MoveStructType,
};
use serde::{Deserialize, Serialize};

/// Struct that represents a SentPaymentEvent.
#[derive(Debug, Serialize, Deserialize)]
pub struct WithdrawEvent {
pub amount: u64,
}

impl WithdrawEvent {
pub fn try_from_bytes(bytes: &[u8]) -> Result<Self> {
bcs::from_bytes(bytes).map_err(Into::into)
}

/// Get the amount sent or received
pub fn amount(&self) -> u64 {
self.amount
}
}

impl MoveStructType for WithdrawEvent {
const MODULE_NAME: &'static IdentStr = ident_str!("coin");
const STRUCT_NAME: &'static IdentStr = ident_str!("WithdrawEvent");
}

impl MoveEventV1Type for WithdrawEvent {}

#[derive(Debug, Serialize, Deserialize)]
pub struct CoinWithdraw {
pub coin_type: String,
pub account: AccountAddress,
pub amount: u64,
}

impl CoinWithdraw {
pub fn try_from_bytes(bytes: &[u8]) -> Result<Self> {
bcs::from_bytes(bytes).map_err(Into::into)
}
}

impl MoveStructType for CoinWithdraw {
const MODULE_NAME: &'static IdentStr = ident_str!("coin");
const STRUCT_NAME: &'static IdentStr = ident_str!("CoinWithdraw");
}

impl MoveEventV2Type for CoinWithdraw {}

/// Struct that represents a DepositPaymentEvent.
#[derive(Debug, Serialize, Deserialize)]
pub struct DepositEvent {
pub amount: u64,
}

impl DepositEvent {
pub fn try_from_bytes(bytes: &[u8]) -> Result<Self> {
bcs::from_bytes(bytes).map_err(Into::into)
}

/// Get the amount sent or received
pub fn amount(&self) -> u64 {
self.amount
}
}

impl MoveStructType for DepositEvent {
const MODULE_NAME: &'static IdentStr = ident_str!("coin");
const STRUCT_NAME: &'static IdentStr = ident_str!("DepositEvent");
}

impl MoveEventV1Type for DepositEvent {}

#[derive(Debug, Serialize, Deserialize)]
pub struct CoinDeposit {
pub coin_type: String,
pub account: AccountAddress,
pub amount: u64,
}

impl CoinDeposit {
pub fn try_from_bytes(bytes: &[u8]) -> Result<Self> {
bcs::from_bytes(bytes).map_err(Into::into)
}
}

impl MoveStructType for CoinDeposit {
const MODULE_NAME: &'static IdentStr = ident_str!("coin");
const STRUCT_NAME: &'static IdentStr = ident_str!("CoinDeposit");
}

impl MoveEventV2Type for CoinDeposit {}

#[derive(Debug, Serialize, Deserialize)]
pub struct CoinRegister {
pub account: AccountAddress,
pub type_info: TypeInfoResource,
}

impl MoveStructType for CoinRegister {
const MODULE_NAME: &'static IdentStr = ident_str!("account");
const STRUCT_NAME: &'static IdentStr = ident_str!("CoinRegister");
}

impl MoveEventV2Type for CoinRegister {}
28 changes: 0 additions & 28 deletions types/src/account_config/events/deposit.rs

This file was deleted.

36 changes: 36 additions & 0 deletions types/src/account_config/events/fungible_asset.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// Copyright © Aptos Foundation
// SPDX-License-Identifier: Apache-2.0

use crate::move_utils::move_event_v2::MoveEventV2Type;
use move_core_types::{
account_address::AccountAddress, ident_str, identifier::IdentStr, move_resource::MoveStructType,
};
use serde::{Deserialize, Serialize};

/// Struct that represents a Withdraw event.
#[derive(Debug, Serialize, Deserialize)]
pub struct WithdrawFAEvent {
pub store: AccountAddress,
pub amount: u64,
}

impl MoveEventV2Type for WithdrawFAEvent {}

impl MoveStructType for WithdrawFAEvent {
const MODULE_NAME: &'static IdentStr = ident_str!("fungible_asset");
const STRUCT_NAME: &'static IdentStr = ident_str!("Withdraw");
}

/// Struct that represents a Deposit event.
#[derive(Debug, Serialize, Deserialize)]
pub struct DepositFAEvent {
pub store: AccountAddress,
pub amount: u64,
}

impl MoveEventV2Type for DepositFAEvent {}

impl MoveStructType for DepositFAEvent {
const MODULE_NAME: &'static IdentStr = ident_str!("fungible_asset");
const STRUCT_NAME: &'static IdentStr = ident_str!("Deposit");
}
8 changes: 4 additions & 4 deletions types/src/account_config/events/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@
// Parts of the project are originally copyright © Meta Platforms, Inc.
// SPDX-License-Identifier: Apache-2.0

pub mod deposit;
pub mod coin;
pub mod fungible_asset;
pub mod new_block;
pub mod new_epoch;
pub mod withdraw;

pub use deposit::*;
pub use coin::*;
pub use fungible_asset::*;
pub use new_block::*;
pub use new_epoch::*;
pub use withdraw::*;

pub fn is_aptos_governance_create_proposal_event(event_type: &str) -> bool {
event_type == "0x1::aptos_governance::CreateProposal"
Expand Down
48 changes: 0 additions & 48 deletions types/src/account_config/events/withdraw.rs

This file was deleted.

14 changes: 8 additions & 6 deletions types/src/account_config/resources/coin_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,18 +76,20 @@ impl<C: CoinType> CoinInfoResource<C> {
}
}

/// Returns a writeset corresponding to the creation of CoinInfo in Move.
/// This can be passed to data store for testing total supply.
pub fn to_writeset(&self, supply: u128) -> anyhow::Result<WriteSet> {
let value_state_key = self
.supply
pub fn supply_aggregator_state_key(&self) -> StateKey {
self.supply
.as_ref()
.unwrap()
.aggregator
.as_ref()
.unwrap()
.state_key();
.state_key()
}

/// Returns a writeset corresponding to the creation of CoinInfo in Move.
/// This can be passed to data store for testing total supply.
pub fn to_writeset(&self, supply: u128) -> anyhow::Result<WriteSet> {
let value_state_key = self.supply_aggregator_state_key();
// We store CoinInfo and aggregatable value separately.
let write_set = vec![
(
Expand Down
8 changes: 8 additions & 0 deletions types/src/account_config/resources/coin_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,17 @@ impl<C: CoinType> CoinStoreResource<C> {
&self.deposit_events
}

pub fn deposit_events_mut(&mut self) -> &mut EventHandle {
&mut self.deposit_events
}

pub fn withdraw_events(&self) -> &EventHandle {
&self.withdraw_events
}

pub fn withdraw_events_mut(&mut self) -> &mut EventHandle {
&mut self.withdraw_events
}
}

impl<C: CoinType> MoveStructType for CoinStoreResource<C> {
Expand Down
6 changes: 3 additions & 3 deletions types/src/account_config/resources/fungible_asset_metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ use move_core_types::{
use serde::{Deserialize, Serialize};

#[derive(Debug, Serialize, Deserialize)]
pub struct ConcurrentSupply {
pub struct ConcurrentSupplyResource {
pub current: AggregatorResource<u128>,
}

impl MoveStructType for ConcurrentSupply {
impl MoveStructType for ConcurrentSupplyResource {
const MODULE_NAME: &'static IdentStr = ident_str!("fungible_asset");
const STRUCT_NAME: &'static IdentStr = ident_str!("ConcurrentSupply");
}

impl MoveResource for ConcurrentSupply {}
impl MoveResource for ConcurrentSupplyResource {}
32 changes: 1 addition & 31 deletions types/src/account_config/resources/fungible_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@
// SPDX-License-Identifier: Apache-2.0

use super::aggregator::AggregatorResource;
use crate::{
account_address::create_derived_object_address, move_utils::move_event_v2::MoveEventV2Type,
};
use crate::account_address::create_derived_object_address;
use move_core_types::{
account_address::AccountAddress,
ident_str,
Expand Down Expand Up @@ -96,31 +94,3 @@ impl MoveStructType for MigrationFlag {
}

impl MoveResource for MigrationFlag {}

/// Struct that represents a Withdraw event.
#[derive(Debug, Serialize, Deserialize)]
pub struct WithdrawFAEvent {
pub store: AccountAddress,
pub amount: u64,
}

impl MoveEventV2Type for WithdrawFAEvent {}

impl MoveStructType for WithdrawFAEvent {
const MODULE_NAME: &'static IdentStr = ident_str!("fungble_asset");
const STRUCT_NAME: &'static IdentStr = ident_str!("Withdraw");
}

/// Struct that represents a Deposit event.
#[derive(Debug, Serialize, Deserialize)]
pub struct DepositFAEvent {
pub store: AccountAddress,
pub amount: u64,
}

impl MoveEventV2Type for DepositFAEvent {}

impl MoveStructType for DepositFAEvent {
const MODULE_NAME: &'static IdentStr = ident_str!("fungble_asset");
const STRUCT_NAME: &'static IdentStr = ident_str!("Deposit");
}
Loading

0 comments on commit b905dd7

Please sign in to comment.