-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(nibiru-std): implement NibiruStargateQuery as an extension of pr…
…ost::Name feat(nibiru-std): implement NibiruStargateQuery as an extension of prost::Name
- Loading branch information
Showing
11 changed files
with
257 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -229,4 +229,4 @@ impl CustomQuery for QueryMsg {} | |
#[cw_serde] | ||
pub struct SudoersQueryResponse { | ||
pub sudoers: Sudoers, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
//! Implements the prost::Name trait for cosmos protobuf types, which defines | ||
//! the prost::Message.type_url function needed for CosmWasm smart contracts. | ||
use prost::Name; | ||
|
||
use crate::proto::cosmos; | ||
|
||
const PACKAGE_BANK: &str = "cosmos.bank.v1beta1"; | ||
|
||
impl Name for cosmos::bank::v1beta1::QuerySupplyOfRequest { | ||
const NAME: &'static str = "QuerySupplyOfRequest"; | ||
const PACKAGE: &'static str = PACKAGE_BANK; | ||
} | ||
|
||
impl Name for cosmos::bank::v1beta1::QueryBalanceRequest { | ||
const NAME: &'static str = "QueryBalanceRequest"; | ||
const PACKAGE: &'static str = PACKAGE_BANK; | ||
} | ||
|
||
impl Name for cosmos::bank::v1beta1::QueryAllBalancesRequest { | ||
const NAME: &'static str = "QueryAllBalancesRequest"; | ||
const PACKAGE: &'static str = PACKAGE_BANK; | ||
} | ||
|
||
impl Name for cosmos::bank::v1beta1::QueryDenomMetadataRequest { | ||
const NAME: &'static str = "QueryDenomMetadataRequest"; | ||
const PACKAGE: &'static str = PACKAGE_BANK; | ||
} | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
|
||
use cosmwasm_std::{Empty, QueryRequest}; | ||
|
||
use crate::{ | ||
errors::{NibiruResult, TestResult}, | ||
proto::{cosmos, NibiruStargateQuery}, | ||
}; | ||
|
||
#[test] | ||
fn stargate_query_conversion() -> TestResult { | ||
let test_cases: Vec<(&str, NibiruResult<QueryRequest<Empty>>)> = vec![ | ||
( | ||
"/cosmos.bank.v1beta1.Query/SupplyOf", | ||
cosmos::bank::v1beta1::QuerySupplyOfRequest { | ||
denom: String::from("some_denom"), | ||
} | ||
.into_stargate_query(), | ||
), | ||
( | ||
"/cosmos.bank.v1beta1.Query/Balance", | ||
cosmos::bank::v1beta1::QueryBalanceRequest { | ||
address: String::from("some_address"), | ||
denom: String::from("some_denom"), | ||
} | ||
.into_stargate_query(), | ||
), | ||
( | ||
"/cosmos.bank.v1beta1.Query/DenomMetadata", | ||
cosmos::bank::v1beta1::QueryDenomMetadataRequest { | ||
denom: String::from("some_denom"), | ||
} | ||
.into_stargate_query(), | ||
), | ||
]; | ||
|
||
for test_case in test_cases { | ||
let test_case_path = test_case.0; | ||
let pb_query = test_case.1?; | ||
if let QueryRequest::Stargate { path, data: _data } = &pb_query { | ||
assert_eq!(test_case_path, path) | ||
} else { | ||
panic!("failed test on case: {:#?} ", test_case_path) | ||
} | ||
} | ||
|
||
Ok(()) | ||
} | ||
} |
Oops, something went wrong.