Fix tests

This commit is contained in:
Amir Bandeali
2019-09-02 14:36:27 -07:00
parent b3b0496c49
commit 48dfb3317a
3 changed files with 52 additions and 11 deletions

View File

@@ -668,7 +668,7 @@ describe('LibBytes', () => {
describe('writeBytesWithLength', () => {
it('should successfully write short, nested array of bytes when it takes up the whole array', async () => {
const testBytesOffset = new BigNumber(0);
const emptyByteArray = ethUtil.bufferToHex(ethUtil.toBuffer(shortTestBytesAsBuffer.byteLength));
const emptyByteArray = ethUtil.bufferToHex(Buffer.alloc(shortTestBytesAsBuffer.byteLength));
const bytesWritten = await libBytes.publicWriteBytesWithLength.callAsync(
emptyByteArray,
testBytesOffset,
@@ -683,7 +683,7 @@ describe('LibBytes', () => {
const prefixDataAsBuffer = ethUtil.toBuffer(prefixData);
const prefixOffset = new BigNumber(0);
const emptyByteArray = ethUtil.bufferToHex(
ethUtil.toBuffer(prefixDataAsBuffer.byteLength + shortTestBytesAsBuffer.byteLength),
Buffer.alloc(prefixDataAsBuffer.byteLength + shortTestBytesAsBuffer.byteLength),
);
let bytesWritten = await libBytes.publicWriteBytesWithLength.callAsync(
emptyByteArray,
@@ -703,7 +703,7 @@ describe('LibBytes', () => {
});
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(ethUtil.toBuffer(wordOfTestBytesAsBuffer.byteLength));
const emptyByteArray = ethUtil.bufferToHex(Buffer.alloc(wordOfTestBytesAsBuffer.byteLength));
const bytesWritten = await libBytes.publicWriteBytesWithLength.callAsync(
emptyByteArray,
testBytesOffset,
@@ -718,7 +718,7 @@ describe('LibBytes', () => {
const prefixDataAsBuffer = ethUtil.toBuffer(prefixData);
const prefixOffset = new BigNumber(0);
const emptyByteArray = ethUtil.bufferToHex(
ethUtil.toBuffer(prefixDataAsBuffer.byteLength + wordOfTestBytesAsBuffer.byteLength),
Buffer.alloc(prefixDataAsBuffer.byteLength + wordOfTestBytesAsBuffer.byteLength),
);
let bytesWritten = await libBytes.publicWriteBytesWithLength.callAsync(
emptyByteArray,
@@ -738,7 +738,7 @@ describe('LibBytes', () => {
});
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(ethUtil.toBuffer(longTestBytesAsBuffer.byteLength));
const emptyByteArray = ethUtil.bufferToHex(Buffer.alloc(longTestBytesAsBuffer.byteLength));
const bytesWritten = await libBytes.publicWriteBytesWithLength.callAsync(
emptyByteArray,
testBytesOffset,
@@ -753,7 +753,7 @@ describe('LibBytes', () => {
const prefixDataAsBuffer = ethUtil.toBuffer(prefixData);
const prefixOffset = new BigNumber(0);
const emptyByteArray = ethUtil.bufferToHex(
ethUtil.toBuffer(prefixDataAsBuffer.byteLength + longTestBytesAsBuffer.byteLength),
Buffer.alloc(prefixDataAsBuffer.byteLength + longTestBytesAsBuffer.byteLength),
);
let bytesWritten = await libBytes.publicWriteBytesWithLength.callAsync(
emptyByteArray,
@@ -769,7 +769,7 @@ describe('LibBytes', () => {
});
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(ethUtil.toBuffer(1));
const emptyByteArray = ethUtil.bufferToHex(Buffer.alloc(1));
const inputLen = new BigNumber((longData.length - 2) / 2);
const expectedError = new LibBytesRevertErrors.InvalidByteOperationError(
LibBytesRevertErrors.InvalidByteOperationErrorCodes.LengthGreaterThanOrEqualsNestedBytesLengthRequired,
@@ -781,7 +781,7 @@ describe('LibBytes', () => {
).to.revertWith(expectedError);
});
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(ethUtil.toBuffer(shortTestBytesAsBuffer.byteLength));
const emptyByteArray = ethUtil.bufferToHex(Buffer.alloc(shortTestBytesAsBuffer.byteLength));
const badOffset = new BigNumber(ethUtil.toBuffer(shortTestBytesAsBuffer).byteLength);
const inputLen = new BigNumber((shortData.length - 2) / 2);
const expectedError = new LibBytesRevertErrors.InvalidByteOperationError(