Add integration test around PostMessage
Change-Id: I8c41db5f3d110ee445ed66d2599d87afb42fde7e
This commit is contained in:
parent
c3151728f5
commit
692da33d0c
|
@ -28,7 +28,10 @@ impl<'b, const State: AccountState> Seeded<&GuardianSetDerivationData>
|
||||||
for GuardianSet<'b, { State }>
|
for GuardianSet<'b, { State }>
|
||||||
{
|
{
|
||||||
fn seeds(data: &GuardianSetDerivationData) -> Vec<Vec<u8>> {
|
fn seeds(data: &GuardianSetDerivationData) -> Vec<Vec<u8>> {
|
||||||
vec![data.index.to_be_bytes().to_vec()]
|
vec![
|
||||||
|
"GuardianSet".as_bytes().to_vec(),
|
||||||
|
data.index.to_be_bytes().to_vec()
|
||||||
|
]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -62,6 +62,17 @@ mod helpers {
|
||||||
(payer, rpc, program)
|
(payer, rpc, program)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn transfer(client: &RpcClient, from: &Keypair, to: &Pubkey, lamports: u64) {
|
||||||
|
let signers = vec![from];
|
||||||
|
let instructions = [system_instruction::transfer(&from.pubkey(), to, lamports)];
|
||||||
|
|
||||||
|
let mut transaction = Transaction::new_with_payer(&instructions, Some(&from.pubkey()));
|
||||||
|
let recent_blockhash = client.get_recent_blockhash().unwrap().0;
|
||||||
|
|
||||||
|
transaction.sign(&signers, recent_blockhash);
|
||||||
|
client.send_and_confirm_transaction(&transaction).unwrap();
|
||||||
|
}
|
||||||
|
|
||||||
pub fn initialize(
|
pub fn initialize(
|
||||||
client: &RpcClient,
|
client: &RpcClient,
|
||||||
program: &Pubkey,
|
program: &Pubkey,
|
||||||
|
@ -88,6 +99,49 @@ mod helpers {
|
||||||
transaction.sign(&signers, recent_blockhash);
|
transaction.sign(&signers, recent_blockhash);
|
||||||
client.send_and_confirm_transaction(&transaction).unwrap();
|
client.send_and_confirm_transaction(&transaction).unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn post_message(
|
||||||
|
client: &RpcClient,
|
||||||
|
program: &Pubkey,
|
||||||
|
payer: &Keypair,
|
||||||
|
message: PostedMessage,
|
||||||
|
sequence: u64,
|
||||||
|
) {
|
||||||
|
let emitter = Keypair::new();
|
||||||
|
let (bridge, _) = Pubkey::find_program_address(&["Bridge".as_ref()], program);
|
||||||
|
let (fee_vault, _) = Pubkey::find_program_address(&["Fees".as_ref()], program);
|
||||||
|
let (fee_collector, _) = Pubkey::find_program_address(&["fee_collector".as_ref()], program);
|
||||||
|
let (sequence_key, _) =
|
||||||
|
Pubkey::find_program_address(&[&emitter.pubkey().to_bytes()], program);
|
||||||
|
let (message_key, _) = Pubkey::find_program_address(
|
||||||
|
&[
|
||||||
|
&emitter.pubkey().to_bytes(),
|
||||||
|
sequence.to_be_bytes().as_ref(),
|
||||||
|
],
|
||||||
|
program,
|
||||||
|
);
|
||||||
|
|
||||||
|
// Top up the fee collector with some base funds.
|
||||||
|
transfer(client, payer, &fee_collector, 1000000);
|
||||||
|
|
||||||
|
let signers = vec![payer, &emitter];
|
||||||
|
let instructions = [instructions::create_post_message(
|
||||||
|
*program,
|
||||||
|
payer.pubkey(),
|
||||||
|
bridge,
|
||||||
|
fee_vault,
|
||||||
|
message_key,
|
||||||
|
emitter.pubkey(),
|
||||||
|
sequence_key,
|
||||||
|
fee_collector,
|
||||||
|
)];
|
||||||
|
|
||||||
|
let mut transaction = Transaction::new_with_payer(&instructions, Some(&payer.pubkey()));
|
||||||
|
let recent_blockhash = client.get_recent_blockhash().unwrap().0;
|
||||||
|
|
||||||
|
transaction.sign(&signers, recent_blockhash);
|
||||||
|
client.send_and_confirm_transaction(&transaction).unwrap();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
mod instructions {
|
mod instructions {
|
||||||
|
@ -118,4 +172,41 @@ mod instructions {
|
||||||
.unwrap(),
|
.unwrap(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn create_post_message(
|
||||||
|
program_id: Pubkey,
|
||||||
|
payer: Pubkey,
|
||||||
|
bridge: Pubkey,
|
||||||
|
fee_vault: Pubkey,
|
||||||
|
message: Pubkey,
|
||||||
|
emitter: Pubkey,
|
||||||
|
sequence: Pubkey,
|
||||||
|
fee_collector: Pubkey,
|
||||||
|
) -> Instruction {
|
||||||
|
Instruction {
|
||||||
|
program_id,
|
||||||
|
|
||||||
|
accounts: vec![
|
||||||
|
AccountMeta::new(bridge, false),
|
||||||
|
AccountMeta::new(fee_vault, false),
|
||||||
|
AccountMeta::new(message, false),
|
||||||
|
AccountMeta::new(emitter, true),
|
||||||
|
AccountMeta::new(sequence, false),
|
||||||
|
AccountMeta::new(payer, true),
|
||||||
|
AccountMeta::new(fee_collector, false),
|
||||||
|
AccountMeta::new_readonly(sysvar::instructions::id(), false),
|
||||||
|
AccountMeta::new_readonly(sysvar::clock::id(), false),
|
||||||
|
AccountMeta::new_readonly(sysvar::rent::id(), false),
|
||||||
|
AccountMeta::new_readonly(solana_program::system_program::id(), false),
|
||||||
|
],
|
||||||
|
|
||||||
|
data: instruction::Instruction::PostMessage(PostMessageData {
|
||||||
|
nonce: 0,
|
||||||
|
payload: vec![],
|
||||||
|
emitter,
|
||||||
|
})
|
||||||
|
.try_to_vec()
|
||||||
|
.unwrap(),
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -55,4 +55,27 @@ fn test_bridge_messages() {
|
||||||
payer,
|
payer,
|
||||||
GuardianSetDerivationData { index: 0 },
|
GuardianSetDerivationData { index: 0 },
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// Post a Message
|
||||||
|
common::post_message(
|
||||||
|
client,
|
||||||
|
program,
|
||||||
|
payer,
|
||||||
|
PostedMessage {
|
||||||
|
vaa_version: 0,
|
||||||
|
vaa_time: 0,
|
||||||
|
vaa_signature_account: Pubkey::new_unique(),
|
||||||
|
|
||||||
|
nonce: 0,
|
||||||
|
sequence: 0,
|
||||||
|
emitter_chain: 1,
|
||||||
|
emitter_address: [0u8; 32],
|
||||||
|
payload: vec![],
|
||||||
|
submission_time: SystemTime::now()
|
||||||
|
.duration_since(SystemTime::UNIX_EPOCH)
|
||||||
|
.unwrap()
|
||||||
|
.as_secs() as u32,
|
||||||
|
},
|
||||||
|
0,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue