mirror of
https://github.com/fluencelabs/trust-graph-test
synced 2025-04-25 21:32:26 +00:00
wip: build service
This commit is contained in:
parent
190fcc16e7
commit
d99683233d
1227
Cargo.lock
generated
1227
Cargo.lock
generated
File diff suppressed because it is too large
Load Diff
0
identity/src/peer_id.rs
Normal file
0
identity/src/peer_id.rs
Normal file
3
service/.repl_history
Normal file
3
service/.repl_history
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
#V2
|
||||||
|
in
|
||||||
|
interface
|
@ -27,3 +27,6 @@ rmp-serde = "0.15.0"
|
|||||||
bincode = "1.3.1"
|
bincode = "1.3.1"
|
||||||
serde_bencode = "^0.2.3"
|
serde_bencode = "^0.2.3"
|
||||||
thiserror = "1.0.23"
|
thiserror = "1.0.23"
|
||||||
|
|
||||||
|
[dev-dependencies]
|
||||||
|
marine-rs-sdk-test = "0.1.11"
|
BIN
service/artifacts/sqlite3.wasm
Normal file
BIN
service/artifacts/sqlite3.wasm
Normal file
Binary file not shown.
BIN
service/artifacts/trust-graph.wasm
Executable file
BIN
service/artifacts/trust-graph.wasm
Executable file
Binary file not shown.
@ -12,3 +12,9 @@ marine build --release
|
|||||||
rm -f artifacts/*
|
rm -f artifacts/*
|
||||||
mkdir -p artifacts
|
mkdir -p artifacts
|
||||||
cp ../target/wasm32-wasi/release/trust-graph.wasm artifacts/
|
cp ../target/wasm32-wasi/release/trust-graph.wasm artifacts/
|
||||||
|
|
||||||
|
# download SQLite 3 to use in tests
|
||||||
|
curl -L https://github.com/fluencelabs/sqlite/releases/download/v0.14.0_w/sqlite3.wasm -o artifacts/sqlite3.wasm
|
||||||
|
|
||||||
|
# generate Aqua bindings
|
||||||
|
marine aqua artifacts/trust-graph.wasm -s TrustGraph -i trust-graph > trust-graph.aqua
|
||||||
|
@ -2,4 +2,4 @@
|
|||||||
set -euo pipefail
|
set -euo pipefail
|
||||||
|
|
||||||
./build.sh
|
./build.sh
|
||||||
RUST_LOG="info" fce-repl Config.toml
|
RUST_LOG="info" mrepl Config.toml
|
||||||
|
1
service/rust-toolchain
Normal file
1
service/rust-toolchain
Normal file
@ -0,0 +1 @@
|
|||||||
|
nightly
|
@ -5,6 +5,7 @@ mod results;
|
|||||||
mod service_api;
|
mod service_api;
|
||||||
mod service_impl;
|
mod service_impl;
|
||||||
mod storage_impl;
|
mod storage_impl;
|
||||||
|
mod tests;
|
||||||
|
|
||||||
pub fn main() {
|
pub fn main() {
|
||||||
WasmLoggerBuilder::new()
|
WasmLoggerBuilder::new()
|
||||||
@ -12,11 +13,3 @@ pub fn main() {
|
|||||||
.build()
|
.build()
|
||||||
.unwrap();
|
.unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
// only option for now is to copy tests from trust graph,
|
|
||||||
// change connector to sqlite and fix compilation -_-
|
|
||||||
// TODO: fix it
|
|
||||||
/*#[cfg(test)]
|
|
||||||
mod tests {
|
|
||||||
|
|
||||||
}*/
|
|
||||||
|
@ -44,32 +44,3 @@ fn add_root(pk: String, weight: u32) -> AddRootResult {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO rewrite test after #[marine_test] will be implemented
|
|
||||||
// #[marine_test]
|
|
||||||
// fn test() -> String {
|
|
||||||
// let mut tg = get_data().lock();
|
|
||||||
//
|
|
||||||
// let root_kp = KeyPair::generate();
|
|
||||||
// let root_kp2 = KeyPair::generate();
|
|
||||||
// let second_kp = KeyPair::generate();
|
|
||||||
//
|
|
||||||
// let expires_at = Duration::new(15, 15);
|
|
||||||
// let issued_at = Duration::new(5, 5);
|
|
||||||
//
|
|
||||||
// let cert = trust_graph::Certificate::issue_root(
|
|
||||||
// &root_kp,
|
|
||||||
// second_kp.public_key(),
|
|
||||||
// expires_at,
|
|
||||||
// issued_at,
|
|
||||||
// );
|
|
||||||
// tg.add_root_weight(root_kp.public().into(), 0).unwrap();
|
|
||||||
// tg.add_root_weight(root_kp2.public().into(), 1).unwrap();
|
|
||||||
// tg.add(cert, Duration::new(10, 10)).unwrap();
|
|
||||||
//
|
|
||||||
// let a = tg.get(second_kp.public_key()).unwrap();
|
|
||||||
// let str = format!("{:?}", a);
|
|
||||||
// log::info!("{}", &str);
|
|
||||||
//
|
|
||||||
// str
|
|
||||||
// }
|
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
// if there is an older trust - don't add received trust
|
// if there is an older trust - don't add received trust
|
||||||
|
|
||||||
use crate::storage_impl::SQLiteStorageError::{
|
use crate::storage_impl::SQLiteStorageError::{
|
||||||
PublcKeyNotFound, PublicKeyConversion, PublicKeyFromStr, TrustNodeConversion,
|
PublicKeyNotFound, PublicKeyConversion, PublicKeyFromStr, TrustNodeConversion,
|
||||||
WeightConversionDB,
|
WeightConversionDB,
|
||||||
};
|
};
|
||||||
use core::convert::TryFrom;
|
use core::convert::TryFrom;
|
||||||
@ -85,7 +85,7 @@ pub enum SQLiteStorageError {
|
|||||||
#[error("Cannot convert trust node as binary from DB")]
|
#[error("Cannot convert trust node as binary from DB")]
|
||||||
TrustNodeConversion,
|
TrustNodeConversion,
|
||||||
#[error("Cannot revoke. There is no trust with such PublicKey")]
|
#[error("Cannot revoke. There is no trust with such PublicKey")]
|
||||||
PublcKeyNotFound,
|
PublicKeyNotFound,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<SQLiteStorageError> for String {
|
impl From<SQLiteStorageError> for String {
|
||||||
@ -203,7 +203,7 @@ impl Storage for SQLiteStorage {
|
|||||||
self.insert(pk.clone(), trust_node)?;
|
self.insert(pk.clone(), trust_node)?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
None => Err(PublcKeyNotFound),
|
None => Err(PublicKeyNotFound),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
47
service/src/tests.rs
Normal file
47
service/src/tests.rs
Normal file
@ -0,0 +1,47 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2021 Fluence Labs Limited
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
use marine_rs_sdk_test::marine_test;
|
||||||
|
use fluence_identity;
|
||||||
|
use std::time::Duration;
|
||||||
|
|
||||||
|
#[marine_test(config_path = "../Config.toml", modules_dir = "../artifacts/")]
|
||||||
|
fn test() {
|
||||||
|
|
||||||
|
let root_kp = Keypai
|
||||||
|
let root_kp2 = KeyPair::generate();
|
||||||
|
let second_kp = KeyPair::generate();
|
||||||
|
|
||||||
|
let expires_at = Duration::new(15, 15);
|
||||||
|
let issued_at = Duration::new(5, 5);
|
||||||
|
|
||||||
|
let cert = trust_graph::Certificate::issue_root(
|
||||||
|
&root_kp,
|
||||||
|
second_kp.public_key(),
|
||||||
|
expires_at,
|
||||||
|
issued_at,
|
||||||
|
);
|
||||||
|
trast_graph.add_root(root_kp.public().into(), 0).unwrap();
|
||||||
|
tg.add_root_weight(root_kp2.public().into(), 1).unwrap();
|
||||||
|
tg.add(cert, Duration::new(10, 10)).unwrap();
|
||||||
|
|
||||||
|
let a = tg.get(second_kp.public_key()).unwrap();
|
||||||
|
let str = format!("{:?}", a);
|
||||||
|
log::info!("{}", &str);
|
||||||
|
}
|
||||||
|
}
|
33
service/trust-graph.aqua
Normal file
33
service/trust-graph.aqua
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
data AddRootResult:
|
||||||
|
ret_code: u32
|
||||||
|
error: string
|
||||||
|
|
||||||
|
data Trust:
|
||||||
|
issued_for: string
|
||||||
|
expires_at: u64
|
||||||
|
signature: string
|
||||||
|
issued_at: u64
|
||||||
|
|
||||||
|
data Certificate:
|
||||||
|
chain: []Trust
|
||||||
|
|
||||||
|
data AllCertsResult:
|
||||||
|
ret_code: u32
|
||||||
|
certificates: []Certificate
|
||||||
|
error: string
|
||||||
|
|
||||||
|
data InsertResult:
|
||||||
|
ret_code: u32
|
||||||
|
error: string
|
||||||
|
|
||||||
|
data WeightResult:
|
||||||
|
ret_code: u32
|
||||||
|
weight: []u32
|
||||||
|
error: string
|
||||||
|
|
||||||
|
service TrustGraph("trust-graph"):
|
||||||
|
add_root(pk: string, weight: u32) -> AddRootResult
|
||||||
|
get_all_certs(issued_for: string) -> AllCertsResult
|
||||||
|
get_weight(public_key: string) -> WeightResult
|
||||||
|
insert_cert(certificate: Certificate, current_time: u64) -> InsertResult
|
||||||
|
insert_cert_raw(certificate: string, current_time: u64) -> InsertResult
|
Loading…
x
Reference in New Issue
Block a user