Skip to content

Commit

Permalink
feat(law): add Law state + tests
Browse files Browse the repository at this point in the history
  • Loading branch information
bdeneux authored and amimart committed Mar 23, 2023
1 parent c9f8664 commit 35e8e91
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 2 deletions.
9 changes: 7 additions & 2 deletions contracts/cw-law-stone/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ pub fn query(_deps: Deps<'_>, _env: Env, _msg: QueryMsg) -> StdResult<Binary> {
#[cfg(test)]
mod tests {
use super::*;

use crate::state::LAW;
use cosmwasm_std::testing::{mock_env, mock_info, MockQuerierCustomHandlerResult};
use cosmwasm_std::{ to_binary, SystemResult, SystemError};
use logic_bindings::{Answer, AskResponse, LogicCustomQuery, Substitution, Term, Result as LogicResult};
Expand Down Expand Up @@ -84,11 +84,16 @@ mod tests {

let msg = InstantiateMsg {
program: Default::default(),
storage_address: "".to_string(),
storage_address: "okp41ffzp0xmjhwkltuxcvccl0z9tyfuu7txp5ke0tpkcjpzuq9fcj3pqrteqt3".to_string(),
};
let info = mock_info("creator", &[]);

let res = instantiate(deps.as_mut(), mock_env(), info, msg).unwrap();
assert_eq!(0, res.messages.len());

// check internal state too
let law = LAW.load(&deps.storage).unwrap();
assert_eq!(law.program.storage_address, "okp41ffzp0xmjhwkltuxcvccl0z9tyfuu7txp5ke0tpkcjpzuq9fcj3pqrteqt3".to_string());
assert_eq!(law.dependencies, vec!["file1".to_string()]);
}
}
1 change: 1 addition & 0 deletions contracts/cw-law-stone/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,6 @@
pub mod contract;
mod error;
pub mod msg;
pub mod state;

pub use crate::error::ContractError;
24 changes: 24 additions & 0 deletions contracts/cw-law-stone/src/state.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};

use cw_storage_plus::Item;

#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)]
pub struct Law {
/// The `cw-storage` object link to the Prolog program carrying law rules and facts.
pub program: Object,

/// The list of all `cw-storage` dependencies of the law program.
pub dependencies: Vec<String>,
}

/// Represent a link to an Object stored in the `cw-storage` contract.
pub struct Object {
/// The object id in the `cw-storage` contract.
pub object_id: String,

/// The `cw-storage` contract address on which the object is stored.
pub storage_address: String,
}

pub const LAW: Item<'_, Law> = Item::new("law");

0 comments on commit 35e8e91

Please sign in to comment.