Skip to content

Commit

Permalink
Merge pull request cosmos#43 from confio/42-cleanup-start
Browse files Browse the repository at this point in the history
Fix linting issues
  • Loading branch information
ethanfrey committed Jul 12, 2021
2 parents e0046b8 + e8881b7 commit 51fb73d
Show file tree
Hide file tree
Showing 7 changed files with 58 additions and 27 deletions.
40 changes: 39 additions & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ workflows:
- typescript
- golang
- rust
- lint-rust

jobs:
typescript:
docker:
Expand Down Expand Up @@ -87,4 +89,40 @@ jobs:
key: v4-cargo-cache-{{ arch }}-{{ checksum "Cargo.lock" }}
- run:
name: Run all tests
command: cargo test --all
command: cargo test --all

lint-rust:
docker:
- image: rust:1.42
working_directory: ~/proofs/rust
steps:
- checkout:
path: ~/proofs
- run:
name: Version information
command: rustc --version; cargo --version; rustup --version; rustup target list --installed
- restore_cache:
keys:
- cargocache-v2-lint-rust:1.42.0-{{ checksum "Cargo.lock" }}
- run:
name: Add rustfmt component
command: rustup component add rustfmt
- run:
name: Add clippy component
command: rustup component add clippy
- run:
name: Check formatting of workspace
command: cargo fmt -- --check
- run:
name: Clippy linting on workspace
command: cargo clippy --tests -- -D warnings
- run:
name: Clippy linting on workspace (no-std)
command: cargo clippy --tests --no-default-features -- -D warnings
- save_cache:
paths:
- /usr/local/cargo/registry
- target/debug/.fingerprint
- target/debug/build
- target/debug/deps
key: cargocache-v2-lint-rust:1.42.0-{{ checksum "Cargo.lock" }}
2 changes: 0 additions & 2 deletions rust/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 8 additions & 7 deletions rust/src/api.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::collections::btree_map::BTreeMap as HashMap;
use std::collections::btree_map::BTreeMap;

#[cfg(not(feature = "std"))]
use std::prelude::*;
Expand Down Expand Up @@ -70,7 +70,7 @@ pub fn verify_batch_membership(
proof: &ics23::CommitmentProof,
spec: &ics23::ProofSpec,
root: &CommitmentRoot,
items: HashMap<&[u8], &[u8]>,
items: BTreeMap<&[u8], &[u8]>,
) -> bool {
// ugly attempt to conditionally decompress...
let mut proof = proof;
Expand Down Expand Up @@ -204,20 +204,21 @@ pub fn tendermint_spec() -> ics23::ProofSpec {
}
}

#[cfg(feature = "std")]
#[cfg(test)]
mod tests {
extern crate std as _std;
use super::*;

use anyhow::{bail, ensure};
use prost::Message;
use serde::Deserialize;
#[cfg(feature = "std")]
use _std::fs::File;
#[cfg(feature = "std")]
use _std::io::prelude::*;
use std::vec::Vec;
use alloc::string::String;
use anyhow::{bail, ensure};
use prost::Message;
use serde::Deserialize;
use std::vec::Vec;

use crate::compress::compress;
use crate::helpers::Result;
Expand Down Expand Up @@ -398,7 +399,7 @@ mod tests {
if let Some(value) = &data.value {
let valid = super::verify_membership(&proof, spec, &data.root, &data.key, &value);
ensure!(valid, "invalid test vector");
let mut items = HashMap::new();
let mut items = BTreeMap::new();
items.insert(data.key.as_slice(), value.as_slice());
let valid = super::verify_batch_membership(&proof, spec, &data.root, items);
ensure!(valid, "invalid test vector");
Expand Down
7 changes: 3 additions & 4 deletions rust/src/compress.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use prost::Message;
use std::borrow::ToOwned;
use std::collections::btree_map::BTreeMap as HashMap;
use std::vec::Vec;
use std::borrow::ToOwned;

use crate::helpers::Result;
use crate::ics23;
Expand Down Expand Up @@ -87,9 +87,8 @@ pub fn compress_exist(
.iter()
.map(|x| {
let mut buf = Vec::new();
x.encode(&mut buf).map_err(|e : prost::EncodeError | {
anyhow::anyhow!(e)
})?;
x.encode(&mut buf)
.map_err(|e: prost::EncodeError| anyhow::anyhow!(e))?;

if let Some(&idx) = registry.get(buf.as_slice()) {
return Ok(idx);
Expand Down
4 changes: 2 additions & 2 deletions rust/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#![cfg_attr(not(feature = "std"), no_std)]
#![allow(dead_code)]
#![allow(unused_imports)]
#![allow(clippy::large_enum_variant)]

extern crate alloc;
extern crate core;
#[cfg(not(feature = "std"))]
extern crate sp_std as std;

mod api;
Expand Down
6 changes: 3 additions & 3 deletions rust/src/ops.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
use alloc::format;
use anyhow::{bail, ensure};
use ripemd160::Ripemd160;
use sha2::{Digest, Sha256, Sha512, Sha512Trunc256};
use sha3::Sha3_512;
use std::convert::TryInto;
use alloc::format;


use crate::helpers::{Hash, Result};
use crate::ics23::{HashOp, InnerOp, LeafOp, LengthOp};
Expand Down Expand Up @@ -78,8 +77,9 @@ fn proto_len(length: usize) -> Result<Hash> {
#[cfg(test)]
mod tests {
use super::*;
use std::vec::Vec;
#[cfg(not(feature = "std"))]
use std::prelude::*;
use std::vec::Vec;

fn decode(input: &str) -> Vec<u8> {
hex::decode(input).unwrap()
Expand Down
11 changes: 3 additions & 8 deletions rust/src/verify.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ use anyhow::{bail, ensure};
use crate::helpers::Result;
use crate::ics23;
use crate::ops::{apply_inner, apply_leaf};
use std::vec::Vec;
use alloc::format;
use std::vec::Vec;

pub type CommitmentRoot = ::std::vec::Vec<u8>;

Expand Down Expand Up @@ -264,9 +264,9 @@ mod tests {
use crate::api;
use crate::ics23::{ExistenceProof, HashOp, InnerOp, LeafOp, LengthOp, ProofSpec};
use std::collections::btree_map::BTreeMap as HashMap;
#[cfg(not(feature = "std"))]
use std::prelude::*;


#[test]
fn calculate_root_from_leaf() {
let leaf = ics23::LeafOp {
Expand Down Expand Up @@ -520,12 +520,7 @@ mod tests {
for (name, tc) in cases {
let check = check_existence_spec(&tc.proof, &tc.spec);
if tc.valid {
assert!(
check.is_ok(),
"{} should be ok, got err {}",
name,
check.unwrap_err()
);
check.expect(name);
} else {
assert!(check.is_err(), "{} should be an error", name);
}
Expand Down

0 comments on commit 51fb73d

Please sign in to comment.