Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Remove debt from total deposit. (#351)
* Remove debt from total deposit. * Add migration and use proper version.
- Loading branch information
Showing
12 changed files
with
105 additions
and
23 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
pub mod v2_0_1; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
use cosmwasm_std::{DepsMut, Response}; | ||
use cw2::{assert_contract_version, set_contract_version}; | ||
|
||
use crate::{ | ||
contract::{CONTRACT_NAME, CONTRACT_VERSION}, | ||
error::ContractError, | ||
}; | ||
|
||
const FROM_VERSION: &str = "2.0.0"; | ||
|
||
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)?; | ||
|
||
set_contract_version(deps.storage, format!("crates.io:{CONTRACT_NAME}"), CONTRACT_VERSION)?; | ||
|
||
Ok(Response::new() | ||
.add_attribute("action", "migrate") | ||
.add_attribute("from_version", FROM_VERSION) | ||
.add_attribute("to_version", CONTRACT_VERSION)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
use cosmwasm_std::{ | ||
attr, | ||
testing::{mock_dependencies, mock_env}, | ||
Empty, Event, | ||
}; | ||
use cw2::{ContractVersion, VersionError}; | ||
use mars_params::{contract::migrate, error::ContractError}; | ||
|
||
#[test] | ||
fn wrong_contract_name() { | ||
let mut deps = mock_dependencies(); | ||
cw2::set_contract_version(deps.as_mut().storage, "contract_xyz", "1.0.0").unwrap(); | ||
|
||
let err = migrate(deps.as_mut(), mock_env(), Empty {}).unwrap_err(); | ||
|
||
assert_eq!( | ||
err, | ||
ContractError::Version(VersionError::WrongContract { | ||
expected: "crates.io:mars-params".to_string(), | ||
found: "contract_xyz".to_string() | ||
}) | ||
); | ||
} | ||
|
||
#[test] | ||
fn wrong_contract_version() { | ||
let mut deps = mock_dependencies(); | ||
cw2::set_contract_version(deps.as_mut().storage, "crates.io:mars-params", "4.1.0").unwrap(); | ||
|
||
let err = migrate(deps.as_mut(), mock_env(), Empty {}).unwrap_err(); | ||
|
||
assert_eq!( | ||
err, | ||
ContractError::Version(VersionError::WrongVersion { | ||
expected: "2.0.0".to_string(), | ||
found: "4.1.0".to_string() | ||
}) | ||
); | ||
} | ||
|
||
#[test] | ||
fn successful_migration_to_v2_0_1() { | ||
let mut deps = mock_dependencies(); | ||
cw2::set_contract_version(deps.as_mut().storage, "crates.io:mars-params", "2.0.0").unwrap(); | ||
|
||
let res = migrate(deps.as_mut(), mock_env(), Empty {}).unwrap(); | ||
|
||
assert_eq!(res.messages, vec![]); | ||
assert_eq!(res.events, vec![] as Vec<Event>); | ||
assert!(res.data.is_none()); | ||
assert_eq!( | ||
res.attributes, | ||
vec![attr("action", "migrate"), attr("from_version", "2.0.0"), attr("to_version", "2.0.1")] | ||
); | ||
|
||
let new_contract_version = ContractVersion { | ||
contract: "crates.io:mars-params".to_string(), | ||
version: "2.0.1".to_string(), | ||
}; | ||
assert_eq!(cw2::get_contract_version(deps.as_ref().storage).unwrap(), new_contract_version); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters