diff --git a/e2e-tests/tests/macro_tests/exec_fn.rs b/e2e-tests/tests/macro_tests/exec_fn.rs index ad317b2f0..7c388ad4f 100644 --- a/e2e-tests/tests/macro_tests/exec_fn.rs +++ b/e2e-tests/tests/macro_tests/exec_fn.rs @@ -165,11 +165,21 @@ fn test_unwrap_amp_msg() { let msg = ExecuteMsg::AMPReceive(amp_pkt); let (ctx, msg, _) = (|| -> Result<(ExecuteContext, ExecuteMsg, Response), ContractError> { - let (ctx, msg, resp) = unwrap_amp_msg!(deps.as_mut(), info, env, msg); + let (ctx, msg, resp) = unwrap_amp_msg!(deps.as_mut(), info.clone(), env.clone(), msg); Ok((ctx, msg, resp)) })().unwrap(); assert_eq!(ctx.info.sender, "sender"); assert_eq!(ctx.raw_info.sender, MOCK_KERNEL_CONTRACT); assert_eq!(msg, sent_msg); + + let empty_amp_pkt = AMPPkt::new("sender".to_string(), "sender".to_string(), vec![]); + let msg = ExecuteMsg::AMPReceive(empty_amp_pkt); + + let err = (|| -> Result<(), ContractError> { + let _ = unwrap_amp_msg!(deps.as_mut(), info, env, msg); + Ok(()) + })().unwrap_err(); + + assert_eq!(err, ContractError::InvalidPacket { error: Some("AMP Packet received with no messages".to_string()) }); } diff --git a/packages/std/src/ado_contract/execute.rs b/packages/std/src/ado_contract/execute.rs index b3bd9ce17..e4482455c 100644 --- a/packages/std/src/ado_contract/execute.rs +++ b/packages/std/src/ado_contract/execute.rs @@ -367,7 +367,16 @@ macro_rules! unwrap_amp_msg { ctx.deps .api .debug(&format!("Set new sender: {}", ctx.info.sender)); - msg = ::cosmwasm_std::from_json(&pkt.messages.pop().unwrap().message)?; + let maybe_amp_msg = pkt.messages.pop(); + + ::cosmwasm_std::ensure!( + maybe_amp_msg.is_some(), + ContractError::InvalidPacket { + error: Some("AMP Packet received with no messages".to_string()), + } + ); + let amp_msg = maybe_amp_msg.unwrap(); + msg = ::cosmwasm_std::from_json(&_msg.message)?; ::cosmwasm_std::ensure!( !msg.must_be_direct(), ContractError::InvalidPacket {