Skip to content

Commit

Permalink
Refresh integration test with local ledger impl
Browse files Browse the repository at this point in the history
  • Loading branch information
howardwu committed May 31, 2021
1 parent 6047bb0 commit f4606ea
Show file tree
Hide file tree
Showing 9 changed files with 1,725 additions and 499 deletions.
52 changes: 18 additions & 34 deletions .snarkos-integration/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
[package]
name = "snarkvm-snarkos-integration"
version = "0.3.1"
name = "snarkvm-integration"
version = "0.4.0"
authors = [ "The Aleo Team <hello@aleo.org>" ]
description = "A test suite for functionalities requiring snarkOS integration"
description = "Integration testing for DPC"
homepage = "https://aleo.org"
repository = "https://github.com/AleoHQ/snarkVM"
keywords = [
Expand All @@ -18,43 +18,32 @@ license = "GPL-3.0"
edition = "2018"

[dependencies.snarkvm-algorithms]
version = "0.3.1"
default-features = false
path = "../algorithms"

[dependencies.snarkvm-curves]
version = "0.3.1"
default-features = false
path = "../curves"

[dependencies.snarkvm-dpc]
version = "0.3.1"
default-features = false
path = "../dpc"

[dependencies.snarkvm-fields]
version = "0.3.1"
default-features = false
path = "../fields"

[dependencies.snarkvm-gadgets]
version = "0.3.1"
default-features = false

[dependencies.snarkvm-objects]
version = "0.3.1"
default-features = false
path = "../gadgets"

[dependencies.snarkvm-parameters]
version = "0.3.1"
default-features = false
path = "../parameters"

[dependencies.snarkvm-profiler]
version = "0.3.1"
path = "../profiler"
default-features = false

[dependencies.snarkvm-r1cs]
version = "0.3.1"
default-features = false
path = "../r1cs"

[dependencies.snarkvm-utilities]
version = "0.3.1"
path = "../utilities"
default-features = false

[dependencies.anyhow]
Expand All @@ -66,6 +55,9 @@ version = "0.1"
[dependencies.bech32]
version = "0.8"

[dependencies.bincode]
version = "1.3.1"

[dependencies.blake2]
version = "0.9"

Expand All @@ -78,20 +70,12 @@ version = "0.4.3"
[dependencies.itertools]
version = "0.10.0"

[dependencies.parking_lot]
version = "0.11.1"

[dependencies.rand]
version = "0.8"

[dependencies.snarkos-storage]
git = "https://github.com/AleoHQ/snarkOS"
rev = "e72d3d9d03d1a053ae148608e3f5b3ae857a4edf" # version 1.3.6 of the package
default-features = false
features = ["mem_storage"]

[dependencies.snarkos-testing]
git = "https://github.com/AleoHQ/snarkOS"
rev = "e72d3d9d03d1a053ae148608e3f5b3ae857a4edf" # version 1.3.6 of the package
default-features = false

[dependencies.thiserror]
version = "1.0"

Expand Down
596 changes: 596 additions & 0 deletions .snarkos-integration/LICENSE.md

Large diffs are not rendered by default.

78 changes: 78 additions & 0 deletions .snarkos-integration/src/dpc.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
// Copyright (C) 2019-2021 Aleo Systems Inc.
// This file is part of the snarkVM library.

// The snarkVM library is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.

// The snarkVM library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.

// You should have received a copy of the GNU General Public License
// along with the snarkVM library. If not, see <https://www.gnu.org/licenses/>.

use crate::Ledger;
use snarkvm_algorithms::{MerkleParameters, CRH};
use snarkvm_dpc::{
testnet1::{instantiated::*, parameters::PublicParameters},
Account,
AccountScheme,
DPCScheme,
Storage,
};
use snarkvm_parameters::{LedgerMerkleTreeParameters, Parameter};
use snarkvm_utilities::bytes::FromBytes;

use rand::Rng;
use std::sync::Arc;

pub type MerkleTreeLedger<S> = Ledger<Tx, CommitmentMerkleParameters, S>;

pub fn setup_or_load_parameters<R: Rng, S: Storage>(
verify_only: bool,
rng: &mut R,
) -> (
Arc<CommitmentMerkleParameters>,
<InstantiatedDPC as DPCScheme<MerkleTreeLedger<S>>>::NetworkParameters,
) {
// TODO (howardwu): Resolve this inconsistency on import structure with a new model once MerkleParameters are refactored.
let crh_parameters =
<MerkleTreeCRH as CRH>::Parameters::read(&LedgerMerkleTreeParameters::load_bytes().unwrap()[..])
.expect("read bytes as hash for MerkleParameters in ledger");
let merkle_tree_hash_parameters = <CommitmentMerkleParameters as MerkleParameters>::H::from(crh_parameters);
let ledger_merkle_tree_parameters = Arc::new(From::from(merkle_tree_hash_parameters));

let parameters = match <InstantiatedDPC as DPCScheme<MerkleTreeLedger<S>>>::NetworkParameters::load(verify_only) {
Ok(parameters) => parameters,
Err(err) => {
println!("error - {}, re-running parameter Setup", err);
<InstantiatedDPC as DPCScheme<MerkleTreeLedger<S>>>::setup(&ledger_merkle_tree_parameters, rng)
.expect("DPC setup failed")
}
};

(ledger_merkle_tree_parameters, parameters)
}

pub fn load_verifying_parameters() -> PublicParameters<Components> {
PublicParameters::<Components>::load_vk_direct().unwrap()
}

pub fn generate_test_accounts<R: Rng, S: Storage>(
parameters: &PublicParameters<Components>,
rng: &mut R,
) -> [Account<Components>; 3] {
let signature_parameters = &parameters.system_parameters.account_signature;
let commitment_parameters = &parameters.system_parameters.account_commitment;
let encryption_parameters = &parameters.system_parameters.account_encryption;

let genesis_account =
Account::new(signature_parameters, commitment_parameters, encryption_parameters, rng).unwrap();
let account_1 = Account::new(signature_parameters, commitment_parameters, encryption_parameters, rng).unwrap();
let account_2 = Account::new(signature_parameters, commitment_parameters, encryption_parameters, rng).unwrap();

[genesis_account, account_1, account_2]
}
Loading

0 comments on commit f4606ea

Please sign in to comment.