Skip to content

Commit

Permalink
Dao account test (#53)
Browse files Browse the repository at this point in the history
* Update DaoAccount and write integration test

* update build

* update CI for genesis_dao branch
  • Loading branch information
jolestar committed Jul 5, 2022
1 parent e3306a6 commit fdddff4
Show file tree
Hide file tree
Showing 13 changed files with 403 additions and 132 deletions.
1 change: 1 addition & 0 deletions .github/workflows/build_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ on:
pull_request:
branches:
- main
- genesis_dao

jobs:
build-and-test:
Expand Down
8 changes: 7 additions & 1 deletion build/StarcoinFramework/BuildInfo.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ compiled_package_info:
? address: "0x00000000000000000000000000000001"
name: Config
: StarcoinFramework
? address: "0x00000000000000000000000000000001"
name: ConfigProposalPlugin
: StarcoinFramework
? address: "0x00000000000000000000000000000001"
name: ConsensusConfig
: StarcoinFramework
Expand Down Expand Up @@ -207,6 +210,9 @@ compiled_package_info:
? address: "0x00000000000000000000000000000001"
name: STCUSDOracle
: StarcoinFramework
? address: "0x00000000000000000000000000000001"
name: SalaryGovPlugin
: StarcoinFramework
? address: "0x00000000000000000000000000000001"
name: SharedEd25519PublicKey
: StarcoinFramework
Expand Down Expand Up @@ -291,7 +297,7 @@ compiled_package_info:
? address: "0x00000000000000000000000000000001"
name: YieldFarmingV2
: StarcoinFramework
source_digest: 37973FE3F7BCD58FFE2521CE3319C0ED239522F2B0DDE5A5F32751C9C324DFF2
source_digest: 7F51997501DC9F3AFC1EA8C06C8025E33EA666DF2E3F15C374AF7C7555F061D5
build_flags:
dev_mode: false
test_mode: false
Expand Down
Binary file modified build/StarcoinFramework/bytecode_modules/DaoAccount.mv
Binary file not shown.
Binary file modified build/StarcoinFramework/bytecode_modules/GenesisDao.mv
Binary file not shown.
100 changes: 80 additions & 20 deletions build/StarcoinFramework/docs/DaoAccount.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,22 @@
- [Function `create_account`](#0x1_DaoAccount_create_account)
- [Function `create_account_entry`](#0x1_DaoAccount_create_account_entry)
- [Function `extract_dao_account_cap`](#0x1_DaoAccount_extract_dao_account_cap)
- [Function `restore_dao_account_cap`](#0x1_DaoAccount_restore_dao_account_cap)
- [Function `upgrade_to_dao`](#0x1_DaoAccount_upgrade_to_dao)
- [Function `upgrade_to_dao_with_signer_cap`](#0x1_DaoAccount_upgrade_to_dao_with_signer_cap)
- [Function `dao_signer`](#0x1_DaoAccount_dao_signer)
- [Function `submit_upgrade_plan`](#0x1_DaoAccount_submit_upgrade_plan)
- [Function `submit_upgrade_plan_entry`](#0x1_DaoAccount_submit_upgrade_plan_entry)
- [Module Specification](#@Module_Specification_1)


<pre><code><b>use</b> <a href="Account.md#0x1_Account">0x1::Account</a>;
<b>use</b> <a href="Config.md#0x1_Config">0x1::Config</a>;
<b>use</b> <a href="Errors.md#0x1_Errors">0x1::Errors</a>;
<b>use</b> <a href="Option.md#0x1_Option">0x1::Option</a>;
<b>use</b> <a href="PackageTxnManager.md#0x1_PackageTxnManager">0x1::PackageTxnManager</a>;
<b>use</b> <a href="Signer.md#0x1_Signer">0x1::Signer</a>;
<b>use</b> <a href="Version.md#0x1_Version">0x1::Version</a>;
</code></pre>


Expand Down Expand Up @@ -55,6 +59,12 @@ DaoAccount
</dt>
<dd>

</dd>
<dt>
<code>upgrade_plan_cap: <a href="PackageTxnManager.md#0x1_PackageTxnManager_UpgradePlanCapability">PackageTxnManager::UpgradePlanCapability</a></code>
</dt>
<dd>

</dd>
</dl>

Expand Down Expand Up @@ -121,17 +131,8 @@ Dao Account is a delegate account, the <code>creator</code> has the <code><a hre


<pre><code><b>public</b> <b>fun</b> <a href="DaoAccount.md#0x1_DaoAccount_create_account">create_account</a>(creator: &signer): <a href="DaoAccount.md#0x1_DaoAccount_DaoAccountCap">DaoAccountCap</a> {
<b>let</b> (dao_address, signer_cap) = <a href="Account.md#0x1_Account_create_delegate_account">Account::create_delegate_account</a>(creator);
<b>let</b> dao_signer = <a href="Account.md#0x1_Account_create_signer_with_cap">Account::create_signer_with_cap</a>(&signer_cap);

<a href="PackageTxnManager.md#0x1_PackageTxnManager_update_module_upgrade_strategy">PackageTxnManager::update_module_upgrade_strategy</a>(&dao_signer, <a href="PackageTxnManager.md#0x1_PackageTxnManager_get_strategy_two_phase">PackageTxnManager::get_strategy_two_phase</a>(), <a href="Option.md#0x1_Option_some">Option::some</a>(0));
<b>move_to</b>(&dao_signer, <a href="DaoAccount.md#0x1_DaoAccount">DaoAccount</a>{
dao_address,
signer_cap: signer_cap,
});
<a href="DaoAccount.md#0x1_DaoAccount_DaoAccountCap">DaoAccountCap</a>{
dao_address
}
<b>let</b> (_dao_address, signer_cap) = <a href="Account.md#0x1_Account_create_delegate_account">Account::create_delegate_account</a>(creator);
<a href="DaoAccount.md#0x1_DaoAccount_upgrade_to_dao_with_signer_cap">upgrade_to_dao_with_signer_cap</a>(signer_cap)
}
</code></pre>

Expand Down Expand Up @@ -169,6 +170,7 @@ Entry function for create dao account, the <code><a href="DaoAccount.md#0x1_DaoA

## Function `extract_dao_account_cap`

Extract the DaoAccountCap from the <code>sender</code>


<pre><code><b>public</b> <b>fun</b> <a href="DaoAccount.md#0x1_DaoAccount_extract_dao_account_cap">extract_dao_account_cap</a>(sender: &signer): <a href="DaoAccount.md#0x1_DaoAccount_DaoAccountCap">DaoAccount::DaoAccountCap</a>
Expand All @@ -189,6 +191,31 @@ Entry function for create dao account, the <code><a href="DaoAccount.md#0x1_DaoA



</details>

<a name="0x1_DaoAccount_restore_dao_account_cap"></a>

## Function `restore_dao_account_cap`

Restore the DaoAccountCap to the <code>sender</code>


<pre><code><b>public</b> <b>fun</b> <a href="DaoAccount.md#0x1_DaoAccount_restore_dao_account_cap">restore_dao_account_cap</a>(sender: &signer, cap: <a href="DaoAccount.md#0x1_DaoAccount_DaoAccountCap">DaoAccount::DaoAccountCap</a>)
</code></pre>



<details>
<summary>Implementation</summary>


<pre><code><b>public</b> <b>fun</b> <a href="DaoAccount.md#0x1_DaoAccount_restore_dao_account_cap">restore_dao_account_cap</a>(sender: &signer, cap: <a href="DaoAccount.md#0x1_DaoAccount_DaoAccountCap">DaoAccountCap</a>) {
<b>move_to</b>(sender, cap)
}
</code></pre>



</details>

<a name="0x1_DaoAccount_upgrade_to_dao"></a>
Expand All @@ -208,16 +235,49 @@ Upgrade <code>sender</code> account to Dao account


<pre><code><b>public</b> <b>fun</b> <a href="DaoAccount.md#0x1_DaoAccount_upgrade_to_dao">upgrade_to_dao</a>(sender: signer): <a href="DaoAccount.md#0x1_DaoAccount_DaoAccountCap">DaoAccountCap</a> {
//TODO <b>assert</b> sender not <a href="Dao.md#0x1_Dao">Dao</a>
<b>let</b> signer_cap = <a href="Account.md#0x1_Account_remove_signer_capability">Account::remove_signer_capability</a>(&sender);
//TODO check the account upgrade_strategy
<a href="PackageTxnManager.md#0x1_PackageTxnManager_update_module_upgrade_strategy">PackageTxnManager::update_module_upgrade_strategy</a>(&sender, <a href="PackageTxnManager.md#0x1_PackageTxnManager_get_strategy_two_phase">PackageTxnManager::get_strategy_two_phase</a>(), <a href="Option.md#0x1_Option_some">Option::some</a>(0));
<b>let</b> dao_address = <a href="Signer.md#0x1_Signer_address_of">Signer::address_of</a>(&sender);
<b>move_to</b>(&sender, <a href="DaoAccount.md#0x1_DaoAccount">DaoAccount</a>{
<a href="DaoAccount.md#0x1_DaoAccount_upgrade_to_dao_with_signer_cap">upgrade_to_dao_with_signer_cap</a>(signer_cap)
}
</code></pre>



</details>

<a name="0x1_DaoAccount_upgrade_to_dao_with_signer_cap"></a>

## Function `upgrade_to_dao_with_signer_cap`

Upgrade the account which have the <code>signer_cap</code> to a Dao Account


<pre><code><b>public</b> <b>fun</b> <a href="DaoAccount.md#0x1_DaoAccount_upgrade_to_dao_with_signer_cap">upgrade_to_dao_with_signer_cap</a>(signer_cap: <a href="Account.md#0x1_Account_SignerCapability">Account::SignerCapability</a>): <a href="DaoAccount.md#0x1_DaoAccount_DaoAccountCap">DaoAccount::DaoAccountCap</a>
</code></pre>



<details>
<summary>Implementation</summary>


<pre><code><b>public</b> <b>fun</b> <a href="DaoAccount.md#0x1_DaoAccount_upgrade_to_dao_with_signer_cap">upgrade_to_dao_with_signer_cap</a>(signer_cap: SignerCapability): <a href="DaoAccount.md#0x1_DaoAccount_DaoAccountCap">DaoAccountCap</a> {
<b>let</b> dao_signer = <a href="Account.md#0x1_Account_create_signer_with_cap">Account::create_signer_with_cap</a>(&signer_cap);
<b>let</b> dao_address = <a href="Signer.md#0x1_Signer_address_of">Signer::address_of</a>(&dao_signer);

<b>let</b> upgrade_plan_cap = <b>if</b>(<a href="Config.md#0x1_Config_config_exist_by_address">Config::config_exist_by_address</a>&lt;<a href="Version.md#0x1_Version_Version">Version::Version</a>&gt;(dao_address)){
//TODO <b>if</b> the account <b>has</b> extract the upgrade plan cap
<a href="PackageTxnManager.md#0x1_PackageTxnManager_extract_submit_upgrade_plan_cap">PackageTxnManager::extract_submit_upgrade_plan_cap</a>(&dao_signer)
}<b>else</b>{
<a href="Config.md#0x1_Config_publish_new_config">Config::publish_new_config</a>&lt;<a href="Version.md#0x1_Version_Version">Version::Version</a>&gt;(&dao_signer, <a href="Version.md#0x1_Version_new_version">Version::new_version</a>(1));
<a href="PackageTxnManager.md#0x1_PackageTxnManager_update_module_upgrade_strategy">PackageTxnManager::update_module_upgrade_strategy</a>(&dao_signer, <a href="PackageTxnManager.md#0x1_PackageTxnManager_get_strategy_two_phase">PackageTxnManager::get_strategy_two_phase</a>(), <a href="Option.md#0x1_Option_some">Option::some</a>(1));
<a href="PackageTxnManager.md#0x1_PackageTxnManager_extract_submit_upgrade_plan_cap">PackageTxnManager::extract_submit_upgrade_plan_cap</a>(&dao_signer)
};
<b>move_to</b>(&dao_signer, <a href="DaoAccount.md#0x1_DaoAccount">DaoAccount</a>{
dao_address,
signer_cap: signer_cap,
signer_cap,
upgrade_plan_cap,
});
<a href="DaoAccount.md#0x1_DaoAccount_DaoAccountCap">DaoAccountCap</a>{
<a href="DaoAccount.md#0x1_DaoAccount_DaoAccountCap">DaoAccountCap</a>{
dao_address
}
}
Expand Down Expand Up @@ -271,8 +331,8 @@ This function is a shortcut for create signer with DaoAccountCap and invoke <cod


<pre><code><b>public</b> <b>fun</b> <a href="DaoAccount.md#0x1_DaoAccount_submit_upgrade_plan">submit_upgrade_plan</a>(cap: &<a href="DaoAccount.md#0x1_DaoAccount_DaoAccountCap">DaoAccountCap</a>, package_hash: vector&lt;u8&gt;, version:u64, enforced: bool) <b>acquires</b> <a href="DaoAccount.md#0x1_DaoAccount">DaoAccount</a>{
<b>let</b> dao_signer = <a href="DaoAccount.md#0x1_DaoAccount_dao_signer">dao_signer</a>(cap);
<a href="PackageTxnManager.md#0x1_PackageTxnManager_submit_upgrade_plan_v2">PackageTxnManager::submit_upgrade_plan_v2</a>(&dao_signer, package_hash, version, enforced);
<b>let</b> upgrade_plan_cap = &<b>borrow_global</b>&lt;<a href="DaoAccount.md#0x1_DaoAccount">DaoAccount</a>&gt;(cap.dao_address).upgrade_plan_cap;
<a href="PackageTxnManager.md#0x1_PackageTxnManager_submit_upgrade_plan_with_cap_v2">PackageTxnManager::submit_upgrade_plan_with_cap_v2</a>(upgrade_plan_cap, package_hash, version, enforced);
}
</code></pre>

Expand Down
Loading

0 comments on commit fdddff4

Please sign in to comment.