From acc3ec14d8264075a6c8d084d007538d3def395d Mon Sep 17 00:00:00 2001 From: Chirantan Ekbote Date: Thu, 15 Dec 2022 19:33:44 +0900 Subject: [PATCH] cosmwasm: accounting: Drop dependency on the tokenbridge contract Now that the accounting contract can handle chain registrations on its own, there's no need to query the tokenbridge contract. Remove references to it from `InstantiateMsg` and the internal state. --- .../wormchain-accounting/src/contract.rs | 14 +---------- .../contracts/wormchain-accounting/src/msg.rs | 1 - .../wormchain-accounting/src/state.rs | 5 ++-- .../tests/helpers/fake_tokenbridge.rs | 25 ------------------- .../wormchain-accounting/tests/helpers/mod.rs | 23 +---------------- 5 files changed, 4 insertions(+), 64 deletions(-) delete mode 100644 cosmwasm/contracts/wormchain-accounting/tests/helpers/fake_tokenbridge.rs diff --git a/cosmwasm/contracts/wormchain-accounting/src/contract.rs b/cosmwasm/contracts/wormchain-accounting/src/contract.rs index 39b1e4607..e8ff1c62e 100644 --- a/cosmwasm/contracts/wormchain-accounting/src/contract.rs +++ b/cosmwasm/contracts/wormchain-accounting/src/contract.rs @@ -30,10 +30,7 @@ use crate::{ AllTransfersResponse, ChainRegistrationResponse, ExecuteMsg, Instantiate, InstantiateMsg, MigrateMsg, Observation, QueryMsg, Upgrade, }, - state::{ - self, Data, PendingTransfer, CHAIN_REGISTRATIONS, GOVERNANCE_VAAS, PENDING_TRANSFERS, - TOKENBRIDGE_ADDR, - }, + state::{self, Data, PendingTransfer, CHAIN_REGISTRATIONS, GOVERNANCE_VAAS, PENDING_TRANSFERS}, }; // version info for migration info @@ -65,15 +62,6 @@ pub fn instantiate( let init: Instantiate = from_binary(&msg.instantiate).context("failed to parse `Instantiate` message")?; - let tokenbridge_addr = deps - .api - .addr_validate(&init.tokenbridge_addr) - .context("failed to validate tokenbridge address")?; - - TOKENBRIDGE_ADDR - .save(deps.storage, &tokenbridge_addr) - .context("failed to save tokenbridge address")?; - let event = accounting::instantiate(deps, init.into()).context("failed to instantiate accounting")?; diff --git a/cosmwasm/contracts/wormchain-accounting/src/msg.rs b/cosmwasm/contracts/wormchain-accounting/src/msg.rs index 3370cbb20..25cc4c424 100644 --- a/cosmwasm/contracts/wormchain-accounting/src/msg.rs +++ b/cosmwasm/contracts/wormchain-accounting/src/msg.rs @@ -7,7 +7,6 @@ use crate::state::{self, PendingTransfer}; #[cw_serde] pub struct Instantiate { - pub tokenbridge_addr: String, pub accounts: Vec, pub transfers: Vec, pub modifications: Vec, diff --git a/cosmwasm/contracts/wormchain-accounting/src/state.rs b/cosmwasm/contracts/wormchain-accounting/src/state.rs index c21892739..a82becf7c 100644 --- a/cosmwasm/contracts/wormchain-accounting/src/state.rs +++ b/cosmwasm/contracts/wormchain-accounting/src/state.rs @@ -1,14 +1,13 @@ use accounting::state::transfer; use cosmwasm_schema::cw_serde; -use cosmwasm_std::{Addr, Binary}; -use cw_storage_plus::{Item, Map}; +use cosmwasm_std::Binary; +use cw_storage_plus::Map; use thiserror::Error; use tinyvec::TinyVec; use wormhole::vaa::Signature; use crate::msg::Observation; -pub const TOKENBRIDGE_ADDR: Item = Item::new("tokenbride_addr"); pub const PENDING_TRANSFERS: Map> = Map::new("pending_transfers"); pub const CHAIN_REGISTRATIONS: Map = Map::new("chain_registrations"); pub const GOVERNANCE_VAAS: Map, ()> = Map::new("governance_vaas"); diff --git a/cosmwasm/contracts/wormchain-accounting/tests/helpers/fake_tokenbridge.rs b/cosmwasm/contracts/wormchain-accounting/tests/helpers/fake_tokenbridge.rs deleted file mode 100644 index fffbab76f..000000000 --- a/cosmwasm/contracts/wormchain-accounting/tests/helpers/fake_tokenbridge.rs +++ /dev/null @@ -1,25 +0,0 @@ -use cosmwasm_std::{ - to_binary, Binary, Deps, DepsMut, Empty, Env, MessageInfo, Response, StdError, StdResult, -}; -use tokenbridge::msg::{ChainRegistrationResponse, QueryMsg}; - -pub fn instantiate(_: DepsMut, _: Env, _: MessageInfo, _: Empty) -> StdResult { - Ok(Response::new()) -} - -pub fn execute(_: DepsMut, _: Env, _: MessageInfo, _: Empty) -> StdResult { - Err(StdError::GenericErr { - msg: "execute not implemented".into(), - }) -} - -pub fn query(_: Deps, _: Env, msg: QueryMsg) -> StdResult { - match msg { - QueryMsg::ChainRegistration { chain } => to_binary(&ChainRegistrationResponse { - address: vec![chain as u8; 32].into(), - }), - _ => Err(StdError::GenericErr { - msg: "unimplemented query message".into(), - }), - } -} diff --git a/cosmwasm/contracts/wormchain-accounting/tests/helpers/mod.rs b/cosmwasm/contracts/wormchain-accounting/tests/helpers/mod.rs index 4d7acea5c..da3724b13 100644 --- a/cosmwasm/contracts/wormchain-accounting/tests/helpers/mod.rs +++ b/cosmwasm/contracts/wormchain-accounting/tests/helpers/mod.rs @@ -23,8 +23,6 @@ use wormhole::{ }; use wormhole_bindings::{fake, WormholeQuery}; -mod fake_tokenbridge; - pub struct Contract { addr: Addr, app: FakeApp, @@ -260,32 +258,13 @@ pub fn proper_instantiate( let wh = fake::WormholeKeeper::new(); let mut app = fake_app(wh.clone()); - let tokenbridge_id = app.store_code(Box::new(ContractWrapper::new_with_empty( - fake_tokenbridge::execute, - fake_tokenbridge::instantiate, - fake_tokenbridge::query, - ))); - let accounting_id = app.store_code(Box::new(ContractWrapper::new( wormchain_accounting::contract::execute, wormchain_accounting::contract::instantiate, wormchain_accounting::contract::query, ))); - let tokenbridge_addr = app - .instantiate_contract( - tokenbridge_id, - Addr::unchecked(ADMIN), - &Empty {}, - &[], - "tokenbridge", - None, - ) - .unwrap() - .into(); - let instantiate = to_binary(&Instantiate { - tokenbridge_addr, accounts, transfers, modifications, @@ -323,7 +302,7 @@ pub fn proper_instantiate( &msg, &[], "accounting", - Some("contract1".into()), + Some("contract0".into()), ) .unwrap();