lesson-3: How to access the struct inside SimpleStorage.sol from StorageFactory.sol #5444
-
I want to access the name and the number of struct inside SimpleStorage.sol from StorageFactory.sol |
Beta Was this translation helpful? Give feedback.
Replies: 7 comments 10 replies
-
@MohammadRokib Answered it here #4300 |
Beta Was this translation helpful? Give feedback.
-
Beta Was this translation helpful? Give feedback.
-
SimpleStorage.sol
ExtraStorage.sol
|
Beta Was this translation helpful? Give feedback.
-
Sorry my bad! StorageFactory.sol
|
Beta Was this translation helpful? Give feedback.
-
In lesson-6 HardHat SimpleStorage when I run the command: yarn hardhat run scripts/deploy.js The output is Deploying contract...
Deployed contract to: 0x5FbDB2315678afecb367f032d93F642f64180aa3 Here the contract is deployed to the address: When I deploy the contract on sepolia testnet the contract is deploying to |
Beta Was this translation helpful? Give feedback.
-
Beta Was this translation helpful? Give feedback.
-
Lesson: 7 (Problem with testing the owner only modifier) FundMe.sol: // SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import "./PriceConverter.sol";
error FundMe__NotOwner();
contract FundMe {
using PriceConverter for uint256;
uint256 public minUSD = 50*1e18;
address[] public funders;
address public immutable owner;
mapping (address => uint256) public addToAmount;
AggregatorV3Interface public priceFeed;
modifier onlyOwner {
// require(msg.sender == owner, "Administrator only");
if (msg.sender != owner) revert FundMe__NotOwner();
_;
}
constructor(address priceFeedAddress) {
owner = msg.sender;
priceFeed = AggregatorV3Interface(priceFeedAddress);
}
function fund() public payable {
require(msg.value.getConversionRate(priceFeed) >= minUSD, "Insufficient fund");
funders.push(msg.sender);
addToAmount[msg.sender] += msg.value;
}
function withdraw() public onlyOwner {
for (uint256 i = 0; i < funders.length; i++) {
address funder = funders[i];
addToAmount[funder] = 0;
}
funders = new address[](0);
(bool callSuccess, ) = payable(msg.sender).call{value: address(this).balance}("");
require(callSuccess, "Transaction Failed");
}
} FundMe.test.js const { assert, expect } = require("chai");
const { deployments, ethers, getNamedAccounts } = require("hardhat");
describe("FundMe", async function () {
let fundMe, deployer, mockV3Aggregator;
const sendValue = ethers.utils.parseEther("1");
beforeEach(async function () {
deployer = (await getNamedAccounts()).deployer;
await deployments.fixture(["all"]);
fundMe = await ethers.getContract("FundMe", deployer);
mockV3Aggregator = await ethers.getContract(
"MockV3Aggregator",
deployer
);
});
describe("withdraw", async function () {
beforeEach(async function () {
await fundMe.fund({ value: sendValue });
});
it("only allows the owner to withdraw", async function () {
const accounts = await ethers.getSigners();
const connection = await fundMe.connect(accounts[1]);
await expect(connection.withdraw()).to.be.revertedWith("FundMe__NotOwner");
});
});
}); When I run the command
|
Beta Was this translation helpful? Give feedback.
@MohammadRokib Answered it here #4300