aboutsummaryrefslogtreecommitdiffstats
path: root/packages
diff options
context:
space:
mode:
authorGreg Hysen <greg.hysen@gmail.com>2018-06-08 07:32:42 +0800
committerGreg Hysen <greg.hysen@gmail.com>2018-06-08 07:32:42 +0800
commit05123ea6f48a71ac0a53dcadcbc5924cbd1d1486 (patch)
tree6dc7d1bc7474473c8c159ffb1f28d13c51212eb4 /packages
parentd62ff34a5a5794a586c0b4bbf27c51ea36efd659 (diff)
downloaddexon-0x-contracts-05123ea6f48a71ac0a53dcadcbc5924cbd1d1486.tar.gz
dexon-0x-contracts-05123ea6f48a71ac0a53dcadcbc5924cbd1d1486.tar.zst
dexon-0x-contracts-05123ea6f48a71ac0a53dcadcbc5924cbd1d1486.zip
Updated LibBytes error messages
Diffstat (limited to 'packages')
-rw-r--r--packages/contracts/src/contracts/current/utils/LibBytes/LibBytes.sol2
-rw-r--r--packages/contracts/src/utils/constants.ts10
-rw-r--r--packages/contracts/test/libraries/lib_bytes.ts52
3 files changed, 36 insertions, 28 deletions
diff --git a/packages/contracts/src/contracts/current/utils/LibBytes/LibBytes.sol b/packages/contracts/src/contracts/current/utils/LibBytes/LibBytes.sol
index 4f9e2f152..d1d10476f 100644
--- a/packages/contracts/src/contracts/current/utils/LibBytes/LibBytes.sol
+++ b/packages/contracts/src/contracts/current/utils/LibBytes/LibBytes.sol
@@ -26,7 +26,7 @@ contract LibBytes is
// Revert reasons
string constant GREATER_THAN_ZERO_LENGTH_REQUIRED = "GREATER_THAN_ZERO_LENGTH_REQUIRED";
- string constant GREATER_OR_EQUAL_TO_4_LENGTH_REQUIRED = "GREATER_THAN_4_LENGTH_REQUIRED";
+ string constant GREATER_OR_EQUAL_TO_4_LENGTH_REQUIRED = "GREATER_OR_EQUAL_TO_4_LENGTH_REQUIRED";
string constant GREATER_OR_EQUAL_TO_20_LENGTH_REQUIRED = "GREATER_OR_EQUAL_TO_20_LENGTH_REQUIRED";
string constant GREATER_OR_EQUAL_TO_32_LENGTH_REQUIRED = "GREATER_OR_EQUAL_TO_32_LENGTH_REQUIRED";
string constant GREATER_OR_EQUAL_TO_NESTED_BYTES_LENGTH_REQUIRED = "GREATER_OR_EQUAL_TO_NESTED_BYTES_LENGTH_REQUIRED";
diff --git a/packages/contracts/src/utils/constants.ts b/packages/contracts/src/utils/constants.ts
index fa2a4af3c..af3f26d82 100644
--- a/packages/contracts/src/utils/constants.ts
+++ b/packages/contracts/src/utils/constants.ts
@@ -19,11 +19,11 @@ const TESTRPC_PRIVATE_KEYS_STRINGS = [
export const constants = {
INVALID_OPCODE: 'invalid opcode',
REVERT: 'revert',
- LIB_BYTES_GT_ZERO_LENGTH_REQUIRED: 'Length must be greater than 0.',
- LIB_BYTES_GTE_4_LENGTH_REQUIRED: 'Length must be greater than or equal to 4.',
- LIB_BYTES_GTE_20_LENGTH_REQUIRED: 'Length must be greater than or equal to 20.',
- LIB_BYTES_GTE_32_LENGTH_REQUIRED: 'Length must be greater than or equal to 32.',
- LIB_BYTES_INDEX_OUT_OF_BOUNDS: 'Specified array index is out of bounds.',
+ LIB_BYTES_GREATER_THAN_ZERO_LENGTH_REQUIRED: 'GREATER_THAN_ZERO_LENGTH_REQUIRED',
+ LIB_BYTES_GREATER_OR_EQUAL_TO_4_LENGTH_REQUIRED: 'GREATER_OR_EQUAL_TO_4_LENGTH_REQUIRED',
+ LIB_BYTES_GREATER_OR_EQUAL_TO_20_LENGTH_REQUIRED: 'GREATER_OR_EQUAL_TO_20_LENGTH_REQUIRED',
+ LIB_BYTES_GREATER_OR_EQUAL_TO_32_LENGTH_REQUIRED: 'GREATER_OR_EQUAL_TO_32_LENGTH_REQUIRED',
+ LIB_BYTES_GREATER_OR_EQUAL_TO_NESTED_BYTES_LENGTH_REQUIRED: 'GREATER_OR_EQUAL_TO_NESTED_BYTES_LENGTH_REQUIRED',
ERC20_INSUFFICIENT_BALANCE: 'Insufficient balance to complete transfer.',
ERC20_INSUFFICIENT_ALLOWANCE: 'Insufficient allowance to complete transfer.',
TESTRPC_NETWORK_ID: 50,
diff --git a/packages/contracts/test/libraries/lib_bytes.ts b/packages/contracts/test/libraries/lib_bytes.ts
index 8334d856b..a3da5baac 100644
--- a/packages/contracts/test/libraries/lib_bytes.ts
+++ b/packages/contracts/test/libraries/lib_bytes.ts
@@ -91,7 +91,7 @@ describe('LibBytes', () => {
it('should revert if length is 0', async () => {
return expectRevertOrOtherErrorAsync(
libBytes.publicPopByte.callAsync(constants.NULL_BYTES),
- constants.LIB_BYTES_GT_ZERO_LENGTH_REQUIRED,
+ constants.LIB_BYTES_GREATER_THAN_ZERO_LENGTH_REQUIRED,
);
});
@@ -108,7 +108,7 @@ describe('LibBytes', () => {
it('should revert if length is less than 20', async () => {
return expectRevertOrOtherErrorAsync(
libBytes.publicPopAddress.callAsync(byteArrayShorterThan20Bytes),
- constants.LIB_BYTES_GTE_20_LENGTH_REQUIRED,
+ constants.LIB_BYTES_GREATER_OR_EQUAL_TO_20_LENGTH_REQUIRED,
);
});
@@ -194,7 +194,7 @@ describe('LibBytes', () => {
const offset = new BigNumber(0);
return expectRevertOrOtherErrorAsync(
libBytes.publicReadAddress.callAsync(shortByteArray, offset),
- constants.LIB_BYTES_GTE_20_LENGTH_REQUIRED,
+ constants.LIB_BYTES_GREATER_OR_EQUAL_TO_20_LENGTH_REQUIRED,
);
});
@@ -203,7 +203,7 @@ describe('LibBytes', () => {
const badOffset = new BigNumber(ethUtil.toBuffer(byteArray).byteLength);
return expectRevertOrOtherErrorAsync(
libBytes.publicReadAddress.callAsync(byteArray, badOffset),
- constants.LIB_BYTES_GTE_20_LENGTH_REQUIRED,
+ constants.LIB_BYTES_GREATER_OR_EQUAL_TO_20_LENGTH_REQUIRED,
);
});
});
@@ -240,7 +240,7 @@ describe('LibBytes', () => {
const offset = new BigNumber(0);
return expectRevertOrOtherErrorAsync(
libBytes.publicReadBytes32.callAsync(byteArrayShorterThan32Bytes, offset),
- constants.LIB_BYTES_GTE_32_LENGTH_REQUIRED,
+ constants.LIB_BYTES_GREATER_OR_EQUAL_TO_32_LENGTH_REQUIRED,
);
});
@@ -248,7 +248,7 @@ describe('LibBytes', () => {
const badOffset = new BigNumber(ethUtil.toBuffer(testBytes32).byteLength);
return expectRevertOrOtherErrorAsync(
libBytes.publicReadBytes32.callAsync(testBytes32, badOffset),
- constants.LIB_BYTES_GTE_32_LENGTH_REQUIRED,
+ constants.LIB_BYTES_GREATER_OR_EQUAL_TO_32_LENGTH_REQUIRED,
);
});
});
@@ -289,7 +289,7 @@ describe('LibBytes', () => {
const offset = new BigNumber(0);
return expectRevertOrOtherErrorAsync(
libBytes.publicReadUint256.callAsync(byteArrayShorterThan32Bytes, offset),
- constants.LIB_BYTES_GTE_32_LENGTH_REQUIRED,
+ constants.LIB_BYTES_GREATER_OR_EQUAL_TO_32_LENGTH_REQUIRED,
);
});
@@ -300,7 +300,7 @@ describe('LibBytes', () => {
const badOffset = new BigNumber(testUint256AsBuffer.byteLength);
return expectRevertOrOtherErrorAsync(
libBytes.publicReadUint256.callAsync(byteArray, badOffset),
- constants.LIB_BYTES_GTE_32_LENGTH_REQUIRED,
+ constants.LIB_BYTES_GREATER_OR_EQUAL_TO_32_LENGTH_REQUIRED,
);
});
});
@@ -322,7 +322,7 @@ describe('LibBytes', () => {
const byteArrayLessThan4Bytes = '0x010101';
return expectRevertOrOtherErrorAsync(
libBytes.publicReadFirst4.callAsync(byteArrayLessThan4Bytes),
- constants.LIB_BYTES_GTE_4_LENGTH_REQUIRED,
+ constants.LIB_BYTES_GREATER_OR_EQUAL_TO_4_LENGTH_REQUIRED,
);
});
it('should return the first 4 bytes of a byte array of arbitrary length', async () => {
@@ -381,30 +381,36 @@ describe('LibBytes', () => {
return expect(bytes).to.be.equal(longData);
});
- it('should fail if the byte array is too short to hold the length of a nested byte array)', async () => {
+ it('should fail if the byte array is too short to hold the length of a nested byte array', async () => {
// The length of the nested array is 32 bytes. By storing less than 32 bytes, a length cannot be read.
const offset = new BigNumber(0);
- return expectRevertOrAlwaysFailingTransactionAsync(
+ return expectRevertOrOtherErrorAsync(
libBytes.publicReadBytes.callAsync(byteArrayShorterThan32Bytes, offset),
+ constants.LIB_BYTES_GREATER_OR_EQUAL_TO_32_LENGTH_REQUIRED,
);
});
- it('should fail if we store a nested byte array length, without a nested byte array)', async () => {
+ it('should fail if we store a nested byte array length, without a nested byte array', async () => {
const offset = new BigNumber(0);
- return expectRevertOrAlwaysFailingTransactionAsync(libBytes.publicReadBytes.callAsync(testBytes32, offset));
+ return expectRevertOrOtherErrorAsync(
+ libBytes.publicReadBytes.callAsync(testBytes32, offset),
+ constants.LIB_BYTES_GREATER_OR_EQUAL_TO_NESTED_BYTES_LENGTH_REQUIRED,
+ );
});
- it('should fail if the length between the offset and end of the byte array is too short to hold the length of a nested byte array)', async () => {
+ it('should fail if the length between the offset and end of the byte array is too short to hold the length of a nested byte array', async () => {
const badOffset = new BigNumber(ethUtil.toBuffer(byteArrayShorterThan32Bytes).byteLength);
- return expectRevertOrAlwaysFailingTransactionAsync(
+ return expectRevertOrOtherErrorAsync(
libBytes.publicReadBytes.callAsync(byteArrayShorterThan32Bytes, badOffset),
+ constants.LIB_BYTES_GREATER_OR_EQUAL_TO_32_LENGTH_REQUIRED,
);
});
- it('should fail if the length between the offset and end of the byte array is too short to hold the nested byte array)', async () => {
+ it('should fail if the length between the offset and end of the byte array is too short to hold the nested byte array', async () => {
const badOffset = new BigNumber(ethUtil.toBuffer(testBytes32).byteLength);
- return expectRevertOrAlwaysFailingTransactionAsync(
+ return expectRevertOrOtherErrorAsync(
libBytes.publicReadBytes.callAsync(testBytes32, badOffset),
+ constants.LIB_BYTES_GREATER_OR_EQUAL_TO_32_LENGTH_REQUIRED,
);
});
});
@@ -435,7 +441,7 @@ describe('LibBytes', () => {
return expect(bytes).to.be.equal(shortData);
});
- it('should successfully write a nested array of bytes - one word in length - when it takes up the whole array)', async () => {
+ it('should successfully write a nested array of bytes - one word in length - when it takes up the whole array', async () => {
const testBytesOffset = new BigNumber(0);
const emptyByteArray = ethUtil.bufferToHex(new Buffer(wordOfTestBytesAsBuffer.byteLength));
const bytesWritten = await libBytes.publicWriteBytes.callAsync(emptyByteArray, testBytesOffset, wordOfData);
@@ -460,7 +466,7 @@ describe('LibBytes', () => {
return expect(bytes).to.be.equal(wordOfData);
});
- it('should successfully write a long, nested bytes when it takes up the whole array)', async () => {
+ it('should successfully write a long, nested bytes when it takes up the whole array', async () => {
const testBytesOffset = new BigNumber(0);
const emptyByteArray = ethUtil.bufferToHex(new Buffer(longTestBytesAsBuffer.byteLength));
const bytesWritten = await libBytes.publicWriteBytes.callAsync(emptyByteArray, testBytesOffset, longData);
@@ -485,19 +491,21 @@ describe('LibBytes', () => {
return expect(bytes).to.be.equal(longData);
});
- it('should fail if the byte array is too short to hold the length of a nested byte array)', async () => {
+ it('should fail if the byte array is too short to hold the length of a nested byte array', async () => {
const offset = new BigNumber(0);
const emptyByteArray = ethUtil.bufferToHex(new Buffer(1));
- return expectRevertOrAlwaysFailingTransactionAsync(
+ return expectRevertOrOtherErrorAsync(
libBytes.publicWriteBytes.callAsync(emptyByteArray, offset, longData),
+ constants.LIB_BYTES_GREATER_OR_EQUAL_TO_NESTED_BYTES_LENGTH_REQUIRED,
);
});
it('should fail if the length between the offset and end of the byte array is too short to hold the length of a nested byte array)', async () => {
const emptyByteArray = ethUtil.bufferToHex(new Buffer(shortTestBytesAsBuffer.byteLength));
const badOffset = new BigNumber(ethUtil.toBuffer(shortTestBytesAsBuffer).byteLength);
- return expectRevertOrAlwaysFailingTransactionAsync(
+ return expectRevertOrOtherErrorAsync(
libBytes.publicWriteBytes.callAsync(emptyByteArray, badOffset, shortData),
+ constants.LIB_BYTES_GREATER_OR_EQUAL_TO_NESTED_BYTES_LENGTH_REQUIRED,
);
});
});