Skip to content

Commit

Permalink
fix fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
qalisander committed May 16, 2024
1 parent 00c4e3c commit dc6697c
Show file tree
Hide file tree
Showing 9 changed files with 41 additions and 26 deletions.
12 changes: 11 additions & 1 deletion Cargo.lock

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

6 changes: 4 additions & 2 deletions contracts/src/erc721/mod.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
//! Implementation of the ERC-721 token standard.
use alloc::vec;

use alloy_primitives::{fixed_bytes, Address, FixedBytes, U128, U256};
use alloy_primitives::{
fixed_bytes, private::derive_more::From, Address, FixedBytes, U128, U256,
};
use stylus_sdk::{
abi::Bytes, alloy_sol_types::sol, call::Call, evm, msg, prelude::*,
};
Expand Down Expand Up @@ -101,7 +103,7 @@ sol! {
/// An ERC-721 error defined as described in [ERC-6093].
///
/// [ERC-6093]: https://eips.ethereum.org/EIPS/eip-6093
#[derive(SolidityError, Debug)]
#[derive(SolidityError, Debug, From)]
pub enum Error {
/// Indicates that an address can't be an owner.
/// For example, `Address::ZERO` is a forbidden owner in ERC-721. Used in
Expand Down
8 changes: 2 additions & 6 deletions examples/erc20/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use alloc::string::String;

use alloy_primitives::{Address, U256};
use contracts::{
erc20::{extensions::ERC20Metadata, ERC20, Error, ERC20InvalidReceiver},
erc20::{extensions::ERC20Metadata, ERC20InvalidReceiver, Error, ERC20},
erc20_burnable_impl,
};
use stylus_sdk::prelude::{entrypoint, external, sol_storage};
Expand Down Expand Up @@ -41,11 +41,7 @@ impl Token {
DECIMALS
}

pub fn mint(
&mut self,
account: Address,
value: U256,
) -> Result<(), Error> {
pub fn mint(&mut self, account: Address, value: U256) -> Result<(), Error> {
// TODO: create function _mint at erc20 similar to solidity
if account.is_zero() {
return Err(Error::InvalidReceiver(ERC20InvalidReceiver {
Expand Down
15 changes: 11 additions & 4 deletions examples/erc721/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,13 @@
extern crate alloc;

use alloc::string::String;
use contracts::erc721::{extensions::ERC721Metadata, ERC721};

use alloy_primitives::Address;
use stylus_sdk::alloy_sol_types::private::U256;
use stylus_sdk::prelude::{entrypoint, external, sol_storage};
use contracts::erc721::{extensions::ERC721Metadata, ERC721};
use stylus_sdk::{
alloy_sol_types::private::U256,
prelude::{entrypoint, external, sol_storage},
};

sol_storage! {
#[entrypoint]
Expand Down Expand Up @@ -33,7 +36,11 @@ impl Token {
self.metadata.constructor(name, symbol, base_uri);
}

pub fn mint(&mut self, to: Address, token_id: U256) -> Result<(), contracts::erc721::Error> {
pub fn mint(
&mut self,
to: Address,
token_id: U256,
) -> Result<(), contracts::erc721::Error> {
self.erc721._mint(to, token_id)
}
}
12 changes: 6 additions & 6 deletions integration/src/erc20.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,18 @@ async fn mint() -> Result<()> {

let initial_balance =
infra.alice.balance_of(infra.alice.wallet.address()).ctx_call().await?;
let initial_supply =
infra.alice.total_supply().ctx_call().await?;

let initial_supply = infra.alice.total_supply().ctx_call().await?;

let _ =
infra.alice.mint(infra.alice.wallet.address(), one).ctx_send().await?;

let new_balance = infra.alice.balance_of(infra.alice.wallet.address()).ctx_call().await?;

let new_balance =
infra.alice.balance_of(infra.alice.wallet.address()).ctx_call().await?;
let new_supply = infra.alice.total_supply().ctx_call().await?;

assert_eq!(initial_balance + one, new_balance);
assert_eq!(initial_supply + one, new_supply);
Ok(())
}

// TODO: add rest of the tests for erc20 base implementation
// TODO: add rest of the tests for erc20 base implementation
2 changes: 1 addition & 1 deletion integration/src/erc721.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use crate::infrastructure::{erc721::*, *};

// TODO: add isolation with mutex per contract

// TODO#q: refactor these tests similarly to unit tests
// TODO#q: refactor these tests similarly to unit tests

#[tokio::test]
async fn mint_nft_and_check_balance() -> Result<()> {
Expand Down
3 changes: 2 additions & 1 deletion integration/src/infrastructure/erc721.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ abigen!(
pub type Erc721 = Erc721Token<HttpMiddleware>;

impl Token for Erc721 {
const STYLUS_PROGRAM_ADDRESS: &'static str = "ERC721_EXAMPLE_DEPLOYMENT_ADDRESS";
const STYLUS_PROGRAM_ADDRESS: &'static str =
"ERC721_EXAMPLE_DEPLOYMENT_ADDRESS";

fn new(address: Address, client: Arc<HttpMiddleware>) -> Self {
Self::new(address, client)
Expand Down
5 changes: 2 additions & 3 deletions integration/src/infrastructure/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ const ALICE_PRIV_KEY: &str = "ALICE_PRIV_KEY";
const BOB_PRIV_KEY: &str = "BOB_PRIV_KEY";
const RPC_URL: &str = "RPC_URL";


/// Integration testing infrastructure that allows to act on behalf of `alice`
/// and `bob` accounts.
pub struct Infrastructure<T: Token> {
Expand Down Expand Up @@ -60,7 +59,8 @@ impl<T: Token> Infrastructure<T> {
}
}

/// Client of participant that allows to check wallet address and call contract functions.
/// Client of participant that allows to check wallet address and call contract
/// functions.
pub struct Client<T: Token> {
pub wallet: LocalWallet,
pub caller: T,
Expand All @@ -75,7 +75,6 @@ impl<T: Token> Deref for Client<T> {
}
}


/// Abstraction for the deployed contract.
pub trait Token {
/// Deployed program address environment variable name for the contract.
Expand Down
4 changes: 2 additions & 2 deletions integration/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
mod erc721;
mod erc20;
mod infrastructure;
mod erc721;
mod infrastructure;

0 comments on commit dc6697c

Please sign in to comment.