diff --git a/contract/src/score/account_score.rs b/contract/src/score/account_score.rs index 7e965b21..bf0be76b 100644 --- a/contract/src/score/account_score.rs +++ b/contract/src/score/account_score.rs @@ -109,7 +109,7 @@ impl AccountScore { fn update_today(&mut self, chain: Chain) -> Vec { for (score, day) in chain { let day_index: usize = day.0.try_into().unwrap(); - self.scores[day_index] += score; + self.scores[day_index] = self.scores[day_index].checked_add(score).unwrap_or(u16::MAX); self.scores_history[day_index] = self.scores_history[day_index].checked_add(score).unwrap_or(u16::MAX); } vec![] diff --git a/contract/src/score/tests.rs b/contract/src/score/tests.rs index c24a0134..0e458936 100644 --- a/contract/src/score/tests.rs +++ b/contract/src/score/tests.rs @@ -413,3 +413,24 @@ fn test_steps_history() { check_score_interest(&ctx, 0); } + +#[test] +fn record_max_score() { + const ALICE_JAR: JarId = 0; + + set_test_log_events(false); + + let mut ctx = TestBuilder::new() + .product(SCORE_PRODUCT, [APY(0), TermDays(10), ScoreCap(20_000)]) + .jar(ALICE_JAR, JarField::Timezone(Timezone::hour_shift(4))) + .build(); + + ctx.record_score(UTC(0), 25000, alice()); + ctx.record_score(UTC(0), 25000, alice()); + ctx.record_score(UTC(0), 25000, alice()); + ctx.record_score(UTC(0), 25000, alice()); + + ctx.set_block_timestamp_in_days(1); + + assert_eq!(ctx.contract().get_score_interest(alice()).unwrap().0, 65535); +} diff --git a/res/sweat_jar.wasm b/res/sweat_jar.wasm index b64b3131..35fca13e 100755 Binary files a/res/sweat_jar.wasm and b/res/sweat_jar.wasm differ