Skip to content

Commit

Permalink
Merge branch 'main' into chore/merge-v0.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
bidzyyys committed Oct 18, 2024
2 parents ca1f26a + 46eabf0 commit b7c64f2
Show file tree
Hide file tree
Showing 59 changed files with 860 additions and 195 deletions.
15 changes: 12 additions & 3 deletions .github/workflows/check-links.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,27 @@ on:
branches: [ main, v* ]

jobs:
check-links:
name: Check Links
check-links-md:
name: Check Markdown Links
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Link Checker
uses: lycheeverse/lychee-action@v1
uses: lycheeverse/lychee-action@v2
with:
args: --no-progress './**/*.md'
fail: true

check-links-adoc:
name: Check AsciiDoc Links
runs-on: ubuntu-latest
# We only run the AsciiDoc link checker on v* branches because:
# 1. The main branch may contain documentation that is not yet published.
if: startsWith(github.ref, 'refs/heads/v') || startsWith(github.base_ref, 'v')
steps:
- uses: actions/checkout@v4

- name: Run linkspector
uses: umbrelladocs/action-linkspector@v1
with:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -110,4 +110,4 @@ jobs:
- name: Checkout Actions Repository
uses: actions/checkout@v4
- name: Check spelling of files in the workspace
uses: crate-ci/typos@v1.24.1
uses: crate-ci/typos@v1.26.0
2 changes: 1 addition & 1 deletion .github/workflows/e2e-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ jobs:

- name: install solc
run: |
curl -LO https://github.com/ethereum/solidity/releases/download/v0.8.21/solc-static-linux
curl -LO https://github.com/ethereum/solidity/releases/download/v0.8.24/solc-static-linux
sudo mv solc-static-linux /usr/bin/solc
sudo chmod a+x /usr/bin/solc
Expand Down
5 changes: 4 additions & 1 deletion .github/workflows/gas-bench.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,12 @@ jobs:
with:
key: "gas-bench"

- name: install cargo-stylus
run: cargo install [email protected]

- name: install solc
run: |
curl -LO https://github.com/ethereum/solidity/releases/download/v0.8.21/solc-static-linux
curl -LO https://github.com/ethereum/solidity/releases/download/v0.8.24/solc-static-linux
sudo mv solc-static-linux /usr/bin/solc
sudo chmod a+x /usr/bin/solc
Expand Down
13 changes: 1 addition & 12 deletions Cargo.lock

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

3 changes: 1 addition & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ resolver = "2"
authors = ["OpenZeppelin"]
edition = "2021"
license = "MIT"
keywords = ["arbitrum", "ethereum", "stylus"]
repository = "https://github.com/OpenZeppelin/rust-contracts-stylus"
version = "0.1.0"

Expand All @@ -64,7 +63,6 @@ all = "warn"
[workspace.dependencies]
# stylus-related
stylus-sdk = { version = "=0.6.0", default-features = false }
stylus-proc = { version = "=0.6.0", default-features = false }
mini-alloc = "0.4.2"

alloy = { version = "=0.1.4", features = [
Expand Down Expand Up @@ -95,6 +93,7 @@ rand = "0.8.5"
regex = "1.10.4"
tiny-keccak = { version = "2.0.2", features = ["keccak"] }
tokio = { version = "1.12.0", features = ["full"] }
futures = "0.3.30"

# procedural macros
syn = { version = "2.0.58", features = ["full"] }
Expand Down
48 changes: 43 additions & 5 deletions GUIDELINES.md
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ Use 1-word names for function parameters or variables that have larger scopes:

```rust
pub fn commit(repo: &Repository, sig: &Signature) -> Result<Commit, Error> {
...
...
}
```

Expand Down Expand Up @@ -207,6 +207,41 @@ Make sure all tests are passing with:

$ cargo test --all-features

### Running end-to-end tests

In order to run end-to-end (e2e) tests you need to have a specific nightly toolchain.
"Nightly" is necessary to use optimization compiler flags and have contract wasm small enough to be eligible for
deployment.

Run the following commands to install the necessary toolchain:

```shell
rustup install nightly-2024-01-01
rustup component add rust-src
```

Also, you should have the cargo stylus tool:

```shell
cargo install cargo-stylus
```

Since most of the e2e tests use [koba](https://github.com/OpenZeppelin/koba) for deploying contracts, you need to
[install](https://docs.soliditylang.org/en/latest/installing-solidity.html#) the solidity compiler (`v0.8.24`).

To run e2e tests, you need to have a local nitro test node up and running.
Run the following command and wait till script exit successfully:

```shell
./scripts/nitro-testnode.sh -i -d
```

Then you will be able to run e2e tests:

```shell
./scripts/e2e-tests.sh
```

### Checking the docs

If you make documentation changes, you may want to check whether there are any
Expand Down Expand Up @@ -279,12 +314,15 @@ conventions that must be followed.
- Custom errors should be declared following the [EIP-6093] rationale whenever
reasonable. Also, consider the following:

- The domain prefix should be picked in the following order:
1. Use `ERC<number>` if the error is a violation of an ERC specification.
2. Use the name of the underlying component where it belongs (eg.
`Governor`, `ECDSA`, or `Timelock`).
- The domain prefix should be picked in the following order:
1. Use `ERC<number>` if the error is a violation of an ERC specification.
2. Use the name of the underlying component where it belongs (eg.
`Governor`, `ECDSA`, or `Timelock`).

[The Rust Style Guide]: https://doc.rust-lang.org/nightly/style-guide/

[EIP-6093]: https://eips.ethereum.org/EIPS/eip-6093

[Semantic versioning]: https://semver.org/spec/v2.0.0.html

[Conventional Commits]: https://www.conventionalcommits.org/en/v1.0.0/
10 changes: 6 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,11 @@
- [Unit] and [integration] test affordances, used in our own tests.

[`openzeppelin-contracts`]: https://github.com/OpenZeppelin/openzeppelin-contracts

[`koba`]: https://github.com/OpenZeppelin/koba

[Unit]: ./lib/motsu/README.md

[integration]: ./lib/e2e/README.md

## Usage
Expand Down Expand Up @@ -50,7 +53,7 @@ sol_storage! {

#[public]
#[inherit(Erc20)]
impl Erc20Example { }
impl Erc20Example {}
```

For a more complex display of what this library offers, refer to our
Expand All @@ -62,8 +65,6 @@ For a full example that includes deploying and querying a contract, see the
For more information on what this library will include in the future, see our
[roadmap].

[specify a git dependency]: https://doc.rust-lang.org/cargo/reference/specifying-dependencies.html#specifying-dependencies-from-git-repositories
[examples]: ./examples
[basic]: ./examples/basic
[roadmap]: https://github.com/OpenZeppelin/rust-contracts-stylus/milestone/2

Expand All @@ -81,4 +82,5 @@ Refer to our [Security Policy](SECURITY.md) for more details.

## License

OpenZeppelin Contracts for Stylus is released under the [MIT License](./LICENSE).
OpenZeppelin Contracts for Stylus is released under
the [MIT License](./LICENSE).
1 change: 1 addition & 0 deletions benches/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ openzeppelin-stylus.workspace = true
alloy-primitives = { workspace = true, features = ["tiny-keccak"] }
alloy.workspace = true
tokio.workspace = true
futures.workspace = true
eyre.workspace = true
koba.workspace = true
e2e.workspace = true
Expand Down
38 changes: 30 additions & 8 deletions benches/src/access_control.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@ use alloy::{
};
use e2e::{receipt, Account};

use crate::report::Report;
use crate::{
report::{ContractReport, FunctionReport},
CacheOpt,
};

sol!(
#[sol(rpc)]
Expand All @@ -33,7 +36,22 @@ const ROLE: [u8; 32] =
const NEW_ADMIN_ROLE: [u8; 32] =
hex!("879ce0d4bfd332649ca3552efe772a38d64a315eb70ab69689fd309c735946b5");

pub async fn bench() -> eyre::Result<Report> {
pub async fn bench() -> eyre::Result<ContractReport> {
let receipts = run_with(CacheOpt::None).await?;
let report = receipts
.into_iter()
.try_fold(ContractReport::new("AccessControl"), ContractReport::add)?;

let cached_receipts = run_with(CacheOpt::Bid(0)).await?;
let report = cached_receipts
.into_iter()
.try_fold(report, ContractReport::add_cached)?;

Ok(report)
}
pub async fn run_with(
cache_opt: CacheOpt,
) -> eyre::Result<Vec<FunctionReport>> {
let alice = Account::new().await?;
let alice_addr = alice.address();
let alice_wallet = ProviderBuilder::new()
Expand All @@ -50,7 +68,8 @@ pub async fn bench() -> eyre::Result<Report> {
.wallet(EthereumWallet::from(bob.signer.clone()))
.on_http(bob.url().parse()?);

let contract_addr = deploy(&alice).await;
let contract_addr = deploy(&alice, cache_opt).await?;

let contract = AccessControl::new(contract_addr, &alice_wallet);
let contract_bob = AccessControl::new(contract_addr, &bob_wallet);

Expand All @@ -66,14 +85,17 @@ pub async fn bench() -> eyre::Result<Report> {
(setRoleAdminCall::SIGNATURE, receipt!(contract.setRoleAdmin(ROLE.into(), NEW_ADMIN_ROLE.into()))?),
];

let report = receipts
receipts
.into_iter()
.try_fold(Report::new("AccessControl"), Report::add)?;
Ok(report)
.map(FunctionReport::new)
.collect::<eyre::Result<Vec<_>>>()
}

async fn deploy(account: &Account) -> Address {
async fn deploy(
account: &Account,
cache_opt: CacheOpt,
) -> eyre::Result<Address> {
let args = AccessControl::constructorCall {};
let args = alloy::hex::encode(args.abi_encode());
crate::deploy(account, "access-control", Some(args)).await
crate::deploy(account, "access-control", Some(args), cache_opt).await
}
Loading

0 comments on commit b7c64f2

Please sign in to comment.