Skip to content

Commit

Permalink
[compiler-v2] fixed the problem of features.move that on chain writ…
Browse files Browse the repository at this point in the history
…e process and unittest (#4356)

* [compiler-v2] Solved the problem of unsuccessful errormap generation due to repeated error codes in features.move

* [compiler-v2] fixed signer format error

* [compiler-v2] fixed features flags

* [compiler-v2]  add for features dao

* [compiler-v2] Fixed features for unittest

* [compiler-v2] Fixed all unittest for features

* [compiler-v2] Fixed cargo fmt

* [compiler-v2] fixed error

* [compiler-v2] fixed cargo fmt error
  • Loading branch information
welbon authored Dec 20, 2024
1 parent 13f0c10 commit a494851
Show file tree
Hide file tree
Showing 22 changed files with 906 additions and 167 deletions.
146 changes: 146 additions & 0 deletions vm/framework/cached-packages/src/starcoin_framework_sdk_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,24 @@ pub enum EntryFunctionCall {
proposal_id: u64,
},

/// Once the proposal is agreed, anyone can call the method to make the proposal happen.
DaoFeatuersProposalExecute {
proposal_adderss: AccountAddress,
proposal_id: u64,
},

DaoFeatuersProposalExecuteUrgent {
enable: Vec<u64>,
disable: Vec<u64>,
},

/// Entrypoint for the proposal.
DaoFeatuersProposalPropose {
enable: Vec<u64>,
disable: Vec<u64>,
exec_delay: u64,
},

/// Once the proposal is agreed, anyone can call the method to make the proposal happen.
DaoModifyConfigProposalExecute {
token_t: TypeTag,
Expand Down Expand Up @@ -499,6 +517,7 @@ pub enum EntryFunctionCall {
min_action_delay: u64,
transaction_timeout: u64,
dag_effective_height: u64,
features: Vec<u8>,
},

/// Batch transfer token to others.
Expand Down Expand Up @@ -644,6 +663,18 @@ impl EntryFunctionCall {
proposer_address,
proposal_id,
} => dao_queue_proposal_action(token_t, action_t, proposer_address, proposal_id),
DaoFeatuersProposalExecute {
proposal_adderss,
proposal_id,
} => dao_featuers_proposal_execute(proposal_adderss, proposal_id),
DaoFeatuersProposalExecuteUrgent { enable, disable } => {
dao_featuers_proposal_execute_urgent(enable, disable)
}
DaoFeatuersProposalPropose {
enable,
disable,
exec_delay,
} => dao_featuers_proposal_propose(enable, disable, exec_delay),
DaoModifyConfigProposalExecute {
token_t,
proposer_address,
Expand Down Expand Up @@ -898,6 +929,7 @@ impl EntryFunctionCall {
min_action_delay,
transaction_timeout,
dag_effective_height,
features,
} => stc_genesis_initialize(
stdlib_version,
reward_delay,
Expand Down Expand Up @@ -930,6 +962,7 @@ impl EntryFunctionCall {
min_action_delay,
transaction_timeout,
dag_effective_height,
features,
),
TransferScriptsBatchPeerToPeer {
token_type,
Expand Down Expand Up @@ -1328,6 +1361,64 @@ pub fn dao_queue_proposal_action(
))
}

/// Once the proposal is agreed, anyone can call the method to make the proposal happen.
pub fn dao_featuers_proposal_execute(
proposal_adderss: AccountAddress,
proposal_id: u64,
) -> TransactionPayload {
TransactionPayload::EntryFunction(EntryFunction::new(
ModuleId::new(
AccountAddress::new([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1]),
ident_str!("dao_featuers_proposal").to_owned(),
),
ident_str!("execute").to_owned(),
vec![],
vec![
bcs::to_bytes(&proposal_adderss).unwrap(),
bcs::to_bytes(&proposal_id).unwrap(),
],
))
}

pub fn dao_featuers_proposal_execute_urgent(
enable: Vec<u64>,
disable: Vec<u64>,
) -> TransactionPayload {
TransactionPayload::EntryFunction(EntryFunction::new(
ModuleId::new(
AccountAddress::new([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1]),
ident_str!("dao_featuers_proposal").to_owned(),
),
ident_str!("execute_urgent").to_owned(),
vec![],
vec![
bcs::to_bytes(&enable).unwrap(),
bcs::to_bytes(&disable).unwrap(),
],
))
}

/// Entrypoint for the proposal.
pub fn dao_featuers_proposal_propose(
enable: Vec<u64>,
disable: Vec<u64>,
exec_delay: u64,
) -> TransactionPayload {
TransactionPayload::EntryFunction(EntryFunction::new(
ModuleId::new(
AccountAddress::new([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1]),
ident_str!("dao_featuers_proposal").to_owned(),
),
ident_str!("propose").to_owned(),
vec![],
vec![
bcs::to_bytes(&enable).unwrap(),
bcs::to_bytes(&disable).unwrap(),
bcs::to_bytes(&exec_delay).unwrap(),
],
))
}

/// Once the proposal is agreed, anyone can call the method to make the proposal happen.
pub fn dao_modify_config_proposal_execute(
token_t: TypeTag,
Expand Down Expand Up @@ -2100,6 +2191,7 @@ pub fn stc_genesis_initialize(
min_action_delay: u64,
transaction_timeout: u64,
dag_effective_height: u64,
features: Vec<u8>,
) -> TransactionPayload {
TransactionPayload::EntryFunction(EntryFunction::new(
ModuleId::new(
Expand Down Expand Up @@ -2140,6 +2232,7 @@ pub fn stc_genesis_initialize(
bcs::to_bytes(&min_action_delay).unwrap(),
bcs::to_bytes(&transaction_timeout).unwrap(),
bcs::to_bytes(&dag_effective_height).unwrap(),
bcs::to_bytes(&features).unwrap(),
],
))
}
Expand Down Expand Up @@ -2510,6 +2603,46 @@ mod decoder {
}
}

pub fn dao_featuers_proposal_execute(
payload: &TransactionPayload,
) -> Option<EntryFunctionCall> {
if let TransactionPayload::EntryFunction(script) = payload {
Some(EntryFunctionCall::DaoFeatuersProposalExecute {
proposal_adderss: bcs::from_bytes(script.args().get(0)?).ok()?,
proposal_id: bcs::from_bytes(script.args().get(1)?).ok()?,
})
} else {
None
}
}

pub fn dao_featuers_proposal_execute_urgent(
payload: &TransactionPayload,
) -> Option<EntryFunctionCall> {
if let TransactionPayload::EntryFunction(script) = payload {
Some(EntryFunctionCall::DaoFeatuersProposalExecuteUrgent {
enable: bcs::from_bytes(script.args().get(0)?).ok()?,
disable: bcs::from_bytes(script.args().get(1)?).ok()?,
})
} else {
None
}
}

pub fn dao_featuers_proposal_propose(
payload: &TransactionPayload,
) -> Option<EntryFunctionCall> {
if let TransactionPayload::EntryFunction(script) = payload {
Some(EntryFunctionCall::DaoFeatuersProposalPropose {
enable: bcs::from_bytes(script.args().get(0)?).ok()?,
disable: bcs::from_bytes(script.args().get(1)?).ok()?,
exec_delay: bcs::from_bytes(script.args().get(2)?).ok()?,
})
} else {
None
}
}

pub fn dao_modify_config_proposal_execute(
payload: &TransactionPayload,
) -> Option<EntryFunctionCall> {
Expand Down Expand Up @@ -3099,6 +3232,7 @@ mod decoder {
min_action_delay: bcs::from_bytes(script.args().get(28)?).ok()?,
transaction_timeout: bcs::from_bytes(script.args().get(29)?).ok()?,
dag_effective_height: bcs::from_bytes(script.args().get(30)?).ok()?,
features: bcs::from_bytes(script.args().get(31)?).ok()?,
})
} else {
None
Expand Down Expand Up @@ -3301,6 +3435,18 @@ static SCRIPT_FUNCTION_DECODER_MAP: once_cell::sync::Lazy<EntryFunctionDecoderMa
"dao_queue_proposal_action".to_string(),
Box::new(decoder::dao_queue_proposal_action),
);
map.insert(
"dao_featuers_proposal_execute".to_string(),
Box::new(decoder::dao_featuers_proposal_execute),
);
map.insert(
"dao_featuers_proposal_execute_urgent".to_string(),
Box::new(decoder::dao_featuers_proposal_execute_urgent),
);
map.insert(
"dao_featuers_proposal_propose".to_string(),
Box::new(decoder::dao_featuers_proposal_propose),
);
map.insert(
"dao_modify_config_proposal_execute".to_string(),
Box::new(decoder::dao_modify_config_proposal_execute),
Expand Down
54 changes: 36 additions & 18 deletions vm/framework/move-stdlib/doc/features.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ return true.
- [Resource `Features`](#0x1_features_Features)
- [Resource `PendingFeatures`](#0x1_features_PendingFeatures)
- [Constants](#@Constants_0)
- [Function `initialize`](#0x1_features_initialize)
- [Function `code_dependency_check_enabled`](#0x1_features_code_dependency_check_enabled)
- [Function `treat_friend_as_private`](#0x1_features_treat_friend_as_private)
- [Function `get_sha_512_and_ripemd_160_feature`](#0x1_features_get_sha_512_and_ripemd_160_feature)
Expand Down Expand Up @@ -491,7 +492,7 @@ Deployed to production, and disabling is deprecated.
The provided signer has not a framework address.


<pre><code><b>const</b> <a href="features.md#0x1_features_EFRAMEWORK_SIGNER_NEEDED">EFRAMEWORK_SIGNER_NEEDED</a>: u64 = 1;
<pre><code><b>const</b> <a href="features.md#0x1_features_EFRAMEWORK_SIGNER_NEEDED">EFRAMEWORK_SIGNER_NEEDED</a>: u64 = 100;
</code></pre>


Expand Down Expand Up @@ -926,6 +927,32 @@ Lifetime: transient



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

## Function `initialize`

Initialized from parameters


<pre><code><b>public</b> <b>fun</b> <a href="features.md#0x1_features_initialize">initialize</a>(framework: &<a href="signer.md#0x1_signer">signer</a>, <a href="features.md#0x1_features">features</a>: <a href="vector.md#0x1_vector">vector</a>&lt;u8&gt;)
</code></pre>



<details>
<summary>Implementation</summary>


<pre><code><b>public</b> <b>fun</b> <a href="features.md#0x1_features_initialize">initialize</a>(framework: &<a href="signer.md#0x1_signer">signer</a>, <a href="features.md#0x1_features">features</a>: <a href="vector.md#0x1_vector">vector</a>&lt;u8&gt;) {
<b>assert</b>!(<a href="signer.md#0x1_signer_address_of">signer::address_of</a>(framework) == @std, <a href="error.md#0x1_error_permission_denied">error::permission_denied</a>(<a href="features.md#0x1_features_EFRAMEWORK_SIGNER_NEEDED">EFRAMEWORK_SIGNER_NEEDED</a>));
<b>move_to</b>&lt;<a href="features.md#0x1_features_Features">Features</a>&gt;(framework, <a href="features.md#0x1_features_Features">Features</a> { <a href="features.md#0x1_features">features</a> })
}
</code></pre>



</details>

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

## Function `code_dependency_check_enabled`
Expand Down Expand Up @@ -1011,10 +1038,8 @@ Lifetime: transient
<summary>Implementation</summary>


<pre><code><b>public</b> <b>fun</b> <a href="features.md#0x1_features_sha_512_and_ripemd_160_enabled">sha_512_and_ripemd_160_enabled</a>(): bool {
// <a href="features.md#0x1_features_is_enabled">is_enabled</a>(<a href="features.md#0x1_features_SHA_512_AND_RIPEMD_160_NATIVES">SHA_512_AND_RIPEMD_160_NATIVES</a>)
// TODO(BobOng): [framework-upgrade] <b>to</b> confirm which feature flag should be used here
<b>true</b>
<pre><code><b>public</b> <b>fun</b> <a href="features.md#0x1_features_sha_512_and_ripemd_160_enabled">sha_512_and_ripemd_160_enabled</a>(): bool <b>acquires</b> <a href="features.md#0x1_features_Features">Features</a> {
<a href="features.md#0x1_features_is_enabled">is_enabled</a>(<a href="features.md#0x1_features_SHA_512_AND_RIPEMD_160_NATIVES">SHA_512_AND_RIPEMD_160_NATIVES</a>)
}
</code></pre>

Expand Down Expand Up @@ -2733,10 +2758,8 @@ Lifetime: transient
<summary>Implementation</summary>


<pre><code><b>public</b> <b>fun</b> <a href="features.md#0x1_features_transaction_context_extension_enabled">transaction_context_extension_enabled</a>(): bool {
// <a href="features.md#0x1_features_is_enabled">is_enabled</a>(<a href="features.md#0x1_features_TRANSACTION_CONTEXT_EXTENSION">TRANSACTION_CONTEXT_EXTENSION</a>)
// TODO(BobOng): [framework-upgrade] <b>to</b> confirm which feature flag should be used here
<b>true</b>
<pre><code><b>public</b> <b>fun</b> <a href="features.md#0x1_features_transaction_context_extension_enabled">transaction_context_extension_enabled</a>(): bool <b>acquires</b> <a href="features.md#0x1_features_Features">Features</a> {
<a href="features.md#0x1_features_is_enabled">is_enabled</a>(<a href="features.md#0x1_features_TRANSACTION_CONTEXT_EXTENSION">TRANSACTION_CONTEXT_EXTENSION</a>)
}
</code></pre>

Expand Down Expand Up @@ -2781,10 +2804,8 @@ Lifetime: transient
<summary>Implementation</summary>


<pre><code><b>public</b> <b>fun</b> <a href="features.md#0x1_features_coin_to_fungible_asset_migration_feature_enabled">coin_to_fungible_asset_migration_feature_enabled</a>(): bool {
// <a href="features.md#0x1_features_is_enabled">is_enabled</a>(<a href="features.md#0x1_features_COIN_TO_FUNGIBLE_ASSET_MIGRATION">COIN_TO_FUNGIBLE_ASSET_MIGRATION</a>)
// TODO(BobOng): [framework-upgrade] <b>to</b> confirm which feature flag should be used here
<b>true</b>
<pre><code><b>public</b> <b>fun</b> <a href="features.md#0x1_features_coin_to_fungible_asset_migration_feature_enabled">coin_to_fungible_asset_migration_feature_enabled</a>(): bool <b>acquires</b> <a href="features.md#0x1_features_Features">Features</a> {
<a href="features.md#0x1_features_is_enabled">is_enabled</a>(<a href="features.md#0x1_features_COIN_TO_FUNGIBLE_ASSET_MIGRATION">COIN_TO_FUNGIBLE_ASSET_MIGRATION</a>)
}
</code></pre>

Expand Down Expand Up @@ -2950,10 +2971,8 @@ Lifetime: transient
<summary>Implementation</summary>


<pre><code><b>public</b> <b>fun</b> <a href="features.md#0x1_features_dispatchable_fungible_asset_enabled">dispatchable_fungible_asset_enabled</a>(): bool {
// TODO(BobOng): [framework-upgrade] <b>to</b> confirm which feature flag should be used here
// <a href="features.md#0x1_features_is_enabled">is_enabled</a>(<a href="features.md#0x1_features_DISPATCHABLE_FUNGIBLE_ASSET">DISPATCHABLE_FUNGIBLE_ASSET</a>)
<b>true</b>
<pre><code><b>public</b> <b>fun</b> <a href="features.md#0x1_features_dispatchable_fungible_asset_enabled">dispatchable_fungible_asset_enabled</a>(): bool <b>acquires</b> <a href="features.md#0x1_features_Features">Features</a> {
<a href="features.md#0x1_features_is_enabled">is_enabled</a>(<a href="features.md#0x1_features_DISPATCHABLE_FUNGIBLE_ASSET">DISPATCHABLE_FUNGIBLE_ASSET</a>)
}
</code></pre>

Expand Down Expand Up @@ -2999,7 +3018,6 @@ Lifetime: transient


<pre><code><b>public</b> <b>fun</b> <a href="features.md#0x1_features_new_accounts_default_to_fa_stc_store_enabled">new_accounts_default_to_fa_stc_store_enabled</a>(): bool <b>acquires</b> <a href="features.md#0x1_features_Features">Features</a> {
// TODO(BobOng): [framework-upgrade] <b>to</b> confirm which feature flag should be used here
<a href="features.md#0x1_features_is_enabled">is_enabled</a>(<a href="features.md#0x1_features_NEW_ACCOUNTS_DEFAULT_TO_FA_STC_STORE">NEW_ACCOUNTS_DEFAULT_TO_FA_STC_STORE</a>)
}
</code></pre>
Expand Down
Loading

0 comments on commit a494851

Please sign in to comment.