Skip to content

Commit

Permalink
Fix (#189)
Browse files Browse the repository at this point in the history
  • Loading branch information
WGB5445 authored Oct 24, 2022
1 parent cb21b0a commit 64d754d
Show file tree
Hide file tree
Showing 9 changed files with 299 additions and 5 deletions.
Binary file modified build/StarcoinFramework/bytecode_modules/MemberProposalPlugin.mv
Binary file not shown.
12 changes: 11 additions & 1 deletion build/StarcoinFramework/docs/MemberProposalPlugin.md
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,17 @@
<b>let</b> proposal_cap = <a href="DAOSpace.md#0x1_DAOSpace_acquire_proposal_cap">DAOSpace::acquire_proposal_cap</a>&lt;DAOT, <a href="MemberProposalPlugin.md#0x1_MemberProposalPlugin">MemberProposalPlugin</a>&gt;(&witness);
<b>let</b> <a href="MemberProposalPlugin.md#0x1_MemberProposalPlugin_MemberJoinAction">MemberJoinAction</a>{member, init_sbt, image_data, image_url} = <a href="DAOSpace.md#0x1_DAOSpace_execute_proposal">DAOSpace::execute_proposal</a>&lt;DAOT, <a href="MemberProposalPlugin.md#0x1_MemberProposalPlugin">MemberProposalPlugin</a>, <a href="MemberProposalPlugin.md#0x1_MemberProposalPlugin_MemberJoinAction">MemberJoinAction</a>&gt;(&proposal_cap, sender, proposal_id);
<b>let</b> member_cap = <a href="DAOSpace.md#0x1_DAOSpace_acquire_member_cap">DAOSpace::acquire_member_cap</a>&lt;DAOT, <a href="MemberProposalPlugin.md#0x1_MemberProposalPlugin">MemberProposalPlugin</a>&gt;(&witness);
<a href="DAOSpace.md#0x1_DAOSpace_member_offer">DAOSpace::member_offer</a>(&member_cap, member, <a href="Option.md#0x1_Option_some">Option::some</a>(image_data), <a href="Option.md#0x1_Option_some">Option::some</a>(image_url) , init_sbt);
<b>let</b> op_image_data = <b>if</b>(<a href="Vector.md#0x1_Vector_length">Vector::length</a>(&image_data) == 0){
<a href="Option.md#0x1_Option_none">Option::none</a>&lt;vector&lt;u8&gt;&gt;()
}<b>else</b>{
<a href="Option.md#0x1_Option_some">Option::some</a>(image_data)
};
<b>let</b> op_image_url = <b>if</b>(<a href="Vector.md#0x1_Vector_length">Vector::length</a>(&image_url) == 0){
<a href="Option.md#0x1_Option_none">Option::none</a>&lt;vector&lt;u8&gt;&gt;()
}<b>else</b>{
<a href="Option.md#0x1_Option_some">Option::some</a>(image_url)
};
<a href="DAOSpace.md#0x1_DAOSpace_member_offer">DAOSpace::member_offer</a>(&member_cap, member,op_image_data , op_image_url , init_sbt);
}
</code></pre>

Expand Down
Binary file modified build/StarcoinFramework/source_maps/MemberProposalPlugin.mvsm
Binary file not shown.
58 changes: 58 additions & 0 deletions integration-tests/daospace/dao_member_proposal.exp
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
processed 29 tasks

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

task 10 'run'. lines 84-91:
{
"gas_used": 378392,
"status": "Executed"
}

task 15 'run'. lines 100-114:
{
"gas_used": 104830,
"status": "Executed"
}

task 17 'run'. lines 118-129:
{
"gas_used": 577624,
"status": "Executed"
}

task 18 'run'. lines 131-140:
{
"gas_used": 505220,
"status": "Executed"
}

task 21 'call'. lines 146-146:
"0xa7dcef9aef26202fce82a7c7d6672afb/1/0x00000000000000000000000000000001::IdentifierNFT::IdentifierNFT<0x00000000000000000000000000000001::DAOSpace::DAOMember<0x662ba5a1a1da0f1c70a9762c7eeb7aaf::DAOHelper::X>,0x00000000000000000000000000000001::DAOSpace::DAOMemberBody<0x662ba5a1a1da0f1c70a9762c7eeb7aaf::DAOHelper::X>>"

task 23 'run'. lines 150-164:
{
"gas_used": 6238590,
"status": "Executed"
}

task 25 'run'. lines 168-178:
{
"gas_used": 109761,
"status": "Executed"
}

task 27 'run'. lines 182-192:
{
"gas_used": 455258,
"status": "Executed"
}

task 28 'run'. lines 194-206:
{
"gas_used": 424219,
"status": "Executed"
}
206 changes: 206 additions & 0 deletions integration-tests/daospace/dao_member_proposal.move
Original file line number Diff line number Diff line change
@@ -0,0 +1,206 @@
//# init -n dev

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

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

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

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

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

//# publish
module creator::DAOHelper {
use StarcoinFramework::DAOAccount;
use StarcoinFramework::DAOSpace::{Self};
use StarcoinFramework::Option;
use StarcoinFramework::InstallPluginProposalPlugin::InstallPluginProposalPlugin;
use StarcoinFramework::AnyMemberPlugin::AnyMemberPlugin;
use StarcoinFramework::AnyMemberPlugin;
use StarcoinFramework::InstallPluginProposalPlugin;
use StarcoinFramework::MemberProposalPlugin;
use StarcoinFramework::MemberProposalPlugin::MemberProposalPlugin;

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, MemberProposalPlugin>(&dao_root_cap, MemberProposalPlugin::required_caps());

DAOSpace::burn_root_cap(dao_root_cap);

}

public fun create_offer_proposal(sender: &signer, title:vector<u8>, introduction:vector<u8>, description: vector<u8>, member: address, image_data:vector<u8>, image_url:vector<u8>, init_sbt: u128, action_delay: u64){
MemberProposalPlugin::create_proposal<X>(sender, title, introduction, description, member, image_data, image_url,init_sbt, action_delay);
}

public fun execute_offer_proposal(sender: &signer, proposal_id: u64){
MemberProposalPlugin::execute_proposal<X>(sender, proposal_id);
}

public fun add_member(sender: &signer, image_data:vector<u8>, image_url:vector<u8>){
AnyMemberPlugin::join<X>(sender, image_data, image_url);
}
}

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

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

//# run --signers alice
script {
use creator::DAOHelper::{Self};
fun add_member(sender: signer){
DAOHelper::add_member(&sender, b"",b"ipfs://");
}

}
//# block --author 0x1 --timestamp 86400020

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

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

//# call-api chain.info

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

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

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

//# 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;
use StarcoinFramework::Debug;

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

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

//alice create grant to alice
fun create_offer_proposal(sender: signer){
DAOHelper::create_offer_proposal(&sender, b"Add member",b"Add bob to DAO", b"ipfs://",@bob,b"",b"ipfs://",1, 10000);
}
}
// check: EXECUTED

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

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

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

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

//# run --signers alice --args {{$.call-api[3]}}
script{
use creator::DAOHelper::{X};
use StarcoinFramework::DAOSpace;
use StarcoinFramework::Debug;

// alice vote
fun cast_vote(sender: signer, snpashot_raw_proofs: vector<u8>){
let choice = DAOSpace::choice_yes();
Debug::print(&choice);

DAOSpace::cast_vote<X>(&sender, 1, snpashot_raw_proofs, choice);
}
}
// check: EXECUTED

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

//# run --signers bob
script{
use creator::DAOHelper::{X};
use StarcoinFramework::DAOSpace;

// execute action
fun queue_proposal_action(_sender: signer){
DAOSpace::queue_proposal_action<X>(1);
}
}
// check: EXECUTED

//# block --author 0x4 --timestamp 90022000

//# run --signers alice
script{
use creator::DAOHelper::{X};
use StarcoinFramework::MemberProposalPlugin;

// execute action
fun execute_action(sender: signer){
MemberProposalPlugin::execute_proposal<X>(&sender,1);
}
}
// check: EXECUTED

//# run --signers bob
script{
use creator::DAOHelper::{X};
use StarcoinFramework::DAOSpace;
use StarcoinFramework::IdentifierNFT;

// execute action
fun join(sender: signer){
IdentifierNFT::accept<DAOSpace::DAOMember<X>,DAOSpace::DAOMemberBody<X>>(&sender);
DAOSpace::join_member_entry<X>(sender);
}
}
// check: EXECUTED
2 changes: 1 addition & 1 deletion integration-tests/daospaceplugin/gas_oracle_plugin.exp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ task 7 'run'. lines 87-96:

task 9 'run'. lines 100-114:
{
"gas_used": 373579,
"gas_used": 377540,
"status": "Executed"
}

Expand Down
2 changes: 1 addition & 1 deletion integration-tests/daospaceplugin/mint_proposal_plugin.exp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ task 11 'run'. lines 110-123:

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

Expand Down
12 changes: 11 additions & 1 deletion sources/daospaceplugin/AnyMemberPlugin.move
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,17 @@ module StarcoinFramework::AnyMemberPlugin{
let witness = AnyMemberPlugin{};
let member_cap = DAOSpace::acquire_member_cap<DAOT, AnyMemberPlugin>(&witness);
IdentifierNFT::accept<DAOSpace::DAOMember<DAOT>,DAOSpace::DAOMemberBody<DAOT>>(sender);
DAOSpace::join_member_with_member_cap(&member_cap, Signer::address_of(sender), Option::some(image_data), Option::some(image_url), 1);
let op_image_data = if(Vector::is_empty(&image_data)){
Option::none<vector<u8>>()
}else{
Option::some(image_data)
};
let op_image_url = if(Vector::is_empty(&image_url)){
Option::none<vector<u8>>()
}else{
Option::some(image_url)
};
DAOSpace::join_member_with_member_cap(&member_cap, Signer::address_of(sender), op_image_data, op_image_url, 1);
}

public (script) fun join_entry<DAOT: store>(sender: signer, image_data:vector<u8>, image_url:vector<u8>){
Expand Down
12 changes: 11 additions & 1 deletion sources/daospaceplugin/MemberProposalPlugin.move
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,17 @@ module StarcoinFramework::MemberProposalPlugin{
let proposal_cap = DAOSpace::acquire_proposal_cap<DAOT, MemberProposalPlugin>(&witness);
let MemberJoinAction{member, init_sbt, image_data, image_url} = DAOSpace::execute_proposal<DAOT, MemberProposalPlugin, MemberJoinAction>(&proposal_cap, sender, proposal_id);
let member_cap = DAOSpace::acquire_member_cap<DAOT, MemberProposalPlugin>(&witness);
DAOSpace::member_offer(&member_cap, member, Option::some(image_data), Option::some(image_url) , init_sbt);
let op_image_data = if(Vector::length(&image_data) == 0){
Option::none<vector<u8>>()
}else{
Option::some(image_data)
};
let op_image_url = if(Vector::length(&image_url) == 0){
Option::none<vector<u8>>()
}else{
Option::some(image_url)
};
DAOSpace::member_offer(&member_cap, member,op_image_data , op_image_url , init_sbt);
}

public (script) fun execute_proposal_entry<DAOT: store>(sender: signer, proposal_id: u64){
Expand Down

0 comments on commit 64d754d

Please sign in to comment.