-
Notifications
You must be signed in to change notification settings - Fork 338
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1292 from CosmWasm/iterator-contract
Improve queue contract for iterator testing
- Loading branch information
Showing
10 changed files
with
163 additions
and
80 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
[package] | ||
name = "queue" | ||
version = "0.0.0" | ||
authors = ["Ethan Frey <[email protected]>"] | ||
authors = ["Simon Warta <[email protected]>", "Ethan Frey <[email protected]>"] | ||
edition = "2021" | ||
publish = false | ||
license = "Apache-2.0" | ||
|
@@ -23,8 +23,9 @@ incremental = false | |
overflow-checks = true | ||
|
||
[features] | ||
# Change this to [] if you don't need Windows support and want faster integration tests. | ||
default = ["cranelift"] | ||
# Change this to ["cranelift"] if you don't need Windows support and want faster integration tests. | ||
#default = ["cranelift"] | ||
default = [] | ||
# Use cranelift backend instead of singlepass. This is required for development on Windows. | ||
cranelift = ["cosmwasm-vm/cranelift"] | ||
# For quicker tests, cargo test --lib. for more explicit tests, cargo test --features=backtraces | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
pub mod contract; | ||
pub mod msg; | ||
pub mod state; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,61 @@ | ||
use schemars::JsonSchema; | ||
use serde::{Deserialize, Serialize}; | ||
|
||
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)] | ||
#[serde(rename_all = "snake_case")] | ||
pub enum ExecuteMsg { | ||
// Enqueue will add some value to the end of list | ||
Enqueue { value: i32 }, | ||
// Dequeue will remove value from start of the list | ||
Dequeue {}, | ||
} | ||
|
||
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)] | ||
pub struct InstantiateMsg {} | ||
|
||
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)] | ||
pub struct MigrateMsg {} | ||
|
||
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)] | ||
#[serde(rename_all = "snake_case")] | ||
pub enum QueryMsg { | ||
// how many items are in the queue | ||
Count {}, | ||
// total of all values in the queue | ||
Sum {}, | ||
// Reducer holds open two iterators at once | ||
Reducer {}, | ||
List {}, | ||
/// Opens the given number of iterators for no reason other than testing. | ||
/// Returns and `Empty` response. | ||
OpenIterators { | ||
count: u32, | ||
}, | ||
} | ||
|
||
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)] | ||
pub struct CountResponse { | ||
pub count: u32, | ||
} | ||
|
||
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)] | ||
pub struct SumResponse { | ||
pub sum: i32, | ||
} | ||
|
||
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)] | ||
// the Vec contains pairs for every element in the queue | ||
// (value of item i, sum of all elements where value > value[i]) | ||
pub struct ReducerResponse { | ||
pub counters: Vec<(i32, i32)>, | ||
} | ||
|
||
#[derive(Serialize, Deserialize, Clone, PartialEq, JsonSchema, Debug)] | ||
pub struct ListResponse { | ||
/// List an empty range, both bounded | ||
pub empty: Vec<u32>, | ||
/// List all IDs lower than 0x20 | ||
pub early: Vec<u32>, | ||
/// List all IDs starting from 0x20 | ||
pub late: Vec<u32>, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
use schemars::JsonSchema; | ||
use serde::{Deserialize, Serialize}; | ||
|
||
// we store one entry for each item in the queue | ||
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)] | ||
pub struct Item { | ||
pub value: i32, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters