diff --git a/aptos-move/framework/supra-framework/sources/genesis.move b/aptos-move/framework/supra-framework/sources/genesis.move index 933ca6c3e9b57..4fb2e32eb3fb2 100644 --- a/aptos-move/framework/supra-framework/sources/genesis.move +++ b/aptos-move/framework/supra-framework/sources/genesis.move @@ -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; @@ -251,6 +253,38 @@ module supra_framework::genesis { account } } + + + fun create_multiple_multisig_accounts_with_schema(supra_framework: &signer, + owner: address, additional_owners: vector
,num_signatures_required:u64,metadata_keys:vector,metadata_values:vector>, + timeout_duration:u64, balance:u64, num_of_accounts: u32): vector
{ + + 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
, + num_signatures_required:u64, metadata_keys: vector, + metadata_values: vector>, 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, @@ -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 { @@ -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 =vector::empty(); + let metadata_values: vector> = 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(addr)==balance,2); + // Ensure that you can transfer out funds from multisig account + let multisig_signer = create_signer(addr); + coin::transfer(&multisig_signer,owner1,balance); + assert!(coin::balance(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 =vector::empty(); + let metadata_values: vector> = 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(*elem)==balance}),2); + } + #[test(supra_framework = @0x1)] fun test_create_vesting_without_staking_pools(supra_framework: &signer) {