Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ mod test {
use motsu::prelude::*;
use pythnet_sdk::wire::v1::{AccumulatorUpdateData, Proof};
use std::time::Duration;
use stylus_sdk::types::AddressVM;
use wormhole_contract::WormholeContract;

const PYTHNET_CHAIN_ID: u16 = 26;
Expand Down Expand Up @@ -106,8 +107,12 @@ mod test {
let result = pyth_contract
.sender_and_value(alice, update_fee)
.update_price_feeds(update_data);

assert!(result.is_ok());

assert_eq!(alice.balance(), U256::ZERO);
assert_eq!(pyth_contract.balance(), update_fee);

let price_result = pyth_contract
.sender(alice)
.get_price_unsafe(ban_usd_feed_id());
Expand Down Expand Up @@ -157,11 +162,17 @@ mod test {
.update_price_feeds(update_data1);
assert!(result1.is_ok());

assert_eq!(alice.balance(), update_fee2);
assert_eq!(pyth_contract.balance(), update_fee1);

let result2 = pyth_contract
.sender_and_value(alice, update_fee2)
.update_price_feeds(update_data2);
assert!(result2.is_ok());

assert_eq!(alice.balance(), U256::ZERO);
assert_eq!(pyth_contract.balance(), update_fee1 + update_fee2);

let price_result = pyth_contract
.sender(alice)
.get_price_unsafe(ban_usd_feed_id());
Expand Down Expand Up @@ -231,6 +242,9 @@ mod test {
.update_price_feeds(update_data);
assert!(result.is_ok());

assert_eq!(alice.balance(), U256::ZERO);
assert_eq!(pyth_contract.balance(), update_fee);

let price_result = pyth_contract
.sender(alice)
.get_price_no_older_than(btc_usd_feed_id(), u64::MAX);
Expand All @@ -257,6 +271,9 @@ mod test {
.update_price_feeds(update_data);
assert!(result.is_ok());

assert_eq!(alice.balance(), U256::ZERO);
assert_eq!(pyth_contract.balance(), update_fee);

let price_result = pyth_contract
.sender(alice)
.get_price_no_older_than(btc_usd_feed_id(), 1);
Expand Down Expand Up @@ -286,6 +303,9 @@ mod test {
.update_price_feeds(update_data);
assert!(result.is_ok());

assert_eq!(alice.balance(), U256::ZERO);
assert_eq!(pyth_contract.balance(), update_fee);

let first_price_result = pyth_contract
.sender(alice)
.get_price_unsafe(ban_usd_feed_id());
Expand Down Expand Up @@ -327,6 +347,9 @@ mod test {
.update_price_feeds(update_data);
assert!(result.is_ok());

assert_eq!(alice.balance(), U256::ZERO);
assert_eq!(pyth_contract.balance(), update_fee);

assert!(pyth_contract
.sender(alice)
.price_feed_exists(ban_usd_feed_id()));
Expand Down Expand Up @@ -368,6 +391,9 @@ mod test {
.sender_and_value(alice, update_fee)
.update_price_feeds(update_data);

assert_eq!(alice.balance(), U256::ZERO);
assert_eq!(pyth_contract.balance(), update_fee);

assert!(result.is_ok());

let price_result = pyth_contract
Expand Down Expand Up @@ -395,6 +421,9 @@ mod test {
.sender_and_value(alice, update_fee)
.update_price_feeds(update_data);

assert_eq!(alice.balance(), U256::ZERO);
assert_eq!(pyth_contract.balance(), update_fee);

assert!(result.is_ok());

let price_result1 = pyth_contract
Expand Down
10 changes: 5 additions & 5 deletions target_chains/stylus/contracts/pyth-receiver/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -213,17 +213,17 @@ impl PythReceiver {
&mut self,
update_data: Vec<Vec<u8>>,
) -> Result<(), PythReceiverError> {
for data in &update_data {
self.update_price_feeds_internal(data.clone(), 0, 0, false)?;
}

let total_fee = self.get_update_fee(update_data)?;
let total_fee = self.get_update_fee(update_data.clone())?;

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

if value < total_fee {
return Err(PythReceiverError::InsufficientFee);
}

for data in &update_data {
self.update_price_feeds_internal(data.clone(), 0, 0, false)?;
}
Ok(())
}

Expand Down