From 09755c6ec2df34d27a7aee8c9b4eeae19dc4fdf8 Mon Sep 17 00:00:00 2001 From: alvrs Date: Thu, 14 Sep 2023 21:44:29 +0100 Subject: [PATCH] remove invalid comments --- packages/store/test/StoreCoreDynamic.t.sol | 70 +++++++++---------- .../modules/keysintable/KeysInTableHook.sol | 15 ++-- 2 files changed, 40 insertions(+), 45 deletions(-) diff --git a/packages/store/test/StoreCoreDynamic.t.sol b/packages/store/test/StoreCoreDynamic.t.sol index dc0e2cf37c..c781320cf7 100644 --- a/packages/store/test/StoreCoreDynamic.t.sol +++ b/packages/store/test/StoreCoreDynamic.t.sol @@ -17,7 +17,7 @@ contract StoreCoreDynamicTest is Test, GasReporter, StoreMock { Schema internal defaultKeySchema = SchemaEncodeHelper.encode(SchemaType.BYTES32); bytes32[] internal _key; - bytes32 internal _table = keccak256("some.tableId"); + bytes32 internal _tableId = keccak256("some.tableId"); bytes32 internal firstDataBytes; uint32[] internal secondData; @@ -37,14 +37,14 @@ contract StoreCoreDynamicTest is Test, GasReporter, StoreMock { } function setUp() public { - // Register tableId's value schema + // Register table's value schema FieldLayout fieldLayout = FieldLayoutEncodeHelper.encode(32, 2); Schema valueSchema = SchemaEncodeHelper.encode( SchemaType.UINT256, SchemaType.UINT32_ARRAY, SchemaType.UINT32_ARRAY ); - StoreCore.registerTable(_table, fieldLayout, defaultKeySchema, valueSchema, new string[](1), new string[](3)); + StoreCore.registerTable(_tableId, fieldLayout, defaultKeySchema, valueSchema, new string[](1), new string[](3)); // Create key _key = new bytes32[](1); @@ -73,14 +73,14 @@ contract StoreCoreDynamicTest is Test, GasReporter, StoreMock { thirdDataBytes = EncodeArray.encode(thirdData); // Set fields - StoreCore.setField(_table, _key, 0, abi.encodePacked(firstDataBytes), fieldLayout); - StoreCore.setField(_table, _key, 1, secondDataBytes, fieldLayout); + StoreCore.setField(_tableId, _key, 0, abi.encodePacked(firstDataBytes), fieldLayout); + StoreCore.setField(_tableId, _key, 1, secondDataBytes, fieldLayout); // Initialize a field with push - StoreCore.pushToField(_table, _key, 2, thirdDataBytes, fieldLayout); + StoreCore.pushToField(_tableId, _key, 2, thirdDataBytes, fieldLayout); } function testPopFromSecondField() public { - FieldLayout fieldLayout = StoreCore.getFieldLayout(_table); + FieldLayout fieldLayout = StoreCore.getFieldLayout(_tableId); bytes memory dataBytes = secondDataBytes; // Prepare expected data @@ -92,34 +92,34 @@ contract StoreCoreDynamicTest is Test, GasReporter, StoreMock { // Expect a StoreSetField event to be emitted vm.expectEmit(true, true, true, true); - emit StoreSetField(_table, _key, 1, newDataBytes); + emit StoreSetField(_tableId, _key, 1, newDataBytes); // Pop from second field startGasReport("pop from field (cold, 1 slot, 1 uint32 item)"); - StoreCore.popFromField(_table, _key, 1, byteLengthToPop, fieldLayout); + StoreCore.popFromField(_tableId, _key, 1, byteLengthToPop, fieldLayout); endGasReport(); // Get second field - bytes memory loadedData = StoreCore.getField(_table, _key, 1, fieldLayout); + bytes memory loadedData = StoreCore.getField(_tableId, _key, 1, fieldLayout); // Verify loaded data is correct assertEq(loadedData, newDataBytes); // Reset the second field and pop again (but warm this time) - StoreCore.setField(_table, _key, 1, dataBytes, fieldLayout); + StoreCore.setField(_tableId, _key, 1, dataBytes, fieldLayout); startGasReport("pop from field (warm, 1 slot, 1 uint32 item)"); - StoreCore.popFromField(_table, _key, 1, byteLengthToPop, fieldLayout); + StoreCore.popFromField(_tableId, _key, 1, byteLengthToPop, fieldLayout); endGasReport(); // Get second field - loadedData = StoreCore.getField(_table, _key, 1, fieldLayout); + loadedData = StoreCore.getField(_tableId, _key, 1, fieldLayout); // Verify loaded data is correct assertEq(loadedData, newDataBytes); // Verify none of the other fields were impacted - assertEq(bytes32(StoreCore.getField(_table, _key, 0, fieldLayout)), firstDataBytes); - assertEq(StoreCore.getField(_table, _key, 2, fieldLayout), thirdDataBytes); + assertEq(bytes32(StoreCore.getField(_tableId, _key, 0, fieldLayout)), firstDataBytes); + assertEq(StoreCore.getField(_tableId, _key, 2, fieldLayout), thirdDataBytes); } function testPopFromThirdField() public { - FieldLayout fieldLayout = StoreCore.getFieldLayout(_table); + FieldLayout fieldLayout = StoreCore.getFieldLayout(_tableId); bytes memory dataBytes = thirdDataBytes; // Prepare expected data @@ -131,74 +131,74 @@ contract StoreCoreDynamicTest is Test, GasReporter, StoreMock { // Expect a StoreSetField event to be emitted after pop vm.expectEmit(true, true, true, true); - emit StoreSetField(_table, _key, 2, dataBytes); + emit StoreSetField(_tableId, _key, 2, dataBytes); // Pop from the field startGasReport("pop from field (cold, 2 slots, 10 uint32 items)"); - StoreCore.popFromField(_table, _key, 2, byteLengthToPop, fieldLayout); + StoreCore.popFromField(_tableId, _key, 2, byteLengthToPop, fieldLayout); endGasReport(); // Load and verify the field - bytes memory loadedData = StoreCore.getField(_table, _key, 2, fieldLayout); + bytes memory loadedData = StoreCore.getField(_tableId, _key, 2, fieldLayout); assertEq(loadedData, newDataBytes); // Reset the field and pop again (but warm this time) - StoreCore.setField(_table, _key, 2, dataBytes, fieldLayout); + StoreCore.setField(_tableId, _key, 2, dataBytes, fieldLayout); startGasReport("pop from field (warm, 2 slots, 10 uint32 items)"); - StoreCore.popFromField(_table, _key, 2, byteLengthToPop, fieldLayout); + StoreCore.popFromField(_tableId, _key, 2, byteLengthToPop, fieldLayout); endGasReport(); // Load and verify the field - loadedData = StoreCore.getField(_table, _key, 2, fieldLayout); + loadedData = StoreCore.getField(_tableId, _key, 2, fieldLayout); assertEq(loadedData, newDataBytes); // Verify none of the other fields were impacted - assertEq(bytes32(StoreCore.getField(_table, _key, 0, fieldLayout)), firstDataBytes); - assertEq(StoreCore.getField(_table, _key, 1, fieldLayout), secondDataBytes); + assertEq(bytes32(StoreCore.getField(_tableId, _key, 0, fieldLayout)), firstDataBytes); + assertEq(StoreCore.getField(_tableId, _key, 1, fieldLayout), secondDataBytes); } function testGetSecondFieldLength() public { - FieldLayout fieldLayout = StoreCore.getFieldLayout(_table); + FieldLayout fieldLayout = StoreCore.getFieldLayout(_tableId); startGasReport("get field length (cold, 1 slot)"); - uint256 length = StoreCore.getFieldLength(_table, _key, 1, fieldLayout); + uint256 length = StoreCore.getFieldLength(_tableId, _key, 1, fieldLayout); endGasReport(); assertEq(length, secondDataBytes.length); startGasReport("get field length (warm, 1 slot)"); - length = StoreCore.getFieldLength(_table, _key, 1, fieldLayout); + length = StoreCore.getFieldLength(_tableId, _key, 1, fieldLayout); endGasReport(); assertEq(length, secondDataBytes.length); } function testGetThirdFieldLength() public { - FieldLayout fieldLayout = StoreCore.getFieldLayout(_table); + FieldLayout fieldLayout = StoreCore.getFieldLayout(_tableId); startGasReport("get field length (warm due to , 2 slots)"); - uint256 length = StoreCore.getFieldLength(_table, _key, 2, fieldLayout); + uint256 length = StoreCore.getFieldLength(_tableId, _key, 2, fieldLayout); endGasReport(); assertEq(length, thirdDataBytes.length); startGasReport("get field length (warm, 2 slots)"); - length = StoreCore.getFieldLength(_table, _key, 2, fieldLayout); + length = StoreCore.getFieldLength(_tableId, _key, 2, fieldLayout); endGasReport(); assertEq(length, thirdDataBytes.length); } function testGetFieldSlice() public { - FieldLayout fieldLayout = StoreCore.getFieldLayout(_table); + FieldLayout fieldLayout = StoreCore.getFieldLayout(_tableId); startGasReport("get field slice (cold, 1 slot)"); - bytes memory secondFieldSlice = StoreCore.getFieldSlice(_table, _key, 1, fieldLayout, 0, 4); + bytes memory secondFieldSlice = StoreCore.getFieldSlice(_tableId, _key, 1, fieldLayout, 0, 4); endGasReport(); assertEq(secondFieldSlice, SliceLib.getSubslice(secondDataBytes, 0, 4).toBytes()); startGasReport("get field slice (warm, 1 slot)"); - secondFieldSlice = StoreCore.getFieldSlice(_table, _key, 1, fieldLayout, 4, 8); + secondFieldSlice = StoreCore.getFieldSlice(_tableId, _key, 1, fieldLayout, 4, 8); endGasReport(); assertEq(secondFieldSlice, SliceLib.getSubslice(secondDataBytes, 4, 8).toBytes()); startGasReport("get field slice (semi-cold, 1 slot)"); - bytes memory thirdFieldSlice = StoreCore.getFieldSlice(_table, _key, 2, fieldLayout, 4, 32); + bytes memory thirdFieldSlice = StoreCore.getFieldSlice(_tableId, _key, 2, fieldLayout, 4, 32); endGasReport(); assertEq(thirdFieldSlice, SliceLib.getSubslice(thirdDataBytes, 4, 32).toBytes()); startGasReport("get field slice (warm, 2 slots)"); - thirdFieldSlice = StoreCore.getFieldSlice(_table, _key, 2, fieldLayout, 8, 40); + thirdFieldSlice = StoreCore.getFieldSlice(_tableId, _key, 2, fieldLayout, 8, 40); endGasReport(); assertEq(thirdFieldSlice, SliceLib.getSubslice(thirdDataBytes, 8, 40).toBytes()); } diff --git a/packages/world/src/modules/keysintable/KeysInTableHook.sol b/packages/world/src/modules/keysintable/KeysInTableHook.sol index e1ece311dc..1953bea6ea 100644 --- a/packages/world/src/modules/keysintable/KeysInTableHook.sol +++ b/packages/world/src/modules/keysintable/KeysInTableHook.sol @@ -14,11 +14,11 @@ contract KeysInTableHook is StoreHook { function handleSet(bytes32 tableId, bytes32[] memory key) internal { bytes32 keysHash = keccak256(abi.encode(key)); - // If the key has not yet been set in the tableId... + // If the key has not yet been set in the table... if (!UsedKeysIndex.getHas(tableId, keysHash)) { uint40 length = uint40(KeysInTable.lengthKeys0(tableId)); - // Push the key to the list of keys in this tableId + // Push the key to the list of keys in this table if (key.length > 0) { KeysInTable.pushKeys0(tableId, key[0]); if (key.length > 1) { @@ -60,15 +60,15 @@ contract KeysInTableHook is StoreHook { bytes32 keysHash = keccak256(abi.encode(key)); (bool has, uint40 index) = UsedKeysIndex.get(tableId, keysHash); - // If the key was part of the tableId... + // If the key was part of the table... if (has) { - // Delete the index as the key is not in the tableId + // Delete the index as the key is not in the table UsedKeysIndex.deleteRecord(tableId, keysHash); uint40 length = uint40(KeysInTable.lengthKeys0(tableId)); if (length == 1) { - // Delete the list of keys in this tableId + // Delete the list of keys in this table KeysInTable.deleteRecord(tableId); } else { if (key.length > 0) { @@ -77,7 +77,6 @@ contract KeysInTableHook is StoreHook { bytes32 lastKey = KeysInTable.getItemKeys0(tableId, length - 1); lastKeyTuple[0] = lastKey; - // Remove the key from the list of keys in this tableId KeysInTable.updateKeys0(tableId, index, lastKey); KeysInTable.popKeys0(tableId); @@ -85,7 +84,6 @@ contract KeysInTableHook is StoreHook { lastKey = KeysInTable.getItemKeys1(tableId, length - 1); lastKeyTuple[1] = lastKey; - // Remove the key from the list of keys in this tableId KeysInTable.updateKeys1(tableId, index, lastKey); KeysInTable.popKeys1(tableId); @@ -93,7 +91,6 @@ contract KeysInTableHook is StoreHook { lastKey = KeysInTable.getItemKeys2(tableId, length - 1); lastKeyTuple[2] = lastKey; - // Swap and pop the key from the list of keys in this tableId KeysInTable.updateKeys2(tableId, index, lastKey); KeysInTable.popKeys2(tableId); @@ -101,7 +98,6 @@ contract KeysInTableHook is StoreHook { lastKey = KeysInTable.getItemKeys3(tableId, length - 1); lastKeyTuple[3] = lastKey; - // Remove the key from the list of keys in this tableId KeysInTable.updateKeys3(tableId, index, lastKey); KeysInTable.popKeys3(tableId); @@ -109,7 +105,6 @@ contract KeysInTableHook is StoreHook { lastKey = KeysInTable.getItemKeys4(tableId, length - 1); lastKeyTuple[4] = lastKey; - // Remove the key from the list of keys in this tableId KeysInTable.updateKeys4(tableId, index, lastKey); KeysInTable.popKeys4(tableId); }