diff --git a/.github/actions/cargo-cache/action.yml b/.github/actions/cargo-cache/action.yml new file mode 100644 index 0000000..54cf637 --- /dev/null +++ b/.github/actions/cargo-cache/action.yml @@ -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- \ No newline at end of file diff --git a/.github/workflows/fmt-and-lint.yml b/.github/workflows/fmt-and-lint.yml new file mode 100644 index 0000000..6394a8e --- /dev/null +++ b/.github/workflows/fmt-and-lint.yml @@ -0,0 +1,54 @@ +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 + run: | + rustup toolchain install nightly-2023-06-01 --no-self-update --profile minimal --component clippy rustfmt + rustup default 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 + run: | + rustup toolchain install nightly-2023-06-01 --no-self-update --profile=minimal --component clippy + rustup default nightly-2023-06-01 + rustup target add wasm32-unknown-unknown + + - name: Cargo cache + uses: ./.github/actions/cargo-cache + + - name: Clippy lint + run: cargo clippy --target wasm32-unknown-unknown -- --D warnings \ No newline at end of file diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000..1966e62 --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,32 @@ +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 + run: | + rustup toolchain install nightly-2023-06-01 --no-self-update --profile minimal + rustup default nightly-2023-06-01 + + - name: Cargo cache + uses: ./.github/actions/cargo-cache + + - name: Cargo test + run: cargo test --no-fail-fast \ No newline at end of file diff --git a/.gitignore b/.gitignore index 17e0f98..f7fafda 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,5 @@ target/ -.vscode/ \ No newline at end of file +.vscode/ + +.idea \ No newline at end of file diff --git a/src/tests/spend_policy.rs b/src/tests/spend_policy.rs index bc9d704..a21818b 100644 --- a/src/tests/spend_policy.rs +++ b/src/tests/spend_policy.rs @@ -12,7 +12,7 @@ mod test { } ); - let spend_policy_deser = serde_json::from_value::(j).unwrap().into(); + let spend_policy_deser = serde_json::from_value::(j).unwrap(); let spend_policy = SpendPolicy::Above(100); assert_eq!(spend_policy, spend_policy_deser); @@ -26,7 +26,7 @@ mod test { } ); - let spend_policy_deser = serde_json::from_value::(j).unwrap().into(); + let spend_policy_deser = serde_json::from_value::(j).unwrap(); let spend_policy = SpendPolicy::After(200); assert_eq!(spend_policy, spend_policy_deser); @@ -43,7 +43,7 @@ mod test { &hex::decode("0102030000000000000000000000000000000000000000000000000000000000").unwrap(), ) .unwrap(); - let spend_policy_deser: SpendPolicy = serde_json::from_value::(j).unwrap().into(); + let spend_policy_deser: SpendPolicy = serde_json::from_value::(j).unwrap(); let spend_policy = SpendPolicy::PublicKey(pubkey); assert_eq!(spend_policy, spend_policy_deser); @@ -57,7 +57,7 @@ mod test { } ); let hash = Hash256::from_str("h:0102030000000000000000000000000000000000000000000000000000000000").unwrap(); - let spend_policy_deser: SpendPolicy = serde_json::from_value::(j).unwrap().into(); + let spend_policy_deser: SpendPolicy = serde_json::from_value::(j).unwrap(); let spend_policy = SpendPolicy::Hash(hash); assert_eq!(spend_policy, spend_policy_deser); @@ -72,7 +72,7 @@ mod test { ); let address = Address::from_str("addr:f72e84ee9e344e424a6764068ffd7fdce4b4e50609892c6801bc1ead79d3ae0d71791b277a3a").unwrap(); - let spend_policy_deser: SpendPolicy = serde_json::from_value::(j).unwrap().into(); + let spend_policy_deser: SpendPolicy = serde_json::from_value::(j).unwrap(); let spend_policy = SpendPolicy::Opaque(address); assert_eq!(spend_policy, spend_policy_deser); @@ -122,7 +122,7 @@ mod test { } ); - let spend_policy_deser: SpendPolicy = serde_json::from_value::(j).unwrap().into(); + let spend_policy_deser: SpendPolicy = serde_json::from_value::(j).unwrap(); assert_eq!(spend_policy, spend_policy_deser); } @@ -152,7 +152,7 @@ mod test { signatures_required: 1, }; - let spend_policy_deser: SpendPolicy = serde_json::from_value::(j).unwrap().into(); + let spend_policy_deser: SpendPolicy = serde_json::from_value::(j).unwrap(); let spend_policy = SpendPolicy::UnlockConditions(uc); assert_eq!(spend_policy, spend_policy_deser);