-
When writing MoodNftIntegrationTest.t.sol i encountered a bug, the hashes of tokenURI were not matching. I decided to check with console.log, but can't compile code. That's the code: // SPDX-License-Identifier: MIT
pragma solidity ^0.8.18;
import {Test, console} from "forge-std/Test.sol";
import {MoodNft} from "src/MoodNft.sol";
import {DeployMoodNft} from "script/DeployMoodNft.s.sol";
contract MoodNftIntegrationTest is Test {
MoodNft moodNft;
DeployMoodNft deployer;
string public constant HAPPY_SVG_URI =
"data:image/svg+xml;base64,PHN2ZyB2aWV3Qm94PSIwIDAgMjAwIDIwMCIgd2lkdGg9IjQwMCIgIGhlaWdodD0iNDAwIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPgogIDxjaXJjbGUgY3g9IjEwMCIgY3k9IjEwMCIgZmlsbD0ieWVsbG93IiByPSI3OCIgc3Ryb2tlPSJibGFjayIgc3Ryb2tlLXdpZHRoPSIzIi8+CiAgPGcgY2xhc3M9ImV5ZXMiPgogICAgPGNpcmNsZSBjeD0iNzAiIGN5PSI4MiIgcj0iMTIiLz4KICAgIDxjaXJjbGUgY3g9IjEyNyIgY3k9IjgyIiByPSIxMiIvPgogIDwvZz4KICA8cGF0aCBkPSJtMTM2LjgxIDExNi41M2MuNjkgMjYuMTctNjQuMTEgNDItODEuNTItLjczIiBzdHlsZT0iZmlsbDpub25lOyBzdHJva2U6IGJsYWNrOyBzdHJva2Utd2lkdGg6IDM7Ii8+Cjwvc3ZnPg==";
string public constant SAD_SVG_URI =
"data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBzdGFuZGFsb25lPSJubyI/Pgo8c3ZnIHdpZHRoPSIxMDI0cHgiIGhlaWdodD0iMTAyNHB4IiB2aWV3Qm94PSIwIDAgMTAyNCAxMDI0IiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPgogIDxwYXRoIGZpbGw9IiMzMzMiIGQ9Ik01MTIgNjRDMjY0LjYgNjQgNjQgMjY0LjYgNjQgNTEyczI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AwIDAgMCA4LTguNEM2NjcuNiA2MDAuMyA1OTcuNSA1MzMgNTEyIDUzM3ptMTI4LTExMmE0OCA0OCAwIDEgMCA5NiAwIDQ4IDQ4IDAgMSAwLTk2IDB6Ii8+Cjwvc3ZnPg==";
address public USER = makeAddr("user");
modifier Minted() {
vm.prank(USER);
moodNft.mintNft();
_;
}
function setUp() public {
deployer = new DeployMoodNft();
moodNft = deployer.run();
}
function testViewTokenURIIntegration() public Minted {
console.log(moodNft.tokenURI(0));
}
function testOwnerCanFlipMood() public Minted {
console.log(keccak256(abi.encodePacked(SAD_SVG_URI)));
vm.prank(USER);
moodNft.flipMood(0);
assert(
keccak256(abi.encodePacked(moodNft.tokenURI(0))) ==
keccak256(abi.encodePacked(SAD_SVG_URI))
);
}
function testFlipMoodRevertWhenNotOwnerFlips() public Minted {
vm.prank(address(1));
vm.expectRevert(MoodNft.MoodNft__CantFlipMoodIfNotOwner.selector);
moodNft.flipMood(0);
}
} The error: forge build
[⠒] Compiling...
[⠊] Compiling 47 files with Solc 0.8.26
[⠒] Solc 0.8.26 finished in 1.74s
Error:
Compiler run failed:
Error (9582): Member "log" not found or not visible after argument-dependent lookup in type(library console).
--> test/integrations/MoodNftIntergationTest.t.sol:35:9:
|
35 | console.log(keccak256(abi.encodePacked(SAD_SVG_URI)));
| ^^^^^^^^^^^ Why do i get this error on line 35, but it's good on line 31? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
Hello, I must say you didn't catch a bug because if the hashes of your tokenURI aren't matching, then, you must have hashed different strings. The console.log() didn't work on line 35 probably because you can't use it on the type of bytes32 object, which is what a |
Beta Was this translation helpful? Give feedback.
-
Issue resolved. Next video on updraft literally starts with Partick encountering the same issue. Sometimes it's hard for me to move forward on the course when i can't resolve the problem i have right now. The issue is that i assert that encoded and hashed json metadata ( Thanks for your involvment and sorry for loss of time! @EngrPips |
Beta Was this translation helpful? Give feedback.
Issue resolved. Next video on updraft literally starts with Partick encountering the same issue. Sometimes it's hard for me to move forward on the course when i can't resolve the problem i have right now.
The issue is that i assert that encoded and hashed json metadata (
moodNft.tokenURI(0)
) is equal to encoded and hashed image URI (SAD_SVG_URI
). Which is, of course, not true, Yep, that silly.Thanks for your involvment and sorry for loss of time! @EngrPips