Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: step migration #122

Merged
merged 3 commits into from
Dec 10, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
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
1 change: 0 additions & 1 deletion contract/src/internal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ impl Contract {
}

pub(crate) fn add_new_jar(&mut self, account_id: &AccountId, jar: Jar) {
self.migrate_account_if_needed(account_id);
let jars = self.accounts.entry(account_id.clone()).or_default();
jars.last_id = jar.id;
jars.push(jar);
Expand Down
2 changes: 2 additions & 0 deletions contract/src/jar/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ impl Contract {
let jar_id = jar_id.0;
let account_id = env::predecessor_account_id();

self.migrate_account_if_needed(&account_id);

let restaked_jar_id = self.increment_and_get_last_jar_id();

let jar = self.get_jar_internal(&account_id, jar_id);
Expand Down
7 changes: 5 additions & 2 deletions contract/src/jar/model/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,11 @@ impl Contract {
let product_id = &ticket.product_id;
let product = self.get_product(product_id);

product.assert_enabled();
product.assert_cap(amount);

self.migrate_account_if_needed(&account_id);

if product.is_score_product() {
match (ticket.timezone, self.get_score_mut(&account_id)) {
// Time zone already set. No actions required.
Expand All @@ -241,8 +246,6 @@ impl Contract {
}
}

product.assert_enabled();
product.assert_cap(amount);
self.verify(&account_id, amount, &ticket, signature);

let id = self.increment_and_get_last_jar_id();
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.
Loading