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

Refactor: Renames & Type Changes #25

Merged
merged 4 commits into from
Oct 10, 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
27 changes: 13 additions & 14 deletions src/msgs/data_requests/execute_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ fn json_commit_result() {
#[test]
fn json_post_request() {
#[cfg(not(feature = "cosmwasm"))]
let dr_inputs = "dr_inputs".to_string();
let exec_inputs = "exec_inputs".to_string();
#[cfg(feature = "cosmwasm")]
let dr_inputs: Bytes = "dr_inputs".as_bytes().into();
let exec_inputs: Bytes = "exec_inputs".as_bytes().into();

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

let gas_price = 100u128.into();

let gas_limit = 100u128.into();
let gas_price: U128 = 100u128.into();
let gas_limit = 100;

#[cfg(not(feature = "cosmwasm"))]
let memo = "memo".to_string();
Expand All @@ -67,9 +66,9 @@ fn json_post_request() {

let args = PostDataRequestArgs {
version: Version::new(1, 0, 0),
dr_binary_id: "dr_binary_id".to_string(),
dr_inputs: dr_inputs.clone(),
tally_binary_id: "tally_binary_id".to_string(),
exec_program_id: "exec_program_id".to_string(),
exec_inputs: exec_inputs.clone(),
tally_program_id: "tally_program_id".to_string(),
tally_inputs: tally_inputs.clone(),
replication_factor: 1,
consensus_filter: consensus_filter.clone(),
Expand All @@ -81,14 +80,14 @@ fn json_post_request() {
"post_data_request": {
"posted_dr": {
"version": "1.0.0",
"dr_binary_id": "dr_binary_id",
"dr_inputs": dr_inputs,
"tally_binary_id": "tally_binary_id",
"exec_program_id": "exec_program_id",
"exec_inputs": exec_inputs,
"tally_program_id": "tally_program_id",
"tally_inputs": tally_inputs,
"replication_factor": 1,
"consensus_filter": consensus_filter,
"gas_price": gas_price.to_string(),
"gas_limit": gas_limit.to_string(),
"gas_limit": gas_limit,
"memo": memo
},
"seda_payload": seda_payload,
Expand All @@ -109,7 +108,7 @@ fn json_post_request() {

#[test]
fn json_reveal_result() {
let gas_used = 100u128.into();
let gas_used = 100;

#[cfg(not(feature = "cosmwasm"))]
let reveal = "reveal".to_string();
Expand All @@ -131,7 +130,7 @@ fn json_reveal_result() {
"id": "dr_id",
"salt": "salt",
"exit_code": 0,
"gas_used": gas_used.to_string(),
"gas_used": gas_used,
"reveal": reveal,
"proxy_public_keys": ["proxy_public_key"]
},
Expand Down
4 changes: 2 additions & 2 deletions src/msgs/data_requests/sudo_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ fn json_post_result() {
#[cfg(feature = "cosmwasm")]
let result_bytes: Bytes = "result".as_bytes().into();

let gas_used = 100u128.into();
let gas_used = 100;

#[cfg(not(feature = "cosmwasm"))]
let seda_payload = "seda_payload".to_string();
Expand Down Expand Up @@ -43,7 +43,7 @@ fn json_post_result() {
"dr_id": "dr_id",
"block_height": 100,
"exit_code": 0,
"gas_used": gas_used.to_string(),
"gas_used": gas_used,
"result": result_bytes,
"payback_address": payback_address,
"seda_payload": seda_payload,
Expand Down
43 changes: 17 additions & 26 deletions src/msgs/data_requests/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,11 @@ pub struct DataRequest {
/// Semantic Version String
pub version: Version,
/// Identifier of DR WASM binary
pub dr_binary_id: String,
pub exec_program_id: String,
/// Inputs for DR WASM binary
pub dr_inputs: Bytes,
pub exec_inputs: Bytes,
/// Identifier of Tally WASM binary
pub tally_binary_id: String,
pub tally_program_id: String,
/// Inputs for Tally WASM binary
pub tally_inputs: Bytes,
/// Amount of required DR executors
Expand All @@ -65,7 +65,7 @@ pub struct DataRequest {
/// Amount of SEDA tokens per gas unit
pub gas_price: U128,
/// Maximum of gas units to be used by data request executors to resolve a data request
pub gas_limit: U128,
pub gas_limit: u64,
/// Public info attached to DR
pub memo: Bytes,

Expand Down Expand Up @@ -129,7 +129,7 @@ pub struct DataResult {
/// Block Height at which data request was finalized
pub block_height: u64,
/// Gas used by the complete data request execution
pub gas_used: U128,
pub gas_used: u64,

// Fields from Data Request Execution
/// Payback address set by the relayer
Expand Down Expand Up @@ -197,7 +197,7 @@ pub struct RevealBody {
pub id: String,
pub salt: String,
pub exit_code: u8,
pub gas_used: U128,
pub gas_used: u64,
pub reveal: Bytes,
pub proxy_public_keys: Vec<String>,
}
Expand All @@ -215,9 +215,6 @@ impl TryHashSelf for RevealBody {
hasher.update(hex::decode(&self.id)?);
hasher.update(&self.salt);
hasher.update(self.exit_code.to_be_bytes());
#[cfg(feature = "cosmwasm")]
hasher.update(self.gas_used.to_be_bytes());
#[cfg(not(feature = "cosmwasm"))]
hasher.update(self.gas_used.to_be_bytes());
hasher.update(reveal_hash);
let proxy_public_keys: &[String] = &self.proxy_public_keys;
Expand All @@ -232,26 +229,26 @@ impl TryHashSelf for RevealBody {
#[cfg_attr(not(feature = "cosmwasm"), serde(rename_all = "snake_case"))]
pub struct PostDataRequestArgs {
pub version: Version,
pub dr_binary_id: String,
pub dr_inputs: Bytes,
pub tally_binary_id: String,
pub exec_program_id: String,
pub exec_inputs: Bytes,
pub tally_program_id: String,
pub tally_inputs: Bytes,
pub replication_factor: u16,
pub consensus_filter: Bytes,
pub gas_price: U128,
pub gas_limit: U128,
pub gas_limit: u64,
pub memo: Bytes,
}

impl TryHashSelf for PostDataRequestArgs {
fn try_hash(&self) -> Result<Hash> {
// hash non-fixed-length inputs
let mut dr_inputs_hasher = Keccak256::new();
let mut exec_inputs_hasher = Keccak256::new();
#[cfg(feature = "cosmwasm")]
dr_inputs_hasher.update(self.dr_inputs.as_slice());
exec_inputs_hasher.update(self.exec_inputs.as_slice());
#[cfg(not(feature = "cosmwasm"))]
dr_inputs_hasher.update(BASE64_STANDARD.decode(&self.dr_inputs)?);
let dr_inputs_hash = dr_inputs_hasher.finalize();
exec_inputs_hasher.update(BASE64_STANDARD.decode(&self.exec_inputs)?);
let exec_inputs_hash = exec_inputs_hasher.finalize();

let mut tally_inputs_hasher = Keccak256::new();
#[cfg(feature = "cosmwasm")]
Expand All @@ -278,19 +275,13 @@ impl TryHashSelf for PostDataRequestArgs {
let mut dr_hasher = Keccak256::new();
dr_hasher.update(self.version.hash());
// I don't think we should decode to hash... expensive in cosmwasm no?
dr_hasher.update(hex::decode(&self.dr_binary_id)?);
dr_hasher.update(dr_inputs_hash);
dr_hasher.update(hex::decode(&self.tally_binary_id)?);
dr_hasher.update(hex::decode(&self.exec_program_id)?);
dr_hasher.update(exec_inputs_hash);
dr_hasher.update(hex::decode(&self.tally_program_id)?);
dr_hasher.update(tally_inputs_hash);
dr_hasher.update(self.replication_factor.to_be_bytes());
dr_hasher.update(consensus_filter_hash);
#[cfg(feature = "cosmwasm")]
dr_hasher.update(self.gas_price.to_be_bytes());
#[cfg(not(feature = "cosmwasm"))]
dr_hasher.update(self.gas_price.to_be_bytes());
#[cfg(feature = "cosmwasm")]
dr_hasher.update(self.gas_limit.to_be_bytes());
#[cfg(not(feature = "cosmwasm"))]
dr_hasher.update(self.gas_limit.to_be_bytes());
dr_hasher.update(memo_hash);

Expand Down
63 changes: 25 additions & 38 deletions src/msgs/data_requests/types_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,19 @@ use serde_json::json;

#[cfg(feature = "cosmwasm")]
use super::Bytes;
use super::{DataRequest, DataResult, HashSelf, PostDataRequestArgs, RevealBody, TimeoutConfig, U128};
use super::{DataRequest, DataResult, HashSelf, PostDataRequestArgs, RevealBody, TimeoutConfig};
use crate::msgs::*;

#[test]
fn json_data_request() {
let id = "id".to_string();
let version = "1.0.0".to_string();
let dr_binary_id = "dr_binary_id".to_string();
let exec_program_id = "exec_program_id".to_string();
#[cfg(not(feature = "cosmwasm"))]
let dr_inputs = "dr_inputs".to_string();
let exec_inputs = "exec_inputs".to_string();
#[cfg(feature = "cosmwasm")]
let dr_inputs: Bytes = "dr_inputs".as_bytes().into();
let tally_binary_id = "tally_binary_id".to_string();
let exec_inputs: Bytes = "exec_inputs".as_bytes().into();
let tally_program_id = "tally_program_id".to_string();
#[cfg(not(feature = "cosmwasm"))]
let tally_inputs = "tally_inputs".to_string();
#[cfg(feature = "cosmwasm")]
Expand All @@ -27,7 +27,7 @@ fn json_data_request() {
#[cfg(feature = "cosmwasm")]
let consensus_filter: Bytes = "consensus_filter".as_bytes().into();
let gas_price: U128 = 1u128.into();
let gas_limit: U128 = 1u128.into();
let gas_limit = 1;
#[cfg(not(feature = "cosmwasm"))]
let memo = "memo".to_string();
#[cfg(feature = "cosmwasm")]
Expand All @@ -47,9 +47,9 @@ fn json_data_request() {
let expected_json = json!({
"id": id,
"version": version,
"dr_binary_id": dr_binary_id,
"dr_inputs": dr_inputs,
"tally_binary_id": tally_binary_id,
"exec_program_id": exec_program_id,
"exec_inputs": exec_inputs,
"tally_program_id": tally_program_id,
"tally_inputs": tally_inputs,
"replication_factor": replication_factor,
"consensus_filter": consensus_filter,
Expand All @@ -66,9 +66,9 @@ fn json_data_request() {
let msg = DataRequest {
id,
version: version.parse().unwrap(),
dr_binary_id,
dr_inputs,
tally_binary_id,
exec_program_id,
exec_inputs,
tally_program_id,
tally_inputs,
replication_factor,
consensus_filter,
Expand Down Expand Up @@ -99,7 +99,7 @@ fn json_data_result() {
#[cfg(feature = "cosmwasm")]
let result: Bytes = "result".as_bytes().into();
let block_height = 1;
let gas_used: U128 = 1u128.into();
let gas_used = 1;
#[cfg(not(feature = "cosmwasm"))]
let payback_address = "payback_address".to_string();
#[cfg(feature = "cosmwasm")]
Expand Down Expand Up @@ -143,7 +143,7 @@ fn json_reveal_body() {
let id = "id".to_string();
let salt = "salt".to_string();
let exit_code = 0;
let gas_used: U128 = 1u128.into();
let gas_used = 1;
#[cfg(not(feature = "cosmwasm"))]
let reveal = "reveal".to_string();
#[cfg(feature = "cosmwasm")]
Expand Down Expand Up @@ -174,28 +174,15 @@ fn json_reveal_body() {
assert_json_deser(msg, expected_json);
}

// pub struct PostDataRequestArgs {
// pub version: Version,
// pub dr_binary_id: String,
// pub dr_inputs: Bytes,
// pub tally_binary_id: String,
// pub tally_inputs: Bytes,
// pub replication_factor: u16,
// pub consensus_filter: Bytes,
// pub gas_price: U128,
// pub gas_limit: U128,
// pub memo: Bytes,
// }

#[test]
fn json_post_data_request_args() {
let version = "1.0.0".to_string();
let dr_binary_id = "dr_binary_id".to_string();
let exec_program_id = "exec_program_id".to_string();
#[cfg(not(feature = "cosmwasm"))]
let dr_inputs = "dr_inputs".to_string();
let exec_inputs = "exec_inputs".to_string();
#[cfg(feature = "cosmwasm")]
let dr_inputs: Bytes = "dr_inputs".as_bytes().into();
let tally_binary_id = "tally_binary_id".to_string();
let exec_inputs: Bytes = "exec_inputs".as_bytes().into();
let tally_program_id = "tally_program_id".to_string();
#[cfg(not(feature = "cosmwasm"))]
let tally_inputs = "tally_inputs".to_string();
#[cfg(feature = "cosmwasm")]
Expand All @@ -206,17 +193,17 @@ fn json_post_data_request_args() {
#[cfg(feature = "cosmwasm")]
let consensus_filter: Bytes = "consensus_filter".as_bytes().into();
let gas_price: U128 = 1u128.into();
let gas_limit: U128 = 1u128.into();
let gas_limit = 1;
#[cfg(not(feature = "cosmwasm"))]
let memo = "memo".to_string();
#[cfg(feature = "cosmwasm")]
let memo: Bytes = "memo".as_bytes().into();

let expected_json = json!({
"version": version,
"dr_binary_id": dr_binary_id,
"dr_inputs": dr_inputs,
"tally_binary_id": tally_binary_id,
"exec_program_id": exec_program_id,
"exec_inputs": exec_inputs,
"tally_program_id": tally_program_id,
"tally_inputs": tally_inputs,
"replication_factor": replication_factor,
"consensus_filter": consensus_filter,
Expand All @@ -227,9 +214,9 @@ fn json_post_data_request_args() {

let msg = PostDataRequestArgs {
version: version.parse().unwrap(),
dr_binary_id,
dr_inputs,
tally_binary_id,
exec_program_id,
exec_inputs,
tally_program_id,
tally_inputs,
replication_factor,
consensus_filter,
Expand Down