Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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
5 changes: 5 additions & 0 deletions .changeset/fruity-impalas-sit.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@orca-so/whirlpools-program": patch
---

Add unit tests to validate account discriminators
19 changes: 19 additions & 0 deletions programs/whirlpool/src/state/adaptive_fee_tier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,25 @@ impl AdaptiveFeeTier {
}
}

#[cfg(test)]
mod discriminator_tests {
use anchor_lang::Discriminator;

use super::*;

#[test]
fn test_discriminator() {
let discriminator = AdaptiveFeeTier::discriminator();
// The discriminator is determined by the struct name and not depending on the program id.
// $ echo -n account:AdaptiveFeeTier | sha256sum | cut -c 1-16
// 931090742f92952e
assert_eq!(
discriminator,
[0x93, 0x10, 0x90, 0x74, 0x2f, 0x92, 0x95, 0x2e]
);
}
}

#[cfg(test)]
mod data_layout_tests {
use anchor_lang::Discriminator;
Expand Down
19 changes: 19 additions & 0 deletions programs/whirlpool/src/state/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,25 @@ pub enum ConfigFeatureFlag {
TokenBadge(bool),
}

#[cfg(test)]
mod discriminator_tests {
use anchor_lang::Discriminator;

use super::*;

#[test]
fn test_discriminator() {
let discriminator = WhirlpoolsConfig::discriminator();
// The discriminator is determined by the struct name and not depending on the program id.
// $ echo -n account:WhirlpoolsConfig | sha256sum | cut -c 1-16
// 9d1431e0d957c1fe
assert_eq!(
discriminator,
[0x9d, 0x14, 0x31, 0xe0, 0xd9, 0x57, 0xc1, 0xfe]
);
}
}

#[cfg(test)]
mod data_layout_tests {
use anchor_lang::Discriminator;
Expand Down
19 changes: 19 additions & 0 deletions programs/whirlpool/src/state/config_extension.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,25 @@ mod whirlpools_config_extension_initialize_tests {
}
}

#[cfg(test)]
mod discriminator_tests {
use anchor_lang::Discriminator;

use super::*;

#[test]
fn test_discriminator() {
let discriminator = WhirlpoolsConfigExtension::discriminator();
// The discriminator is determined by the struct name and not depending on the program id.
// $ echo -n account:WhirlpoolsConfigExtension | sha256sum | cut -c 1-16
// 0263d7a3f01a993a
assert_eq!(
discriminator,
[0x2, 0x63, 0xd7, 0xa3, 0xf0, 0x1a, 0x99, 0x3a]
);
}
}

#[cfg(test)]
mod whirlpools_config_extension_update_tests {
use super::*;
Expand Down
5 changes: 4 additions & 1 deletion programs/whirlpool/src/state/dynamic_tick_array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -949,7 +949,10 @@ mod discriminator_tests {
// The discriminator is determined by the struct name and not depending on the program id.
// $ echo -n account:DynamicTickArray | sha256sum | cut -c 1-16
// 11d8f68ee1c7da38
assert_eq!(discriminator, [17, 216, 246, 142, 225, 199, 218, 56]);
assert_eq!(
discriminator,
[0x11, 0xd8, 0xf6, 0x8e, 0xe1, 0xc7, 0xda, 0x38]
);
}
}

Expand Down
19 changes: 19 additions & 0 deletions programs/whirlpool/src/state/fee_tier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,25 @@ impl FeeTier {
}
}

#[cfg(test)]
mod discriminator_tests {
use anchor_lang::Discriminator;

use super::*;

#[test]
fn test_discriminator() {
let discriminator = FeeTier::discriminator();
// The discriminator is determined by the struct name and not depending on the program id.
// $ echo -n account:FeeTier | sha256sum | cut -c 1-16
// 384b9f4c8e44be69
assert_eq!(
discriminator,
[0x38, 0x4b, 0x9f, 0x4c, 0x8e, 0x44, 0xbe, 0x69]
);
}
}

#[cfg(test)]
mod data_layout_tests {
use anchor_lang::Discriminator;
Expand Down
19 changes: 19 additions & 0 deletions programs/whirlpool/src/state/fixed_tick_array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,25 @@ mod array_update_tests {
}
}

#[cfg(test)]
mod discriminator_tests {
use anchor_lang::Discriminator;

use super::*;

#[test]
fn test_discriminator() {
let discriminator = TickArray::discriminator();
// The discriminator is determined by the struct name and not depending on the program id.
// $ echo -n account:TickArray | sha256sum | cut -c 1-16
// 4561bdbe6e0742bb
assert_eq!(
discriminator,
[0x45, 0x61, 0xbd, 0xbe, 0x6e, 0x07, 0x42, 0xbb]
);
}
}

#[cfg(test)]
mod data_layout_tests {
use crate::state::NUM_REWARDS;
Expand Down
19 changes: 19 additions & 0 deletions programs/whirlpool/src/state/lock_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,25 @@ mod lock_config_initialize_tests {
}
}

#[cfg(test)]
mod discriminator_tests {
use anchor_lang::Discriminator;

use super::*;

#[test]
fn test_discriminator() {
let discriminator = LockConfig::discriminator();
// The discriminator is determined by the struct name and not depending on the program id.
// $ echo -n account:LockConfig | sha256sum | cut -c 1-16
// 6a2fee9f7c0ca0c0
assert_eq!(
discriminator,
[0x6a, 0x2f, 0xee, 0x9f, 0x7c, 0x0c, 0xa0, 0xc0]
);
}
}

#[cfg(test)]
mod data_layout_tests {
use anchor_lang::Discriminator;
Expand Down
19 changes: 19 additions & 0 deletions programs/whirlpool/src/state/oracle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -480,6 +480,25 @@ impl<'info> OracleAccessor<'info> {
}
}

#[cfg(test)]
mod discriminator_tests {
use anchor_lang::Discriminator;

use super::*;

#[test]
fn test_discriminator() {
let discriminator = Oracle::discriminator();
// The discriminator is determined by the struct name and not depending on the program id.
// $ echo -n account:Oracle | sha256sum | cut -c 1-16
// 8bc283b38cb3e5f4
assert_eq!(
discriminator,
[0x8b, 0xc2, 0x83, 0xb3, 0x8c, 0xb3, 0xe5, 0xf4]
);
}
}

#[cfg(test)]
mod data_layout_tests {
use super::*;
Expand Down
19 changes: 19 additions & 0 deletions programs/whirlpool/src/state/position.rs
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,25 @@ pub mod position_builder {
}
}

#[cfg(test)]
mod discriminator_tests {
use anchor_lang::Discriminator;

use super::*;

#[test]
fn test_discriminator() {
let discriminator = Position::discriminator();
// The discriminator is determined by the struct name and not depending on the program id.
// $ echo -n account:Position | sha256sum | cut -c 1-16
// aabc8fe47a40f7d0
assert_eq!(
discriminator,
[0xaa, 0xbc, 0x8f, 0xe4, 0x7a, 0x40, 0xf7, 0xd0]
);
}
}

#[cfg(test)]
mod data_layout_tests {
use anchor_lang::Discriminator;
Expand Down
19 changes: 19 additions & 0 deletions programs/whirlpool/src/state/position_bundle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,25 @@ mod position_bundle_open_and_close_tests {
}
}

#[cfg(test)]
mod discriminator_tests {
use anchor_lang::Discriminator;

use super::*;

#[test]
fn test_discriminator() {
let discriminator = PositionBundle::discriminator();
// The discriminator is determined by the struct name and not depending on the program id.
// $ echo -n account:PositionBundle | sha256sum | cut -c 1-16
// 81a9af41b95f2064
assert_eq!(
discriminator,
[0x81, 0xa9, 0xaf, 0x41, 0xb9, 0x5f, 0x20, 0x64]
);
}
}

#[cfg(test)]
mod data_layout_tests {
use anchor_lang::Discriminator;
Expand Down
19 changes: 19 additions & 0 deletions programs/whirlpool/src/state/token_badge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,25 @@ mod token_badge_initialize_tests {
}
}

#[cfg(test)]
mod discriminator_tests {
use anchor_lang::Discriminator;

use super::*;

#[test]
fn test_discriminator() {
let discriminator = TokenBadge::discriminator();
// The discriminator is determined by the struct name and not depending on the program id.
// $ echo -n account:TokenBadge | sha256sum | cut -c 1-16
// 74dbcce5f974ff96
assert_eq!(
discriminator,
[0x74, 0xdb, 0xcc, 0xe5, 0xf9, 0x74, 0xff, 0x96]
);
}
}

#[cfg(test)]
mod data_layout_tests {
use anchor_lang::Discriminator;
Expand Down
19 changes: 19 additions & 0 deletions programs/whirlpool/src/state/whirlpool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -558,6 +558,25 @@ pub mod whirlpool_builder {
}
}

#[cfg(test)]
mod discriminator_tests {
use anchor_lang::Discriminator;

use super::*;

#[test]
fn test_discriminator() {
let discriminator = Whirlpool::discriminator();
// The discriminator is determined by the struct name and not depending on the program id.
// $ echo -n account:Whirlpool | sha256sum | cut -c 1-16
// 3f95d10ce1806309
assert_eq!(
discriminator,
[0x3f, 0x95, 0xd1, 0x0c, 0xe1, 0x80, 0x63, 0x09]
);
}
}

#[cfg(test)]
mod data_layout_tests {
use anchor_lang::Discriminator;
Expand Down