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

ref: Add/Sub Assignment Operations + e2e-tests.sh #467

Merged
merged 24 commits into from
Jan 2, 2025
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
34e8883
docs: add warning to pause/unpause in examples
0xNeshi Dec 26, 2024
cce990b
test: update e2e-tests script
0xNeshi Dec 26, 2024
3054d65
docs: add warning to pause/unpause in erc1155 example
0xNeshi Dec 26, 2024
fff4210
docs: add missing eyre module import in README example
0xNeshi Dec 26, 2024
5fbb8aa
ref: explicitly import eyre::Result in e2e accounts.rs
0xNeshi Dec 26, 2024
3406681
ref: use assign unchecked traits in erc20::update
0xNeshi Dec 26, 2024
75d3e1b
docs: update docs for nonces contract
0xNeshi Dec 26, 2024
a264c90
ref: reuse logic in use_checked_nonce
0xNeshi Dec 26, 2024
84fceef
ref: update AddAssignUnchecked and SubAssignUnchecked to cast values …
0xNeshi Dec 26, 2024
627fd17
chore: add missing PR ids to changelog
0xNeshi Dec 26, 2024
dbfc6cb
docs: add links explaining undefined behavior
0xNeshi Dec 26, 2024
a3d5470
ref: address 'clippy::used_underscore_binding' warnings
0xNeshi Dec 26, 2024
f51bc08
test: simplify e2e-tests.sh
0xNeshi Dec 26, 2024
da89ce4
test: update comments in e2e-tests.sh
0xNeshi Dec 26, 2024
c858b28
docs: Apply comment updates from code review
0xNeshi Dec 27, 2024
fa3956a
docs: change F link to plain code
0xNeshi Dec 27, 2024
33f834e
docs: format in nonces
0xNeshi Dec 27, 2024
59c1ead
Merge branch 'main' into return-res-refactor
bidzyyys Dec 27, 2024
b5e7bec
feat: now panics on exceeding
0xNeshi Dec 30, 2024
ad9732d
docs: align Nonce docs to existing convention
0xNeshi Dec 30, 2024
26f7c59
ci: remove std feature from e2e-tests.sh
0xNeshi Dec 30, 2024
07ebad3
test: remove dir navigation from e2e-tests.sh
0xNeshi Dec 31, 2024
c3a1599
revert: update AddAssignUnchecked and SubAssignUnchecked to cast valu…
0xNeshi Dec 31, 2024
c5c7be5
revert: remove dir navigation from e2e-tests.sh
0xNeshi Dec 31, 2024
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
19 changes: 19 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,25 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]

### Added

-

### Changed

- Refactor how `AddAssignUnchecked` and `SubAssignUnchecked` are used in `Erc20`, `Erc721`, and `Erc721Consecutive`. #467
0xNeshi marked this conversation as resolved.
Show resolved Hide resolved
- Refactor `Nonces`. #467
0xNeshi marked this conversation as resolved.
Show resolved Hide resolved
0xNeshi marked this conversation as resolved.
Show resolved Hide resolved

### Changed (Breaking)

-

### Fixed

-

## [v0.2.0-alpha.2] - 2024-12-18

### Added
Expand Down
11 changes: 6 additions & 5 deletions contracts/src/token/erc20/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@
stylus_proc::{public, SolidityError},
};

use crate::utils::introspection::erc165::{Erc165, IErc165};
use crate::utils::{
introspection::erc165::{Erc165, IErc165},
math::storage::{AddAssignUnchecked, SubAssignUnchecked},
};

pub mod extensions;
pub mod utils;
Expand Down Expand Up @@ -489,17 +492,15 @@
}

if to.is_zero() {
let total_supply = self.total_supply();
// Overflow not possible:
// `value` <= `_total_supply` or
// `value` <= `from_balance` <= `_total_supply`.
self._total_supply.set(total_supply - value);
self._total_supply.sub_assign_unchecked(value);

Check warning on line 498 in contracts/src/token/erc20/mod.rs

View workflow job for this annotation

GitHub Actions / clippy

[clippy] contracts/src/token/erc20/mod.rs#L498

warning: used underscore-prefixed binding --> contracts/src/token/erc20/mod.rs:498:13 | 498 | self._total_supply.sub_assign_unchecked(value); | ^^^^^^^^^^^^^^^^^^ | note: binding is defined here --> contracts/src/token/erc20/mod.rs:133:5 | 133 | pub _total_supply: StorageU256, | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#used_underscore_binding
Raw output
contracts/src/token/erc20/mod.rs:498:13:w:warning: used underscore-prefixed binding
   --> contracts/src/token/erc20/mod.rs:498:13
    |
498 |             self._total_supply.sub_assign_unchecked(value);
    |             ^^^^^^^^^^^^^^^^^^
    |
note: binding is defined here
   --> contracts/src/token/erc20/mod.rs:133:5
    |
133 |     pub _total_supply: StorageU256,
    |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#used_underscore_binding


__END__
} else {
let balance_to = self._balances.get(to);
// Overflow not possible:
// `balance_to` + `value` is at most `total_supply`,
// which fits into a `U256`.
self._balances.setter(to).set(balance_to + value);
self._balances.setter(to).add_assign_unchecked(value);

Check warning on line 503 in contracts/src/token/erc20/mod.rs

View workflow job for this annotation

GitHub Actions / clippy

[clippy] contracts/src/token/erc20/mod.rs#L503

warning: used underscore-prefixed binding --> contracts/src/token/erc20/mod.rs:503:13 | 503 | self._balances.setter(to).add_assign_unchecked(value); | ^^^^^^^^^^^^^^ | note: binding is defined here --> contracts/src/token/erc20/mod.rs:129:5 | 129 | pub _balances: StorageMap<Address, StorageU256>, | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#used_underscore_binding
Raw output
contracts/src/token/erc20/mod.rs:503:13:w:warning: used underscore-prefixed binding
   --> contracts/src/token/erc20/mod.rs:503:13
    |
503 |             self._balances.setter(to).add_assign_unchecked(value);
    |             ^^^^^^^^^^^^^^
    |
note: binding is defined here
   --> contracts/src/token/erc20/mod.rs:129:5
    |
129 |     pub _balances: StorageMap<Address, StorageU256>,
    |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#used_underscore_binding


__END__
}

evm::log(Transfer { from, to, value });
Expand Down
10 changes: 2 additions & 8 deletions contracts/src/token/erc721/extensions/consecutive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -452,17 +452,11 @@
// Clear approval. No need to re-authorize or emit the `Approval`
// event.
self._approve(Address::ZERO, token_id, Address::ZERO, false)?;
self.erc721
._balances
.setter(from)
.sub_assign_unchecked(uint!(1_U256));
self.erc721._balances.setter(from).sub_assign_unchecked(1);

Check warning on line 455 in contracts/src/token/erc721/extensions/consecutive.rs

View workflow job for this annotation

GitHub Actions / clippy

[clippy] contracts/src/token/erc721/extensions/consecutive.rs#L455

warning: used underscore-prefixed binding --> contracts/src/token/erc721/extensions/consecutive.rs:455:13 | 455 | self.erc721._balances.setter(from).sub_assign_unchecked(1); | ^^^^^^^^^^^^^^^^^^^^^ | note: binding is defined here --> contracts/src/token/erc721/mod.rs:202:5 | 202 | pub _balances: StorageMap<Address, StorageU256>, | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#used_underscore_binding
Raw output
contracts/src/token/erc721/extensions/consecutive.rs:455:13:w:warning: used underscore-prefixed binding
   --> contracts/src/token/erc721/extensions/consecutive.rs:455:13
    |
455 |             self.erc721._balances.setter(from).sub_assign_unchecked(1);
    |             ^^^^^^^^^^^^^^^^^^^^^
    |
note: binding is defined here
   --> contracts/src/token/erc721/mod.rs:202:5
    |
202 |     pub _balances: StorageMap<Address, StorageU256>,
    |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#used_underscore_binding


__END__
}

if !to.is_zero() {
self.erc721
._balances
.setter(to)
.add_assign_unchecked(uint!(1_U256));
self.erc721._balances.setter(to).add_assign_unchecked(1);

Check warning on line 459 in contracts/src/token/erc721/extensions/consecutive.rs

View workflow job for this annotation

GitHub Actions / clippy

[clippy] contracts/src/token/erc721/extensions/consecutive.rs#L459

warning: used underscore-prefixed binding --> contracts/src/token/erc721/extensions/consecutive.rs:459:13 | 459 | self.erc721._balances.setter(to).add_assign_unchecked(1); | ^^^^^^^^^^^^^^^^^^^^^ | note: binding is defined here --> contracts/src/token/erc721/mod.rs:202:5 | 202 | pub _balances: StorageMap<Address, StorageU256>, | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#used_underscore_binding
Raw output
contracts/src/token/erc721/extensions/consecutive.rs:459:13:w:warning: used underscore-prefixed binding
   --> contracts/src/token/erc721/extensions/consecutive.rs:459:13
    |
459 |             self.erc721._balances.setter(to).add_assign_unchecked(1);
    |             ^^^^^^^^^^^^^^^^^^^^^
    |
note: binding is defined here
   --> contracts/src/token/erc721/mod.rs:202:5
    |
202 |     pub _balances: StorageMap<Address, StorageU256>,
    |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#used_underscore_binding


__END__
}

self.erc721._owners.setter(token_id).set(to);
Expand Down
8 changes: 4 additions & 4 deletions contracts/src/token/erc721/mod.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//! Implementation of the [`Erc721`] token standard.
use alloc::vec;

use alloy_primitives::{uint, Address, FixedBytes, U128, U256};
use alloy_primitives::{Address, FixedBytes, U128, U256};
use openzeppelin_stylus_proc::interface_id;
use stylus_sdk::{
abi::Bytes,
Expand Down Expand Up @@ -688,7 +688,7 @@
/// * `account` - Account to increase balance.
/// * `value` - The number of tokens to increase balance.
pub fn _increase_balance(&mut self, account: Address, value: U128) {
self._balances.setter(account).add_assign_unchecked(U256::from(value));
self._balances.setter(account).add_assign_unchecked(value);

Check warning on line 691 in contracts/src/token/erc721/mod.rs

View workflow job for this annotation

GitHub Actions / clippy

[clippy] contracts/src/token/erc721/mod.rs#L691

warning: used underscore-prefixed binding --> contracts/src/token/erc721/mod.rs:691:9 | 691 | self._balances.setter(account).add_assign_unchecked(value); | ^^^^^^^^^^^^^^ | note: binding is defined here --> contracts/src/token/erc721/mod.rs:202:5 | 202 | pub _balances: StorageMap<Address, StorageU256>, | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#used_underscore_binding
Raw output
contracts/src/token/erc721/mod.rs:691:9:w:warning: used underscore-prefixed binding
   --> contracts/src/token/erc721/mod.rs:691:9
    |
691 |         self._balances.setter(account).add_assign_unchecked(value);
    |         ^^^^^^^^^^^^^^
    |
note: binding is defined here
   --> contracts/src/token/erc721/mod.rs:202:5
    |
202 |     pub _balances: StorageMap<Address, StorageU256>,
    |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#used_underscore_binding


__END__
}

/// Transfers `token_id` from its current owner to `to`, or alternatively
Expand Down Expand Up @@ -738,11 +738,11 @@
// Clear approval. No need to re-authorize or emit the `Approval`
// event.
self._approve(Address::ZERO, token_id, Address::ZERO, false)?;
self._balances.setter(from).sub_assign_unchecked(uint!(1_U256));
self._balances.setter(from).sub_assign_unchecked(1);

Check warning on line 741 in contracts/src/token/erc721/mod.rs

View workflow job for this annotation

GitHub Actions / clippy

[clippy] contracts/src/token/erc721/mod.rs#L741

warning: used underscore-prefixed binding --> contracts/src/token/erc721/mod.rs:741:13 | 741 | self._balances.setter(from).sub_assign_unchecked(1); | ^^^^^^^^^^^^^^ | note: binding is defined here --> contracts/src/token/erc721/mod.rs:202:5 | 202 | pub _balances: StorageMap<Address, StorageU256>, | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#used_underscore_binding
Raw output
contracts/src/token/erc721/mod.rs:741:13:w:warning: used underscore-prefixed binding
   --> contracts/src/token/erc721/mod.rs:741:13
    |
741 |             self._balances.setter(from).sub_assign_unchecked(1);
    |             ^^^^^^^^^^^^^^
    |
note: binding is defined here
   --> contracts/src/token/erc721/mod.rs:202:5
    |
202 |     pub _balances: StorageMap<Address, StorageU256>,
    |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#used_underscore_binding


__END__
}

if !to.is_zero() {
self._balances.setter(to).add_assign_unchecked(uint!(1_U256));
self._balances.setter(to).add_assign_unchecked(1);

Check warning on line 745 in contracts/src/token/erc721/mod.rs

View workflow job for this annotation

GitHub Actions / clippy

[clippy] contracts/src/token/erc721/mod.rs#L745

warning: used underscore-prefixed binding --> contracts/src/token/erc721/mod.rs:745:13 | 745 | self._balances.setter(to).add_assign_unchecked(1); | ^^^^^^^^^^^^^^ | note: binding is defined here --> contracts/src/token/erc721/mod.rs:202:5 | 202 | pub _balances: StorageMap<Address, StorageU256>, | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#used_underscore_binding
Raw output
contracts/src/token/erc721/mod.rs:745:13:w:warning: used underscore-prefixed binding
   --> contracts/src/token/erc721/mod.rs:745:13
    |
745 |             self._balances.setter(to).add_assign_unchecked(1);
    |             ^^^^^^^^^^^^^^
    |
note: binding is defined here
   --> contracts/src/token/erc721/mod.rs:202:5
    |
202 |     pub _balances: StorageMap<Address, StorageU256>,
    |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#used_underscore_binding


__END__
}

self._owners.setter(token_id).set(to);
Expand Down
18 changes: 11 additions & 7 deletions contracts/src/utils/math/storage.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//! Simple math operations missing in `stylus_sdk::storage`.
use alloy_primitives::Uint;
use alloy_primitives::{ruint::UintTryFrom, Uint};
use stylus_sdk::storage::StorageUint;

/// Adds value and assign the result to `self`, ignoring overflow.
Expand All @@ -8,11 +8,13 @@ pub(crate) trait AddAssignUnchecked<T> {
fn add_assign_unchecked(&mut self, rhs: T);
}

impl<const B: usize, const L: usize> AddAssignUnchecked<Uint<B, L>>
impl<T, const B: usize, const L: usize> AddAssignUnchecked<T>
for StorageUint<B, L>
where
Uint<B, L>: UintTryFrom<T>,
{
fn add_assign_unchecked(&mut self, rhs: Uint<B, L>) {
let new_balance = self.get() + rhs;
fn add_assign_unchecked(&mut self, rhs: T) {
let new_balance = self.get() + Uint::<B, L>::from(rhs);
0xNeshi marked this conversation as resolved.
Show resolved Hide resolved
self.set(new_balance);
}
}
Expand All @@ -23,11 +25,13 @@ pub(crate) trait SubAssignUnchecked<T> {
fn sub_assign_unchecked(&mut self, rhs: T);
}

impl<const B: usize, const L: usize> SubAssignUnchecked<Uint<B, L>>
impl<T, const B: usize, const L: usize> SubAssignUnchecked<T>
for StorageUint<B, L>
where
Uint<B, L>: UintTryFrom<T>,
{
fn sub_assign_unchecked(&mut self, rhs: Uint<B, L>) {
let new_balance = self.get() - rhs;
fn sub_assign_unchecked(&mut self, rhs: T) {
let new_balance = self.get() - Uint::<B, L>::from(rhs);
self.set(new_balance);
}
}
30 changes: 15 additions & 15 deletions contracts/src/utils/nonces.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ mod sol {
/// The nonce used for an `account` is not the expected current nonce.
#[derive(Debug)]
#[allow(missing_docs)]
error InvalidAccountNonce(address account, uint256 currentNonce);
error InvalidAccountNonce(address account, uint256 current_nonce);
}
}

Expand Down Expand Up @@ -60,13 +60,17 @@ impl Nonces {
/// * `&mut self` - Write access to the contract's state.
/// * `owner` - The address for which to consume the nonce.
///
/// # Panics
/// # Safety
///
/// This function will panic if the nonce for the given `owner` has reached
/// the maximum value representable by `U256`, causing the `checked_add`
/// method to return `None`.
/// the function will experience **undefined behavior**, if the nonce for
/// the given `owner` has reached the maximum value representable by `U256`.
/// Extreme caution should be taken to ensure overflow cannot occur.
pub fn use_nonce(&mut self, owner: Address) -> U256 {
let nonce = self._nonces.get(owner);

// For each account, the nonce has an initial value of 0, can only be
0xNeshi marked this conversation as resolved.
Show resolved Hide resolved
// incremented by one, and cannot be decremented or reset. This
// guarantees that the nonce never overflows.
0xNeshi marked this conversation as resolved.
Show resolved Hide resolved
self._nonces
.setter(owner)
.set(unsafe { nonce.checked_add(ONE).unwrap_unchecked() });
0xNeshi marked this conversation as resolved.
Show resolved Hide resolved
Expand All @@ -83,11 +87,11 @@ impl Nonces {
/// * `owner` - The address for which to consume the nonce.
/// * `nonce` - The nonce to consume.
///
/// # Panics
/// # Safety
///
/// This function will panic if the nonce for the given `owner` has reached
/// the maximum value representable by `U256`, causing the `checked_add`
/// method to return `None`.
/// the function will experience **undefined behavior**, if the nonce for
/// the given `owner` has reached the maximum value representable by `U256`.
/// Extreme caution should be taken to ensure overflow cannot occur.
///
/// # Errors
///
Expand All @@ -98,19 +102,15 @@ impl Nonces {
owner: Address,
nonce: U256,
) -> Result<(), Error> {
let current_nonce = self._nonces.get(owner);
let current_nonce = self.use_nonce(owner);

if nonce != current_nonce {
return Err(Error::InvalidAccountNonce(InvalidAccountNonce {
account: owner,
currentNonce: current_nonce,
current_nonce,
}));
}

self._nonces
.setter(owner)
.set(unsafe { nonce.checked_add(ONE).unwrap_unchecked() });

Ok(())
}
}
Expand Down
4 changes: 4 additions & 0 deletions examples/erc1155/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,10 @@ impl Erc1155Example {
Erc1155::supports_interface(interface_id)
}

/// WARNING: These functions are intended for **testing purposes** only. In
/// **production**, ensure strict access control to prevent unauthorized
/// pausing or unpausing, which can disrupt contract functionality. Remove
/// or secure these functions before deployment.
fn pause(&mut self) -> Result<(), Vec<u8>> {
self.pausable.pause().map_err(|e| e.into())
}
Expand Down
4 changes: 4 additions & 0 deletions examples/erc20/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,10 @@ impl Erc20Example {
|| Erc20Metadata::supports_interface(interface_id)
}

/// WARNING: These functions are intended for **testing purposes** only. In
0xNeshi marked this conversation as resolved.
Show resolved Hide resolved
/// **production**, ensure strict access control to prevent unauthorized
/// pausing or unpausing, which can disrupt contract functionality. Remove
/// or secure these functions before deployment.
pub fn pause(&mut self) -> Result<(), Vec<u8>> {
self.pausable.pause().map_err(|e| e.into())
}
Expand Down
4 changes: 4 additions & 0 deletions examples/erc721/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,10 @@ impl Erc721Example {
|| Enumerable::supports_interface(interface_id)
}

/// WARNING: These functions are intended for **testing purposes** only. In
/// **production**, ensure strict access control to prevent unauthorized
/// pausing or unpausing, which can disrupt contract functionality. Remove
/// or secure these functions before deployment.
pub fn pause(&mut self) -> Result<(), Vec<u8>> {
self.pausable.pause().map_err(|e| e.into())
}
Expand Down
2 changes: 1 addition & 1 deletion lib/e2e/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ Then altogether, your first test case can look like this:
sol!("src/constructor.sol")
#[e2e::test]
async fn constructs(alice: Account) -> Result<()> {
async fn constructs(alice: Account) -> eyre::Result<()> {
let ctr = Example::constructorCall {
name_: "Token".to_owned(),
symbol_: "TKN".to_owned(),
Expand Down
3 changes: 1 addition & 2 deletions lib/e2e/src/account.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ use alloy::{
providers::{Provider, ProviderBuilder},
signers::{local::PrivateKeySigner, Signature, Signer},
};
use eyre::Result;
use once_cell::sync::Lazy;
use tokio::sync::{Mutex, MutexGuard};

Expand All @@ -30,7 +29,7 @@ impl Account {
/// # Errors
///
/// May fail if funding the newly created account fails.
pub async fn new() -> Result<Self> {
pub async fn new() -> eyre::Result<Self> {
AccountFactory::create().await
}

Expand Down
31 changes: 26 additions & 5 deletions scripts/e2e-tests.sh
Original file line number Diff line number Diff line change
@@ -1,14 +1,35 @@
#!/bin/bash
set -e

TEST_ARG="${1:-*}"
# Default test file or wildcard
TEST_ARG="*"
CARGO_TEST_FLAGS=""
TEST_BINARY_ARGS=""

MYDIR=$(realpath "$(dirname "$0")")
cd "$MYDIR"
cd ..
# Parse arguments
for arg in "$@"; do
if [[ "$arg" == "--" ]]; then
# Everything after `--` goes to the test binary
shift
TEST_BINARY_ARGS="$@"
break
elif [[ "$arg" == -* ]]; then
# Capture cargo test flags (e.g., --exclude, --no-run)
CARGO_TEST_FLAGS="$CARGO_TEST_FLAGS $arg"
else
# Set the test file (first positional argument)
TEST_ARG="$arg"
fi
done

# Move to project root
cd "$(dirname "$(realpath "$0")")/.."
0xNeshi marked this conversation as resolved.
Show resolved Hide resolved

# Build the project
cargo build --release --target wasm32-unknown-unknown -Z build-std=std,panic_abort -Z build-std-features=panic_immediate_abort

# Set RPC_URL environment variable
export RPC_URL=http://localhost:8547

cargo test --features std,e2e --test "$TEST_ARG"
# Run the tests with cargo test flags and test binary arguments
cargo test --features std,e2e --test "$TEST_ARG" $CARGO_TEST_FLAGS -- $TEST_BINARY_ARGS
Loading