aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGreg Hysen <greg.hysen@gmail.com>2018-08-30 04:14:51 +0800
committerGreg Hysen <greg.hysen@gmail.com>2018-08-30 04:14:51 +0800
commit62b93cf2ebf242ea5b432daddc030b24da46421f (patch)
tree49bb45c35c2697be40191d15d2c3893213795b51
parent8c803ab232d094c2f69d3b2d44cae11f153d2d5f (diff)
downloaddexon-sol-tools-62b93cf2ebf242ea5b432daddc030b24da46421f.tar.gz
dexon-sol-tools-62b93cf2ebf242ea5b432daddc030b24da46421f.tar.zst
dexon-sol-tools-62b93cf2ebf242ea5b432daddc030b24da46421f.zip
More tests for LibBytes
-rw-r--r--packages/contracts/test/libraries/lib_bytes.ts19
1 files changed, 16 insertions, 3 deletions
diff --git a/packages/contracts/test/libraries/lib_bytes.ts b/packages/contracts/test/libraries/lib_bytes.ts
index 6fda9dc97..646875f1e 100644
--- a/packages/contracts/test/libraries/lib_bytes.ts
+++ b/packages/contracts/test/libraries/lib_bytes.ts
@@ -42,7 +42,7 @@ describe('LibBytes', () => {
const testUint256 = new BigNumber(testBytes32, 16);
const testUint256B = new BigNumber(testBytes32B, 16);
const testBytes4 = '0xabcdef12';
- const testBytes4B = new BigNumber(testBytes4, 16);
+ const testByte = '0xab';
let shortData: string;
let shortTestBytes: string;
let shortTestBytesAsBuffer: Buffer;
@@ -108,13 +108,19 @@ describe('LibBytes', () => {
RevertReason.LibBytesGreaterThanZeroLengthRequired,
);
});
- it('should pop the last byte from the input and return it', async () => {
+ it('should pop the last byte from the input and return it when array holds more than 1 byte', async () => {
const [newBytes, poppedByte] = await libBytes.publicPopLastByte.callAsync(byteArrayLongerThan32Bytes);
const expectedNewBytes = byteArrayLongerThan32Bytes.slice(0, -2);
const expectedPoppedByte = `0x${byteArrayLongerThan32Bytes.slice(-2)}`;
expect(newBytes).to.equal(expectedNewBytes);
expect(poppedByte).to.equal(expectedPoppedByte);
});
+ it('should pop the last byte from the input and return it when array is exactly one', async () => {
+ const [newBytes, poppedByte] = await libBytes.publicPopLastByte.callAsync(testByte);
+ const expectedNewBytes = '0x';
+ expect(newBytes).to.equal(expectedNewBytes);
+ return expect(poppedByte).to.be.equal(testByte);
+ });
});
describe('popLast20Bytes', () => {
@@ -124,13 +130,20 @@ describe('LibBytes', () => {
RevertReason.LibBytesGreaterOrEqualTo20LengthRequired,
);
});
- it('should pop the last 20 bytes from the input and return it', async () => {
+ it('should pop the last 20 bytes from the input and return it when array holds more than one byte', async () => {
const [newBytes, poppedAddress] = await libBytes.publicPopLast20Bytes.callAsync(byteArrayLongerThan32Bytes);
const expectedNewBytes = byteArrayLongerThan32Bytes.slice(0, -40);
const expectedPoppedAddress = `0x${byteArrayLongerThan32Bytes.slice(-40)}`;
expect(newBytes).to.equal(expectedNewBytes);
expect(poppedAddress).to.equal(expectedPoppedAddress);
});
+ it('should pop the last 20 bytes from the input and return it when array is exactly 20 bytes', async () => {
+ const [newBytes, poppedAddress] = await libBytes.publicPopLast20Bytes.callAsync(testAddress);
+ const expectedNewBytes = '0x';
+ const expectedPoppedAddress = testAddress;
+ expect(newBytes).to.equal(expectedNewBytes);
+ expect(poppedAddress).to.equal(expectedPoppedAddress);
+ });
});
describe('equals', () => {