serum-dex/safe/tests/migrate.rs

84 lines
2.4 KiB
Rust
Raw Normal View History

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.
//
// 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,
..
} = 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(),
);
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.
}
}