-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add daospace module upgrade test (#98)
- Loading branch information
Showing
2 changed files
with
171 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
processed 16 tasks | ||
|
||
task 7 'run'. lines 78-85: | ||
{ | ||
"gas_used": 600, | ||
"status": "MiscellaneousError" | ||
} | ||
|
||
task 8 'run'. lines 87-101: | ||
{ | ||
"gas_used": 173698, | ||
"status": "Executed" | ||
} | ||
|
||
task 9 'run'. lines 102-111: | ||
{ | ||
"gas_used": 991772, | ||
"status": "Executed" | ||
} | ||
|
||
task 10 'deploy'. lines 113-113: | ||
Publish failure: Discard { status_code: StrView(2015), status_code_name: "UNEXPECTED_ERROR_FROM_KNOWN_MOVE_FUNCTION" } | ||
|
||
task 12 'run'. lines 117-124: | ||
{ | ||
"gas_used": 110070, | ||
"status": "Executed" | ||
} | ||
|
||
task 15 'run'. lines 130-137: | ||
{ | ||
"gas_used": 11344, | ||
"status": "Executed" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,137 @@ | ||
//# init -n dev | ||
|
||
//# faucet --addr creator --amount 100000000000 | ||
|
||
//# faucet --addr alice --amount 10000000000 | ||
|
||
//# publish | ||
module creator::DAOHelper { | ||
use StarcoinFramework::DAOAccount; | ||
use StarcoinFramework::DAOSpace::{Self, CapType}; | ||
use StarcoinFramework::AnyMemberPlugin::{Self, AnyMemberPlugin}; | ||
use StarcoinFramework::InstallPluginProposalPlugin::{Self, InstallPluginProposalPlugin}; | ||
use StarcoinFramework::Vector; | ||
use StarcoinFramework::Option; | ||
|
||
struct X has store, copy, drop {} | ||
|
||
const NAME: vector<u8> = b"X"; | ||
|
||
/// directly upgrade the sender account to DAOAccount and create DAO | ||
public(script) fun create_dao( | ||
sender: signer, | ||
voting_delay: u64, | ||
voting_period: u64, | ||
voting_quorum_rate: u8, | ||
min_action_delay: u64, | ||
min_proposal_deposit: u128, ) { | ||
let dao_account_cap = DAOAccount::upgrade_to_dao(sender); | ||
|
||
let config = DAOSpace::new_dao_config( | ||
voting_delay, | ||
voting_period, | ||
voting_quorum_rate, | ||
min_action_delay, | ||
min_proposal_deposit, | ||
); | ||
let dao_root_cap = DAOSpace::create_dao<X>(dao_account_cap, *&NAME, Option::none<vector<u8>>(), Option::none<vector<u8>>(), b"ipfs://description", X {}, config); | ||
|
||
DAOSpace::install_plugin_with_root_cap<X, InstallPluginProposalPlugin>(&dao_root_cap, InstallPluginProposalPlugin::required_caps()); | ||
DAOSpace::install_plugin_with_root_cap<X, AnyMemberPlugin>(&dao_root_cap, AnyMemberPlugin::required_caps()); | ||
|
||
DAOSpace::install_plugin_with_root_cap<X, XPlugin>(&dao_root_cap, required_caps()); | ||
|
||
DAOSpace::burn_root_cap(dao_root_cap); | ||
} | ||
|
||
struct XPlugin has store, drop {} | ||
|
||
public fun required_caps(): vector<CapType> { | ||
let caps = Vector::singleton(DAOSpace::proposal_cap_type()); | ||
Vector::push_back(&mut caps, DAOSpace::install_plugin_cap_type()); | ||
Vector::push_back(&mut caps, DAOSpace::member_cap_type()); | ||
Vector::push_back(&mut caps, DAOSpace::upgrade_module_cap_type()); | ||
caps | ||
} | ||
|
||
public fun submit_upgrade_plan(package_hash: vector<u8>, version: u64, enforced: bool) { | ||
let witness = XPlugin {}; | ||
let upgrade_cap = DAOSpace::acquire_upgrade_module_cap<X, XPlugin>(&witness); | ||
DAOSpace::submit_upgrade_plan(&upgrade_cap, package_hash, version, enforced); | ||
} | ||
} | ||
|
||
//# package | ||
module creator::test { | ||
public fun hello() {} | ||
} | ||
|
||
//# package | ||
module creator::test { | ||
public fun hello() {} | ||
|
||
public fun world() {} | ||
} | ||
|
||
//# deploy {{$.package[0].file}} | ||
|
||
//# run --signers alice | ||
script { | ||
use creator::test; | ||
|
||
fun main(_sender: signer) { | ||
test::world(); | ||
} | ||
} | ||
|
||
//# run --signers creator | ||
script { | ||
use StarcoinFramework::Config; | ||
use StarcoinFramework::PackageTxnManager; | ||
use StarcoinFramework::Version; | ||
use StarcoinFramework::Option; | ||
use StarcoinFramework::Signer; | ||
|
||
fun main(account: signer) { | ||
Config::publish_new_config<Version::Version>(&account, Version::new_version(1)); | ||
PackageTxnManager::update_module_upgrade_strategy(&account, PackageTxnManager::get_strategy_two_phase(), Option::some<u64>(1)); | ||
let strategy = PackageTxnManager::get_module_upgrade_strategy(Signer::address_of(&account)); | ||
assert!(strategy == PackageTxnManager::get_strategy_two_phase(), 1001); | ||
} | ||
} | ||
//# run --signers creator | ||
script { | ||
use creator::DAOHelper; | ||
|
||
fun main(sender: signer) { | ||
// time unit is millsecond | ||
DAOHelper::create_dao(sender, 10000, 3600000, 2, 10000, 10); | ||
} | ||
} | ||
// check: EXECUTED | ||
|
||
//# deploy {{$.package[1].file}} --signers alice | ||
|
||
//# block --author 0x1 --timestamp 86400000 | ||
|
||
//# run --signers alice --args {{$.package[1].package_hash}} | ||
script { | ||
use creator::DAOHelper; | ||
|
||
fun main(_sender: signer, package_hash: vector<u8>) { | ||
DAOHelper::submit_upgrade_plan(package_hash, 2, false); | ||
} | ||
} | ||
|
||
//# block --author 0x1 --timestamp 86500000 | ||
|
||
//# deploy {{$.package[1].file}} --signers alice | ||
|
||
//# run --signers alice | ||
script { | ||
use creator::test; | ||
|
||
fun main(_sender: signer) { | ||
test::world(); | ||
} | ||
} |