Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix dao in testsuite #4298

Merged
merged 2 commits into from
Nov 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
90 changes: 45 additions & 45 deletions testsuite/features/cmd.feature
Original file line number Diff line number Diff line change
Expand Up @@ -198,51 +198,51 @@ Feature: cmd integration test
# | |
#
#flexidagconfig dao testing
# Scenario Outline: [cmd] starcoin flexidagconfig dao
# # 1. deposit to default account which is a proposer
# Then cmd: "dev get-coin -v 1000000"
# Then cmd: "account unlock"
# # 2. create FlexiDagConfig proposal with proposer account
# Then cmd: "account execute-function --function 0x1::OnChainConfigScripts::propose_update_flexi_dag_effective_height -s {{$.account[0].ok.address}} --arg 10000u64 --arg 0u64 -b"
# Then cmd: "dev sleep -t 60000"
# # 3. make sure proposal has been ACTIVE for voting
# Then cmd: "dev gen-block"
# Then cmd: "dev call --function 0x1::Dao::proposal_state -t 0x1::STC::STC -t 0x1::OnChainConfigDao::OnChainConfigUpdate<0x1::FlexiDagConfig::FlexiDagConfig> --arg {{$.account[0].ok.address}} --arg 0"
# Then assert: "{{$.dev[-1].ok[0]}} == 2"
# # 4. create a new account to vote, deposit enough tokens
# Then cmd: "account create -p 1234"
# Then cmd: "dev get-coin -v 10000000 {{$.account[2].ok.address}}"
# Then cmd: "dev get-coin -v 10000000 {{$.account[2].ok.address}}"
# Then cmd: "account unlock {{$.account[2].ok.address}} -p 1234"
# # 5. stake and cast vote with new account
# Then cmd: "account execute-function --function 0x1::DaoVoteScripts::cast_vote -t 0x1::STC::STC -t 0x1::OnChainConfigDao::OnChainConfigUpdate<0x1::FlexiDagConfig::FlexiDagConfig> -s {{$.account[2].ok.address}} --arg {{$.account[0].ok.address}} --arg 0 --arg true --arg 12740545600000000u128 -b"
# Then cmd: "dev sleep -t 3600000"
# # 6. switch to proposer account, make sure proposal has been AGREED
# Then cmd: "account unlock"
# Then cmd: "dev gen-block"
# Then cmd: "dev call --function 0x1::Dao::proposal_state -t 0x1::STC::STC -t 0x1::OnChainConfigDao::OnChainConfigUpdate<0x1::FlexiDagConfig::FlexiDagConfig> --arg {{$.account[0].ok.address}} --arg 0"
# Then assert: "{{$.dev[-1].ok[0]}} == 4"
# # 7. add proposal to execution queue with proposer account
# Then cmd: "account execute-function -s {{$.account[0].ok.address}} --function 0x1::Dao::queue_proposal_action -t 0x1::STC::STC -t 0x1::OnChainConfigDao::OnChainConfigUpdate<0x1::FlexiDagConfig::FlexiDagConfig> --arg {{$.account[0].ok.address}} --arg 0 -b"
# Then cmd: "dev sleep -t 3600000"
# # 8. make sure proposal is EXECUTABLE
# Then cmd: "dev gen-block"
# Then cmd: "dev call --function 0x1::Dao::proposal_state -t 0x1::STC::STC -t 0x1::OnChainConfigDao::OnChainConfigUpdate<0x1::FlexiDagConfig::FlexiDagConfig> --arg {{$.account[0].ok.address}} --arg 0"
# Then assert: "{{$.dev[-1].ok[0]}} == 6"
# # 9. execute proposal with proposer account
# Then cmd: "account execute-function -s {{$.account[0].ok.address}} --function 0x1::OnChainConfigScripts::execute_on_chain_config_proposal -t 0x1::FlexiDagConfig::FlexiDagConfig --arg 0 -b"
# # 10. make sure the proposal is EXTRACTED
# Then cmd: "dev gen-block"
# Then cmd: "dev call --function 0x1::Dao::proposal_state -t 0x1::STC::STC -t 0x1::OnChainConfigDao::OnChainConfigUpdate<0x1::FlexiDagConfig::FlexiDagConfig> --arg {{$.account[0].ok.address}} --arg 0"
# Then assert: "{{$.dev[-1].ok[0]}} == 7"
# # 11. clean up proposal
# Then cmd: "account execute-function --function 0x1::Dao::destroy_terminated_proposal -t 0x1::STC::STC -t 0x1::OnChainConfigDao::OnChainConfigUpdate<0x1::FlexiDagConfig::FlexiDagConfig> --arg {{$.account[0].ok.address}} --arg 0u64"
# # 12. check the latest flexidagconfig
# Then cmd: "state get resource 0x1 0x1::Config::Config<0x01::FlexiDagConfig::FlexiDagConfig>"
# Then assert: "{{$.state[0].ok.json.payload.effective_height}} == 10000"
#
# Examples:
# | | |
Scenario Outline: [cmd] starcoin flexidagconfig dao
# 1. deposit to default account which is a proposer
Then cmd: "dev get-coin -v 1000000"
Then cmd: "account unlock"
# 2. create FlexiDagConfig proposal with proposer account
Then cmd: "account execute-function --function 0x1::on_chain_config_scripts::propose_update_flexi_dag_effective_height -s {{$.account[0].ok.address}} --arg 10000u64 --arg 0u64 -b"
Then cmd: "dev sleep -t 60000"
# 3. make sure proposal has been ACTIVE for voting
Then cmd: "dev gen-block"
Then cmd: "dev call --function 0x1::dao::proposal_state -t 0x1::starcoin_coin::STC -t 0x1::on_chain_config_dao::OnChainConfigUpdate<0x1::flexi_dag_config::FlexiDagConfig> --arg {{$.account[0].ok.address}} --arg 0"
Then assert: "{{$.dev[-1].ok[0]}} == 2"
# 4. create a new account to vote, deposit enough tokens
Then cmd: "account create -p 1234"
Then cmd: "dev get-coin -v 10000000 {{$.account[2].ok.address}}"
Then cmd: "dev get-coin -v 10000000 {{$.account[2].ok.address}}"
Then cmd: "account unlock {{$.account[2].ok.address}} -p 1234"
# 5. stake and cast vote with new account
Then cmd: "account execute-function --function 0x1::dao_vote_scripts::cast_vote -t 0x1::starcoin_coin::STC -t 0x1::on_chain_config_dao::OnChainConfigUpdate<0x1::flexi_dag_config::FlexiDagConfig> -s {{$.account[2].ok.address}} --arg {{$.account[0].ok.address}} --arg 0 --arg true --arg 12740545600000000u128 -b"
Then cmd: "dev sleep -t 3600000"
# 6. switch to proposer account, make sure proposal has been AGREED
Then cmd: "account unlock"
Then cmd: "dev gen-block"
Then cmd: "dev call --function 0x1::dao::proposal_state -t 0x1::starcoin_coin::STC -t 0x1::on_chain_config_dao::OnChainConfigUpdate<0x1::flexi_dag_config::FlexiDagConfig> --arg {{$.account[0].ok.address}} --arg 0"
Then assert: "{{$.dev[-1].ok[0]}} == 4"
# 7. add proposal to execution queue with proposer account
Then cmd: "account execute-function -s {{$.account[0].ok.address}} --function 0x1::dao::queue_proposal_action -t 0x1::starcoin_coin::STC -t 0x1::on_chain_config_dao::OnChainConfigUpdate<0x1::flexi_dag_config::FlexiDagConfig> --arg {{$.account[0].ok.address}} --arg 0 -b"
Then cmd: "dev sleep -t 3600000"
# 8. make sure proposal is EXECUTABLE
Then cmd: "dev gen-block"
Then cmd: "dev call --function 0x1::dao::proposal_state -t 0x1::starcoin_coin::STC -t 0x1::on_chain_config_dao::OnChainConfigUpdate<0x1::flexi_dag_config::FlexiDagConfig> --arg {{$.account[0].ok.address}} --arg 0"
Then assert: "{{$.dev[-1].ok[0]}} == 6"
# 9. execute proposal with proposer account
Then cmd: "account execute-function -s {{$.account[0].ok.address}} --function 0x1::on_chain_config_scripts::execute_on_chain_config_proposal -t 0x1::flexi_dag_config::FlexiDagConfig --arg 0 -b"
# 10. make sure the proposal is EXTRACTED
Then cmd: "dev gen-block"
Then cmd: "dev call --function 0x1::dao::proposal_state -t 0x1::starcoin_coin::STC -t 0x1::on_chain_config_dao::OnChainConfigUpdate<0x1::flexi_dag_config::FlexiDagConfig> --arg {{$.account[0].ok.address}} --arg 0"
Then assert: "{{$.dev[-1].ok[0]}} == 7"
# 11. clean up proposal
Then cmd: "account execute-function --function 0x1::dao::destroy_terminated_proposal -t 0x1::starcoin_coin::STC -t 0x1::on_chain_config_dao::OnChainConfigUpdate<0x1::flexi_dag_config::FlexiDagConfig> --arg {{$.account[0].ok.address}} --arg 0u64"
# 12. check the latest flexidagconfig
Then cmd: "state get resource 0x1 0x1::on_chain_config::Config<0x01::flexi_dag_config::FlexiDagConfig>"
Then assert: "{{$.state[0].ok.json.payload.effective_height}} == 10000"

Examples:
| | |

# #easy gas testing
# Scenario Outline: starcoin easy gas test
Expand Down
87 changes: 81 additions & 6 deletions vm/framework/cached-packages/src/starcoin_framework_sdk_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -396,6 +396,8 @@ pub enum EntryFunctionCall {
amount: u128,
},

EmptyScriptsEmptyScript {},

/// Withdraw an `amount` of coin `CoinType` from `account` and burn it.
ManagedCoinBurn {
coin_type: TypeTag,
Expand Down Expand Up @@ -673,6 +675,11 @@ pub enum EntryFunctionCall {
exec_delay: u64,
},

OnChainConfigScriptsProposeUpdateFlexiDagEffectiveHeight {
new_height: u64,
exec_delay: u64,
},

OnChainConfigScriptsProposeUpdateMoveLanguageVersion {
new_version: u64,
exec_delay: u64,
Expand Down Expand Up @@ -1118,7 +1125,7 @@ pub enum EntryFunctionCall {
voting_quorum_rate: u8,
min_action_delay: u64,
transaction_timeout: u64,
_dag_effective_height: u64,
dag_effective_height: u64,
},

TransactionFeeConvertToStarcoinFaBurnRef {},
Expand Down Expand Up @@ -1510,6 +1517,7 @@ impl EntryFunctionCall {
EasyGasScriptWithdrawGasFeeEntry { token_type, amount } => {
easy_gas_script_withdraw_gas_fee_entry(token_type, amount)
}
EmptyScriptsEmptyScript {} => empty_scripts_empty_script(),
ManagedCoinBurn { coin_type, amount } => managed_coin_burn(coin_type, amount),
ManagedCoinInitialize {
coin_type,
Expand Down Expand Up @@ -1721,6 +1729,12 @@ impl EntryFunctionCall {
strategy,
exec_delay,
),
OnChainConfigScriptsProposeUpdateFlexiDagEffectiveHeight {
new_height,
exec_delay,
} => on_chain_config_scripts_propose_update_flexi_dag_effective_height(
new_height, exec_delay,
),
OnChainConfigScriptsProposeUpdateMoveLanguageVersion {
new_version,
exec_delay,
Expand Down Expand Up @@ -2024,7 +2038,7 @@ impl EntryFunctionCall {
voting_quorum_rate,
min_action_delay,
transaction_timeout,
_dag_effective_height,
dag_effective_height,
} => stc_genesis_initialize(
stdlib_version,
reward_delay,
Expand Down Expand Up @@ -2056,7 +2070,7 @@ impl EntryFunctionCall {
voting_quorum_rate,
min_action_delay,
transaction_timeout,
_dag_effective_height,
dag_effective_height,
),
TransactionFeeConvertToStarcoinFaBurnRef {} => {
transaction_fee_convert_to_starcoin_fa_burn_ref()
Expand Down Expand Up @@ -3040,6 +3054,18 @@ pub fn easy_gas_script_withdraw_gas_fee_entry(
))
}

pub fn empty_scripts_empty_script() -> 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!("empty_scripts").to_owned(),
),
ident_str!("empty_script").to_owned(),
vec![],
vec![],
))
}

/// Withdraw an `amount` of coin `CoinType` from `account` and burn it.
pub fn managed_coin_burn(coin_type: TypeTag, amount: u64) -> TransactionPayload {
TransactionPayload::EntryFunction(EntryFunction::new(
Expand Down Expand Up @@ -3734,6 +3760,24 @@ pub fn on_chain_config_scripts_propose_update_consensus_config(
))
}

pub fn on_chain_config_scripts_propose_update_flexi_dag_effective_height(
new_height: 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!("on_chain_config_scripts").to_owned(),
),
ident_str!("propose_update_flexi_dag_effective_height").to_owned(),
vec![],
vec![
bcs::to_bytes(&new_height).unwrap(),
bcs::to_bytes(&exec_delay).unwrap(),
],
))
}

pub fn on_chain_config_scripts_propose_update_move_language_version(
new_version: u64,
exec_delay: u64,
Expand Down Expand Up @@ -4900,7 +4944,7 @@ pub fn stc_genesis_initialize(
voting_quorum_rate: u8,
min_action_delay: u64,
transaction_timeout: u64,
_dag_effective_height: u64,
dag_effective_height: u64,
) -> TransactionPayload {
TransactionPayload::EntryFunction(EntryFunction::new(
ModuleId::new(
Expand Down Expand Up @@ -4940,7 +4984,7 @@ pub fn stc_genesis_initialize(
bcs::to_bytes(&voting_quorum_rate).unwrap(),
bcs::to_bytes(&min_action_delay).unwrap(),
bcs::to_bytes(&transaction_timeout).unwrap(),
bcs::to_bytes(&_dag_effective_height).unwrap(),
bcs::to_bytes(&dag_effective_height).unwrap(),
],
))
}
Expand Down Expand Up @@ -5952,6 +5996,14 @@ mod decoder {
}
}

pub fn empty_scripts_empty_script(payload: &TransactionPayload) -> Option<EntryFunctionCall> {
if let TransactionPayload::EntryFunction(_script) = payload {
Some(EntryFunctionCall::EmptyScriptsEmptyScript {})
} else {
None
}
}

pub fn managed_coin_burn(payload: &TransactionPayload) -> Option<EntryFunctionCall> {
if let TransactionPayload::EntryFunction(script) = payload {
Some(EntryFunctionCall::ManagedCoinBurn {
Expand Down Expand Up @@ -6416,6 +6468,21 @@ mod decoder {
}
}

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

pub fn on_chain_config_scripts_propose_update_move_language_version(
payload: &TransactionPayload,
) -> Option<EntryFunctionCall> {
Expand Down Expand Up @@ -7256,7 +7323,7 @@ mod decoder {
voting_quorum_rate: bcs::from_bytes(script.args().get(27)?).ok()?,
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()?,
dag_effective_height: bcs::from_bytes(script.args().get(30)?).ok()?,
})
} else {
None
Expand Down Expand Up @@ -7753,6 +7820,10 @@ static SCRIPT_FUNCTION_DECODER_MAP: once_cell::sync::Lazy<EntryFunctionDecoderMa
"easy_gas_script_withdraw_gas_fee_entry".to_string(),
Box::new(decoder::easy_gas_script_withdraw_gas_fee_entry),
);
map.insert(
"empty_scripts_empty_script".to_string(),
Box::new(decoder::empty_scripts_empty_script),
);
map.insert(
"managed_coin_burn".to_string(),
Box::new(decoder::managed_coin_burn),
Expand Down Expand Up @@ -7885,6 +7956,10 @@ static SCRIPT_FUNCTION_DECODER_MAP: once_cell::sync::Lazy<EntryFunctionDecoderMa
"on_chain_config_scripts_propose_update_consensus_config".to_string(),
Box::new(decoder::on_chain_config_scripts_propose_update_consensus_config),
);
map.insert(
"on_chain_config_scripts_propose_update_flexi_dag_effective_height".to_string(),
Box::new(decoder::on_chain_config_scripts_propose_update_flexi_dag_effective_height),
);
map.insert(
"on_chain_config_scripts_propose_update_move_language_version".to_string(),
Box::new(decoder::on_chain_config_scripts_propose_update_move_language_version),
Expand Down
1 change: 1 addition & 0 deletions vm/framework/starcoin-framework/doc/dao.md
Original file line number Diff line number Diff line change
Expand Up @@ -1119,6 +1119,7 @@ extract proposal action to execute.
proposer_address: <b>address</b>,
proposal_id: u64,
): ActionT <b>acquires</b> <a href="dao.md#0x1_dao_Proposal">Proposal</a> {
<a href="../../starcoin-stdlib/doc/debug.md#0x1_debug_print">debug::print</a>(&std::string::utf8(b"<a href="dao.md#0x1_dao_extract_proposal_action">dao::extract_proposal_action</a> | Entered"));
// Only executable proposal's action can be extracted.
<b>assert</b>!(
<a href="dao.md#0x1_dao_proposal_state">proposal_state</a>&lt;TokenT, ActionT&gt;(proposer_address, proposal_id) == <a href="dao.md#0x1_dao_EXECUTABLE">EXECUTABLE</a>,
Expand Down
50 changes: 50 additions & 0 deletions vm/framework/starcoin-framework/doc/empty_scripts.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@

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

# Module `0x1::empty_scripts`



- [Function `empty_script`](#0x1_empty_scripts_empty_script)
- [Specification](#@Specification_0)


<pre><code></code></pre>



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

## Function `empty_script`



<pre><code><b>public</b> entry <b>fun</b> <a href="empty_scripts.md#0x1_empty_scripts_empty_script">empty_script</a>()
</code></pre>



<details>
<summary>Implementation</summary>


<pre><code><b>public</b> entry <b>fun</b> <a href="empty_scripts.md#0x1_empty_scripts_empty_script">empty_script</a>() {}
</code></pre>



</details>

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

## Specification



<pre><code><b>pragma</b> verify = <b>false</b>;
<b>pragma</b> aborts_if_is_partial = <b>false</b>;
<b>pragma</b> aborts_if_is_strict = <b>false</b>;
</code></pre>


[move-book]: https://starcoin.dev/move/book/SUMMARY
Loading
Loading