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

feat(test): migrate unit tests to the new motsu layout #423

Draft
wants to merge 89 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
89 commits
Select commit Hold shift + click to select a range
64cb1ec
add storage guard
qalisander Oct 17, 2024
e2fafe8
comment non erc721 unit test
qalisander Nov 21, 2024
02d3468
++
qalisander Nov 22, 2024
d126f0e
++
qalisander Nov 22, 2024
ef905e5
++
qalisander Nov 22, 2024
7883a64
add ping pong test case
qalisander Nov 22, 2024
f49daf5
add test router
qalisander Nov 22, 2024
1dc7519
add call shim
qalisander Nov 22, 2024
092a370
++
qalisander Nov 22, 2024
e5028fc
add msg::value
qalisander Nov 22, 2024
c03429d
fix deadlock
qalisander Nov 22, 2024
0c5ac77
ping pong works
qalisander Nov 22, 2024
924e72e
++
qalisander Nov 22, 2024
59cc1a2
++
qalisander Nov 22, 2024
110d340
++
qalisander Nov 22, 2024
aa577f2
++
qalisander Nov 22, 2024
01401e8
comment erc721 tests
qalisander Nov 23, 2024
0cd4299
add erc721 receiver test
qalisander Nov 23, 2024
2b944ce
use contract wrapper in motsu params
qalisander Nov 28, 2024
0aaa81e
add msg sender mock
qalisander Nov 28, 2024
b920606
Merge remote-tracking branch 'origin/main' into unit-tests/multiple-c…
qalisander Nov 28, 2024
33454f6
++
qalisander Nov 28, 2024
299ecc4
++
qalisander Nov 29, 2024
acc631f
Merge remote-tracking branch 'origin/main' into unit-tests/multiple-c…
qalisander Dec 2, 2024
4a747f1
comment test not ported test cases
qalisander Dec 2, 2024
73c5792
remove motsu from default members, since we're going to split this li…
qalisander Dec 2, 2024
abfbbb9
have cargo hack just for contracts
qalisander Dec 2, 2024
f4a74c5
++
qalisander Dec 2, 2024
2b688ce
build: bump Stylus SDK and alloy versions
bidzyyys Nov 29, 2024
ddef560
fix: move const value in AccessControl
bidzyyys Nov 29, 2024
1d27f6c
ref: move interfaces to base modules
bidzyyys Dec 2, 2024
c3cc640
ref: fix AccessControl example
bidzyyys Dec 2, 2024
e0e71ba
fix: add missing Vec imports
bidzyyys Dec 2, 2024
b24bcdf
build: use koba with updated alloy
bidzyyys Dec 4, 2024
0f40dc4
build: update E2E crate with new alloy
bidzyyys Dec 3, 2024
3c909bf
ref: extract v as u8 from Signature
bidzyyys Dec 3, 2024
1acaa4c
fix: use proper data type for U96
bidzyyys Dec 3, 2024
fa476f1
fix: benches
bidzyyys Dec 3, 2024
1078a12
fix: constrain storage ints
bidzyyys Dec 4, 2024
a9c3fbe
build: update koba to v0.3.0
bidzyyys Dec 5, 2024
94cb034
remove not used Provider
qalisander Dec 6, 2024
06945d6
add stylus-sdk patch for external calls
qalisander Dec 6, 2024
3a6e6bd
retrieve tx hashes for block timestamp
qalisander Dec 7, 2024
d33bdc3
fix run_check_release test for vesting_wallet
qalisander Dec 7, 2024
a580f98
Merge remote-tracking branch 'origin/main' into build/stylus-v0.7.0-b…
qalisander Dec 7, 2024
eb5cc95
update alloy to 0.8.14
qalisander Dec 9, 2024
378da95
Merge remote-tracking branch 'origin/main' into build/stylus-v0.7.0-b…
qalisander Dec 10, 2024
e7d074f
Merge remote-tracking branch 'origin/main' into build/stylus-v0.7.0-b…
qalisander Dec 11, 2024
c255a90
++
qalisander Dec 11, 2024
f8b7645
import alloc::vec::Vec for permit
qalisander Dec 11, 2024
0f2a246
remove unused code
qalisander Dec 11, 2024
a5d40c1
Merge remote-tracking branch 'origin/main' into unit-tests/multiple-c…
qalisander Dec 11, 2024
843ded7
Merge branch 'build/stylus-v0.7.0-beta.1' into unit-tests/multiple-co…
qalisander Dec 11, 2024
f27aed9
++
qalisander Dec 11, 2024
f0f94ac
++
qalisander Dec 11, 2024
32ad8fd
test ping_pong_works pass with msg::sender()
qalisander Dec 11, 2024
0b31370
remove context msg_sender
qalisander Dec 11, 2024
74b4672
Merge remote-tracking branch 'origin/main' into build/stylus-v0.7.0-b…
qalisander Dec 13, 2024
b6898fc
post merge fix
qalisander Dec 13, 2024
a16de97
++
qalisander Dec 13, 2024
acd843a
++
qalisander Dec 13, 2024
47a3aa3
Merge branch 'build/stylus-v0.7.0-beta.1' into unit-tests/multiple-co…
qalisander Dec 13, 2024
9a84c14
post merge fix
qalisander Dec 13, 2024
ed41209
alloy-primitives 0.8.14 -> 0.8.13
qalisander Dec 18, 2024
780c6ec
++
qalisander Dec 23, 2024
1487ee0
Merge branch 'unit-tests/multiple-contract-deployment-v0.7.0-beta' in…
qalisander Dec 23, 2024
4c3366a
Merge remote-tracking branch 'origin/main' into unit-tests/multiple-c…
qalisander Dec 23, 2024
297b574
patch motsu
qalisander Dec 23, 2024
267289c
++
qalisander Dec 31, 2024
6f71be6
++
qalisander Dec 31, 2024
425cf63
++
qalisander Dec 31, 2024
0ecc2a3
++
qalisander Dec 31, 2024
7ee9dc1
++
qalisander Dec 31, 2024
6e3bf2b
++
qalisander Dec 31, 2024
c302a60
++
qalisander Dec 31, 2024
4b135dd
erc721 uri storage tests
qalisander Jan 6, 2025
c455196
erc20 tests
qalisander Jan 7, 2025
0ac0b28
bump stylus sdk v0.7.0
qalisander Jan 7, 2025
e8fd4aa
Merge remote-tracking branch 'origin/main' into unit-tests/multiple-c…
qalisander Jan 15, 2025
2d29ce0
++
qalisander Jan 15, 2025
7b39a37
++
qalisander Jan 15, 2025
5c0ef1a
++
qalisander Jan 15, 2025
f6c71b5
++
qalisander Jan 15, 2025
00b1fce
Merge remote-tracking branch 'origin/main' into unit-tests/multiple-c…
qalisander Jan 15, 2025
2b042a7
++
qalisander Jan 16, 2025
1aba40b
++
qalisander Jan 16, 2025
eedad10
++
qalisander Jan 16, 2025
75176c3
++
qalisander Jan 16, 2025
09944a7
++
qalisander Jan 16, 2025
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
Next Next commit
add storage guard
  • Loading branch information
qalisander committed Nov 21, 2024
commit 64cb1ec8b03da5f1816864565b8698ecb54c0cb2
31 changes: 30 additions & 1 deletion Cargo.lock

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

10 changes: 5 additions & 5 deletions contracts/src/token/erc721/extensions/enumerable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -454,7 +454,7 @@ mod tests {
assert_eq!(owner, alice);

let res =
contract._add_token_to_owner_enumeration(alice, token_id, &erc721);
contract._add_token_to_owner_enumeration(alice, token_id, &*erc721);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need additional *?

assert!(res.is_ok());

let test_token_id = contract
Expand Down Expand Up @@ -483,7 +483,7 @@ mod tests {
assert_eq!(owner, alice);

let res =
contract._add_token_to_owner_enumeration(alice, token_id, &erc721);
contract._add_token_to_owner_enumeration(alice, token_id, &*erc721);
assert!(res.is_ok());

let err =
Expand Down Expand Up @@ -525,7 +525,7 @@ mod tests {
assert_eq!(owner, alice);

let res =
contract._add_token_to_owner_enumeration(alice, token_id, &erc721);
contract._add_token_to_owner_enumeration(alice, token_id, &*erc721);
assert!(res.is_ok());

// Transfer the token from ALICE to BOB.
Expand All @@ -538,11 +538,11 @@ mod tests {
assert_eq!(owner, BOB);

let res = contract
._remove_token_from_owner_enumeration(alice, token_id, &erc721);
._remove_token_from_owner_enumeration(alice, token_id, &*erc721);
assert!(res.is_ok());

let res =
contract._add_token_to_owner_enumeration(BOB, token_id, &erc721);
contract._add_token_to_owner_enumeration(BOB, token_id, &*erc721);
assert!(res.is_ok());

let test_token_id = contract
Expand Down
6 changes: 4 additions & 2 deletions lib/motsu-proc/src/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ pub(crate) fn test(_attr: &TokenStream, input: TokenStream) -> TokenStream {
let sig = &item_fn.sig;
let fn_name = &sig.ident;
let fn_return_type = &sig.output;
let fn_block = &item_fn.block;
let fn_stmts = &item_fn.block.stmts;
let fn_args = &sig.inputs;

// Currently, more than one contract per unit test is not supported.
Expand Down Expand Up @@ -45,7 +45,9 @@ pub(crate) fn test(_attr: &TokenStream, input: TokenStream) -> TokenStream {
fn #fn_name() #fn_return_type {
use ::motsu::prelude::DefaultStorage;
#( #contract_declarations )*
let res = #fn_block;
let res = {
#( #fn_stmts )*
};
::motsu::prelude::Context::current().reset_storage();
res
}
Expand Down
1 change: 1 addition & 0 deletions lib/motsu/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ tiny-keccak.workspace = true
stylus-sdk.workspace = true
motsu-proc.workspace = true
dashmap.workspace = true
derive_more = { version = "1.0.0", features = ["full"] }

[lints]
workspace = true
15 changes: 12 additions & 3 deletions lib/motsu/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,13 @@ use std::{collections::HashMap, ptr};

use dashmap::DashMap;
use once_cell::sync::Lazy;
use stylus_sdk::{alloy_primitives::uint, prelude::StorageType};
use stylus_sdk::{
alloy_primitives::{
private::derive_more::{Deref, DerefMut},
uint,
},
prelude::StorageType,
};

use crate::prelude::{Bytes32, WORD_BYTES};

Expand Down Expand Up @@ -101,9 +107,12 @@ pub trait DefaultStorage: StorageType {
/// Initializes fields of contract storage and child contract storages with
/// default values.
#[must_use]
fn default() -> Self {
unsafe { Self::new(uint!(0_U256), 0) }
fn default() -> StorageGuard<Self> {
StorageGuard(unsafe { Self::new(uint!(0_U256), 0) })
}
}

impl<ST: StorageType> DefaultStorage for ST {}

#[derive(Deref, DerefMut)]
pub struct StorageGuard<ST: StorageType>(ST);