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

DAOAccountCap check #89

Merged
merged 1 commit into from
Aug 17, 2022
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion build/StarcoinFramework/BuildInfo.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ compiled_package_info:
? address: "0x00000000000000000000000000000001"
name: YieldFarmingV2
: StarcoinFramework
source_digest: 7138A8A0DEBB195CC13E43D24FAACA4CCE188BA3536A5DED8646E8934CBC2431
source_digest: 7383E555375A13FC20185C03038B1A256C817A71C484233F6D7EAEE9FA1263EA
build_flags:
dev_mode: false
test_mode: false
Expand Down
42 changes: 39 additions & 3 deletions integration-tests/daospace/dao_account.exp
Original file line number Diff line number Diff line change
@@ -1,17 +1,53 @@
processed 4 tasks
processed 6 tasks

task 2 'run'. lines 6-23:
{
"gas_used": 827652,
"gas_used": 837509,
"status": {
"Keep": "Executed"
}
}

task 3 'run'. lines 28-40:
{
"gas_used": 74662,
"gas_used": 84519,
"status": {
"Keep": "Executed"
}
}

task 4 'run'. lines 42-51:
{
"gas_used": 712879,
"status": {
"Keep": {
"MoveAbort": [
{
"Module": {
"address": "0x00000000000000000000000000000001",
"name": "DAOAccount"
}
},
25862
]
}
}
}

task 5 'run'. lines 53-61:
{
"gas_used": 711648,
"status": {
"Keep": {
"MoveAbort": [
{
"Module": {
"address": "0x00000000000000000000000000000001",
"name": "DAOAccount"
}
},
25862
]
}
}
}
25 changes: 23 additions & 2 deletions integration-tests/daospace/dao_account.move
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//# init -n dev

//# faucet --addr alice --amount 1000000
//# faucet --addr alice --amount 10000000


//# run --signers alice
Expand Down Expand Up @@ -37,4 +37,25 @@ script {
DAOAccount::restore_dao_account_cap(&sender, dao_cap);
}
}
// check: EXECUTED
// check: EXECUTED

//# run --signers alice
script {
use StarcoinFramework::DAOAccount;

fun main(sender: signer) {
let dao_cap = DAOAccount::create_account(&sender);
DAOAccount::restore_dao_account_cap(&sender, dao_cap);
}
}
// check: ABORT, code 25862. Reason: alice already has a DAOAccountCap

//# run --signers alice
script {
use StarcoinFramework::DAOAccount;

fun main(sender: signer) {
DAOAccount::create_account_entry(sender);
}
}
// check: ABORT, code 25862. Reason: alice already has a DAOAccountCap
4 changes: 4 additions & 0 deletions sources/daospace/DAOAccount.move
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ module StarcoinFramework::DAOAccount{
}

const ERR_ACCOUNT_CAP_NOT_EXISTS:u64 = 100;
const ERR_ACCOUNT_CAP_EXISTS: u64 = 101;

/// DAOAccount
struct DAOAccount has key{
Expand All @@ -36,6 +37,7 @@ module StarcoinFramework::DAOAccount{
/// Entry function for create dao account, the `DAOAccountCap` save to the `creator` account
public(script) fun create_account_entry(sender: signer){
let cap = create_account(&sender);
assert!(!exists<DAOAccountCap>(Signer::address_of(&sender)), Errors::already_published(ERR_ACCOUNT_CAP_EXISTS));
move_to(&sender, cap);
}

Expand All @@ -48,6 +50,8 @@ module StarcoinFramework::DAOAccount{

/// Restore the DAOAccountCap to the `sender`
public fun restore_dao_account_cap(sender: &signer, cap: DAOAccountCap) {
let sender_addr = Signer::address_of(sender);
assert!(!exists<DAOAccountCap>(sender_addr), Errors::already_published(ERR_ACCOUNT_CAP_EXISTS));
move_to(sender, cap)
}

Expand Down