update abi-gen with new method interfaces (#2325)
* update abi-gen with new method interfaces * wip: get all packages to build * wip: get all packages to build * Fix two contract wrapper calls * Export necessary types part of the contract wrapper public interfaces * Revive and fix wrapper_unit_tests * Remove duplicate type * Fix lib_exchange_rich_error_decoder tests * Fix remaining test failures in contracts-* packages * Prettier fixes * remove transactionHelper * lint and update changelogs * Fix prettier * Revert changes to reference docs * Add back changelog already published and add revert changelog entry * Add missing CHANGELOG entries * Add missing comma * Update mesh-rpc-client dep * Update Mesh RPC logic in @0x/orderbook to v6.0.1-beta * Align package versions
This commit is contained in:
@@ -47,68 +47,68 @@ describe('Authorizable', () => {
|
||||
describe('addAuthorizedAddress', () => {
|
||||
it('should revert if not called by owner', async () => {
|
||||
const expectedError = new OwnableRevertErrors.OnlyOwnerError(notOwner, owner);
|
||||
const tx = authorizable.addAuthorizedAddress.sendTransactionAsync(notOwner, { from: notOwner });
|
||||
const tx = authorizable.addAuthorizedAddress(notOwner).sendTransactionAsync({ from: notOwner });
|
||||
return expect(tx).to.revertWith(expectedError);
|
||||
});
|
||||
|
||||
it('should allow owner to add an authorized address', async () => {
|
||||
await authorizable.addAuthorizedAddress.awaitTransactionSuccessAsync(address, { from: owner });
|
||||
const isAuthorized = await authorizable.authorized.callAsync(address);
|
||||
await authorizable.addAuthorizedAddress(address).awaitTransactionSuccessAsync({ from: owner });
|
||||
const isAuthorized = await authorizable.authorized(address).callAsync();
|
||||
expect(isAuthorized).to.be.true();
|
||||
});
|
||||
|
||||
it('should revert if owner attempts to authorize the zero address', async () => {
|
||||
const expectedError = new AuthorizableRevertErrors.ZeroCantBeAuthorizedError();
|
||||
const tx = authorizable.addAuthorizedAddress.sendTransactionAsync(constants.NULL_ADDRESS, { from: owner });
|
||||
const tx = authorizable.addAuthorizedAddress(constants.NULL_ADDRESS).sendTransactionAsync({ from: owner });
|
||||
return expect(tx).to.revertWith(expectedError);
|
||||
});
|
||||
|
||||
it('should revert if owner attempts to authorize a duplicate address', async () => {
|
||||
await authorizable.addAuthorizedAddress.awaitTransactionSuccessAsync(address, { from: owner });
|
||||
await authorizable.addAuthorizedAddress(address).awaitTransactionSuccessAsync({ from: owner });
|
||||
const expectedError = new AuthorizableRevertErrors.TargetAlreadyAuthorizedError(address);
|
||||
const tx = authorizable.addAuthorizedAddress.sendTransactionAsync(address, { from: owner });
|
||||
const tx = authorizable.addAuthorizedAddress(address).sendTransactionAsync({ from: owner });
|
||||
return expect(tx).to.revertWith(expectedError);
|
||||
});
|
||||
});
|
||||
|
||||
describe('removeAuthorizedAddress', () => {
|
||||
it('should revert if not called by owner', async () => {
|
||||
await authorizable.addAuthorizedAddress.awaitTransactionSuccessAsync(address, { from: owner });
|
||||
await authorizable.addAuthorizedAddress(address).awaitTransactionSuccessAsync({ from: owner });
|
||||
const expectedError = new OwnableRevertErrors.OnlyOwnerError(notOwner, owner);
|
||||
const tx = authorizable.removeAuthorizedAddress.sendTransactionAsync(address, { from: notOwner });
|
||||
const tx = authorizable.removeAuthorizedAddress(address).sendTransactionAsync({ from: notOwner });
|
||||
return expect(tx).to.revertWith(expectedError);
|
||||
});
|
||||
|
||||
it('should allow owner to remove an authorized address', async () => {
|
||||
await authorizable.addAuthorizedAddress.awaitTransactionSuccessAsync(address, { from: owner });
|
||||
await authorizable.removeAuthorizedAddress.awaitTransactionSuccessAsync(address, { from: owner });
|
||||
const isAuthorized = await authorizable.authorized.callAsync(address);
|
||||
await authorizable.addAuthorizedAddress(address).awaitTransactionSuccessAsync({ from: owner });
|
||||
await authorizable.removeAuthorizedAddress(address).awaitTransactionSuccessAsync({ from: owner });
|
||||
const isAuthorized = await authorizable.authorized(address).callAsync();
|
||||
expect(isAuthorized).to.be.false();
|
||||
});
|
||||
|
||||
it('should revert if owner attempts to remove an address that is not authorized', async () => {
|
||||
const expectedError = new AuthorizableRevertErrors.TargetNotAuthorizedError(address);
|
||||
const tx = authorizable.removeAuthorizedAddress.sendTransactionAsync(address, { from: owner });
|
||||
const tx = authorizable.removeAuthorizedAddress(address).sendTransactionAsync({ from: owner });
|
||||
return expect(tx).to.revertWith(expectedError);
|
||||
});
|
||||
});
|
||||
|
||||
describe('removeAuthorizedAddressAtIndex', () => {
|
||||
it('should revert if not called by owner', async () => {
|
||||
await authorizable.addAuthorizedAddress.awaitTransactionSuccessAsync(address, { from: owner });
|
||||
await authorizable.addAuthorizedAddress(address).awaitTransactionSuccessAsync({ from: owner });
|
||||
const index = new BigNumber(0);
|
||||
const expectedError = new OwnableRevertErrors.OnlyOwnerError(notOwner, owner);
|
||||
const tx = authorizable.removeAuthorizedAddressAtIndex.sendTransactionAsync(address, index, {
|
||||
const tx = authorizable.removeAuthorizedAddressAtIndex(address, index).sendTransactionAsync({
|
||||
from: notOwner,
|
||||
});
|
||||
return expect(tx).to.revertWith(expectedError);
|
||||
});
|
||||
|
||||
it('should revert if index is >= authorities.length', async () => {
|
||||
await authorizable.addAuthorizedAddress.awaitTransactionSuccessAsync(address, { from: owner });
|
||||
await authorizable.addAuthorizedAddress(address).awaitTransactionSuccessAsync({ from: owner });
|
||||
const index = new BigNumber(1);
|
||||
const expectedError = new AuthorizableRevertErrors.IndexOutOfBoundsError(index, index);
|
||||
const tx = authorizable.removeAuthorizedAddressAtIndex.sendTransactionAsync(address, index, {
|
||||
const tx = authorizable.removeAuthorizedAddressAtIndex(address, index).sendTransactionAsync({
|
||||
from: owner,
|
||||
});
|
||||
return expect(tx).to.revertWith(expectedError);
|
||||
@@ -117,7 +117,7 @@ describe('Authorizable', () => {
|
||||
it('should revert if owner attempts to remove an address that is not authorized', async () => {
|
||||
const index = new BigNumber(0);
|
||||
const expectedError = new AuthorizableRevertErrors.TargetNotAuthorizedError(address);
|
||||
const tx = authorizable.removeAuthorizedAddressAtIndex.sendTransactionAsync(address, index, {
|
||||
const tx = authorizable.removeAuthorizedAddressAtIndex(address, index).sendTransactionAsync({
|
||||
from: owner,
|
||||
});
|
||||
return expect(tx).to.revertWith(expectedError);
|
||||
@@ -126,37 +126,37 @@ describe('Authorizable', () => {
|
||||
it('should revert if address at index does not match target', async () => {
|
||||
const address1 = address;
|
||||
const address2 = notOwner;
|
||||
await authorizable.addAuthorizedAddress.awaitTransactionSuccessAsync(address1, { from: owner });
|
||||
await authorizable.addAuthorizedAddress.awaitTransactionSuccessAsync(address2, { from: owner });
|
||||
await authorizable.addAuthorizedAddress(address1).awaitTransactionSuccessAsync({ from: owner });
|
||||
await authorizable.addAuthorizedAddress(address2).awaitTransactionSuccessAsync({ from: owner });
|
||||
const address1Index = new BigNumber(0);
|
||||
const expectedError = new AuthorizableRevertErrors.AuthorizedAddressMismatchError(address1, address2);
|
||||
const tx = authorizable.removeAuthorizedAddressAtIndex.sendTransactionAsync(address2, address1Index, {
|
||||
const tx = authorizable.removeAuthorizedAddressAtIndex(address2, address1Index).sendTransactionAsync({
|
||||
from: owner,
|
||||
});
|
||||
return expect(tx).to.revertWith(expectedError);
|
||||
});
|
||||
|
||||
it('should allow owner to remove an authorized address', async () => {
|
||||
await authorizable.addAuthorizedAddress.awaitTransactionSuccessAsync(address, { from: owner });
|
||||
await authorizable.addAuthorizedAddress(address).awaitTransactionSuccessAsync({ from: owner });
|
||||
const index = new BigNumber(0);
|
||||
await authorizable.removeAuthorizedAddressAtIndex.awaitTransactionSuccessAsync(address, index, {
|
||||
await authorizable.removeAuthorizedAddressAtIndex(address, index).awaitTransactionSuccessAsync({
|
||||
from: owner,
|
||||
});
|
||||
const isAuthorized = await authorizable.authorized.callAsync(address);
|
||||
const isAuthorized = await authorizable.authorized(address).callAsync();
|
||||
expect(isAuthorized).to.be.false();
|
||||
});
|
||||
});
|
||||
|
||||
describe('getAuthorizedAddresses', () => {
|
||||
it('should return all authorized addresses', async () => {
|
||||
const initial = await authorizable.getAuthorizedAddresses.callAsync();
|
||||
const initial = await authorizable.getAuthorizedAddresses().callAsync();
|
||||
expect(initial).to.have.length(0);
|
||||
await authorizable.addAuthorizedAddress.awaitTransactionSuccessAsync(address, { from: owner });
|
||||
const afterAdd = await authorizable.getAuthorizedAddresses.callAsync();
|
||||
await authorizable.addAuthorizedAddress(address).awaitTransactionSuccessAsync({ from: owner });
|
||||
const afterAdd = await authorizable.getAuthorizedAddresses().callAsync();
|
||||
expect(afterAdd).to.have.length(1);
|
||||
expect(afterAdd).to.include(address);
|
||||
await authorizable.removeAuthorizedAddress.awaitTransactionSuccessAsync(address, { from: owner });
|
||||
const afterRemove = await authorizable.getAuthorizedAddresses.callAsync();
|
||||
await authorizable.removeAuthorizedAddress(address).awaitTransactionSuccessAsync({ from: owner });
|
||||
const afterRemove = await authorizable.getAuthorizedAddresses().callAsync();
|
||||
expect(afterRemove).to.have.length(0);
|
||||
});
|
||||
});
|
||||
|
@@ -31,12 +31,12 @@ describe('LibAddress', () => {
|
||||
|
||||
describe('isContract', () => {
|
||||
it('should return false for a non-contract address', async () => {
|
||||
const isContract = await lib.externalIsContract.callAsync(nonContract);
|
||||
const isContract = await lib.externalIsContract(nonContract).callAsync();
|
||||
expect(isContract).to.be.false();
|
||||
});
|
||||
|
||||
it('should return true for a non-contract address', async () => {
|
||||
const isContract = await lib.externalIsContract.callAsync(lib.address);
|
||||
const isContract = await lib.externalIsContract(lib.address).callAsync();
|
||||
expect(isContract).to.be.true();
|
||||
});
|
||||
});
|
||||
|
@@ -31,7 +31,7 @@ describe('LibAddressArray', () => {
|
||||
describe('append', () => {
|
||||
it('should append to empty array', async () => {
|
||||
const addr = randomAddress();
|
||||
const result = await lib.publicAppend.callAsync([], addr);
|
||||
const result = await lib.publicAppend([], addr).callAsync();
|
||||
const expected = [addr];
|
||||
expect(result).to.deep.equal(expected);
|
||||
});
|
||||
@@ -40,7 +40,7 @@ describe('LibAddressArray', () => {
|
||||
const arr = _.times(3, () => randomAddress());
|
||||
const addr = randomAddress();
|
||||
const expected = [...arr, addr];
|
||||
const result = await lib.publicAppend.callAsync(arr, addr);
|
||||
const result = await lib.publicAppend(arr, addr).callAsync();
|
||||
expect(result).to.deep.equal(expected);
|
||||
});
|
||||
|
||||
@@ -53,7 +53,7 @@ describe('LibAddressArray', () => {
|
||||
addressArrayEndPtr.plus(freeMemOffset),
|
||||
addressArrayEndPtr,
|
||||
);
|
||||
return expect(lib.testAppendRealloc.callAsync(arr, freeMemOffset, addr)).to.revertWith(expectedError);
|
||||
return expect(lib.testAppendRealloc(arr, freeMemOffset, addr).callAsync()).to.revertWith(expectedError);
|
||||
});
|
||||
|
||||
it('should keep the same memory address if free memory pointer does not move', async () => {
|
||||
@@ -61,11 +61,9 @@ describe('LibAddressArray', () => {
|
||||
const addr = randomAddress();
|
||||
const freeMemOffset = new BigNumber(0);
|
||||
const expected = [...arr, addr];
|
||||
const [result, oldArrayMemStart, newArrayMemStart] = await lib.testAppendRealloc.callAsync(
|
||||
arr,
|
||||
freeMemOffset,
|
||||
addr,
|
||||
);
|
||||
const [result, oldArrayMemStart, newArrayMemStart] = await lib
|
||||
.testAppendRealloc(arr, freeMemOffset, addr)
|
||||
.callAsync();
|
||||
expect(result).to.deep.equal(expected);
|
||||
expect(newArrayMemStart).bignumber.to.be.equal(oldArrayMemStart);
|
||||
});
|
||||
@@ -75,11 +73,9 @@ describe('LibAddressArray', () => {
|
||||
const addr = randomAddress();
|
||||
const freeMemOffset = new BigNumber(1);
|
||||
const expectedArray = [...arr, addr];
|
||||
const [result, oldArrayMemStart, newArrayMemStart] = await lib.testAppendRealloc.callAsync(
|
||||
arr,
|
||||
freeMemOffset,
|
||||
addr,
|
||||
);
|
||||
const [result, oldArrayMemStart, newArrayMemStart] = await lib
|
||||
.testAppendRealloc(arr, freeMemOffset, addr)
|
||||
.callAsync();
|
||||
// The new location should be the end of the old array + freeMemOffset.
|
||||
const expectedNewArrayMemStart = oldArrayMemStart.plus((arr.length + 1) * 32).plus(freeMemOffset);
|
||||
expect(result).to.deep.equal(expectedArray);
|
||||
@@ -90,27 +86,27 @@ describe('LibAddressArray', () => {
|
||||
describe('contains', () => {
|
||||
it('should return false on an empty array', async () => {
|
||||
const addr = randomAddress();
|
||||
const isFound = await lib.publicContains.callAsync([], addr);
|
||||
const isFound = await lib.publicContains([], addr).callAsync();
|
||||
expect(isFound).to.equal(false);
|
||||
});
|
||||
|
||||
it('should return false on a missing item', async () => {
|
||||
const arr = _.times(3, () => randomAddress());
|
||||
const addr = randomAddress();
|
||||
const isFound = await lib.publicContains.callAsync(arr, addr);
|
||||
const isFound = await lib.publicContains(arr, addr).callAsync();
|
||||
expect(isFound).to.equal(false);
|
||||
});
|
||||
|
||||
it('should return true on an included item', async () => {
|
||||
const arr = _.times(4, () => randomAddress());
|
||||
const addr = _.sample(arr) as string;
|
||||
const isFound = await lib.publicContains.callAsync(arr, addr);
|
||||
const isFound = await lib.publicContains(arr, addr).callAsync();
|
||||
expect(isFound).to.equal(true);
|
||||
});
|
||||
|
||||
it('should return true on the only item in the array', async () => {
|
||||
const arr = _.times(1, () => randomAddress());
|
||||
const isFound = await lib.publicContains.callAsync(arr, arr[0]);
|
||||
const isFound = await lib.publicContains(arr, arr[0]).callAsync();
|
||||
expect(isFound).to.equal(true);
|
||||
});
|
||||
});
|
||||
@@ -118,14 +114,14 @@ describe('LibAddressArray', () => {
|
||||
describe('indexOf', () => {
|
||||
it('should fail on an empty array', async () => {
|
||||
const addr = randomAddress();
|
||||
const [isSuccess] = await lib.publicIndexOf.callAsync([], addr);
|
||||
const [isSuccess] = await lib.publicIndexOf([], addr).callAsync();
|
||||
expect(isSuccess).to.equal(false);
|
||||
});
|
||||
|
||||
it('should fail on a missing item', async () => {
|
||||
const arr = _.times(3, () => randomAddress());
|
||||
const addr = randomAddress();
|
||||
const [isSuccess] = await lib.publicIndexOf.callAsync(arr, addr);
|
||||
const [isSuccess] = await lib.publicIndexOf(arr, addr).callAsync();
|
||||
expect(isSuccess).to.equal(false);
|
||||
});
|
||||
|
||||
@@ -133,14 +129,14 @@ describe('LibAddressArray', () => {
|
||||
const arr = _.times(4, () => randomAddress());
|
||||
const expectedIndexOf = _.random(0, arr.length - 1);
|
||||
const addr = arr[expectedIndexOf];
|
||||
const [isSuccess, index] = await lib.publicIndexOf.callAsync(arr, addr);
|
||||
const [isSuccess, index] = await lib.publicIndexOf(arr, addr).callAsync();
|
||||
expect(isSuccess).to.equal(true);
|
||||
expect(index).bignumber.to.equal(expectedIndexOf);
|
||||
});
|
||||
|
||||
it('should succeed on the only item in the array', async () => {
|
||||
const arr = _.times(1, () => randomAddress());
|
||||
const [isSuccess, index] = await lib.publicIndexOf.callAsync(arr, arr[0]);
|
||||
const [isSuccess, index] = await lib.publicIndexOf(arr, arr[0]).callAsync();
|
||||
expect(isSuccess).to.equal(true);
|
||||
expect(index).bignumber.to.equal(0);
|
||||
});
|
||||
|
@@ -60,17 +60,17 @@ blockchainTests('LibBytes', env => {
|
||||
constants.ZERO_AMOUNT,
|
||||
constants.ZERO_AMOUNT,
|
||||
);
|
||||
return expect(libBytes.publicPopLastByte.callAsync(constants.NULL_BYTES)).to.revertWith(expectedError);
|
||||
return expect(libBytes.publicPopLastByte(constants.NULL_BYTES).callAsync()).to.revertWith(expectedError);
|
||||
});
|
||||
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 [newBytes, poppedByte] = await libBytes.publicPopLastByte(byteArrayLongerThan32Bytes).callAsync();
|
||||
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 1 byte', async () => {
|
||||
const [newBytes, poppedByte] = await libBytes.publicPopLastByte.callAsync(testByte);
|
||||
const [newBytes, poppedByte] = await libBytes.publicPopLastByte(testByte).callAsync();
|
||||
const expectedNewBytes = '0x';
|
||||
expect(newBytes).to.equal(expectedNewBytes);
|
||||
return expect(poppedByte).to.be.equal(testByte);
|
||||
@@ -79,51 +79,45 @@ blockchainTests('LibBytes', env => {
|
||||
|
||||
describe('equals', () => {
|
||||
it('should return true if byte arrays are equal (both arrays < 32 bytes)', async () => {
|
||||
const isEqual = await libBytes.publicEquals.callAsync(
|
||||
byteArrayShorterThan32Bytes,
|
||||
byteArrayShorterThan32Bytes,
|
||||
);
|
||||
const isEqual = await libBytes
|
||||
.publicEquals(byteArrayShorterThan32Bytes, byteArrayShorterThan32Bytes)
|
||||
.callAsync();
|
||||
return expect(isEqual).to.be.true();
|
||||
});
|
||||
it('should return true if byte arrays are equal (both arrays > 32 bytes)', async () => {
|
||||
const isEqual = await libBytes.publicEquals.callAsync(
|
||||
byteArrayLongerThan32Bytes,
|
||||
byteArrayLongerThan32Bytes,
|
||||
);
|
||||
const isEqual = await libBytes
|
||||
.publicEquals(byteArrayLongerThan32Bytes, byteArrayLongerThan32Bytes)
|
||||
.callAsync();
|
||||
return expect(isEqual).to.be.true();
|
||||
});
|
||||
it('should return false if byte arrays are not equal (first array < 32 bytes, second array > 32 bytes)', async () => {
|
||||
const isEqual = await libBytes.publicEquals.callAsync(
|
||||
byteArrayShorterThan32Bytes,
|
||||
byteArrayLongerThan32Bytes,
|
||||
);
|
||||
const isEqual = await libBytes
|
||||
.publicEquals(byteArrayShorterThan32Bytes, byteArrayLongerThan32Bytes)
|
||||
.callAsync();
|
||||
return expect(isEqual).to.be.false();
|
||||
});
|
||||
it('should return false if byte arrays are not equal (first array > 32 bytes, second array < 32 bytes)', async () => {
|
||||
const isEqual = await libBytes.publicEquals.callAsync(
|
||||
byteArrayLongerThan32Bytes,
|
||||
byteArrayShorterThan32Bytes,
|
||||
);
|
||||
const isEqual = await libBytes
|
||||
.publicEquals(byteArrayLongerThan32Bytes, byteArrayShorterThan32Bytes)
|
||||
.callAsync();
|
||||
return expect(isEqual).to.be.false();
|
||||
});
|
||||
it('should return false if byte arrays are not equal (same length, but a byte in first word differs)', async () => {
|
||||
const isEqual = await libBytes.publicEquals.callAsync(
|
||||
byteArrayLongerThan32BytesFirstBytesSwapped,
|
||||
byteArrayLongerThan32Bytes,
|
||||
);
|
||||
const isEqual = await libBytes
|
||||
.publicEquals(byteArrayLongerThan32BytesFirstBytesSwapped, byteArrayLongerThan32Bytes)
|
||||
.callAsync();
|
||||
return expect(isEqual).to.be.false();
|
||||
});
|
||||
it('should return false if byte arrays are not equal (same length, but a byte in last word differs)', async () => {
|
||||
const isEqual = await libBytes.publicEquals.callAsync(
|
||||
byteArrayLongerThan32BytesLastBytesSwapped,
|
||||
byteArrayLongerThan32Bytes,
|
||||
);
|
||||
const isEqual = await libBytes
|
||||
.publicEquals(byteArrayLongerThan32BytesLastBytesSwapped, byteArrayLongerThan32Bytes)
|
||||
.callAsync();
|
||||
return expect(isEqual).to.be.false();
|
||||
});
|
||||
|
||||
describe('should ignore trailing data', () => {
|
||||
it('should return true when both < 32 bytes', async () => {
|
||||
const isEqual = await libBytes.publicEqualsPop1.callAsync('0x0102', '0x0103');
|
||||
const isEqual = await libBytes.publicEqualsPop1('0x0102', '0x0103').callAsync();
|
||||
return expect(isEqual).to.be.true();
|
||||
});
|
||||
});
|
||||
@@ -133,7 +127,7 @@ blockchainTests('LibBytes', env => {
|
||||
it('should successfully read address when the address takes up the whole array', async () => {
|
||||
const byteArray = ethUtil.addHexPrefix(testAddress);
|
||||
const testAddressOffset = new BigNumber(0);
|
||||
const address = await libBytes.publicReadAddress.callAsync(byteArray, testAddressOffset);
|
||||
const address = await libBytes.publicReadAddress(byteArray, testAddressOffset).callAsync();
|
||||
return expect(address).to.be.equal(testAddress);
|
||||
});
|
||||
it('should successfully read address when it is offset in the array', async () => {
|
||||
@@ -142,7 +136,7 @@ blockchainTests('LibBytes', env => {
|
||||
const combinedByteArrayBuffer = Buffer.concat([prefixByteArrayBuffer, addressByteArrayBuffer]);
|
||||
const combinedByteArray = ethUtil.bufferToHex(combinedByteArrayBuffer);
|
||||
const testAddressOffset = new BigNumber(prefixByteArrayBuffer.byteLength);
|
||||
const address = await libBytes.publicReadAddress.callAsync(combinedByteArray, testAddressOffset);
|
||||
const address = await libBytes.publicReadAddress(combinedByteArray, testAddressOffset).callAsync();
|
||||
return expect(address).to.be.equal(testAddress);
|
||||
});
|
||||
it('should fail if the byte array is too short to hold an address', async () => {
|
||||
@@ -153,7 +147,7 @@ blockchainTests('LibBytes', env => {
|
||||
new BigNumber(3),
|
||||
new BigNumber(20),
|
||||
);
|
||||
return expect(libBytes.publicReadAddress.callAsync(shortByteArray, offset)).to.revertWith(expectedError);
|
||||
return expect(libBytes.publicReadAddress(shortByteArray, offset).callAsync()).to.revertWith(expectedError);
|
||||
});
|
||||
it('should fail if the length between the offset and end of the byte array is too short to hold an address', async () => {
|
||||
const byteArray = testAddress;
|
||||
@@ -163,7 +157,7 @@ blockchainTests('LibBytes', env => {
|
||||
new BigNumber(20),
|
||||
new BigNumber(40),
|
||||
);
|
||||
return expect(libBytes.publicReadAddress.callAsync(byteArray, badOffset)).to.revertWith(expectedError);
|
||||
return expect(libBytes.publicReadAddress(byteArray, badOffset).callAsync()).to.revertWith(expectedError);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -171,11 +165,9 @@ blockchainTests('LibBytes', env => {
|
||||
it('should successfully write address when the address takes up the whole array', async () => {
|
||||
const byteArray = testAddress;
|
||||
const testAddressOffset = new BigNumber(0);
|
||||
const newByteArray = await libBytes.publicWriteAddress.callAsync(
|
||||
byteArray,
|
||||
testAddressOffset,
|
||||
testAddressB,
|
||||
);
|
||||
const newByteArray = await libBytes
|
||||
.publicWriteAddress(byteArray, testAddressOffset, testAddressB)
|
||||
.callAsync();
|
||||
return expect(newByteArray).to.be.equal(testAddressB);
|
||||
});
|
||||
it('should successfully write address when it is offset in the array', async () => {
|
||||
@@ -184,11 +176,9 @@ blockchainTests('LibBytes', env => {
|
||||
const combinedByteArrayBuffer = Buffer.concat([prefixByteArrayBuffer, addressByteArrayBuffer]);
|
||||
const combinedByteArray = ethUtil.bufferToHex(combinedByteArrayBuffer);
|
||||
const testAddressOffset = new BigNumber(prefixByteArrayBuffer.byteLength);
|
||||
const newByteArray = await libBytes.publicWriteAddress.callAsync(
|
||||
combinedByteArray,
|
||||
testAddressOffset,
|
||||
testAddressB,
|
||||
);
|
||||
const newByteArray = await libBytes
|
||||
.publicWriteAddress(combinedByteArray, testAddressOffset, testAddressB)
|
||||
.callAsync();
|
||||
const newByteArrayBuffer = ethUtil.toBuffer(newByteArray);
|
||||
const addressFromOffsetBuffer = newByteArrayBuffer.slice(prefixByteArrayBuffer.byteLength);
|
||||
const addressFromOffset = ethUtil.addHexPrefix(ethUtil.bufferToHex(addressFromOffsetBuffer));
|
||||
@@ -203,7 +193,7 @@ blockchainTests('LibBytes', env => {
|
||||
new BigNumber(20),
|
||||
);
|
||||
return expect(
|
||||
libBytes.publicWriteAddress.callAsync(byteArrayShorterThan20Bytes, offset, testAddress),
|
||||
libBytes.publicWriteAddress(byteArrayShorterThan20Bytes, offset, testAddress).callAsync(),
|
||||
).to.revertWith(expectedError);
|
||||
});
|
||||
it('should fail if the length between the offset and end of the byte array is too short to hold an address', async () => {
|
||||
@@ -214,7 +204,7 @@ blockchainTests('LibBytes', env => {
|
||||
badOffset,
|
||||
badOffset.plus(new BigNumber(20)),
|
||||
);
|
||||
return expect(libBytes.publicWriteAddress.callAsync(byteArray, badOffset, testAddress)).to.revertWith(
|
||||
return expect(libBytes.publicWriteAddress(byteArray, badOffset, testAddress).callAsync()).to.revertWith(
|
||||
expectedError,
|
||||
);
|
||||
});
|
||||
@@ -223,7 +213,7 @@ blockchainTests('LibBytes', env => {
|
||||
describe('readBytes32', () => {
|
||||
it('should successfully read bytes32 when the bytes32 takes up the whole array', async () => {
|
||||
const testBytes32Offset = new BigNumber(0);
|
||||
const bytes32 = await libBytes.publicReadBytes32.callAsync(testBytes32, testBytes32Offset);
|
||||
const bytes32 = await libBytes.publicReadBytes32(testBytes32, testBytes32Offset).callAsync();
|
||||
return expect(bytes32).to.be.equal(testBytes32);
|
||||
});
|
||||
it('should successfully read bytes32 when it is offset in the array', async () => {
|
||||
@@ -232,7 +222,7 @@ blockchainTests('LibBytes', env => {
|
||||
const combinedByteArrayBuffer = Buffer.concat([prefixByteArrayBuffer, bytes32ByteArrayBuffer]);
|
||||
const combinedByteArray = ethUtil.bufferToHex(combinedByteArrayBuffer);
|
||||
const testBytes32Offset = new BigNumber(prefixByteArrayBuffer.byteLength);
|
||||
const bytes32 = await libBytes.publicReadBytes32.callAsync(combinedByteArray, testBytes32Offset);
|
||||
const bytes32 = await libBytes.publicReadBytes32(combinedByteArray, testBytes32Offset).callAsync();
|
||||
return expect(bytes32).to.be.equal(testBytes32);
|
||||
});
|
||||
it('should fail if the byte array is too short to hold a bytes32', async () => {
|
||||
@@ -243,7 +233,7 @@ blockchainTests('LibBytes', env => {
|
||||
byteLen,
|
||||
new BigNumber(32),
|
||||
);
|
||||
return expect(libBytes.publicReadBytes32.callAsync(byteArrayShorterThan32Bytes, offset)).to.revertWith(
|
||||
return expect(libBytes.publicReadBytes32(byteArrayShorterThan32Bytes, offset).callAsync()).to.revertWith(
|
||||
expectedError,
|
||||
);
|
||||
});
|
||||
@@ -254,7 +244,7 @@ blockchainTests('LibBytes', env => {
|
||||
badOffset,
|
||||
badOffset.plus(new BigNumber(32)),
|
||||
);
|
||||
return expect(libBytes.publicReadBytes32.callAsync(testBytes32, badOffset)).to.revertWith(expectedError);
|
||||
return expect(libBytes.publicReadBytes32(testBytes32, badOffset).callAsync()).to.revertWith(expectedError);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -262,11 +252,9 @@ blockchainTests('LibBytes', env => {
|
||||
it('should successfully write bytes32 when the address takes up the whole array', async () => {
|
||||
const byteArray = testBytes32;
|
||||
const testBytes32Offset = new BigNumber(0);
|
||||
const newByteArray = await libBytes.publicWriteBytes32.callAsync(
|
||||
byteArray,
|
||||
testBytes32Offset,
|
||||
testBytes32B,
|
||||
);
|
||||
const newByteArray = await libBytes
|
||||
.publicWriteBytes32(byteArray, testBytes32Offset, testBytes32B)
|
||||
.callAsync();
|
||||
return expect(newByteArray).to.be.equal(testBytes32B);
|
||||
});
|
||||
it('should successfully write bytes32 when it is offset in the array', async () => {
|
||||
@@ -275,11 +263,9 @@ blockchainTests('LibBytes', env => {
|
||||
const combinedByteArrayBuffer = Buffer.concat([prefixByteArrayBuffer, bytes32ByteArrayBuffer]);
|
||||
const combinedByteArray = ethUtil.bufferToHex(combinedByteArrayBuffer);
|
||||
const testBytes32Offset = new BigNumber(prefixByteArrayBuffer.byteLength);
|
||||
const newByteArray = await libBytes.publicWriteBytes32.callAsync(
|
||||
combinedByteArray,
|
||||
testBytes32Offset,
|
||||
testBytes32B,
|
||||
);
|
||||
const newByteArray = await libBytes
|
||||
.publicWriteBytes32(combinedByteArray, testBytes32Offset, testBytes32B)
|
||||
.callAsync();
|
||||
const newByteArrayBuffer = ethUtil.toBuffer(newByteArray);
|
||||
const bytes32FromOffsetBuffer = newByteArrayBuffer.slice(prefixByteArrayBuffer.byteLength);
|
||||
const bytes32FromOffset = ethUtil.addHexPrefix(ethUtil.bufferToHex(bytes32FromOffsetBuffer));
|
||||
@@ -294,7 +280,7 @@ blockchainTests('LibBytes', env => {
|
||||
new BigNumber(32),
|
||||
);
|
||||
return expect(
|
||||
libBytes.publicWriteBytes32.callAsync(byteArrayShorterThan32Bytes, offset, testBytes32),
|
||||
libBytes.publicWriteBytes32(byteArrayShorterThan32Bytes, offset, testBytes32).callAsync(),
|
||||
).to.revertWith(expectedError);
|
||||
});
|
||||
it('should fail if the length between the offset and end of the byte array is too short to hold a bytes32', async () => {
|
||||
@@ -305,7 +291,7 @@ blockchainTests('LibBytes', env => {
|
||||
badOffset,
|
||||
badOffset.plus(new BigNumber(32)),
|
||||
);
|
||||
return expect(libBytes.publicWriteBytes32.callAsync(byteArray, badOffset, testBytes32)).to.revertWith(
|
||||
return expect(libBytes.publicWriteBytes32(byteArray, badOffset, testBytes32).callAsync()).to.revertWith(
|
||||
expectedError,
|
||||
);
|
||||
});
|
||||
@@ -317,7 +303,7 @@ blockchainTests('LibBytes', env => {
|
||||
const testUint256AsBuffer = ethUtil.toBuffer(formattedTestUint256);
|
||||
const byteArray = ethUtil.bufferToHex(testUint256AsBuffer);
|
||||
const testUint256Offset = new BigNumber(0);
|
||||
const uint256 = await libBytes.publicReadUint256.callAsync(byteArray, testUint256Offset);
|
||||
const uint256 = await libBytes.publicReadUint256(byteArray, testUint256Offset).callAsync();
|
||||
return expect(uint256).to.bignumber.equal(testUint256);
|
||||
});
|
||||
it('should successfully read uint256 when it is offset in the array', async () => {
|
||||
@@ -327,7 +313,7 @@ blockchainTests('LibBytes', env => {
|
||||
const combinedByteArrayBuffer = Buffer.concat([prefixByteArrayBuffer, testUint256AsBuffer]);
|
||||
const combinedByteArray = ethUtil.bufferToHex(combinedByteArrayBuffer);
|
||||
const testUint256Offset = new BigNumber(prefixByteArrayBuffer.byteLength);
|
||||
const uint256 = await libBytes.publicReadUint256.callAsync(combinedByteArray, testUint256Offset);
|
||||
const uint256 = await libBytes.publicReadUint256(combinedByteArray, testUint256Offset).callAsync();
|
||||
return expect(uint256).to.bignumber.equal(testUint256);
|
||||
});
|
||||
it('should fail if the byte array is too short to hold a uint256', async () => {
|
||||
@@ -338,7 +324,7 @@ blockchainTests('LibBytes', env => {
|
||||
byteLen,
|
||||
new BigNumber(32),
|
||||
);
|
||||
return expect(libBytes.publicReadUint256.callAsync(byteArrayShorterThan32Bytes, offset)).to.revertWith(
|
||||
return expect(libBytes.publicReadUint256(byteArrayShorterThan32Bytes, offset).callAsync()).to.revertWith(
|
||||
expectedError,
|
||||
);
|
||||
});
|
||||
@@ -352,7 +338,7 @@ blockchainTests('LibBytes', env => {
|
||||
badOffset,
|
||||
badOffset.plus(new BigNumber(32)),
|
||||
);
|
||||
return expect(libBytes.publicReadUint256.callAsync(byteArray, badOffset)).to.revertWith(expectedError);
|
||||
return expect(libBytes.publicReadUint256(byteArray, badOffset).callAsync()).to.revertWith(expectedError);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -360,11 +346,9 @@ blockchainTests('LibBytes', env => {
|
||||
it('should successfully write uint256 when the address takes up the whole array', async () => {
|
||||
const byteArray = testBytes32;
|
||||
const testUint256Offset = new BigNumber(0);
|
||||
const newByteArray = await libBytes.publicWriteUint256.callAsync(
|
||||
byteArray,
|
||||
testUint256Offset,
|
||||
testUint256B,
|
||||
);
|
||||
const newByteArray = await libBytes
|
||||
.publicWriteUint256(byteArray, testUint256Offset, testUint256B)
|
||||
.callAsync();
|
||||
const newByteArrayAsUint256 = new BigNumber(newByteArray, 16);
|
||||
return expect(newByteArrayAsUint256).to.be.bignumber.equal(testUint256B);
|
||||
});
|
||||
@@ -374,11 +358,9 @@ blockchainTests('LibBytes', env => {
|
||||
const combinedByteArrayBuffer = Buffer.concat([prefixByteArrayBuffer, bytes32ByteArrayBuffer]);
|
||||
const combinedByteArray = ethUtil.bufferToHex(combinedByteArrayBuffer);
|
||||
const testUint256Offset = new BigNumber(prefixByteArrayBuffer.byteLength);
|
||||
const newByteArray = await libBytes.publicWriteUint256.callAsync(
|
||||
combinedByteArray,
|
||||
testUint256Offset,
|
||||
testUint256B,
|
||||
);
|
||||
const newByteArray = await libBytes
|
||||
.publicWriteUint256(combinedByteArray, testUint256Offset, testUint256B)
|
||||
.callAsync();
|
||||
const newByteArrayBuffer = ethUtil.toBuffer(newByteArray);
|
||||
const uint256FromOffsetBuffer = newByteArrayBuffer.slice(prefixByteArrayBuffer.byteLength);
|
||||
const uint256FromOffset = new BigNumber(
|
||||
@@ -396,7 +378,7 @@ blockchainTests('LibBytes', env => {
|
||||
new BigNumber(32),
|
||||
);
|
||||
return expect(
|
||||
libBytes.publicWriteUint256.callAsync(byteArrayShorterThan32Bytes, offset, testUint256),
|
||||
libBytes.publicWriteUint256(byteArrayShorterThan32Bytes, offset, testUint256).callAsync(),
|
||||
).to.revertWith(expectedError);
|
||||
});
|
||||
it('should fail if the length between the offset and end of the byte array is too short to hold a uint256', async () => {
|
||||
@@ -407,7 +389,7 @@ blockchainTests('LibBytes', env => {
|
||||
badOffset,
|
||||
badOffset.plus(new BigNumber(32)),
|
||||
);
|
||||
return expect(libBytes.publicWriteUint256.callAsync(byteArray, badOffset, testUint256)).to.revertWith(
|
||||
return expect(libBytes.publicWriteUint256(byteArray, badOffset, testUint256).callAsync()).to.revertWith(
|
||||
expectedError,
|
||||
);
|
||||
});
|
||||
@@ -424,18 +406,20 @@ blockchainTests('LibBytes', env => {
|
||||
new BigNumber(byteLen), // length of byteArrayLessThan4Bytes
|
||||
new BigNumber(4),
|
||||
);
|
||||
return expect(libBytes.publicReadBytes4.callAsync(byteArrayLessThan4Bytes, offset)).to.revertWith(
|
||||
return expect(libBytes.publicReadBytes4(byteArrayLessThan4Bytes, offset).callAsync()).to.revertWith(
|
||||
expectedError,
|
||||
);
|
||||
});
|
||||
it('should return the first 4 bytes of a byte array of arbitrary length', async () => {
|
||||
const first4Bytes = await libBytes.publicReadBytes4.callAsync(byteArrayLongerThan32Bytes, new BigNumber(0));
|
||||
const first4Bytes = await libBytes
|
||||
.publicReadBytes4(byteArrayLongerThan32Bytes, new BigNumber(0))
|
||||
.callAsync();
|
||||
const expectedFirst4Bytes = byteArrayLongerThan32Bytes.slice(0, 10);
|
||||
expect(first4Bytes).to.equal(expectedFirst4Bytes);
|
||||
});
|
||||
it('should successfully read bytes4 when the bytes4 takes up the whole array', async () => {
|
||||
const testBytes4Offset = new BigNumber(0);
|
||||
const bytes4 = await libBytes.publicReadBytes4.callAsync(testBytes4, testBytes4Offset);
|
||||
const bytes4 = await libBytes.publicReadBytes4(testBytes4, testBytes4Offset).callAsync();
|
||||
return expect(bytes4).to.be.equal(testBytes4);
|
||||
});
|
||||
it('should successfully read bytes4 when it is offset in the array', async () => {
|
||||
@@ -444,7 +428,7 @@ blockchainTests('LibBytes', env => {
|
||||
const combinedByteArrayBuffer = Buffer.concat([prefixByteArrayBuffer, bytes4ByteArrayBuffer]);
|
||||
const combinedByteArray = ethUtil.bufferToHex(combinedByteArrayBuffer);
|
||||
const testBytes4Offset = new BigNumber(prefixByteArrayBuffer.byteLength);
|
||||
const bytes4 = await libBytes.publicReadBytes4.callAsync(combinedByteArray, testBytes4Offset);
|
||||
const bytes4 = await libBytes.publicReadBytes4(combinedByteArray, testBytes4Offset).callAsync();
|
||||
return expect(bytes4).to.be.equal(testBytes4);
|
||||
});
|
||||
it('should fail if the length between the offset and end of the byte array is too short to hold a bytes4', async () => {
|
||||
@@ -455,7 +439,7 @@ blockchainTests('LibBytes', env => {
|
||||
byteLen,
|
||||
badOffset.plus(new BigNumber(4)),
|
||||
);
|
||||
return expect(libBytes.publicReadBytes4.callAsync(testBytes4, badOffset)).to.revertWith(expectedError);
|
||||
return expect(libBytes.publicReadBytes4(testBytes4, badOffset).callAsync()).to.revertWith(expectedError);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -477,12 +461,9 @@ blockchainTests('LibBytes', env => {
|
||||
tests.forEach(([dest, source, length, job]) =>
|
||||
it(job, async () => {
|
||||
const expected = refMemcpy(memory, dest, source, length);
|
||||
const resultStr = await libBytes.testMemcpy.callAsync(
|
||||
memHex,
|
||||
new BigNumber(dest),
|
||||
new BigNumber(source),
|
||||
new BigNumber(length),
|
||||
);
|
||||
const resultStr = await libBytes
|
||||
.testMemcpy(memHex, new BigNumber(dest), new BigNumber(source), new BigNumber(length))
|
||||
.callAsync();
|
||||
const result = fromHex(resultStr);
|
||||
expect(result).to.deep.equal(expected);
|
||||
}),
|
||||
@@ -634,14 +615,14 @@ blockchainTests('LibBytes', env => {
|
||||
from,
|
||||
to,
|
||||
);
|
||||
return expect(libBytes.publicSlice.callAsync(byteArrayLongerThan32Bytes, from, to)).to.revertWith(
|
||||
return expect(libBytes.publicSlice(byteArrayLongerThan32Bytes, from, to).callAsync()).to.revertWith(
|
||||
expectedError,
|
||||
);
|
||||
});
|
||||
it('should return a byte array of length 0 if from == to', async () => {
|
||||
const from = new BigNumber(0);
|
||||
const to = from;
|
||||
const [result, original] = await libBytes.publicSlice.callAsync(byteArrayLongerThan32Bytes, from, to);
|
||||
const [result, original] = await libBytes.publicSlice(byteArrayLongerThan32Bytes, from, to).callAsync();
|
||||
expect(original).to.eq(byteArrayLongerThan32Bytes);
|
||||
expect(result).to.eq(constants.NULL_BYTES);
|
||||
});
|
||||
@@ -649,7 +630,7 @@ blockchainTests('LibBytes', env => {
|
||||
const byteLen = fromHex(byteArrayLongerThan32Bytes).length;
|
||||
const from = new BigNumber(byteLen);
|
||||
const to = from;
|
||||
const [result, original] = await libBytes.publicSlice.callAsync(byteArrayLongerThan32Bytes, from, to);
|
||||
const [result, original] = await libBytes.publicSlice(byteArrayLongerThan32Bytes, from, to).callAsync();
|
||||
expect(original).to.eq(byteArrayLongerThan32Bytes);
|
||||
expect(result).to.eq(constants.NULL_BYTES);
|
||||
});
|
||||
@@ -662,14 +643,14 @@ blockchainTests('LibBytes', env => {
|
||||
to,
|
||||
new BigNumber(byteLen),
|
||||
);
|
||||
return expect(libBytes.publicSlice.callAsync(byteArrayLongerThan32Bytes, from, to)).to.revertWith(
|
||||
return expect(libBytes.publicSlice(byteArrayLongerThan32Bytes, from, to).callAsync()).to.revertWith(
|
||||
expectedError,
|
||||
);
|
||||
});
|
||||
it('should slice a section of the input', async () => {
|
||||
const from = new BigNumber(1);
|
||||
const to = new BigNumber(2);
|
||||
const [result, original] = await libBytes.publicSlice.callAsync(byteArrayLongerThan32Bytes, from, to);
|
||||
const [result, original] = await libBytes.publicSlice(byteArrayLongerThan32Bytes, from, to).callAsync();
|
||||
const expectedResult = `0x${byteArrayLongerThan32Bytes.slice(4, 6)}`;
|
||||
expect(original).to.eq(byteArrayLongerThan32Bytes);
|
||||
expect(result).to.eq(expectedResult);
|
||||
@@ -678,7 +659,7 @@ blockchainTests('LibBytes', env => {
|
||||
const byteLen = fromHex(byteArrayLongerThan32Bytes).length;
|
||||
const from = new BigNumber(0);
|
||||
const to = new BigNumber(byteLen);
|
||||
const [result, original] = await libBytes.publicSlice.callAsync(byteArrayLongerThan32Bytes, from, to);
|
||||
const [result, original] = await libBytes.publicSlice(byteArrayLongerThan32Bytes, from, to).callAsync();
|
||||
expect(original).to.eq(byteArrayLongerThan32Bytes);
|
||||
expect(result).to.eq(byteArrayLongerThan32Bytes);
|
||||
});
|
||||
@@ -693,21 +674,21 @@ blockchainTests('LibBytes', env => {
|
||||
from,
|
||||
to,
|
||||
);
|
||||
return expect(libBytes.publicSlice.callAsync(byteArrayLongerThan32Bytes, from, to)).to.revertWith(
|
||||
return expect(libBytes.publicSlice(byteArrayLongerThan32Bytes, from, to).callAsync()).to.revertWith(
|
||||
expectedError,
|
||||
);
|
||||
});
|
||||
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(byteArrayLongerThan32Bytes, from, to).callAsync();
|
||||
expect(result).to.eq(constants.NULL_BYTES);
|
||||
});
|
||||
it('should return a byte array of length 0 if from == to == b.length', async () => {
|
||||
const byteLen = fromHex(byteArrayLongerThan32Bytes).length;
|
||||
const from = new BigNumber(byteLen);
|
||||
const to = from;
|
||||
const [result] = await libBytes.publicSliceDestructive.callAsync(byteArrayLongerThan32Bytes, from, to);
|
||||
const [result] = await libBytes.publicSliceDestructive(byteArrayLongerThan32Bytes, from, to).callAsync();
|
||||
expect(result).to.eq(constants.NULL_BYTES);
|
||||
});
|
||||
it('should revert if to > input.length', async () => {
|
||||
@@ -720,13 +701,13 @@ blockchainTests('LibBytes', env => {
|
||||
new BigNumber(byteLen),
|
||||
);
|
||||
return expect(
|
||||
libBytes.publicSliceDestructive.callAsync(byteArrayLongerThan32Bytes, from, to),
|
||||
libBytes.publicSliceDestructive(byteArrayLongerThan32Bytes, from, to).callAsync(),
|
||||
).to.revertWith(expectedError);
|
||||
});
|
||||
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(byteArrayLongerThan32Bytes, from, to).callAsync();
|
||||
const expectedResult = `0x${byteArrayLongerThan32Bytes.slice(4, 6)}`;
|
||||
expect(result).to.eq(expectedResult);
|
||||
});
|
||||
@@ -734,37 +715,31 @@ blockchainTests('LibBytes', env => {
|
||||
const byteLen = fromHex(byteArrayLongerThan32Bytes).length;
|
||||
const from = new BigNumber(0);
|
||||
const to = new BigNumber(byteLen);
|
||||
const [result] = await libBytes.publicSliceDestructive.callAsync(byteArrayLongerThan32Bytes, from, to);
|
||||
const [result] = await libBytes.publicSliceDestructive(byteArrayLongerThan32Bytes, from, to).callAsync();
|
||||
expect(result).to.eq(byteArrayLongerThan32Bytes);
|
||||
});
|
||||
});
|
||||
|
||||
describe('writeLength', () => {
|
||||
it('should return a null byte array if length is set to 0', async () => {
|
||||
const result = await libBytes.publicWriteLength.callAsync(
|
||||
byteArrayLongerThan32Bytes,
|
||||
constants.ZERO_AMOUNT,
|
||||
constants.NULL_BYTES,
|
||||
);
|
||||
const result = await libBytes
|
||||
.publicWriteLength(byteArrayLongerThan32Bytes, constants.ZERO_AMOUNT, constants.NULL_BYTES)
|
||||
.callAsync();
|
||||
expect(result).to.eq(constants.NULL_BYTES);
|
||||
});
|
||||
it('should return the same byte array if length is unchanged', async () => {
|
||||
const byteLen = fromHex(byteArrayLongerThan32Bytes).length;
|
||||
const result = await libBytes.publicWriteLength.callAsync(
|
||||
byteArrayLongerThan32Bytes,
|
||||
new BigNumber(byteLen),
|
||||
constants.NULL_BYTES,
|
||||
);
|
||||
const result = await libBytes
|
||||
.publicWriteLength(byteArrayLongerThan32Bytes, new BigNumber(byteLen), constants.NULL_BYTES)
|
||||
.callAsync();
|
||||
expect(result).to.eq(byteArrayLongerThan32Bytes);
|
||||
});
|
||||
it('should shave off lower order bytes if new length is less than original', async () => {
|
||||
const byteLen = fromHex(byteArrayLongerThan32Bytes).length;
|
||||
const newLen = new BigNumber(byteLen).dividedToIntegerBy(2);
|
||||
const result = await libBytes.publicWriteLength.callAsync(
|
||||
byteArrayLongerThan32Bytes,
|
||||
newLen,
|
||||
constants.NULL_BYTES,
|
||||
);
|
||||
const result = await libBytes
|
||||
.publicWriteLength(byteArrayLongerThan32Bytes, newLen, constants.NULL_BYTES)
|
||||
.callAsync();
|
||||
expect(result).to.eq(
|
||||
byteArrayLongerThan32Bytes.slice(
|
||||
0,
|
||||
@@ -778,35 +753,31 @@ blockchainTests('LibBytes', env => {
|
||||
it("should right pad with 0's if new length is greater than original and no extra bytes are appended", async () => {
|
||||
const byteLen = fromHex(byteArrayLongerThan32Bytes).length;
|
||||
const newLen = new BigNumber(byteLen).multipliedBy(2);
|
||||
const result = await libBytes.publicWriteLength.callAsync(
|
||||
byteArrayLongerThan32Bytes,
|
||||
newLen,
|
||||
constants.NULL_BYTES,
|
||||
);
|
||||
const result = await libBytes
|
||||
.publicWriteLength(byteArrayLongerThan32Bytes, newLen, constants.NULL_BYTES)
|
||||
.callAsync();
|
||||
expect(result).to.eq(`${byteArrayLongerThan32Bytes}${'0'.repeat(byteArrayLongerThan32Bytes.length - 2)}`);
|
||||
});
|
||||
it('should right pad with extra bytes if specified', async () => {
|
||||
const byteLen = fromHex(byteArrayLongerThan32Bytes).length;
|
||||
const newLen = new BigNumber(byteLen).multipliedBy(2);
|
||||
const result = await libBytes.publicWriteLength.callAsync(
|
||||
byteArrayLongerThan32Bytes,
|
||||
newLen,
|
||||
byteArrayLongerThan32Bytes,
|
||||
);
|
||||
const result = await libBytes
|
||||
.publicWriteLength(byteArrayLongerThan32Bytes, newLen, byteArrayLongerThan32Bytes)
|
||||
.callAsync();
|
||||
expect(result).to.eq(`${byteArrayLongerThan32Bytes}${byteArrayLongerThan32Bytes.slice(2)}`);
|
||||
});
|
||||
it('should result in the same byte array if length is reduced and reset', async () => {
|
||||
const byteLen = fromHex(byteArrayLongerThan32Bytes).length;
|
||||
const tempByteLen = new BigNumber(byteLen).dividedToIntegerBy(2);
|
||||
return expect(
|
||||
libBytes.assertBytesUnchangedAfterLengthReset.callAsync(byteArrayLongerThan32Bytes, tempByteLen),
|
||||
libBytes.assertBytesUnchangedAfterLengthReset(byteArrayLongerThan32Bytes, tempByteLen).callAsync(),
|
||||
).to.be.fulfilled('');
|
||||
});
|
||||
it('should result in the same byte array if length is increased and reset', async () => {
|
||||
const byteLen = fromHex(byteArrayLongerThan32Bytes).length;
|
||||
const tempByteLen = new BigNumber(byteLen).multipliedBy(2);
|
||||
return expect(
|
||||
libBytes.assertBytesUnchangedAfterLengthReset.callAsync(byteArrayLongerThan32Bytes, tempByteLen),
|
||||
libBytes.assertBytesUnchangedAfterLengthReset(byteArrayLongerThan32Bytes, tempByteLen).callAsync(),
|
||||
).to.be.fulfilled('');
|
||||
});
|
||||
});
|
||||
|
@@ -45,12 +45,9 @@ describe('LibEIP712', () => {
|
||||
chainId,
|
||||
verifyingContract,
|
||||
});
|
||||
const actualHash = await lib.externalHashEIP712DomainSeperator.callAsync(
|
||||
name,
|
||||
version,
|
||||
new BigNumber(chainId),
|
||||
verifyingContract,
|
||||
);
|
||||
const actualHash = await lib
|
||||
.externalHashEIP712DomainSeperator(name, version, new BigNumber(chainId), verifyingContract)
|
||||
.callAsync();
|
||||
expect(actualHash).to.be.eq(hexConcat(expectedHash));
|
||||
}
|
||||
|
||||
@@ -84,7 +81,7 @@ describe('LibEIP712', () => {
|
||||
const expectedHash = '0x'.concat(ethUtil.sha3(input).toString('hex'));
|
||||
|
||||
// Get the actual hash by calling the smart contract
|
||||
const actualHash = await lib.externalHashEIP712Message.callAsync(domainHash, hashStruct);
|
||||
const actualHash = await lib.externalHashEIP712Message(domainHash, hashStruct).callAsync();
|
||||
|
||||
// Verify that the actual hash matches the expected hash
|
||||
expect(actualHash).to.be.eq(expectedHash);
|
||||
|
@@ -21,7 +21,7 @@ blockchainTests('LibRichErrors', env => {
|
||||
it('should correctly revert the extra bytes', async () => {
|
||||
const extraBytes = hexRandom(100);
|
||||
try {
|
||||
await lib.externalRRevert.callAsync(extraBytes);
|
||||
await lib.externalRRevert(extraBytes).callAsync();
|
||||
} catch (err) {
|
||||
const revertError = coerceThrownErrorAsRevertError(err);
|
||||
return expect(revertError.encode()).to.eq(extraBytes);
|
||||
@@ -33,7 +33,7 @@ blockchainTests('LibRichErrors', env => {
|
||||
|
||||
it('should correctly revert a StringRevertError', async () => {
|
||||
const error = new StringRevertError('foo');
|
||||
return expect(lib.externalRRevert.callAsync(error.encode())).to.revertWith(error);
|
||||
return expect(lib.externalRRevert(error.encode()).callAsync()).to.revertWith(error);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
@@ -30,17 +30,17 @@ blockchainTests('SafeMath', env => {
|
||||
const a = ONE_ETHER;
|
||||
const b = ONE_ETHER.times(2);
|
||||
const expected = ReferenceFunctions.safeMul(a, b);
|
||||
const actual = await safeMath.externalSafeMul.callAsync(a, b);
|
||||
const actual = await safeMath.externalSafeMul(a, b).callAsync();
|
||||
expect(actual).bignumber.to.be.eq(expected);
|
||||
});
|
||||
|
||||
it('should return zero if first argument is zero', async () => {
|
||||
const result = await safeMath.externalSafeMul.callAsync(constants.ZERO_AMOUNT, toBigNumber(1));
|
||||
const result = await safeMath.externalSafeMul(constants.ZERO_AMOUNT, toBigNumber(1)).callAsync();
|
||||
expect(result).bignumber.to.be.eq(constants.ZERO_AMOUNT);
|
||||
});
|
||||
|
||||
it('should return zero if second argument is zero', async () => {
|
||||
const result = await safeMath.externalSafeMul.callAsync(toBigNumber(1), constants.ZERO_AMOUNT);
|
||||
const result = await safeMath.externalSafeMul(toBigNumber(1), constants.ZERO_AMOUNT).callAsync();
|
||||
expect(result).bignumber.to.be.eq(constants.ZERO_AMOUNT);
|
||||
});
|
||||
|
||||
@@ -52,11 +52,11 @@ blockchainTests('SafeMath', env => {
|
||||
a,
|
||||
b,
|
||||
);
|
||||
return expect(safeMath.externalSafeMul.callAsync(a, b)).to.revertWith(expectedError);
|
||||
return expect(safeMath.externalSafeMul(a, b).callAsync()).to.revertWith(expectedError);
|
||||
});
|
||||
|
||||
it("should calculate correct value for values that don't overflow", async () => {
|
||||
const result = await safeMath.externalSafeMul.callAsync(toBigNumber(15), toBigNumber(13));
|
||||
const result = await safeMath.externalSafeMul(toBigNumber(15), toBigNumber(13)).callAsync();
|
||||
expect(result).bignumber.to.be.eq(toBigNumber(195));
|
||||
});
|
||||
});
|
||||
@@ -66,27 +66,27 @@ blockchainTests('SafeMath', env => {
|
||||
const a = ONE_ETHER;
|
||||
const b = ONE_ETHER.times(2);
|
||||
const expected = ReferenceFunctions.safeDiv(a, b);
|
||||
const actual = await safeMath.externalSafeDiv.callAsync(a, b);
|
||||
const actual = await safeMath.externalSafeDiv(a, b).callAsync();
|
||||
expect(actual).bignumber.to.be.eq(expected);
|
||||
});
|
||||
|
||||
it('should return the correct value if both values are the same', async () => {
|
||||
const result = await safeMath.externalSafeDiv.callAsync(toBigNumber(1), toBigNumber(1));
|
||||
const result = await safeMath.externalSafeDiv(toBigNumber(1), toBigNumber(1)).callAsync();
|
||||
expect(result).bignumber.to.be.eq(toBigNumber(1));
|
||||
});
|
||||
|
||||
it('should return the correct value if the values are different', async () => {
|
||||
const result = await safeMath.externalSafeDiv.callAsync(toBigNumber(3), toBigNumber(2));
|
||||
const result = await safeMath.externalSafeDiv(toBigNumber(3), toBigNumber(2)).callAsync();
|
||||
expect(result).bignumber.to.be.eq(toBigNumber(1));
|
||||
});
|
||||
|
||||
it('should return zero if the numerator is smaller than the denominator', async () => {
|
||||
const result = await safeMath.externalSafeDiv.callAsync(toBigNumber(2), toBigNumber(3));
|
||||
const result = await safeMath.externalSafeDiv(toBigNumber(2), toBigNumber(3)).callAsync();
|
||||
expect(result).bignumber.to.be.eq(constants.ZERO_AMOUNT);
|
||||
});
|
||||
|
||||
it('should return zero if first argument is zero', async () => {
|
||||
const result = await safeMath.externalSafeDiv.callAsync(constants.ZERO_AMOUNT, toBigNumber(1));
|
||||
const result = await safeMath.externalSafeDiv(constants.ZERO_AMOUNT, toBigNumber(1)).callAsync();
|
||||
expect(result).bignumber.to.be.eq(constants.ZERO_AMOUNT);
|
||||
});
|
||||
|
||||
@@ -98,7 +98,7 @@ blockchainTests('SafeMath', env => {
|
||||
a,
|
||||
b,
|
||||
);
|
||||
return expect(safeMath.externalSafeDiv.callAsync(a, b)).to.revertWith(expectedError);
|
||||
return expect(safeMath.externalSafeDiv(a, b).callAsync()).to.revertWith(expectedError);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -107,7 +107,7 @@ blockchainTests('SafeMath', env => {
|
||||
const a = ONE_ETHER;
|
||||
const b = ONE_ETHER.dividedToIntegerBy(2);
|
||||
const expected = ReferenceFunctions.safeSub(a, b);
|
||||
const actual = await safeMath.externalSafeSub.callAsync(a, b);
|
||||
const actual = await safeMath.externalSafeSub(a, b).callAsync();
|
||||
expect(actual).bignumber.to.be.eq(expected);
|
||||
});
|
||||
|
||||
@@ -119,16 +119,16 @@ blockchainTests('SafeMath', env => {
|
||||
a,
|
||||
b,
|
||||
);
|
||||
return expect(safeMath.externalSafeSub.callAsync(a, b)).to.revertWith(expectedError);
|
||||
return expect(safeMath.externalSafeSub(a, b).callAsync()).to.revertWith(expectedError);
|
||||
});
|
||||
|
||||
it('should calculate correct value for values that are equal', async () => {
|
||||
const result = await safeMath.externalSafeMul.callAsync(constants.ZERO_AMOUNT, constants.ZERO_AMOUNT);
|
||||
const result = await safeMath.externalSafeMul(constants.ZERO_AMOUNT, constants.ZERO_AMOUNT).callAsync();
|
||||
expect(result).bignumber.to.be.eq(constants.ZERO_AMOUNT);
|
||||
});
|
||||
|
||||
it('should calculate correct value for values that are not equal', async () => {
|
||||
const result = await safeMath.externalSafeSub.callAsync(toBigNumber(15), toBigNumber(13));
|
||||
const result = await safeMath.externalSafeSub(toBigNumber(15), toBigNumber(13)).callAsync();
|
||||
expect(result).bignumber.to.be.eq(toBigNumber(2));
|
||||
});
|
||||
});
|
||||
@@ -138,7 +138,7 @@ blockchainTests('SafeMath', env => {
|
||||
const a = ONE_ETHER;
|
||||
const b = ONE_ETHER.dividedToIntegerBy(2);
|
||||
const expected = ReferenceFunctions.safeAdd(a, b);
|
||||
const actual = await safeMath.externalSafeAdd.callAsync(a, b);
|
||||
const actual = await safeMath.externalSafeAdd(a, b).callAsync();
|
||||
expect(actual).bignumber.to.be.eq(expected);
|
||||
});
|
||||
|
||||
@@ -150,55 +150,55 @@ blockchainTests('SafeMath', env => {
|
||||
a,
|
||||
b,
|
||||
);
|
||||
return expect(safeMath.externalSafeAdd.callAsync(a, b)).to.revertWith(expectedError);
|
||||
return expect(safeMath.externalSafeAdd(a, b).callAsync()).to.revertWith(expectedError);
|
||||
});
|
||||
|
||||
it('should calculate correct value if addition does not overflow', async () => {
|
||||
const result = await safeMath.externalSafeAdd.callAsync(toBigNumber(15), toBigNumber(13));
|
||||
const result = await safeMath.externalSafeAdd(toBigNumber(15), toBigNumber(13)).callAsync();
|
||||
expect(result).bignumber.to.be.eq(toBigNumber(28));
|
||||
});
|
||||
|
||||
it('should calculate correct value if first argument is zero', async () => {
|
||||
const result = await safeMath.externalSafeAdd.callAsync(constants.ZERO_AMOUNT, toBigNumber(13));
|
||||
const result = await safeMath.externalSafeAdd(constants.ZERO_AMOUNT, toBigNumber(13)).callAsync();
|
||||
expect(result).bignumber.to.be.eq(toBigNumber(13));
|
||||
});
|
||||
|
||||
it('should calculate correct value if second argument is zero', async () => {
|
||||
const result = await safeMath.externalSafeAdd.callAsync(toBigNumber(13), constants.ZERO_AMOUNT);
|
||||
const result = await safeMath.externalSafeAdd(toBigNumber(13), constants.ZERO_AMOUNT).callAsync();
|
||||
expect(result).bignumber.to.be.eq(toBigNumber(13));
|
||||
});
|
||||
});
|
||||
|
||||
describe('maxUint256', () => {
|
||||
it('should return first argument if it is greater than the second', async () => {
|
||||
const result = await safeMath.externalMaxUint256.callAsync(toBigNumber(13), constants.ZERO_AMOUNT);
|
||||
const result = await safeMath.externalMaxUint256(toBigNumber(13), constants.ZERO_AMOUNT).callAsync();
|
||||
expect(result).bignumber.to.be.eq(toBigNumber(13));
|
||||
});
|
||||
|
||||
it('should return first argument if it is equal the second', async () => {
|
||||
const result = await safeMath.externalMaxUint256.callAsync(constants.ZERO_AMOUNT, constants.ZERO_AMOUNT);
|
||||
const result = await safeMath.externalMaxUint256(constants.ZERO_AMOUNT, constants.ZERO_AMOUNT).callAsync();
|
||||
expect(result).bignumber.to.be.eq(constants.ZERO_AMOUNT);
|
||||
});
|
||||
|
||||
it('should return second argument if it is greater than the first', async () => {
|
||||
const result = await safeMath.externalMaxUint256.callAsync(constants.ZERO_AMOUNT, toBigNumber(13));
|
||||
const result = await safeMath.externalMaxUint256(constants.ZERO_AMOUNT, toBigNumber(13)).callAsync();
|
||||
expect(result).bignumber.to.be.eq(toBigNumber(13));
|
||||
});
|
||||
});
|
||||
|
||||
describe('minUint256', () => {
|
||||
it('should return first argument if it is less than the second', async () => {
|
||||
const result = await safeMath.externalMaxUint256.callAsync(constants.ZERO_AMOUNT, toBigNumber(13));
|
||||
const result = await safeMath.externalMaxUint256(constants.ZERO_AMOUNT, toBigNumber(13)).callAsync();
|
||||
expect(result).bignumber.to.be.eq(toBigNumber(13));
|
||||
});
|
||||
|
||||
it('should return first argument if it is equal the second', async () => {
|
||||
const result = await safeMath.externalMaxUint256.callAsync(constants.ZERO_AMOUNT, constants.ZERO_AMOUNT);
|
||||
const result = await safeMath.externalMaxUint256(constants.ZERO_AMOUNT, constants.ZERO_AMOUNT).callAsync();
|
||||
expect(result).bignumber.to.be.eq(constants.ZERO_AMOUNT);
|
||||
});
|
||||
|
||||
it('should return second argument if it is less than the first', async () => {
|
||||
const result = await safeMath.externalMaxUint256.callAsync(toBigNumber(13), constants.ZERO_AMOUNT);
|
||||
const result = await safeMath.externalMaxUint256(toBigNumber(13), constants.ZERO_AMOUNT).callAsync();
|
||||
expect(result).bignumber.to.be.eq(toBigNumber(13));
|
||||
});
|
||||
});
|
||||
|
@@ -49,19 +49,25 @@ describe('TestLogDecoding', () => {
|
||||
|
||||
describe('Decoding Log Arguments', () => {
|
||||
it('should decode locally emitted event args when no dependencies are passed into wrapper', async () => {
|
||||
const txReceipt = await testLogDecodingDeployedWithoutDependencies.emitEvent.awaitTransactionSuccessAsync();
|
||||
const txReceipt = await testLogDecodingDeployedWithoutDependencies
|
||||
.emitEvent()
|
||||
.awaitTransactionSuccessAsync();
|
||||
expect(txReceipt.logs.length).to.be.equal(1);
|
||||
// tslint:disable no-unnecessary-type-assertion
|
||||
expect((txReceipt.logs[0] as LogWithDecodedArgs<DecodedLogArgs>).args).to.be.deep.equal(expectedEvent);
|
||||
});
|
||||
it('should not decode event args when no dependencies are passed into wrapper', async () => {
|
||||
const txReceipt = await testLogDecodingDeployedWithoutDependencies.emitEventDownstream.awaitTransactionSuccessAsync();
|
||||
const txReceipt = await testLogDecodingDeployedWithoutDependencies
|
||||
.emitEventDownstream()
|
||||
.awaitTransactionSuccessAsync();
|
||||
expect(txReceipt.logs.length).to.be.equal(1);
|
||||
// tslint:disable no-unnecessary-type-assertion
|
||||
expect((txReceipt.logs[0] as LogWithDecodedArgs<DecodedLogArgs>).args).to.be.undefined();
|
||||
});
|
||||
it('should decode args for local but not downstream event when no dependencies are passed into wrapper', async () => {
|
||||
const txReceipt = await testLogDecodingDeployedWithoutDependencies.emitEventsLocalAndDownstream.awaitTransactionSuccessAsync();
|
||||
const txReceipt = await testLogDecodingDeployedWithoutDependencies
|
||||
.emitEventsLocalAndDownstream()
|
||||
.awaitTransactionSuccessAsync();
|
||||
expect(txReceipt.logs.length).to.be.equal(2);
|
||||
// tslint:disable no-unnecessary-type-assertion
|
||||
expect((txReceipt.logs[0] as LogWithDecodedArgs<DecodedLogArgs>).args).to.be.deep.equal(expectedEvent);
|
||||
@@ -69,13 +75,15 @@ describe('TestLogDecoding', () => {
|
||||
expect((txReceipt.logs[1] as LogWithDecodedArgs<DecodedLogArgs>).args).to.be.undefined();
|
||||
});
|
||||
it('should decode locally emitted event args when dependencies are passed into wrapper', async () => {
|
||||
const txReceipt = await testLogDecodingWithDependencies.emitEvent.awaitTransactionSuccessAsync();
|
||||
const txReceipt = await testLogDecodingWithDependencies.emitEvent().awaitTransactionSuccessAsync();
|
||||
expect(txReceipt.logs.length).to.be.equal(1);
|
||||
// tslint:disable no-unnecessary-type-assertion
|
||||
expect((txReceipt.logs[0] as LogWithDecodedArgs<DecodedLogArgs>).args).to.be.deep.equal(expectedEvent);
|
||||
});
|
||||
it('should decode downstream event args when dependencies are passed into wrapper', async () => {
|
||||
const txReceipt = await testLogDecodingWithDependencies.emitEventDownstream.awaitTransactionSuccessAsync();
|
||||
const txReceipt = await testLogDecodingWithDependencies
|
||||
.emitEventDownstream()
|
||||
.awaitTransactionSuccessAsync();
|
||||
expect(txReceipt.logs.length).to.be.equal(1);
|
||||
// tslint:disable no-unnecessary-type-assertion
|
||||
expect((txReceipt.logs[0] as LogWithDecodedArgs<DecodedLogArgs>).args).to.be.deep.equal(
|
||||
@@ -83,7 +91,9 @@ describe('TestLogDecoding', () => {
|
||||
);
|
||||
});
|
||||
it('should decode args for both local and downstream events when dependencies are passed into wrapper', async () => {
|
||||
const txReceipt = await testLogDecodingWithDependencies.emitEventsLocalAndDownstream.awaitTransactionSuccessAsync();
|
||||
const txReceipt = await testLogDecodingWithDependencies
|
||||
.emitEventsLocalAndDownstream()
|
||||
.awaitTransactionSuccessAsync();
|
||||
expect(txReceipt.logs.length).to.be.equal(2);
|
||||
// tslint:disable no-unnecessary-type-assertion
|
||||
expect((txReceipt.logs[0] as LogWithDecodedArgs<DecodedLogArgs>).args).to.be.deep.equal(expectedEvent);
|
||||
|
@@ -24,11 +24,11 @@ blockchainTests.resets('Ownable', env => {
|
||||
describe('onlyOwner', () => {
|
||||
it('should revert if sender is not the owner', async () => {
|
||||
const expectedError = new OwnableRevertErrors.OnlyOwnerError(nonOwner, owner);
|
||||
return expect(ownable.externalOnlyOwner.callAsync({ from: nonOwner })).to.revertWith(expectedError);
|
||||
return expect(ownable.externalOnlyOwner().callAsync({ from: nonOwner })).to.revertWith(expectedError);
|
||||
});
|
||||
|
||||
it('should succeed if sender is the owner', async () => {
|
||||
const isSuccessful = await ownable.externalOnlyOwner.callAsync({ from: owner });
|
||||
const isSuccessful = await ownable.externalOnlyOwner().callAsync({ from: owner });
|
||||
expect(isSuccessful).to.be.true();
|
||||
});
|
||||
});
|
||||
@@ -36,12 +36,12 @@ blockchainTests.resets('Ownable', env => {
|
||||
describe('transferOwnership', () => {
|
||||
it('should revert if the specified new owner is the zero address', async () => {
|
||||
const expectedError = new OwnableRevertErrors.TransferOwnerToZeroError();
|
||||
const tx = ownable.transferOwnership.sendTransactionAsync(constants.NULL_ADDRESS, { from: owner });
|
||||
const tx = ownable.transferOwnership(constants.NULL_ADDRESS).sendTransactionAsync({ from: owner });
|
||||
return expect(tx).to.revertWith(expectedError);
|
||||
});
|
||||
|
||||
it('should transfer ownership if the specified new owner is not the zero address', async () => {
|
||||
const receipt = await ownable.transferOwnership.awaitTransactionSuccessAsync(nonOwner, { from: owner });
|
||||
const receipt = await ownable.transferOwnership(nonOwner).awaitTransactionSuccessAsync({ from: owner });
|
||||
|
||||
// Ensure that the correct logs were emitted.
|
||||
expect(receipt.logs.length).to.be.eq(1);
|
||||
@@ -52,7 +52,7 @@ blockchainTests.resets('Ownable', env => {
|
||||
expect(event).to.be.deep.eq({ previousOwner: owner, newOwner: nonOwner });
|
||||
|
||||
// Ensure that the owner was actually updated
|
||||
const updatedOwner = await ownable.owner.callAsync();
|
||||
const updatedOwner = await ownable.owner().callAsync();
|
||||
expect(updatedOwner).to.be.eq(nonOwner);
|
||||
});
|
||||
});
|
||||
|
@@ -32,11 +32,11 @@ describe('ReentrancyGuard', () => {
|
||||
describe('nonReentrant', () => {
|
||||
it('should revert if reentrancy occurs', async () => {
|
||||
const expectedError = new ReentrancyGuardRevertErrors.IllegalReentrancyError();
|
||||
return expect(guard.guarded.sendTransactionAsync(true)).to.revertWith(expectedError);
|
||||
return expect(guard.guarded(true).sendTransactionAsync()).to.revertWith(expectedError);
|
||||
});
|
||||
|
||||
it('should succeed if reentrancy does not occur', async () => {
|
||||
const isSuccessful = await guard.guarded.callAsync(false);
|
||||
const isSuccessful = await guard.guarded(false).callAsync();
|
||||
expect(isSuccessful).to.be.true();
|
||||
});
|
||||
});
|
||||
|
@@ -36,14 +36,14 @@ blockchainTests('Refundable', env => {
|
||||
blockchainTests.resets('refundNonzeroBalance', () => {
|
||||
it('should not send a refund when no value is sent', async () => {
|
||||
// Send 100 wei to the refundable contract that should be refunded.
|
||||
await receiver.testRefundNonZeroBalance.awaitTransactionSuccessAsync(refundable.address, {
|
||||
await receiver.testRefundNonZeroBalance(refundable.address).awaitTransactionSuccessAsync({
|
||||
value: constants.ZERO_AMOUNT,
|
||||
});
|
||||
});
|
||||
|
||||
it('should send a full refund when nonzero value is sent', async () => {
|
||||
// Send 100 wei to the refundable contract that should be refunded.
|
||||
await receiver.testRefundNonZeroBalance.awaitTransactionSuccessAsync(refundable.address, {
|
||||
await receiver.testRefundNonZeroBalance(refundable.address).awaitTransactionSuccessAsync({
|
||||
value: ONE_HUNDRED,
|
||||
});
|
||||
});
|
||||
@@ -54,7 +54,7 @@ blockchainTests('Refundable', env => {
|
||||
blockchainTests.resets('refundFinalBalance', () => {
|
||||
it('should fully refund the sender when `shouldNotRefund` is false', async () => {
|
||||
// Send 100 wei to the refundable contract that should be refunded to the receiver contract.
|
||||
await receiver.testRefundFinalBalance.awaitTransactionSuccessAsync(refundable.address, false, {
|
||||
await receiver.testRefundFinalBalance(refundable.address, false).awaitTransactionSuccessAsync({
|
||||
value: ONE_HUNDRED,
|
||||
});
|
||||
});
|
||||
@@ -62,19 +62,19 @@ blockchainTests('Refundable', env => {
|
||||
// This test may not be necessary, but it is included here as a sanity check.
|
||||
it('should fully refund the sender when `shouldNotRefund` is false for two calls in a row', async () => {
|
||||
// Send 100 wei to the refundable contract that should be refunded to the receiver contract.
|
||||
await receiver.testRefundFinalBalance.awaitTransactionSuccessAsync(refundable.address, false, {
|
||||
await receiver.testRefundFinalBalance(refundable.address, false).awaitTransactionSuccessAsync({
|
||||
value: ONE_HUNDRED,
|
||||
});
|
||||
|
||||
// Send 1000 wei to the refundable contract that should be refunded to the receiver contract.
|
||||
await receiver.testRefundFinalBalance.awaitTransactionSuccessAsync(refundable.address, false, {
|
||||
await receiver.testRefundFinalBalance(refundable.address, false).awaitTransactionSuccessAsync({
|
||||
value: new BigNumber(1000),
|
||||
});
|
||||
});
|
||||
|
||||
it('should not refund the sender if `shouldNotRefund` is true', async () => {
|
||||
/// Send 100 wei to the refundable contract that should not be refunded.
|
||||
await receiver.testRefundFinalBalance.awaitTransactionSuccessAsync(refundable.address, true, {
|
||||
await receiver.testRefundFinalBalance(refundable.address, true).awaitTransactionSuccessAsync({
|
||||
value: new BigNumber(1000),
|
||||
});
|
||||
});
|
||||
@@ -85,7 +85,7 @@ blockchainTests('Refundable', env => {
|
||||
blockchainTests.resets('disableRefundUntilEnd', () => {
|
||||
it('should fully refund the sender when `shouldNotRefund` is false', async () => {
|
||||
// Send 100 wei to the refundable contract that should be refunded to the receiver contract.
|
||||
await receiver.testDisableRefundUntilEnd.awaitTransactionSuccessAsync(refundable.address, false, {
|
||||
await receiver.testDisableRefundUntilEnd(refundable.address, false).awaitTransactionSuccessAsync({
|
||||
value: ONE_HUNDRED,
|
||||
});
|
||||
});
|
||||
@@ -93,47 +93,47 @@ blockchainTests('Refundable', env => {
|
||||
// This test may not be necessary, but it is included here as a sanity check.
|
||||
it('should fully refund the sender when `shouldNotRefund` is false for two calls in a row', async () => {
|
||||
// Send 100 wei to the refundable contract that should be refunded to the receiver contract.
|
||||
await receiver.testDisableRefundUntilEnd.awaitTransactionSuccessAsync(refundable.address, false, {
|
||||
await receiver.testDisableRefundUntilEnd(refundable.address, false).awaitTransactionSuccessAsync({
|
||||
value: ONE_HUNDRED,
|
||||
});
|
||||
|
||||
// Send 1000 wei to the refundable contract that should be refunded to the receiver contract.
|
||||
await receiver.testDisableRefundUntilEnd.awaitTransactionSuccessAsync(refundable.address, false, {
|
||||
await receiver.testDisableRefundUntilEnd(refundable.address, false).awaitTransactionSuccessAsync({
|
||||
value: ONE_THOUSAND,
|
||||
});
|
||||
});
|
||||
|
||||
it('should not refund the sender if `shouldNotRefund` is true', async () => {
|
||||
/// Send 100 wei to the refundable contract that should not be refunded.
|
||||
await receiver.testDisableRefundUntilEnd.awaitTransactionSuccessAsync(refundable.address, false, {
|
||||
await receiver.testDisableRefundUntilEnd(refundable.address, false).awaitTransactionSuccessAsync({
|
||||
value: ONE_HUNDRED,
|
||||
});
|
||||
});
|
||||
|
||||
it('should disable the `disableRefundUntilEnd` modifier and refund when `shouldNotRefund` is false', async () => {
|
||||
/// Send 100 wei to the refundable contract that should be refunded.
|
||||
await receiver.testNestedDisableRefundUntilEnd.awaitTransactionSuccessAsync(refundable.address, false, {
|
||||
await receiver.testNestedDisableRefundUntilEnd(refundable.address, false).awaitTransactionSuccessAsync({
|
||||
value: ONE_HUNDRED,
|
||||
});
|
||||
});
|
||||
|
||||
it('should disable the `refundFinalBalance` modifier and send no refund when `shouldNotRefund` is true', async () => {
|
||||
/// Send 100 wei to the refundable contract that should not be refunded.
|
||||
await receiver.testNestedDisableRefundUntilEnd.awaitTransactionSuccessAsync(refundable.address, true, {
|
||||
await receiver.testNestedDisableRefundUntilEnd(refundable.address, true).awaitTransactionSuccessAsync({
|
||||
value: ONE_HUNDRED,
|
||||
});
|
||||
});
|
||||
|
||||
it('should disable the `refundFinalBalance` modifier and refund when `shouldNotRefund` is false', async () => {
|
||||
/// Send 100 wei to the refundable contract that should be refunded.
|
||||
await receiver.testMixedRefunds.awaitTransactionSuccessAsync(refundable.address, false, {
|
||||
await receiver.testMixedRefunds(refundable.address, false).awaitTransactionSuccessAsync({
|
||||
value: ONE_HUNDRED,
|
||||
});
|
||||
});
|
||||
|
||||
it('should disable the `refundFinalBalance` modifier and send no refund when `shouldNotRefund` is true', async () => {
|
||||
/// Send 100 wei to the refundable contract that should not be refunded.
|
||||
await receiver.testMixedRefunds.awaitTransactionSuccessAsync(refundable.address, true, {
|
||||
await receiver.testMixedRefunds(refundable.address, true).awaitTransactionSuccessAsync({
|
||||
value: ONE_HUNDRED,
|
||||
});
|
||||
});
|
||||
|
Reference in New Issue
Block a user