Skip to content

Commit

Permalink
Add nightly rustfmt checks (#171)
Browse files Browse the repository at this point in the history
* Add nightly rustfmt checks

* fmt

* Add nightly to CI

* Try to use basic nightly
  • Loading branch information
MitchTurner authored Mar 30, 2024
1 parent 8cfd04c commit fbbd58f
Show file tree
Hide file tree
Showing 81 changed files with 1,893 additions and 706 deletions.
20 changes: 18 additions & 2 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,25 @@ jobs:
run: cargo build --verbose --workspace
- name: Run tests
run: cargo test --verbose --workspace
- name: Lint
run: cargo fmt --all -- --check
- name: Clippy
run: cargo clippy --all-targets --all-features -- -D warnings

lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Install latest nightly
uses: dtolnay/rust-toolchain@master
with:
toolchain: nightly
components: rustfmt
- name: Rustfmt check
run: cargo +nightly fmt --all -- --check


audit:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Audit
run: cargo audit
8 changes: 8 additions & 0 deletions .rustfmt.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
max_width = 90
normalize_comments = true
imports_layout = "Vertical"
imports_granularity = "Crate"
trailing_semicolon = false
edition = "2021"
use_try_shorthand = true
use_field_init_shorthand = true
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ FYI, CI requires these commands to pass. So, try to run them locally to save you
```
cargo build --workspace
cargo test --workspace
cargo fmt --all -- --check
cargo +nightly fmt --all -- --check
cargo clippy --all-targets --all-features -- -D warnings
```

Expand Down
6 changes: 4 additions & 2 deletions nau-scripts/build.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
use aiken_lang::ast::Tracing;
use aiken_project::telemetry::Terminal;
use aiken_project::Project;
use aiken_project::{
telemetry::Terminal,
Project,
};

const MINT_NFT_PROJECT: &str = "./aiken/mint_nft";

Expand Down
41 changes: 26 additions & 15 deletions nau-scripts/src/one_shot.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
use naumachia::scripts::raw_script::BlueprintFile;
use naumachia::{
output::Output as NauOutput,
scripts::{
plutus_minting_policy::OneParamPlutusPolicy,
plutus_validator::plutus_data::{Constr, PlutusData},
ScriptError, ScriptResult,
plutus_validator::plutus_data::{
Constr,
PlutusData,
},
raw_script::BlueprintFile,
ScriptError,
ScriptResult,
},
};

Expand Down Expand Up @@ -53,16 +57,16 @@ impl From<OutputReference> for PlutusData {
}
}

pub fn get_parameterized_script() -> ScriptResult<OneParamPlutusPolicy<OutputReference, ()>> {
pub fn get_parameterized_script(
) -> ScriptResult<OneParamPlutusPolicy<OutputReference, ()>> {
let script_file: BlueprintFile = serde_json::from_str(BLUEPRINT)
.map_err(|e| ScriptError::FailedToConstruct(e.to_string()))?;
let validator_blueprint =
script_file
.get_validator(VALIDATOR_NAME)
.ok_or(ScriptError::FailedToConstruct(format!(
"Validator not listed in Blueprint: {:?}",
VALIDATOR_NAME
)))?;
let validator_blueprint = script_file.get_validator(VALIDATOR_NAME).ok_or(
ScriptError::FailedToConstruct(format!(
"Validator not listed in Blueprint: {:?}",
VALIDATOR_NAME
)),
)?;
let raw_script_validator = OneParamPlutusPolicy::from_blueprint(validator_blueprint)
.map_err(|e| ScriptError::FailedToConstruct(e.to_string()))?;
Ok(raw_script_validator)
Expand All @@ -72,10 +76,17 @@ pub fn get_parameterized_script() -> ScriptResult<OneParamPlutusPolicy<OutputRef
#[cfg(test)]
mod tests {
use super::*;
use naumachia::output::Output;
use naumachia::scripts::context::{pub_key_hash_from_address_if_available, ContextBuilder};
use naumachia::scripts::MintingPolicy;
use naumachia::Address;
use naumachia::{
output::Output,
scripts::{
context::{
pub_key_hash_from_address_if_available,
ContextBuilder,
},
MintingPolicy,
},
Address,
};

#[test]
fn execute__succeeds_when_output_included() {
Expand Down
6 changes: 4 additions & 2 deletions sample-dApps/always-succeeds-contract/build.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
use aiken_lang::ast::Tracing;
use aiken_project::telemetry::Terminal;
use aiken_project::Project;
use aiken_project::{
telemetry::Terminal,
Project,
};

const PROJECT: &str = "./always_succeeds";

Expand Down
18 changes: 14 additions & 4 deletions sample-dApps/always-succeeds-contract/src/logic.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,18 @@
use crate::logic::script::get_script;
use async_trait::async_trait;
use naumachia::logic::error::{SCLogicError, SCLogicResult};
use naumachia::{
ledger_client::LedgerClient,
logic::SCLogic,
output::{Output, OutputId},
logic::{
error::{
SCLogicError,
SCLogicResult,
},
SCLogic,
},
output::{
Output,
OutputId,
},
policy_id::PolicyId,
scripts::Validator,
transaction::TxActions,
Expand Down Expand Up @@ -54,7 +62,9 @@ impl SCLogic for AlwaysSucceedsLogic {
ledger_client: &LC,
) -> SCLogicResult<TxActions<Self::Datums, Self::Redeemers>> {
match endpoint {
AlwaysSucceedsEndpoints::Lock { amount } => impl_lock(ledger_client, amount).await,
AlwaysSucceedsEndpoints::Lock { amount } => {
impl_lock(ledger_client, amount).await
}
AlwaysSucceedsEndpoints::Claim { output_id } => {
impl_claim(ledger_client, output_id).await
}
Expand Down
35 changes: 22 additions & 13 deletions sample-dApps/always-succeeds-contract/src/logic/script.rs
Original file line number Diff line number Diff line change
@@ -1,20 +1,22 @@
use naumachia::scripts::plutus_validator::PlutusValidator;
use naumachia::scripts::raw_script::BlueprintFile;
use naumachia::scripts::{ScriptError, ScriptResult};
use naumachia::scripts::{
plutus_validator::PlutusValidator,
raw_script::BlueprintFile,
ScriptError,
ScriptResult,
};

const BLUEPRINT: &str = include_str!("../../always_succeeds/plutus.json");
const VALIDATOR_NAME: &str = "always_true.spend";

pub fn get_script() -> ScriptResult<PlutusValidator<(), ()>> {
let script_file: BlueprintFile = serde_json::from_str(BLUEPRINT)
.map_err(|e| ScriptError::FailedToConstruct(e.to_string()))?;
let validator_blueprint =
script_file
.get_validator(VALIDATOR_NAME)
.ok_or(ScriptError::FailedToConstruct(format!(
"Validator not listed in Blueprint: {:?}",
VALIDATOR_NAME
)))?;
let validator_blueprint = script_file.get_validator(VALIDATOR_NAME).ok_or(
ScriptError::FailedToConstruct(format!(
"Validator not listed in Blueprint: {:?}",
VALIDATOR_NAME
)),
)?;
let raw_script_validator = PlutusValidator::from_blueprint(validator_blueprint)
.map_err(|e| ScriptError::FailedToConstruct(e.to_string()))?;
Ok(raw_script_validator)
Expand All @@ -23,9 +25,16 @@ pub fn get_script() -> ScriptResult<PlutusValidator<(), ()>> {
#[cfg(test)]
mod tests {
use super::*;
use naumachia::scripts::context::{pub_key_hash_from_address_if_available, ContextBuilder};
use naumachia::scripts::Validator;
use naumachia::Address;
use naumachia::{
scripts::{
context::{
pub_key_hash_from_address_if_available,
ContextBuilder,
},
Validator,
},
Address,
};

#[test]
fn test() {
Expand Down
12 changes: 9 additions & 3 deletions sample-dApps/always-succeeds-contract/src/logic/tests.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
use super::*;
use naumachia::ledger_client::test_ledger_client::TestLedgerClientBuilder;
use naumachia::smart_contract::{SmartContract, SmartContractTrait};
use naumachia::{Address, Network};
use naumachia::{
ledger_client::test_ledger_client::TestLedgerClientBuilder,
smart_contract::{
SmartContract,
SmartContractTrait,
},
Address,
Network,
};

#[tokio::test]
async fn lock_and_claim() {
Expand Down
9 changes: 7 additions & 2 deletions sample-dApps/always-succeeds-contract/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
use always_succeeds_contract::logic::{
AlwaysSucceedsEndpoints, AlwaysSucceedsLogic, AlwaysSucceedsLookupResponses,
AlwaysSucceedsEndpoints,
AlwaysSucceedsLogic,
AlwaysSucceedsLookupResponses,
AlwaysSucceedsLookups,
};
use clap::Parser;
use naumachia::{
output::OutputId,
smart_contract::{SmartContract, SmartContractTrait},
smart_contract::{
SmartContract,
SmartContractTrait,
},
trireme_ledger_client::get_trireme_ledger_client_from_file,
};

Expand Down
6 changes: 4 additions & 2 deletions sample-dApps/checking_account/build.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
use aiken_lang::ast::Tracing;
use aiken_project::telemetry::Terminal;
use aiken_project::Project;
use aiken_project::{
telemetry::Terminal,
Project,
};

const PROJECT: &str = "./checking";

Expand Down
2 changes: 1 addition & 1 deletion sample-dApps/checking_account/checking/aiken.lock
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ requirements = []
source = "github"

[etags]
"aiken-lang/stdlib@main" = [{ secs_since_epoch = 1708887379, nanos_since_epoch = 415727333 }, "cf946239d3dd481ed41f20e56bf24910b5229ea35aa171a708edc2a47fc20a7b"]
"aiken-lang/stdlib@main" = [{ secs_since_epoch = 1711836891, nanos_since_epoch = 667346334 }, "2a710731e0127ec3e21c6c3962a0254c98602e7428b33fc4fcaa67ab368ce1b1"]
11 changes: 8 additions & 3 deletions sample-dApps/checking_account/src/datum.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
use naumachia::scripts::context::PubKeyHash;
use naumachia::scripts::plutus_validator::plutus_data::{Constr, PlutusData};
use naumachia::scripts::{
context::PubKeyHash,
plutus_validator::plutus_data::{
Constr,
PlutusData,
},
};

#[derive(Debug, Clone, Eq, PartialEq, Hash)]
pub enum CheckingAccountDatums {
Expand Down Expand Up @@ -149,7 +154,7 @@ fn allowed_puller(fields: &[PlutusData]) -> Result<CheckingAccountDatums, ()> {
let datum = CheckingAccountDatums::AllowedPuller(AllowedPuller {
owner,
puller,
amount_lovelace: amount_lovelace as u64, //TODO
amount_lovelace: amount_lovelace as u64, // TODO
next_pull,
period,
spending_token,
Expand Down
29 changes: 21 additions & 8 deletions sample-dApps/checking_account/src/endpoints/add_puller.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,26 @@
use crate::{
pull_validator, spend_token_policy, AllowedPuller, CheckingAccountDatums, CheckingAccountError,
pull_validator,
spend_token_policy,
AllowedPuller,
CheckingAccountDatums,
CheckingAccountError,
SPEND_TOKEN_ASSET_NAME,
};
use naumachia::logic::error::{SCLogicError, SCLogicResult};
use naumachia::{
ledger_client::LedgerClient,
logic::error::{
SCLogicError,
SCLogicResult,
},
policy_id::PolicyId,
scripts::context::{pub_key_hash_from_address_if_available, PubKeyHash},
scripts::MintingPolicy,
scripts::Validator,
scripts::{
context::{
pub_key_hash_from_address_if_available,
PubKeyHash,
},
MintingPolicy,
Validator,
},
transaction::TxActions,
values::Values,
};
Expand All @@ -29,9 +41,10 @@ pub async fn add_puller<LC: LedgerClient<CheckingAccountDatums, ()>>(
.signer_base_address()
.await
.map_err(|e| SCLogicError::Endpoint(Box::new(e)))?;
let owner = pub_key_hash_from_address_if_available(&me).ok_or(SCLogicError::Endpoint(
Box::new(CheckingAccountError::InvalidAddress(me.clone())),
))?;
let owner =
pub_key_hash_from_address_if_available(&me).ok_or(SCLogicError::Endpoint(
Box::new(CheckingAccountError::InvalidAddress(me.clone())),
))?;

let nft_id_bytes = hex::decode(checking_account_nft_id).unwrap();
let my_pubkey = pub_key_hash_from_address_if_available(&me).unwrap();
Expand Down
16 changes: 13 additions & 3 deletions sample-dApps/checking_account/src/endpoints/fund_account.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,17 @@
use crate::{checking_account_validator, CheckingAccountDatums, CheckingAccountError};
use naumachia::logic::error::{SCLogicError, SCLogicResult};
use crate::{
checking_account_validator,
CheckingAccountDatums,
CheckingAccountError,
};
use naumachia::{
ledger_client::LedgerClient, output::OutputId, policy_id::PolicyId, scripts::Validator,
ledger_client::LedgerClient,
logic::error::{
SCLogicError,
SCLogicResult,
},
output::OutputId,
policy_id::PolicyId,
scripts::Validator,
transaction::TxActions,
};

Expand Down
27 changes: 20 additions & 7 deletions sample-dApps/checking_account/src/endpoints/init_account.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,29 @@
use crate::{
checking_account_validator, spend_token_policy, CheckingAccount, CheckingAccountDatums,
CheckingAccountError, CHECKING_ACCOUNT_NFT_ASSET_NAME,
checking_account_validator,
spend_token_policy,
CheckingAccount,
CheckingAccountDatums,
CheckingAccountError,
CHECKING_ACCOUNT_NFT_ASSET_NAME,
};
use nau_scripts::{
one_shot,
one_shot::OutputReference,
};
use nau_scripts::{one_shot, one_shot::OutputReference};
use naumachia::logic::error::{SCLogicError, SCLogicResult};
use naumachia::{
ledger_client::LedgerClient,
logic::error::{
SCLogicError,
SCLogicResult,
},
output::Output,
policy_id::PolicyId,
scripts::context::pub_key_hash_from_address_if_available,
scripts::Validator,
scripts::{MintingPolicy, ScriptError},
scripts::{
context::pub_key_hash_from_address_if_available,
MintingPolicy,
ScriptError,
Validator,
},
transaction::TxActions,
values::Values,
};
Expand Down
Loading

0 comments on commit fbbd58f

Please sign in to comment.