Skip to content

Commit

Permalink
[Feature] DAO incompatible module upgrade test (#133)
Browse files Browse the repository at this point in the history
* #130 add dao upgrade incompatible module

* modify the deploy order
  • Loading branch information
WGB5445 authored Sep 19, 2022
1 parent c8c9ba7 commit 022ca1a
Show file tree
Hide file tree
Showing 2 changed files with 234 additions and 0 deletions.
46 changes: 46 additions & 0 deletions integration-tests/daospace/dao_upgrade_incompatible.exp
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
processed 19 tasks

task 3 'run'. lines 7-15:
{
"gas_used": 6483371,
"status": "Executed"
}

task 5 'run'. lines 97-105:
{
"gas_used": 522882,
"status": "Executed"
}

task 9 'run'. lines 121-136:
{
"gas_used": 173698,
"status": "Executed"
}

task 10 'run'. lines 138-147:
{
"gas_used": 1047820,
"status": "Executed"
}

task 12 'run'. lines 151-159:
{
"gas_used": 110070,
"status": "Executed"
}

task 14 'deploy'. lines 163-164:
Publish failure: MiscellaneousError

task 15 'run'. lines 166-174:
{
"gas_used": 110070,
"status": "Executed"
}

task 18 'run'. lines 180-188:
{
"gas_used": 11346,
"status": "Executed"
}
188 changes: 188 additions & 0 deletions integration-tests/daospace/dao_upgrade_incompatible.move
Original file line number Diff line number Diff line change
@@ -0,0 +1,188 @@
//# init -n dev

//# faucet --addr creator --amount 100000000000

//# faucet --addr alice --amount 10000000000

//# run --signers creator
script {
use StarcoinFramework::StdlibUpgradeScripts;

fun upgrade_from_v11_to_v12() {
StdlibUpgradeScripts::upgrade_from_v12_to_v12_1();
}
}
// check: EXECUTED

//# publish
module creator::DAOHelper {
use StarcoinFramework::DAOPluginMarketplace;
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 initialize_x_plugin(sender: &signer) {
DAOPluginMarketplace::register_plugin<XPlugin>(
sender,
b"0x1::XPlugin",
b"The X plugin.",
Option::none(),
);

let implement_extpoints = Vector::empty<vector<u8>>();
let depend_extpoints = Vector::empty<vector<u8>>();

let witness = XPlugin{};
DAOPluginMarketplace::publish_plugin_version<XPlugin>(
sender,
&witness,
b"v0.1.0",
*&implement_extpoints,
*&depend_extpoints,
b"inner-plugin://x-plugin",
);
}

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);
}
}

//# run --signers creator
script {
use creator::DAOHelper;

fun main(sender: signer) {
DAOHelper::initialize_x_plugin(&sender);
}
}
// check: EXECUTED

//# package
module creator::test {
public fun hello() {}
}

//# package
module creator::test {
public fun hello(_i: u8) {}

public fun world(_i: u8) {}
}

//# deploy {{$.package[0].file}}

//# 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);
}
}
//check: EXECUTED

//# 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

//# 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);
}
}
//check: EXECUTED

//# block --author 0x1 --timestamp 86600000

//# deploy {{$.package[1].file}} --signers alice
//check: Publish failure: MiscellaneousError

//# 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, true);
}
}
//check: EXECUTED

//# block --author 0x1 --timestamp 86700000

//# deploy {{$.package[1].file}} --signers alice

//# run --signers alice
script {
use creator::test;

fun main(_sender: signer) {
test::world(1);
}
}
//check: EXECUTED

0 comments on commit 022ca1a

Please sign in to comment.