Skip to content

Commit 86df3ef

Browse files
authored
Make imports used for tests test only (#342)
1 parent 13f2d48 commit 86df3ef

File tree

5 files changed

+113
-77
lines changed

5 files changed

+113
-77
lines changed

aptos/contracts/sources/batch_price_attestation.move

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,21 @@
11
module pyth::batch_price_attestation {
22
use pyth::price_feed::{Self};
3-
use pyth::price;
43
use pyth::error;
5-
use pyth::i64;
64
use pyth::price_info::{Self, PriceInfo};
75
use pyth::price_identifier::{Self};
86
use pyth::price_status;
97
use pyth::deserialize::{Self};
10-
use aptos_framework::account;
118
use aptos_framework::timestamp;
129
use wormhole::cursor::{Self, Cursor};
1310
use std::vector::{Self};
1411

12+
#[test_only]
13+
use pyth::price;
14+
#[test_only]
15+
use pyth::i64;
16+
#[test_only]
17+
use aptos_framework::account;
18+
1519
const MAGIC: u64 = 0x50325748; // "P2WH" (Pyth2Wormhole) raw ASCII bytes
1620

1721
struct BatchPriceAttestation {

aptos/contracts/sources/deserialize.move

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,12 @@ module pyth::deserialize {
22
use wormhole::deserialize;
33
use wormhole::u16;
44
use wormhole::u32;
5-
use wormhole::cursor::{Self, Cursor};
5+
use wormhole::cursor::{Cursor};
66
use pyth::i64::{Self, I64};
77

8+
#[test_only]
9+
use wormhole::cursor::{Self};
10+
811
public fun deserialize_vector(cur: &mut Cursor<u8>, n: u64): vector<u8> {
912
deserialize::deserialize_vector(cur, n)
1013
}

aptos/contracts/sources/governance/governance.move

Lines changed: 29 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,16 @@
11
module pyth::governance {
22
use wormhole::vaa::{Self, VAA};
3-
use pyth::data_source::{Self, DataSource};
3+
use pyth::data_source::{Self};
44
use wormhole::u16;
55
use pyth::governance_instruction;
6-
use pyth::pyth;
76
use pyth::governance_action;
87
use pyth::contract_upgrade;
9-
use pyth::contract_upgrade_hash;
108
use pyth::set_governance_data_source;
119
use pyth::set_data_sources;
1210
use pyth::set_stale_price_threshold;
1311
use pyth::error;
1412
use pyth::set_update_fee;
1513
use pyth::state;
16-
use wormhole::external_address;
17-
use std::account;
18-
use std::vector;
1914

2015
public entry fun execute_governance_instruction(vaa_bytes: vector<u8>) {
2116
let parsed_vaa = parse_and_verify_governance_vaa(vaa_bytes);
@@ -59,6 +54,18 @@ module pyth::governance {
5954

6055
parsed_vaa
6156
}
57+
}
58+
59+
#[test_only]
60+
module pyth::governance_test {
61+
use pyth::data_source::{Self, DataSource};
62+
use pyth::pyth;
63+
use pyth::governance;
64+
use pyth::contract_upgrade_hash;
65+
use pyth::state;
66+
use wormhole::external_address;
67+
use std::account;
68+
use std::vector;
6269

6370
#[test_only]
6471
fun setup_test(
@@ -82,7 +89,7 @@ module pyth::governance {
8289
fun test_execute_governance_instruction_invalid_vaa() {
8390
setup_test(50, 24, x"f06413c0148c78916554f134dcd17a7c8029a3a2bda475a4a1182305c53078bf", 100);
8491
let vaa_bytes = x"6c436741b108";
85-
execute_governance_instruction(vaa_bytes);
92+
governance::execute_governance_instruction(vaa_bytes);
8693
}
8794

8895
#[test]
@@ -94,7 +101,7 @@ module pyth::governance {
94101
// - Emitter chain ID of 20
95102
// - Emitter address of 0xed67fcc21620d1bf9f69db61ea65ea36ae2df4f86c8e1b9503f0da287c24ed41
96103
let vaa_bytes = x"0100000000010066359039306c20c8e6d0047ca82aef1b3d1059a3196ab9b21ee9eb8d8438c4e06c3f181d86687cf52f8c4a167ce8af6a5dbadad22253a4016dc28a25f181a37301527e4f9b000000010014ed67fcc21620d1bf9f69db61ea65ea36ae2df4f86c8e1b9503f0da287c24ed410000000000000000005054474eb01087a85361f738f19454e66664d3c9";
97-
execute_governance_instruction(vaa_bytes);
104+
governance::execute_governance_instruction(vaa_bytes);
98105
}
99106

100107
#[test]
@@ -108,7 +115,7 @@ module pyth::governance {
108115
// - Emitter address 0xf06413c0148c78916554f134dcd17a7c8029a3a2bda475a4a1182305c53078bf
109116
// - Sequence number 0
110117
let vaa_bytes = x"010000000001004d7facf7151ada96a35a3f099843c5f13bd0e0a6cbf50722d4e456d370bbce8641ecc16450979d4c403888f9f08d5975503d810732dc95575880d2a4c64d40aa01527e4f9b000000010032f06413c0148c78916554f134dcd17a7c8029a3a2bda475a4a1182305c53078bf0000000000000000005054474eb01087a85361f738f19454e66664d3c9";
111-
execute_governance_instruction(vaa_bytes);
118+
governance::execute_governance_instruction(vaa_bytes);
112119
}
113120

114121
#[test]
@@ -122,7 +129,7 @@ module pyth::governance {
122129
// - Sequence number 1
123130
// - A payload with the value x"5054474eb01087a85361f738f19454e66664d3c9", so the magic number will be 5054474e
124131
let vaa_bytes = x"01000000000100583334c65aff30780bf7f2ac783398a2a985e3e4873264e46c3cddfdfb2eaa484365e9f4a3ecc14d059ac1cf0a7b6a58075749ad17a3bfd4153d8f45b9084a3500527e4f9b000000010032f06413c0148c78916554f134dcd17a7c8029a3a2bda475a4a1182305c53078bf0000000000000001005054474eb01087a85361f738f19454e66664d3c9";
125-
execute_governance_instruction(vaa_bytes);
132+
governance::execute_governance_instruction(vaa_bytes);
126133
}
127134

128135
#[test]
@@ -137,7 +144,7 @@ module pyth::governance {
137144
// - A payload representing a governance instruction with:
138145
// - Module number 2
139146
let vaa_bytes = x"010000000001001d9fd73b3fb0fc522eae5eb5bd40ddf68941894495d7cec8c8efdbf462e48715171b5c6d4bbca0c1e3843b3c28d0ca6f3f76874624b5595a3a2cbfdb3907b62501527e4f9b000000010032f06413c0148c78916554f134dcd17a7c8029a3a2bda475a4a1182305c53078bf0000000000000001005054474d0202001003001793a28e2e5b4cb88f69e96fb29a8287a88b23f0e99f5502f81744e904da8e3b4d000c9a4066ce1fa26da1c102a3e268abd3ca58e3b3c25f250e6ad9a3525066fbf8b00012f7778ca023d5cbe37449bab2faa2a133fe02b056c2c25605950320df08750f35";
140-
execute_governance_instruction(vaa_bytes);
147+
governance::execute_governance_instruction(vaa_bytes);
141148
}
142149

143150
#[test]
@@ -153,7 +160,7 @@ module pyth::governance {
153160
// - Module number 1
154161
// - Target chain 17 != wormhole test chain ID 22
155162
let vaa_bytes = x"010000000001001ed81e10f8e52e6a7daeca12bf0859c14e8dabed737eaed9a1f8227190a9d11c48d58856713243c5d7de08ed49de4aa1efe7c5e6020c11056802e2d702aa4b2e00527e4f9b000000010032f06413c0148c78916554f134dcd17a7c8029a3a2bda475a4a1182305c53078bf0000000000000001005054474d0102001103001793a28e2e5b4cb88f69e96fb29a8287a88b23f0e99f5502f81744e904da8e3b4d000c9a4066ce1fa26da1c102a3e268abd3ca58e3b3c25f250e6ad9a3525066fbf8b00012f7778ca023d5cbe37449bab2faa2a133fe02b056c2c25605950320df08750f35";
156-
execute_governance_instruction(vaa_bytes);
163+
governance::execute_governance_instruction(vaa_bytes);
157164
}
158165

159166
#[test]
@@ -170,7 +177,7 @@ module pyth::governance {
170177
// - Target chain 22
171178
// - Action 19 (invalid)
172179
let vaa_bytes = x"0100000000010049fdadd56a51e8bd30637dbf9fc79a154a80c96479ce223061ec1f5094f2908715d6c691e5f06068873daa79c87fc25deb62555db7c520468d05aa2437fda97201527e4f9b000000010032f06413c0148c78916554f134dcd17a7c8029a3a2bda475a4a1182305c53078bf0000000000000001005054474d0113001603001793a28e2e5b4cb88f69e96fb29a8287a88b23f0e99f5502f81744e904da8e3b4d000c9a4066ce1fa26da1c102a3e268abd3ca58e3b3c25f250e6ad9a3525066fbf8b00012f7778ca023d5cbe37449bab2faa2a133fe02b056c2c25605950320df08750f35";
173-
execute_governance_instruction(vaa_bytes);
180+
governance::execute_governance_instruction(vaa_bytes);
174181
}
175182

176183
#[test]
@@ -189,7 +196,7 @@ module pyth::governance {
189196
// }
190197
let vaa_bytes = x"010000000001002242229aec7d320a437cb241672dacfbc34c9155c02f60cd806bbfcd69bb7ba667fc069e372ae0443a7f3e08eaad61930b00784faeb2b72ecf5d1b0f0fa486a101527e4f9b000000010032f06413c0148c78916554f134dcd17a7c8029a3a2bda475a4a1182305c53078bf0000000000000005005054474d01000016a381a47fd0e97f34c71ef491c82208f58cd0080e784c697e65966d2a25d20d56";
191198

192-
execute_governance_instruction(vaa_bytes);
199+
governance::execute_governance_instruction(vaa_bytes);
193200
assert!(state::get_last_executed_governance_sequence() == 5, 1);
194201

195202
assert!(state::get_contract_upgrade_authorized_hash() ==
@@ -213,7 +220,7 @@ module pyth::governance {
213220
// }
214221
let vaa_bytes = x"01000000000100303c10020c537205ed0322b7ec9d9b296f4e3e12e39ebde985ed4ef4c8f5565256cfc6f90800c4683dba62b577cc994e2ca9135d32b955040b94718cdcb5527600527e4f9b000000010032f06413c0148c78916554f134dcd17a7c8029a3a2bda475a4a1182305c53078bf0000000000000005005054474d01000000a381a47fd0e97f34c71ef491c82208f58cd0080e784c697e65966d2a25d20d56";
215222

216-
execute_governance_instruction(vaa_bytes);
223+
governance::execute_governance_instruction(vaa_bytes);
217224
assert!(state::get_last_executed_governance_sequence() == 5, 1);
218225

219226
assert!(state::get_contract_upgrade_authorized_hash() ==
@@ -245,7 +252,7 @@ module pyth::governance {
245252
// }
246253
let vaa_bytes = x"01000000000100e8ce9e581b64ab7fbe168a0d9f86d1d2220e57947fb0c75174849838104d5fdf39ceb52ca44706bbe2817e6d33dd84ff92dc13ffe024578722178602ffd1775b01527e4f9b000000010032f06413c0148c78916554f134dcd17a7c8029a3a2bda475a4a1182305c53078bf000000000000001b005054474d010100160009625bae57728a368652a0ab0a89808de5fffa61d3312f1a27c3e200e99b1f3058000000000000000a";
247254

248-
execute_governance_instruction(vaa_bytes);
255+
governance::execute_governance_instruction(vaa_bytes);
249256

250257
// Check that the governance data source and sequence number has been updated correctly
251258
assert!(state::get_last_executed_governance_sequence() == 10, 1);
@@ -266,7 +273,7 @@ module pyth::governance {
266273
// threshold: 900
267274
// }
268275
let second_vaa_bytes = x"010000000001008df31b9853fe9f49b1949b66e10795595c37dfc5dede5ea15c1d136cc104843e2048488dfffc3d791ac1c11c71cdb7b73f250b00eb6977cd80e943542142c3a500527e4f9b000000010009625bae57728a368652a0ab0a89808de5fffa61d3312f1a27c3e200e99b1f3058000000000000000f005054474d010400160000000000000384";
269-
execute_governance_instruction(second_vaa_bytes);
276+
governance::execute_governance_instruction(second_vaa_bytes);
270277

271278
assert!(state::get_last_executed_governance_sequence() == 15, 1);
272279
assert!(state::get_stale_price_threshold_secs() == 900, 1);
@@ -298,7 +305,7 @@ module pyth::governance {
298305
// }
299306
let vaa_bytes = x"01000000000100e8ce9e581b64ab7fbe168a0d9f86d1d2220e57947fb0c75174849838104d5fdf39ceb52ca44706bbe2817e6d33dd84ff92dc13ffe024578722178602ffd1775b01527e4f9b000000010032f06413c0148c78916554f134dcd17a7c8029a3a2bda475a4a1182305c53078bf000000000000001b005054474d010100160009625bae57728a368652a0ab0a89808de5fffa61d3312f1a27c3e200e99b1f3058000000000000000a";
300307

301-
execute_governance_instruction(vaa_bytes);
308+
governance::execute_governance_instruction(vaa_bytes);
302309

303310
// Check that the governance data source and sequence number has been updated correctly
304311
assert!(state::get_last_executed_governance_sequence() == 10, 1);
@@ -313,7 +320,7 @@ module pyth::governance {
313320
// - Emitter address 0xf06413c0148c78916554f134dcd17a7c8029a3a2bda475a4a1182305c53078bf
314321
// - Sequence number 30
315322
let second_vaa_bytes = x"010000000001000e2670b14d716673d44f3766684a42a55c49feaf9a38acffb6971ec66fee2a211e7260413ccf4e3de608111dc0b92a131e8c9b8f5e83e6c36d5fc2228e46eb2d01527e4f9b000000010032f06413c0148c78916554f134dcd17a7c8029a3a2bda475a4a1182305c53078bf000000000000001e005054474d010400160000000000000384";
316-
execute_governance_instruction(second_vaa_bytes);
323+
governance::execute_governance_instruction(second_vaa_bytes);
317324
}
318325

319326
#[test]
@@ -335,7 +342,7 @@ module pyth::governance {
335342
// }
336343
let vaa_bytes = x"010000000001009f843a3359e75940cad00eaec50a1ac075aca3248634576437cfd53d95c2e29859a3a1902a3ef3e0529b434cf63ce96b21e4e6c05204ba62a446371aa132174000527e4f9b000000010032f06413c0148c78916554f134dcd17a7c8029a3a2bda475a4a1182305c53078bf0000000000000001005054474d0103001600000000000000110000000000000003";
337344

338-
execute_governance_instruction(vaa_bytes);
345+
governance::execute_governance_instruction(vaa_bytes);
339346
assert!(state::get_last_executed_governance_sequence() == 1, 1);
340347

341348
let expected = 17000;
@@ -360,7 +367,7 @@ module pyth::governance {
360367
// }
361368
let vaa_bytes = x"01000000000100e863ad8824f2c2a1695c6b028fa36c5f654b5f3e8d33712032aa3a2197329f3e2c59fc86cc026e6c68608d9e13982f2a22098bbc877ae2b106f6659ea320850a00527e4f9b000000010032f06413c0148c78916554f134dcd17a7c8029a3a2bda475a4a1182305c53078bf0000000000000001005054474d0104001600000000000002f4";
362369

363-
execute_governance_instruction(vaa_bytes);
370+
governance::execute_governance_instruction(vaa_bytes);
364371
assert!(state::get_last_executed_governance_sequence() == 1, 1);
365372

366373
assert!(state::get_stale_price_threshold_secs() == 756, 1);
@@ -391,7 +398,7 @@ module pyth::governance {
391398
state::set_data_sources(vector<DataSource>[initial_data_source]);
392399

393400
// Execute the VAA
394-
execute_governance_instruction(vaa_bytes);
401+
governance::execute_governance_instruction(vaa_bytes);
395402
assert!(state::get_last_executed_governance_sequence() == 1, 1);
396403

397404
// Check that the data sources have been set correctly

0 commit comments

Comments
 (0)