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

A set of fixes and features for wit\2 #2472

Open
wants to merge 14 commits into
base: 2.0-master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 8 additions & 6 deletions bridges/centralized-ethereum/src/actors/dr_sender/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ use witnet_data_structures::chain::{RADAggregate, RADRequest, RADRetrieve, RADTa
#[test]
fn deserialize_empty_dr() {
// An empty data request is invalid with error 0xE0: BridgeMalformedRequest
let err = deserialize_and_validate_dr_bytes(&[], 1).unwrap_err();
let err = deserialize_and_validate_dr_bytes(&[], 0, 1).unwrap_err();
assert_eq!(err.encode_cbor(), vec![216, 39, 129, 24, 224]);
}

#[test]
fn deserialize_dr_not_protobuf() {
// A malformed data request is invalid with error 0xE0: BridgeMalformedRequest
let err = deserialize_and_validate_dr_bytes(&[1, 2, 3, 4], 1).unwrap_err();
let err = deserialize_and_validate_dr_bytes(&[1, 2, 3, 4], 0, 1).unwrap_err();
assert_eq!(err.encode_cbor(), vec![216, 39, 129, 24, 224]);
}

Expand Down Expand Up @@ -55,7 +55,8 @@ fn deserialize_dr_high_value() {
let dro_bytes = dro.to_pb_bytes().unwrap();
// Setting the maximum allowed value to 1 nanowit below that will result in an error 0xE1:
// BridgePoorIncentives
let err = deserialize_and_validate_dr_bytes(&dro_bytes, total_value - 1).unwrap_err();
let err =
deserialize_and_validate_dr_bytes(&dro_bytes, 1_000_000_000, total_value - 1).unwrap_err();
assert_eq!(err.encode_cbor(), vec![216, 39, 129, 24, 225]);
}

Expand All @@ -78,7 +79,7 @@ fn deserialize_dr_collateral_one_nanowit() {
assert_eq!(total_value, 20_000_000);

let dro_bytes = dro.to_pb_bytes().unwrap();
let err = deserialize_and_validate_dr_bytes(&dro_bytes, total_value).unwrap_err();
let err = deserialize_and_validate_dr_bytes(&dro_bytes, 1, total_value).unwrap_err();
assert_eq!(err.encode_cbor(), vec![216, 39, 129, 24, 224]);
}

Expand All @@ -95,7 +96,7 @@ fn deserialize_dr_value_overflow() {
};

let dro_bytes = dro.to_pb_bytes().unwrap();
let err = deserialize_and_validate_dr_bytes(&dro_bytes, 1).unwrap_err();
let err = deserialize_and_validate_dr_bytes(&dro_bytes, 0, 1).unwrap_err();
assert_eq!(err.encode_cbor(), vec![216, 39, 129, 24, 224]);
}

Expand All @@ -115,6 +116,7 @@ fn deserialize_and_validate_dr_bytes_wip_0022() {
let dro_bytes = dro.to_pb_bytes().unwrap();
let witnet_dr_max_value_nanowits = 100_000_000_000;
let err =
deserialize_and_validate_dr_bytes(&dro_bytes, witnet_dr_max_value_nanowits).unwrap_err();
deserialize_and_validate_dr_bytes(&dro_bytes, 1_000_000_000, witnet_dr_max_value_nanowits)
.unwrap_err();
assert_eq!(err.encode_cbor(), vec![216, 39, 129, 24, 224]);
}
5 changes: 4 additions & 1 deletion bridges/centralized-ethereum/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,10 @@ fn run(callback: fn()) -> Result<(), String> {

// Initialize Storage Manager
let mut node_config = NodeConfig::default();
node_config.storage.db_path = config.storage.db_path.clone();
node_config
.storage
.db_path
.clone_from(&config.storage.db_path);
storage_mngr::start_from_config(node_config);
});

Expand Down
2 changes: 1 addition & 1 deletion data_structures/src/chain/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1642,7 +1642,7 @@ impl KeyedSignature {
compact: &[u8],
message: &[u8],
) -> Result<Self, Secp256k1ConversionError> {
let recid = RecoveryId::from_i32(compact[0] as i32)
let recid = RecoveryId::from_i32(i32::from(compact[0]))
.map_err(|e| Secp256k1ConversionError::Secp256k1 { inner: e })?;
let recoverable = RecoverableSignature::from_compact(&compact[1..], recid)
.map_err(|e| Secp256k1ConversionError::Secp256k1 { inner: e })?;
Expand Down
2 changes: 1 addition & 1 deletion data_structures/src/staking/errors.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::staking::aux::StakeKey;
use crate::staking::helpers::StakeKey;
use failure::Fail;
use std::{
convert::From,
Expand Down
6 changes: 3 additions & 3 deletions data_structures/src/staking/mod.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
#![deny(missing_docs)]

/// Auxiliary convenience types and data structures.
pub mod helpers;
/// Constants related to the staking functionality.
pub mod constants;
/// Errors related to the staking functionality.
pub mod errors;
/// Auxiliary convenience types and data structures.
pub mod helpers;
/// The data structure and related logic for stake entries.
pub mod stake;
/// The data structure and related logic for keeping track of multiple stake entries.
Expand All @@ -16,9 +16,9 @@ pub mod stakes;
pub mod prelude {
pub use crate::capabilities::*;

pub use super::helpers::*;
pub use super::constants::*;
pub use super::errors::*;
pub use super::helpers::*;
pub use super::stake::*;
pub use super::stakes::*;
}
Expand Down
1 change: 1 addition & 0 deletions data_structures/src/staking/stake.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ where
let product_added = coins * epoch;

let coins_after = coins_before + coins;
#[allow(clippy::cast_possible_truncation)]
let epoch_after = Epoch::from(
(u64::from(product_before + product_added) / u64::from(coins_after)) as u32,
);
Expand Down