diff options
author | Amir Bandeali <abandeali1@gmail.com> | 2018-06-13 06:29:18 +0800 |
---|---|---|
committer | Amir Bandeali <abandeali1@gmail.com> | 2018-06-13 06:30:46 +0800 |
commit | 0917fa0d75b7328c156af2ffafa641ae09286e2e (patch) | |
tree | 6caa5f5dfb2029a4285baa69a9f6eb2250675b94 /packages | |
parent | cfb73dd53417895fbc2fadfae29412b4288a63ef (diff) | |
download | dexon-sol-tools-0917fa0d75b7328c156af2ffafa641ae09286e2e.tar dexon-sol-tools-0917fa0d75b7328c156af2ffafa641ae09286e2e.tar.gz dexon-sol-tools-0917fa0d75b7328c156af2ffafa641ae09286e2e.tar.bz2 dexon-sol-tools-0917fa0d75b7328c156af2ffafa641ae09286e2e.tar.lz dexon-sol-tools-0917fa0d75b7328c156af2ffafa641ae09286e2e.tar.xz dexon-sol-tools-0917fa0d75b7328c156af2ffafa641ae09286e2e.tar.zst dexon-sol-tools-0917fa0d75b7328c156af2ffafa641ae09286e2e.zip |
Rename popByte and popAddress
Diffstat (limited to 'packages')
5 files changed, 18 insertions, 18 deletions
diff --git a/packages/contracts/src/contracts/current/protocol/Exchange/MixinSettlement.sol b/packages/contracts/src/contracts/current/protocol/Exchange/MixinSettlement.sol index 69b70112f..29a9c87bd 100644 --- a/packages/contracts/src/contracts/current/protocol/Exchange/MixinSettlement.sol +++ b/packages/contracts/src/contracts/current/protocol/Exchange/MixinSettlement.sol @@ -62,8 +62,8 @@ contract MixinSettlement is ) internal { - uint8 makerAssetProxyId = uint8(popByte(order.makerAssetData)); - uint8 takerAssetProxyId = uint8(popByte(order.takerAssetData)); + uint8 makerAssetProxyId = uint8(popLastByte(order.makerAssetData)); + uint8 takerAssetProxyId = uint8(popLastByte(order.takerAssetData)); bytes memory zrxAssetData = ZRX_ASSET_DATA; dispatchTransferFrom( order.makerAssetData, @@ -108,8 +108,8 @@ contract MixinSettlement is ) internal { - uint8 leftMakerAssetProxyId = uint8(popByte(leftOrder.makerAssetData)); - uint8 rightMakerAssetProxyId = uint8(popByte(rightOrder.makerAssetData)); + uint8 leftMakerAssetProxyId = uint8(popLastByte(leftOrder.makerAssetData)); + uint8 rightMakerAssetProxyId = uint8(popLastByte(rightOrder.makerAssetData)); bytes memory zrxAssetData = ZRX_ASSET_DATA; // Order makers and taker dispatchTransferFrom( diff --git a/packages/contracts/src/contracts/current/protocol/Exchange/MixinSignatureValidator.sol b/packages/contracts/src/contracts/current/protocol/Exchange/MixinSignatureValidator.sol index 48a0c5552..1a556dfe2 100644 --- a/packages/contracts/src/contracts/current/protocol/Exchange/MixinSignatureValidator.sol +++ b/packages/contracts/src/contracts/current/protocol/Exchange/MixinSignatureValidator.sol @@ -93,7 +93,7 @@ contract MixinSignatureValidator is ); // Pop last byte off of signature byte array. - SignatureType signatureType = SignatureType(uint8(popByte(signature))); + SignatureType signatureType = SignatureType(uint8(popLastByte(signature))); // Variables are not scoped in Solidity. uint8 v; @@ -183,7 +183,7 @@ contract MixinSignatureValidator is // | 0x14 + x | 1 | Signature type is always "\x06" | } else if (signatureType == SignatureType.Validator) { // Pop last 20 bytes off of signature byte array. - address validator = popAddress(signature); + address validator = popLast20Bytes(signature); // Ensure signer has approved validator. if (!allowedValidators[signer][validator]) { return false; diff --git a/packages/contracts/src/contracts/current/test/TestLibBytes/TestLibBytes.sol b/packages/contracts/src/contracts/current/test/TestLibBytes/TestLibBytes.sol index abce0cb22..6f1898acd 100644 --- a/packages/contracts/src/contracts/current/test/TestLibBytes/TestLibBytes.sol +++ b/packages/contracts/src/contracts/current/test/TestLibBytes/TestLibBytes.sol @@ -28,24 +28,24 @@ contract TestLibBytes is /// @dev Pops the last byte off of a byte array by modifying its length. /// @param b Byte array that will be modified. /// @return The byte that was popped off. - function publicPopByte(bytes memory b) + function publicPopLastByte(bytes memory b) public pure returns (bytes memory, bytes1 result) { - result = popByte(b); + result = popLastByte(b); return (b, result); } /// @dev Pops the last 20 bytes off of a byte array by modifying its length. /// @param b Byte array that will be modified. /// @return The 20 byte address that was popped off. - function publicPopAddress(bytes memory b) + function publicPopLast20Bytes(bytes memory b) public pure returns (bytes memory, address result) { - result = popAddress(b); + result = popLast20Bytes(b); return (b, result); } diff --git a/packages/contracts/src/contracts/current/utils/LibBytes/LibBytes.sol b/packages/contracts/src/contracts/current/utils/LibBytes/LibBytes.sol index 339270a57..10d7ce41a 100644 --- a/packages/contracts/src/contracts/current/utils/LibBytes/LibBytes.sol +++ b/packages/contracts/src/contracts/current/utils/LibBytes/LibBytes.sol @@ -35,7 +35,7 @@ contract LibBytes is /// @dev Pops the last byte off of a byte array by modifying its length. /// @param b Byte array that will be modified. /// @return The byte that was popped off. - function popByte(bytes memory b) + function popLastByte(bytes memory b) internal pure returns (bytes1 result) @@ -59,7 +59,7 @@ contract LibBytes is /// @dev Pops the last 20 bytes off of a byte array by modifying its length. /// @param b Byte array that will be modified. /// @return The 20 byte address that was popped off. - function popAddress(bytes memory b) + function popLast20Bytes(bytes memory b) internal pure returns (address result) diff --git a/packages/contracts/test/libraries/lib_bytes.ts b/packages/contracts/test/libraries/lib_bytes.ts index 25e75a505..a31a4789c 100644 --- a/packages/contracts/test/libraries/lib_bytes.ts +++ b/packages/contracts/test/libraries/lib_bytes.ts @@ -91,15 +91,15 @@ describe('LibBytes', () => { await blockchainLifecycle.revertAsync(); }); - describe('popByte', () => { + describe('popLastByte', () => { it('should revert if length is 0', async () => { return expectRevertOrOtherErrorAsync( - libBytes.publicPopByte.callAsync(constants.NULL_BYTES), + libBytes.publicPopLastByte.callAsync(constants.NULL_BYTES), constants.LIB_BYTES_GREATER_THAN_ZERO_LENGTH_REQUIRED, ); }); it('should pop the last byte from the input and return it', async () => { - const [newBytes, poppedByte] = await libBytes.publicPopByte.callAsync(byteArrayLongerThan32Bytes); + 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); @@ -107,15 +107,15 @@ describe('LibBytes', () => { }); }); - describe('popAddress', () => { + describe('popLast20Bytes', () => { it('should revert if length is less than 20', async () => { return expectRevertOrOtherErrorAsync( - libBytes.publicPopAddress.callAsync(byteArrayShorterThan20Bytes), + libBytes.publicPopLast20Bytes.callAsync(byteArrayShorterThan20Bytes), constants.LIB_BYTES_GREATER_OR_EQUAL_TO_20_LENGTH_REQUIRED, ); }); it('should pop the last 20 bytes from the input and return it', async () => { - const [newBytes, poppedAddress] = await libBytes.publicPopAddress.callAsync(byteArrayLongerThan32Bytes); + 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); |