Skip to content

Commit

Permalink
Merge ff0311e into f885695
Browse files Browse the repository at this point in the history
  • Loading branch information
greenhat committed Aug 4, 2020
2 parents f885695 + ff0311e commit 4784b18
Show file tree
Hide file tree
Showing 24 changed files with 947 additions and 234 deletions.
11 changes: 10 additions & 1 deletion .github/workflows/android.yml
@@ -1,5 +1,14 @@
name: Android tests
on: [push, pull_request]
on:
push:
branches:
- master
- develop
pull_request:
types:
- opened
- synchronize


jobs:
android:
Expand Down
35 changes: 35 additions & 0 deletions .github/workflows/wasm_test.yml
@@ -0,0 +1,35 @@
name: WASM tests
on:
push:
branches:
- master
- develop
pull_request:
types:
- opened
- synchronize


jobs:
wasm_tests:
name: run WASM tests
runs-on: ubuntu-latest
defaults:
run:
working-directory: bindings/ergo-wallet-lib-wasm
steps:
- name: checkout
uses: actions/checkout@v2

- name: install deps
run: |
curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh -s -- -f
- name: run tests
run: |
wasm-pack build
# wasm-pack test --firefox --headless
# wasm-pack test --firefox --headless --release
wasm-pack test --chrome --headless
wasm-pack test --chrome --headless --release
22 changes: 0 additions & 22 deletions .travis.yml
Expand Up @@ -52,28 +52,6 @@ matrix:
after_success:
- cargo tarpaulin --ciserver travis-ci --coveralls $TRAVIS_JOB_ID

- name: WASM tests
rust: stable
dist: xenial
cache: false
# sudo: true
addons:
firefox: latest
chrome: stable
# before_cache:
# - rm -rf /home/travis/.cargo/bin/wasm-pack
# before_install:
# - sudo apt-get install packagekit-gtk3-module
before_script:
- curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh -s -- -f
script:
- cd bindings/ergo-wallet-lib-wasm
- wasm-pack build
- wasm-pack test --firefox --headless
- wasm-pack test --firefox --headless --release
# - wasm-pack test --chrome --headless
# - wasm-pack test --chrome --headless --release

- name: JS tests
dist: bionic
sudo: true
Expand Down
3 changes: 1 addition & 2 deletions bindings/ergo-wallet-lib-android/src/main/rust/exception.rs
Expand Up @@ -12,8 +12,6 @@
// See the License for the specific language governing permissions and
// limitations under the License.

#![allow(dead_code)]

use failure::Error;
use jni::JNIEnv;
use std::any::Any;
Expand Down Expand Up @@ -47,6 +45,7 @@ pub fn unwrap_exc_or<T>(env: &JNIEnv, res: ExceptionResult<T>, error_val: T) ->
}

// Same as `unwrap_exc_or` but returns default value.
#[allow(dead_code)]
pub fn unwrap_exc_or_default<T: Default>(env: &JNIEnv, res: ExceptionResult<T>) -> T {
unwrap_exc_or(env, res, T::default())
}
Expand Down
1 change: 1 addition & 0 deletions sigma-tree/Cargo.toml
Expand Up @@ -18,6 +18,7 @@ serde = { version = "1.0", features = ["derive"], optional = true }
serde_json = "1.0"
thiserror = "1"
bs58 = "0.3.1"
num-bigint = "0.3.0"

[features]
default = []
Expand Down
3 changes: 1 addition & 2 deletions sigma-tree/src/ast/constant.rs
@@ -1,8 +1,7 @@
use crate::chain::{Base16DecodedBytes, Base16EncodedBytes};
use crate::{
chain::ErgoBox,
ecpoint::EcPoint,
sigma_protocol::SigmaProp,
sigma_protocol::{dlog_group::EcPoint, SigmaProp},
types::{LiftIntoSType, SType},
};
#[cfg(feature = "with-serde")]
Expand Down
45 changes: 45 additions & 0 deletions sigma-tree/src/big_integer.rs
@@ -0,0 +1,45 @@
use k256::arithmetic::Scalar;
use num_bigint::BigInt;
// use std::convert::TryFrom;

#[derive(Debug, PartialEq)]
pub struct BigInteger(BigInt);

impl From<BigInt> for BigInteger {
fn from(b: BigInt) -> Self {
BigInteger(b)
}
}

impl From<Scalar> for BigInteger {
fn from(s: Scalar) -> Self {
let bytes = s.to_bytes();
BigInt::from_signed_bytes_be(&bytes[..]).into()
}
}

// impl TryFrom<BigInteger> for Scalar {
// type Error;
// fn try_from(value: BigInteger) -> Result<Self, Self::Error> {
// todo!()
// }
// }
//

#[cfg(test)]
mod tests {
use super::*;
use crate::sigma_protocol::dlog_group;
use std::convert::TryInto;

#[test]
fn scalar_conversion_roundtrip() {
let s = dlog_group::random_scalar_in_group_range();
let b: BigInteger = s.into();
let bytes = b.0.to_signed_bytes_be();
let s2 =
Scalar::from_bytes(bytes.as_slice().try_into().expect("expected 32 bytes")).unwrap();
let b2: BigInteger = s2.into();
assert_eq!(b, b2);
}
}
7 changes: 4 additions & 3 deletions sigma-tree/src/chain.rs
Expand Up @@ -19,11 +19,12 @@ pub use address::*;
pub use base16_bytes::Base16DecodedBytes;
pub use base16_bytes::Base16EncodedBytes;
pub use box_id::*;
pub use context_extension::ContextExtension;
pub use context_extension::*;
pub use contract::*;
pub use digest32::Digest32;
pub use digest32::*;
pub use ergo_box::*;
pub use input::*;
pub use prover_result::ProverResult;
pub use prover_result::*;
pub use prover_result::*;
pub use token::*;
pub use transaction::*;
5 changes: 3 additions & 2 deletions sigma-tree/src/chain/address.rs
@@ -1,8 +1,9 @@
use super::digest32;
use crate::{
ast::Expr,
ecpoint::EcPoint,
sigma_protocol::{ProveDlog, SigmaBoolean, SigmaProofOfKnowledgeTree, SigmaProp},
sigma_protocol::{
dlog_group::EcPoint, ProveDlog, SigmaBoolean, SigmaProofOfKnowledgeTree, SigmaProp,
},
ErgoTree,
};
use sigma_ser::serializer::{SerializationError, SigmaSerializable};
Expand Down
1 change: 0 additions & 1 deletion sigma-tree/src/chain/contract.rs
Expand Up @@ -5,7 +5,6 @@ use crate::ErgoTree;
use sigma_ser::serializer::SerializationError;

/// High-level wrapper for ErgoTree
#[allow(dead_code)]
pub struct Contract {
ergo_tree: ErgoTree,
}
Expand Down
2 changes: 2 additions & 0 deletions sigma-tree/src/chain/digest32.rs
Expand Up @@ -34,6 +34,7 @@ impl Digest32 {
}
}

/// Blake2b256 hash (256 bit)
pub fn blake2b256_hash(bytes: &[u8]) -> Digest32 {
// unwrap is safe 32 bytes is a valid hash size (<= 512 && 32 % 8 == 0)
let mut hasher = VarBlake2b::new(Digest32::SIZE).unwrap();
Expand Down Expand Up @@ -82,6 +83,7 @@ impl SigmaSerializable for Digest32 {
}
}

/// Invalie byte array size
#[derive(Error, Debug)]
#[error("Invalid byte array size ({0})")]
pub struct Digest32Error(std::array::TryFromSliceError);
Expand Down
111 changes: 0 additions & 111 deletions sigma-tree/src/ecpoint.rs

This file was deleted.

34 changes: 22 additions & 12 deletions sigma-tree/src/ergo_tree.rs
Expand Up @@ -12,7 +12,6 @@ use std::rc::Rc;
use vlq_encode::{ReadSigmaVlqExt, WriteSigmaVlqExt};

#[derive(PartialEq, Eq, Debug, Clone)]
#[allow(dead_code)]
struct ParsedTree {
constants: Vec<Constant>,
root: Result<Rc<Expr>, ErgoTreeRootParsingError>,
Expand All @@ -21,7 +20,6 @@ struct ParsedTree {
/** The root of ErgoScript IR. Serialized instances of this class are self sufficient and can be passed around.
*/
#[derive(PartialEq, Eq, Debug, Clone)]
#[allow(dead_code)]
pub struct ErgoTree {
header: ErgoTreeHeader,
tree: Result<ParsedTree, ErgoTreeConstantsParsingError>,
Expand Down Expand Up @@ -75,19 +73,31 @@ impl ErgoTree {
.map_err(ErgoTreeParsingError::TreeParsingError)
.and_then(|t| t.root.map_err(ErgoTreeParsingError::RootParsingError))
}

/// Build ErgoTree using expr as is, without constants segregated
pub fn without_segregation(expr: Rc<Expr>) -> ErgoTree {
ErgoTree {
header: ErgoTree::DEFAULT_HEADER,
tree: Ok(ParsedTree {
constants: Vec::new(),
root: Ok(expr),
}),
}
}

/// Build ErgoTree with constants segregated from expr
pub fn with_segregation(_: Rc<Expr>) -> ErgoTree {
todo!()
}
}

impl From<Rc<Expr>> for ErgoTree {
fn from(expr: Rc<Expr>) -> Self {
match &*expr {
Expr::Const(c) if c.tpe == SType::SSigmaProp => ErgoTree {
header: ErgoTree::DEFAULT_HEADER,
tree: Ok(ParsedTree {
constants: Vec::new(),
root: Ok(expr),
}),
},
_ => panic!("not yet supported"),
match expr.as_ref() {
Expr::Const(Constant { tpe, .. }) if *tpe == SType::SSigmaProp => {
ErgoTree::without_segregation(expr)
}
_ => ErgoTree::with_segregation(expr),
}
}
}
Expand Down Expand Up @@ -192,7 +202,7 @@ impl SigmaSerializable for ErgoTree {
#[cfg(test)]
mod tests {
use super::*;
use crate::{ast::ConstantVal, chain, sigma_protocol::SigmaProp};
use crate::{ast::ConstantVal, chain, sigma_protocol::SigmaProp, types::SType};
use proptest::prelude::*;
use sigma_ser::test_helpers::*;

Expand Down

0 comments on commit 4784b18

Please sign in to comment.