Skip to content

Commit

Permalink
fix: step migration
Browse files Browse the repository at this point in the history
  • Loading branch information
VladasZ committed Dec 9, 2024
1 parent 52f7198 commit b2c9c91
Show file tree
Hide file tree
Showing 7 changed files with 53 additions and 10 deletions.
4 changes: 2 additions & 2 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion contract/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "sweat_jar"
version = "3.4.0"
version = "3.4.1"
authors = ["Sweat Economy"]
edition = "2021"

Expand Down
12 changes: 6 additions & 6 deletions contract/src/event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ mod test {
fn test_contract_version() {
let admin = admin();
let context = Context::new(admin);
assert_eq!(context.contract().contract_version(), "sweat_jar-3.4.0");
assert_eq!(context.contract().contract_version(), "sweat_jar-3.4.1");
}

#[test]
Expand All @@ -200,7 +200,7 @@ mod test {
.to_json_event_string(),
r#"EVENT_JSON:{
"standard": "sweat_jar",
"version": "3.4.0",
"version": "3.4.1",
"event": "top_up",
"data": {
"id": 10,
Expand Down Expand Up @@ -228,7 +228,7 @@ mod test {
.to_json_event_string(),
r#"EVENT_JSON:{
"standard": "sweat_jar",
"version": "3.4.0",
"version": "3.4.1",
"event": "create_jar",
"data": {
"id": 555,
Expand All @@ -248,7 +248,7 @@ mod test {
SweatJarEvent::from(EventKind::Claim(vec![(1, 1.into()), (2, 2.into())])).to_json_event_string(),
r#"EVENT_JSON:{
"standard": "sweat_jar",
"version": "3.4.0",
"version": "3.4.1",
"event": "claim",
"data": [
[
Expand Down Expand Up @@ -277,7 +277,7 @@ mod test {
.to_json_event_string(),
r#"EVENT_JSON:{
"standard": "sweat_jar",
"version": "3.4.0",
"version": "3.4.1",
"event": "record_score",
"data": [
{
Expand Down Expand Up @@ -306,7 +306,7 @@ mod test {
SweatJarEvent::from(EventKind::OldScoreWarning((111, Local(5)))).to_json_event_string(),
r#"EVENT_JSON:{
"standard": "sweat_jar",
"version": "3.4.0",
"version": "3.4.1",
"event": "old_score_warning",
"data": [
111,
Expand Down
3 changes: 3 additions & 0 deletions contract/src/jar/model/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,9 @@ impl Contract {
let product = self.get_product(product_id);

if product.is_score_product() {
// For score products we need to migrate earlier to write timezone to already migrated account
self.migrate_account_if_needed(&account_id);

match (ticket.timezone, self.get_score_mut(&account_id)) {
// Time zone already set. No actions required.
(Some(_) | None, Some(_)) => (),
Expand Down
40 changes: 40 additions & 0 deletions contract/src/score/tests.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
#![cfg(test)]

use fake::Fake;
use near_contract_standards::fungible_token::receiver::FungibleTokenReceiver;
use near_sdk::{
json_types::{I64, U128},
serde_json::json,
store::LookupMap,
test_utils::test_env::{alice, bob},
NearToken, Timestamp,
Expand All @@ -19,6 +21,7 @@ use crate::{
test_data::{set_test_future_success, set_test_log_events},
tests::Context,
},
jar::model::AccountJarsLegacy,
test_builder::{JarField, ProductField::*, TestAccess, TestBuilder},
test_utils::{admin, expect_panic, UnwrapPromise, PRODUCT, SCORE_PRODUCT},
StorageKey,
Expand Down Expand Up @@ -460,3 +463,40 @@ fn claim_when_there_were_no_walkchains_for_some_time() {

assert_eq!(ctx.contract().get_total_interest(alice()).amount.total.0, 0);
}

#[test]
fn test_steps_and_migration() {
set_test_log_events(false);

let mut ctx = TestBuilder::new()
.product(SCORE_PRODUCT, [APY(0), TermDays(10), ScoreCap(20_000)])
.build();

ctx.contract().account_jars_v1.insert(
alice(),
AccountJarsLegacy {
last_id: 0,
jars: vec![],
},
);

ctx.switch_account_to_ft_contract_account();
ctx.contract().ft_on_transfer(
alice(),
10_000.into(),
json!({
"type": "stake",
"data": {
"ticket": {
"product_id": SCORE_PRODUCT,
"valid_until": "0",
"timezone": 0,
}
}
})
.to_string()
.into(),
);

ctx.record_score(UTC(0), 25000, alice());
}
2 changes: 1 addition & 1 deletion model/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "sweat-jar-model"
version = "3.4.0"
version = "3.4.1"
publish = false
edition = "2021"

Expand Down
Binary file modified res/sweat_jar.wasm
Binary file not shown.

0 comments on commit b2c9c91

Please sign in to comment.