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: turn contracts into a crate #6

Merged
merged 3 commits into from
Mar 25, 2024
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
85 changes: 39 additions & 46 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[workspace]
members = ["contracts/*", "lib/*"]
members = ["contracts", "lib/*"]
# Explicitly set the resolver to version 2, which is the default for packages
# with edition >= 2021.
# https://doc.rust-lang.org/edition-guide/rust-2021/default-cargo-resolver.html
Expand Down
8 changes: 5 additions & 3 deletions contracts/token/Cargo.toml → contracts/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
[package]
name = "token"
# TODO: Figure out public name before v0.1.0 release.
name = "contracts"
qalisander marked this conversation as resolved.
Show resolved Hide resolved
categories = ["no-std", "wasm"]
description = "Token Standards for Stylus"
description = "Contracts for Stylus"
edition.workspace = true
keywords.workspace = true
license.workspace = true
Expand All @@ -16,11 +17,12 @@ stylus-proc = { version = "0.4.3", default-features = false }
mini-alloc = "0.4.2"

[dev-dependencies]
test-utils = { path = "../test-utils" }
wavm-shims = { path = "../lib/wavm-shims" }

[features]
default = []
erc20 = []
erc721 = []

[lib]
# The Stylus team sets new crates with the following types:
Expand Down
1 change: 1 addition & 0 deletions contracts/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Contracts
Original file line number Diff line number Diff line change
Expand Up @@ -348,10 +348,10 @@ mod tests {
msg,
storage::{StorageMap, StorageType, StorageU256},
};
#[allow(unused_imports)]
use test_utils::*;

use crate::erc20::{Error, ERC20};
#[allow(unused_imports)]
use crate::test_utils;
qalisander marked this conversation as resolved.
Show resolved Hide resolved

impl Default for ERC20 {
fn default() -> Self {
Expand Down
1 change: 1 addition & 0 deletions contracts/src/erc721/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

9 changes: 8 additions & 1 deletion contracts/token/src/lib.rs → contracts/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#![doc = include_str!("../README.md")]
#![doc = include_str!("../../README.md")]
#![warn(missing_docs, unreachable_pub, rust_2021_compatibility)]
#![warn(clippy::all, clippy::pedantic)]
#![cfg_attr(not(test), no_std, no_main)]
Expand All @@ -9,6 +9,13 @@ static ALLOC: mini_alloc::MiniAlloc = mini_alloc::MiniAlloc::INIT;

#[cfg(any(test, erc20))]
pub mod erc20;
#[cfg(any(test, erc721))]
pub mod erc721;
#[cfg(test)]
mod test_utils;

qalisander marked this conversation as resolved.
Show resolved Hide resolved
#[cfg(test)]
extern crate std;

#[cfg(not(any(test, target_arch = "wasm32-unknown-unknown")))]
#[panic_handler]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//! Unit-testing utilities for Stylus contracts.
use std::sync::{Mutex, MutexGuard};

pub use wavm_shims::*;
pub(crate) use wavm_shims::*;

/// A global static mutex.
///
Expand All @@ -10,15 +10,15 @@ pub use wavm_shims::*;
/// accesses storage in an non-overlapping manner.
///
/// See [`with_storage`].
pub static STORAGE_MUTEX: Mutex<()> = Mutex::new(());
pub(crate) static STORAGE_MUTEX: Mutex<()> = Mutex::new(());

/// Acquires access to storage.
pub fn acquire_storage() -> MutexGuard<'static, ()> {
pub(crate) fn acquire_storage() -> MutexGuard<'static, ()> {
STORAGE_MUTEX.lock().unwrap()
}

/// Decorates a closure by running it with exclusive access to storage.
pub fn with_storage<C: Default>(closure: impl FnOnce(&mut C)) {
pub(crate) fn with_storage<C: Default>(closure: impl FnOnce(&mut C)) {
let _lock = acquire_storage();
let mut contract = C::default();
closure(&mut contract);
Expand Down
12 changes: 0 additions & 12 deletions contracts/test-utils/Cargo.toml

This file was deleted.

Loading
Loading