Skip to content

Commit

Permalink
Clean up naming, fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
ethanfrey committed Feb 7, 2020
1 parent 7276c33 commit 78759c4
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
3 changes: 2 additions & 1 deletion contracts/hackatom/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ pub struct State {
// failure modes to help test wasmd, based on this comment
// https://github.com/cosmwasm/wasmd/issues/8#issuecomment-576146751
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
#[serde(rename_all = "lowercase")]
pub enum HandleMsg {
// Release is the only "proper" action, releasing funds in the contract
Release {},
Expand Down Expand Up @@ -103,7 +104,7 @@ fn cpu_loop() -> Result<Response> {
let mut counter = 0u64;
loop {
counter += 1;
if counter >= 9000000000 {
if counter >= 9_000_000_000 {
counter = 0;
}
}
Expand Down
14 changes: 11 additions & 3 deletions contracts/hackatom/tests/integration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use cosmwasm::serde::{from_slice, to_vec};
use cosmwasm::traits::{Api, ReadonlyStorage};
use cosmwasm::types::{coin, CosmosMsg, HumanAddr, QueryResult};

use cosmwasm_vm::{call_handle};
use cosmwasm_vm::call_handle;
use cosmwasm_vm::testing::{handle, init, mock_instance, query};

use hackatom::contract::{HandleMsg, InitMsg, QueryMsg, State, CONFIG_KEY};
Expand Down Expand Up @@ -214,13 +214,21 @@ fn handle_panic_and_loops() {
let handle_params = mock_params(&deps.api, beneficiary.as_str(), &[], &coin("1000", "earth"));
// panic inside contract should not panic out here
// Note: we need to use the production-call, not the testing call (which unwraps any vm error)
let handle_res = call_handle(&mut deps, &handle_params, &to_vec(&HandleMsg::Panic {}).unwrap());
let handle_res = call_handle(
&mut deps,
&handle_params,
&to_vec(&HandleMsg::Panic {}).unwrap(),
);
assert!(handle_res.is_err());

// TRY INFINITE LOOP
// Note: we need to use the production-call, not the testing call (which unwraps any vm error)
deps.set_gas(1_000_000);
let handle_res = call_handle(&mut deps, &handle_params, &to_vec(&HandleMsg::CpuLoop {}).unwrap());
let handle_res = call_handle(
&mut deps,
&handle_params,
&to_vec(&HandleMsg::CpuLoop {}).unwrap(),
);
assert!(handle_res.is_err());
assert_eq!(deps.get_gas(), 0);
}

0 comments on commit 78759c4

Please sign in to comment.