aboutsummaryrefslogtreecommitdiffstats
path: root/packages/contracts/test/libraries
diff options
context:
space:
mode:
authorAmir Bandeali <abandeali1@gmail.com>2018-05-31 08:53:22 +0800
committerGitHub <noreply@github.com>2018-05-31 08:53:22 +0800
commit5b31d0aa3635ea524fb42d73cd6c713887dfef6a (patch)
tree5d80666f6521737879e2e700afd5ef1d1a55b0e6 /packages/contracts/test/libraries
parentc0cf55b40bb4a13cfd94a506bf125f6eb57c6767 (diff)
parent79e7c44884f81f12733d555314c54d4c912f0e88 (diff)
downloaddexon-sol-tools-5b31d0aa3635ea524fb42d73cd6c713887dfef6a.tar.gz
dexon-sol-tools-5b31d0aa3635ea524fb42d73cd6c713887dfef6a.tar.zst
dexon-sol-tools-5b31d0aa3635ea524fb42d73cd6c713887dfef6a.zip
Merge pull request #561 from 0xProject/feature/contracts/txorigin
Add Validator signature type
Diffstat (limited to 'packages/contracts/test/libraries')
-rw-r--r--packages/contracts/test/libraries/lib_bytes.ts31
1 files changed, 31 insertions, 0 deletions
diff --git a/packages/contracts/test/libraries/lib_bytes.ts b/packages/contracts/test/libraries/lib_bytes.ts
index 968bac300..e817951ab 100644
--- a/packages/contracts/test/libraries/lib_bytes.ts
+++ b/packages/contracts/test/libraries/lib_bytes.ts
@@ -22,6 +22,7 @@ describe('LibBytes', () => {
let owner: string;
let libBytes: TestLibBytesContract;
const byteArrayShorterThan32Bytes = '0x012345';
+ const byteArrayShorterThan20Bytes = byteArrayShorterThan32Bytes;
const byteArrayLongerThan32Bytes =
'0x0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef';
const byteArrayLongerThan32BytesFirstBytesSwapped =
@@ -60,6 +61,36 @@ describe('LibBytes', () => {
await blockchainLifecycle.revertAsync();
});
+ 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 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(