Skip to content

Commit

Permalink
Address feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
joncinque committed Nov 22, 2024
1 parent 109e835 commit 688ef3b
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 1 deletion.
36 changes: 36 additions & 0 deletions token/program-2022-test/tests/scaled_ui_amount.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,27 @@ async fn fail_initialize_with_interest_bearing() {
);
}

#[tokio::test]
async fn fail_initialize_with_bad_multiplier() {
let mut context = TestContext::new().await;
let err = context
.init_token_with_mint(vec![ExtensionInitializationParams::ScaledUiAmountConfig {
authority: None,
multiplier: 0.0,
}])
.await
.unwrap_err();
assert_eq!(
err,
TokenClientError::Client(Box::new(TransportError::TransactionError(
TransactionError::InstructionError(
1,
InstructionError::Custom(TokenError::InvalidScale as u32)
)
)))
);
}

#[tokio::test]
async fn update_multiplier() {
let authority = Keypair::new();
Expand Down Expand Up @@ -115,6 +136,21 @@ async fn update_multiplier() {
assert_eq!(f64::from(extension.new_multiplier), new_multiplier);
assert_eq!(i64::from(extension.new_multiplier_effective_timestamp), 0);

// fail, bad number
let err = token
.update_multiplier(&authority.pubkey(), f64::INFINITY, 0, &[&authority])
.await
.unwrap_err();
assert_eq!(
err,
TokenClientError::Client(Box::new(TransportError::TransactionError(
TransactionError::InstructionError(
0,
InstructionError::Custom(TokenError::InvalidScale as u32)
)
)))
);

// correct in the future
let newest_multiplier = 100.0;
token
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ pub enum ScaledUiAmountMintInstruction {
/// Fails if the mint has already been initialized, so must be called before
/// `InitializeMint`.
///
/// Fails with any number less than 0.
/// Fails if the multiplier is less than or equal to 0 or if it's
/// [subnormal](https://en.wikipedia.org/wiki/Subnormal_number).
///
/// The mint must have exactly enough space allocated for the base mint (82
/// bytes), plus 83 bytes of padding, 1 byte reserved for the account type,
Expand All @@ -44,6 +45,9 @@ pub enum ScaledUiAmountMintInstruction {
/// Update the multiplier. Only supported for mints that include the
/// `ScaledUiAmount` extension.
///
/// Fails if the multiplier is less than or equal to 0 or if it's
/// [subnormal](https://en.wikipedia.org/wiki/Subnormal_number).
///
/// The authority provides a new multiplier and a unix timestamp on which
/// it should take effect. If the timestamp is before the current time,
/// immediately sets the multiplier.
Expand Down

0 comments on commit 688ef3b

Please sign in to comment.