Skip to content

Commit

Permalink
feat: add migration logic based on semver comparison (#130)
Browse files Browse the repository at this point in the history
* add hpl-utils

* apply migrator (hpl-mailbox)

* apply migrator (hpl-va)

* apply migrator (hpl-hook-aggregate)

* chore: fmt

* apply migrator (hpl-hooks-fee)

* apply migrator (hpl-hooks-merkle)

* apply migrator (hpl-hooks-pausable)

* merge & simplify

* apply migrator (hpl-hook-routing)

* apply migrator (hpl-hook-routing-custom)

* apply migrator (hpl-hook-routing-fallback)

* apply migrator (hpl-igp)

* apply migrator (hpl-igp-oracle)

* apply migrator (hpl-ism-aggregate)

* apply migrator (hpl-ism-multisig)

* apply migrator (hpl-ism-pausable)

* apply migrator (hpl-ism-routing)

* apply migrator (hpl-test-mock-hook)

* apply migrator (hpl-test-mock-ism)

* apply migrator (hpl-test-mock-msg-receiver)

* apply migrator (hpl-warp-cw20)

* apply migrator (hpl-warp-native)

* allow & fmt
  • Loading branch information
byeongsu-hong authored May 16, 2024
1 parent df8a25c commit 00f64a9
Show file tree
Hide file tree
Showing 54 changed files with 333 additions and 73 deletions.
2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ cw20 = "1.1.2"
cw20-base = { version = "1.1.2", features = ["library"] }

# utilities
semver = "1.0.23"
thiserror = { version = "1.0.37" }
anyhow = { version = "1.0.71", features = ["backtrace"] }
eyre = { version = "0.6.8" }
Expand Down Expand Up @@ -115,3 +116,4 @@ hpl-ownable = { path = "./packages/ownable" }
hpl-pausable = { path = "./packages/pausable" }
hpl-router = { path = "./packages/router" }
hpl-interface = { path = "./packages/interface" }
hpl-utils = { path = "./packages/utils" }
1 change: 1 addition & 0 deletions contracts/core/mailbox/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ bech32.workspace = true

thiserror.workspace = true

hpl-utils.workspace = true
hpl-ownable.workspace = true
hpl-interface.workspace = true

Expand Down
3 changes: 2 additions & 1 deletion contracts/core/mailbox/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,8 @@ pub fn query(deps: Deps, env: Env, msg: QueryMsg) -> Result<QueryResponse, Contr
}

#[cfg_attr(not(feature = "library"), entry_point)]
pub fn migrate(_deps: DepsMut, _env: Env, _msg: Empty) -> Result<Response, ContractError> {
pub fn migrate(deps: DepsMut, _env: Env, _msg: Empty) -> Result<Response, ContractError> {
hpl_utils::migrate(deps.storage, CONTRACT_NAME, CONTRACT_VERSION)?;
Ok(Response::default())
}

Expand Down
3 changes: 3 additions & 0 deletions contracts/core/mailbox/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ pub enum ContractError {
#[error("{0}")]
CoinsError(#[from] cosmwasm_std::CoinsError),

#[error("{0}")]
MigrationError(#[from] hpl_utils::MigrationError),

#[error("unauthorized")]
Unauthorized {},

Expand Down
11 changes: 5 additions & 6 deletions contracts/core/mailbox/src/execute.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
use cosmwasm_std::{
ensure, ensure_eq, to_json_binary, wasm_execute, Coin, Coins, DepsMut, Env,
HexBinary, MessageInfo, Response,
ensure, ensure_eq, to_json_binary, wasm_execute, Coin, Coins, DepsMut, Env, HexBinary,
MessageInfo, Response,
};
use cw_utils::PaymentError::MissingDenom;
use hpl_interface::{
core::{
mailbox::{DispatchMsg, DispatchResponse},
Expand Down Expand Up @@ -123,7 +122,7 @@ pub fn dispatch(

let mut funds = Coins::try_from(info.funds.clone())?;
for coin in required_hook_fees.iter() {
if let Err(_) = funds.sub(coin.clone()) {
if funds.sub(coin.clone()).is_err() {
return Err(ContractError::HookPayment {
wanted: required_hook_fees,
received: info.funds,
Expand Down Expand Up @@ -233,8 +232,8 @@ mod tests {
use cosmwasm_std::{
coin, from_json,
testing::{mock_dependencies, mock_env, mock_info, MockApi, MockQuerier, MockStorage},
to_json_binary, Addr, ContractResult, CosmosMsg, OwnedDeps, QuerierResult,
SystemResult, WasmMsg, WasmQuery,
to_json_binary, Addr, ContractResult, CosmosMsg, OwnedDeps, QuerierResult, SystemResult,
WasmMsg, WasmQuery,
};

use hpl_interface::{
Expand Down
1 change: 1 addition & 0 deletions contracts/core/va/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ serde.workspace = true

thiserror.workspace = true

hpl-utils.workspace = true
hpl-interface.workspace = true

[dev-dependencies]
Expand Down
5 changes: 3 additions & 2 deletions contracts/core/va/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -216,8 +216,9 @@ fn announce(
}

#[cfg_attr(not(feature = "library"), entry_point)]
pub fn migrate(_deps: DepsMut, _env: Env, _msg: Empty) -> Result<Response, ContractError> {
Ok(Response::new())
pub fn migrate(deps: DepsMut, _env: Env, _msg: Empty) -> Result<Response, ContractError> {
hpl_utils::migrate(deps.storage, CONTRACT_NAME, CONTRACT_VERSION)?;
Ok(Response::default())
}

#[cfg(test)]
Expand Down
3 changes: 3 additions & 0 deletions contracts/core/va/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ pub enum ContractError {
#[error("{0}")]
RecoverPubkeyError(#[from] RecoverPubkeyError),

#[error("{0}")]
MigrationError(#[from] hpl_utils::MigrationError),

#[error("unauthorized. reason: {0}")]
Unauthorized(String),

Expand Down
1 change: 1 addition & 0 deletions contracts/hooks/aggregate/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ serde-json-wasm.workspace = true

thiserror.workspace = true

hpl-utils.workspace = true
hpl-ownable.workspace = true
hpl-interface.workspace = true

Expand Down
16 changes: 0 additions & 16 deletions contracts/hooks/aggregate/src/error.rs

This file was deleted.

31 changes: 26 additions & 5 deletions contracts/hooks/aggregate/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
mod error;

#[cfg(not(feature = "library"))]
use cosmwasm_std::entry_point;
use cosmwasm_std::{
ensure_eq, Addr, Coins, CosmosMsg, Deps, DepsMut, Env, Event, HexBinary, MessageInfo,
QueryResponse, Response, StdResult,
ensure_eq, Addr, Coins, CosmosMsg, Deps, DepsMut, Empty, Env, Event, HexBinary, MessageInfo,
QueryResponse, Response, StdError, StdResult,
};
use cw_storage_plus::Item;
use error::ContractError;
use hpl_interface::{
hook::{
aggregate::{AggregateHookQueryMsg, ExecuteMsg, HooksResponse, InstantiateMsg, QueryMsg},
Expand All @@ -19,6 +16,24 @@ use hpl_interface::{
};
use hpl_ownable::get_owner;

#[derive(thiserror::Error, Debug, PartialEq)]
pub enum ContractError {
#[error("{0}")]
Std(#[from] StdError),

#[error("{0}")]
PaymentError(#[from] cw_utils::PaymentError),

#[error("{0}")]
CoinsError(#[from] cosmwasm_std::CoinsError),

#[error("{0}")]
MigrationError(#[from] hpl_utils::MigrationError),

#[error("unauthorized")]
Unauthorized {},
}

// version info for migration info
pub const CONTRACT_NAME: &str = env!("CARGO_PKG_NAME");
pub const CONTRACT_VERSION: &str = env!("CARGO_PKG_VERSION");
Expand Down Expand Up @@ -178,3 +193,9 @@ fn get_hooks(deps: Deps) -> Result<HooksResponse, ContractError> {
.collect(),
})
}

#[cfg_attr(not(feature = "library"), entry_point)]
pub fn migrate(deps: DepsMut, _env: Env, _msg: Empty) -> Result<Response, ContractError> {
hpl_utils::migrate(deps.storage, CONTRACT_NAME, CONTRACT_VERSION)?;
Ok(Response::default())
}
1 change: 1 addition & 0 deletions contracts/hooks/fee/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ serde-json-wasm.workspace = true

thiserror.workspace = true

hpl-utils.workspace = true
hpl-ownable.workspace = true
hpl-interface.workspace = true

Expand Down
15 changes: 13 additions & 2 deletions contracts/hooks/fee/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#[cfg(not(feature = "library"))]
use cosmwasm_std::entry_point;
use cosmwasm_std::{
ensure, ensure_eq, BankMsg, Coin, CosmosMsg, Deps, DepsMut, Env, Event, MessageInfo,
ensure, ensure_eq, BankMsg, Coin, CosmosMsg, Deps, DepsMut, Empty, Env, Event, MessageInfo,
QueryResponse, Response, StdError,
};
use cw_storage_plus::Item;
Expand All @@ -21,6 +21,9 @@ pub enum ContractError {
#[error("{0}")]
PaymentError(#[from] cw_utils::PaymentError),

#[error("{0}")]
MigrationError(#[from] hpl_utils::MigrationError),

#[error("unauthorized")]
Unauthorized {},

Expand Down Expand Up @@ -150,6 +153,12 @@ fn quote_dispatch(deps: Deps) -> Result<QuoteDispatchResponse, ContractError> {
Ok(QuoteDispatchResponse { fees: vec![fee] })
}

#[cfg_attr(not(feature = "library"), entry_point)]
pub fn migrate(deps: DepsMut, _env: Env, _msg: Empty) -> Result<Response, ContractError> {
hpl_utils::migrate(deps.storage, CONTRACT_NAME, CONTRACT_VERSION)?;
Ok(Response::default())
}

#[cfg(test)]
mod test {
use cosmwasm_schema::serde::{de::DeserializeOwned, Serialize};
Expand Down Expand Up @@ -258,7 +267,9 @@ mod test {
deps.as_mut(),
mock_env(),
mock_info(sender.as_str(), &[]),
ExecuteMsg::FeeHook(FeeHookMsg::Claim { recipient: recipient.clone() }),
ExecuteMsg::FeeHook(FeeHookMsg::Claim {
recipient: recipient.clone(),
}),
)
.map_err(|e| e.to_string())
.unwrap();
Expand Down
1 change: 1 addition & 0 deletions contracts/hooks/merkle/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ serde-json-wasm.workspace = true

thiserror.workspace = true

hpl-utils.workspace = true
hpl-ownable.workspace = true
hpl-interface.workspace = true

Expand Down
8 changes: 6 additions & 2 deletions contracts/hooks/merkle/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ pub enum ContractError {
#[error("unauthorized. reason: {0}")]
Unauthorized(String),

#[error("{0}")]
MigrationError(#[from] hpl_utils::MigrationError),

#[error("hook paused")]
Paused {},
}
Expand Down Expand Up @@ -191,8 +194,9 @@ fn get_tree_checkpoint(deps: Deps) -> Result<merkle::CheckPointResponse, Contrac
}

#[cfg_attr(not(feature = "library"), entry_point)]
pub fn migrate(_deps: DepsMut, _env: Env, _msg: Empty) -> Result<Response, ContractError> {
Ok(Response::new())
pub fn migrate(deps: DepsMut, _env: Env, _msg: Empty) -> Result<Response, ContractError> {
hpl_utils::migrate(deps.storage, CONTRACT_NAME, CONTRACT_VERSION)?;
Ok(Response::default())
}

#[cfg(test)]
Expand Down
1 change: 1 addition & 0 deletions contracts/hooks/pausable/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ serde-json-wasm.workspace = true

thiserror.workspace = true

hpl-utils.workspace = true
hpl-ownable.workspace = true
hpl-pausable.workspace = true
hpl-interface.workspace = true
Expand Down
11 changes: 10 additions & 1 deletion contracts/hooks/pausable/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#[cfg(not(feature = "library"))]
use cosmwasm_std::entry_point;
use cosmwasm_std::{
ensure, Deps, DepsMut, Env, Event, MessageInfo, QueryResponse, Response, StdError,
ensure, Deps, DepsMut, Empty, Env, Event, MessageInfo, QueryResponse, Response, StdError,
};
use hpl_interface::{
hook::{
Expand All @@ -19,6 +19,9 @@ pub enum ContractError {
#[error("{0}")]
PaymentError(#[from] cw_utils::PaymentError),

#[error("{0}")]
MigrationError(#[from] hpl_utils::MigrationError),

#[error("unauthorized")]
Unauthorized {},

Expand Down Expand Up @@ -99,6 +102,12 @@ fn quote_dispatch() -> Result<QuoteDispatchResponse, ContractError> {
Ok(QuoteDispatchResponse { fees: vec![] })
}

#[cfg_attr(not(feature = "library"), entry_point)]
pub fn migrate(deps: DepsMut, _env: Env, _msg: Empty) -> Result<Response, ContractError> {
hpl_utils::migrate(deps.storage, CONTRACT_NAME, CONTRACT_VERSION)?;
Ok(Response::default())
}

#[cfg(test)]
mod test {
use cosmwasm_schema::serde::{de::DeserializeOwned, Serialize};
Expand Down
1 change: 1 addition & 0 deletions contracts/hooks/routing-custom/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ serde-json-wasm.workspace = true

thiserror.workspace = true

hpl-utils.workspace = true
hpl-ownable.workspace = true
hpl-router.workspace = true
hpl-interface.workspace = true
Expand Down
11 changes: 10 additions & 1 deletion contracts/hooks/routing-custom/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#[cfg(not(feature = "library"))]
use cosmwasm_std::entry_point;
use cosmwasm_std::{
ensure_eq, wasm_execute, Addr, Deps, DepsMut, Env, Event, HexBinary, MessageInfo,
ensure_eq, wasm_execute, Addr, Deps, DepsMut, Empty, Env, Event, HexBinary, MessageInfo,
QueryResponse, Response, StdError, StdResult, Storage,
};

Expand Down Expand Up @@ -29,6 +29,9 @@ pub enum ContractError {
#[error("{0}")]
PaymentError(#[from] cw_utils::PaymentError),

#[error("{0}")]
MigrationError(#[from] hpl_utils::MigrationError),

#[error("unauthorized")]
Unauthorized {},

Expand Down Expand Up @@ -312,6 +315,12 @@ fn quote_dispatch(
Ok(resp)
}

#[cfg_attr(not(feature = "library"), entry_point)]
pub fn migrate(deps: DepsMut, _env: Env, _msg: Empty) -> Result<Response, ContractError> {
hpl_utils::migrate(deps.storage, CONTRACT_NAME, CONTRACT_VERSION)?;
Ok(Response::default())
}

#[cfg(test)]
mod test {
use cosmwasm_std::{
Expand Down
1 change: 1 addition & 0 deletions contracts/hooks/routing-fallback/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ serde-json-wasm.workspace = true

thiserror.workspace = true

hpl-utils.workspace = true
hpl-ownable.workspace = true
hpl-router.workspace = true
hpl-interface.workspace = true
Expand Down
11 changes: 10 additions & 1 deletion contracts/hooks/routing-fallback/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#[cfg(not(feature = "library"))]
use cosmwasm_std::entry_point;
use cosmwasm_std::{
ensure_eq, wasm_execute, Addr, Deps, DepsMut, Env, Event, HexBinary, MessageInfo,
ensure_eq, wasm_execute, Addr, Deps, DepsMut, Empty, Env, Event, HexBinary, MessageInfo,
QueryResponse, Response, StdError, Storage,
};

Expand All @@ -25,6 +25,9 @@ pub enum ContractError {
#[error("{0}")]
PaymentError(#[from] cw_utils::PaymentError),

#[error("{0}")]
MigrationError(#[from] hpl_utils::MigrationError),

#[error("unauthorized")]
Unauthorized {},
}
Expand Down Expand Up @@ -154,6 +157,12 @@ pub fn quote_dispatch(
Ok(resp)
}

#[cfg_attr(not(feature = "library"), entry_point)]
pub fn migrate(deps: DepsMut, _env: Env, _msg: Empty) -> Result<Response, ContractError> {
hpl_utils::migrate(deps.storage, CONTRACT_NAME, CONTRACT_VERSION)?;
Ok(Response::default())
}

#[cfg(test)]
mod test {
use cosmwasm_std::{
Expand Down
1 change: 1 addition & 0 deletions contracts/hooks/routing/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ serde-json-wasm.workspace = true

thiserror.workspace = true

hpl-utils.workspace = true
hpl-ownable.workspace = true
hpl-router.workspace = true
hpl-interface.workspace = true
Expand Down
Loading

0 comments on commit 00f64a9

Please sign in to comment.