Coder Social home page Coder Social logo

ethereum-benchmark's Issues

Making tests for custm functions

Hey, i want to know how my smart contracts methods will function when simulated an x couple of time, like the average transaction fee, change in gasPrice etc, but i do not really know how to implement it correctly, here is the smart contract`// SPDX-License-Identifier: MIT
pragma solidity 0.8.19;

/** Smart contract to list products */
contract Listing {
struct Item {
address seller;
string name;
string description;
uint256 price;
bool isAvailable;
}

// Mapping items to unique identifiers
mapping(uint256 => Item) public items;

// Counter to generate unique id
uint256 public itemIdCounter;

// Event emitted when a new product is listed
event ItemListed(
    uint256 itemId,
    address indexed seller,
    string name,
    uint256 price
);

// Event emitted when item is deleted
event ItemDeleted(uint256 itemId, address indexed seller);

// Modifier to ensure only the seller can perform certain actions
modifier onlySeller(uint256 itemId) {
    require(msg.sender == items[itemId].seller, "You are not the seller");
    _;
}

// Function to list a new item
function listNewItem(
    string memory itemName,
    string memory itemDescription,
    uint256 price
) external {
    require(price > 0, "Price must be greater than 0");

    // Increment item id counter to generate a unique id for the new item
    itemIdCounter++;

    // Create a new item and store it in the mapping
    items[itemIdCounter] = Item({
        seller: msg.sender,
        name: itemName,
        description: itemDescription,
        price: price,
        isAvailable: true
    });

    // Emit an event to notify a new item has been listed
    emit ItemListed(itemIdCounter, msg.sender, itemName, price);
}

// Function to get details of a listed item
function getItemDetails(
    uint256 itemId
) external view returns (Item memory) {
    return items[itemId];
}

// Function to purchase a listed item
function purchaseItem(uint256 itemId) external payable {
    // Check item availability
    require(items[itemId].isAvailable, "Item is not available");

    // Check if the sent value matches the item's price
    require(
        msg.value == items[itemId].price,
        "Incorrect payment amount for item"
    );

    // Transfer funds to the seller
    payable(items[itemId].seller).transfer(msg.value);

    // Mark the item as sold
    items[itemId].isAvailable = false;
}

// Function to update details of a listed item
function updateItemDetails(
    uint256 itemId,
    string memory newItemName,
    string memory newItemDescription,
    uint256 newPrice
) external onlySeller(itemId) {
    require(newPrice > 0, "Price must be greater than zero");

    // Update details of the item
    items[itemId].name = newItemName;
    items[itemId].description = newItemDescription;
    items[itemId].price = newPrice;
}

// Function to delete a listed item
function deleteItem(uint256 itemId) external onlySeller(itemId) {
    // Mark the item as no longer available
    items[itemId].isAvailable = false;

    // Emit an event to notify deletion
    emit ItemDeleted(itemId, msg.sender);
}

}
` thank you in advance

where to set private keys with ETH

hello

thank you for creating this repo
I can't find where I can sent the private key of some wallet funded with (my) ETH. I see you generate couple of random wallets, but they are all empty.
I thought there should be some sort of "master" account to fund them

Thank you again

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.