Skip to content

Commit

Permalink
Integration tests
Browse files Browse the repository at this point in the history
  • Loading branch information
deniszagumennov committed Oct 10, 2024
1 parent 348e983 commit 897ebea
Show file tree
Hide file tree
Showing 25 changed files with 651 additions and 148 deletions.
18 changes: 16 additions & 2 deletions contracts/factory/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ use drop_staking_base::{
InstantiateMsg as WithdrawalManagerInstantiateMsg,
QueryMsg as WithdrawalManagerQueryMsg,
},
withdrawal_token::InstantiateMsg as WithdrawalTokenInstantiateMsg,
withdrawal_voucher::InstantiateMsg as WithdrawalVoucherInstantiateMsg,
},
state::pump::PumpTimeout,
Expand Down Expand Up @@ -213,7 +214,7 @@ pub fn instantiate(
core_contract: core_contract.to_string(),
puppeteer_contract: puppeteer_contract.to_string(),
staker_contract: staker_contract.to_string(),
withdrawal_token_contract: withdrawal_voucher_contract.to_string(),
withdrawal_token_contract: withdrawal_token_contract.to_string(),
withdrawal_voucher_contract: withdrawal_voucher_contract.to_string(),
withdrawal_manager_contract: withdrawal_manager_contract.to_string(),
strategy_contract: strategy_contract.to_string(),
Expand All @@ -232,7 +233,7 @@ pub fn instantiate(
label: get_contract_label("token"),
msg: to_json_binary(&TokenInstantiateMsg {
core_address: core_contract.to_string(),
subdenom: msg.subdenom,
subdenom: msg.subdenom.clone(),
token_metadata: msg.token_metadata,
owner: env.contract.address.to_string(),
})?,
Expand Down Expand Up @@ -310,6 +311,19 @@ pub fn instantiate(
funds: vec![],
salt: Binary::from(salt),
}),
CosmosMsg::Wasm(WasmMsg::Instantiate2 {
admin: Some(env.contract.address.to_string()),
code_id: msg.code_ids.withdrawal_token_code_id,
label: get_contract_label("withdrawal-token"),
msg: to_json_binary(&WithdrawalTokenInstantiateMsg {
core_address: core_contract.to_string(),
withdrawal_manager_address: withdrawal_manager_contract.to_string(),
denom_prefix: msg.subdenom.clone(),
owner: env.contract.address.to_string(),
})?,
funds: vec![],
salt: Binary::from(salt),
}),
CosmosMsg::Wasm(WasmMsg::Instantiate2 {
admin: Some(env.contract.address.to_string()),
code_id: msg.code_ids.core_code_id,
Expand Down
17 changes: 17 additions & 0 deletions contracts/factory/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ use drop_staking_base::{
ExecuteMsg as WithdrawalManagerExecuteMsg,
InstantiateMsg as WithdrawalManagerInstantiateMsg,
},
withdrawal_token::InstantiateMsg as WithdrawalTokenInstantiateMsg,
withdrawal_voucher::InstantiateMsg as WithdrawalVoucherInstantiateMsg,
},
state::{pump::PumpTimeout, splitter::Config as SplitterConfig},
Expand Down Expand Up @@ -268,6 +269,22 @@ fn test_instantiate() {
salt: cosmwasm_std::Binary::from("salt".as_bytes())
}
)),
cosmwasm_std::SubMsg::new(cosmwasm_std::CosmosMsg::Wasm(
cosmwasm_std::WasmMsg::Instantiate2 {
admin: Some("factory_contract".to_string()),
code_id: 5,
label: "drop-staking-withdrawal-token".to_string(),
msg: to_json_binary(&WithdrawalTokenInstantiateMsg {
core_address: "some_humanized_address".to_string(),
withdrawal_manager_address: "some_humanized_address".to_string(),
denom_prefix: "subdenom".to_string(),
owner: "factory_contract".to_string(),
})
.unwrap(),
funds: vec![],
salt: cosmwasm_std::Binary::from("salt".as_bytes())
}
)),
cosmwasm_std::SubMsg::new(cosmwasm_std::CosmosMsg::Wasm(
cosmwasm_std::WasmMsg::Instantiate2 {
admin: Some("factory_contract".to_string()),
Expand Down
7 changes: 5 additions & 2 deletions contracts/withdrawal-manager/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,9 @@ pub fn execute(
}
}
}
ExecuteMsg::ReceiveWithdrawalDenoms {} => execute_receive_withdrawal_denoms(deps, info),
ExecuteMsg::ReceiveWithdrawalDenoms { receiver } => {
execute_receive_withdrawal_denoms(deps, info, receiver)
}
ExecuteMsg::Pause {} => exec_pause(deps, info),
ExecuteMsg::Unpause {} => exec_unpause(deps, info),
}
Expand Down Expand Up @@ -242,6 +244,7 @@ fn execute_receive_nft_withdraw(
fn execute_receive_withdrawal_denoms(
deps: DepsMut<NeutronQuery>,
info: MessageInfo,
receiver: Option<String>,
) -> ContractResult<Response<NeutronMsg>> {
pause_guard(deps.storage)?;

Expand All @@ -267,7 +270,7 @@ fn execute_receive_withdrawal_denoms(
let user_share = Decimal::from_ratio(amount, unbond_batch.total_dasset_amount_to_withdraw);

let payout_amount = user_share * unbond_batch.unbonded_amount.unwrap_or(Uint128::zero());
let to_address = info.sender.into_string();
let to_address = receiver.unwrap_or(info.sender.to_string());
attrs.push(attr("batch_id", batch_id.to_string()));
attrs.push(attr("payout_amount", payout_amount.to_string()));
attrs.push(attr("to_address", &to_address));
Expand Down
14 changes: 7 additions & 7 deletions contracts/withdrawal-manager/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ fn test_receive_withdrawal_denoms_happy_path() {
"factory/withdrawal_token_contract/dATOM:unbond:0",
)],
),
ExecuteMsg::ReceiveWithdrawalDenoms {},
ExecuteMsg::ReceiveWithdrawalDenoms { receiver: None },
)
.unwrap();

Expand Down Expand Up @@ -124,7 +124,7 @@ fn test_receive_withdrawal_denoms_has_few_parts() {
deps.as_mut(),
mock_env().clone(),
mock_info("any sender", &[Coin::new(1000, "factory/dATOM:unbond:0")]),
ExecuteMsg::ReceiveWithdrawalDenoms {},
ExecuteMsg::ReceiveWithdrawalDenoms { receiver: None },
);
assert!(res.is_err());
assert_eq!(res, Err(ContractError::InvalidDenom {}));
Expand All @@ -143,7 +143,7 @@ fn test_receive_withdrawal_denoms_has_incorrect_prefix() {
deps.as_mut(),
mock_env().clone(),
mock_info("any sender", &[Coin::new(1000, denom)]),
ExecuteMsg::ReceiveWithdrawalDenoms {},
ExecuteMsg::ReceiveWithdrawalDenoms { receiver: None },
);
assert!(res.is_err());
assert_eq!(res, Err(ContractError::InvalidDenom {}));
Expand All @@ -162,7 +162,7 @@ fn test_receive_withdrawal_denoms_has_incorrect_owner() {
deps.as_mut(),
mock_env().clone(),
mock_info("any sender", &[Coin::new(1000, denom)]),
ExecuteMsg::ReceiveWithdrawalDenoms {},
ExecuteMsg::ReceiveWithdrawalDenoms { receiver: None },
);
assert!(res.is_err());
assert_eq!(res, Err(ContractError::InvalidDenom {}));
Expand All @@ -181,7 +181,7 @@ fn test_receive_withdrawal_denoms_has_incorrect_subdenom() {
deps.as_mut(),
mock_env().clone(),
mock_info("any sender", &[Coin::new(1000, denom)]),
ExecuteMsg::ReceiveWithdrawalDenoms {},
ExecuteMsg::ReceiveWithdrawalDenoms { receiver: None },
);
assert!(res.is_err());
assert_eq!(res, Err(ContractError::InvalidDenom {}));
Expand All @@ -200,7 +200,7 @@ fn test_receive_withdrawal_denoms_has_incorrect_subdenom_batch_id() {
deps.as_mut(),
mock_env().clone(),
mock_info("any sender", &[Coin::new(1000, denom)]),
ExecuteMsg::ReceiveWithdrawalDenoms {},
ExecuteMsg::ReceiveWithdrawalDenoms { receiver: None },
);
assert!(res.is_err());
assert_eq!(res, Err(ContractError::InvalidDenom {}));
Expand Down Expand Up @@ -239,7 +239,7 @@ fn test_receive_withdrawal_denoms_batch_not_withdrawn() {
"factory/withdrawal_token_contract/dATOM:unbond:0",
)],
),
ExecuteMsg::ReceiveWithdrawalDenoms {},
ExecuteMsg::ReceiveWithdrawalDenoms { receiver: None },
);
assert!(res.is_err());
assert_eq!(res, Err(ContractError::BatchIsNotWithdrawn {}));
Expand Down
17 changes: 13 additions & 4 deletions contracts/withdrawal-token/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use drop_helpers::answer::{attr_coin, response};
use drop_staking_base::{
error::withdrawal_token::{ContractError, ContractResult},
msg::withdrawal_token::{ConfigResponse, ExecuteMsg, InstantiateMsg, MigrateMsg, QueryMsg},
state::withdrawal_token::{CORE_ADDRESS, DENOM_PREFIX},
state::withdrawal_token::{CORE_ADDRESS, DENOM_PREFIX, WITHDRAWAL_MANAGER_ADDRESS},
};
use neutron_sdk::{
bindings::{msg::NeutronMsg, query::NeutronQuery},
Expand All @@ -31,12 +31,18 @@ pub fn instantiate(
let core = deps.api.addr_validate(&msg.core_address)?;
CORE_ADDRESS.save(deps.storage, &core)?;

let withdrawal_manager = deps.api.addr_validate(&msg.withdrawal_manager_address)?;
WITHDRAWAL_MANAGER_ADDRESS.save(deps.storage, &withdrawal_manager)?;

DENOM_PREFIX.save(deps.storage, &msg.denom_prefix)?;

Ok(response(
"instantiate",
CONTRACT_NAME,
[attr("core_address", core)],
[
attr("core_address", core),
attr("withdrawal_manager_address", withdrawal_manager),
],
))
}

Expand Down Expand Up @@ -125,8 +131,8 @@ fn burn(
env: Env,
batch_id: Uint128,
) -> ContractResult<Response<NeutronMsg>> {
let core = CORE_ADDRESS.load(deps.storage)?;
ensure_eq!(info.sender, core, ContractError::Unauthorized);
let withdrawal_manager = WITHDRAWAL_MANAGER_ADDRESS.load(deps.storage)?;
ensure_eq!(info.sender, withdrawal_manager, ContractError::Unauthorized);

let denom_prefix = DENOM_PREFIX.load(deps.storage)?;
let subdenom = build_subdenom_name(denom_prefix, batch_id);
Expand Down Expand Up @@ -154,9 +160,12 @@ pub fn query(deps: Deps<NeutronQuery>, _env: Env, msg: QueryMsg) -> ContractResu
)?),
QueryMsg::Config {} => {
let core_address = CORE_ADDRESS.load(deps.storage)?.into_string();
let withdrawal_manager_address =
WITHDRAWAL_MANAGER_ADDRESS.load(deps.storage)?.into_string();
let denom_prefix = DENOM_PREFIX.load(deps.storage)?;
Ok(to_json_binary(&ConfigResponse {
core_address,
withdrawal_manager_address,
denom_prefix,
})?)
}
Expand Down
Loading

0 comments on commit 897ebea

Please sign in to comment.