Add more slice tests
This commit is contained in:
@@ -883,7 +883,16 @@ describe('LibBytes', () => {
|
||||
it('should return a byte array of length 0 if from == to', async () => {
|
||||
const from = new BigNumber(0);
|
||||
const to = from;
|
||||
const result = await libBytes.publicSlice.callAsync(byteArrayLongerThan32Bytes, from, to);
|
||||
const [result, original] = await libBytes.publicSlice.callAsync(byteArrayLongerThan32Bytes, from, to);
|
||||
expect(original).to.eq(byteArrayLongerThan32Bytes);
|
||||
expect(result).to.eq(constants.NULL_BYTES);
|
||||
});
|
||||
it('should return a byte array of length 0 if from == to == b.length', async () => {
|
||||
const byteLen = (byteArrayLongerThan32Bytes.length - 2) / 2;
|
||||
const from = new BigNumber(byteLen);
|
||||
const to = from;
|
||||
const [result, original] = await libBytes.publicSlice.callAsync(byteArrayLongerThan32Bytes, from, to);
|
||||
expect(original).to.eq(byteArrayLongerThan32Bytes);
|
||||
expect(result).to.eq(constants.NULL_BYTES);
|
||||
});
|
||||
it('should revert if to > input.length', async () => {
|
||||
@@ -898,15 +907,17 @@ describe('LibBytes', () => {
|
||||
it('should slice a section of the input', async () => {
|
||||
const from = new BigNumber(1);
|
||||
const to = new BigNumber(2);
|
||||
const result = await libBytes.publicSlice.callAsync(byteArrayLongerThan32Bytes, from, to);
|
||||
const [result, original] = await libBytes.publicSlice.callAsync(byteArrayLongerThan32Bytes, from, to);
|
||||
const expectedResult = `0x${byteArrayLongerThan32Bytes.slice(4, 6)}`;
|
||||
expect(original).to.eq(byteArrayLongerThan32Bytes);
|
||||
expect(result).to.eq(expectedResult);
|
||||
});
|
||||
it('should copy the entire input if from = 0 and to = input.length', async () => {
|
||||
const byteLen = (byteArrayLongerThan32Bytes.length - 2) / 2;
|
||||
const from = new BigNumber(0);
|
||||
const to = new BigNumber(byteLen);
|
||||
const result = await libBytes.publicSlice.callAsync(byteArrayLongerThan32Bytes, from, to);
|
||||
const [result, original] = await libBytes.publicSlice.callAsync(byteArrayLongerThan32Bytes, from, to);
|
||||
expect(original).to.eq(byteArrayLongerThan32Bytes);
|
||||
expect(result).to.eq(byteArrayLongerThan32Bytes);
|
||||
});
|
||||
});
|
||||
@@ -923,7 +934,14 @@ describe('LibBytes', () => {
|
||||
it('should return a byte array of length 0 if from == to', async () => {
|
||||
const from = new BigNumber(0);
|
||||
const to = from;
|
||||
const result = await libBytes.publicSliceDestructive.callAsync(byteArrayLongerThan32Bytes, from, to);
|
||||
const [result] = await libBytes.publicSliceDestructive.callAsync(byteArrayLongerThan32Bytes, from, to);
|
||||
expect(result).to.eq(constants.NULL_BYTES);
|
||||
});
|
||||
it('should return a byte array of length 0 if from == to == b.length', async () => {
|
||||
const byteLen = (byteArrayLongerThan32Bytes.length - 2) / 2;
|
||||
const from = new BigNumber(byteLen);
|
||||
const to = from;
|
||||
const [result] = await libBytes.publicSliceDestructive.callAsync(byteArrayLongerThan32Bytes, from, to);
|
||||
expect(result).to.eq(constants.NULL_BYTES);
|
||||
});
|
||||
it('should revert if to > input.length', async () => {
|
||||
@@ -938,7 +956,7 @@ describe('LibBytes', () => {
|
||||
it('should slice a section of the input', async () => {
|
||||
const from = new BigNumber(1);
|
||||
const to = new BigNumber(2);
|
||||
const result = await libBytes.publicSliceDestructive.callAsync(byteArrayLongerThan32Bytes, from, to);
|
||||
const [result] = await libBytes.publicSliceDestructive.callAsync(byteArrayLongerThan32Bytes, from, to);
|
||||
const expectedResult = `0x${byteArrayLongerThan32Bytes.slice(4, 6)}`;
|
||||
expect(result).to.eq(expectedResult);
|
||||
});
|
||||
@@ -946,7 +964,7 @@ describe('LibBytes', () => {
|
||||
const byteLen = (byteArrayLongerThan32Bytes.length - 2) / 2;
|
||||
const from = new BigNumber(0);
|
||||
const to = new BigNumber(byteLen);
|
||||
const result = await libBytes.publicSliceDestructive.callAsync(byteArrayLongerThan32Bytes, from, to);
|
||||
const [result] = await libBytes.publicSliceDestructive.callAsync(byteArrayLongerThan32Bytes, from, to);
|
||||
expect(result).to.eq(byteArrayLongerThan32Bytes);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user