From 328125aa1ea9171dcaaca1e864ac34619ca070a3 Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Tue, 7 Dec 2021 10:29:59 +0100 Subject: Add CI setup for github Signed-off-by: Matthias Beyer --- .github/workflows/ci.yml | 61 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 .github/workflows/ci.yml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..efece1a --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,61 @@ +on: [push, pull_request] + +name: CI + +jobs: + check: + name: Check + runs-on: ubuntu-latest + strategy: + matrix: + rust: + - 1.57.0 + - stable + - beta + + steps: + - name: Install dependencies + run: sudo apt-get install -y openssl pkg-config zlib1g protobuf-compiler + + - name: Checkout sources + uses: actions/checkout@v2 + + - name: Install toolchain + uses: actions-rs/toolchain@v1 + with: + toolchain: ${{ matrix.rust }} + override: true + + - name: Run cargo check + uses: actions-rs/cargo@v1 + with: + command: check + + test: + needs: [check] + name: Test Suite + runs-on: ubuntu-latest + strategy: + matrix: + rust: + - 1.54.0 + - stable + - beta + steps: + - name: Install dependencies + run: sudo apt-get install -y openssl pkg-config zlib1g protobuf-compiler + + - name: Checkout sources + uses: actions/checkout@v2 + + - name: Install toolchain + uses: actions-rs/toolchain@v1 + with: + toolchain: ${{ matrix.rust }} + override: true + + - name: Run cargo test + uses: actions-rs/cargo@v1 + with: + command: test + args: --all --all-features -- cgit v1.2.3 From 2b6e6789b4a0eb63709551be0b1de481a2d9b1bb Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Tue, 7 Dec 2021 14:44:06 +0100 Subject: Fix expected CID Signed-off-by: Matthias Beyer --- src/profile/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/profile/mod.rs b/src/profile/mod.rs index 8849e34..6ec14c3 100644 --- a/src/profile/mod.rs +++ b/src/profile/mod.rs @@ -182,7 +182,7 @@ mod tests { assert!(profile.is_ok()); let profile = profile.unwrap(); let head = profile.head(); - let exp_cid = cid::Cid::try_from("bafyreie4haukbqj7u6vogjfvaxbwg73b7bzi7nqxbnkvv77dvwcqg5wtpe").unwrap(); + let exp_cid = cid::Cid::try_from("bafyreig2koltmta6tvag37dwnzfjf5ft2qxrafymqt56a7r4e5dfkhy3zu").unwrap(); assert_eq!(*head, exp_cid, "{} != {}", *head, exp_cid); let exit = profile.exit().await; assert!(exit.is_ok(), "Not cleanly exited: {:?}", exit); -- cgit v1.2.3 From f2d612b64bd3b89cb6c7bd59b36192891ae49ab6 Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Tue, 7 Dec 2021 14:44:43 +0100 Subject: Fix: Do not use deprecated Arg::with_name() Signed-off-by: Matthias Beyer --- src/cli.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/cli.rs b/src/cli.rs index 3041e33..8e912e0 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -20,7 +20,7 @@ pub fn app<'a>() -> App<'a> { .version(crate_version!()) .about("Create profile") - .arg(Arg::with_name("name") + .arg(Arg::new("name") .long("name") .required(true) .takes_value(true) @@ -34,7 +34,7 @@ pub fn app<'a>() -> App<'a> { .version(crate_version!()) .about("Just serve the profile") - .arg(Arg::with_name("name") + .arg(Arg::new("name") .long("name") .required(true) .takes_value(true) @@ -42,7 +42,7 @@ pub fn app<'a>() -> App<'a> { .about("Name of the profile") ) - .arg(Arg::with_name("connect") + .arg(Arg::new("connect") .long("connect") .required(false) .takes_value(true) -- cgit v1.2.3 From 2fa44701955cd42b450168776b135dbd24ef009e Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Tue, 7 Dec 2021 14:45:00 +0100 Subject: Fix: Remove unused imports Signed-off-by: Matthias Beyer --- src/client.rs | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/client.rs b/src/client.rs index 4e50a8e..bb280a5 100644 --- a/src/client.rs +++ b/src/client.rs @@ -1,8 +1,6 @@ use std::convert::TryFrom; -use anyhow::Context; use anyhow::Result; -use futures::TryStreamExt; use ipfs::Cid; use crate::config::Config; -- cgit v1.2.3 From d8f230de7ea01237112ea280d99756d6142d272b Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Tue, 7 Dec 2021 14:47:06 +0100 Subject: Fix: Remove unused argument Signed-off-by: Matthias Beyer --- src/profile/mod.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/profile/mod.rs b/src/profile/mod.rs index 6ec14c3..3438793 100644 --- a/src/profile/mod.rs +++ b/src/profile/mod.rs @@ -24,7 +24,7 @@ impl Profile { let keypair = ipfs::Keypair::generate_ed25519(); let options = ipfs::IpfsOptions { - ipfs_path: Self::ipfs_path(state_dir, name).await?, + ipfs_path: Self::ipfs_path(state_dir).await?, keypair, bootstrap, mdns, @@ -70,7 +70,7 @@ impl Profile { client.post_text_node(vec![], text).await } - async fn ipfs_path(state_dir: &StateDir, name: &str) -> Result { + async fn ipfs_path(state_dir: &StateDir) -> Result { let path = state_dir.ipfs(); tokio::fs::create_dir_all(&path).await?; Ok(path) @@ -129,7 +129,7 @@ impl Profile { log::debug!("Configuring IPFS backend"); let options = ipfs::IpfsOptions { - ipfs_path: Self::ipfs_path(&state_dir_path, name).await?, + ipfs_path: Self::ipfs_path(&state_dir_path).await?, keypair, bootstrap, mdns, -- cgit v1.2.3 From 321e5774cea1f2eb79640f97a9423a96a871a658 Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Tue, 7 Dec 2021 14:47:31 +0100 Subject: Fix: Make function only in tests available Signed-off-by: Matthias Beyer --- src/profile/mod.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/profile/mod.rs b/src/profile/mod.rs index 3438793..a15158e 100644 --- a/src/profile/mod.rs +++ b/src/profile/mod.rs @@ -41,6 +41,7 @@ impl Profile { Self::new(ipfs, config, name.to_string(), keypair).await } + #[cfg(test)] async fn new_inmemory(config: Config, name: &str) -> Result { let mut opts = ipfs::IpfsOptions::inmemory_with_generated_keys(); opts.mdns = true; -- cgit v1.2.3 From d75bd75636fe5d5a96dc9f807480585fe6e2e277 Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Tue, 7 Dec 2021 14:47:55 +0100 Subject: Fix: Remove unused imports Signed-off-by: Matthias Beyer --- src/profile/mod.rs | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/profile/mod.rs b/src/profile/mod.rs index a15158e..4a37bca 100644 --- a/src/profile/mod.rs +++ b/src/profile/mod.rs @@ -163,9 +163,7 @@ impl Profile { mod tests { use super::*; use std::convert::TryFrom; - use crate::client::Client; use crate::config::Config; - use crate::ipfs_client::IpfsClient; #[tokio::test] async fn test_create_profile() { -- cgit v1.2.3 From c316c5895885fb0ce0a6627f00ded6bcc81cca7c Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Tue, 7 Dec 2021 18:21:08 +0100 Subject: Remove posting of "Hello world" message for new profile This is actually not desireable and also caused tests to fail because the hash changed on each test because of the timestamp that is inserted on every block. Signed-off-by: Matthias Beyer --- src/commands/profile.rs | 2 +- src/profile/mod.rs | 18 ++++-------------- src/profile/state.rs | 12 ++++++------ 3 files changed, 11 insertions(+), 21 deletions(-) diff --git a/src/commands/profile.rs b/src/commands/profile.rs index 4da70f1..853984f 100644 --- a/src/commands/profile.rs +++ b/src/commands/profile.rs @@ -44,7 +44,7 @@ async fn profile_serve(matches: &ArgMatches) -> Result<()> { log::info!("Loading '{}' from {}", name, state_dir.display()); let profile = Profile::load(Config::default(), &name).await?; log::info!("Profile loaded"); - log::info!("Profile HEAD = {}", profile.head()); + log::info!("Profile HEAD = {:?}", profile.head()); if let Some(connect_to) = connect_peer { log::info!("Connecting to {:?}", connect_to); diff --git a/src/profile/mod.rs b/src/profile/mod.rs index 4a37bca..56b4ac9 100644 --- a/src/profile/mod.rs +++ b/src/profile/mod.rs @@ -53,24 +53,18 @@ impl Profile { async fn new(ipfs: IpfsClient, config: Config, profile_name: String, keypair: libp2p::identity::Keypair) -> Result { let client = Client::new(ipfs, config); - let profile_head = Self::post_hello_world(&client, &profile_name).await?; - let state = ProfileState::new(profile_head, profile_name, keypair); + let state = ProfileState::new(profile_name, keypair); Ok(Profile { state, client }) } - pub fn head(&self) -> &cid::Cid { - self.state.profile_head() + pub fn head(&self) -> Option<&cid::Cid> { + self.state.profile_head().as_ref() } pub async fn connect(&self, peer: ipfs::MultiaddrWithPeerId) -> Result<()> { self.client.connect(peer).await } - async fn post_hello_world(client: &Client, name: &str) -> Result { - let text = format!("Hello world, I am {}", name); - client.post_text_node(vec![], text).await - } - async fn ipfs_path(state_dir: &StateDir) -> Result { let path = state_dir.ipfs(); tokio::fs::create_dir_all(&path).await?; @@ -180,11 +174,7 @@ mod tests { let profile = Profile::new_inmemory(Config::default(), "test-create-profile-and-helloworld").await; assert!(profile.is_ok()); let profile = profile.unwrap(); - let head = profile.head(); - let exp_cid = cid::Cid::try_from("bafyreig2koltmta6tvag37dwnzfjf5ft2qxrafymqt56a7r4e5dfkhy3zu").unwrap(); - assert_eq!(*head, exp_cid, "{} != {}", *head, exp_cid); - let exit = profile.exit().await; - assert!(exit.is_ok(), "Not cleanly exited: {:?}", exit); + assert!(profile.head().is_none()); } } diff --git a/src/profile/state.rs b/src/profile/state.rs index a84ff23..4075b52 100644 --- a/src/profile/state.rs +++ b/src/profile/state.rs @@ -32,7 +32,7 @@ impl From for StateDir { #[derive(getset::Getters)] pub struct ProfileState { #[getset(get = "pub")] - profile_head: cid::Cid, + profile_head: Option, #[getset(get = "pub")] profile_name: String, @@ -42,9 +42,9 @@ pub struct ProfileState { } impl ProfileState { - pub(super) fn new(profile_head: cid::Cid, profile_name: String, keypair: libp2p::identity::Keypair) -> Self { + pub(super) fn new(profile_name: String, keypair: libp2p::identity::Keypair) -> Self { Self { - profile_head, + profile_head: None, profile_name, keypair } @@ -59,7 +59,7 @@ impl std::fmt::Debug for ProfileState { #[derive(Debug, serde::Serialize, serde::Deserialize, getset::Getters)] pub(super) struct ProfileStateSaveable { - profile_head: Vec, + profile_head: Option>, profile_name: String, keypair: Vec, } @@ -67,7 +67,7 @@ pub(super) struct ProfileStateSaveable { impl ProfileStateSaveable { pub(super) fn new(s: &ProfileState) -> Result { Ok(Self { - profile_head: s.profile_head.to_bytes(), + profile_head: s.profile_head.clone().map(|v| v.to_bytes()), profile_name: s.profile_name.clone(), keypair: match s.keypair { libp2p::identity::Keypair::Ed25519(ref kp) => Vec::from(kp.encode()), @@ -116,7 +116,7 @@ impl TryInto for ProfileStateSaveable { fn try_into(mut self) -> Result { Ok(ProfileState { - profile_head: cid::Cid::try_from(self.profile_head)?, + profile_head: self.profile_head.map(|h| cid::Cid::try_from(h)).transpose()?, profile_name: self.profile_name, keypair: { let kp = libp2p::identity::ed25519::Keypair::decode(&mut self.keypair)?; -- cgit v1.2.3