Skip to content

Commit

Permalink
add an integration test
Browse files Browse the repository at this point in the history
  • Loading branch information
yeptos committed Sep 28, 2024
1 parent e517218 commit 449e4ac
Show file tree
Hide file tree
Showing 3 changed files with 124 additions and 0 deletions.
55 changes: 55 additions & 0 deletions api/src/tests/multisig_transactions_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,61 @@ async fn test_multisig_transaction_with_payload_succeeds() {
assert_eq!(0, context.get_apt_balance(multisig_account).await);
}

#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
async fn test_multisig_transaction_with_existing_account() {
let mut context = new_test_context(current_function_name!());
let multisig_account = &mut context.create_account().await;
let owner_account_1 = &mut context.create_account().await;
let owner_account_2 = &mut context.create_account().await;
let owner_account_3 = &mut context.create_account().await;
context
.create_multisig_account_with_existing(
multisig_account,
vec![
owner_account_1.address(),
owner_account_2.address(),
owner_account_3.address(),
],
2,
1000,
)
.await;
let org_balance = context.get_apt_balance(multisig_account.address()).await;

let multisig_payload = construct_multisig_txn_transfer_payload(owner_account_1.address(), 1000);
context
.create_multisig_transaction(
owner_account_1,
multisig_account.address(),
multisig_payload.clone(),
)
.await;
// Owner 2 approves and owner 3 rejects. There are still 2 approvals total (owners 1 and 2) so
// the transaction can still be executed.
context
.approve_multisig_transaction(owner_account_2, multisig_account.address(), 1)
.await;
context
.reject_multisig_transaction(owner_account_3, multisig_account.address(), 1)
.await;
context
.execute_multisig_transaction(owner_account_1, multisig_account.address(), 202)
.await;

// The multisig tx that transfers away 1000 APT should have succeeded.
assert_multisig_tx_executed(
&mut context,
multisig_account.address(),
multisig_payload,
1,
)
.await;
assert_eq!(
org_balance - 1000,
context.get_apt_balance(multisig_account.address()).await
);
}

#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
async fn test_multisig_transaction_to_update_owners() {
let mut context = new_test_context(current_function_name!());
Expand Down
43 changes: 43 additions & 0 deletions api/test-context/src/test_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -451,6 +451,49 @@ impl TestContext {
multisig_address
}

pub async fn create_multisig_account_with_existing(
&mut self,
account: &mut LocalAccount,
owners: Vec<AccountAddress>,
signatures_required: u64,
initial_balance: u64,
) {
let factory = self.transaction_factory();
let txn = account.sign_with_transaction_builder(
factory
.create_multisig_account_with_existing(owners, signatures_required)
.expiration_timestamp_secs(u64::MAX),
);
self.commit_block(&vec![
txn,
self.account_transfer_to(account, account.address(), initial_balance),
])
.await;
}

pub async fn create_multisig_account_with_existing_and_revoke_auth_key(
&mut self,
account: &mut LocalAccount,
owners: Vec<AccountAddress>,
signatures_required: u64,
initial_balance: u64,
) {
let factory = self.transaction_factory();
let txn = account.sign_with_transaction_builder(
factory
.create_multisig_account_with_existing_and_revoke_auth_key(
owners,
signatures_required,
)
.expiration_timestamp_secs(u64::MAX),
);
self.commit_block(&vec![
txn,
self.account_transfer_to(account, account.address(), initial_balance),
])
.await;
}

pub async fn create_multisig_transaction(
&mut self,
owner: &mut LocalAccount,
Expand Down
26 changes: 26 additions & 0 deletions sdk/src/transaction_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,32 @@ impl TransactionFactory {
))
}

pub fn create_multisig_account_with_existing(
&self,
additional_owners: Vec<AccountAddress>,
signatures_required: u64,
) -> TransactionBuilder {
self.payload(aptos_stdlib::multisig_account_create_with_existing_account_call(
additional_owners,
signatures_required,
vec![],
vec![],
))
}

pub fn create_multisig_account_with_existing_and_revoke_auth_key(
&self,
additional_owners: Vec<AccountAddress>,
signatures_required: u64,
) -> TransactionBuilder {
self.payload(aptos_stdlib::multisig_account_create_with_existing_account_and_revoke_auth_key_call(
additional_owners,
signatures_required,
vec![],
vec![],
))
}

pub fn create_multisig_transaction(
&self,
multisig_account: AccountAddress,
Expand Down

0 comments on commit 449e4ac

Please sign in to comment.