Tests in Solidity for Merkle Trees (Foundry)

Hi there,

I've been diving into using Foundry for Solidity testing, but I'm finding it difficult to test the OZ MerkleProof.verify() function. Everytime I try to construct the proof in bytes32 it fails or errors.

Tried [keccak256(abi.encodePacked("-proof node-")] and tried declaring bytes32 and pushing keccak256(abi.encodePacked("-proof node-"). Neither work, but merkleTree.verify works in JS.

I was able to solve this by taking the js output and using it in a helper function like this:

bytes32[] memory proof = new bytes32[](4);

proof[0] = bytes32( 0x.... );
proof[1] = bytes32( 0x.... );
proof[2] = bytes32( 0x.... );
proof[3] = bytes32( 0x.... );

return proof; 
1 Like

Thanks for this. Could you share your whole test for context? Im doing this as well but seems to still be failing for me. Now Im curious to see how youre generating the merkle root and what your address formatting looks like. Thanks!