You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm using foundry for solidity development and I have some issues with using structs in my tests.
the problem :
the function below lets users make an offer and saves and pushes the offer in an array of offers in a private mapping. the other function lets the owner of tokens get the offers for their token.in this case, for testing these functions I need to get the offer object in my test.
I tried the library solution and made a library having my offer struct in it and then imported the library in my test file and it worked but in this case, I have to use the library for my whole contract and it feels not okay to me.
isn't there any other way to test my structs in Foundry?
the functions :
mapping(uint256=> Offer[]) private tokenIdToOffers;
function makeOffer(uint256tokenId, uint256offeredPrice) public {
if (!_exists(tokenId) ||ownerOf(tokenId) ==msg.sender) {
revertwrongTokenIdEnterd();
}
if (tokenIdToHighestBid[tokenId] !=0|| tokenIdToIsListed[tokenId]) {
reverttokenAlreadyInSaleOrAuction();
}
Offer memory offer =Offer(msg.sender, offeredPrice);
tokenIdToOffers[tokenId].push(offer);
}
function getOffers(
uint256tokenId
) externalviewonlyTokenOwner(tokenId) returns (Offer[] memory) {
return tokenIdToOffers[tokenId];
}
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Hey everyone
I'm using foundry for solidity development and I have some issues with using structs in my tests.
the problem :
the function below lets users make an offer and saves and pushes the offer in an array of offers in a private mapping. the other function lets the owner of tokens get the offers for their token.in this case, for testing these functions I need to get the offer object in my test.
I tried the library solution and made a library having my offer struct in it and then imported the library in my test file and it worked but in this case, I have to use the library for my whole contract and it feels not okay to me.
isn't there any other way to test my structs in Foundry?
the functions :
the test :
UPDATE : the problem with mappings got solved so I edited the question.
Beta Was this translation helpful? Give feedback.
All reactions