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

[Feature] DAO incompatible module upgrade test #133

Merged
merged 3 commits into from
Sep 19, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
52 changes: 52 additions & 0 deletions integration-tests/daospace/dao_upgrade_incompatible.exp
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
processed 18 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-128:
Error: error[E04016]: too few arguments
┌─ /tmp/.tmpfbNNCj:125:9
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

测试里报错,文件名不一样

┌─ /tmp/.tmpfbNNCj:125:9
┌─ /tmp/.tmpJmKxUw:125:9

125 │ test::world();
│ ^^^^^^^^^^^^^
│ │ │
│ │ Found 0 argument(s) here
│ Invalid call of 'creator::test::world'. The call expected 1 argument(s) but got 0



task 10 'run'. lines 130-144:
{
"gas_used": 173698,
"status": "Executed"
}

task 11 'run'. lines 145-154:
{
"gas_used": 1047820,
"status": "Executed"
}

task 12 'deploy'. lines 156-156:
Publish failure: Discard { status_code: StrView(2015), status_code_name: "UNEXPECTED_ERROR_FROM_KNOWN_MOVE_FUNCTION" }

task 14 'run'. lines 160-167:
{
"gas_used": 110070,
"status": "Executed"
}

task 17 'run'. lines 173-180:
{
"gas_used": 11346,
"status": "Executed"
}
180 changes: 180 additions & 0 deletions integration-tests/daospace/dao_upgrade_incompatible.move
Original file line number Diff line number Diff line change
@@ -0,0 +1,180 @@
//# 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 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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里都没有先提交 upgrade plan,所以执行失败是升级策略检查失败,并不是不兼容导致的失败。感觉可以先提交 plan,但不是强制升级,然后失败。后面再强制升级。


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

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

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

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

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