Skip to content

Commit

Permalink
[compiler-v2 framework] framework testsuite: fixed `dao_upgrade_modul…
Browse files Browse the repository at this point in the history
…e_proposal.move` module test
  • Loading branch information
welbon committed Nov 25, 2024
1 parent 7c2be75 commit 3d425d4
Show file tree
Hide file tree
Showing 9 changed files with 569 additions and 71 deletions.
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 @@ -671,6 +671,7 @@ propose a proposal.
action_delay: u64,
) <b>acquires</b> <a href="dao.md#0x1_dao_DaoGlobalInfo">DaoGlobalInfo</a> {
<a href="../../starcoin-stdlib/doc/debug.md#0x1_debug_print">debug::print</a>(&std::string::utf8(b"dao::proposal | Entered"));
<a href="../../starcoin-stdlib/doc/debug.md#0x1_debug_print">debug::print</a>(&<a href="../../move-stdlib/doc/signer.md#0x1_signer_address_of">signer::address_of</a>(<a href="../../move-stdlib/doc/signer.md#0x1_signer">signer</a>));

<b>if</b> (action_delay == 0) {
action_delay = <a href="dao.md#0x1_dao_min_action_delay">min_action_delay</a>&lt;TokenT&gt;();
Expand Down
329 changes: 329 additions & 0 deletions vm/framework/starcoin-framework/doc/dao_upgrade_module_proposal.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,329 @@

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

# Module `0x1::dao_upgrade_module_proposal`

dao_upgrade_module_proposal is a proposal moudle used to upgrade contract codes under a token.


- [Resource `UpgradeModuleCapability`](#0x1_dao_upgrade_module_proposal_UpgradeModuleCapability)
- [Struct `UpgradeModuleV2`](#0x1_dao_upgrade_module_proposal_UpgradeModuleV2)
- [Constants](#@Constants_0)
- [Function `plugin`](#0x1_dao_upgrade_module_proposal_plugin)
- [Function `propose_module_upgrade_v2`](#0x1_dao_upgrade_module_proposal_propose_module_upgrade_v2)
- [Function `submit_module_upgrade_plan`](#0x1_dao_upgrade_module_proposal_submit_module_upgrade_plan)
- [Specification](#@Specification_1)
- [Function `plugin`](#@Specification_1_plugin)
- [Function `propose_module_upgrade_v2`](#@Specification_1_propose_module_upgrade_v2)
- [Function `submit_module_upgrade_plan`](#@Specification_1_submit_module_upgrade_plan)


<pre><code><b>use</b> <a href="dao.md#0x1_dao">0x1::dao</a>;
<b>use</b> <a href="../../move-stdlib/doc/error.md#0x1_error">0x1::error</a>;
<b>use</b> <a href="../../move-stdlib/doc/signer.md#0x1_signer">0x1::signer</a>;
<b>use</b> <a href="stc_transaction_package_validation.md#0x1_stc_transaction_package_validation">0x1::stc_transaction_package_validation</a>;
<b>use</b> <a href="stc_util.md#0x1_stc_util">0x1::stc_util</a>;
</code></pre>



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

## Resource `UpgradeModuleCapability`

A wrapper of <code><a href="stc_transaction_package_validation.md#0x1_stc_transaction_package_validation_UpgradePlanCapability">stc_transaction_package_validation::UpgradePlanCapability</a></code>.


<pre><code><b>struct</b> <a href="dao_upgrade_module_proposal.md#0x1_dao_upgrade_module_proposal_UpgradeModuleCapability">UpgradeModuleCapability</a>&lt;TokenT&gt; <b>has</b> key
</code></pre>



<details>
<summary>Fields</summary>


<dl>
<dt>
<code>cap: <a href="stc_transaction_package_validation.md#0x1_stc_transaction_package_validation_UpgradePlanCapability">stc_transaction_package_validation::UpgradePlanCapability</a></code>
</dt>
<dd>

</dd>
</dl>


</details>

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

## Struct `UpgradeModuleV2`



<pre><code><b>struct</b> <a href="dao_upgrade_module_proposal.md#0x1_dao_upgrade_module_proposal_UpgradeModuleV2">UpgradeModuleV2</a> <b>has</b> <b>copy</b>, drop, store
</code></pre>



<details>
<summary>Fields</summary>


<dl>
<dt>
<code>module_address: <b>address</b></code>
</dt>
<dd>

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

</dd>
<dt>
<code><a href="version.md#0x1_version">version</a>: u64</code>
</dt>
<dd>

</dd>
<dt>
<code>enforced: bool</code>
</dt>
<dd>

</dd>
</dl>


</details>

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

## Constants


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



<pre><code><b>const</b> <a href="dao_upgrade_module_proposal.md#0x1_dao_upgrade_module_proposal_ERR_NOT_AUTHORIZED">ERR_NOT_AUTHORIZED</a>: u64 = 401;
</code></pre>



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



<pre><code><b>const</b> <a href="dao_upgrade_module_proposal.md#0x1_dao_upgrade_module_proposal_ERR_ADDRESS_MISSMATCH">ERR_ADDRESS_MISSMATCH</a>: u64 = 402;
</code></pre>



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



<pre><code><b>const</b> <a href="dao_upgrade_module_proposal.md#0x1_dao_upgrade_module_proposal_ERR_UNABLE_TO_UPGRADE">ERR_UNABLE_TO_UPGRADE</a>: u64 = 400;
</code></pre>



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

## Function `plugin`

If this goverment can upgrade module, call this to register capability.


<pre><code><b>public</b> <b>fun</b> <a href="dao_upgrade_module_proposal.md#0x1_dao_upgrade_module_proposal_plugin">plugin</a>&lt;TokenT&gt;(<a href="../../move-stdlib/doc/signer.md#0x1_signer">signer</a>: &<a href="../../move-stdlib/doc/signer.md#0x1_signer">signer</a>, cap: <a href="stc_transaction_package_validation.md#0x1_stc_transaction_package_validation_UpgradePlanCapability">stc_transaction_package_validation::UpgradePlanCapability</a>)
</code></pre>



<details>
<summary>Implementation</summary>


<pre><code><b>public</b> <b>fun</b> <a href="dao_upgrade_module_proposal.md#0x1_dao_upgrade_module_proposal_plugin">plugin</a>&lt;TokenT&gt;(
<a href="../../move-stdlib/doc/signer.md#0x1_signer">signer</a>: &<a href="../../move-stdlib/doc/signer.md#0x1_signer">signer</a>,
cap: <a href="stc_transaction_package_validation.md#0x1_stc_transaction_package_validation_UpgradePlanCapability">stc_transaction_package_validation::UpgradePlanCapability</a>,
) {
<b>let</b> token_issuer = <a href="stc_util.md#0x1_stc_util_token_issuer">stc_util::token_issuer</a>&lt;TokenT&gt;();
<b>assert</b>!(<a href="../../move-stdlib/doc/signer.md#0x1_signer_address_of">signer::address_of</a>(<a href="../../move-stdlib/doc/signer.md#0x1_signer">signer</a>) == token_issuer, <a href="../../move-stdlib/doc/error.md#0x1_error_unauthenticated">error::unauthenticated</a>(<a href="dao_upgrade_module_proposal.md#0x1_dao_upgrade_module_proposal_ERR_NOT_AUTHORIZED">ERR_NOT_AUTHORIZED</a>));
<b>move_to</b>(<a href="../../move-stdlib/doc/signer.md#0x1_signer">signer</a>, <a href="dao_upgrade_module_proposal.md#0x1_dao_upgrade_module_proposal_UpgradeModuleCapability">UpgradeModuleCapability</a>&lt;TokenT&gt; { cap })
}
</code></pre>



</details>

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

## Function `propose_module_upgrade_v2`



<pre><code><b>public</b> <b>fun</b> <a href="dao_upgrade_module_proposal.md#0x1_dao_upgrade_module_proposal_propose_module_upgrade_v2">propose_module_upgrade_v2</a>&lt;TokenT&gt;(<a href="../../move-stdlib/doc/signer.md#0x1_signer">signer</a>: &<a href="../../move-stdlib/doc/signer.md#0x1_signer">signer</a>, module_address: <b>address</b>, package_hash: <a href="../../move-stdlib/doc/vector.md#0x1_vector">vector</a>&lt;u8&gt;, <a href="version.md#0x1_version">version</a>: u64, exec_delay: u64, enforced: bool)
</code></pre>



<details>
<summary>Implementation</summary>


<pre><code><b>public</b> <b>fun</b> <a href="dao_upgrade_module_proposal.md#0x1_dao_upgrade_module_proposal_propose_module_upgrade_v2">propose_module_upgrade_v2</a>&lt;TokenT&gt;(
<a href="../../move-stdlib/doc/signer.md#0x1_signer">signer</a>: &<a href="../../move-stdlib/doc/signer.md#0x1_signer">signer</a>,
module_address: <b>address</b>,
package_hash: <a href="../../move-stdlib/doc/vector.md#0x1_vector">vector</a>&lt;u8&gt;,
<a href="version.md#0x1_version">version</a>: u64,
exec_delay: u64,
enforced: bool,
) <b>acquires</b> <a href="dao_upgrade_module_proposal.md#0x1_dao_upgrade_module_proposal_UpgradeModuleCapability">UpgradeModuleCapability</a> {
<b>let</b> cap = <b>borrow_global</b>&lt;<a href="dao_upgrade_module_proposal.md#0x1_dao_upgrade_module_proposal_UpgradeModuleCapability">UpgradeModuleCapability</a>&lt;TokenT&gt;&gt;(<a href="stc_util.md#0x1_stc_util_token_issuer">stc_util::token_issuer</a>&lt;TokenT&gt;());
<b>let</b> account_address = <a href="stc_transaction_package_validation.md#0x1_stc_transaction_package_validation_account_address">stc_transaction_package_validation::account_address</a>(&cap.cap);
<b>assert</b>!(account_address == module_address, <a href="../../move-stdlib/doc/error.md#0x1_error_permission_denied">error::permission_denied</a>(<a href="dao_upgrade_module_proposal.md#0x1_dao_upgrade_module_proposal_ERR_ADDRESS_MISSMATCH">ERR_ADDRESS_MISSMATCH</a>));
<a href="dao.md#0x1_dao_propose">dao::propose</a>&lt;TokenT, <a href="dao_upgrade_module_proposal.md#0x1_dao_upgrade_module_proposal_UpgradeModuleV2">UpgradeModuleV2</a>&gt;(
<a href="../../move-stdlib/doc/signer.md#0x1_signer">signer</a>,
<a href="dao_upgrade_module_proposal.md#0x1_dao_upgrade_module_proposal_UpgradeModuleV2">UpgradeModuleV2</a> { module_address, package_hash, <a href="version.md#0x1_version">version</a>, enforced },
exec_delay,
);
}
</code></pre>



</details>

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

## Function `submit_module_upgrade_plan`

Once the proposal is agreed, anyone can call this method to generate the upgrading plan.


<pre><code><b>public</b> <b>fun</b> <a href="dao_upgrade_module_proposal.md#0x1_dao_upgrade_module_proposal_submit_module_upgrade_plan">submit_module_upgrade_plan</a>&lt;TokenT&gt;(proposer_address: <b>address</b>, proposal_id: u64)
</code></pre>



<details>
<summary>Implementation</summary>


<pre><code><b>public</b> <b>fun</b> <a href="dao_upgrade_module_proposal.md#0x1_dao_upgrade_module_proposal_submit_module_upgrade_plan">submit_module_upgrade_plan</a>&lt;TokenT&gt;(
proposer_address: <b>address</b>,
proposal_id: u64,
) <b>acquires</b> <a href="dao_upgrade_module_proposal.md#0x1_dao_upgrade_module_proposal_UpgradeModuleCapability">UpgradeModuleCapability</a> {
<b>let</b> <a href="dao_upgrade_module_proposal.md#0x1_dao_upgrade_module_proposal_UpgradeModuleV2">UpgradeModuleV2</a> {
module_address, package_hash, <a href="version.md#0x1_version">version</a>, enforced
} = <a href="dao.md#0x1_dao_extract_proposal_action">dao::extract_proposal_action</a>&lt;
TokenT,
<a href="dao_upgrade_module_proposal.md#0x1_dao_upgrade_module_proposal_UpgradeModuleV2">UpgradeModuleV2</a>,
&gt;(proposer_address, proposal_id);
<b>let</b> cap = <b>borrow_global</b>&lt;<a href="dao_upgrade_module_proposal.md#0x1_dao_upgrade_module_proposal_UpgradeModuleCapability">UpgradeModuleCapability</a>&lt;TokenT&gt;&gt;(<a href="stc_util.md#0x1_stc_util_token_issuer">stc_util::token_issuer</a>&lt;TokenT&gt;());
<b>let</b> account_address = <a href="stc_transaction_package_validation.md#0x1_stc_transaction_package_validation_account_address">stc_transaction_package_validation::account_address</a>(&cap.cap);
<b>assert</b>!(account_address == module_address, <a href="../../move-stdlib/doc/error.md#0x1_error_permission_denied">error::permission_denied</a>(<a href="dao_upgrade_module_proposal.md#0x1_dao_upgrade_module_proposal_ERR_ADDRESS_MISSMATCH">ERR_ADDRESS_MISSMATCH</a>));
<a href="stc_transaction_package_validation.md#0x1_stc_transaction_package_validation_submit_upgrade_plan_with_cap_v2">stc_transaction_package_validation::submit_upgrade_plan_with_cap_v2</a>(
&cap.cap,
package_hash,
<a href="version.md#0x1_version">version</a>,
enforced,
);
}
</code></pre>



</details>

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

## Specification



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



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

### Function `plugin`


<pre><code><b>public</b> <b>fun</b> <a href="dao_upgrade_module_proposal.md#0x1_dao_upgrade_module_proposal_plugin">plugin</a>&lt;TokenT&gt;(<a href="../../move-stdlib/doc/signer.md#0x1_signer">signer</a>: &<a href="../../move-stdlib/doc/signer.md#0x1_signer">signer</a>, cap: <a href="stc_transaction_package_validation.md#0x1_stc_transaction_package_validation_UpgradePlanCapability">stc_transaction_package_validation::UpgradePlanCapability</a>)
</code></pre>




<pre><code><b>pragma</b> aborts_if_is_partial = <b>false</b>;
<b>let</b> sender = <a href="../../move-stdlib/doc/signer.md#0x1_signer_address_of">signer::address_of</a>(<a href="../../move-stdlib/doc/signer.md#0x1_signer">signer</a>);
<b>aborts_if</b> sender != @0x2;
<b>aborts_if</b> <b>exists</b>&lt;<a href="dao_upgrade_module_proposal.md#0x1_dao_upgrade_module_proposal_UpgradeModuleCapability">UpgradeModuleCapability</a>&lt;TokenT&gt;&gt;(sender);
</code></pre>




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


<pre><code><b>schema</b> <a href="dao_upgrade_module_proposal.md#0x1_dao_upgrade_module_proposal_AbortIfUnableUpgrade">AbortIfUnableUpgrade</a>&lt;TokenT&gt; {
module_address: <b>address</b>;
<b>let</b> token_issuer = @0x2;
<b>aborts_if</b> !<b>exists</b>&lt;<a href="dao_upgrade_module_proposal.md#0x1_dao_upgrade_module_proposal_UpgradeModuleCapability">UpgradeModuleCapability</a>&lt;TokenT&gt;&gt;(token_issuer);
<b>let</b> cap = <b>global</b>&lt;<a href="dao_upgrade_module_proposal.md#0x1_dao_upgrade_module_proposal_UpgradeModuleCapability">UpgradeModuleCapability</a>&lt;TokenT&gt;&gt;(token_issuer).cap;
<b>aborts_if</b> <a href="stc_transaction_package_validation.md#0x1_stc_transaction_package_validation_account_address">stc_transaction_package_validation::account_address</a>(cap) != module_address;
}
</code></pre>



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

### Function `propose_module_upgrade_v2`


<pre><code><b>public</b> <b>fun</b> <a href="dao_upgrade_module_proposal.md#0x1_dao_upgrade_module_proposal_propose_module_upgrade_v2">propose_module_upgrade_v2</a>&lt;TokenT&gt;(<a href="../../move-stdlib/doc/signer.md#0x1_signer">signer</a>: &<a href="../../move-stdlib/doc/signer.md#0x1_signer">signer</a>, module_address: <b>address</b>, package_hash: <a href="../../move-stdlib/doc/vector.md#0x1_vector">vector</a>&lt;u8&gt;, <a href="version.md#0x1_version">version</a>: u64, exec_delay: u64, enforced: bool)
</code></pre>




<pre><code><b>pragma</b> aborts_if_is_partial = <b>true</b>;
<b>include</b> <a href="dao_upgrade_module_proposal.md#0x1_dao_upgrade_module_proposal_AbortIfUnableUpgrade">AbortIfUnableUpgrade</a>&lt;TokenT&gt;;
</code></pre>



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

### Function `submit_module_upgrade_plan`


<pre><code><b>public</b> <b>fun</b> <a href="dao_upgrade_module_proposal.md#0x1_dao_upgrade_module_proposal_submit_module_upgrade_plan">submit_module_upgrade_plan</a>&lt;TokenT&gt;(proposer_address: <b>address</b>, proposal_id: u64)
</code></pre>




<pre><code><b>let</b> expected_states = vec&lt;u8&gt;(6);
<b>include</b> <a href="dao.md#0x1_dao_CheckProposalStates">dao::CheckProposalStates</a>&lt;TokenT, <a href="dao_upgrade_module_proposal.md#0x1_dao_upgrade_module_proposal_UpgradeModuleV2">UpgradeModuleV2</a>&gt; { expected_states };
<b>let</b> proposal = <b>global</b>&lt;<a href="dao.md#0x1_dao_Proposal">dao::Proposal</a>&lt;TokenT, <a href="dao_upgrade_module_proposal.md#0x1_dao_upgrade_module_proposal_UpgradeModuleV2">UpgradeModuleV2</a>&gt;&gt;(proposer_address);
<b>aborts_if</b> <a href="../../move-stdlib/doc/option.md#0x1_option_is_none">option::is_none</a>(proposal.action);
<b>let</b> action = proposal.action.vec[0];
<b>include</b> <a href="dao_upgrade_module_proposal.md#0x1_dao_upgrade_module_proposal_AbortIfUnableUpgrade">AbortIfUnableUpgrade</a>&lt;TokenT&gt; { module_address: action.module_address };
</code></pre>


[move-book]: https://starcoin.dev/move/book/SUMMARY
1 change: 1 addition & 0 deletions vm/framework/starcoin-framework/doc/overview.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ This is the reference documentation of the Starcoin framework.
- [`0x1::dao`](dao.md#0x1_dao)
- [`0x1::dao_modify_config_proposal`](dao_modify_config_proposal.md#0x1_dao_modify_config_proposal)
- [`0x1::dao_treasury_withdraw_proposal`](dao_treasury_withdraw_proposal.md#0x1_dao_treasury_withdraw_proposal)
- [`0x1::dao_upgrade_module_proposal`](dao_upgrade_module_proposal.md#0x1_dao_upgrade_module_proposal)
- [`0x1::dao_vote_scripts`](dao_vote_scripts.md#0x1_dao_vote_scripts)
- [`0x1::delegation_pool`](delegation_pool.md#0x1_delegation_pool)
- [`0x1::dispatchable_fungible_asset`](dispatchable_fungible_asset.md#0x1_dispatchable_fungible_asset)
Expand Down
10 changes: 4 additions & 6 deletions vm/framework/starcoin-framework/doc/stc_block.md
Original file line number Diff line number Diff line change
Expand Up @@ -331,9 +331,8 @@ Get the hash of the parents block, used for DAG
<summary>Implementation</summary>


<pre><code><b>public</b> <b>fun</b> <a href="stc_block.md#0x1_stc_block_get_parents_hash">get_parents_hash</a>(): <a href="../../move-stdlib/doc/vector.md#0x1_vector">vector</a>&lt;u8&gt; {
// *&<b>borrow_global</b>&lt;<a href="stc_block.md#0x1_stc_block_BlockMetadata">BlockMetadata</a>&gt;(<a href="system_addresses.md#0x1_system_addresses_get_starcoin_framework">system_addresses::get_starcoin_framework</a>()).parent_hash
<a href="../../move-stdlib/doc/vector.md#0x1_vector_empty">vector::empty</a>()
<pre><code><b>public</b> <b>fun</b> <a href="stc_block.md#0x1_stc_block_get_parents_hash">get_parents_hash</a>(): <a href="../../move-stdlib/doc/vector.md#0x1_vector">vector</a>&lt;u8&gt; <b>acquires</b> <a href="stc_block.md#0x1_stc_block_BlockMetadata">BlockMetadata</a> {
*&<b>borrow_global</b>&lt;<a href="stc_block.md#0x1_stc_block_BlockMetadata">BlockMetadata</a>&gt;(<a href="system_addresses.md#0x1_system_addresses_get_starcoin_framework">system_addresses::get_starcoin_framework</a>()).parents_hash
}
</code></pre>

Expand All @@ -357,9 +356,8 @@ Gets the address of the author of the current block
<summary>Implementation</summary>


<pre><code><b>public</b> <b>fun</b> <a href="stc_block.md#0x1_stc_block_get_current_author">get_current_author</a>(): <b>address</b> {
// <b>borrow_global</b>&lt;<a href="stc_block.md#0x1_stc_block_BlockMetadata">BlockMetadata</a>&gt;(<a href="system_addresses.md#0x1_system_addresses_get_starcoin_framework">system_addresses::get_starcoin_framework</a>()).author
@0x1
<pre><code><b>public</b> <b>fun</b> <a href="stc_block.md#0x1_stc_block_get_current_author">get_current_author</a>(): <b>address</b> <b>acquires</b> <a href="stc_block.md#0x1_stc_block_BlockMetadata">BlockMetadata</a> {
<b>borrow_global</b>&lt;<a href="stc_block.md#0x1_stc_block_BlockMetadata">BlockMetadata</a>&gt;(<a href="system_addresses.md#0x1_system_addresses_get_starcoin_framework">system_addresses::get_starcoin_framework</a>()).author
}
</code></pre>

Expand Down
Loading

0 comments on commit 3d425d4

Please sign in to comment.