aboutsummaryrefslogtreecommitdiffstats
path: root/packages/contracts/src
diff options
context:
space:
mode:
authorGreg Hysen <greg.hysen@gmail.com>2018-05-25 15:31:03 +0800
committerGreg Hysen <greg.hysen@gmail.com>2018-06-08 06:38:42 +0800
commit842363200b3b8aded3b03fc8e46a329ff9534e36 (patch)
tree8f535e5a16c298594b4d3f0959ec4b73f707cf48 /packages/contracts/src
parentd9f9895b2bcd3cde09febbe0e1af31be5ddc80e2 (diff)
downloaddexon-sol-tools-842363200b3b8aded3b03fc8e46a329ff9534e36.tar
dexon-sol-tools-842363200b3b8aded3b03fc8e46a329ff9534e36.tar.gz
dexon-sol-tools-842363200b3b8aded3b03fc8e46a329ff9534e36.tar.bz2
dexon-sol-tools-842363200b3b8aded3b03fc8e46a329ff9534e36.tar.lz
dexon-sol-tools-842363200b3b8aded3b03fc8e46a329ff9534e36.tar.xz
dexon-sol-tools-842363200b3b8aded3b03fc8e46a329ff9534e36.tar.zst
dexon-sol-tools-842363200b3b8aded3b03fc8e46a329ff9534e36.zip
Tons of tests around nested byte arrays and ERC721 receiver
Diffstat (limited to 'packages/contracts/src')
-rw-r--r--packages/contracts/src/contracts/current/test/TestLibBytes/TestLibBytes.sol25
-rw-r--r--packages/contracts/src/contracts/current/utils/LibBytes/LibBytes.sol17
2 files changed, 32 insertions, 10 deletions
diff --git a/packages/contracts/src/contracts/current/test/TestLibBytes/TestLibBytes.sol b/packages/contracts/src/contracts/current/test/TestLibBytes/TestLibBytes.sol
index 69554605d..0bf11b03b 100644
--- a/packages/contracts/src/contracts/current/test/TestLibBytes/TestLibBytes.sol
+++ b/packages/contracts/src/contracts/current/test/TestLibBytes/TestLibBytes.sol
@@ -155,6 +155,7 @@ contract TestLibBytes is
return b;
}
+=======
/// @dev Reads the first 4 bytes from a byte array of arbitrary length.
/// @param b Byte array to read first 4 bytes from.
/// @return First 4 bytes of data.
@@ -166,4 +167,28 @@ contract TestLibBytes is
result = readFirst4(b);
return result;
}
+
+ function publicReadBytes(
+ bytes memory b,
+ uint256 index)
+ public
+ pure
+ returns (bytes memory result)
+ {
+ result = readBytes(b, index);
+ return result;
+ }
+
+
+ function publicWriteBytes(
+ bytes memory b,
+ uint256 index,
+ bytes memory input)
+ public
+ pure
+ returns (bytes memory)
+ {
+ writeBytes(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 fb8359462..6351f1a46 100644
--- a/packages/contracts/src/contracts/current/utils/LibBytes/LibBytes.sol
+++ b/packages/contracts/src/contracts/current/utils/LibBytes/LibBytes.sol
@@ -300,24 +300,21 @@ contract LibBytes is
returns (bytes memory result)
{
// Read length of nested bytes
- require(
- b.length >= index + 32,
- GTE_32_LENGTH_REQUIRED
- );
uint256 nestedBytesLength = readUint256(b, index);
+ index += 32;
// Assert length of <b> is valid, given
// length of nested bytes
require(
- b.length >= index + 32 + nestedBytesLength,
+ b.length >= index + nestedBytesLength,
GTE_32_LENGTH_REQUIRED
);
// Allocate memory and copy value to result
result = new bytes(nestedBytesLength);
memcpy(
- getMemAddress(result) + 32, // +32 skips array length
- getMemAddress(b) + index + 32, // +32 skips array length
+ getMemAddress(result) + 32, // +32 skips array length
+ getMemAddress(b) + index + 32,
nestedBytesLength
);
@@ -344,9 +341,9 @@ contract LibBytes is
// Copy <input> into <b>
memcpy(
- getMemAddress(b) + index,
- getMemAddress(input),
- input.length + 32 /* 32 bytes to store length */
+ getMemAddress(b) + index + 32, // +32 to skip length of <b>
+ getMemAddress(input), // include length of byte array
+ input.length + 32 // +32 bytes to store length
);
}
}