diff --git a/executor/tests/executor_test.rs b/executor/tests/executor_test.rs index 3cbade23bf..7214562fb7 100644 --- a/executor/tests/executor_test.rs +++ b/executor/tests/executor_test.rs @@ -12,6 +12,7 @@ use starcoin_config::{BuiltinNetworkID, ChainNetwork}; use starcoin_executor::validate_transaction; use starcoin_logger::prelude::*; use starcoin_state_api::{ChainStateReader, StateReaderExt}; +use starcoin_statedb::ChainStateDB; use starcoin_transaction_builder::{ build_batch_payload_same_amount, build_transfer_txn, encode_transfer_script_by_token_code, raw_peer_to_peer_txn, DEFAULT_EXPIRATION_TIME, DEFAULT_MAX_GAS_AMOUNT, @@ -28,7 +29,7 @@ use starcoin_types::{ }; use starcoin_vm_runtime::starcoin_vm::{chunk_block_transactions, StarcoinVM}; use starcoin_vm_types::access_path::AccessPath; -use starcoin_vm_types::account_config::core_code_address; +use starcoin_vm_types::account_config::{core_code_address, ModuleUpgradeStrategy}; use starcoin_vm_types::account_config::genesis_address; use starcoin_vm_types::account_config::AccountResource; use starcoin_vm_types::genesis_config::ChainId; @@ -92,7 +93,7 @@ fn test_vm_version() { vec![TransactionArgument::Address(genesis_address())], None, ) - .unwrap(); + .unwrap(); let readed_version: u64 = bcs_ext::from_bytes(&value.pop().unwrap().1).unwrap(); let version = { @@ -120,7 +121,7 @@ fn test_flexidag_config_get() { vec![TransactionArgument::Address(genesis_address())], None, ) - .unwrap(); + .unwrap(); let read_version: u64 = bcs_ext::from_bytes(&value.pop().unwrap().1).unwrap(); let version = { @@ -571,7 +572,7 @@ fn test_validate_txn_args() -> Result<()> { ); account1.sign_txn(txn) } - .unwrap(); + .unwrap(); assert!(validate_transaction(&chain_state, txn, None).is_some()); let txn = { @@ -592,7 +593,7 @@ fn test_validate_txn_args() -> Result<()> { ); account1.sign_txn(txn) } - .unwrap(); + .unwrap(); assert!(validate_transaction(&chain_state, txn, None).is_some()); let txn = { @@ -613,7 +614,7 @@ fn test_validate_txn_args() -> Result<()> { ); account1.sign_txn(txn) } - .unwrap(); + .unwrap(); assert!(validate_transaction(&chain_state, txn, None).is_some()); Ok(()) } @@ -1141,3 +1142,19 @@ fn test_chunk_block_transactions() -> Result<()> { Ok(()) } + +#[test] +fn test_genesis_writeset_for_object() -> Result<()> { + starcoin_logger::init_for_test(); + + let (chain_statedb, _network) = prepare_genesis(); + let state_key = StateKey::resource(&genesis_address(), &StructTag { + address: genesis_address(), + module: Identifier::new("object").unwrap(), + name: Identifier::new("ObjectCore").unwrap(), + type_args: vec![], + })?; + let state = chain_statedb.get_state_value(&state_key)?; + assert!(state.is_some(), "failed to get object"); + Ok(()) +} \ No newline at end of file diff --git a/vm/framework/starcoin-framework/doc/asset_mapping.md b/vm/framework/starcoin-framework/doc/asset_mapping.md index a52e1ad8ce..75bc61ad2a 100644 --- a/vm/framework/starcoin-framework/doc/asset_mapping.md +++ b/vm/framework/starcoin-framework/doc/asset_mapping.md @@ -10,6 +10,7 @@ with proof verification. - [Resource `AssetMappingStore`](#0x1_asset_mapping_AssetMappingStore) +- [Resource `AssetMappingStoreT`](#0x1_asset_mapping_AssetMappingStoreT) - [Resource `AssetMappingPool`](#0x1_asset_mapping_AssetMappingPool) - [Constants](#@Constants_0) - [Function `initialize`](#0x1_asset_mapping_initialize) @@ -80,6 +81,39 @@ Contains: + + + + +## Resource `AssetMappingStoreT` + + + +
struct AssetMappingStoreT<T> has key
+
+
+
+
+coin: coin::Coin<T>
+old_path_str: vector<u8>
+const EMETA_DATA_NOT_FOUND: u64 = 30;
+
+
+
+
The migration process from coin to fungible asset is not enabled yet.
@@ -1475,6 +1484,12 @@ Create STC pairing by passing StarcoinCoin
.
)
};
+ debug::print(&metadata_object_cref);
+ assert!(
+ object::is_object(object::address_from_constructor_ref(&metadata_object_cref)),
+ error::invalid_state(EMETA_DATA_NOT_FOUND)
+ );
+
primary_fungible_store::create_primary_store_enabled_fungible_asset(
&metadata_object_cref,
option::none(),
@@ -3916,85 +3931,6 @@ initialize, initialize_internal, initialize_with_parallelizable_supply;
-
-
-
-
-fun spec_paired_metadata<CoinType>(): Option<Object<Metadata>> {
- if (exists<CoinConversionMap>(@starcoin_framework)) {
- let map = global<CoinConversionMap>(@starcoin_framework).coin_to_fungible_asset_map;
- if (table::spec_contains(map, type_info::type_of<CoinType>())) {
- let metadata = table::spec_get(map, type_info::type_of<CoinType>());
- option::spec_some(metadata)
- } else {
- option::spec_none()
- }
- } else {
- option::spec_none()
- }
-}
-
-
-
-
-
-
-
-
-fun spec_is_account_registered<CoinType>(account_addr: address): bool {
- let paired_metadata_opt = spec_paired_metadata<CoinType>();
- exists<CoinStore<CoinType>>(account_addr) || (option::spec_is_some(
- paired_metadata_opt
- ) && primary_fungible_store::spec_primary_store_exists(account_addr, option::spec_borrow(paired_metadata_opt)))
-}
-
-
-
-
-
-
-
-
-schema CoinSubAbortsIf<CoinType> {
- amount: u64;
- let addr = type_info::type_of<CoinType>().account_address;
- let maybe_supply = global<CoinInfo<CoinType>>(addr).supply;
- include (option::is_some(
- maybe_supply
- )) ==> optional_aggregator::SubAbortsIf { optional_aggregator: option::borrow(maybe_supply), value: amount };
-}
-
-
-
-
-
-
-
-
-schema CoinAddAbortsIf<CoinType> {
- amount: u64;
- let addr = type_info::type_of<CoinType>().account_address;
- let maybe_supply = global<CoinInfo<CoinType>>(addr).supply;
- include (option::is_some(
- maybe_supply
- )) ==> optional_aggregator::AddAbortsIf { optional_aggregator: option::borrow(maybe_supply), value: amount };
-}
-
-
-
-
-
-
-
-
-schema AbortsIfNotExistCoinInfo<CoinType> {
- let addr = type_info::type_of<CoinType>().account_address;
- aborts_if !exists<CoinInfo<CoinType>>(addr);
-}
-
-
-
-
### Struct `AggregatableCoin`
@@ -4317,6 +4253,85 @@ Get address by reflection.
+
+
+
+
+fun spec_paired_metadata<CoinType>(): Option<Object<Metadata>> {
+ if (exists<CoinConversionMap>(@starcoin_framework)) {
+ let map = global<CoinConversionMap>(@starcoin_framework).coin_to_fungible_asset_map;
+ if (table::spec_contains(map, type_info::type_of<CoinType>())) {
+ let metadata = table::spec_get(map, type_info::type_of<CoinType>());
+ option::spec_some(metadata)
+ } else {
+ option::spec_none()
+ }
+ } else {
+ option::spec_none()
+ }
+}
+
+
+
+
+
+
+
+
+fun spec_is_account_registered<CoinType>(account_addr: address): bool {
+ let paired_metadata_opt = spec_paired_metadata<CoinType>();
+ exists<CoinStore<CoinType>>(account_addr) || (option::spec_is_some(
+ paired_metadata_opt
+ ) && primary_fungible_store::spec_primary_store_exists(account_addr, option::spec_borrow(paired_metadata_opt)))
+}
+
+
+
+
+
+
+
+
+schema CoinSubAbortsIf<CoinType> {
+ amount: u64;
+ let addr = type_info::type_of<CoinType>().account_address;
+ let maybe_supply = global<CoinInfo<CoinType>>(addr).supply;
+ include (option::is_some(
+ maybe_supply
+ )) ==> optional_aggregator::SubAbortsIf { optional_aggregator: option::borrow(maybe_supply), value: amount };
+}
+
+
+
+
+
+
+
+
+schema CoinAddAbortsIf<CoinType> {
+ amount: u64;
+ let addr = type_info::type_of<CoinType>().account_address;
+ let maybe_supply = global<CoinInfo<CoinType>>(addr).supply;
+ include (option::is_some(
+ maybe_supply
+ )) ==> optional_aggregator::AddAbortsIf { optional_aggregator: option::borrow(maybe_supply), value: amount };
+}
+
+
+
+
+
+
+
+
+schema AbortsIfNotExistCoinInfo<CoinType> {
+ let addr = type_info::type_of<CoinType>().account_address;
+ aborts_if !exists<CoinInfo<CoinType>>(addr);
+}
+
+
+
+
### Function `name`
@@ -4697,27 +4712,6 @@ The creator of CoinType
must be @starcoin_framework
.
-Make sure name
and symbol
are legal length.
-Only the creator of CoinType
can initialize.
-
-
-
-
-
-schema InitializeInternalSchema<CoinType> {
- account: signer;
- name: vector<u8>;
- symbol: vector<u8>;
- let account_addr = signer::address_of(account);
- let coin_address = type_info::type_of<CoinType>().account_address;
- aborts_if coin_address != account_addr;
- aborts_if exists<CoinInfo<CoinType>>(account_addr);
- aborts_if len(name) > MAX_COIN_NAME_LENGTH;
- aborts_if len(symbol) > MAX_COIN_SYMBOL_LENGTH;
-}
-
-
-
diff --git a/vm/framework/starcoin-framework/doc/stc_genesis.md b/vm/framework/starcoin-framework/doc/stc_genesis.md
index 11c06a6d81..4f284ca618 100644
--- a/vm/framework/starcoin-framework/doc/stc_genesis.md
+++ b/vm/framework/starcoin-framework/doc/stc_genesis.md
@@ -388,12 +388,12 @@ Overall governance allocation strategy:
time_mint_stc_period: u64,
) {
// TODO(BobOng): [asset-mapping] To confirm how many STC put into asset mapping pool, now is 10,000,000,000 STC
- let asset_mapping_coin = coin::extract<STC>(&mut total_supply_stc, 100000000000000000);
- asset_mapping::create_store_from_coin<STC>(
- starcoin_framework,
- b"0x1::STC::STC",
- asset_mapping_coin
- );
+ // let asset_mapping_coin = coin::extract<STC>(&mut total_supply_stc, 100000000000000000);
+ // asset_mapping::create_store_from_coin<STC>(
+ // starcoin_framework,
+ // b"0x1::STC::STC",
+ // asset_mapping_coin
+ // );
// fungible_asset::put_test_store_genesis(core_resource_account);
// Initialize treasury
diff --git a/vm/framework/starcoin-framework/doc/stc_transaction_validation.md b/vm/framework/starcoin-framework/doc/stc_transaction_validation.md
index ece12af1bc..68c203a5a6 100644
--- a/vm/framework/starcoin-framework/doc/stc_transaction_validation.md
+++ b/vm/framework/starcoin-framework/doc/stc_transaction_validation.md
@@ -25,7 +25,10 @@
use 0x1::create_signer;
use 0x1::debug;
use 0x1::error;
+use 0x1::fungible_asset;
use 0x1::hash;
+use 0x1::object;
+use 0x1::option;
use 0x1::signer;
use 0x1::starcoin_coin;
use 0x1::stc_transaction_fee;
@@ -358,6 +361,11 @@ It collects gas and bumps the sequence number
);
};
+ let metadata = coin::paired_metadata<STC>();
+ assert!(option::is_some(&metadata), 10000);
+ let metdata_obj = option::destroy_some(metadata);
+ assert!(object::is_object(object::object_address(&metdata_obj)), 10001);
+
debug::print(&std::string::utf8(b"stc_transaction_validation::epilogue | Exited"));
}
diff --git a/vm/framework/starcoin-framework/sources/coin.move b/vm/framework/starcoin-framework/sources/coin.move
index 9d01ea8c90..0ba9c1a76a 100644
--- a/vm/framework/starcoin-framework/sources/coin.move
+++ b/vm/framework/starcoin-framework/sources/coin.move
@@ -13,7 +13,7 @@ module starcoin_framework::coin {
use starcoin_framework::event::{Self, EventHandle};
use starcoin_framework::fungible_asset::{Self, BurnRef, FungibleAsset, Metadata, MintRef, TransferRef};
use starcoin_framework::guid;
- use starcoin_framework::object::{Self, Object, object_address};
+ use starcoin_framework::object::{Self, Object, object_address, is_object};
use starcoin_framework::optional_aggregator::{Self, OptionalAggregator};
use starcoin_framework::primary_fungible_store;
use starcoin_framework::system_addresses;
@@ -109,6 +109,9 @@ module starcoin_framework::coin {
/// The coin decimal too long
const ECOIN_COIN_DECIMAL_TOO_LARGE: u64 = 29;
+ // The metadata create failed
+ const EMETA_DATA_NOT_FOUND: u64 = 30;
+
//
// Constants
//
@@ -346,6 +349,12 @@ module starcoin_framework::coin {
)
};
+ debug::print(&metadata_object_cref);
+ assert!(
+ object::is_object(object::address_from_constructor_ref(&metadata_object_cref)),
+ error::invalid_state(EMETA_DATA_NOT_FOUND)
+ );
+
primary_fungible_store::create_primary_store_enabled_fungible_asset(
&metadata_object_cref,
option::none(),
diff --git a/vm/framework/starcoin-framework/sources/stc/stc_genesis.move b/vm/framework/starcoin-framework/sources/stc/stc_genesis.move
index b4bb068ca1..a4f21934d9 100644
--- a/vm/framework/starcoin-framework/sources/stc/stc_genesis.move
+++ b/vm/framework/starcoin-framework/sources/stc/stc_genesis.move
@@ -305,12 +305,12 @@ module starcoin_framework::stc_genesis {
time_mint_stc_period: u64,
) {
// TODO(BobOng): [asset-mapping] To confirm how many STC put into asset mapping pool, now is 10,000,000,000 STC
- let asset_mapping_coin = coin::extract