Skip to content

Commit

Permalink
ref: unpack Result from watch! macro
Browse files Browse the repository at this point in the history
  • Loading branch information
bidzyyys committed Feb 6, 2025
1 parent 6f0b193 commit 62499de
Show file tree
Hide file tree
Showing 24 changed files with 338 additions and 331 deletions.
6 changes: 3 additions & 3 deletions benches/src/erc721.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,9 @@ pub async fn run(cache_opt: Opt) -> eyre::Result<Vec<FunctionReport>> {
let token_3 = uint!(3_U256);
let token_4 = uint!(4_U256);

let _ = receipt!(contract.mint(alice_addr, token_2))?;
let _ = receipt!(contract.mint(alice_addr, token_3))?;
let _ = receipt!(contract.mint(alice_addr, token_4))?;
_ = receipt!(contract.mint(alice_addr, token_2))?;
_ = receipt!(contract.mint(alice_addr, token_3))?;
_ = receipt!(contract.mint(alice_addr, token_4))?;

// IMPORTANT: Order matters!
use Erc721::*;
Expand Down
2 changes: 1 addition & 1 deletion benches/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ fn cache_contract(
) -> eyre::Result<()> {
// We don't need a status code.
// Since it is not zero when the contract is already cached.
let _ = Command::new("cargo")
_ = Command::new("cargo")
.args(["stylus", "cache", "bid"])
.args(["-e", &env("RPC_URL")?])
.args(["--private-key", &format!("0x{}", account.pk())])
Expand Down
4 changes: 2 additions & 2 deletions benches/src/vesting_wallet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ pub async fn run(cache_opt: Opt) -> eyre::Result<Vec<FunctionReport>> {
let contract = VestingWallet::new(contract_addr, &alice_wallet);
let erc20 = Erc20::new(erc20_addr, &alice_wallet);

let _ = receipt!(contract.receiveEther().value(uint!(1000_U256)))?;
let _ = receipt!(erc20.mint(contract_addr, uint!(1000_U256)))?;
_ = receipt!(contract.receiveEther().value(uint!(1000_U256)))?;
_ = receipt!(erc20.mint(contract_addr, uint!(1000_U256)))?;

// IMPORTANT: Order matters!
use VestingWallet::*;
Expand Down
2 changes: 1 addition & 1 deletion contracts/src/access/ownable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ mod tests {
) {
contract.init(alice, |contract| contract._owner.set(alice));

let _ = contract.sender(alice).renounce_ownership();
_ = contract.sender(alice).renounce_ownership();
let owner = contract.sender(alice).owner();
assert_eq!(owner, Address::ZERO);
}
Expand Down
5 changes: 2 additions & 3 deletions contracts/src/token/erc1155/extensions/supply.rs
Original file line number Diff line number Diff line change
Expand Up @@ -476,8 +476,7 @@ mod tests {
.sender(alice)
._mint(dave, token_id, U256::MAX / two, &vec![].into())
.expect("should mint to dave");
let _ =
contract.sender(alice)._mint(bob, token_id, three, &vec![].into());
_ = contract.sender(alice)._mint(bob, token_id, three, &vec![].into());
}

#[motsu::test]
Expand All @@ -492,7 +491,7 @@ mod tests {
.sender(alice)
._mint(bob, token_ids[0], U256::MAX, &vec![].into())
.expect("should mint");
let _ = contract.sender(alice)._mint(
_ = contract.sender(alice)._mint(
bob,
token_ids[1],
U256::from(1),
Expand Down
1 change: 1 addition & 0 deletions contracts/src/token/erc1155/extensions/uri_storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ mod tests {
assert_eq!(uri, contract.sender(alice).uri(TOKEN_ID));
}

#[motsu::test]
fn uri_returns_empty_string_when_no_uri_is_set(
contract: Contract<Erc1155MetadataExample>,
alice: Address,
Expand Down
2 changes: 1 addition & 1 deletion contracts/src/token/erc20/extensions/erc4626.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1148,7 +1148,7 @@ impl Erc4626 {
mod tests {
use alloy_primitives::{address, Address, U256, U8};
use motsu::prelude::Contract;
use stylus_sdk::{msg, prelude::*};
use stylus_sdk::prelude::*;

use super::{Erc4626, IErc4626};
use crate::token::erc20::Erc20;
Expand Down
4 changes: 2 additions & 2 deletions contracts/src/token/erc20/extensions/flash_mint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -337,8 +337,8 @@ impl IErc3156FlashLender for Erc20FlashMint {

#[cfg(all(test, feature = "std"))]
mod tests {
use alloy_primitives::{address, uint, Address, U256};
use motsu::prelude::{Account, Contract};
use alloy_primitives::{uint, Address, U256};
use motsu::prelude::Contract;
use stylus_sdk::{abi::Bytes, msg, prelude::*};

use super::{
Expand Down
6 changes: 3 additions & 3 deletions contracts/src/token/erc721/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2692,10 +2692,10 @@ mod tests {
#[selector(name = "onERC721Received")]
fn on_erc721_received(
&mut self,
operator: Address,
from: Address,
_operator: Address,
_from: Address,
token_id: U256,
data: Bytes,
_data: Bytes,
) -> FixedBytes<4> {
self._received_token_id.set(token_id);
fixed_bytes!("150b7a02")
Expand Down
4 changes: 2 additions & 2 deletions contracts/src/utils/math/alloy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ mod tests {
#[should_panic = "division by U256::ZERO in `Math::mul_div`"]
fn check_mul_div_panics_when_denominator_is_zero() {
proptest!(|(x: U256, y: U256)| {
let _ = x.mul_div(y, U256::ZERO, Rounding::Floor);
_ = x.mul_div(y, U256::ZERO, Rounding::Floor);
})
}

Expand All @@ -261,7 +261,7 @@ mod tests {
proptest!(|(x: U256, y: U256)| {
prop_assume!(x != U256::ZERO, "Guaranteed `x` for overflow.");
prop_assume!(y > U256::MAX / x, "Guaranteed `y` for overflow.");
let _ = x.mul_div(y, U256::from(1), Rounding::Floor);
_ = x.mul_div(y, U256::from(1), Rounding::Floor);
})
}
}
18 changes: 9 additions & 9 deletions examples/access-control/tests/access_control.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ async fn admin_can_revoke_role(alice: Account, bob: Account) -> Result<()> {
let alice_addr = alice.address();
let bob_addr = bob.address();

let _ = watch!(contract.grantRole(ROLE.into(), bob_addr))?;
_ = watch!(contract.grantRole(ROLE.into(), bob_addr))?;

let receipt = receipt!(contract.revokeRole(ROLE.into(), bob_addr))?;
assert!(receipt.emits(RoleRevoked {
Expand All @@ -167,7 +167,7 @@ async fn error_when_non_admin_revokes_role(
let alice_addr = alice.address();
let bob_addr = bob.address();

let _ = watch!(contract.grantRole(ROLE.into(), alice_addr))?;
_ = watch!(contract.grantRole(ROLE.into(), alice_addr))?;

let contract = AccessControl::new(contract_addr, &bob.wallet);
let err = send!(contract.revokeRole(ROLE.into(), alice_addr))
Expand All @@ -191,7 +191,7 @@ async fn roles_can_be_revoked_multiple_times(
let alice_addr = alice.address();
let bob_addr = bob.address();

let _ = watch!(contract.revokeRole(ROLE.into(), bob_addr))?;
_ = watch!(contract.revokeRole(ROLE.into(), bob_addr))?;
let receipt = receipt!(contract.revokeRole(ROLE.into(), bob_addr))?;
assert!(!receipt.emits(RoleRevoked {
role: ROLE.into(),
Expand Down Expand Up @@ -224,7 +224,7 @@ async fn bearer_can_renounce_role(alice: Account, bob: Account) -> Result<()> {
let contract_addr = alice.as_deployer().deploy().await?.address()?;
let contract = AccessControl::new(contract_addr, &alice.wallet);

let _ = watch!(contract.grantRole(ROLE.into(), bob_addr))?;
_ = watch!(contract.grantRole(ROLE.into(), bob_addr))?;

let contract = AccessControl::new(contract_addr, &bob.wallet);
let receipt = receipt!(contract.renounceRole(ROLE.into(), bob_addr))?;
Expand All @@ -248,7 +248,7 @@ async fn error_when_the_one_renouncing_is_not_the_sender(
let alice_addr = alice.address();
let bob_addr = bob.address();

let _ = watch!(contract.grantRole(ROLE.into(), bob_addr))?;
_ = watch!(contract.grantRole(ROLE.into(), bob_addr))?;

let contract = AccessControl::new(contract_addr, &bob.wallet);
let err = send!(contract.renounceRole(ROLE.into(), alice_addr))
Expand All @@ -264,7 +264,7 @@ async fn roles_can_be_renounced_multiple_times(alice: Account) -> Result<()> {
let contract_addr = alice.as_deployer().deploy().await?.address()?;
let contract = AccessControl::new(contract_addr, &alice.wallet);

let _ = watch!(contract.renounceRole(ROLE.into(), alice_addr))?;
_ = watch!(contract.renounceRole(ROLE.into(), alice_addr))?;
let receipt = receipt!(contract.renounceRole(ROLE.into(), alice_addr))?;
assert!(!receipt.emits(RoleRevoked {
role: ROLE.into(),
Expand Down Expand Up @@ -314,7 +314,7 @@ async fn the_new_admin_can_grant_roles(
newAdminRole: NEW_ADMIN_ROLE.into()
}));

let _ = watch!(contract.grantRole(NEW_ADMIN_ROLE.into(), bob_addr))?;
_ = watch!(contract.grantRole(NEW_ADMIN_ROLE.into(), bob_addr))?;

let contract = AccessControl::new(contract_addr, &bob.wallet);
let receipt = receipt!(contract.grantRole(ROLE.into(), alice_addr))?;
Expand Down Expand Up @@ -346,10 +346,10 @@ async fn the_new_admin_can_revoke_roles(
newAdminRole: NEW_ADMIN_ROLE.into()
}));

let _ = watch!(contract.grantRole(NEW_ADMIN_ROLE.into(), bob_addr))?;
_ = watch!(contract.grantRole(NEW_ADMIN_ROLE.into(), bob_addr))?;

let contract = AccessControl::new(contract_addr, &bob.wallet);
let _ = watch!(contract.grantRole(ROLE.into(), alice_addr))?;
_ = watch!(contract.grantRole(ROLE.into(), alice_addr))?;
let receipt = receipt!(contract.revokeRole(ROLE.into(), alice_addr))?;
assert!(receipt.emits(RoleRevoked {
role: ROLE.into(),
Expand Down
4 changes: 2 additions & 2 deletions examples/erc1155-metadata-uri/tests/erc1155-metadata-uri.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ async fn uri_returns_concatenated_base_uri_and_token_uri(
let token_uri = "/some/token/uri";
let expected_uri = BASE_URI.to_owned() + token_uri;

let _ = watch!(contract.setBaseURI(BASE_URI.to_owned()))?;
_ = watch!(contract.setBaseURI(BASE_URI.to_owned()))?;

let receipt =
receipt!(contract.setTokenURI(token_id, token_uri.to_owned()))?;
Expand Down Expand Up @@ -142,7 +142,7 @@ async fn uri_ignores_metadata_uri_when_token_uri_is_set(
let token_uri = "/some/token/uri";
let expected_uri = BASE_URI.to_owned() + token_uri;

let _ = watch!(contract.setBaseURI(BASE_URI.to_owned()))?;
_ = watch!(contract.setBaseURI(BASE_URI.to_owned()))?;

let receipt =
receipt!(contract.setTokenURI(token_id, token_uri.to_owned()))?;
Expand Down
Loading

0 comments on commit 62499de

Please sign in to comment.