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

[Debt] Improve consistency of best practice application #32

Merged
Merged
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
33 changes: 33 additions & 0 deletions .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<!--
Thank you for your Pull Request. Please provide a description above and review
the requirements below.

Bug fixes and new features should include tests.

Contributors guide: https://github.com/alloy-rs/examples/blob/main/CONTRIBUTING.md

The contributors guide includes instructions for running rustfmt and building the
documentation.
-->

<!-- ** Please select "Allow edits from maintainers" in the PR Options ** -->

## Motivation

<!--
Explain the context and why you're making that change. What is the problem
you're trying to solve? In some cases there is not a problem and this can be
thought of as being the motivation for your change.
-->

## Solution

<!--
Summarize the solution and provide any necessary context needed to understand
the code change.
-->

## PR Checklist

- [ ] Added Documentation
- [ ] Breaking changes
10 changes: 6 additions & 4 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -125,11 +125,13 @@ less work from you.
This section lists some commonly needed commands.

```sh
cargo check --all-features
cargo check --examples --all-features
cargo build --examples --all-features
cargo +nightly fmt --all
cargo build --all-features
cargo test --all-features
cargo +nightly clippy --all-features
cargo +nightly clippy \
--examples \
--all-features \
-- -D warnings
```

### Tests
Expand Down
44 changes: 44 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,50 @@ repository = "https://github.com/alloy-rs/examples"
publish = false
exclude = ["examples/"]

[workspace.lints]
rust.missing_debug_implementations = "warn"
rust.missing_docs = "warn"
rust.unreachable_pub = "warn"
rustdoc.all = "warn"
rust.unused_must_use = "deny"
rust.rust_2018_idioms = "deny"

[workspace.lints.clippy]
# These are some of clippy's nursery (i.e., experimental) lints that we like.
# By default, nursery lints are allowed. Some of the lints below have made good
# suggestions which we fixed. The others didn't have any findings, so we can
# assume they don't have that many false positives. Let's enable them to
# prevent future problems.
branches_sharing_code = "warn"
clear_with_drain = "warn"
derive_partial_eq_without_eq = "warn"
empty_line_after_outer_attr = "warn"
equatable_if_let = "warn"
imprecise_flops = "warn"
iter_on_empty_collections = "warn"
iter_with_drain = "warn"
large_stack_frames = "warn"
manual_clamp = "warn"
mutex_integer = "warn"
needless_pass_by_ref_mut = "warn"
nonstandard_macro_braces = "warn"
or_fun_call = "warn"
path_buf_push_overwrite = "warn"
read_zero_byte_vec = "warn"
redundant_clone = "warn"
suboptimal_flops = "warn"
suspicious_operation_groupings = "warn"
trailing_empty_array = "warn"
trait_duplication_in_bounds = "warn"
transmute_undefined_repr = "warn"
trivial_regex = "warn"
tuple_array_conversions = "warn"
uninhabited_references = "warn"
unused_peekable = "warn"
unused_rounding = "warn"
useless_let_if_seq = "warn"
uninlined_format_args = "warn"

[workspace.dependencies]
alloy = { git = "https://github.com/alloy-rs/alloy", rev = "f7333c4", features = [
# "dyn-abi",
Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
Example code using [alloy](https://github.com/alloy-rs/alloy) and [alloy-core](https://github.com/alloy-rs/core).

These examples demonstrate the main features of [Alloy](https://github.com/alloy-rs/alloy) and how to use them.
To run an example, use the command `cargo run --example <Example>`.

To run an example, use the command `cargo run --example <Example>`:

```sh
cargo run --example mnemonic_signer
Expand Down
4 changes: 3 additions & 1 deletion examples/anvil/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
[package]
name = "examples-anvil"

publish.workspace = true
version.workspace = true
edition.workspace = true
Expand All @@ -10,6 +9,9 @@ license.workspace = true
homepage.workspace = true
repository.workspace = true

[lints]
workspace = true

[dev-dependencies]
alloy.workspace = true

Expand Down
15 changes: 8 additions & 7 deletions examples/anvil/examples/deploy_contract_anvil.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ use eyre::Result;

// Codegen from embedded Solidity code and precompiled bytecode.
sol! {
#[allow(missing_docs)]
// solc v0.8.24; solc a.sol --via-ir --optimize --bin
#[sol(rpc, bytecode="608080604052346100155760d2908161001a8239f35b5f80fdfe60808060405260043610156011575f80fd5b5f3560e01c9081633fb5c1cb1460865781638381f58a14606f575063d09de08a146039575f80fd5b34606b575f366003190112606b575f545f1981146057576001015f55005b634e487b7160e01b5f52601160045260245ffd5b5f80fd5b34606b575f366003190112606b576020905f548152f35b34606b576020366003190112606b576004355f5500fea2646970667358221220bdecd3c1dd631eb40587cafcd6e8297479db76db6a328e18ad1ea5b340852e3864736f6c63430008180033")]
contract Counter {
Expand All @@ -31,17 +32,17 @@ sol! {
#[tokio::main]
async fn main() -> Result<()> {
// Spin up a local Anvil node.
// Ensure `anvil` is available in $PATH
// Ensure `anvil` is available in $PATH.
let anvil = Anvil::new().try_spawn()?;

// Set up wallet
let wallet: LocalWallet = anvil.keys()[0].clone().into();
// Set up signer from the first default Anvil account (Alice).
let signer: LocalWallet = anvil.keys()[0].clone().into();

// Create a provider with a signer and the network.
let http = anvil.endpoint().parse()?;
let rpc_url = anvil.endpoint().parse()?;
let provider = ProviderBuilder::new()
.signer(EthereumSigner::from(wallet))
.on_client(RpcClient::new_http(http));
.signer(EthereumSigner::from(signer))
.on_client(RpcClient::new_http(rpc_url));

println!("Anvil running at `{}`", anvil.endpoint());

Expand All @@ -54,7 +55,7 @@ async fn main() -> Result<()> {
let contract_address =
contract_builder.gas(estimate).gas_price(base_fee).nonce(0).deploy().await?;

println!("Deployed contract at address: {:?}", contract_address);
println!("Deployed contract at address: {contract_address:?}");

let contract = Counter::new(contract_address, &provider);

Expand Down
2 changes: 1 addition & 1 deletion examples/anvil/examples/fork_anvil.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use eyre::Result;
#[tokio::main]
async fn main() -> Result<()> {
// Spin up a forked Anvil node.
// Ensure `anvil` is available in $PATH
// Ensure `anvil` is available in $PATH.
let anvil = Anvil::new().fork("https://eth.merkle.io").try_spawn()?;

println!("Anvil running at `{}`", anvil.endpoint());
Expand Down
2 changes: 1 addition & 1 deletion examples/anvil/examples/local_anvil.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use eyre::Result;
#[tokio::main]
async fn main() -> Result<()> {
// Spin up a local Anvil node.
// Ensure `anvil` is available in $PATH
// Ensure `anvil` is available in $PATH.
let anvil = Anvil::new().block_time(1).chain_id(1337).try_spawn()?;

println!("Anvil running at `{}`", anvil.endpoint());
Expand Down
4 changes: 3 additions & 1 deletion examples/big-numbers/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
[package]
name = "examples-big-numbers"

publish.workspace = true
version.workspace = true
edition.workspace = true
Expand All @@ -10,6 +9,9 @@ license.workspace = true
homepage.workspace = true
repository.workspace = true

[lints]
workspace = true

[dev-dependencies]
alloy.workspace = true

Expand Down
4 changes: 3 additions & 1 deletion examples/contracts/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
[package]
name = "examples-contracts"

publish.workspace = true
version.workspace = true
edition.workspace = true
Expand All @@ -10,6 +9,9 @@ license.workspace = true
homepage.workspace = true
repository.workspace = true

[lints]
workspace = true

[dev-dependencies]
alloy.workspace = true

Expand Down
15 changes: 8 additions & 7 deletions examples/contracts/examples/deploy_from_artifact.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ use eyre::Result;

// Codegen from artifact.
sol!(
#[allow(missing_docs)]
#[sol(rpc)]
Counter,
"examples/artifacts/Counter.json"
Expand All @@ -21,17 +22,17 @@ sol!(
#[tokio::main]
async fn main() -> Result<()> {
// Spin up a local Anvil node.
// Ensure `anvil` is available in $PATH
// Ensure `anvil` is available in $PATH.
let anvil = Anvil::new().try_spawn()?;

// Set up wallet
let wallet: LocalWallet = anvil.keys()[0].clone().into();
// Set up signer from the first default Anvil account (Alice).
let signer: LocalWallet = anvil.keys()[0].clone().into();

// Create a provider with a signer.
let http = anvil.endpoint().parse()?;
let rpc_url = anvil.endpoint().parse()?;
let provider = ProviderBuilder::new()
.signer(EthereumSigner::from(wallet))
.on_client(RpcClient::new_http(http));
.signer(EthereumSigner::from(signer))
.on_client(RpcClient::new_http(rpc_url));

println!("Anvil running at `{}`", anvil.endpoint());

Expand All @@ -44,7 +45,7 @@ async fn main() -> Result<()> {
let contract_address =
contract_builder.gas(estimate).gas_price(base_fee).nonce(0).deploy().await?;

println!("Deployed contract at address: {:?}", contract_address);
println!("Deployed contract at address: {contract_address:?}");

let contract = Counter::new(contract_address, &provider);

Expand Down
15 changes: 8 additions & 7 deletions examples/contracts/examples/deploy_from_contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ use eyre::Result;

// Codegen from embedded Solidity code and precompiled bytecode.
sol! {
#[allow(missing_docs)]
// solc v0.8.24; solc a.sol --via-ir --optimize --bin
#[sol(rpc, bytecode="608080604052346100155760d2908161001a8239f35b5f80fdfe60808060405260043610156011575f80fd5b5f3560e01c9081633fb5c1cb1460865781638381f58a14606f575063d09de08a146039575f80fd5b34606b575f366003190112606b575f545f1981146057576001015f55005b634e487b7160e01b5f52601160045260245ffd5b5f80fd5b34606b575f366003190112606b576020905f548152f35b34606b576020366003190112606b576004355f5500fea2646970667358221220bdecd3c1dd631eb40587cafcd6e8297479db76db6a328e18ad1ea5b340852e3864736f6c63430008180033")]
contract Counter {
Expand All @@ -31,17 +32,17 @@ sol! {
#[tokio::main]
async fn main() -> Result<()> {
// Spin up a local Anvil node.
// Ensure `anvil` is available in $PATH
// Ensure `anvil` is available in $PATH.
let anvil = Anvil::new().try_spawn()?;

// Set up wallet
let wallet: LocalWallet = anvil.keys()[0].clone().into();
// Set up signer from the first default Anvil account (Alice).
let signer: LocalWallet = anvil.keys()[0].clone().into();

// Create a provider with a signer.
let http = anvil.endpoint().parse()?;
let rpc_url = anvil.endpoint().parse()?;
let provider = ProviderBuilder::new()
.signer(EthereumSigner::from(wallet))
.on_client(RpcClient::new_http(http));
.signer(EthereumSigner::from(signer))
.on_client(RpcClient::new_http(rpc_url));

println!("Anvil running at `{}`", anvil.endpoint());

Expand All @@ -54,7 +55,7 @@ async fn main() -> Result<()> {
let contract_address =
contract_builder.gas(estimate).gas_price(base_fee).nonce(0).deploy().await?;

println!("Deployed contract at address: {:?}", contract_address);
println!("Deployed contract at address: {contract_address:?}");

let contract = Counter::new(contract_address, &provider);

Expand Down
3 changes: 2 additions & 1 deletion examples/contracts/examples/generate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use eyre::Result;

// Codegen from ABI file to interact with the contract.
sol!(
#[allow(missing_docs)]
#[sol(rpc)]
IERC20,
"examples/abi/IERC20.json"
Expand All @@ -13,7 +14,7 @@ sol!(
#[tokio::main]
async fn main() -> Result<()> {
// Spin up a forked Anvil node.
// Ensure `anvil` is available in $PATH
// Ensure `anvil` is available in $PATH.
let anvil = Anvil::new().fork("https://eth.merkle.io").try_spawn()?;

// Create a provider.
Expand Down
4 changes: 3 additions & 1 deletion examples/layers/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
[package]
name = "examples-layers"

publish.workspace = true
version.workspace = true
edition.workspace = true
Expand All @@ -10,6 +9,9 @@ license.workspace = true
homepage.workspace = true
repository.workspace = true

[lints]
workspace = true

[dev-dependencies]
alloy.workspace = true

Expand Down
Loading
Loading