Skip to content

Commit

Permalink
166 Integrate VC Data Model Spec Test Suite (#167)
Browse files Browse the repository at this point in the history
1. Refactored `Credential`, `Presentation` & `VerifiablePresentation`
structs in SSI to support full flexibility required by the VC Data Model
2. Integrated vc test suite spec tests and added it as a GH Action on
every PR
  • Loading branch information
LuisOsta authored Nov 28, 2023
1 parent 049e356 commit 4a4b73a
Show file tree
Hide file tree
Showing 12 changed files with 628 additions and 86 deletions.
50 changes: 50 additions & 0 deletions .github/workflows/vc_model_spec_test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
name: VC Model Spec Test
# Tests the VC Model Spec against the vc-test-suite - https://github.com/w3c/vc-test-suite
on:
pull_request:
branches:
- main
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

- name: Cache Rust dependencies
uses: Swatinem/rust-cache@v2

- name: Install Protoc and cargo-make
run: ./container/deps.sh protoc cargo-make

- uses: knox-networks/github-actions-public/.github/actions/setup-protofetch@main
with:
cross-repo-username: "developersKnox"
cross-repo-token: ${{ secrets.PROTOFETCH_GITHUB_TOKEN }}

- name: Test protos
run: (cd registry_resolver; protofetch fetch) && git diff --exit-code

- name: Build CLI
run: cargo build --package cli --release

- name: Add CLI to bin
run: sudo cp $PWD/target/release/ssi_cli /bin/ssi_cli

- name: Install Node & NPM
uses: actions/setup-node@v2
with:
node-version: "20"

- name: Clone & Install vc-test-suite
run: |
git clone https://github.com/knox-networks/vc-test-suite
cd vc-test-suite
npm install
- name: Copy vc-test-suite config
run: cp tests/vc_model_spec_test/config.json vc-test-suite/config.json

- name: Run vc-test-suite
run: |
cd vc-test-suite
npm run test
172 changes: 172 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ members = [
"signature",
"ssi",
"ephemeral_resolver",
"ffi"
"ffi",
"cli",
]


Expand Down
15 changes: 15 additions & 0 deletions cli/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
[package]
name = "cli"
version.workspace = true
edition.workspace = true

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
clap = {version = "4.4.8", features = ["derive"]}
ssi = {path = "../ssi"}

# binary definition
[[bin]]
name = "ssi_cli"
path = "src/main.rs"
45 changes: 45 additions & 0 deletions cli/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
use std::str::FromStr;

use clap::{command, Parser, Subcommand};

#[derive(Parser, Debug)]
#[command(author, version, about, long_about = None)]
#[command(propagate_version = true)]
struct CliArguments {
#[command(subcommand)]
command: Command,
}

#[derive(Subcommand, Debug)]
enum Command {
/// Read the JSON string file in input_file and parse it into a VerifiableCredential. Then prints the VerifiableCredential
TestIssueCredential {
#[arg(short, long)]
input_file: String,
},
/// Read the JSON string file in input_file and parse it into a VerifiablePresentation. Then prints the VerifiablePresentation
TestIssuePresentation {
#[arg(short, long)]
input_file: String,
},
}

fn main() {
let args = CliArguments::parse();
match args.command {
Command::TestIssueCredential {
input_file: input_file_path,
} => {
let input = std::fs::read_to_string(input_file_path).unwrap();
let vc = ssi::credential::VerifiableCredential::from_str(&input).unwrap();
println!("{}", vc);
}
Command::TestIssuePresentation {
input_file: input_file_path,
} => {
let input = std::fs::read_to_string(input_file_path).unwrap();
let vc = ssi::credential::VerifiablePresentation::from_str(&input).unwrap();
println!("{}", vc);
}
}
}
1 change: 1 addition & 0 deletions core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ mockall = {workspace = true}
thiserror = {workspace = true}
json-ld = "0.15.0"
sophia = { git = "https://github.com/pchampin/sophia_rs.git", rev = "572512bd4a13dce4ca52f9310ac907b06dbea556", features = ["jsonld","http_client"] }
serde_valid = "0.16.3"

[dev-dependencies]
rstest = "0.15.0"
Expand Down
Loading

0 comments on commit 4a4b73a

Please sign in to comment.