Skip to content

Commit 458e49b

Browse files
authored
Move tests to rust (#352)
* Fix * Checkpoitn * Checkpoint * Cleanup * Cleanup * More cleanup * Cleanup * Cleanup * Refactor process_ixs * More cleanup * add more tests * Add more checks * CI * More refactor * Match original test
1 parent d083104 commit 458e49b

File tree

8 files changed

+515
-43
lines changed

8 files changed

+515
-43
lines changed

program/rust/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ solana-sdk = "=1.13.3"
2121
tokio = "1.14.1"
2222
hex = "0.3.1"
2323
quickcheck = "1"
24+
rand = "0.8.5"
2425
quickcheck_macros = "1"
2526
bincode = "1.3.3"
2627
serde = { version = "1.0", features = ["derive"] }

program/rust/src/processor/upd_price.rs

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,13 @@ use {
44
PriceAccount,
55
PriceInfo,
66
},
7-
c_oracle_header::{
8-
MAX_CI_DIVISOR,
9-
PC_STATUS_IGNORED,
10-
},
117
deserialize::{
128
load,
139
load_checked,
1410
},
1511
instruction::UpdPriceArgs,
1612
utils::{
13+
check_confidence_too_big,
1714
check_valid_funding_account,
1815
check_valid_writable_account,
1916
is_component_update,
@@ -145,18 +142,11 @@ pub fn upd_price(
145142
}
146143
}
147144

145+
148146
// Try to update the publisher's price
149147
if is_component_update(cmd_args)? {
150-
let mut status: u32 = cmd_args.status;
151-
let mut threshold_conf = cmd_args.price / MAX_CI_DIVISOR;
152-
153-
if threshold_conf < 0 {
154-
threshold_conf = -threshold_conf;
155-
}
156-
157-
if cmd_args.confidence > try_convert::<_, u64>(threshold_conf)? {
158-
status = PC_STATUS_IGNORED
159-
}
148+
let status: u32 =
149+
check_confidence_too_big(cmd_args.price, cmd_args.confidence, cmd_args.status)?;
160150

161151
{
162152
let mut price_data =

program/rust/src/tests/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ mod test_ema;
1212
mod test_init_mapping;
1313
mod test_init_price;
1414
mod test_permission_migration;
15+
mod test_publish;
16+
mod test_publish_batch;
1517
mod test_set_min_pub;
1618
mod test_sizes;
1719
mod test_sma;

0 commit comments

Comments
 (0)