Skip to content

Commit

Permalink
Use a fuzz-tested list of prices
Browse files Browse the repository at this point in the history
  • Loading branch information
kayabaNerve committed Feb 18, 2024
1 parent bd762a2 commit 7531750
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 102 deletions.
2 changes: 2 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions substrate/dex/pallet/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ coins-pallet = { package = "serai-coins-pallet", path = "../../coins/pallet", de

serai-primitives = { path = "../../primitives", default-features = false }

[dev-dependencies]
rand_core = { version = "0.6", default-features = false, features = ["getrandom"] }

[features]
default = ["std"]
std = [
Expand Down
109 changes: 7 additions & 102 deletions substrate/dex/pallet/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1271,111 +1271,16 @@ fn cannot_block_pool_creation() {
#[test]
fn test_median_price() {
new_test_ext().execute_with(|| {
let prices: Vec<u64> = vec![
89094597672602079,
9812545476752143188,
735020655991311,
9285083041886385685,
53762221139194,
13946534802749779967,
109372747683,
11819301306422986078,
737471142364463,
5198787146240868890,
12664490967510575660,
17980533125308,
13875105403707512416,
8588894095664203595,
4339496150923070988,
4231647914743370582,
10647602703415832559,
14880694170381462414,
6096962179554666106,
6659285945129437525,
16456564335889698351,
13845959324357347,
1648569167474441524,
13133695496521888158,
7616461337984068322,
12726729663511294792,
8000797058089650061,
15005828517346690662,
1793588,
7220477668898016104,
16181904040794627088,
14797634045215342682,
19639150764444,
8177870148422964533,
581491679308004752,
4314801822544279657,
94651700756056691,
96186224808132,
8410150218145059327,
14985557922391323432,
11352279857984687689,
34328309207209,
5611615379596223089,
18125943563248874553,
17533195941173182568,
18169879009154892725,
6008387172344065013,
2998266057356919988,
2644053484132935149,
11547298436182772089,
4586345667609119481,
6172439446948403799,
10626959711571315184,
12907610780314711856,
17196831155500322373,
15974476473205372690,
14655680501878891324,
6726170126210474968,
57886895824576419,
4617815046373141865,
17316901742166242228,
13898507508355951049,
10252715777491496804,
8757446702634329168,
3825982926411780397,
5429203804114305693,
14146937173155582346,
4166019698606353622,
11249167927606315147,
18015207767097956850,
13660375940391754802,
564863094733853289,
9530638362187710906,
3188632306609925749,
18113494183422781593,
1835777136545799569,
6632144245864749829,
8626951292883317778,
8029065522637372030,
5223975568957781514,
8948791824790231783,
8608930334805227719,
4018500067378149536,
3096559742628404701,
12236725434494870905,
1073499773668488616,
10723113063135353762,
13242954556652696261,
13691823023000210372,
12624898660330224628,
3250859179908177396,
13075208133426449118,
18011040994576979536,
1915235854583868831,
12468256923643148798,
95752683624580217,
1724650070088393290,
8239892706949648329,
7652806705326215966,
82960,
];
use rand_core::{RngCore, OsRng};

let mut prices = vec![];
for _ in 0 .. 100 {
prices.push(OsRng.next_u64());
}
let coin = Coin::Bitcoin;

let window_size = usize::try_from(ORACLE_WINDOWS_SIZE).unwrap();
assert!(prices.len() >= (2 * window_size));
for i in 0 .. prices.len() {
let price = prices[i];
let n = BlockNumberFor::<Test>::from(u32::try_from(i).unwrap());
Expand Down

0 comments on commit 7531750

Please sign in to comment.