1
- use crate :: testing_engine:: config:: ExpectedError ;
1
+ use crate :: testing_engine:: config:: {
2
+ ExpectedError , InitializeFastMarketOrderShimInstructionConfig ,
3
+ } ;
4
+ use crate :: testing_engine:: state:: {
5
+ FastMarketOrderAccountCreatedState , GuardianSetState , TestingEngineState ,
6
+ } ;
2
7
3
- use super :: verify_shim:: GuardianSignatureInfo ;
8
+ use super :: verify_shim:: { create_guardian_signatures , GuardianSignatureInfo } ;
4
9
use crate :: testing_engine:: setup:: TestingContext ;
5
10
use crate :: utils;
6
11
use common:: messages:: FastMarketOrder ;
@@ -38,34 +43,86 @@ use wormhole_io::TypePrefixedPayload;
38
43
/// # Asserts
39
44
///
40
45
/// * The expected error, if any, is reached when executing the instruction
41
- pub async fn initialize_fast_market_order_fallback (
46
+ pub async fn initialize_fast_market_order_shimful (
42
47
testing_context : & TestingContext ,
43
48
test_context : & mut ProgramTestContext ,
44
- payer_signer : & Rc < Keypair > ,
45
- fast_market_order : FastMarketOrderState ,
46
- guardian_signature_info : & GuardianSignatureInfo ,
47
49
expected_error : Option < & ExpectedError > ,
48
- ) {
50
+ current_state : & TestingEngineState ,
51
+ config : & InitializeFastMarketOrderShimInstructionConfig ,
52
+ ) -> TestingEngineState {
49
53
let program_id = & testing_context. get_matching_engine_program_id ( ) ;
50
- let initialize_fast_market_order_ix = initialize_fast_market_order_fallback_instruction (
51
- payer_signer,
54
+ let test_vaa_pair = current_state. get_test_vaa_pair ( config. vaa_index ) ;
55
+ let fast_transfer_vaa = test_vaa_pair. fast_transfer_vaa . clone ( ) ;
56
+ let fast_market_order = create_fast_market_order_state_from_vaa_data (
57
+ & fast_transfer_vaa. vaa_data ,
58
+ config
59
+ . close_account_refund_recipient
60
+ . unwrap_or_else ( || testing_context. testing_actors . solvers [ 0 ] . pubkey ( ) ) ,
61
+ ) ;
62
+ let payer_signer = config
63
+ . payer_signer
64
+ . clone ( )
65
+ . unwrap_or_else ( || testing_context. testing_actors . payer_signer . clone ( ) ) ;
66
+ let guardian_signature_info = create_guardian_signatures (
67
+ & testing_context,
68
+ test_context,
69
+ & payer_signer,
70
+ & fast_transfer_vaa. vaa_data ,
71
+ & testing_context. get_wormhole_program_id ( ) ,
72
+ None ,
73
+ )
74
+ . await
75
+ . expect ( "Failed to create guardian signatures" ) ;
76
+
77
+ let ( fast_market_order_account, fast_market_order_bump) = Pubkey :: find_program_address (
78
+ & [
79
+ FastMarketOrderState :: SEED_PREFIX ,
80
+ & fast_market_order. digest ( ) ,
81
+ & fast_market_order. close_account_refund_recipient . as_ref ( ) ,
82
+ ] ,
83
+ program_id,
84
+ ) ;
85
+ let initialize_fast_market_order_ix = initialize_fast_market_order_shimful_instruction (
86
+ & payer_signer,
52
87
program_id,
53
88
fast_market_order,
54
- guardian_signature_info,
89
+ & guardian_signature_info,
55
90
) ;
56
91
let transaction = testing_context
57
92
. create_transaction (
58
93
test_context,
59
94
& [ initialize_fast_market_order_ix] ,
60
95
Some ( & payer_signer. pubkey ( ) ) ,
61
- & [ payer_signer] ,
96
+ & [ & payer_signer] ,
62
97
1000000000 ,
63
98
1000000000 ,
64
99
)
65
100
. await ;
66
101
testing_context
67
102
. execute_and_verify_transaction ( test_context, transaction, expected_error)
68
103
. await ;
104
+ if config. expected_error . is_none ( ) {
105
+ TestingEngineState :: FastMarketOrderAccountCreated {
106
+ base : current_state. base ( ) . clone ( ) ,
107
+ initialized : current_state. initialized ( ) . unwrap ( ) . clone ( ) ,
108
+ router_endpoints : current_state. router_endpoints ( ) . cloned ( ) ,
109
+ fast_market_order : FastMarketOrderAccountCreatedState {
110
+ fast_market_order_address : fast_market_order_account,
111
+ fast_market_order_bump,
112
+ fast_market_order,
113
+ close_account_refund_recipient : fast_market_order. close_account_refund_recipient ,
114
+ } ,
115
+ guardian_set_state : GuardianSetState {
116
+ guardian_set_address : guardian_signature_info. guardian_set_pubkey ,
117
+ guardian_signatures_address : guardian_signature_info. guardian_signatures_pubkey ,
118
+ } ,
119
+ auction_state : current_state. auction_state ( ) . clone ( ) ,
120
+ auction_accounts : current_state. auction_accounts ( ) . cloned ( ) ,
121
+ order_prepared : current_state. order_prepared ( ) . cloned ( ) ,
122
+ }
123
+ } else {
124
+ current_state. clone ( )
125
+ }
69
126
}
70
127
71
128
/// Creates the initialize fast market order fallback instruction
@@ -84,7 +141,7 @@ pub async fn initialize_fast_market_order_fallback(
84
141
/// # Returns
85
142
///
86
143
/// * `Instruction` - The initialize fast market order fallback instruction
87
- fn initialize_fast_market_order_fallback_instruction (
144
+ pub fn initialize_fast_market_order_shimful_instruction (
88
145
payer_signer : & Rc < Keypair > ,
89
146
program_id : & Pubkey ,
90
147
fast_market_order : FastMarketOrderState ,
0 commit comments