cosmwasm: tokenbridge: Add chain registration query
Add a query to get the registered emitterr address for a given chain id. This will be used by accounting.
This commit is contained in:
parent
a3682cc158
commit
09459fcf9e
|
@ -31,8 +31,8 @@ use cosmwasm_std::{
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
msg::{
|
msg::{
|
||||||
ExecuteMsg, ExternalIdResponse, InstantiateMsg, IsVaaRedeemedResponse, MigrateMsg,
|
ChainRegistrationResponse, ExecuteMsg, ExternalIdResponse, InstantiateMsg,
|
||||||
QueryMsg, TransferInfoResponse, WrappedRegistryResponse,
|
IsVaaRedeemedResponse, MigrateMsg, QueryMsg, TransferInfoResponse, WrappedRegistryResponse,
|
||||||
},
|
},
|
||||||
state::{
|
state::{
|
||||||
bridge_contracts, bridge_contracts_read, bridge_deposit, config, config_read,
|
bridge_contracts, bridge_contracts_read, bridge_deposit, config, config_read,
|
||||||
|
@ -1449,6 +1449,9 @@ pub fn query(deps: Deps, env: Env, msg: QueryMsg) -> StdResult<Binary> {
|
||||||
QueryMsg::TransferInfo { vaa } => to_binary(&query_transfer_info(deps, env, &vaa)?),
|
QueryMsg::TransferInfo { vaa } => to_binary(&query_transfer_info(deps, env, &vaa)?),
|
||||||
QueryMsg::ExternalId { external_id } => to_binary(&query_external_id(deps, external_id)?),
|
QueryMsg::ExternalId { external_id } => to_binary(&query_external_id(deps, external_id)?),
|
||||||
QueryMsg::IsVaaRedeemed { vaa } => to_binary(&query_is_vaa_redeemed(deps, env, &vaa)?),
|
QueryMsg::IsVaaRedeemed { vaa } => to_binary(&query_is_vaa_redeemed(deps, env, &vaa)?),
|
||||||
|
QueryMsg::ChainRegistration { chain } => {
|
||||||
|
query_chain_registration(deps, chain).and_then(|r| to_binary(&r))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1526,6 +1529,13 @@ fn query_is_vaa_redeemed(deps: Deps, _env: Env, vaa: &Binary) -> StdResult<IsVaa
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn query_chain_registration(deps: Deps, chain: u16) -> StdResult<ChainRegistrationResponse> {
|
||||||
|
bridge_contracts_read(deps.storage)
|
||||||
|
.load(&chain.to_be_bytes())
|
||||||
|
.map(Binary::from)
|
||||||
|
.map(|address| ChainRegistrationResponse { address })
|
||||||
|
}
|
||||||
|
|
||||||
fn is_governance_emitter(cfg: &ConfigInfo, emitter_chain: u16, emitter_address: &[u8]) -> bool {
|
fn is_governance_emitter(cfg: &ConfigInfo, emitter_chain: u16, emitter_address: &[u8]) -> bool {
|
||||||
cfg.gov_chain == emitter_chain && cfg.gov_address == emitter_address
|
cfg.gov_chain == emitter_chain && cfg.gov_address == emitter_address
|
||||||
}
|
}
|
||||||
|
|
|
@ -79,6 +79,7 @@ pub enum QueryMsg {
|
||||||
TransferInfo { vaa: Binary },
|
TransferInfo { vaa: Binary },
|
||||||
ExternalId { external_id: Binary },
|
ExternalId { external_id: Binary },
|
||||||
IsVaaRedeemed { vaa: Binary },
|
IsVaaRedeemed { vaa: Binary },
|
||||||
|
ChainRegistration { chain: u16 },
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)]
|
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)]
|
||||||
|
@ -110,3 +111,9 @@ pub struct ExternalIdResponse {
|
||||||
pub struct IsVaaRedeemedResponse {
|
pub struct IsVaaRedeemedResponse {
|
||||||
pub is_redeemed: bool,
|
pub is_redeemed: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)]
|
||||||
|
#[serde(rename_all = "snake_case")]
|
||||||
|
pub struct ChainRegistrationResponse {
|
||||||
|
pub address: Binary,
|
||||||
|
}
|
||||||
|
|
|
@ -262,6 +262,7 @@ test("Deploy Contracts", (done) => {
|
||||||
})();
|
})();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
passOnceTests(false, 1);
|
||||||
alwaysPassTests(false, 1);
|
alwaysPassTests(false, 1);
|
||||||
|
|
||||||
describe("Upgrade to shutdown contracts Tests", () => {
|
describe("Upgrade to shutdown contracts Tests", () => {
|
||||||
|
@ -350,7 +351,7 @@ describe("Upgrade to shutdown contracts Tests", () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
alwaysPassTests(true, 2);
|
alwaysPassTests(true, 2);
|
||||||
passOnceTests(true, 1);
|
passOnceTests(true, 2);
|
||||||
failInShutdownModeTests(true, 1);
|
failInShutdownModeTests(true, 1);
|
||||||
|
|
||||||
describe("Upgrade to previous non-shutdown contracts Tests", () => {
|
describe("Upgrade to previous non-shutdown contracts Tests", () => {
|
||||||
|
@ -1374,6 +1375,27 @@ function alwaysPassTests(shutdownMode: boolean, pass: number) {
|
||||||
}
|
}
|
||||||
})();
|
})();
|
||||||
});
|
});
|
||||||
|
test("Query Chain Registration", (done) => {
|
||||||
|
(async () => {
|
||||||
|
try {
|
||||||
|
const [client] = await makeProviderAndWallet();
|
||||||
|
|
||||||
|
const tokenbridge = contracts.get("tokenBridge")!;
|
||||||
|
const result: any = await client.wasm.contractQuery(tokenbridge, {
|
||||||
|
chain_registration: {
|
||||||
|
chain: FOREIGN_CHAIN,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
expect(result).toStrictEqual({
|
||||||
|
address: Buffer.from(FOREIGN_TOKEN_BRIDGE, "hex").toString("base64")
|
||||||
|
});
|
||||||
|
done();
|
||||||
|
} catch (e) {
|
||||||
|
console.error(e);
|
||||||
|
done("Failed to Query Chain Registration");
|
||||||
|
}
|
||||||
|
})();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue