2020-09-23 23:40:32 -07:00
|
|
|
use common::lifecycle;
|
|
|
|
use rand::rngs::OsRng;
|
|
|
|
use solana_client_gen::solana_sdk::instruction::AccountMeta;
|
|
|
|
use solana_client_gen::solana_sdk::signature::{Keypair, Signer};
|
|
|
|
|
|
|
|
mod common;
|
|
|
|
|
|
|
|
// TODO: if we enable migration, then we need to check if migration has happened
|
|
|
|
// on all instructions and exit if so.
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn migrate() {
|
|
|
|
// Given.
|
|
|
|
//
|
2020-09-24 19:57:37 -07:00
|
|
|
// An initialized safe with deposit (scheduled doesn't matter for
|
|
|
|
// this test).
|
|
|
|
let deposit_amount = 100;
|
2020-09-23 23:40:32 -07:00
|
|
|
let lifecycle::Deposited {
|
|
|
|
client,
|
|
|
|
safe_acc,
|
|
|
|
safe_srm_vault,
|
|
|
|
safe_srm_vault_authority,
|
|
|
|
srm_mint,
|
|
|
|
safe_authority,
|
|
|
|
..
|
2020-09-24 19:57:37 -07:00
|
|
|
} = lifecycle::deposit_with_schedule(100, 100_000, 1);
|
2020-09-23 23:40:32 -07:00
|
|
|
// And.
|
|
|
|
//
|
|
|
|
// An SPL account to transfer to.
|
|
|
|
let recipient_owner = Keypair::generate(&mut OsRng);
|
|
|
|
let receiver_token_acc = serum_common::client::rpc::create_token_account(
|
|
|
|
client.rpc(),
|
|
|
|
&srm_mint.pubkey(),
|
|
|
|
&recipient_owner.pubkey(),
|
|
|
|
client.payer(),
|
|
|
|
)
|
|
|
|
.unwrap();
|
|
|
|
|
|
|
|
// When.
|
|
|
|
//
|
|
|
|
// I migrate thh safe.
|
|
|
|
let accounts = [
|
|
|
|
AccountMeta::new_readonly(safe_authority.pubkey(), true),
|
|
|
|
AccountMeta::new(safe_acc, false),
|
|
|
|
AccountMeta::new(safe_srm_vault.pubkey(), false),
|
|
|
|
AccountMeta::new_readonly(safe_srm_vault_authority, false),
|
|
|
|
AccountMeta::new(receiver_token_acc.pubkey(), false),
|
|
|
|
AccountMeta::new_readonly(spl_token::ID, false),
|
|
|
|
];
|
|
|
|
let signers = [&safe_authority, client.payer()];
|
|
|
|
client.migrate_with_signers(&signers, &accounts).unwrap();
|
|
|
|
|
|
|
|
// Then.
|
|
|
|
//
|
|
|
|
// The safe's vault should be drained.
|
|
|
|
{
|
|
|
|
let safe_vault: spl_token::state::Account =
|
|
|
|
serum_common::client::rpc::account_token_unpacked(
|
|
|
|
client.rpc(),
|
|
|
|
&safe_srm_vault.pubkey(),
|
|
|
|
);
|
|
|
|
assert_eq!(safe_vault.amount, 0);
|
|
|
|
}
|
|
|
|
// Then.
|
|
|
|
//
|
|
|
|
// The receipient should have all the funds.
|
|
|
|
{
|
|
|
|
let recipient: spl_token::state::Account =
|
|
|
|
serum_common::client::rpc::account_token_unpacked(
|
|
|
|
client.rpc(),
|
|
|
|
&receiver_token_acc.pubkey(),
|
|
|
|
);
|
2020-09-24 19:57:37 -07:00
|
|
|
assert_eq!(recipient.amount, deposit_amount);
|
2020-09-23 23:40:32 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// Then.
|
|
|
|
//
|
|
|
|
// The safe account should be updated.
|
|
|
|
{
|
|
|
|
// todo: add a check here if we want to place a marker for migration
|
|
|
|
// on the Safe state.
|
|
|
|
}
|
|
|
|
}
|