Use last byte of signature as signature type

This commit is contained in:
Amir Bandeali
2018-05-21 15:59:58 -07:00
parent 6d462fc961
commit 822e319efe
8 changed files with 106 additions and 109 deletions

View File

@@ -22,6 +22,7 @@ describe('LibBytes', () => {
let owner: string;
let libBytes: TestLibBytesContract;
const byteArrayShorterThan32Bytes = '0x012345';
const byteArrayShorterThan20Bytes = byteArrayShorterThan32Bytes;
const byteArrayLongerThan32Bytes =
'0x0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef';
const byteArrayLongerThan32BytesFirstBytesSwapped =
@@ -60,39 +61,35 @@ describe('LibBytes', () => {
await blockchainLifecycle.revertAsync();
});
describe('deepCopyBytes', () => {
const byteArrayLongerThan32BytesLen = (byteArrayLongerThan32Bytes.length - 2) / 2;
it('should return a byte array of length 0 if len is 0', async () => {
const index = new BigNumber(0);
const len = new BigNumber(0);
const copy = await libBytes.publicDeepCopyBytes.callAsync(byteArrayLongerThan32Bytes, index, len);
expect(copy).to.equal(constants.NULL_BYTES);
describe('popByte', () => {
it('should revert if length is 0', async () => {
return expect(libBytes.publicPopByte.callAsync(constants.NULL_BYTES)).to.be.rejectedWith(constants.REVERT);
});
it('should throw if start index + length to copy is greater than length of byte array', async () => {
const index = new BigNumber(0);
const len = new BigNumber(byteArrayLongerThan32BytesLen + 1);
return expect(
libBytes.publicDeepCopyBytes.callAsync(byteArrayLongerThan32Bytes, index, len),
).to.be.rejectedWith(constants.REVERT);
});
it('should copy the entire byte array if index = 0 and len = b.length', async () => {
const index = new BigNumber(0);
const len = new BigNumber(byteArrayLongerThan32BytesLen);
const copy = await libBytes.publicDeepCopyBytes.callAsync(byteArrayLongerThan32Bytes, index, len);
expect(copy).to.equal(byteArrayLongerThan32Bytes);
});
it('should copy part of the byte array if area to copy is less than b.length', async () => {
const index = new BigNumber(10);
const len = new BigNumber(4);
const copy = await libBytes.publicDeepCopyBytes.callAsync(byteArrayLongerThan32Bytes, index, len);
const expectedCopy = `0x${byteArrayLongerThan32Bytes.slice(22, 30)}`;
expect(copy).to.equal(expectedCopy);
it('should pop the last byte from the input and return it', async () => {
const [newBytes, poppedByte] = await libBytes.publicPopByte.callAsync(byteArrayLongerThan32Bytes);
const expectedNewBytes = byteArrayLongerThan32Bytes.slice(0, -2);
const expectedPoppedByte = `0x${byteArrayLongerThan32Bytes.slice(-2)}`;
expect(newBytes).to.equal(expectedNewBytes);
expect(poppedByte).to.equal(expectedPoppedByte);
});
});
describe('popAddress', () => {
it('should revert if length is less than 20', async () => {
return expect(libBytes.publicPopAddress.callAsync(byteArrayShorterThan20Bytes)).to.be.rejectedWith(
constants.REVERT,
);
});
it('should pop the last 20 bytes from the input and return it', async () => {
const [newBytes, poppedAddress] = await libBytes.publicPopAddress.callAsync(byteArrayLongerThan32Bytes);
const expectedNewBytes = byteArrayLongerThan32Bytes.slice(0, -40);
const expectedPoppedAddress = `0x${byteArrayLongerThan32Bytes.slice(-40)}`;
expect(newBytes).to.equal(expectedNewBytes);
expect(poppedAddress).to.equal(expectedPoppedAddress);
});
});
describe('areBytesEqual', () => {
it('should return true if byte arrays are equal (both arrays < 32 bytes)', async () => {
const areBytesEqual = await libBytes.publicAreBytesEqual.callAsync(