-
Notifications
You must be signed in to change notification settings - Fork 419
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
3,191 additions
and
143 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.4; | ||
|
||
import "../universalResolver/BytesArrayValidator.sol"; | ||
|
||
contract TestBytesArrayValidator { | ||
function testValidBytesArray() public pure { | ||
// Create a valid bytes array | ||
bytes[] memory validArray = new bytes[](5); | ||
validArray[0] = "Hello"; | ||
validArray[1] = "World"; | ||
validArray[2] = "Two"; | ||
validArray[3] = "Three"; | ||
validArray[4] = "Four"; | ||
bytes memory encodedValidArray = abi.encode(validArray); | ||
|
||
bool isValid = BytesArrayValidator.isValidBytesArray(encodedValidArray); | ||
require(isValid, "Should be a valid bytes array"); | ||
} | ||
|
||
function testInvalidBytesArray() public pure { | ||
// Create an invalid bytes array (too short) | ||
bytes memory invalidArray = new bytes(16); | ||
|
||
bool isValid = BytesArrayValidator.isValidBytesArray(invalidArray); | ||
require(!isValid, "Should be an invalid bytes array"); | ||
} | ||
|
||
function testEmptyBytesArray() public pure { | ||
// Create an empty bytes array | ||
bytes[] memory emptyArray = new bytes[](0); | ||
bytes memory encodedEmptyArray = abi.encode(emptyArray); | ||
|
||
bool isValid = BytesArrayValidator.isValidBytesArray(encodedEmptyArray); | ||
require(isValid, "Empty array should be valid"); | ||
} | ||
|
||
function testEmptyItemInBytesArray() public pure { | ||
// Create an empty bytes array | ||
bytes[] memory emptyArray = new bytes[](1); | ||
emptyArray[0] = ""; | ||
bytes memory encodedEmptyArray = abi.encode(emptyArray); | ||
|
||
bool isValid = BytesArrayValidator.isValidBytesArray(encodedEmptyArray); | ||
require(isValid, "Empty array should be valid"); | ||
} | ||
|
||
function largeEmptyBytesArray() public pure { | ||
bytes[] memory largeArray = new bytes[](1000); | ||
bytes memory encodedLargeArray = abi.encode(largeArray); | ||
|
||
bool isValid = BytesArrayValidator.isValidBytesArray(encodedLargeArray); | ||
require(isValid, "Large array should be valid"); | ||
} | ||
|
||
function testLargeBytesArray() public pure { | ||
// Create a large bytes array | ||
bytes[] memory largeArray = new bytes[](1000); | ||
for (uint i = 0; i < 1000; i++) { | ||
largeArray[i] = new bytes(100); | ||
} | ||
bytes memory encodedLargeArray = abi.encode(largeArray); | ||
|
||
bool isValid = BytesArrayValidator.isValidBytesArray(encodedLargeArray); | ||
require(isValid, "Large array should be valid"); | ||
} | ||
|
||
function testInvalidOffsets() public pure { | ||
// Create an invalid bytes array with incorrect offsets | ||
bytes memory invalidOffsets = new bytes(128); | ||
// Set an invalid offset | ||
assembly { | ||
mstore(add(invalidOffsets, 64), 0x20) | ||
} | ||
|
||
bool isValid = BytesArrayValidator.isValidBytesArray(invalidOffsets); | ||
require(!isValid, "Array with invalid offsets should be invalid"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.4; | ||
|
||
import "../universalResolver/ERC3668Caller.sol"; | ||
import "hardhat/console.sol"; | ||
|
||
contract TestUserCallbackFunctions is ERC3668Caller { | ||
function testCreateUserCallbackFunctions() public view { | ||
bytes4 internalCallbackFunction = bytes4(0x11111111); | ||
bytes4 calldataRewriteFunction = bytes4(0x22222222); | ||
bytes4 failureCallbackFunction = bytes4(0x33333333); | ||
bytes4 validateResponseFunction = bytes4(0x44444444); | ||
|
||
uint256 gasBefore = gasleft(); | ||
uint256 callbackFunctions = createUserCallbackFunctions( | ||
internalCallbackFunction, | ||
calldataRewriteFunction, | ||
failureCallbackFunction, | ||
validateResponseFunction | ||
); | ||
uint256 gasAfter = gasleft(); | ||
console.log("gas", gasBefore - gasAfter); | ||
|
||
console.logBytes32(bytes32(callbackFunctions)); | ||
|
||
require( | ||
callbackFunctions == | ||
0x0000000000000000000000000000000044444444333333332222222211111111, | ||
"Callback functions should be correct" | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.4; | ||
|
||
import "@openzeppelin/contracts/utils/introspection/ERC165.sol"; | ||
import "../../../contracts/resolvers/profiles/IAddrResolver.sol"; | ||
import "../../../contracts/resolvers/profiles/IExtendedResolver.sol"; | ||
|
||
error OffchainLookup( | ||
address sender, | ||
string[] urls, | ||
bytes callData, | ||
bytes4 callbackFunction, | ||
bytes extraData | ||
); | ||
|
||
contract DummyAddrOffchainResolver is IAddrResolver, ERC165 { | ||
function supportsInterface( | ||
bytes4 interfaceId | ||
) public view virtual override returns (bool) { | ||
return | ||
interfaceId == type(IAddrResolver).interfaceId || | ||
super.supportsInterface(interfaceId); | ||
} | ||
|
||
function addr(bytes32) external view returns (address payable) { | ||
string[] memory urls = new string[](1); | ||
urls[0] = "https://example.com/"; | ||
|
||
bytes memory data = abi.encode(address(this)); | ||
|
||
revert OffchainLookup( | ||
address(this), | ||
urls, | ||
data, | ||
this.addrCallback.selector, | ||
data | ||
); | ||
} | ||
|
||
function addrOnchain(bytes32) external view returns (address) { | ||
return address(this); | ||
} | ||
|
||
function addrCallback( | ||
bytes calldata response, | ||
bytes calldata extraData | ||
) external view returns (address) { | ||
return abi.decode(response, (address)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.