Skip to content

Commit

Permalink
[asset-mapping] add test for writeset of object
Browse files Browse the repository at this point in the history
  • Loading branch information
welbon committed Jan 12, 2025
1 parent 4da80c5 commit 66dc4a7
Show file tree
Hide file tree
Showing 8 changed files with 189 additions and 119 deletions.
29 changes: 23 additions & 6 deletions executor/tests/executor_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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;
Expand Down Expand Up @@ -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 = {
Expand Down Expand Up @@ -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 = {
Expand Down Expand Up @@ -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 = {
Expand All @@ -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 = {
Expand All @@ -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(())
}
Expand Down Expand Up @@ -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(())
}
34 changes: 34 additions & 0 deletions vm/framework/starcoin-framework/doc/asset_mapping.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -80,6 +81,39 @@ Contains:
</dl>


</details>

<a id="0x1_asset_mapping_AssetMappingStoreT"></a>

## Resource `AssetMappingStoreT`



<pre><code><b>struct</b> <a href="asset_mapping.md#0x1_asset_mapping_AssetMappingStoreT">AssetMappingStoreT</a>&lt;T&gt; <b>has</b> key
</code></pre>



<details>
<summary>Fields</summary>


<dl>
<dt>
<code><a href="coin.md#0x1_coin">coin</a>: <a href="coin.md#0x1_coin_Coin">coin::Coin</a>&lt;T&gt;</code>
</dt>
<dd>

</dd>
<dt>
<code>old_path_str: <a href="../../move-stdlib/doc/vector.md#0x1_vector">vector</a>&lt;u8&gt;</code>
</dt>
<dd>

</dd>
</dl>


</details>

<a id="0x1_asset_mapping_AssetMappingPool"></a>
Expand Down
194 changes: 94 additions & 100 deletions vm/framework/starcoin-framework/doc/coin.md
Original file line number Diff line number Diff line change
Expand Up @@ -1201,6 +1201,15 @@ CoinStore is frozen. Coins cannot be deposited or withdrawn



<a id="0x1_coin_EMETA_DATA_NOT_FOUND"></a>



<pre><code><b>const</b> <a href="coin.md#0x1_coin_EMETA_DATA_NOT_FOUND">EMETA_DATA_NOT_FOUND</a>: u64 = 30;
</code></pre>



<a id="0x1_coin_EMIGRATION_FRAMEWORK_NOT_ENABLED"></a>

The migration process from coin to fungible asset is not enabled yet.
Expand Down Expand Up @@ -1475,6 +1484,12 @@ Create STC pairing by passing <code>StarcoinCoin</code>.
)
};

<a href="../../starcoin-stdlib/doc/debug.md#0x1_debug_print">debug::print</a>(&metadata_object_cref);
<b>assert</b>!(
<a href="object.md#0x1_object_is_object">object::is_object</a>(<a href="object.md#0x1_object_address_from_constructor_ref">object::address_from_constructor_ref</a>(&metadata_object_cref)),
<a href="../../move-stdlib/doc/error.md#0x1_error_invalid_state">error::invalid_state</a>(<a href="coin.md#0x1_coin_EMETA_DATA_NOT_FOUND">EMETA_DATA_NOT_FOUND</a>)
);

<a href="primary_fungible_store.md#0x1_primary_fungible_store_create_primary_store_enabled_fungible_asset">primary_fungible_store::create_primary_store_enabled_fungible_asset</a>(
&metadata_object_cref,
<a href="../../move-stdlib/doc/option.md#0x1_option_none">option::none</a>(),
Expand Down Expand Up @@ -3916,85 +3931,6 @@ initialize, initialize_internal, initialize_with_parallelizable_supply;




<a id="0x1_coin_spec_paired_metadata"></a>


<pre><code><b>fun</b> <a href="coin.md#0x1_coin_spec_paired_metadata">spec_paired_metadata</a>&lt;CoinType&gt;(): Option&lt;Object&lt;Metadata&gt;&gt; {
<b>if</b> (<b>exists</b>&lt;<a href="coin.md#0x1_coin_CoinConversionMap">CoinConversionMap</a>&gt;(@starcoin_framework)) {
<b>let</b> map = <b>global</b>&lt;<a href="coin.md#0x1_coin_CoinConversionMap">CoinConversionMap</a>&gt;(@starcoin_framework).coin_to_fungible_asset_map;
<b>if</b> (<a href="../../starcoin-stdlib/doc/table.md#0x1_table_spec_contains">table::spec_contains</a>(map, <a href="../../starcoin-stdlib/doc/type_info.md#0x1_type_info_type_of">type_info::type_of</a>&lt;CoinType&gt;())) {
<b>let</b> metadata = <a href="../../starcoin-stdlib/doc/table.md#0x1_table_spec_get">table::spec_get</a>(map, <a href="../../starcoin-stdlib/doc/type_info.md#0x1_type_info_type_of">type_info::type_of</a>&lt;CoinType&gt;());
<a href="../../move-stdlib/doc/option.md#0x1_option_spec_some">option::spec_some</a>(metadata)
} <b>else</b> {
<a href="../../move-stdlib/doc/option.md#0x1_option_spec_none">option::spec_none</a>()
}
} <b>else</b> {
<a href="../../move-stdlib/doc/option.md#0x1_option_spec_none">option::spec_none</a>()
}
}
</code></pre>




<a id="0x1_coin_spec_is_account_registered"></a>


<pre><code><b>fun</b> <a href="coin.md#0x1_coin_spec_is_account_registered">spec_is_account_registered</a>&lt;CoinType&gt;(account_addr: <b>address</b>): bool {
<b>let</b> paired_metadata_opt = <a href="coin.md#0x1_coin_spec_paired_metadata">spec_paired_metadata</a>&lt;CoinType&gt;();
<b>exists</b>&lt;<a href="coin.md#0x1_coin_CoinStore">CoinStore</a>&lt;CoinType&gt;&gt;(account_addr) || (<a href="../../move-stdlib/doc/option.md#0x1_option_spec_is_some">option::spec_is_some</a>(
paired_metadata_opt
) && <a href="primary_fungible_store.md#0x1_primary_fungible_store_spec_primary_store_exists">primary_fungible_store::spec_primary_store_exists</a>(account_addr, <a href="../../move-stdlib/doc/option.md#0x1_option_spec_borrow">option::spec_borrow</a>(paired_metadata_opt)))
}
</code></pre>




<a id="0x1_coin_CoinSubAbortsIf"></a>


<pre><code><b>schema</b> <a href="coin.md#0x1_coin_CoinSubAbortsIf">CoinSubAbortsIf</a>&lt;CoinType&gt; {
amount: u64;
<b>let</b> addr = <a href="../../starcoin-stdlib/doc/type_info.md#0x1_type_info_type_of">type_info::type_of</a>&lt;CoinType&gt;().account_address;
<b>let</b> maybe_supply = <b>global</b>&lt;<a href="coin.md#0x1_coin_CoinInfo">CoinInfo</a>&lt;CoinType&gt;&gt;(addr).<a href="coin.md#0x1_coin_supply">supply</a>;
<b>include</b> (<a href="../../move-stdlib/doc/option.md#0x1_option_is_some">option::is_some</a>(
maybe_supply
)) ==&gt; <a href="optional_aggregator.md#0x1_optional_aggregator_SubAbortsIf">optional_aggregator::SubAbortsIf</a> { <a href="optional_aggregator.md#0x1_optional_aggregator">optional_aggregator</a>: <a href="../../move-stdlib/doc/option.md#0x1_option_borrow">option::borrow</a>(maybe_supply), value: amount };
}
</code></pre>




<a id="0x1_coin_CoinAddAbortsIf"></a>


<pre><code><b>schema</b> <a href="coin.md#0x1_coin_CoinAddAbortsIf">CoinAddAbortsIf</a>&lt;CoinType&gt; {
amount: u64;
<b>let</b> addr = <a href="../../starcoin-stdlib/doc/type_info.md#0x1_type_info_type_of">type_info::type_of</a>&lt;CoinType&gt;().account_address;
<b>let</b> maybe_supply = <b>global</b>&lt;<a href="coin.md#0x1_coin_CoinInfo">CoinInfo</a>&lt;CoinType&gt;&gt;(addr).<a href="coin.md#0x1_coin_supply">supply</a>;
<b>include</b> (<a href="../../move-stdlib/doc/option.md#0x1_option_is_some">option::is_some</a>(
maybe_supply
)) ==&gt; <a href="optional_aggregator.md#0x1_optional_aggregator_AddAbortsIf">optional_aggregator::AddAbortsIf</a> { <a href="optional_aggregator.md#0x1_optional_aggregator">optional_aggregator</a>: <a href="../../move-stdlib/doc/option.md#0x1_option_borrow">option::borrow</a>(maybe_supply), value: amount };
}
</code></pre>




<a id="0x1_coin_AbortsIfNotExistCoinInfo"></a>


<pre><code><b>schema</b> <a href="coin.md#0x1_coin_AbortsIfNotExistCoinInfo">AbortsIfNotExistCoinInfo</a>&lt;CoinType&gt; {
<b>let</b> addr = <a href="../../starcoin-stdlib/doc/type_info.md#0x1_type_info_type_of">type_info::type_of</a>&lt;CoinType&gt;().account_address;
<b>aborts_if</b> !<b>exists</b>&lt;<a href="coin.md#0x1_coin_CoinInfo">CoinInfo</a>&lt;CoinType&gt;&gt;(addr);
}
</code></pre>



<a id="@Specification_1_AggregatableCoin"></a>

### Struct `AggregatableCoin`
Expand Down Expand Up @@ -4317,6 +4253,85 @@ Get address by reflection.




<a id="0x1_coin_spec_paired_metadata"></a>


<pre><code><b>fun</b> <a href="coin.md#0x1_coin_spec_paired_metadata">spec_paired_metadata</a>&lt;CoinType&gt;(): Option&lt;Object&lt;Metadata&gt;&gt; {
<b>if</b> (<b>exists</b>&lt;<a href="coin.md#0x1_coin_CoinConversionMap">CoinConversionMap</a>&gt;(@starcoin_framework)) {
<b>let</b> map = <b>global</b>&lt;<a href="coin.md#0x1_coin_CoinConversionMap">CoinConversionMap</a>&gt;(@starcoin_framework).coin_to_fungible_asset_map;
<b>if</b> (<a href="../../starcoin-stdlib/doc/table.md#0x1_table_spec_contains">table::spec_contains</a>(map, <a href="../../starcoin-stdlib/doc/type_info.md#0x1_type_info_type_of">type_info::type_of</a>&lt;CoinType&gt;())) {
<b>let</b> metadata = <a href="../../starcoin-stdlib/doc/table.md#0x1_table_spec_get">table::spec_get</a>(map, <a href="../../starcoin-stdlib/doc/type_info.md#0x1_type_info_type_of">type_info::type_of</a>&lt;CoinType&gt;());
<a href="../../move-stdlib/doc/option.md#0x1_option_spec_some">option::spec_some</a>(metadata)
} <b>else</b> {
<a href="../../move-stdlib/doc/option.md#0x1_option_spec_none">option::spec_none</a>()
}
} <b>else</b> {
<a href="../../move-stdlib/doc/option.md#0x1_option_spec_none">option::spec_none</a>()
}
}
</code></pre>




<a id="0x1_coin_spec_is_account_registered"></a>


<pre><code><b>fun</b> <a href="coin.md#0x1_coin_spec_is_account_registered">spec_is_account_registered</a>&lt;CoinType&gt;(account_addr: <b>address</b>): bool {
<b>let</b> paired_metadata_opt = <a href="coin.md#0x1_coin_spec_paired_metadata">spec_paired_metadata</a>&lt;CoinType&gt;();
<b>exists</b>&lt;<a href="coin.md#0x1_coin_CoinStore">CoinStore</a>&lt;CoinType&gt;&gt;(account_addr) || (<a href="../../move-stdlib/doc/option.md#0x1_option_spec_is_some">option::spec_is_some</a>(
paired_metadata_opt
) && <a href="primary_fungible_store.md#0x1_primary_fungible_store_spec_primary_store_exists">primary_fungible_store::spec_primary_store_exists</a>(account_addr, <a href="../../move-stdlib/doc/option.md#0x1_option_spec_borrow">option::spec_borrow</a>(paired_metadata_opt)))
}
</code></pre>




<a id="0x1_coin_CoinSubAbortsIf"></a>


<pre><code><b>schema</b> <a href="coin.md#0x1_coin_CoinSubAbortsIf">CoinSubAbortsIf</a>&lt;CoinType&gt; {
amount: u64;
<b>let</b> addr = <a href="../../starcoin-stdlib/doc/type_info.md#0x1_type_info_type_of">type_info::type_of</a>&lt;CoinType&gt;().account_address;
<b>let</b> maybe_supply = <b>global</b>&lt;<a href="coin.md#0x1_coin_CoinInfo">CoinInfo</a>&lt;CoinType&gt;&gt;(addr).<a href="coin.md#0x1_coin_supply">supply</a>;
<b>include</b> (<a href="../../move-stdlib/doc/option.md#0x1_option_is_some">option::is_some</a>(
maybe_supply
)) ==&gt; <a href="optional_aggregator.md#0x1_optional_aggregator_SubAbortsIf">optional_aggregator::SubAbortsIf</a> { <a href="optional_aggregator.md#0x1_optional_aggregator">optional_aggregator</a>: <a href="../../move-stdlib/doc/option.md#0x1_option_borrow">option::borrow</a>(maybe_supply), value: amount };
}
</code></pre>




<a id="0x1_coin_CoinAddAbortsIf"></a>


<pre><code><b>schema</b> <a href="coin.md#0x1_coin_CoinAddAbortsIf">CoinAddAbortsIf</a>&lt;CoinType&gt; {
amount: u64;
<b>let</b> addr = <a href="../../starcoin-stdlib/doc/type_info.md#0x1_type_info_type_of">type_info::type_of</a>&lt;CoinType&gt;().account_address;
<b>let</b> maybe_supply = <b>global</b>&lt;<a href="coin.md#0x1_coin_CoinInfo">CoinInfo</a>&lt;CoinType&gt;&gt;(addr).<a href="coin.md#0x1_coin_supply">supply</a>;
<b>include</b> (<a href="../../move-stdlib/doc/option.md#0x1_option_is_some">option::is_some</a>(
maybe_supply
)) ==&gt; <a href="optional_aggregator.md#0x1_optional_aggregator_AddAbortsIf">optional_aggregator::AddAbortsIf</a> { <a href="optional_aggregator.md#0x1_optional_aggregator">optional_aggregator</a>: <a href="../../move-stdlib/doc/option.md#0x1_option_borrow">option::borrow</a>(maybe_supply), value: amount };
}
</code></pre>




<a id="0x1_coin_AbortsIfNotExistCoinInfo"></a>


<pre><code><b>schema</b> <a href="coin.md#0x1_coin_AbortsIfNotExistCoinInfo">AbortsIfNotExistCoinInfo</a>&lt;CoinType&gt; {
<b>let</b> addr = <a href="../../starcoin-stdlib/doc/type_info.md#0x1_type_info_type_of">type_info::type_of</a>&lt;CoinType&gt;().account_address;
<b>aborts_if</b> !<b>exists</b>&lt;<a href="coin.md#0x1_coin_CoinInfo">CoinInfo</a>&lt;CoinType&gt;&gt;(addr);
}
</code></pre>



<a id="@Specification_1_name"></a>

### Function `name`
Expand Down Expand Up @@ -4697,27 +4712,6 @@ The creator of <code>CoinType</code> must be <code>@starcoin_framework</code>.
</code></pre>


Make sure <code>name</code> and <code>symbol</code> are legal length.
Only the creator of <code>CoinType</code> can initialize.


<a id="0x1_coin_InitializeInternalSchema"></a>


<pre><code><b>schema</b> <a href="coin.md#0x1_coin_InitializeInternalSchema">InitializeInternalSchema</a>&lt;CoinType&gt; {
<a href="account.md#0x1_account">account</a>: <a href="../../move-stdlib/doc/signer.md#0x1_signer">signer</a>;
name: <a href="../../move-stdlib/doc/vector.md#0x1_vector">vector</a>&lt;u8&gt;;
symbol: <a href="../../move-stdlib/doc/vector.md#0x1_vector">vector</a>&lt;u8&gt;;
<b>let</b> account_addr = <a href="../../move-stdlib/doc/signer.md#0x1_signer_address_of">signer::address_of</a>(<a href="account.md#0x1_account">account</a>);
<b>let</b> coin_address = <a href="../../starcoin-stdlib/doc/type_info.md#0x1_type_info_type_of">type_info::type_of</a>&lt;CoinType&gt;().account_address;
<b>aborts_if</b> coin_address != account_addr;
<b>aborts_if</b> <b>exists</b>&lt;<a href="coin.md#0x1_coin_CoinInfo">CoinInfo</a>&lt;CoinType&gt;&gt;(account_addr);
<b>aborts_if</b> len(name) &gt; <a href="coin.md#0x1_coin_MAX_COIN_NAME_LENGTH">MAX_COIN_NAME_LENGTH</a>;
<b>aborts_if</b> len(symbol) &gt; <a href="coin.md#0x1_coin_MAX_COIN_SYMBOL_LENGTH">MAX_COIN_SYMBOL_LENGTH</a>;
}
</code></pre>



<a id="@Specification_1_initialize_internal"></a>

Expand Down
12 changes: 6 additions & 6 deletions vm/framework/starcoin-framework/doc/stc_genesis.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
<b>let</b> asset_mapping_coin = <a href="coin.md#0x1_coin_extract">coin::extract</a>&lt;STC&gt;(&<b>mut</b> total_supply_stc, 100000000000000000);
<a href="asset_mapping.md#0x1_asset_mapping_create_store_from_coin">asset_mapping::create_store_from_coin</a>&lt;STC&gt;(
starcoin_framework,
b"0x1::STC::STC",
asset_mapping_coin
);
// <b>let</b> asset_mapping_coin = <a href="coin.md#0x1_coin_extract">coin::extract</a>&lt;STC&gt;(&<b>mut</b> total_supply_stc, 100000000000000000);
// <a href="asset_mapping.md#0x1_asset_mapping_create_store_from_coin">asset_mapping::create_store_from_coin</a>&lt;STC&gt;(
// starcoin_framework,
// b"0x1::STC::STC",
// asset_mapping_coin
// );
// fungible_asset::put_test_store_genesis(core_resource_account);

// Initialize <a href="treasury.md#0x1_treasury">treasury</a>
Expand Down
Loading

0 comments on commit 66dc4a7

Please sign in to comment.