Skip to content

Commit

Permalink
Merge pull request #87 from securesecrets/contract-tester/rust-migration
Browse files Browse the repository at this point in the history
Contract tester in rust
  • Loading branch information
FloppyDisck authored Sep 12, 2021
2 parents a1e57ad + 8000dbd commit 9a30ddc
Show file tree
Hide file tree
Showing 21 changed files with 1,717 additions and 523 deletions.
577 changes: 78 additions & 499 deletions Cargo.lock

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
[workspace]
members = [
"packages/shade_protocol",
"packages/secretcli",
"contracts/initializer",
"contracts/mint",
"contracts/micro_mint",
Expand Down
6 changes: 3 additions & 3 deletions contracts/initializer/src/query.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use cosmwasm_std::{Storage, Api, Querier, Extern, StdResult, to_binary, Binary};
use shade_protocol::initializer::{QueryMsg, ContractsAnswer};
use shade_protocol::initializer::{QueryMsg, QueryAnswer};
use crate::state::config_r;

pub fn query_contracts<S: Storage, A: Api, Q: Querier>(deps: &Extern<S, A, Q>) -> StdResult<ContractsAnswer> {
Ok(ContractsAnswer { contracts: config_r(&deps.storage).load()?.contracts })
pub fn query_contracts<S: Storage, A: Api, Q: Querier>(deps: &Extern<S, A, Q>) -> StdResult<QueryAnswer> {
Ok(QueryAnswer::ContractsAnswer { contracts: config_r(&deps.storage).load()?.contracts })
}
4 changes: 2 additions & 2 deletions contracts/micro_mint/src/handle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use shade_protocol::{
Config,
SupportedAsset,
},
mint::SnipMsgHook,
mint::MintMsgHook,
snip20::{Snip20Asset, token_config_query, TokenConfig},
oracle::{
QueryMsg::GetPrice,
Expand Down Expand Up @@ -70,7 +70,7 @@ pub fn try_burn<S: Storage, A: Api, Q: Querier>(

// Setup msgs
let mut messages = vec![];
let msgs: SnipMsgHook = match msg {
let msgs: MintMsgHook = match msg {
Some(x) => from_binary(&x)?,
None => return Err(StdError::generic_err("data cannot be empty")),
};
Expand Down
5 changes: 1 addition & 4 deletions contracts/mock_band/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,7 @@ use cosmwasm_std::{
};
use serde::{Deserialize, Serialize};
use schemars::JsonSchema;
use shade_protocol::band::ReferenceData;

#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
pub struct InitMsg { }
use shade_protocol::band::{ReferenceData, InitMsg};

pub fn init<S: Storage, A: Api, Q: Querier>(
_deps: &mut Extern<S, A, Q>,
Expand Down
21 changes: 13 additions & 8 deletions makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,24 @@ contracts_dir=contracts
compiled_dir=compiled
checksum_dir=${compiled_dir}/checksum

CONTRACTS = mint snip20 treasury micro_mint oracle mock_band initializer
define build_wasm =
(cd $(contracts_dir)/$(1); cargo unit-test)
(cd ${contracts_dir}; cargo build --release --target wasm32-unknown-unknown --locked)
wasm-opt -Oz ./target/wasm32-unknown-unknown/release/$(2).wasm -o ./$(1).wasm
echo $(md5sum $(1).wasm | cut -f 1 -d " ") >> ${checksum_dir}/$(1).txt
cat ./$(1).wasm | gzip -n -9 > ${compiled_dir}/$(1).wasm.gz
rm ./$(1).wasm
endef

CONTRACTS = mint treasury micro_mint oracle mock_band initializer

COMPILED = ${CONTRACTS:=.wasm.gz}

all: setup $(CONTRACTS)
all: setup $(CONTRACTS); $(call build_wasm,snip20,snip20_reference_impl)

$(CONTRACTS):
(cd $(contracts_dir)/$@; cargo unit-test)
(cd ${contracts_dir}; cargo build --release --target wasm32-unknown-unknown --locked)
wasm-opt -Oz ./target/wasm32-unknown-unknown/release/$@.wasm -o ./$@.wasm
echo $(md5sum $@.wasm | cut -f 1 -d " ") >> ${checksum_dir}/$@.txt
cat ./$@.wasm | gzip -n -9 > ${compiled_dir}/$@.wasm.gz
rm ./$@.wasm
$(call build_wasm,$@,$@)


setup: $(compiled_dir) $(checksum_dir)

Expand Down
Loading

0 comments on commit 9a30ddc

Please sign in to comment.