Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade contracts to cosmwasm 2 #302

Merged
merged 4 commits into from
Jun 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
266 changes: 136 additions & 130 deletions Cargo.lock

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ resolver = "2"

[workspace.dependencies]
# nois = { git = "https://github.com/noislabs/nois", branch = "add-published-time" }
nois = "0.7.0"
cw2 = "1.1.1"
nois = "2.0.0"
cw2 = "2"

[profile.release.package.nois-protocol]
codegen-units = 1
Expand Down
9 changes: 3 additions & 6 deletions contracts/nois-demo/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,11 @@ license = "Apache-2.0"
crate-type = ["cdylib", "rlib"]

[features]
# for quicker tests, cargo test --lib
# for more explicit tests, cargo test --features=backtraces
backtraces = ["cosmwasm-std/backtraces"]

[dependencies]
cosmwasm-std = { version = "1.5.4", features = ["iterator"] }
cosmwasm-schema = { version = "1.5.4" }
cw-storage-plus = { version = "1.1.0" }
cosmwasm-std = { version = "2.0.4", features = ["iterator"] }
cosmwasm-schema = { version = "2.0.4" }
cw-storage-plus = { version = "2" }
nois.workspace = true
serde = { version = "1.0.103", default-features = false, features = ["derive"] }
thiserror = { version = "1.0.23" }
Expand Down
24 changes: 15 additions & 9 deletions contracts/nois-demo/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ fn query_result(deps: Deps, job_id: String) -> StdResult<Option<Decimal>> {
mod tests {
use super::*;
use cosmwasm_std::{
testing::{mock_dependencies, mock_env, mock_info, MockApi, MockQuerier, MockStorage},
testing::{message_info, mock_dependencies, mock_env, MockApi, MockQuerier, MockStorage},
Empty, HexBinary, OwnedDeps, Timestamp,
};

Expand All @@ -133,49 +133,54 @@ mod tests {
#[test]
fn instantiate_works() {
let mut deps = mock_dependencies();
let creator = deps.api.addr_make(CREATOR);
let msg = InstantiateMsg {
nois_proxy: "address123".to_string(),
nois_proxy: deps.api.addr_make("address123").into(),
};
let info = mock_info(CREATOR, &[]);
let info = message_info(&creator, &[]);
let res = instantiate(deps.as_mut(), mock_env(), info, msg).unwrap();
assert_eq!(0, res.messages.len());
}

#[test]
fn instantiate_fails_for_invalid_proxy_address() {
let mut deps = mock_dependencies();
let creator = deps.api.addr_make(CREATOR);
let msg = InstantiateMsg {
nois_proxy: "".to_string(),
};
let info = mock_info(CREATOR, &[]);
let info = message_info(&creator, &[]);
let res = instantiate(deps.as_mut(), mock_env(), info, msg).unwrap_err();
assert_eq!(res, ContractError::InvalidProxyAddress);
}

fn instantiate_proxy() -> OwnedDeps<MockStorage, MockApi, MockQuerier, Empty> {
let mut deps = mock_dependencies();
let creator = deps.api.addr_make(CREATOR);
let msg = InstantiateMsg {
nois_proxy: PROXY_ADDRESS.to_string(),
nois_proxy: deps.api.addr_make(PROXY_ADDRESS).into(),
};
let info = mock_info(CREATOR, &[]);
let info = message_info(&creator, &[]);
instantiate(deps.as_mut(), mock_env(), info, msg).unwrap();
deps
}

#[test]
fn execute_estimate_pi_works() {
let mut deps = instantiate_proxy();
let guest = deps.api.addr_make("guest");

let msg = ExecuteMsg::EstimatePi {
job_id: "123".to_owned(),
};
let info = mock_info("guest", &[]);
let info = message_info(&guest, &[]);
execute(deps.as_mut(), mock_env(), info, msg).unwrap();
}

#[test]
fn execute_receive_works() {
let mut deps = instantiate_proxy();
let proxy = deps.api.addr_make(PROXY_ADDRESS);

let msg = ExecuteMsg::NoisReceive {
callback: NoisCallback {
Expand All @@ -187,13 +192,14 @@ mod tests {
.unwrap(),
},
};
let info = mock_info(PROXY_ADDRESS, &[]);
let info = message_info(&proxy, &[]);
execute(deps.as_mut(), mock_env(), info, msg).unwrap();
}

#[test]
fn execute_receive_fails_for_wrong_sender() {
let mut deps = instantiate_proxy();
let guest = deps.api.addr_make("guest");

let msg = ExecuteMsg::NoisReceive {
callback: NoisCallback {
Expand All @@ -205,7 +211,7 @@ mod tests {
.unwrap(),
},
};
let info = mock_info("guest", &[]);
let info = message_info(&guest, &[]);
let err = execute(deps.as_mut(), mock_env(), info, msg).unwrap_err();
assert!(matches!(err, ContractError::UnauthorizedReceive));
}
Expand Down
9 changes: 3 additions & 6 deletions contracts/nois-drand/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,15 @@ license = "Apache-2.0"
crate-type = ["cdylib", "rlib"]

[features]
# for quicker tests, cargo test --lib
# for more explicit tests, cargo test --features=backtraces
backtraces = ["cosmwasm-std/backtraces"]
# use library feature to disable all instantiate/execute/query exports
library = []

[dependencies]
nois.workspace = true
drand-common = { path = "../../packages/drand-common" }
cosmwasm-std = { version = "1.5.4", features = ["iterator", "ibc3"] }
cosmwasm-schema = { version = "1.5.4" }
cw-storage-plus = { version = "1.1.0" }
cosmwasm-std = { version = "2.0.4", features = ["iterator"] }
cosmwasm-schema = { version = "2.0.4" }
cw-storage-plus = { version = "2" }
cw2.workspace = true
serde = { version = "1.0.103", default-features = false, features = ["derive"] }
thiserror = { version = "1.0.23" }
Expand Down
Loading