From ae900ad12ea5e97dd2600339e91505d84a2ff860 Mon Sep 17 00:00:00 2001 From: "shane.stars" Date: Fri, 9 Dec 2022 21:02:22 -0500 Subject: [PATCH] Associate address in event (#229) * Fix associated address event * Add test --- contracts/name-minter/src/integration_tests.rs | 10 +++++++++- contracts/sg721-name/src/contract.rs | 7 +++++-- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/contracts/name-minter/src/integration_tests.rs b/contracts/name-minter/src/integration_tests.rs index af3e734e..ea94de9d 100644 --- a/contracts/name-minter/src/integration_tests.rs +++ b/contracts/name-minter/src/integration_tests.rs @@ -316,7 +316,7 @@ fn bid(app: &mut StargazeApp, bidder: &str, amount: u128) { } mod execute { - use cosmwasm_std::StdError; + use cosmwasm_std::{attr, StdError}; use cw721::{NftInfoResponse, OperatorsResponse}; use name_marketplace::state::{Ask, SudoParams}; use sg721_name::msg::QueryMsg as Sg721NameQueryMsg; @@ -656,6 +656,14 @@ mod execute { &[], ); assert!(res.is_ok()); + + res.unwrap().events.iter().for_each(|e| { + if e.ty == "wasm-associate-address" { + assert_eq!(e.attributes[1], attr("name", NAME)); + assert_eq!(e.attributes[2], attr("owner", ADMIN2)); + assert_eq!(e.attributes[3], attr("address", MINTER)); + } + }); } #[test] diff --git a/contracts/sg721-name/src/contract.rs b/contracts/sg721-name/src/contract.rs index 5c0ef25a..c56aeb69 100644 --- a/contracts/sg721-name/src/contract.rs +++ b/contracts/sg721-name/src/contract.rs @@ -138,10 +138,13 @@ pub fn execute_associate_address( // 6. save new reverse map entry token_uri.map(|addr| REVERSE_MAP.save(deps.storage, &addr, &name)); - let event = Event::new("associate-address") + let mut event = Event::new("associate-address") .add_attribute("name", name) .add_attribute("owner", info.sender); - address.map(|addr| event.clone().add_attribute("address", addr)); + + if let Some(address) = address { + event = event.add_attribute("address", address); + } Ok(Response::new().add_event(event)) }