Skip to content

Commit

Permalink
Fix for missing init for next order id. (#189)
Browse files Browse the repository at this point in the history
* Fix for missing init for next order id.

* Update audit.
  • Loading branch information
piobab authored Dec 10, 2024
1 parent 18e617a commit 5334a9b
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 2 deletions.
2 changes: 1 addition & 1 deletion .cargo/audit.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@
# Ignore the following advisory IDs.
# Reported vulnerabilities relate to test-tube which is only used for testing.
# RUSTSEC-2024-0344 - no newer dependency fixing the issue in cosmwasm
ignore = ["RUSTSEC-2024-0003", "RUSTSEC-2024-0006", "RUSTSEC-2024-0019", "RUSTSEC-2024-0332", "RUSTSEC-2024-0336", "RUSTSEC-2024-0344"]
ignore = ["RUSTSEC-2024-0003", "RUSTSEC-2024-0006", "RUSTSEC-2024-0019", "RUSTSEC-2024-0332", "RUSTSEC-2024-0336", "RUSTSEC-2024-0344", "RUSTSEC-2024-0421"]
3 changes: 3 additions & 0 deletions contracts/credit-manager/src/migrations/v2_2_0.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use cw2::{assert_contract_version, set_contract_version};
use crate::{
contract::{CONTRACT_NAME, CONTRACT_VERSION},
error::ContractError,
state::NEXT_TRIGGER_ID,
};

const FROM_VERSION: &str = "2.1.0";
Expand All @@ -12,6 +13,8 @@ pub fn migrate(deps: DepsMut) -> Result<Response, ContractError> {
// make sure we're migrating the correct contract and from the correct version
assert_contract_version(deps.storage, &format!("crates.io:{CONTRACT_NAME}"), FROM_VERSION)?;

NEXT_TRIGGER_ID.save(deps.storage, &1)?;

set_contract_version(deps.storage, format!("crates.io:{CONTRACT_NAME}"), CONTRACT_VERSION)?;

Ok(Response::new()
Expand Down
5 changes: 4 additions & 1 deletion contracts/credit-manager/tests/tests/test_migration_v2.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use cosmwasm_std::{attr, testing::mock_env, Empty, Event};
use cw2::{ContractVersion, VersionError};
use mars_credit_manager::{contract::migrate, error::ContractError};
use mars_credit_manager::{contract::migrate, error::ContractError, state::NEXT_TRIGGER_ID};
use mars_testing::mock_dependencies;

#[test]
Expand Down Expand Up @@ -44,6 +44,9 @@ fn successful_migration() {

let res = migrate(deps.as_mut(), mock_env(), Empty {}).unwrap();

let order_id = NEXT_TRIGGER_ID.load(deps.as_ref().storage).unwrap();
assert_eq!(order_id, 1);

assert_eq!(res.messages, vec![]);
assert_eq!(res.events, vec![] as Vec<Event>);
assert!(res.data.is_none());
Expand Down

0 comments on commit 5334a9b

Please sign in to comment.