Repository: CosmWasm/cosmwasm
Pull request #1046 (2021-08-10 20:54:44)

Parse contract address from instantiate event, not message event
Fixes an issue that occurred when we updated the events handling in wasmd.

Notably https://github.com/CosmWasm/wasmd/pull/586

(This is also a good argument that we stabilise the events before a 1.0 release)


Patch:
diff --git a/contracts/ibc-reflect/src/contract.rs b/contracts/ibc-reflect/src/contract.rs
index a4493f7f4..c2ff44a18 100644
--- a/contracts/ibc-reflect/src/contract.rs
+++ b/contracts/ibc-reflect/src/contract.rs
@@ -43,11 +43,11 @@ pub fn reply(deps: DepsMut, _env: Env, reply: Reply) -> StdResult<Response> {
     }
 }
 
-// see https://github.com/CosmWasm/wasmd/blob/408bba14a5c6d583abe32ffb235a364130136298/x/wasm/keeper/msg_server.go#L63-L69
+// updated with https://github.com/CosmWasm/wasmd/pull/586 (emitted in keeper.Instantiate)
 fn parse_contract_from_event(events: Vec<Event>) -> Option<String> {
     events
         .into_iter()
-        .find(|e| e.ty == "message")
+        .find(|e| e.ty == "instantiate")
         .and_then(|ev| {
             ev.attributes
                 .into_iter()
@@ -355,9 +355,7 @@ mod tests {
     }
 
     fn fake_events(reflect_addr: &str) -> Vec<Event> {
-        let event = Event::new("message").add_attributes(vec![
-            attr("module", "wasm"),
-            attr("signer", MOCK_CONTRACT_ADDR),
+        let event = Event::new("instantiate").add_attributes(vec![
             attr("code_id", "17"),
             // We have to force this one to avoid the debug assertion against _
             mock_wasmd_attr("_contract_address", reflect_addr),
diff --git a/packages/vm/src/calls.rs b/packages/vm/src/calls.rs
index 151cdfe14..f341ea906 100644
--- a/packages/vm/src/calls.rs
+++ b/packages/vm/src/calls.rs
@@ -721,7 +721,7 @@ mod tests {
             );
             assert_eq!(ReplyOn::Success, res.messages[0].reply_on);
             let id = res.messages[0].id;
-            let event = Event::new("message").add_attributes(vec![
+            let event = Event::new("instantiate").add_attributes(vec![
                 // We have to force this one to avoid the debug assertion against _
                 mock_wasmd_attr("_contract_address", account),
             ]);


Test patch:
diff --git a/contracts/ibc-reflect/tests/integration.rs b/contracts/ibc-reflect/tests/integration.rs
index b9adb9f9a..3c16cf83f 100644
--- a/contracts/ibc-reflect/tests/integration.rs
+++ b/contracts/ibc-reflect/tests/integration.rs
@@ -27,7 +27,7 @@ use cosmwasm_std::{
 };
 use cosmwasm_vm::testing::{
     ibc_channel_connect, ibc_channel_open, ibc_packet_receive, instantiate, mock_env, mock_info,
-    mock_instance, query, reply, MockApi, MockQuerier, MockStorage, MOCK_CONTRACT_ADDR,
+    mock_instance, query, reply, MockApi, MockQuerier, MockStorage,
 };
 use cosmwasm_vm::{from_slice, Instance};
 
@@ -60,9 +60,7 @@ fn setup() -> Instance<MockApi, MockStorage, MockQuerier> {
 }
 
 fn fake_events(reflect_addr: &str) -> Vec<Event> {
-    let event = Event::new("message").add_attributes(vec![
-        attr("module", "wasm"),
-        attr("signer", MOCK_CONTRACT_ADDR),
+    let event = Event::new("instantiate").add_attributes(vec![
         attr("code_id", "17"),
         // We have to force this one to avoid the debug assertion against _
         mock_wasmd_attr("_contract_address", reflect_addr),