Skip to content

Commit 3d76021

Browse files
committed
fixed order
1 parent 6635edd commit 3d76021

File tree

2 files changed

+34
-5
lines changed

2 files changed

+34
-5
lines changed

target_chains/stylus/contracts/pyth-receiver/src/integration_tests.rs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ mod test {
88
use motsu::prelude::*;
99
use pythnet_sdk::wire::v1::{AccumulatorUpdateData, Proof};
1010
use std::time::Duration;
11+
use stylus_sdk::types::AddressVM;
1112
use wormhole_contract::WormholeContract;
1213

1314
const PYTHNET_CHAIN_ID: u16 = 26;
@@ -106,8 +107,12 @@ mod test {
106107
let result = pyth_contract
107108
.sender_and_value(alice, update_fee)
108109
.update_price_feeds(update_data);
110+
109111
assert!(result.is_ok());
110112

113+
assert_eq!(alice.balance(), U256::ZERO);
114+
assert_eq!(pyth_contract.balance(), update_fee);
115+
111116
let price_result = pyth_contract
112117
.sender(alice)
113118
.get_price_unsafe(ban_usd_feed_id());
@@ -157,11 +162,17 @@ mod test {
157162
.update_price_feeds(update_data1);
158163
assert!(result1.is_ok());
159164

165+
assert_eq!(alice.balance(), update_fee2);
166+
assert_eq!(pyth_contract.balance(), update_fee1);
167+
160168
let result2 = pyth_contract
161169
.sender_and_value(alice, update_fee2)
162170
.update_price_feeds(update_data2);
163171
assert!(result2.is_ok());
164172

173+
assert_eq!(alice.balance(), U256::ZERO);
174+
assert_eq!(pyth_contract.balance(), update_fee1 + update_fee2);
175+
165176
let price_result = pyth_contract
166177
.sender(alice)
167178
.get_price_unsafe(ban_usd_feed_id());
@@ -231,6 +242,9 @@ mod test {
231242
.update_price_feeds(update_data);
232243
assert!(result.is_ok());
233244

245+
assert_eq!(alice.balance(), U256::ZERO);
246+
assert_eq!(pyth_contract.balance(), update_fee);
247+
234248
let price_result = pyth_contract
235249
.sender(alice)
236250
.get_price_no_older_than(btc_usd_feed_id(), u64::MAX);
@@ -257,6 +271,9 @@ mod test {
257271
.update_price_feeds(update_data);
258272
assert!(result.is_ok());
259273

274+
assert_eq!(alice.balance(), U256::ZERO);
275+
assert_eq!(pyth_contract.balance(), update_fee);
276+
260277
let price_result = pyth_contract
261278
.sender(alice)
262279
.get_price_no_older_than(btc_usd_feed_id(), 1);
@@ -286,6 +303,9 @@ mod test {
286303
.update_price_feeds(update_data);
287304
assert!(result.is_ok());
288305

306+
assert_eq!(alice.balance(), U256::ZERO);
307+
assert_eq!(pyth_contract.balance(), update_fee);
308+
289309
let first_price_result = pyth_contract
290310
.sender(alice)
291311
.get_price_unsafe(ban_usd_feed_id());
@@ -327,6 +347,9 @@ mod test {
327347
.update_price_feeds(update_data);
328348
assert!(result.is_ok());
329349

350+
assert_eq!(alice.balance(), U256::ZERO);
351+
assert_eq!(pyth_contract.balance(), update_fee);
352+
330353
assert!(pyth_contract
331354
.sender(alice)
332355
.price_feed_exists(ban_usd_feed_id()));
@@ -368,6 +391,9 @@ mod test {
368391
.sender_and_value(alice, update_fee)
369392
.update_price_feeds(update_data);
370393

394+
assert_eq!(alice.balance(), U256::ZERO);
395+
assert_eq!(pyth_contract.balance(), update_fee);
396+
371397
assert!(result.is_ok());
372398

373399
let price_result = pyth_contract
@@ -395,6 +421,9 @@ mod test {
395421
.sender_and_value(alice, update_fee)
396422
.update_price_feeds(update_data);
397423

424+
assert_eq!(alice.balance(), U256::ZERO);
425+
assert_eq!(pyth_contract.balance(), update_fee);
426+
398427
assert!(result.is_ok());
399428

400429
let price_result1 = pyth_contract

target_chains/stylus/contracts/pyth-receiver/src/lib.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -213,17 +213,17 @@ impl PythReceiver {
213213
&mut self,
214214
update_data: Vec<Vec<u8>>,
215215
) -> Result<(), PythReceiverError> {
216-
for data in &update_data {
217-
self.update_price_feeds_internal(data.clone(), 0, 0, false)?;
218-
}
219-
220-
let total_fee = self.get_update_fee(update_data)?;
216+
let total_fee = self.get_update_fee(update_data.clone())?;
221217

222218
let value = self.vm().msg_value();
223219

224220
if value < total_fee {
225221
return Err(PythReceiverError::InsufficientFee);
226222
}
223+
224+
for data in &update_data {
225+
self.update_price_feeds_internal(data.clone(), 0, 0, false)?;
226+
}
227227
Ok(())
228228
}
229229

0 commit comments

Comments
 (0)