Cyfrin / foundry-nft-cu

22 stars 25 forks source link

BasicNftTest::testCanMintAndHaveABalance() Issue #25

Closed monteago30 closed 8 months ago

monteago30 commented 8 months ago

I am running into an issue with testing the above function. The test is failing and getting a panic: assertion failed(0x01). I think it seems that the ipfs URI of the Pug image is not matching up with the tokenURI function in BasicNft.sol.

Code Snippet: BasicNftTest.t.sol:

contract BasicNftTest is Test { DeployBasicNft public deployer; BasicNft public basicNft; address public USER = makeAddr("user"); string public constant PUG = "ipfs://bafybeig37ioir76s7mg5oobetncojcm3c3hxasyd4rvid4jqhy4gkaheg4/?filename=0-PUG.json";

function testCanMintAndHaveABalance() public { vm.prank(USER); basicNft.mintNft(PUG);

    assert(basicNft.balanceOf(USER) == 1);
    assert(keccak256(abi.encodePacked(PUG)) == keccak256(abi.encodePacked(basicNft.tokenURI)));
}

BasicNft.sol function tokenURI(uint256 tokenId) public view override returns (string memory) { return s_tokenIdToUri[tokenId]; }

Ran 1 test for test/BasicNftTest.t.sol:BasicNftTest [FAIL. Reason: panic: assertion failed (0x01)] testCanMintAndHaveABalance() (gas: 171974) Traces: [2025034] BasicNftTest::setUp() ├─ [1042185] → new DeployBasicNft@0x5615dEB798BB3E4dFa0139dFa1b3D433Cc23b72f │ └─ ← 5095 bytes of code ├─ [904825] DeployBasicNft::run() │ ├─ [0] VM::startBroadcast() │ │ └─ ← () │ ├─ [868406] → new BasicNft@0x90193C961A926261B756D1E5bb255e67ff9498A1 │ │ └─ ← 4101 bytes of code │ ├─ [0] VM::stopBroadcast() │ │ └─ ← () │ └─ ← BasicNft: [0x90193C961A926261B756D1E5bb255e67ff9498A1] └─ ← ()

[171974] BasicNftTest::testCanMintAndHaveABalance() ├─ [0] VM::prank(user: [0x6CA6d1e2D5347Bfab1d91e883F1915560e09129D]) │ └─ ← () ├─ [159258] BasicNft::mintNft("ipfs://bafybeig37ioir76s7mg5oobetncojcm3c3hxasyd4rvid4jqhy4gkaheg4/?filename=0-PUG.json") │ ├─ emit Transfer(from: 0x0000000000000000000000000000000000000000, to: user: [0x6CA6d1e2D5347Bfab1d91e883F1915560e09129D], tokenId: 0) │ └─ ← () ├─ [612] BasicNft::balanceOf(user: [0x6CA6d1e2D5347Bfab1d91e883F1915560e09129D]) [staticcall] │ └─ ← 1 └─ ← panic: assertion failed (0x01)

Test result: FAILED. 0 passed; 1 failed; 0 skipped; finished in 1.32ms

Ran 1 test suite in 1.32ms: 0 tests passed, 1 failed, 0 skipped (1 total tests)

Failing tests: Encountered 1 failing test in test/BasicNftTest.t.sol:BasicNftTest [FAIL. Reason: panic: assertion failed (0x01)] testCanMintAndHaveABalance() (gas: 171974)

Encountered a total of 1 failing tests, 0 tests succeeded

PatrickAlphaC commented 8 months ago

Hello! Thanks for making this issue.

Can you:

  1. Make this a discussion on the full repo? https://github.com/Cyfrin/foundry-full-course-f23/discussions

  2. Could you please remember to follow this section to format your questions? https://youtu.be/umepbfKp5rI?t=22464