Skip to content

Commit

Permalink
PR: decimal value shall not be greater than 18 (#309)
Browse files Browse the repository at this point in the history
* PR: decimal value shall not be greater than 18

* test.rs: decimal_is_over_eighteen() test added

* test.rs: cargo fmt changes
  • Loading branch information
unboxedtype authored May 28, 2024
1 parent 002edec commit fbf4860
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 10 deletions.
4 changes: 2 additions & 2 deletions token/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ impl Token {
panic!("already initialized")
}
write_administrator(&e, &admin);
if decimal > u8::MAX.into() {
panic!("Decimal must fit in a u8");
if decimal > 18 {
panic!("Decimal must not be greater than 18");
}

write_metadata(
Expand Down
11 changes: 3 additions & 8 deletions token/src/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -242,17 +242,12 @@ fn initialize_already_initialized() {
}

#[test]
#[should_panic(expected = "Decimal must fit in a u8")]
fn decimal_is_over_max() {
#[should_panic(expected = "Decimal must not be greater than 18")]
fn decimal_is_over_eighteen() {
let e = Env::default();
let admin = Address::generate(&e);
let token = TokenClient::new(&e, &e.register_contract(None, Token {}));
token.initialize(
&admin,
&(u32::from(u8::MAX) + 1),
&"name".into_val(&e),
&"symbol".into_val(&e),
);
token.initialize(&admin, &19, &"name".into_val(&e), &"symbol".into_val(&e));
}

#[test]
Expand Down

0 comments on commit fbf4860

Please sign in to comment.