Skip to content

Commit

Permalink
fix gas reports
Browse files Browse the repository at this point in the history
  • Loading branch information
alvrs committed Sep 20, 2023
1 parent 6032b6b commit 2944c82
Show file tree
Hide file tree
Showing 5 changed files with 76 additions and 8 deletions.
44 changes: 41 additions & 3 deletions packages/store/test/StoreCore.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,12 @@ contract StoreCoreTest is Test, StoreMock {
mapping(uint256 => bytes) private testMapping;
Schema defaultKeySchema = SchemaEncodeHelper.encode(SchemaType.BYTES32);
string[] defaultKeyNames = new string[](1);
ResourceId tableId = ResourceIdLib.encode("some table", RESOURCE_TABLE);
ResourceId tableId2 = ResourceIdLib.encode("some other table", RESOURCE_TABLE);
ResourceId _tableId = ResourceIdLib.encode("some table", RESOURCE_TABLE);
ResourceId _tableId2 = ResourceIdLib.encode("some other table", RESOURCE_TABLE);

function testRegisterTable() public {
ResourceId tableId = _tableId;

function testRegisterAndGetFieldLayout() public {
FieldLayout fieldLayout = FieldLayoutEncodeHelper.encode(1, 2, 1, 2, 0);
Schema keySchema = SchemaEncodeHelper.encode(SchemaType.UINT8, SchemaType.UINT16);
Schema valueSchema = SchemaEncodeHelper.encode(
Expand Down Expand Up @@ -85,9 +87,14 @@ contract StoreCoreTest is Test, StoreMock {

bytes memory loadedFieldNames = Tables.getAbiEncodedFieldNames(IStore(this), ResourceId.unwrap(tableId));
assertEq(loadedFieldNames, abi.encode(fieldNames));

// Expect the table ID to be registered
assertTrue(ResourceIds._getExists(ResourceId.unwrap(tableId)));
}

function testRevertRegisterInvalidFieldLayout() public {
ResourceId tableId = _tableId;

string[] memory keyNames = new string[](2);
string[] memory fieldNames = new string[](4);
FieldLayout invalidFieldLayout = FieldLayout.wrap(keccak256("random bytes as value field layout"));
Expand Down Expand Up @@ -126,6 +133,9 @@ contract StoreCoreTest is Test, StoreMock {
}

function testHasFieldLayoutAndSchema() public {
ResourceId tableId = _tableId;
ResourceId tableId2 = _tableId2;

string[] memory keyNames = new string[](1);
string[] memory fieldNames = new string[](4);
FieldLayout fieldLayout = FieldLayoutEncodeHelper.encode(1, 2, 1, 2, 0);
Expand Down Expand Up @@ -173,6 +183,8 @@ contract StoreCoreTest is Test, StoreMock {
}

function testRegisterTableRevertNames() public {
ResourceId tableId = _tableId;

FieldLayout fieldLayout = FieldLayoutEncodeHelper.encode(1, 0);
Schema keySchema = SchemaEncodeHelper.encode(
SchemaType.UINT8,
Expand All @@ -194,6 +206,8 @@ contract StoreCoreTest is Test, StoreMock {
}

function testSetAndGetDynamicDataLength() public {
ResourceId tableId = _tableId;

FieldLayout fieldLayout = FieldLayoutEncodeHelper.encode(1, 2, 4, 2);
Schema valueSchema = SchemaEncodeHelper.encode(
SchemaType.UINT8,
Expand Down Expand Up @@ -236,6 +250,8 @@ contract StoreCoreTest is Test, StoreMock {
}

function testSetAndGetStaticData() public {
ResourceId tableId = _tableId;

// Register table
FieldLayout fieldLayout = FieldLayoutEncodeHelper.encode(1, 2, 1, 2, 0);
Schema valueSchema = SchemaEncodeHelper.encode(
Expand Down Expand Up @@ -272,6 +288,8 @@ contract StoreCoreTest is Test, StoreMock {
}

function testRevertSetAndGetStaticData() public {
ResourceId tableId = _tableId;

// Register table
FieldLayout fieldLayout = FieldLayoutEncodeHelper.encode(1, 2, 1, 2, 0);
Schema valueSchema = SchemaEncodeHelper.encode(
Expand All @@ -294,6 +312,8 @@ contract StoreCoreTest is Test, StoreMock {
}

function testSetAndGetStaticDataSpanningWords() public {
ResourceId tableId = _tableId;

// Register table
FieldLayout fieldLayout = FieldLayoutEncodeHelper.encode(16, 32, 0);
{
Expand Down Expand Up @@ -329,6 +349,8 @@ contract StoreCoreTest is Test, StoreMock {
}

function testSetAndGetDynamicData() public {
ResourceId tableId = _tableId;

// Register table
FieldLayout fieldLayout = FieldLayoutEncodeHelper.encode(16, 2);
{
Expand Down Expand Up @@ -413,6 +435,8 @@ contract StoreCoreTest is Test, StoreMock {
}

function testSetAndGetField() public {
ResourceId tableId = _tableId;

SetAndGetData memory _data;
_data.tableId = tableId;

Expand Down Expand Up @@ -628,6 +652,8 @@ contract StoreCoreTest is Test, StoreMock {
}

function testDeleteData() public {
ResourceId tableId = _tableId;

// Register table
FieldLayout fieldLayout = FieldLayoutEncodeHelper.encode(16, 2);
{
Expand Down Expand Up @@ -718,6 +744,8 @@ contract StoreCoreTest is Test, StoreMock {
}

function testPushToField() public {
ResourceId tableId = _tableId;

TestPushToFieldData memory data = TestPushToFieldData(tableId, new bytes32[](0), 0, "", "", "", "", "", "", "");

// Register table
Expand Down Expand Up @@ -857,6 +885,8 @@ contract StoreCoreTest is Test, StoreMock {
}

function testUpdateInField() public {
ResourceId tableId = _tableId;

TestUpdateInFieldData memory data = TestUpdateInFieldData(
tableId,
new bytes32[](0),
Expand Down Expand Up @@ -1001,6 +1031,8 @@ contract StoreCoreTest is Test, StoreMock {
}

function testAccessEmptyData() public {
ResourceId tableId = _tableId;

FieldLayout fieldLayout = FieldLayoutEncodeHelper.encode(4, 1);
Schema valueSchema = SchemaEncodeHelper.encode(SchemaType.UINT32, SchemaType.UINT32_ARRAY);

Expand All @@ -1027,6 +1059,8 @@ contract StoreCoreTest is Test, StoreMock {
}

function testRegisterHook() public {
ResourceId tableId = _tableId;

bytes32[] memory keyTuple = new bytes32[](1);
keyTuple[0] = "some key";

Expand Down Expand Up @@ -1071,6 +1105,8 @@ contract StoreCoreTest is Test, StoreMock {
}

function testUnregisterHook() public {
ResourceId tableId = _tableId;

bytes32[] memory keyTuple = new bytes32[](1);
keyTuple[0] = "some key";

Expand Down Expand Up @@ -1185,6 +1221,8 @@ contract StoreCoreTest is Test, StoreMock {
}

function testHooksDynamicData() public {
ResourceId tableId = _tableId;

bytes32[] memory keyTuple = new bytes32[](1);
keyTuple[0] = "some key";

Expand Down
30 changes: 28 additions & 2 deletions packages/store/test/StoreCoreGas.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,12 @@ contract StoreCoreGasTest is Test, GasReporter, StoreMock {

mapping(uint256 => bytes) private testMapping;
Schema defaultKeySchema = SchemaEncodeHelper.encode(SchemaType.BYTES32);
ResourceId tableId = ResourceIdLib.encode("some table", RESOURCE_TABLE);
ResourceId tableId2 = ResourceIdLib.encode("some other table", RESOURCE_TABLE);
ResourceId _tableId = ResourceIdLib.encode("some table", RESOURCE_TABLE);
ResourceId _tableId2 = ResourceIdLib.encode("some other table", RESOURCE_TABLE);

function testRegisterAndGetFieldLayout() public {
ResourceId tableId = _tableId;

FieldLayout fieldLayout = FieldLayoutEncodeHelper.encode(1, 2, 1, 2, 0);
Schema valueSchema = SchemaEncodeHelper.encode(
SchemaType.UINT8,
Expand Down Expand Up @@ -75,6 +77,8 @@ contract StoreCoreGasTest is Test, GasReporter, StoreMock {
}

function testHasFieldLayout() public {
ResourceId tableId = _tableId;

Schema valueSchema = SchemaEncodeHelper.encode(
SchemaType.UINT8,
SchemaType.UINT16,
Expand All @@ -94,6 +98,8 @@ contract StoreCoreGasTest is Test, GasReporter, StoreMock {
}

function testSetAndGetDynamicDataLength() public {
ResourceId tableId = _tableId;

Schema valueSchema = SchemaEncodeHelper.encode(
SchemaType.UINT8,
SchemaType.UINT16,
Expand Down Expand Up @@ -128,6 +134,8 @@ contract StoreCoreGasTest is Test, GasReporter, StoreMock {
}

function testSetAndGetStaticData() public {
ResourceId tableId = _tableId;

// Register table
Schema valueSchema = SchemaEncodeHelper.encode(
SchemaType.UINT8,
Expand Down Expand Up @@ -155,6 +163,8 @@ contract StoreCoreGasTest is Test, GasReporter, StoreMock {
}

function testSetAndGetStaticDataSpanningWords() public {
ResourceId tableId = _tableId;

// Register table
Schema valueSchema = SchemaEncodeHelper.encode(SchemaType.UINT128, SchemaType.UINT256);
FieldLayout fieldLayout = FieldLayoutEncodeHelper.encode(16, 32, 0);
Expand All @@ -181,6 +191,8 @@ contract StoreCoreGasTest is Test, GasReporter, StoreMock {
}

function testSetAndGetDynamicData() public {
ResourceId tableId = _tableId;

// Register table
FieldLayout fieldLayout = FieldLayoutEncodeHelper.encode(16, 2);
Schema valueSchema = SchemaEncodeHelper.encode(
Expand Down Expand Up @@ -251,6 +263,8 @@ contract StoreCoreGasTest is Test, GasReporter, StoreMock {
}

function testSetAndGetField() public {
ResourceId tableId = _tableId;

// Register table
FieldLayout fieldLayout = FieldLayoutEncodeHelper.encode(16, 32, 2);
Schema valueSchema = SchemaEncodeHelper.encode(
Expand Down Expand Up @@ -339,6 +353,8 @@ contract StoreCoreGasTest is Test, GasReporter, StoreMock {
}

function testDeleteData() public {
ResourceId tableId = _tableId;

// Register table
FieldLayout fieldLayout = FieldLayoutEncodeHelper.encode(16, 2);
Schema valueSchema = SchemaEncodeHelper.encode(
Expand Down Expand Up @@ -390,6 +406,8 @@ contract StoreCoreGasTest is Test, GasReporter, StoreMock {
}

function testPushToField() public {
ResourceId tableId = _tableId;

// Register table
FieldLayout fieldLayout = FieldLayoutEncodeHelper.encode(32, 2);
Schema valueSchema = SchemaEncodeHelper.encode(
Expand Down Expand Up @@ -474,6 +492,8 @@ contract StoreCoreGasTest is Test, GasReporter, StoreMock {
}

function testUpdateInField() public {
ResourceId tableId = _tableId;

TestUpdateInFieldData memory data = TestUpdateInFieldData("", "", "", "", "", "", "");
// Register table
FieldLayout fieldLayout = FieldLayoutEncodeHelper.encode(32, 2);
Expand Down Expand Up @@ -549,6 +569,8 @@ contract StoreCoreGasTest is Test, GasReporter, StoreMock {
}

function testAccessEmptyData() public {
ResourceId tableId = _tableId;

FieldLayout fieldLayout = FieldLayoutEncodeHelper.encode(4, 1);
Schema valueSchema = SchemaEncodeHelper.encode(SchemaType.UINT32, SchemaType.UINT32_ARRAY);

Expand Down Expand Up @@ -580,6 +602,8 @@ contract StoreCoreGasTest is Test, GasReporter, StoreMock {
}

function testHooks() public {
ResourceId tableId = _tableId;

bytes32[] memory keyTuple = new bytes32[](1);
keyTuple[0] = keccak256("some key");

Expand Down Expand Up @@ -621,6 +645,8 @@ contract StoreCoreGasTest is Test, GasReporter, StoreMock {
}

function testHooksDynamicData() public {
ResourceId tableId = _tableId;

bytes32[] memory keyTuple = new bytes32[](1);
keyTuple[0] = keccak256("some key");

Expand Down
2 changes: 1 addition & 1 deletion packages/world/src/interfaces/IBalanceTransferSystem.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ pragma solidity >=0.8.0;

/* Autogenerated file. Do not edit manually. */

import { ResourceId } from "./../WorldResourceId.sol";
import { ResourceId } from "@latticexyz/store/src/ResourceId.sol";

interface IBalanceTransferSystem {
function transferBalanceToNamespace(ResourceId fromNamespaceId, ResourceId toNamespaceId, uint256 amount) external;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
// SPDX-License-Identifier: MIT
pragma solidity >=0.8.0;

import { ResourceId, ResourceIdInstance } from "@latticexyz/store/src/ResourceId.sol";

import { System } from "../../../System.sol";
import { revertWithBytes } from "../../../revertWithBytes.sol";
import { ResourceId, WorldResourceIdLib, WorldResourceIdInstance } from "../../../WorldResourceId.sol";
import { WorldResourceIdLib, WorldResourceIdInstance } from "../../../WorldResourceId.sol";
import { AccessControl } from "../../../AccessControl.sol";
import { RESOURCE_NAMESPACE } from "../../../worldResourceTypes.sol";
import { IWorldErrors } from "../../../interfaces/IWorldErrors.sol";

import { Balances } from "../tables/Balances.sol";

contract BalanceTransferSystem is System, IWorldErrors {
using ResourceIdInstance for ResourceId;
using WorldResourceIdInstance for ResourceId;

/**
Expand Down
2 changes: 1 addition & 1 deletion packages/world/test/WorldBalance.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ contract WorldBalanceTest is Test, GasReporter {
assertEq(Balances.get(world, ResourceId.unwrap(namespaceId)), 0);
}

function testTransferBalanceToNamespaceRevertInvalidResourceType() {
function testTransferBalanceToNamespaceRevertInvalidResourceType() public {
uint256 value = 1 ether;

// Expect the root namespace to have no balance
Expand Down

0 comments on commit 2944c82

Please sign in to comment.