From 9c23a0699de19bb706d8a91a812b15af5e4b2a2b Mon Sep 17 00:00:00 2001 From: Ethan Frey Date: Tue, 27 Jun 2023 16:56:24 +0200 Subject: [PATCH] All IBC code minus sending message runs in test for better coverage --- .../provider/external-staking/src/contract.rs | 63 ++++++++++--------- 1 file changed, 34 insertions(+), 29 deletions(-) diff --git a/contracts/provider/external-staking/src/contract.rs b/contracts/provider/external-staking/src/contract.rs index 31846753..45daeeaa 100644 --- a/contracts/provider/external-staking/src/contract.rs +++ b/contracts/provider/external-staking/src/contract.rs @@ -288,7 +288,6 @@ impl ExternalStakingContract<'_> { let tx_id = self.next_tx_id(ctx.deps.storage)?; // Save tx - #[allow(clippy::redundant_clone)] let new_tx = Tx::InFlightRemoteUnstaking { id: tx_id, amount: amount.amount, @@ -297,29 +296,32 @@ impl ExternalStakingContract<'_> { }; self.pending_txs.save(ctx.deps.storage, tx_id, &new_tx)?; + #[allow(unused_mut)] let mut resp = Response::new() .add_attribute("action", "unstake") - .add_attribute("amount", amount.amount.to_string()); + .add_attribute("amount", amount.amount.to_string()) + .add_attribute("owner", ctx.info.sender); - // add ibc packet if we are ibc enabled (skip in tests) + let channel = IBC_CHANNEL.load(ctx.deps.storage)?; + let packet = ProviderPacket::Unstake { + validator, + unstake: amount, + tx_id, + }; + let msg = IbcMsg::SendPacket { + channel_id: channel.endpoint.channel_id, + data: to_binary(&packet)?, + timeout: packet_timeout(&ctx.env), + }; + // send packet if we are ibc enabled (skip in tests) #[cfg(not(test))] { - let channel = IBC_CHANNEL.load(ctx.deps.storage)?; - let packet = ProviderPacket::Unstake { - validator, - unstake: amount, - tx_id, - }; - let msg = IbcMsg::SendPacket { - channel_id: channel.endpoint.channel_id, - data: to_binary(&packet)?, - timeout: packet_timeout(&ctx.env), - }; resp = resp.add_message(msg); } - - // put this later so compiler doens't complain about mut in test mode - resp = resp.add_attribute("owner", ctx.info.sender); + #[cfg(test)] + { + let _ = msg; + } Ok(resp) } @@ -981,7 +983,6 @@ pub mod cross_staking { .save(ctx.deps.storage, (&owner, &msg.validator), &stake_lock)?; // Save tx - #[allow(clippy::redundant_clone)] let new_tx = Tx::InFlightRemoteStaking { id: tx_id, amount: amount.amount, @@ -992,22 +993,26 @@ pub mod cross_staking { let mut resp = Response::new(); + let channel = IBC_CHANNEL.load(ctx.deps.storage)?; + let packet = ProviderPacket::Stake { + validator: msg.validator, + stake: amount.clone(), + tx_id, + }; + let msg = IbcMsg::SendPacket { + channel_id: channel.endpoint.channel_id, + data: to_binary(&packet)?, + timeout: packet_timeout(&ctx.env), + }; // add ibc packet if we are ibc enabled (skip in tests) #[cfg(not(test))] { - let channel = IBC_CHANNEL.load(ctx.deps.storage)?; - let packet = ProviderPacket::Stake { - validator: msg.validator, - stake: amount.clone(), - tx_id, - }; - let msg = IbcMsg::SendPacket { - channel_id: channel.endpoint.channel_id, - data: to_binary(&packet)?, - timeout: packet_timeout(&ctx.env), - }; resp = resp.add_message(msg); } + #[cfg(test)] + { + let _ = msg; + } resp = resp .add_attribute("action", "receive_virtual_stake")