diff options
Diffstat (limited to 'packages/contracts/src')
3 files changed, 148 insertions, 9 deletions
diff --git a/packages/contracts/src/contracts/current/test/TestLibBytes/TestLibBytes.sol b/packages/contracts/src/contracts/current/test/TestLibBytes/TestLibBytes.sol new file mode 100644 index 000000000..1597ff8d5 --- /dev/null +++ b/packages/contracts/src/contracts/current/test/TestLibBytes/TestLibBytes.sol @@ -0,0 +1,133 @@ +/* + + Copyright 2018 ZeroEx Intl. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + +*/ + +pragma solidity ^0.4.23; +pragma experimental ABIEncoderV2; + +import "../../utils/LibBytes/LibBytes.sol"; + +contract TestLibBytes is + LibBytes +{ + + /// @dev Tests equality of two byte arrays. + /// @param lhs First byte array to compare. + /// @param rhs Second byte array to compare. + /// @return True if arrays are the same. False otherwise. + function publicAreBytesEqual(bytes memory lhs, bytes memory rhs) + public + pure + returns (bool equal) + { + equal = areBytesEqual(lhs, rhs); + return equal; + } + + /// @dev Reads an address from a position in a byte array. + /// @param b Byte array containing an address. + /// @param index Index in byte array of address. + /// @return address from byte array. + function publicReadAddress( + bytes memory b, + uint256 index) + public + pure + returns (address result) + { + result = readAddress(b, index); + return result; + } + + /// @dev Writes an address into a specific position in a byte array. + /// @param b Byte array to insert address into. + /// @param index Index in byte array of address. + /// @param input Address to put into byte array. + function publicWriteAddress( + bytes memory b, + uint256 index, + address input) + public + pure + returns (bytes memory) + { + writeAddress(b, index, input); + return b; + } + + /// @dev Reads a bytes32 value from a position in a byte array. + /// @param b Byte array containing a bytes32 value. + /// @param index Index in byte array of bytes32 value. + /// @return bytes32 value from byte array. + function publicReadBytes32( + bytes memory b, + uint256 index) + public + pure + returns (bytes32 result) + { + result = readBytes32(b, index); + return result; + } + + /// @dev Writes a bytes32 into a specific position in a byte array. + /// @param b Byte array to insert <input> into. + /// @param index Index in byte array of <input>. + /// @param input bytes32 to put into byte array. + function publicWriteBytes32( + bytes memory b, + uint256 index, + bytes32 input) + public + pure + returns (bytes memory) + { + writeBytes32(b, index, input); + return b; + } + + /// @dev Reads a uint256 value from a position in a byte array. + /// @param b Byte array containing a uint256 value. + /// @param index Index in byte array of uint256 value. + /// @return uint256 value from byte array. + function publicReadUint256( + bytes memory b, + uint256 index) + public + pure + returns (uint256 result) + { + result = readUint256(b, index); + return result; + } + + /// @dev Writes a uint256 into a specific position in a byte array. + /// @param b Byte array to insert <input> into. + /// @param index Index in byte array of <input>. + /// @param input uint256 to put into byte array. + function publicWriteUint256( + bytes memory b, + uint256 index, + uint256 input) + public + pure + returns (bytes memory) + { + writeUint256(b, index, input); + return b; + } +} diff --git a/packages/contracts/src/contracts/current/utils/LibBytes/LibBytes.sol b/packages/contracts/src/contracts/current/utils/LibBytes/LibBytes.sol index cff780ba4..3eba0708f 100644 --- a/packages/contracts/src/contracts/current/utils/LibBytes/LibBytes.sol +++ b/packages/contracts/src/contracts/current/utils/LibBytes/LibBytes.sol @@ -17,7 +17,6 @@ */ pragma solidity ^0.4.23; -pragma experimental ABIEncoderV2; contract LibBytes { @@ -26,7 +25,8 @@ contract LibBytes { /// @param rhs Second byte array to compare. /// @return True if arrays are the same. False otherwise. function areBytesEqual(bytes memory lhs, bytes memory rhs) - public pure + internal + pure returns (bool equal) { assembly { @@ -59,7 +59,8 @@ contract LibBytes { function readAddress( bytes memory b, uint256 index) - public pure + internal + pure returns (address result) { require( @@ -90,7 +91,8 @@ contract LibBytes { bytes memory b, uint256 index, address input) - public pure + internal + pure { require( b.length >= index + 20, // 20 is length of address @@ -126,7 +128,8 @@ contract LibBytes { function readBytes32( bytes memory b, uint256 index) - public pure + internal + pure returns (bytes32 result) { require( @@ -152,7 +155,8 @@ contract LibBytes { bytes memory b, uint256 index, bytes32 input) - public pure + internal + pure { require( b.length >= index + 32, @@ -175,7 +179,8 @@ contract LibBytes { function readUint256( bytes memory b, uint256 index) - public pure + internal + pure returns (uint256 result) { return uint256(readBytes32(b, index)); @@ -189,7 +194,8 @@ contract LibBytes { bytes memory b, uint256 index, uint256 input) - public pure + internal + pure { writeBytes32(b, index, bytes32(input)); } diff --git a/packages/contracts/src/utils/types.ts b/packages/contracts/src/utils/types.ts index 6f9aeda94..2200e09f3 100644 --- a/packages/contracts/src/utils/types.ts +++ b/packages/contracts/src/utils/types.ts @@ -99,7 +99,7 @@ export enum ContractName { ERC20Proxy = 'ERC20Proxy', ERC721Proxy = 'ERC721Proxy', DummyERC721Token = 'DummyERC721Token', - LibBytes = 'LibBytes', + TestLibBytes = 'TestLibBytes', Authorizable = 'Authorizable', } |