Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CI CD workflows #4

Open
wants to merge 4 commits into
base: release_candidate_1
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions .github/actions/cargo-cache/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: 'Set up cargo cache'
description: 'Sets up the cargo cache for the workflow'
runs:
using: 'composite'
steps:
- name: Checkout repository
uses: actions/checkout@v3

- name: Set up cargo cache
uses: actions/cache@v3
continue-on-error: false
with:
path: |
~/.cargo/bin/
~/.cargo/registry/index/
~/.cargo/registry/cache/
~/.cargo/git/db/
target/
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
restore-keys: ${{ runner.os }}-cargo-
60 changes: 60 additions & 0 deletions .github/workflows/fmt-and-lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
name: Format and Lint
on: [push]

concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true

jobs:
fmt-and-lint:
name: x86 Format and Lint Checks
timeout-minutes: 30
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Install Rust toolchain
uses: actions-rs/toolchain@v1
with:
components: clippy, rustfmt
override: true
profile: minimal
toolchain: nightly-2023-06-01

- name: Cargo cache
uses: ./.github/actions/cargo-cache

- name: fmt check
# Format checks aren't OS dependent.
if: matrix.os == 'ubuntu-latest'
run: cargo fmt --all -- --check

- name: Clippy lint
run: cargo clippy --all-targets --all-features -- --D warnings

wasm-lint:
name: Wasm Lint Checks
timeout-minutes: 30
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Install Rust toolchain
uses: actions-rs/toolchain@v1
with:
components: clippy
override: true
profile: minimal
toolchain: nightly-2023-06-01
target: wasm32-unknown-unknown

- name: Cargo cache
uses: ./.github/actions/cargo-cache

- name: Clippy lint
run: cargo clippy --target wasm32-unknown-unknown -- --D warnings
35 changes: 35 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: Test
on:
push:
branches-ignore:
- main

concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true

jobs:
x86-64-unit-tests:
name: x86 Cargo unit tests
timeout-minutes: 30
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Install Rust toolchain
uses: actions-rs/toolchain@v1
with:
components: clippy, rustfmt
override: true
profile: minimal
toolchain: nightly-2023-06-01

- name: Cargo cache
uses: ./.github/actions/cargo-cache

- name: Cargo test
run: cargo test --no-fail-fast
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
target/

.vscode/
.vscode/

.idea
14 changes: 7 additions & 7 deletions src/tests/spend_policy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ mod test {
}
);

let spend_policy_deser = serde_json::from_value::<SpendPolicy>(j).unwrap().into();
let spend_policy_deser = serde_json::from_value::<SpendPolicy>(j).unwrap();
let spend_policy = SpendPolicy::Above(100);

assert_eq!(spend_policy, spend_policy_deser);
Expand All @@ -27,7 +27,7 @@ mod test {
}
);

let spend_policy_deser = serde_json::from_value::<SpendPolicy>(j).unwrap().into();
let spend_policy_deser = serde_json::from_value::<SpendPolicy>(j).unwrap();
let spend_policy = SpendPolicy::After(200);

assert_eq!(spend_policy, spend_policy_deser);
Expand All @@ -44,7 +44,7 @@ mod test {
&hex::decode("0102030000000000000000000000000000000000000000000000000000000000").unwrap(),
)
.unwrap();
let spend_policy_deser: SpendPolicy = serde_json::from_value::<SpendPolicy>(j).unwrap().into();
let spend_policy_deser: SpendPolicy = serde_json::from_value::<SpendPolicy>(j).unwrap();
let spend_policy = SpendPolicy::PublicKey(pubkey);

assert_eq!(spend_policy, spend_policy_deser);
Expand All @@ -58,7 +58,7 @@ mod test {
}
);
let hash = Hash256::try_from("h:0102030000000000000000000000000000000000000000000000000000000000").unwrap();
let spend_policy_deser: SpendPolicy = serde_json::from_value::<SpendPolicy>(j).unwrap().into();
let spend_policy_deser: SpendPolicy = serde_json::from_value::<SpendPolicy>(j).unwrap();
let spend_policy = SpendPolicy::Hash(hash);

assert_eq!(spend_policy, spend_policy_deser);
Expand All @@ -73,7 +73,7 @@ mod test {
);
let address =
Address::from_str("addr:f72e84ee9e344e424a6764068ffd7fdce4b4e50609892c6801bc1ead79d3ae0d71791b277a3a").unwrap();
let spend_policy_deser: SpendPolicy = serde_json::from_value::<SpendPolicy>(j).unwrap().into();
let spend_policy_deser: SpendPolicy = serde_json::from_value::<SpendPolicy>(j).unwrap();
let spend_policy = SpendPolicy::Opaque(address);

assert_eq!(spend_policy, spend_policy_deser);
Expand Down Expand Up @@ -123,7 +123,7 @@ mod test {
}
);

let spend_policy_deser: SpendPolicy = serde_json::from_value::<SpendPolicy>(j).unwrap().into();
let spend_policy_deser: SpendPolicy = serde_json::from_value::<SpendPolicy>(j).unwrap();

assert_eq!(spend_policy, spend_policy_deser);
}
Expand Down Expand Up @@ -153,7 +153,7 @@ mod test {
signatures_required: 1,
};

let spend_policy_deser: SpendPolicy = serde_json::from_value::<SpendPolicy>(j).unwrap().into();
let spend_policy_deser: SpendPolicy = serde_json::from_value::<SpendPolicy>(j).unwrap();
let spend_policy = SpendPolicy::UnlockConditions(uc);

assert_eq!(spend_policy, spend_policy_deser);
Expand Down
4 changes: 2 additions & 2 deletions src/transport/client/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,10 @@ pub trait ApiClientHelpers: ApiClient {
if selected_amount < *total_amount {
return Err(ApiClientHelpersError::SelectOutputs {
available: selected_amount.into(),
required: total_amount.into(),
required: total_amount,
});
}
let change = selected_amount as u128 - *total_amount;
let change = selected_amount - *total_amount;

Ok((selected, change.into()))
}
Expand Down
2 changes: 1 addition & 1 deletion src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ impl<'de> Deserialize<'de> for Event {
}?;

Ok(Event {
id: helper.id.into(),
id: helper.id,
index: helper.index,
timestamp: helper.timestamp,
maturity_height: helper.maturity_height,
Expand Down
18 changes: 9 additions & 9 deletions src/types/atomic_swap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ impl IsValidatedPolicy for AtomicSwap {
}),
SpendPolicy::Threshold { n, of: _ } => Err(AtomicSwapError::InvalidN {
policy: policy.clone(),
n: n.clone(),
n: *n,
}),
_ => Err(AtomicSwapError::InvalidSpendPolicyVariant(policy.clone())),
}
Expand Down Expand Up @@ -212,7 +212,7 @@ impl IsValidatedPolicy for HashLockPath {
}),
SpendPolicy::Threshold { n, of: _ } => Err(ComponentError::HashLockInvalidN {
policy: policy.clone(),
n: n.clone(),
n: *n,
}),
_ => Err(ComponentError::HashLockInvalidSpendPolicyVariant(policy.clone())),
}
Expand Down Expand Up @@ -256,7 +256,7 @@ impl IsValidatedPolicy for TimeLockPath {
}),
SpendPolicy::Threshold { n, of: _ } => Err(ComponentError::TimeLockInvalidN {
policy: policy.clone(),
n: n.clone(),
n: *n,
}),
_ => Err(ComponentError::TimeLockInvalidSpendPolicyVariant(policy.clone())),
}
Expand Down Expand Up @@ -424,7 +424,7 @@ mod test {
of: vec![SpendPolicy::PublicKey(pubkey0()), valid_component_time_lock()],
};

match AtomicSwap::new(policy.clone()).unwrap_err() {
match AtomicSwap::new(policy).unwrap_err() {
AtomicSwapError::InvalidHashComponent(ComponentError::HashLockInvalidSpendPolicyVariant(_)) => (),
_ => panic!(),
}
Expand All @@ -437,7 +437,7 @@ mod test {
of: vec![valid_component_hash_lock(), SpendPolicy::PublicKey(pubkey0())],
};

match AtomicSwap::new(policy.clone()).unwrap_err() {
match AtomicSwap::new(policy).unwrap_err() {
AtomicSwapError::InvalidTimeComponent(ComponentError::TimeLockInvalidSpendPolicyVariant(_)) => (),
_ => panic!(),
}
Expand All @@ -450,7 +450,7 @@ mod test {
of: vec![valid_component_time_lock(), valid_component_hash_lock()],
};

match AtomicSwap::new(policy.clone()).unwrap_err() {
match AtomicSwap::new(policy).unwrap_err() {
AtomicSwapError::InvalidHashComponent(ComponentError::HashLockInvalidThresholdStructure(_)) => (),
_ => panic!(),
}
Expand Down Expand Up @@ -517,7 +517,7 @@ mod test {
},
_ => unreachable!(),
}
match AtomicSwap::new(policy.clone()) {
match AtomicSwap::new(policy) {
Err(AtomicSwapError::InvalidM { policy: _, m }) => {
assert_eq!(m, 0);
},
Expand All @@ -533,7 +533,7 @@ mod test {
_ => unreachable!(),
}

match AtomicSwap::new(policy.clone()) {
match AtomicSwap::new(policy) {
Err(AtomicSwapError::InvalidN { policy: _, n }) => {
assert_eq!(n, 10);
},
Expand All @@ -545,7 +545,7 @@ mod test {
fn test_atomic_swap_contract_invalid_policy_variant() {
let policy = SpendPolicy::PublicKey(pubkey0());

match AtomicSwap::new(policy.clone()) {
match AtomicSwap::new(policy) {
Err(AtomicSwapError::InvalidSpendPolicyVariant { .. }) => (),
_ => panic!(),
}
Expand Down
2 changes: 1 addition & 1 deletion src/types/keypair.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ impl Signer<Signature> for Keypair {
/// Sign a message with this keypair's secret key.
fn try_sign(&self, message: &[u8]) -> Result<Signature, Ed25519SignatureError> {
let expanded: ExpandedSecretKey = (&self.private.0).into();
Ok(Signature::new(expanded.sign(&message, &self.public.0)))
Ok(Signature::new(expanded.sign(message, &self.public.0)))
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/types/signature.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ impl Signature {
}

pub fn verify(&self, message: &[u8], public_key: &PublicKey) -> Result<(), SignatureError> {
public_key.verify(message, &self)
public_key.verify(message, self)
}
}

Expand Down