Updated LibBytes error messages
This commit is contained in:
parent
d62ff34a5a
commit
05123ea6f4
@ -26,7 +26,7 @@ contract LibBytes is
|
|||||||
|
|
||||||
// Revert reasons
|
// Revert reasons
|
||||||
string constant GREATER_THAN_ZERO_LENGTH_REQUIRED = "GREATER_THAN_ZERO_LENGTH_REQUIRED";
|
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_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_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";
|
string constant GREATER_OR_EQUAL_TO_NESTED_BYTES_LENGTH_REQUIRED = "GREATER_OR_EQUAL_TO_NESTED_BYTES_LENGTH_REQUIRED";
|
||||||
|
@ -19,11 +19,11 @@ const TESTRPC_PRIVATE_KEYS_STRINGS = [
|
|||||||
export const constants = {
|
export const constants = {
|
||||||
INVALID_OPCODE: 'invalid opcode',
|
INVALID_OPCODE: 'invalid opcode',
|
||||||
REVERT: 'revert',
|
REVERT: 'revert',
|
||||||
LIB_BYTES_GT_ZERO_LENGTH_REQUIRED: 'Length must be greater than 0.',
|
LIB_BYTES_GREATER_THAN_ZERO_LENGTH_REQUIRED: 'GREATER_THAN_ZERO_LENGTH_REQUIRED',
|
||||||
LIB_BYTES_GTE_4_LENGTH_REQUIRED: 'Length must be greater than or equal to 4.',
|
LIB_BYTES_GREATER_OR_EQUAL_TO_4_LENGTH_REQUIRED: 'GREATER_OR_EQUAL_TO_4_LENGTH_REQUIRED',
|
||||||
LIB_BYTES_GTE_20_LENGTH_REQUIRED: 'Length must be greater than or equal to 20.',
|
LIB_BYTES_GREATER_OR_EQUAL_TO_20_LENGTH_REQUIRED: 'GREATER_OR_EQUAL_TO_20_LENGTH_REQUIRED',
|
||||||
LIB_BYTES_GTE_32_LENGTH_REQUIRED: 'Length must be greater than or equal to 32.',
|
LIB_BYTES_GREATER_OR_EQUAL_TO_32_LENGTH_REQUIRED: 'GREATER_OR_EQUAL_TO_32_LENGTH_REQUIRED',
|
||||||
LIB_BYTES_INDEX_OUT_OF_BOUNDS: 'Specified array index is out of bounds.',
|
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_BALANCE: 'Insufficient balance to complete transfer.',
|
||||||
ERC20_INSUFFICIENT_ALLOWANCE: 'Insufficient allowance to complete transfer.',
|
ERC20_INSUFFICIENT_ALLOWANCE: 'Insufficient allowance to complete transfer.',
|
||||||
TESTRPC_NETWORK_ID: 50,
|
TESTRPC_NETWORK_ID: 50,
|
||||||
|
@ -91,7 +91,7 @@ describe('LibBytes', () => {
|
|||||||
it('should revert if length is 0', async () => {
|
it('should revert if length is 0', async () => {
|
||||||
return expectRevertOrOtherErrorAsync(
|
return expectRevertOrOtherErrorAsync(
|
||||||
libBytes.publicPopByte.callAsync(constants.NULL_BYTES),
|
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 () => {
|
it('should revert if length is less than 20', async () => {
|
||||||
return expectRevertOrOtherErrorAsync(
|
return expectRevertOrOtherErrorAsync(
|
||||||
libBytes.publicPopAddress.callAsync(byteArrayShorterThan20Bytes),
|
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);
|
const offset = new BigNumber(0);
|
||||||
return expectRevertOrOtherErrorAsync(
|
return expectRevertOrOtherErrorAsync(
|
||||||
libBytes.publicReadAddress.callAsync(shortByteArray, offset),
|
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);
|
const badOffset = new BigNumber(ethUtil.toBuffer(byteArray).byteLength);
|
||||||
return expectRevertOrOtherErrorAsync(
|
return expectRevertOrOtherErrorAsync(
|
||||||
libBytes.publicReadAddress.callAsync(byteArray, badOffset),
|
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);
|
const offset = new BigNumber(0);
|
||||||
return expectRevertOrOtherErrorAsync(
|
return expectRevertOrOtherErrorAsync(
|
||||||
libBytes.publicReadBytes32.callAsync(byteArrayShorterThan32Bytes, offset),
|
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);
|
const badOffset = new BigNumber(ethUtil.toBuffer(testBytes32).byteLength);
|
||||||
return expectRevertOrOtherErrorAsync(
|
return expectRevertOrOtherErrorAsync(
|
||||||
libBytes.publicReadBytes32.callAsync(testBytes32, badOffset),
|
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);
|
const offset = new BigNumber(0);
|
||||||
return expectRevertOrOtherErrorAsync(
|
return expectRevertOrOtherErrorAsync(
|
||||||
libBytes.publicReadUint256.callAsync(byteArrayShorterThan32Bytes, offset),
|
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);
|
const badOffset = new BigNumber(testUint256AsBuffer.byteLength);
|
||||||
return expectRevertOrOtherErrorAsync(
|
return expectRevertOrOtherErrorAsync(
|
||||||
libBytes.publicReadUint256.callAsync(byteArray, badOffset),
|
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';
|
const byteArrayLessThan4Bytes = '0x010101';
|
||||||
return expectRevertOrOtherErrorAsync(
|
return expectRevertOrOtherErrorAsync(
|
||||||
libBytes.publicReadFirst4.callAsync(byteArrayLessThan4Bytes),
|
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 () => {
|
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);
|
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.
|
// 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);
|
const offset = new BigNumber(0);
|
||||||
return expectRevertOrAlwaysFailingTransactionAsync(
|
return expectRevertOrOtherErrorAsync(
|
||||||
libBytes.publicReadBytes.callAsync(byteArrayShorterThan32Bytes, offset),
|
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);
|
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 () => {
|
|
||||||
const badOffset = new BigNumber(ethUtil.toBuffer(byteArrayShorterThan32Bytes).byteLength);
|
|
||||||
return expectRevertOrAlwaysFailingTransactionAsync(
|
|
||||||
libBytes.publicReadBytes.callAsync(byteArrayShorterThan32Bytes, badOffset),
|
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
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 length of a nested byte array', async () => {
|
||||||
|
const badOffset = new BigNumber(ethUtil.toBuffer(byteArrayShorterThan32Bytes).byteLength);
|
||||||
|
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 () => {
|
||||||
const badOffset = new BigNumber(ethUtil.toBuffer(testBytes32).byteLength);
|
const badOffset = new BigNumber(ethUtil.toBuffer(testBytes32).byteLength);
|
||||||
return expectRevertOrAlwaysFailingTransactionAsync(
|
return expectRevertOrOtherErrorAsync(
|
||||||
libBytes.publicReadBytes.callAsync(testBytes32, badOffset),
|
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);
|
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 testBytesOffset = new BigNumber(0);
|
||||||
const emptyByteArray = ethUtil.bufferToHex(new Buffer(wordOfTestBytesAsBuffer.byteLength));
|
const emptyByteArray = ethUtil.bufferToHex(new Buffer(wordOfTestBytesAsBuffer.byteLength));
|
||||||
const bytesWritten = await libBytes.publicWriteBytes.callAsync(emptyByteArray, testBytesOffset, wordOfData);
|
const bytesWritten = await libBytes.publicWriteBytes.callAsync(emptyByteArray, testBytesOffset, wordOfData);
|
||||||
@ -460,7 +466,7 @@ describe('LibBytes', () => {
|
|||||||
return expect(bytes).to.be.equal(wordOfData);
|
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 testBytesOffset = new BigNumber(0);
|
||||||
const emptyByteArray = ethUtil.bufferToHex(new Buffer(longTestBytesAsBuffer.byteLength));
|
const emptyByteArray = ethUtil.bufferToHex(new Buffer(longTestBytesAsBuffer.byteLength));
|
||||||
const bytesWritten = await libBytes.publicWriteBytes.callAsync(emptyByteArray, testBytesOffset, longData);
|
const bytesWritten = await libBytes.publicWriteBytes.callAsync(emptyByteArray, testBytesOffset, longData);
|
||||||
@ -485,19 +491,21 @@ describe('LibBytes', () => {
|
|||||||
return expect(bytes).to.be.equal(longData);
|
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 offset = new BigNumber(0);
|
||||||
const emptyByteArray = ethUtil.bufferToHex(new Buffer(1));
|
const emptyByteArray = ethUtil.bufferToHex(new Buffer(1));
|
||||||
return expectRevertOrAlwaysFailingTransactionAsync(
|
return expectRevertOrOtherErrorAsync(
|
||||||
libBytes.publicWriteBytes.callAsync(emptyByteArray, offset, longData),
|
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 () => {
|
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 emptyByteArray = ethUtil.bufferToHex(new Buffer(shortTestBytesAsBuffer.byteLength));
|
||||||
const badOffset = new BigNumber(ethUtil.toBuffer(shortTestBytesAsBuffer).byteLength);
|
const badOffset = new BigNumber(ethUtil.toBuffer(shortTestBytesAsBuffer).byteLength);
|
||||||
return expectRevertOrAlwaysFailingTransactionAsync(
|
return expectRevertOrOtherErrorAsync(
|
||||||
libBytes.publicWriteBytes.callAsync(emptyByteArray, badOffset, shortData),
|
libBytes.publicWriteBytes.callAsync(emptyByteArray, badOffset, shortData),
|
||||||
|
constants.LIB_BYTES_GREATER_OR_EQUAL_TO_NESTED_BYTES_LENGTH_REQUIRED,
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user