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

Fix: u128 deser errors #19

Merged
merged 7 commits into from
Aug 20, 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
6 changes: 2 additions & 4 deletions src/msgs/assert_json.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
//! if cosmwasm feature is enabled, also assert that we can deserialize the json back to the msg

#[track_caller]
#[cfg(not(feature = "cosmwasm"))]
pub fn assert_json_ok<M>(msg: M, expected_json: serde_json::Value)
pub fn assert_json_ser<M>(msg: M, expected_json: serde_json::Value)
where
M: serde::Serialize + std::fmt::Debug + PartialEq,
{
Expand All @@ -12,8 +11,7 @@ where
}

#[track_caller]
#[cfg(feature = "cosmwasm")]
pub fn assert_json_ok<M>(msg: M, expected_json: serde_json::Value)
pub fn assert_json_deser<M>(msg: M, expected_json: serde_json::Value)
where
M: serde::Serialize + std::fmt::Debug + PartialEq + serde::de::DeserializeOwned,
{
Expand Down
3 changes: 2 additions & 1 deletion src/msgs/data_requests/execute/commit_result.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,14 @@ impl ExecuteFactory {
&self.hash
}

pub fn create_message(self, proof: Vec<u8>) -> Execute {
pub fn create_message(self, proof: Vec<u8>) -> crate::msgs::ExecuteMsg {
Execute {
dr_id: self.dr_id,
commitment: self.commitment,
public_key: self.public_key,
proof: proof.to_hex(),
}
.into()
}
}

Expand Down
3 changes: 2 additions & 1 deletion src/msgs/data_requests/execute/reveal_result.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ impl ExecuteFactory {
&self.hash
}

pub fn create_message(self, proof: Vec<u8>) -> Execute {
pub fn create_message(self, proof: Vec<u8>) -> crate::msgs::ExecuteMsg {
Execute {
dr_id: self.dr_id,
reveal_body: self.reveal_body,
Expand All @@ -71,6 +71,7 @@ impl ExecuteFactory {
stderr: self.stderr,
stdout: self.stdout,
}
.into()
}
}

Expand Down
36 changes: 18 additions & 18 deletions src/msgs/data_requests/execute_tests.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
use semver::Version;
use serde_json::json;

use super::{execute::*, ExecuteMsg, PostDataRequestArgs, RevealBody};
#[cfg(feature = "cosmwasm")]
use super::{Bytes, U128};
use crate::msgs::assert_json_ok;
use super::Bytes;
use super::{execute::*, ExecuteMsg, PostDataRequestArgs, RevealBody};
use crate::msgs::*;

#[test]
fn json_commit_result() {
Expand All @@ -23,7 +23,10 @@ fn json_commit_result() {
proof: "proof".to_string(),
}
.into();
assert_json_ok(msg, expected_json);
#[cfg(not(feature = "cosmwasm"))]
assert_json_ser(msg, expected_json);
#[cfg(feature = "cosmwasm")]
assert_json_deser(msg, expected_json);
}

#[test]
Expand All @@ -43,15 +46,9 @@ fn json_post_request() {
#[cfg(feature = "cosmwasm")]
let consensus_filter: Bytes = "consensus_filter".as_bytes().into();

#[cfg(not(feature = "cosmwasm"))]
let gas_price = 100;
#[cfg(feature = "cosmwasm")]
let gas_price: U128 = 100u128.into();
let gas_price = 100u128.into();

#[cfg(not(feature = "cosmwasm"))]
let gas_limit = 100;
#[cfg(feature = "cosmwasm")]
let gas_limit: U128 = 100u128.into();
let gas_limit = 100u128.into();

#[cfg(not(feature = "cosmwasm"))]
let memo = "memo".to_string();
Expand Down Expand Up @@ -104,15 +101,15 @@ fn json_post_request() {
payback_address,
}
.into();
assert_json_ok(msg, expected_json);
#[cfg(not(feature = "cosmwasm"))]
assert_json_ser(msg, expected_json);
#[cfg(feature = "cosmwasm")]
assert_json_deser(msg, expected_json);
}

#[test]
fn json_reveal_result() {
#[cfg(not(feature = "cosmwasm"))]
let gas_used = 100;
#[cfg(feature = "cosmwasm")]
let gas_used: U128 = 100u128.into();
let gas_used = 100u128.into();

#[cfg(not(feature = "cosmwasm"))]
let reveal = "reveal".to_string();
Expand Down Expand Up @@ -149,5 +146,8 @@ fn json_reveal_result() {
stdout: vec!["some-output".to_string()],
}
.into();
assert_json_ok(msg, expected_json);
#[cfg(not(feature = "cosmwasm"))]
assert_json_ser(msg, expected_json);
#[cfg(feature = "cosmwasm")]
assert_json_deser(msg, expected_json);
}
1 change: 1 addition & 0 deletions src/msgs/data_requests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,5 @@ mod test {
mod execute_tests;
mod query_tests;
mod sudo_tests;
mod types_tests;
}
43 changes: 32 additions & 11 deletions src/msgs/data_requests/query_tests.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use serde_json::json;

use super::{data_requests::DataRequestStatus, query::QueryMsg as DrQueryMsg, QueryMsg};
use crate::msgs::assert_json_ok;
use crate::msgs::*;

#[test]
fn json_get_data_request() {
Expand All @@ -14,7 +14,10 @@ fn json_get_data_request() {
dr_id: "dr_id".to_string(),
}
.into();
assert_json_ok(msg, expected_json);
#[cfg(not(feature = "cosmwasm"))]
assert_json_ser(msg, expected_json);
#[cfg(feature = "cosmwasm")]
assert_json_deser(msg, expected_json);
}

#[test]
Expand All @@ -30,7 +33,10 @@ fn json_get_data_request_commitment() {
public_key: "public_key".to_string(),
}
.into();
assert_json_ok(msg, expected_json);
#[cfg(not(feature = "cosmwasm"))]
assert_json_ser(msg, expected_json);
#[cfg(feature = "cosmwasm")]
assert_json_deser(msg, expected_json);
}

#[test]
Expand All @@ -44,7 +50,10 @@ fn json_get_data_request_commitments() {
dr_id: "dr_id".to_string(),
}
.into();
assert_json_ok(msg, expected_json);
#[cfg(not(feature = "cosmwasm"))]
assert_json_ser(msg, expected_json);
#[cfg(feature = "cosmwasm")]
assert_json_deser(msg, expected_json);
}

#[test]
Expand All @@ -60,21 +69,27 @@ fn json_get_data_request_reveal() {
public_key: "public_key".to_string(),
}
.into();
assert_json_ok(msg, expected_json);
#[cfg(not(feature = "cosmwasm"))]
assert_json_ser(msg, expected_json);
#[cfg(feature = "cosmwasm")]
assert_json_deser(msg, expected_json);
}

#[test]
fn json_get_data_request_reveals() {
let expected_json = json!({
"get_data_request_reveals": {
"dr_id": "dr_id",
}
"get_data_request_reveals": {
"dr_id": "dr_id",
}
});
let msg: QueryMsg = DrQueryMsg::GetDataRequestReveals {
dr_id: "dr_id".to_string(),
}
.into();
assert_json_ok(msg, expected_json);
#[cfg(not(feature = "cosmwasm"))]
assert_json_ser(msg, expected_json);
#[cfg(feature = "cosmwasm")]
assert_json_deser(msg, expected_json);
}

#[test]
Expand All @@ -88,7 +103,10 @@ fn json_get_data_result() {
dr_id: "dr_id".to_string(),
}
.into();
assert_json_ok(msg, expected_json);
#[cfg(not(feature = "cosmwasm"))]
assert_json_ser(msg, expected_json);
#[cfg(feature = "cosmwasm")]
assert_json_deser(msg, expected_json);
}

#[test]
Expand All @@ -106,5 +124,8 @@ fn json_get_data_requests_by_status() {
limit: 10,
}
.into();
assert_json_ok(msg, expected_json);
#[cfg(not(feature = "cosmwasm"))]
assert_json_ser(msg, expected_json);
#[cfg(feature = "cosmwasm")]
assert_json_deser(msg, expected_json);
}
16 changes: 8 additions & 8 deletions src/msgs/data_requests/sudo_tests.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
use semver::Version;
use serde_json::json;

use super::{sudo::*, DataResult, SudoMsg};
#[cfg(feature = "cosmwasm")]
use super::{Bytes, U128};
use crate::msgs::assert_json_ok;
use super::Bytes;
use super::{sudo::*, DataResult, SudoMsg};
use crate::msgs::*;

#[test]
fn json_post_result() {
Expand All @@ -13,10 +13,7 @@ fn json_post_result() {
#[cfg(feature = "cosmwasm")]
let result_bytes: Bytes = "result".as_bytes().into();

#[cfg(not(feature = "cosmwasm"))]
let gas_used = 100;
#[cfg(feature = "cosmwasm")]
let gas_used: U128 = 100u128.into();
let gas_used = 100u128.into();

#[cfg(not(feature = "cosmwasm"))]
let seda_payload = "seda_payload".to_string();
Expand Down Expand Up @@ -61,5 +58,8 @@ fn json_post_result() {
exit_code: 0,
}
.into();
assert_json_ok(msg, expected_json);
#[cfg(not(feature = "cosmwasm"))]
assert_json_ser(msg, expected_json);
#[cfg(feature = "cosmwasm")]
assert_json_deser(msg, expected_json);
}
4 changes: 0 additions & 4 deletions src/msgs/data_requests/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,6 @@ pub struct DataResult {
/// Block Height at which data request was finalized
pub block_height: u64,
/// Gas used by the complete data request execution
#[cfg_attr(not(feature = "cosmwasm"), serde(serialize_with = "crate::types::serialize_as_str"))]
pub gas_used: U128,

// Fields from Data Request Execution
Expand Down Expand Up @@ -197,7 +196,6 @@ impl TryHashSelf for DataResult {
pub struct RevealBody {
pub salt: String,
pub exit_code: u8,
#[cfg_attr(not(feature = "cosmwasm"), serde(serialize_with = "crate::types::serialize_as_str"))]
pub gas_used: U128,
pub reveal: Bytes,
}
Expand Down Expand Up @@ -235,9 +233,7 @@ pub struct PostDataRequestArgs {
pub tally_inputs: Bytes,
pub replication_factor: u16,
pub consensus_filter: Bytes,
#[cfg_attr(not(feature = "cosmwasm"), serde(serialize_with = "crate::types::serialize_as_str"))]
pub gas_price: U128,
#[cfg_attr(not(feature = "cosmwasm"), serde(serialize_with = "crate::types::serialize_as_str"))]
pub gas_limit: U128,
pub memo: Bytes,
}
Expand Down
Loading