chore: Move trust-graph to subdir (#85)

* Fix?

* Move trust-grap to subdir

* fix quickcheck update

* fix fmt

* fix service tests

* use marine 0.9.1

---------

Co-authored-by: Maria Kuklina <maria@fluence.one>
Co-authored-by: Valery Antopol <valery.antopol@gmail.com>
This commit is contained in:
Anatolios Laskaris 2023-04-13 13:55:35 +03:00 committed by GitHub
parent 81eb924476
commit e9399b7d0c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
22 changed files with 1203 additions and 620 deletions

View File

@ -18,7 +18,7 @@
}
],
"packages": {
".": {
"trust-graph": {
"component": "trust-graph"
},
"aqua": {

View File

@ -1,5 +1,5 @@
{
".": "0.4.0",
"trust-graph": "0.4.0",
"aqua": "0.4.0",
"service": "0.4.0",
"keypair": "0.10.0"

1726
Cargo.lock generated

File diff suppressed because it is too large Load Diff

View File

@ -1,26 +1,3 @@
[package]
name = "trust-graph"
version = "0.4.0"
authors = ["Fluence Labs"]
edition = "2021"
description = "trust graph"
license = "Apache-2.0"
repository = "https://github.com/fluencelabs/trust-graph"
[dependencies]
serde = { version = "1.0.118", features = ["derive"] }
fluence-keypair = { path = "./keypair", version = "0.10.0" }
bs58 = "0.4.0"
failure = "0.1.6"
log = "0.4.11"
ref-cast = "1.0.2"
derivative = "2.1.1"
thiserror = "1.0.23"
sha2 = "0.10.6"
rand = "0.8.5"
nonempty = "0.8.1"
[workspace]
members = [
"keypair",

View File

@ -234,7 +234,6 @@ pub struct Signature(pub Vec<u8>);
mod tests {
use super::*;
use quickcheck::*;
use rand::seq::SliceRandom;
use std::fmt;
const KEY1: &'static [u8] = include_bytes!("test/rsa-2048.pk8");
@ -251,8 +250,8 @@ mod tests {
}
impl Arbitrary for SomeKeypair {
fn arbitrary<G: Gen>(g: &mut G) -> SomeKeypair {
let mut key = [KEY1, KEY2, KEY3].choose(g).unwrap().to_vec();
fn arbitrary(g: &mut Gen) -> SomeKeypair {
let mut key = g.choose(&[KEY1, KEY2, KEY3]).unwrap().to_vec();
SomeKeypair(Keypair::from_pkcs8(&mut key).unwrap())
}
}

View File

@ -12,7 +12,7 @@ name = "trust-graph"
path = "src/main.rs"
[dependencies]
trust-graph = { version = "0.4.0", path = "../." }
trust-graph = { version = "0.4.0", path = "../trust-graph" }
fluence-keypair = { version = "0.10.0", path = "../keypair" }
marine-rs-sdk = { version = "0.7.1", features = ["logger"] }
marine-sqlite-connector = "0.8.0"
@ -29,8 +29,8 @@ bincode = "1.3.1"
thiserror = "1.0.23"
[dev-dependencies]
marine-rs-sdk-test = "0.8.1"
marine-rs-sdk-test = "0.9.1"
rusqlite = "0.28.0"
[build-dependencies]
marine-rs-sdk-test = "0.8.1"
marine-rs-sdk-test = "0.9.1"

View File

@ -5,12 +5,10 @@ modules_dir = "artifacts/"
logger_enabled = true
[module.wasi]
preopened_files = ["/tmp"]
mapped_dirs = { "tmp" = "/tmp" }
mapped_dirs = { "/tmp" = "data" }
[[module]]
name = "trust-graph"
logger_enabled = true
[module.wasi]
preopened_files = ["/tmp"]
mapped_dirs = { "tmp" = "/tmp" }
mapped_dirs = { "/tmp" = "data" }

View File

@ -13,7 +13,7 @@ mkdir -p artifacts
cp ../target/wasm32-wasi/release/trust-graph.wasm artifacts/
# download SQLite 3 to use in tests
curl -sS -L https://github.com/fluencelabs/sqlite/releases/download/v0.15.0_w/sqlite3.wasm -o artifacts/sqlite3.wasm
curl -sS -L https://github.com/fluencelabs/sqlite/releases/download/v0.18.0_w/sqlite3.wasm -o artifacts/sqlite3.wasm
# generate Aqua bindings
marine aqua artifacts/trust-graph.wasm -s TrustGraph -i trust-graph > ../aqua/trust-graph.aqua

View File

@ -18,18 +18,18 @@
mod service_tests {
marine_rs_sdk_test::include_test_env!("/marine_test_env.rs");
use crate::error::ServiceError;
use crate::storage_impl::DB_PATH;
use crate::TRUSTED_TIMESTAMP;
use fluence_keypair::KeyPair;
use libp2p_identity::PeerId;
use marine_rs_sdk::{CallParameters, SecurityTetraplet};
use marine_test_env::trust_graph::{Certificate, Revocation, ServiceInterface, Trust};
use rusqlite::Connection;
use std::collections::HashMap;
use std::time::{SystemTime, UNIX_EPOCH};
static HOST_ID: &str = "some_host_id";
static TEST_DB_PATH: &str = "data/trust-graph.sqlite";
struct Auth {
issuer: PeerId,
trust: Trust,
@ -55,12 +55,7 @@ mod service_tests {
}
fn clear_env() {
let connection = Connection::open(DB_PATH).unwrap();
connection
.execute("DELETE FROM trust_relations", [])
.unwrap();
connection.execute("DELETE FROM roots", []).unwrap();
std::fs::remove_file(TEST_DB_PATH).unwrap_or_default();
}
fn get_correct_timestamp_cp(arg_number: usize) -> CallParameters {
@ -445,32 +440,32 @@ mod service_tests {
let mut trust_graph = marine_test_env::trust_graph::ServiceInterface::new();
clear_env();
let peerA_kp = KeyPair::generate_ed25519();
let peer_a_kp = KeyPair::generate_ed25519();
let mut cur_time = 100u64;
add_root_with_trust(&mut trust_graph, &peerA_kp, cur_time, cur_time + 9999, 10);
add_root_with_trust(&mut trust_graph, &peer_a_kp, cur_time, cur_time + 9999, 10);
let peerB_kp = KeyPair::generate_ed25519();
let peer_b_kp = KeyPair::generate_ed25519();
add_trust(
&mut trust_graph,
&peerA_kp,
&peerB_kp.get_peer_id(),
&peer_a_kp,
&peer_b_kp.get_peer_id(),
cur_time,
cur_time + 99999,
);
let weight = get_weight(&mut trust_graph, peerB_kp.get_peer_id(), cur_time);
let weight = get_weight(&mut trust_graph, peer_b_kp.get_peer_id(), cur_time);
assert_ne!(weight, 0u32);
cur_time += 1;
// A revokes B and cancels trust
revoke(
&mut trust_graph,
&peerA_kp,
&peerB_kp.get_peer_id(),
&peer_a_kp,
&peer_b_kp.get_peer_id(),
cur_time,
);
let weight = get_weight(&mut trust_graph, peerB_kp.get_peer_id(), cur_time);
let weight = get_weight(&mut trust_graph, peer_b_kp.get_peer_id(), cur_time);
assert_eq!(weight, 0u32);
}

22
trust-graph/Cargo.toml Normal file
View File

@ -0,0 +1,22 @@
[package]
name = "trust-graph"
version = "0.4.0"
authors = ["Fluence Labs"]
edition = "2021"
description = "trust graph"
license = "Apache-2.0"
repository = "https://github.com/fluencelabs/trust-graph"
[dependencies]
serde = { version = "1.0.118", features = ["derive"] }
fluence-keypair = { path = "../keypair", version = "0.10.0" }
bs58 = "0.4.0"
failure = "0.1.6"
log = "0.4.11"
ref-cast = "1.0.2"
derivative = "2.1.1"
thiserror = "1.0.23"
sha2 = "0.10.6"
rand = "0.8.5"
nonempty = "0.8.1"