1
1
#[ cfg( test) ]
2
2
mod test {
3
+ use crate :: error:: PythReceiverError ;
4
+ use crate :: test_data:: * ;
3
5
use crate :: PythReceiver ;
4
6
use alloy_primitives:: { Address , U256 } ;
7
+ use mock_instant:: global:: MockClock ;
5
8
use motsu:: prelude:: * ;
9
+ use pythnet_sdk:: wire:: v1:: { AccumulatorUpdateData , Proof } ;
10
+ use std:: time:: Duration ;
6
11
use hex:: FromHex ;
7
12
use wormhole_contract:: WormholeContract ;
8
13
use wormhole_vaas:: { Vaa , Readable , Writeable } ;
@@ -18,11 +23,25 @@ mod test {
18
23
const GOVERNANCE_CONTRACT : U256 = U256 :: from_limbs ( [ 4 , 0 , 0 , 0 ] ) ;
19
24
20
25
const SINGLE_UPDATE_FEE_IN_WEI : U256 = U256 :: from_limbs ( [ 100 , 0 , 0 , 0 ] ) ;
26
+ const TRANSACTION_FEE_IN_WEI : U256 = U256 :: from_limbs ( [ 32 , 0 , 0 , 0 ] ) ;
27
+
28
+ const TEST_SIGNER1 : Address = Address :: new ( [
29
+ 0xbe , 0xFA , 0x42 , 0x9d , 0x57 , 0xcD , 0x18 , 0xb7 , 0xF8 , 0xA4 , 0xd9 , 0x1A , 0x2d , 0xa9 , 0xAB , 0x4A , 0xF0 , 0x5d , 0x0F , 0xBe
30
+ ] ) ;
31
+ const TEST_SIGNER2 : Address = Address :: new ( [
32
+ 0x4b , 0xa0 , 0xC2 , 0xdb , 0x9A , 0x26 , 0x20 , 0x8b , 0x3b , 0xB1 , 0xa5 , 0x0B , 0x01 , 0xb1 , 0x69 , 0x41 , 0xc1 , 0x0D , 0x76 , 0xdb
33
+ ] ) ;
21
34
const GOVERNANCE_CHAIN_ID : u16 = 1 ;
22
35
const GOVERNANCE_EMITTER : [ u8 ; 32 ] = [
23
36
0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 ,
24
37
0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x11
25
38
] ;
39
+ const TEST_PYTH2_WORMHOLE_CHAIN_ID : u16 = 1 ;
40
+ const TEST_PYTH2_WORMHOLE_EMITTER : [ u8 ; 32 ] = [
41
+ 0x71 , 0xf8 , 0xdc , 0xb8 , 0x63 , 0xd1 , 0x76 , 0xe2 , 0xc4 , 0x20 , 0xad , 0x66 , 0x10 , 0xcf , 0x68 , 0x73 ,
42
+ 0x59 , 0x61 , 0x2b , 0x6f , 0xb3 , 0x92 , 0xe0 , 0x64 , 0x2b , 0x0c , 0xa6 , 0xb1 , 0xf1 , 0x86 , 0xaa , 0x3b
43
+ ] ;
44
+ const TARGET_CHAIN_ID : u16 = 2 ;
26
45
27
46
#[ cfg( test) ]
28
47
fn pyth_wormhole_init (
@@ -35,13 +54,14 @@ mod test {
35
54
Address :: new( [ 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x02 ] ) ,
36
55
Address :: new( [ 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x03 ] ) ,
37
56
] ;
57
+
38
58
let governance_contract =
39
59
Address :: from_slice ( & GOVERNANCE_CONTRACT . to_be_bytes :: < 32 > ( ) [ 12 ..32 ] ) ;
40
60
wormhole_contract
41
61
. sender ( * alice)
42
62
. initialize (
43
63
guardians,
44
- 0 , // guardian set index 0
64
+ 4 ,
45
65
CHAIN_ID ,
46
66
GOVERNANCE_CHAIN_ID ,
47
67
governance_contract,
@@ -77,29 +97,16 @@ mod test {
77
97
) {
78
98
pyth_wormhole_init ( & pyth_contract, & wormhole_contract, & alice) ;
79
99
80
-
81
100
let hex_str = "01000000000100a53d7675143a514fa10756ef19e1281648aec03be2ea071c139f241839cb01206ce5c7f3673fc446a045cab2d4f97ef0de01de70269ab2678bba76b41c3a60ce010000000100000000000100000000000000000000000000000000000000000000000000000000000000110000000000000001005054474d010200020100010000000000000000000000000000000000000000000000000000000000001111" ;
82
101
let bytes = Vec :: from_hex ( hex_str) . expect ( "Invalid hex string" ) ;
83
102
84
- use wormhole_vaas:: Vaa ;
85
- let vm = Vaa :: read ( & mut bytes. as_slice ( ) ) . expect ( "Failed to parse VAA" ) ;
86
- let instruction = crate :: governance_structs:: parse_instruction ( vm. body . payload . to_vec ( ) )
87
- . expect ( "Failed to parse governance instruction" ) ;
88
-
89
- match instruction. payload {
90
- crate :: governance_structs:: GovernancePayload :: SetDataSources ( payload) => {
91
- assert_eq ! ( payload. sources. len( ) , 1 ) ;
92
- let expected_source = & payload. sources [ 0 ] ;
93
- assert_eq ! ( expected_source. chain_id. to:: <u16 >( ) , 1 ) ;
94
- assert_eq ! ( expected_source. emitter_address. as_slice( ) , & [
95
- 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 ,
96
- 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x11 , 0x11
97
- ] ) ;
98
- println ! ( "Successfully parsed SetDataSources governance instruction with {} data sources" , payload. sources. len( ) ) ;
99
- }
100
- _ => panic ! ( "Expected SetDataSources governance instruction" ) ,
103
+ let result = pyth_contract. sender ( alice) . execute_governance_instruction ( bytes. clone ( ) ) ;
104
+ if let Err ( e) = & result {
105
+ println ! ( "Governance instruction failed with error: {:?}" , e) ;
101
106
}
102
-
107
+
108
+ println ! ( "{:?}" , result) ;
109
+ assert ! ( result. is_ok( ) ) ;
103
110
}
104
111
105
112
}
0 commit comments