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

MintProposalPlugin #105

Merged
merged 6 commits into from
Sep 2, 2022
Merged
Show file tree
Hide file tree
Changes from 4 commits
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
5 changes: 4 additions & 1 deletion build/StarcoinFramework/BuildInfo.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,9 @@ compiled_package_info:
? address: "0x00000000000000000000000000000001"
name: MintDaoProposal
: StarcoinFramework
? address: "0x00000000000000000000000000000001"
name: MintProposalPlugin
: StarcoinFramework
? address: "0x00000000000000000000000000000001"
name: MintScripts
: StarcoinFramework
Expand Down Expand Up @@ -300,7 +303,7 @@ compiled_package_info:
? address: "0x00000000000000000000000000000001"
name: YieldFarmingV2
: StarcoinFramework
source_digest: C3F10D8763E687130581034F694C48F86494655044F4BC0919B011480303FC2C
source_digest: D6ADACD0C31267FF55725214591287FBA47FF16ACC1F489DE83DE749BBE51F11
build_flags:
dev_mode: false
test_mode: false
Expand Down
1 change: 1 addition & 0 deletions build/StarcoinFramework/docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ This is the root document for the Move StarcoinFramework module documentation. T
- [`0x1::MerkleNFTDistributor`](MerkleNFT.md#0x1_MerkleNFTDistributor)
- [`0x1::MerkleProof`](MerkleNFT.md#0x1_MerkleProof)
- [`0x1::MintDaoProposal`](MintDaoProposal.md#0x1_MintDaoProposal)
- [`0x1::MintProposalPlugin`](MintProposalPlugin.md#0x1_MintProposalPlugin)
- [`0x1::MintScripts`](MintScripts.md#0x1_MintScripts)
- [`0x1::ModifyDaoConfigProposal`](ModifyDaoConfigProposal.md#0x1_ModifyDaoConfigProposal)
- [`0x1::ModuleUpgradeScripts`](ModuleUpgradeScripts.md#0x1_ModuleUpgradeScripts)
Expand Down
81 changes: 81 additions & 0 deletions integration-tests/daospaceplugin/mint_proposal_plugin.exp
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
processed 29 tasks

task 8 'run'. lines 71-85:
{
"gas_used": 125922,
"status": "Executed"
}

task 9 'run'. lines 87-96:
{
"gas_used": 1106607,
"status": "Executed"
}

task 10 'run'. lines 98-108:
{
"gas_used": 58629,
"status": "Executed"
}

task 11 'run'. lines 110-123:
{
"gas_used": 8525,
"status": {
"ExecutionFailure": {
"location": {
"Module": {
"address": "0x00000000000000000000000000000001",
"name": "Token"
}
},
"function": 16,
"code_offset": 2
}
}
}

task 12 'run'. lines 125-139:
{
"gas_used": 264852,
"status": "Executed"
}

task 16 'run'. lines 147-158:
{
"gas_used": 101444,
"status": "Executed"
}

task 19 'run'. lines 164-173:
{
"gas_used": 575882,
"status": "Executed"
}

task 20 'run'. lines 175-200:
{
"gas_used": 435676,
"status": "Executed"
}

task 22 'call'. lines 204-204:
"0xa7dcef9aef26202fce82a7c7d6672afb/1/0x00000000000000000000000000000001::IdentifierNFT::IdentifierNFT<0x00000000000000000000000000000001::DAOSpace::DAOMember<0x662ba5a1a1da0f1c70a9762c7eeb7aaf::XDAO::XDAO>,0x00000000000000000000000000000001::DAOSpace::DAOMemberBody<0x662ba5a1a1da0f1c70a9762c7eeb7aaf::XDAO::XDAO>>"

task 24 'run'. lines 208-222:
{
"gas_used": 8799322,
"status": "Executed"
}

task 26 'run'. lines 226-240:
{
"gas_used": 173467,
"status": "Executed"
}

task 28 'run'. lines 244-265:
{
"gas_used": 513530,
"status": "Executed"
}
265 changes: 265 additions & 0 deletions integration-tests/daospaceplugin/mint_proposal_plugin.move
Original file line number Diff line number Diff line change
@@ -0,0 +1,265 @@
//# init -n dev

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

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

//# faucet --addr bob --amount 10000000000

//# faucet --addr cindy --amount 10000000000

//# publish
module creator::XDAO {
use StarcoinFramework::DAOAccount;
use StarcoinFramework::DAOSpace;
use StarcoinFramework::AnyMemberPlugin::{Self, AnyMemberPlugin};
use StarcoinFramework::InstallPluginProposalPlugin::{Self, InstallPluginProposalPlugin};
use StarcoinFramework::MintProposalPlugin::{Self, MintProposalPlugin};
use StarcoinFramework::Option;

struct XDAO 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 dao_signer = DAOAccount::dao_signer(&dao_account_cap);
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<XDAO>(dao_account_cap, *&NAME, Option::none<vector<u8>>(),
Option::none<vector<u8>>(), b"ipfs://description", XDAO{}, config);

DAOSpace::install_plugin_with_root_cap<XDAO, InstallPluginProposalPlugin>(&dao_root_cap, InstallPluginProposalPlugin::required_caps());
DAOSpace::install_plugin_with_root_cap<XDAO, AnyMemberPlugin>(&dao_root_cap, AnyMemberPlugin::required_caps());
DAOSpace::install_plugin_with_root_cap<XDAO, MintProposalPlugin>(&dao_root_cap, MintProposalPlugin::required_caps());

DAOSpace::burn_root_cap(dao_root_cap);

}
}

//# publish
module alice::AliceToken {
use StarcoinFramework::Token;

struct AliceToken has copy, drop, store { }

public fun init(account: &signer) {
Token::register_token<AliceToken>(
account,
3,
);
}
}

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

//# run --signers alice
script {
use alice::AliceToken::{AliceToken, Self};
use StarcoinFramework::Account;
use StarcoinFramework::Token;

fun main(account: signer) {
AliceToken::init(&account);
let market_cap = Token::market_cap<AliceToken>();
assert!(market_cap == 0, 101);
assert!(Token::is_registered_in<AliceToken>(@alice), 102);
Account::do_accept_token<AliceToken>(&account);
}
}
// check: EXECUTED

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

fun main(sender: signer){
// time unit is millsecond
XDAO::create_dao(sender, 10000, 360000, 1, 10000, 0);
}
}
// check: EXECUTED

//# run --signers alice
script {
use alice::AliceToken::AliceToken;
use creator::XDAO::XDAO;
use StarcoinFramework::MintProposalPlugin;

fun main(sender: signer) {
MintProposalPlugin::delegate_token_mint_cap<XDAO, AliceToken>(sender);
}
}
// check: EXECUTED

//# run --signers alice
script {
use alice::AliceToken::AliceToken;
use StarcoinFramework::Account;
use StarcoinFramework::Token;
use StarcoinFramework::Signer;

fun main(sender: signer) {
let token = Token::mint<AliceToken>(&sender, 100000);
let receiver = Signer::address_of(&sender);
Account::deposit<AliceToken>(receiver, token);
}
}
// check: ABORTED, Alice don't have MintCapability

//# run --signers alice
script {
use creator::XDAO::XDAO;
use StarcoinFramework::AnyMemberPlugin;
use StarcoinFramework::IdentifierNFT;
use StarcoinFramework::DAOSpace::{DAOMember, DAOMemberBody};

fun main(sender: signer) {
IdentifierNFT::accept<DAOMember<XDAO>, DAOMemberBody<XDAO>>(&sender);
let image_data = b"image";
let image_url = b"";
AnyMemberPlugin::join<XDAO>(sender, image_data, image_url);
}
}
// check: EXECUTED

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

//# block --author=0x2 --timestamp 86420000

//# call-api chain.info

//# run --signers alice --args {{$.call-api[0].head.parent_hash}}
script {
use StarcoinFramework::Block;

fun checkpoint(_account: signer, parent_hash: vector<u8>) {
let expect_parent_hash = Block::get_parent_hash();
assert!(expect_parent_hash == parent_hash, 103);

Block::checkpoint();
}
}
// check: EXECUTED

//# block --author=0x3 --timestamp 86450000

//# call-api chain.get_block_by_hash ["{{$.call-api[0].head.parent_hash}}",{"raw":true}]

//# run --signers alice --args {{$.call-api[1].raw.header}}

script {
use StarcoinFramework::Block;

fun update(_account: signer, raw_header: vector<u8>) {
Block::update_state_root(raw_header);
}
}
// check: EXECUTED

//# run --signers alice
script {
use alice::AliceToken::AliceToken;
use creator::XDAO::XDAO;
use StarcoinFramework::MintProposalPlugin;

use StarcoinFramework::Debug;
use StarcoinFramework::DAOSpace;

fun main(sender: signer) {
let description = b"mint to bob";
let amount = 100000;
let action_delay = 0;
MintProposalPlugin::create_mint_proposal<XDAO, AliceToken>(
sender, description, @bob, amount, action_delay);
let (_id, proposer, start_time, end_time, _yes_votes, _no_votes, _no_with_veto_votes, _abstain_votes, block_number, state_root) = DAOSpace::proposal_info<XDAO>(1);

Debug::print(&proposer);
Debug::print(&start_time);
Debug::print(&end_time);
Debug::print(&block_number);
Debug::print(&state_root);

}
}
// check: EXECUTED

//# block --author=0x3 --timestamp 86460000

//# call 0x1::SnapshotUtil::get_access_path --type-args {{$.faucet[0].txn.raw_txn.decoded_payload.ScriptFunction.args[0]}}::XDAO::XDAO --args {{$.faucet[1].txn.raw_txn.decoded_payload.ScriptFunction.args[0]}}

//# call-api state.get_with_proof_by_root_raw ["{{$.call[0]}}","{{$.call-api[1].header.state_root}}"]

//# run --signers alice --args {{$.call-api[2]}}
script{
use creator::XDAO::XDAO;
use StarcoinFramework::DAOSpace;

fun cast_vote(sender: signer, snpashot_raw_proofs: vector<u8>){
let proposal_id = 1;
let choice = DAOSpace::choice_yes();
DAOSpace::cast_vote<XDAO>(&sender, proposal_id, snpashot_raw_proofs, choice);

let proposal_state = DAOSpace::proposal_state<XDAO>(1);
assert!(proposal_state == 2, 104); // DAOSpace::ACTIVE
}
}
// check: EXECUTED

//# block --author=0x3 --timestamp 86830000

//# run --signers alice
script{
use creator::XDAO::XDAO;
use StarcoinFramework::DAOSpace;

// execute action
fun queue_proposal_action(sender: signer){
let proposal_id = 1;
let proposal_state = DAOSpace::proposal_state<XDAO>(proposal_id);
assert!(proposal_state == 4, 105); // DAOSpace::AGREED
DAOSpace::do_queue_proposal_action<XDAO>(&sender, proposal_id);

}
}
// check: EXECUTED

//# block --author=0x3 --timestamp 86840000

//# run --signers bob
script {
use creator::XDAO::XDAO;
use alice::AliceToken::AliceToken;
use StarcoinFramework::MintProposalPlugin;
use StarcoinFramework::Account;
use StarcoinFramework::Signer;
use StarcoinFramework::Token;
use StarcoinFramework::DAOSpace;

fun main(sender: signer) {
let proposal_id = 1;
let proposal_state = DAOSpace::proposal_state<XDAO>(proposal_id);
assert!(proposal_state == 6, 106); // DAOSpace::EXECUTABLE

let addr = Signer::address_of(&sender);
MintProposalPlugin::execute_mint_proposal<XDAO, AliceToken>(sender, proposal_id);
let balance = Account::balance<AliceToken>(addr);
assert!(balance == 100000, 107);
assert!(Token::market_cap<AliceToken>() == balance, 108);
}
}
Loading