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

Multisig genesis #66

Merged
merged 3 commits into from
Sep 3, 2024
Merged
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
87 changes: 85 additions & 2 deletions aptos-move/framework/supra-framework/sources/genesis.move
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@ module supra_framework::genesis {
use std::fixed_point32;
use std::vector;
use std::option;
use std::string::{Self, String};

use aptos_std::simple_map;
use supra_framework::supra_account;
use supra_framework::delegation_pool;
use supra_framework::pbo_delegation_pool;
use supra_framework::multisig_account;

use supra_framework::account;
use supra_framework::aggregator_factory;
Expand Down Expand Up @@ -251,6 +253,38 @@ module supra_framework::genesis {
account
}
}


fun create_multiple_multisig_accounts_with_schema(supra_framework: &signer,
owner: address, additional_owners: vector<address>,num_signatures_required:u64,metadata_keys:vector<String>,metadata_values:vector<vector<u8>>,
timeout_duration:u64, balance:u64, num_of_accounts: u32): vector<address> {

let counter = 0;
let result = vector::empty();
while (counter < num_of_accounts) {
let account_addr = create_multisig_account_with_balance(supra_framework, owner, additional_owners,
num_signatures_required,metadata_keys,metadata_values,timeout_duration,balance);
vector::push_back(&mut result,account_addr);
account::increment_sequence_number(owner);
counter = counter + 1;
};
result
}
fun create_multisig_account_with_balance(supra_framework: &signer, owner: address, additional_owners: vector<address>,
num_signatures_required:u64, metadata_keys: vector<String>,
metadata_values: vector<vector<u8>>, timeout_duration: u64, balance:u64 ) : address {


assert!(account::exists_at(owner),error::invalid_argument(EACCOUNT_DOES_NOT_EXIST));
assert!(vector::all(&additional_owners,|ao_addr|{account::exists_at(*ao_addr)}),error::invalid_argument(EACCOUNT_DOES_NOT_EXIST));
let addr = multisig_account::get_next_multisig_account_address(owner);
let owner_signer = create_signer(owner);
multisig_account::create_with_owners(&owner_signer,additional_owners,num_signatures_required,metadata_keys,metadata_values,timeout_duration);
supra_coin::mint(supra_framework,addr,balance);
addr

}


fun create_employee_validators(
employee_vesting_start: u64,
Expand Down Expand Up @@ -776,8 +810,6 @@ module supra_framework::genesis {

#[test_only]
use aptos_std::ed25519;
#[test_only]
use supra_framework::multisig_account;

#[test_only]
fun generate_multisig_account(owner: &signer, addition_owner: vector<address>): address {
Expand Down Expand Up @@ -1098,6 +1130,57 @@ module supra_framework::genesis {
assert!(pbo_delegation_pool::delegation_pool_exists(pool_address1), 0);
assert!(pbo_delegation_pool::delegation_pool_exists(pool_address2), 1);
}

#[test (supra_framework=@0x1, owner1=@0x1234, owner2=@0x2345, owner3=@0x3456)]
fun test_create_multisig_account_with_balance(supra_framework: &signer, owner1: address, owner2: address, owner3: address)
{
setup();
initialize_supra_coin(supra_framework);
let additional_owners = vector[owner2, owner3];
let timeout_duration=600;
let num_signatures_required = 2;
let metadata_keys: vector<String> =vector::empty();
let metadata_values: vector<vector<u8>> = vector::empty();
let balance = 10000000000;
create_account(supra_framework,owner1,0);
create_account(supra_framework,owner2,0);
create_account(supra_framework,owner3,0);
let addr = create_multisig_account_with_balance(supra_framework,owner1, additional_owners,
num_signatures_required, metadata_keys, metadata_values, timeout_duration,balance);
//Ensure it is indeed on-chain multisig account with required threshold
assert!(multisig_account::num_signatures_required(addr)==2,1);
//Ensure the account is seeded with supplied balance
assert!(coin::balance<SupraCoin>(addr)==balance,2);
// Ensure that you can transfer out funds from multisig account
let multisig_signer = create_signer(addr);
coin::transfer<SupraCoin>(&multisig_signer,owner1,balance);
assert!(coin::balance<SupraCoin>(owner1)==balance,3);
}

#[test (supra_framework=@0x1, owner1=@0x1234, owner2=@0x2345, owner3=@0x3456)]
fun test_create_multisig_account_with_schema(supra_framework: &signer, owner1: address, owner2: address, owner3: address)
{
setup();
initialize_supra_coin(supra_framework);
let additional_owners = vector[owner2, owner3];
let timeout_duration=600;
let num_signatures_required = 2;
let metadata_keys: vector<String> =vector::empty();
let metadata_values: vector<vector<u8>> = vector::empty();
let balance = 10000000000;
let num_accounts = 3;
create_account(supra_framework,owner1,0);
create_account(supra_framework,owner2,0);
create_account(supra_framework,owner3,0);
let vec_addr = create_multiple_multisig_accounts_with_schema(supra_framework,owner1,
additional_owners,num_signatures_required,metadata_keys,metadata_values,
timeout_duration,balance,num_accounts);
//Ensure they are indeed on-chain multisig account with required threshold
assert!(vector::all(&vec_addr,|elem| {multisig_account::num_signatures_required(*elem)==2}),1);
//Ensure the accounts are seeded with supplied balance
assert!(vector::all(&vec_addr,|elem| {coin::balance<SupraCoin>(*elem)==balance}),2);
}


#[test(supra_framework = @0x1)]
fun test_create_vesting_without_staking_pools(supra_framework: &signer) {
Expand Down
Loading