Skip to content

Commit

Permalink
👥 Compare encode/encodePacked()
Browse files Browse the repository at this point in the history
  • Loading branch information
smitrajput committed Jun 7, 2023
1 parent edff453 commit baa14ab
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 5 deletions.
3 changes: 2 additions & 1 deletion src/PuzzleBox.sol
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,8 @@ contract PuzzleBox {
}

modifier maxCallDataSize(uint256 maxBytes) {
// console.log('msg.data.length', msg.data.length);
console.log('msg.data.length', msg.data.length);
console.logBytes(msg.data);
require(msg.data.length <= maxBytes, 'call data too large');
_;
}
Expand Down
9 changes: 8 additions & 1 deletion src/PuzzleBoxSolution_V0.sol
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,17 @@ contract PuzzleBoxSolution_V0 is Test {
inputArray[4] = 8;
inputArray[5] = 9;
bytes memory encodedDripIds = abi.encode(inputArray);
console.logBytes(encodedDripIds);

// 0x20 6 2 4 6 7 8 9
// 0x20 0x100 0x20 6 2 4 6 7 8 9

// (bool success,) = address(puzzle).call(abi.encodeWithSelector(puzzle.torch.selector, encodedDripIds));
// require(success, "call failed");

(bool success,) = address(puzzle).call(abi.encodePacked(
puzzle.torch.selector, uint256(0x01), uint8(0), encodedDripIds));
require(success, "call failed");
require(success, "call failed");

address payable[] memory friends = new address payable[](1);
uint256[] memory friendsCutBps = new uint256[](3);
Expand Down
6 changes: 3 additions & 3 deletions test/PuzzleBox.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ pragma solidity ^0.8.19;

import "forge-std/Test.sol";
import "../src/PuzzleBox.sol";
import "../src/PuzzleBoxSolution_V2.sol";
import "../src/PuzzleBoxSolution_V0.sol";

contract PuzzleBoxFixture is Test {
event Lock(bytes4 selector, bool isLocked);
Expand All @@ -18,7 +18,7 @@ contract PuzzleBoxFixture is Test {

PuzzleBoxFactory _factory = new PuzzleBoxFactory();
PuzzleBox _puzzle;
PuzzleBoxSolution_V2 _solution;
PuzzleBoxSolution_V0 _solution;
// address deployer;

// Use a modifier instead of setUp() to keep it all in one tx.
Expand All @@ -27,7 +27,7 @@ contract PuzzleBoxFixture is Test {
// vm.deal(deployer, 1 ether);
// vm.startPrank(deployer);
_puzzle = _factory.createPuzzleBox{value: 1337}();
_solution = PuzzleBoxSolution_V2(address(new SolutionContainer(type(PuzzleBoxSolution_V2).runtimeCode)));
_solution = PuzzleBoxSolution_V0(address(new SolutionContainer(type(PuzzleBoxSolution_V0).runtimeCode)));
_;
}

Expand Down

0 comments on commit baa14ab

Please sign in to comment.