diff --git a/packages/store/test/Callbacks.t.sol b/packages/store/test/Callbacks.t.sol index f9af114b08..108d7d8105 100644 --- a/packages/store/test/Callbacks.t.sol +++ b/packages/store/test/Callbacks.t.sol @@ -5,6 +5,7 @@ import { Test } from "forge-std/Test.sol"; import { GasReporter } from "@latticexyz/gas-report/src/GasReporter.sol"; import { Callbacks } from "./codegen/tables/Callbacks.sol"; import { StoreMock } from "./StoreMock.sol"; +import { Schema, SchemaLib, SchemaType } from "../src/Schema.sol"; contract CallbacksTest is Test, GasReporter, StoreMock { function testSetAndGet() public { @@ -34,4 +35,18 @@ contract CallbacksTest is Test, GasReporter, StoreMock { assertEq(returnedCallbacks.length, 2); assertEq(returnedCallbacks[1], callbacks[0]); } + + function testKeySchemaEncoding() public { + SchemaType[] memory _keySchema = new SchemaType[](1); + _keySchema[0] = SchemaType.BYTES32; + + assertEq(Schema.unwrap(SchemaLib.encode(_keySchema)), Schema.unwrap(Callbacks._keySchema)); + } + + function testValueSchemaEncoding() public { + SchemaType[] memory _valueSchema = new SchemaType[](1); + _valueSchema[0] = SchemaType.BYTES24_ARRAY; + + assertEq(Schema.unwrap(SchemaLib.encode(_valueSchema)), Schema.unwrap(Callbacks._valueSchema)); + } } diff --git a/packages/store/test/KeyEncoding.t.sol b/packages/store/test/KeyEncoding.t.sol index 9412fa2de8..308bc696b2 100644 --- a/packages/store/test/KeyEncoding.t.sol +++ b/packages/store/test/KeyEncoding.t.sol @@ -5,7 +5,7 @@ import { Test } from "forge-std/Test.sol"; import { GasReporter } from "@latticexyz/gas-report/src/GasReporter.sol"; import { StoreCore } from "../src/StoreCore.sol"; import { FieldLayout } from "../src/FieldLayout.sol"; -import { Schema } from "../src/Schema.sol"; +import { Schema, SchemaLib, SchemaType } from "../src/Schema.sol"; import { StoreMock } from "./StoreMock.sol"; import { KeyEncoding } from "./codegen/index.sol"; @@ -87,4 +87,23 @@ contract KeyEncodingTest is Test, GasReporter, StoreMock { assertEq(keyTuple[4], bytes32(abi.encode(true))); assertEq(keyTuple[5], bytes32(abi.encode(ExampleEnum.Third))); } + + function testKeySchemaEncoding() public { + SchemaType[] memory _keySchema = new SchemaType[](6); + _keySchema[0] = SchemaType.UINT256; + _keySchema[1] = SchemaType.INT32; + _keySchema[2] = SchemaType.BYTES16; + _keySchema[3] = SchemaType.ADDRESS; + _keySchema[4] = SchemaType.BOOL; + _keySchema[5] = SchemaType.UINT8; + + assertEq(Schema.unwrap(SchemaLib.encode(_keySchema)), Schema.unwrap(KeyEncoding._keySchema)); + } + + function testValueSchemaEncoding() public { + SchemaType[] memory _valueSchema = new SchemaType[](1); + _valueSchema[0] = SchemaType.BOOL; + + assertEq(Schema.unwrap(SchemaLib.encode(_valueSchema)), Schema.unwrap(KeyEncoding._valueSchema)); + } } diff --git a/packages/store/test/Mixed.t.sol b/packages/store/test/Mixed.t.sol index cd334d7588..31925d812f 100644 --- a/packages/store/test/Mixed.t.sol +++ b/packages/store/test/Mixed.t.sol @@ -6,7 +6,7 @@ import { GasReporter } from "@latticexyz/gas-report/src/GasReporter.sol"; import { StoreCore } from "../src/StoreCore.sol"; import { StoreMock } from "../test/StoreMock.sol"; import { FieldLayout } from "../src/FieldLayout.sol"; -import { Schema } from "../src/Schema.sol"; +import { Schema, SchemaLib, SchemaType } from "../src/Schema.sol"; import { PackedCounter } from "../src/PackedCounter.sol"; import { Mixed, MixedData } from "./codegen/index.sol"; @@ -130,4 +130,21 @@ contract MixedTest is Test, GasReporter, StoreMock { assertEq(encodedLengths.unwrap(), hex"000000000000000000000000000000000000000b000000000800000000000013"); assertEq(dynamicData, hex"0000000300000004736f6d6520737472696e67"); } + + function testKeySchemaEncoding() public { + SchemaType[] memory _keySchema = new SchemaType[](1); + _keySchema[0] = SchemaType.BYTES32; + + assertEq(Schema.unwrap(SchemaLib.encode(_keySchema)), Schema.unwrap(Mixed._keySchema)); + } + + function testValueSchemaEncoding() public { + SchemaType[] memory _valueSchema = new SchemaType[](4); + _valueSchema[0] = SchemaType.UINT32; + _valueSchema[1] = SchemaType.UINT128; + _valueSchema[2] = SchemaType.UINT32_ARRAY; + _valueSchema[3] = SchemaType.STRING; + + assertEq(Schema.unwrap(SchemaLib.encode(_valueSchema)), Schema.unwrap(Mixed._valueSchema)); + } } diff --git a/packages/store/test/Vector2.t.sol b/packages/store/test/Vector2.t.sol index e5081609d7..6ad8c1aae6 100644 --- a/packages/store/test/Vector2.t.sol +++ b/packages/store/test/Vector2.t.sol @@ -6,7 +6,7 @@ import { GasReporter } from "@latticexyz/gas-report/src/GasReporter.sol"; import { StoreCore } from "../src/StoreCore.sol"; import { StoreMock } from "../test/StoreMock.sol"; import { FieldLayout } from "../src/FieldLayout.sol"; -import { Schema } from "../src/Schema.sol"; +import { Schema, SchemaLib, SchemaType } from "../src/Schema.sol"; import { Vector2, Vector2Data } from "./codegen/index.sol"; @@ -46,4 +46,19 @@ contract Vector2Test is Test, GasReporter, StoreMock { assertEq(vector.x, 1); assertEq(vector.y, 2); } + + function testKeySchemaEncoding() public { + SchemaType[] memory _keySchema = new SchemaType[](1); + _keySchema[0] = SchemaType.BYTES32; + + assertEq(Schema.unwrap(SchemaLib.encode(_keySchema)), Schema.unwrap(Vector2._keySchema)); + } + + function testValueSchemaEncoding() public { + SchemaType[] memory _valueSchema = new SchemaType[](2); + _valueSchema[0] = SchemaType.UINT32; + _valueSchema[1] = SchemaType.UINT32; + + assertEq(Schema.unwrap(SchemaLib.encode(_valueSchema)), Schema.unwrap(Vector2._valueSchema)); + } }