From 7667fb02786dae17d4f9eff94af4d27a223a9f81 Mon Sep 17 00:00:00 2001 From: yonada Date: Fri, 12 Jan 2024 16:28:39 +0000 Subject: [PATCH] refactor(store,world): delete unused functions and variables [N-04] (#2090) Co-authored-by: Kevin Ingersoll --- packages/store/gas-report.json | 48 --- packages/store/src/Bytes.sol | 478 ---------------------- packages/store/src/ResourceId.sol | 5 - packages/store/src/Slice.sol | 1 - packages/store/test/Bytes.t.sol | 114 ------ packages/store/test/StoreCore.t.sol | 4 +- packages/world/src/worldResourceTypes.sol | 8 - 7 files changed, 2 insertions(+), 656 deletions(-) diff --git a/packages/store/gas-report.json b/packages/store/gas-report.json index 52bcf844a7..a519e817cd 100644 --- a/packages/store/gas-report.json +++ b/packages/store/gas-report.json @@ -1,64 +1,16 @@ [ - { - "file": "test/Bytes.t.sol", - "test": "testEquals", - "name": "compare equal bytes", - "gasUsed": 196 - }, - { - "file": "test/Bytes.t.sol", - "test": "testEqualsFalse", - "name": "compare unequal bytes", - "gasUsed": 196 - }, - { - "file": "test/Bytes.t.sol", - "test": "testSetBytes1", - "name": "set bytes1 in bytes32", - "gasUsed": 16 - }, - { - "file": "test/Bytes.t.sol", - "test": "testSetBytes2", - "name": "set bytes2 in bytes32", - "gasUsed": 16 - }, - { - "file": "test/Bytes.t.sol", - "test": "testSetBytes4", - "name": "set bytes4 in bytes32", - "gasUsed": 16 - }, { "file": "test/Bytes.t.sol", "test": "testSetBytes4Memory", "name": "set bytes4 in bytes memory", "gasUsed": 37 }, - { - "file": "test/Bytes.t.sol", - "test": "testSlice3", - "name": "slice bytes3 with offset 1", - "gasUsed": 68 - }, { "file": "test/Bytes.t.sol", "test": "testSlice32", "name": "slice bytes32 with offset 10", "gasUsed": 68 }, - { - "file": "test/Bytes.t.sol", - "test": "testToBytes32", - "name": "create bytes32 from bytes memory with offset 0", - "gasUsed": 25 - }, - { - "file": "test/Bytes.t.sol", - "test": "testToBytes32CrossWord", - "name": "create bytes32 from bytes memory with offset 16", - "gasUsed": 36 - }, { "file": "test/Callbacks.t.sol", "test": "testSetAndGet", diff --git a/packages/store/src/Bytes.sol b/packages/store/src/Bytes.sol index 1c81f79a58..4da11f7ff3 100644 --- a/packages/store/src/Bytes.sol +++ b/packages/store/src/Bytes.sol @@ -6,41 +6,12 @@ pragma solidity >=0.8.21; * @notice Utility functions for bytes. */ library Bytes { - /** - * @dev Converts a `bytes` memory blob to a single `bytes32` memory value, starting at the given byte offset. - * @param input The `bytes` blob to read from. - * @param offset The byte offset at which to start reading. - * @return output The `bytes32` value. - */ - function toBytes32(bytes memory input, uint256 offset) internal pure returns (bytes32 output) { - assembly { - // input is a pointer to the start of the bytes array - // in memory, the first 32 bytes are the length of the array - // so we add 32 to the pointer to get to the start of the data - // then we add the start offset to get to the start of the desired word - output := mload(add(input, add(0x20, offset))) - } - } - /************************************************************************ * * UTILS * ************************************************************************/ - /** - * @dev Compares two bytes blobs for equality. - * @param a First bytes blob. - * @param b Second bytes blob. - * @return True if the two bytes blobs are equal, false otherwise. - */ - function equals(bytes memory a, bytes memory b) internal pure returns (bool) { - if (a.length != b.length) { - return false; - } - return keccak256(a) == keccak256(b); - } - /** * @dev Sets the length of a bytes blob in memory. * This function does not resize the memory allocation; it only changes the length @@ -62,57 +33,6 @@ library Bytes { * ************************************************************************/ - /** - * @dev Sets a specific byte in a bytes32 value. - * @param input The bytes32 data in which a specific byte is to be altered. - * @param index The position of the byte to be altered. Index starts from the left. - * @param overwrite The new byte value to be set at the specified index. - * @return output The modified bytes32 data with the new byte value at the specified index. - */ - function setBytes1(bytes32 input, uint256 index, bytes1 overwrite) internal pure returns (bytes32 output) { - bytes1 mask = 0xff; - assembly { - mask := shr(mul(8, index), mask) // create a mask by shifting 0xff right by index bytes - output := and(input, not(mask)) // zero out the byte at index - output := or(output, shr(mul(8, index), overwrite)) // set the byte at index - } - return output; - } - - /** - * @dev Sets a specific 2-byte sequence in a bytes32 variable. - * @param input The bytes32 data in which a specific 2-byte sequence is to be altered. - * @param index The position of the 2-byte sequence to be altered. Index starts from the left. - * @param overwrite The new 2-byte value to be set at the specified index. - * @return output The modified bytes32 data with the new 2-byte value at the specified index. - */ - function setBytes2(bytes32 input, uint256 index, bytes2 overwrite) internal pure returns (bytes32 output) { - bytes2 mask = 0xffff; - assembly { - mask := shr(mul(8, index), mask) // create a mask by shifting 0xffff right by index bytes - output := and(input, not(mask)) // zero out the byte at index - output := or(output, shr(mul(8, index), overwrite)) // set the byte at index - } - return output; - } - - /** - * @dev Sets a specific 4-byte sequence in a bytes32 variable. - * @param input The bytes32 data in which a specific 4-byte sequence is to be altered. - * @param index The position of the 4-byte sequence to be altered. Index starts from the left. - * @param overwrite The new 4-byte value to be set at the specified index. - * @return output The modified bytes32 data with the new 4-byte value at the specified index. - */ - function setBytes4(bytes32 input, uint256 index, bytes4 overwrite) internal pure returns (bytes32 output) { - bytes4 mask = 0xffffffff; - assembly { - mask := shr(mul(8, index), mask) // create a mask by shifting 0xffffffff right by index bytes - output := and(input, not(mask)) // zero out the byte at index - output := or(output, shr(mul(8, index), overwrite)) // set the byte at index - } - return output; - } - /** * @dev Sets a specific 4-byte sequence in a bytes blob at a given index. * @param input The bytes blob in which a specific 4-byte sequence is to be altered. @@ -131,40 +51,6 @@ library Bytes { return input; } - /** - * @dev Sets a specific 5-byte sequence in a bytes32 variable. - * @param input The bytes32 data in which a specific 5-byte sequence is to be altered. - * @param index The position of the 5-byte sequence to be altered. Index starts from the left. - * @param overwrite The new 5-byte value to be set at the specified index. - * @return output The modified bytes32 data with the new 5-byte value at the specified index. - */ - function setBytes5(bytes32 input, uint256 index, bytes5 overwrite) internal pure returns (bytes32 output) { - bytes5 mask = bytes5(type(uint40).max); - assembly { - mask := shr(mul(8, index), mask) // create a mask by shifting 0xff...ff right by index bytes - output := and(input, not(mask)) // zero out the byte at index - output := or(output, shr(mul(8, index), overwrite)) // set the byte at index - } - return output; - } - - /** - * @dev Sets a specific 7-byte sequence in a bytes32 variable. - * @param input The bytes32 data in which a specific 7-byte sequence is to be altered. - * @param index The position of the 7-byte sequence to be altered. Index starts from the left. - * @param overwrite The new 7-byte value to be set at the specified index. - * @return output The modified bytes32 data with the new 7-byte value at the specified index. - */ - function setBytes7(bytes32 input, uint256 index, bytes7 overwrite) internal pure returns (bytes32 output) { - bytes7 mask = bytes7(type(uint56).max); - assembly { - mask := shr(mul(8, index), mask) // create a mask by shifting 0xff...ff right by index bytes - output := and(input, not(mask)) // zero out the byte at index - output := or(output, shr(mul(8, index), overwrite)) // set the byte at index - } - return output; - } - /************************************************************************ * * SLICE @@ -227,20 +113,6 @@ library Bytes { return output; } - /** - * @dev Extracts a 3-byte sequence from a bytes blob starting at a specific position. - * @param data The bytes blob from which a 3-byte sequence is to be extracted. - * @param start The starting position within the bytes blob for extraction. - * @return The extracted bytes3 value from the specified position in the bytes blob. - */ - function slice3(bytes memory data, uint256 start) internal pure returns (bytes3) { - bytes3 output; - assembly { - output := mload(add(add(data, 0x20), start)) - } - return output; - } - /** * @dev Extracts a 4-byte sequence from a bytes blob starting at a specific position. * @param data The bytes blob from which a 4-byte sequence is to be extracted. @@ -255,20 +127,6 @@ library Bytes { return output; } - /** - * @dev Extracts a 4-byte sequence from a bytes32 value starting at a specific position. - * @param data The bytes32 value from which a 4-byte sequence is to be extracted. - * @param start The starting position within the bytes32 value for extraction. - * @return The extracted bytes4 value from the specified position in the bytes32 value. - */ - function slice4(bytes32 data, uint256 start) internal pure returns (bytes4) { - bytes4 output; - assembly { - output := shl(mul(8, start), data) - } - return output; - } - /** * @dev Extracts a 5-byte sequence from a bytes blob starting at a specific position. * @param data The bytes blob from which a 5-byte sequence is to be extracted. @@ -283,48 +141,6 @@ library Bytes { return output; } - /** - * @dev Extracts a 5-byte sequence from a bytes32 value starting at a specific position. - * @param data The bytes32 value from which a 5-byte sequence is to be extracted. - * @param start The starting position within the bytes32 value for extraction. - * @return The extracted bytes5 value from the specified position in the bytes32 value. - */ - function slice5(bytes32 data, uint256 start) internal pure returns (bytes5) { - bytes5 output; - assembly { - output := shl(mul(8, start), data) - } - return output; - } - - /** - * @dev Extracts a 6-byte sequence from a bytes blob starting at a specific position. - * @param data The bytes blob from which a 6-byte sequence is to be extracted. - * @param start The starting position within the bytes blob for extraction. - * @return The extracted bytes6 value from the specified position in the bytes blob. - */ - function slice6(bytes memory data, uint256 start) internal pure returns (bytes6) { - bytes6 output; - assembly { - output := mload(add(add(data, 0x20), start)) - } - return output; - } - - /** - * @dev Extracts a 7-byte sequence from a bytes blob starting at a specific position. - * @param data The bytes blob from which a 7-byte sequence is to be extracted. - * @param start The starting position within the bytes blob for extraction. - * @return The extracted bytes7 value from the specified position in the bytes blob. - */ - function slice7(bytes memory data, uint256 start) internal pure returns (bytes7) { - bytes7 output; - assembly { - output := mload(add(add(data, 0x20), start)) - } - return output; - } - /** * @dev Extracts a 8-byte sequence from a bytes blob starting at a specific position. * @param data The bytes blob from which a 8-byte sequence is to be extracted. @@ -339,104 +155,6 @@ library Bytes { return output; } - /** - * @dev Extracts a 9-byte sequence from a bytes blob starting at a specific position. - * @param data The bytes blob from which a 9-byte sequence is to be extracted. - * @param start The starting position within the bytes blob for extraction. - * @return The extracted bytes9 value from the specified position in the bytes blob. - */ - function slice9(bytes memory data, uint256 start) internal pure returns (bytes9) { - bytes9 output; - assembly { - output := mload(add(add(data, 0x20), start)) - } - return output; - } - - /** - * @dev Extracts a 10-byte sequence from a bytes blob starting at a specific position. - * @param data The bytes blob from which a 10-byte sequence is to be extracted. - * @param start The starting position within the bytes blob for extraction. - * @return The extracted bytes10 value from the specified position in the bytes blob. - */ - function slice10(bytes memory data, uint256 start) internal pure returns (bytes10) { - bytes10 output; - assembly { - output := mload(add(add(data, 0x20), start)) - } - return output; - } - - /** - * @dev Extracts a 11-byte sequence from a bytes blob starting at a specific position. - * @param data The bytes blob from which a 11-byte sequence is to be extracted. - * @param start The starting position within the bytes blob for extraction. - * @return The extracted bytes11 value from the specified position in the bytes blob. - */ - function slice11(bytes memory data, uint256 start) internal pure returns (bytes11) { - bytes11 output; - assembly { - output := mload(add(add(data, 0x20), start)) - } - return output; - } - - /** - * @dev Extracts a 12-byte sequence from a bytes blob starting at a specific position. - * @param data The bytes blob from which a 12-byte sequence is to be extracted. - * @param start The starting position within the bytes blob for extraction. - * @return The extracted bytes12 value from the specified position in the bytes blob. - */ - function slice12(bytes memory data, uint256 start) internal pure returns (bytes12) { - bytes12 output; - assembly { - output := mload(add(add(data, 0x20), start)) - } - return output; - } - - /** - * @dev Extracts a 13-byte sequence from a bytes blob starting at a specific position. - * @param data The bytes blob from which a 13-byte sequence is to be extracted. - * @param start The starting position within the bytes blob for extraction. - * @return The extracted bytes13 value from the specified position in the bytes blob. - */ - function slice13(bytes memory data, uint256 start) internal pure returns (bytes13) { - bytes13 output; - assembly { - output := mload(add(add(data, 0x20), start)) - } - return output; - } - - /** - * @dev Extracts a 14-byte sequence from a bytes blob starting at a specific position. - * @param data The bytes blob from which a 14-byte sequence is to be extracted. - * @param start The starting position within the bytes blob for extraction. - * @return The extracted bytes14 value from the specified position in the bytes blob. - */ - function slice14(bytes memory data, uint256 start) internal pure returns (bytes14) { - bytes14 output; - assembly { - output := mload(add(add(data, 0x20), start)) - } - return output; - } - - /** - * @dev Extracts a 15-byte sequence from a bytes blob starting at a specific position. - * @param data The bytes blob from which a 15-byte sequence is to be extracted. - * @param start The starting position within the bytes blob for extraction. - * @return The extracted bytes15 value from the specified position in the bytes blob. - */ - function slice15(bytes memory data, uint256 start) internal pure returns (bytes15) { - bytes15 output; - assembly { - output := mload(add(add(data, 0x20), start)) - } - return output; - } - /** * @dev Extracts a 16-byte sequence from a bytes blob starting at a specific position. * @param data The bytes blob from which a 16-byte sequence is to be extracted. @@ -451,48 +169,6 @@ library Bytes { return output; } - /** - * @dev Extracts a 17-byte sequence from a bytes blob starting at a specific position. - * @param data The bytes blob from which a 17-byte sequence is to be extracted. - * @param start The starting position within the bytes blob for extraction. - * @return The extracted bytes17 value from the specified position in the bytes blob. - */ - function slice17(bytes memory data, uint256 start) internal pure returns (bytes17) { - bytes17 output; - assembly { - output := mload(add(add(data, 0x20), start)) - } - return output; - } - - /** - * @dev Extracts a 18-byte sequence from a bytes blob starting at a specific position. - * @param data The bytes blob from which a 18-byte sequence is to be extracted. - * @param start The starting position within the bytes blob for extraction. - * @return The extracted bytes18 value from the specified position in the bytes blob. - */ - function slice18(bytes memory data, uint256 start) internal pure returns (bytes18) { - bytes18 output; - assembly { - output := mload(add(add(data, 0x20), start)) - } - return output; - } - - /** - * @dev Extracts a 19-byte sequence from a bytes blob starting at a specific position. - * @param data The bytes blob from which a 19-byte sequence is to be extracted. - * @param start The starting position within the bytes blob for extraction. - * @return The extracted bytes19 value from the specified position in the bytes blob. - */ - function slice19(bytes memory data, uint256 start) internal pure returns (bytes19) { - bytes19 output; - assembly { - output := mload(add(add(data, 0x20), start)) - } - return output; - } - /** * @dev Extracts a 20-byte sequence from a bytes blob starting at a specific position. * @param data The bytes blob from which a 20-byte sequence is to be extracted. @@ -507,160 +183,6 @@ library Bytes { return output; } - /** - * @dev Extracts a 21-byte sequence from a bytes blob starting at a specific position. - * @param data The bytes blob from which a 21-byte sequence is to be extracted. - * @param start The starting position within the bytes blob for extraction. - * @return The extracted bytes21 value from the specified position in the bytes blob. - */ - function slice21(bytes memory data, uint256 start) internal pure returns (bytes21) { - bytes21 output; - assembly { - output := mload(add(add(data, 0x20), start)) - } - return output; - } - - /** - * @dev Extracts a 22-byte sequence from a bytes blob starting at a specific position. - * @param data The bytes blob from which a 22-byte sequence is to be extracted. - * @param start The starting position within the bytes blob for extraction. - * @return The extracted bytes22 value from the specified position in the bytes blob. - */ - function slice22(bytes memory data, uint256 start) internal pure returns (bytes22) { - bytes22 output; - assembly { - output := mload(add(add(data, 0x20), start)) - } - return output; - } - - /** - * @dev Extracts a 23-byte sequence from a bytes blob starting at a specific position. - * @param data The bytes blob from which a 23-byte sequence is to be extracted. - * @param start The starting position within the bytes blob for extraction. - * @return The extracted bytes23 value from the specified position in the bytes blob. - */ - function slice23(bytes memory data, uint256 start) internal pure returns (bytes23) { - bytes23 output; - assembly { - output := mload(add(add(data, 0x20), start)) - } - return output; - } - - /** - * @dev Extracts a 24-byte sequence from a bytes blob starting at a specific position. - * @param data The bytes blob from which a 24-byte sequence is to be extracted. - * @param start The starting position within the bytes blob for extraction. - * @return The extracted bytes24 value from the specified position in the bytes blob. - */ - function slice24(bytes memory data, uint256 start) internal pure returns (bytes24) { - bytes24 output; - assembly { - output := mload(add(add(data, 0x20), start)) - } - return output; - } - - /** - * @dev Extracts a 25-byte sequence from a bytes blob starting at a specific position. - * @param data The bytes blob from which a 25-byte sequence is to be extracted. - * @param start The starting position within the bytes blob for extraction. - * @return The extracted bytes25 value from the specified position in the bytes blob. - */ - function slice25(bytes memory data, uint256 start) internal pure returns (bytes25) { - bytes25 output; - assembly { - output := mload(add(add(data, 0x20), start)) - } - return output; - } - - /** - * @dev Extracts a 26-byte sequence from a bytes blob starting at a specific position. - * @param data The bytes blob from which a 26-byte sequence is to be extracted. - * @param start The starting position within the bytes blob for extraction. - * @return The extracted bytes26 value from the specified position in the bytes blob. - */ - function slice26(bytes memory data, uint256 start) internal pure returns (bytes26) { - bytes26 output; - assembly { - output := mload(add(add(data, 0x20), start)) - } - return output; - } - - /** - * @dev Extracts a 27-byte sequence from a bytes blob starting at a specific position. - * @param data The bytes blob from which a 27-byte sequence is to be extracted. - * @param start The starting position within the bytes blob for extraction. - * @return The extracted bytes27 value from the specified position in the bytes blob. - */ - function slice27(bytes memory data, uint256 start) internal pure returns (bytes27) { - bytes27 output; - assembly { - output := mload(add(add(data, 0x20), start)) - } - return output; - } - - /** - * @dev Extracts a 28-byte sequence from a bytes blob starting at a specific position. - * @param data The bytes blob from which a 28-byte sequence is to be extracted. - * @param start The starting position within the bytes blob for extraction. - * @return The extracted bytes28 value from the specified position in the bytes blob. - */ - function slice28(bytes memory data, uint256 start) internal pure returns (bytes28) { - bytes28 output; - assembly { - output := mload(add(add(data, 0x20), start)) - } - return output; - } - - /** - * @dev Extracts a 29-byte sequence from a bytes blob starting at a specific position. - * @param data The bytes blob from which a 29-byte sequence is to be extracted. - * @param start The starting position within the bytes blob for extraction. - * @return The extracted bytes29 value from the specified position in the bytes blob. - */ - function slice29(bytes memory data, uint256 start) internal pure returns (bytes29) { - bytes29 output; - assembly { - output := mload(add(add(data, 0x20), start)) - } - return output; - } - - /** - * @dev Extracts a 30-byte sequence from a bytes blob starting at a specific position. - * @param data The bytes blob from which a 30-byte sequence is to be extracted. - * @param start The starting position within the bytes blob for extraction. - * @return The extracted bytes30 value from the specified position in the bytes blob. - */ - function slice30(bytes memory data, uint256 start) internal pure returns (bytes30) { - bytes30 output; - assembly { - output := mload(add(add(data, 0x20), start)) - } - return output; - } - - /** - * @dev Extracts a 31-byte sequence from a bytes blob starting at a specific position. - * @param data The bytes blob from which a 31-byte sequence is to be extracted. - * @param start The starting position within the bytes blob for extraction. - * @return The extracted bytes31 value from the specified position in the bytes blob. - */ - function slice31(bytes memory data, uint256 start) internal pure returns (bytes31) { - bytes31 output; - assembly { - output := mload(add(add(data, 0x20), start)) - } - return output; - } - /** * @dev Extracts a 32-byte sequence from a bytes blob starting at a specific position. * @param data The bytes blob from which a 32-byte sequence is to be extracted. diff --git a/packages/store/src/ResourceId.sol b/packages/store/src/ResourceId.sol index 03d3189004..6f337dec07 100644 --- a/packages/store/src/ResourceId.sol +++ b/packages/store/src/ResourceId.sol @@ -10,11 +10,6 @@ type ResourceId is bytes32; /// @dev Number of bits reserved for the type in the ResourceId. uint256 constant TYPE_BITS = 2 * 8; // 2 bytes * 8 bits per byte -/// @dev Number of bits reserved for the name in the ResourceId. -uint256 constant NAME_BITS = 32 * 8 - TYPE_BITS; // 32 bytes * 8 bits per byte - type bits - -/// @dev Bitmask to extract the type from the ResourceId. -bytes32 constant TYPE_MASK = bytes32(hex"ffff"); /** * @title ResourceIdLib Library diff --git a/packages/store/src/Slice.sol b/packages/store/src/Slice.sol index d82d331a4a..65f1112c1e 100644 --- a/packages/store/src/Slice.sol +++ b/packages/store/src/Slice.sol @@ -20,7 +20,6 @@ library SliceLib { error Slice_OutOfBounds(bytes data, uint256 start, uint256 end); uint256 constant MASK_LEN = uint256(type(uint128).max); - uint256 constant MASK_PTR = uint256(type(uint128).max) << 128; /** * @notice Converts a bytes array to a slice (without copying data) diff --git a/packages/store/test/Bytes.t.sol b/packages/store/test/Bytes.t.sol index 1c90b6bc93..660b579c0e 100644 --- a/packages/store/test/Bytes.t.sol +++ b/packages/store/test/Bytes.t.sol @@ -6,76 +6,7 @@ import { GasReporter } from "@latticexyz/gas-report/src/GasReporter.sol"; import { Bytes } from "../src/Bytes.sol"; contract BytesTest is Test, GasReporter { - function testToBytes32() public { - bytes memory input = new bytes(32); - input[0] = 0x01; - input[31] = 0x02; - - startGasReport("create bytes32 from bytes memory with offset 0"); - bytes32 output = Bytes.toBytes32(input, 0); - endGasReport(); - - assertEq(uint256(output), 0x0100000000000000000000000000000000000000000000000000000000000002); - } - - function testToBytes32CrossWord() public { - bytes memory input = new bytes(64); - input[0 + 16] = 0x01; - input[31 + 16] = 0x02; - - startGasReport("create bytes32 from bytes memory with offset 16"); - bytes32 output = Bytes.toBytes32(input, 16); - endGasReport(); - - assertEq(uint256(output), 0x0100000000000000000000000000000000000000000000000000000000000002); - } - - function testEquals() public { - bytes memory a = bytes("a"); - bytes memory b = bytes("a"); - - startGasReport("compare equal bytes"); - bool equals = Bytes.equals(a, b); - endGasReport(); - - assertTrue(equals); - } - - function testEqualsFalse() public { - bytes memory a = bytes("a"); - bytes memory b = bytes("b"); - - startGasReport("compare unequal bytes"); - bool equals = Bytes.equals(a, b); - endGasReport(); - - assertFalse(equals); - } - - function testEqualsFalseDiffLength() public { - bytes memory a = bytes("a"); - bytes memory b = bytes("aa"); - assertFalse(Bytes.equals(a, b)); - } - // TODO: add tests for other sliceX functions - function testSlice3() public { - bytes memory a = new bytes(5); - a[0] = 0x01; - a[1] = 0x02; - a[2] = 0x03; - a[3] = 0x04; - a[4] = 0x05; - - startGasReport("slice bytes3 with offset 1"); - bytes3 b = Bytes.slice3(a, 1); - endGasReport(); - - assertEq(b.length, 3); - assertEq(uint256(uint8(b[0])), 0x02); - assertEq(uint256(uint8(b[1])), 0x03); - assertEq(uint256(uint8(b[2])), 0x04); - } function testSlice32() public { bytes32 original = keccak256("some data"); @@ -88,51 +19,6 @@ contract BytesTest is Test, GasReporter { assertEq(output, original); } - function testSetBytes1() public { - bytes32 input = bytes32(0); - - startGasReport("set bytes1 in bytes32"); - bytes32 output = Bytes.setBytes1(input, 8, 0xff); - endGasReport(); - - assertEq(output, hex"0000000000000000ff"); - assertEq(Bytes.setBytes1(input, 0, 0x01), bytes32(bytes1(0x01))); - assertEq(Bytes.setBytes1(input, 31, 0x01), bytes32(uint256(0x01))); - } - - function testSetBytes2() public { - bytes32 input = bytes32(0); - - startGasReport("set bytes2 in bytes32"); - bytes32 output = Bytes.setBytes2(input, 8, 0xffff); - endGasReport(); - - assertEq(output, hex"0000000000000000ffff"); - assertEq(Bytes.setBytes2(input, 0, 0xffff), bytes32(bytes2(0xffff))); - assertEq(Bytes.setBytes2(input, 30, 0xffff), bytes32(uint256(0xffff))); - } - - function testSetBytes4() public { - bytes32 input = bytes32(0); - - startGasReport("set bytes4 in bytes32"); - bytes32 output = Bytes.setBytes4(input, 8, 0xffffffff); - endGasReport(); - - assertEq(output, hex"0000000000000000ffffffff"); - assertEq(Bytes.setBytes4(input, 0, 0xffffffff), bytes32(bytes4(0xffffffff))); - assertEq(Bytes.setBytes4(input, 30, 0xffffffff), bytes32(uint256(0xffff))); - assertEq(Bytes.setBytes4(input, 28, 0xffffffff), bytes32(uint256(0xffffffff))); - - bytes32 input2 = bytes32(0x0000000a000a0000000000000000000000000000000000000000000000000000); - bytes4 overwrite = bytes4(0x0000006d); - - assertEq( - Bytes.setBytes4(input2, 0, overwrite), - bytes32(0x0000006d000a0000000000000000000000000000000000000000000000000000) - ); - } - function testSetBytes4Memory() public { bytes4 first = bytes4(0x1000000a); bytes32 remainder = bytes32(keccak256("some data")); diff --git a/packages/store/test/StoreCore.t.sol b/packages/store/test/StoreCore.t.sol index 15a3983363..73d076ad2b 100644 --- a/packages/store/test/StoreCore.t.sol +++ b/packages/store/test/StoreCore.t.sol @@ -304,7 +304,7 @@ contract StoreCoreTest is Test, StoreMock { fieldLayout ); - assertTrue(Bytes.equals(staticData, loadedStaticData)); + assertEq(staticData, loadedStaticData); assertEq(_encodedLengths.unwrap(), bytes32(0)); assertEq(_dynamicData, ""); } @@ -341,7 +341,7 @@ contract StoreCoreTest is Test, StoreMock { fieldLayout ); - assertTrue(Bytes.equals(staticData, loadedStaticData)); + assertEq(staticData, loadedStaticData); assertEq(_encodedLengths.unwrap(), bytes32(0)); assertEq(_dynamicData, ""); } diff --git a/packages/world/src/worldResourceTypes.sol b/packages/world/src/worldResourceTypes.sol index fc56c085e8..510cf6b3ea 100644 --- a/packages/world/src/worldResourceTypes.sol +++ b/packages/world/src/worldResourceTypes.sol @@ -14,17 +14,9 @@ import { RESOURCE_TABLE, RESOURCE_OFFCHAIN_TABLE } from "@latticexyz/store/src/s // A namespace can include tables and systems. bytes2 constant RESOURCE_NAMESPACE = "ns"; -// Resource that identifies a module, an on-chain script that -// can be executed on the World. Modules are used to install tables, -// systems, hooks, and new entry point to a World in order to extend -// its capabilities. -bytes2 constant RESOURCE_MODULE = "md"; - // Resource that identifies a system, a contract used to manipulate // the state. bytes2 constant RESOURCE_SYSTEM = "sy"; // Masks used to filter or match a specific resource type bytes32 constant MASK_RESOURCE_NAMESPACE = bytes32(RESOURCE_NAMESPACE); -bytes32 constant MASK_RESOURCE_MODULE = bytes32(RESOURCE_MODULE); -bytes32 constant MASK_RESOURCE_SYSTEM = bytes32(RESOURCE_SYSTEM);