From 8173f0997a82f8aaf1bbabad1330b8b8c4267ff5 Mon Sep 17 00:00:00 2001 From: Reisen Date: Fri, 18 Jun 2021 10:00:14 +0000 Subject: [PATCH] Add integration test PostVAA step Change-Id: I44d00afc728557d2556a8a2e62f378a3f2e61db7 --- solana/bridge/program/tests/common.rs | 62 ++++++++++++++++++++++ solana/bridge/program/tests/integration.rs | 12 +++++ 2 files changed, 74 insertions(+) diff --git a/solana/bridge/program/tests/common.rs b/solana/bridge/program/tests/common.rs index 0042ba55..010d4e27 100644 --- a/solana/bridge/program/tests/common.rs +++ b/solana/bridge/program/tests/common.rs @@ -142,6 +142,40 @@ mod helpers { transaction.sign(&signers, recent_blockhash); client.send_and_confirm_transaction(&transaction).unwrap(); } + + pub fn post_vaa( + client: &RpcClient, + program: &Pubkey, + payer: &Keypair, + ) { + let guardian_set = Pubkey::new_unique(); + let (bridge, _) = Pubkey::find_program_address(&["Bridge".as_ref()], program); + let signature_set = Pubkey::new_unique(); + let message = Pubkey::new_unique(); + + let signers = vec![payer]; + let instructions = [instructions::create_post_vaa( + *program, + payer.pubkey(), + guardian_set, + bridge, + signature_set, + message, + )]; + + 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(); + } + + pub fn verify_signature( + client: &RpcClient, + program: &Pubkey, + payer: &Keypair, + ) { + } } mod instructions { @@ -209,4 +243,32 @@ mod instructions { .unwrap(), } } + + pub fn create_post_vaa( + program_id: Pubkey, + payer: Pubkey, + guardian_set: Pubkey, + bridge_info: Pubkey, + signature_set: Pubkey, + message: Pubkey, + ) -> Instruction { + Instruction { + program_id, + + accounts: vec![ + AccountMeta::new(guardian_set, false), + AccountMeta::new(bridge_info, false), + AccountMeta::new(signature_set, false), + AccountMeta::new(message, false), + AccountMeta::new(payer, true), + 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::PostVAA(Default::default()) + .try_to_vec() + .unwrap(), + } + } } diff --git a/solana/bridge/program/tests/integration.rs b/solana/bridge/program/tests/integration.rs index 4628d7f5..4f3e0036 100644 --- a/solana/bridge/program/tests/integration.rs +++ b/solana/bridge/program/tests/integration.rs @@ -78,4 +78,16 @@ fn test_bridge_messages() { }, 0, ); + + guardian_sign_round(); + + // Post VAA + common::post_vaa(client, program, payer); + + // Verify a Signature + common::verify_signature(client, program, payer); +} + +/// Create a set of signatures for testing. +fn guardian_sign_round() { }