Skip to content

Commit

Permalink
feat(dataverse): implements dataverse query
Browse files Browse the repository at this point in the history
  • Loading branch information
amimart committed Mar 13, 2024
1 parent 4c81b9d commit f93641d
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 9 deletions.
48 changes: 44 additions & 4 deletions contracts/okp4-dataverse/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,16 +113,29 @@ pub mod execute {
}

#[cfg_attr(not(feature = "library"), entry_point)]
pub fn query(_deps: Deps<'_>, _env: Env, _msg: QueryMsg) -> StdResult<Binary> {
Err(StdError::generic_err("Not implemented"))
pub fn query(deps: Deps<'_>, _env: Env, msg: QueryMsg) -> StdResult<Binary> {
match msg {
QueryMsg::Dataverse {} => to_json_binary(&query::dataverse(deps)?),
}
}

pub mod query {}
pub mod query {
use crate::msg::DataverseResponse;
use crate::state::DATAVERSE;
use cosmwasm_std::{Deps, StdResult};

pub fn dataverse(deps: Deps<'_>) -> StdResult<DataverseResponse> {
DATAVERSE.load(deps.storage).map(|d| DataverseResponse {
name: d.name,
triplestore_address: d.triplestore_address,
})
}
}

#[cfg(test)]
mod tests {
use super::*;
use crate::msg::{RdfFormat, TripleStoreConfig, TripleStoreLimitsInput};
use crate::msg::{DataverseResponse, RdfFormat, TripleStoreConfig, TripleStoreLimitsInput};
use crate::testutil::testutil::read_test_data;
use cosmwasm_std::testing::{mock_dependencies, mock_env, mock_info};
use cosmwasm_std::{
Expand Down Expand Up @@ -197,6 +210,33 @@ mod tests {
)
}

#[test]
fn proper_dataverse() {
let mut deps = mock_dependencies();

DATAVERSE
.save(
deps.as_mut().storage,
&Dataverse {
name: "my-dataverse".to_string(),
triplestore_address: Addr::unchecked("my-dataverse-addr"),
},
)
.unwrap();

let res = query(deps.as_ref(), mock_env(), QueryMsg::Dataverse {});
assert!(res.is_ok());
let res: StdResult<DataverseResponse> = from_json(res.unwrap());
assert!(res.is_ok());
assert_eq!(
res.unwrap(),
DataverseResponse {
name: "my-dataverse".to_string(),
triplestore_address: Addr::unchecked("my-dataverse-addr"),
}
);
}

#[test]
fn proper_submit_claims() {
let mut deps = mock_dependencies();
Expand Down
4 changes: 3 additions & 1 deletion contracts/okp4-dataverse/src/msg.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use cosmwasm_schema::{cw_serde, QueryResponses};
use cosmwasm_std::{Binary, Uint128, Uint64};
use cosmwasm_std::{Addr, Binary, Uint128, Uint64};

/// `InstantiateMsg` is used to initialize a new instance of the dataverse.
#[cw_serde]
Expand Down Expand Up @@ -189,4 +189,6 @@ pub enum QueryMsg {
pub struct DataverseResponse {
/// The name of the dataverse.
pub name: String,
/// The cognitarium contract address.
pub triplestore_address: Addr,
}
23 changes: 19 additions & 4 deletions docs/okp4-dataverse.md
Original file line number Diff line number Diff line change
Expand Up @@ -135,12 +135,27 @@ Retrieves information about the current dataverse instance.

DataverseResponse is the response of the Dataverse query.

| property | description |
| -------- | ----------------------------------------------------- |
| `name` | _(Required.) _ **string**. The name of the dataverse. |
| property | description |
| --------------------- | ------------------------------------------------------------------- |
| `name` | _(Required.) _ **string**. The name of the dataverse. |
| `triplestore_address` | _(Required.) _ **[Addr](#addr)**. The cognitarium contract address. |

## Definitions

### Addr

A human readable address.

In Cosmos, this is typically bech32 encoded. But for multi-chain smart contracts no assumptions should be made other than being UTF-8 encoded and of reasonable length.

This type represents a validated address. It can be created in the following ways 1. Use `Addr::unchecked(input)` 2. Use `let checked: Addr = deps.api.addr_validate(input)?` 3. Use `let checked: Addr = deps.api.addr_humanize(canonical_addr)?` 4. Deserialize from JSON. This must only be done from JSON that was validated before such as a contract's state. `Addr` must not be used in messages sent by the user because this would result in unvalidated instances.

This type is immutable. If you really need to mutate it (Really? Are you sure?), create a mutable copy using `let mut mutable = Addr::to_string()` and operate on that `String` instance.

| type |
| ----------- |
| **string**. |

### Binary

A string containing Base64-encoded data.
Expand Down Expand Up @@ -223,5 +238,5 @@ let b = Uint64::from(70u32); assert_eq!(b.u64(), 70); ```
---
*Rendered by [Fadroma](https://fadroma.tech) ([@fadroma/schema 1.1.0](https://www.npmjs.com/package/@fadroma/schema)) from `okp4-dataverse.json` (`c007ecd2b9eeb04a`)*
*Rendered by [Fadroma](https://fadroma.tech) ([@fadroma/schema 1.1.0](https://www.npmjs.com/package/@fadroma/schema)) from `okp4-dataverse.json` (`bd9dd1798f1b3a0d`)*
````

0 comments on commit f93641d

Please sign in to comment.