From 086be4ef4f3c1ecb3eac0e9554d7d4eb64531fc2 Mon Sep 17 00:00:00 2001 From: alvarius Date: Tue, 4 Jul 2023 13:11:51 +0100 Subject: [PATCH] test(e2e): add more test cases (#1074) --------- Co-authored-by: authcall Co-authored-by: Kevin Ingersoll --- .changeset/strange-candles-shout.md | 5 + .../src/mud/contractComponents.ts | 16 + e2e/packages/contracts/mud.config.ts | 12 + e2e/packages/contracts/src/codegen/Tables.sol | 1 + .../contracts/src/codegen/tables/Multi.sol | 284 ++++++++++++++++++ e2e/packages/sync-test/data/callWorld.ts | 6 +- .../sync-test/data/encodeTestData.test.ts | 2 +- e2e/packages/sync-test/data/encodeTestData.ts | 8 +- e2e/packages/sync-test/data/mergeTestData.ts | 3 +- .../sync-test/data/readClientStore.ts | 29 +- e2e/packages/sync-test/data/testData.ts | 21 +- e2e/packages/sync-test/data/utils.ts | 28 ++ e2e/packages/sync-test/modeSync.test.ts | 3 +- .../services/pkg/mode/storecore/encoding.go | 23 +- 14 files changed, 412 insertions(+), 29 deletions(-) create mode 100644 .changeset/strange-candles-shout.md create mode 100644 e2e/packages/contracts/src/codegen/tables/Multi.sol create mode 100644 e2e/packages/sync-test/data/utils.ts diff --git a/.changeset/strange-candles-shout.md b/.changeset/strange-candles-shout.md new file mode 100644 index 0000000000..a68835c468 --- /dev/null +++ b/.changeset/strange-candles-shout.md @@ -0,0 +1,5 @@ +--- +"@latticexyz/services": patch +--- + +fix a bug related to encoding negative bigints in MODE diff --git a/e2e/packages/client-vanilla/src/mud/contractComponents.ts b/e2e/packages/client-vanilla/src/mud/contractComponents.ts index 1165357031..388ac45595 100644 --- a/e2e/packages/client-vanilla/src/mud/contractComponents.ts +++ b/e2e/packages/client-vanilla/src/mud/contractComponents.ts @@ -51,5 +51,21 @@ export function defineContractComponents(world: World) { } ); })(), + Multi: (() => { + const tableId = new TableId("", "Multi"); + return defineComponent( + world, + { + num: RecsType.BigInt, + value: RecsType.Boolean, + }, + { + metadata: { + contractId: tableId.toHex(), + tableId: tableId.toString(), + }, + } + ); + })(), }; } diff --git a/e2e/packages/contracts/mud.config.ts b/e2e/packages/contracts/mud.config.ts index 318ed57667..762ce21584 100644 --- a/e2e/packages/contracts/mud.config.ts +++ b/e2e/packages/contracts/mud.config.ts @@ -25,5 +25,17 @@ export default mudConfig({ value: "uint32[]", }, }, + Multi: { + keySchema: { + a: "uint32", + b: "bool", + c: "uint256", + d: "int120", + }, + schema: { + num: "int256", + value: "bool", + }, + }, }, }); diff --git a/e2e/packages/contracts/src/codegen/Tables.sol b/e2e/packages/contracts/src/codegen/Tables.sol index f8b2bd68fc..98f8d2feb8 100644 --- a/e2e/packages/contracts/src/codegen/Tables.sol +++ b/e2e/packages/contracts/src/codegen/Tables.sol @@ -6,3 +6,4 @@ pragma solidity >=0.8.0; import { Number, NumberTableId } from "./tables/Number.sol"; import { Vector, VectorData, VectorTableId } from "./tables/Vector.sol"; import { NumberList, NumberListTableId } from "./tables/NumberList.sol"; +import { Multi, MultiData, MultiTableId } from "./tables/Multi.sol"; diff --git a/e2e/packages/contracts/src/codegen/tables/Multi.sol b/e2e/packages/contracts/src/codegen/tables/Multi.sol new file mode 100644 index 0000000000..37a78b8cd2 --- /dev/null +++ b/e2e/packages/contracts/src/codegen/tables/Multi.sol @@ -0,0 +1,284 @@ +// SPDX-License-Identifier: MIT +pragma solidity >=0.8.0; + +/* Autogenerated file. Do not edit manually. */ + +// Import schema type +import { SchemaType } from "@latticexyz/schema-type/src/solidity/SchemaType.sol"; + +// Import store internals +import { IStore } from "@latticexyz/store/src/IStore.sol"; +import { StoreSwitch } from "@latticexyz/store/src/StoreSwitch.sol"; +import { StoreCore } from "@latticexyz/store/src/StoreCore.sol"; +import { Bytes } from "@latticexyz/store/src/Bytes.sol"; +import { Memory } from "@latticexyz/store/src/Memory.sol"; +import { SliceLib } from "@latticexyz/store/src/Slice.sol"; +import { EncodeArray } from "@latticexyz/store/src/tightcoder/EncodeArray.sol"; +import { Schema, SchemaLib } from "@latticexyz/store/src/Schema.sol"; +import { PackedCounter, PackedCounterLib } from "@latticexyz/store/src/PackedCounter.sol"; + +bytes32 constant _tableId = bytes32(abi.encodePacked(bytes16(""), bytes16("Multi"))); +bytes32 constant MultiTableId = _tableId; + +struct MultiData { + int256 num; + bool value; +} + +library Multi { + /** Get the table's schema */ + function getSchema() internal pure returns (Schema) { + SchemaType[] memory _schema = new SchemaType[](2); + _schema[0] = SchemaType.INT256; + _schema[1] = SchemaType.BOOL; + + return SchemaLib.encode(_schema); + } + + function getKeySchema() internal pure returns (Schema) { + SchemaType[] memory _schema = new SchemaType[](4); + _schema[0] = SchemaType.UINT32; + _schema[1] = SchemaType.BOOL; + _schema[2] = SchemaType.UINT256; + _schema[3] = SchemaType.INT120; + + return SchemaLib.encode(_schema); + } + + /** Get the table's metadata */ + function getMetadata() internal pure returns (string memory, string[] memory) { + string[] memory _fieldNames = new string[](2); + _fieldNames[0] = "num"; + _fieldNames[1] = "value"; + return ("Multi", _fieldNames); + } + + /** Register the table's schema */ + function registerSchema() internal { + StoreSwitch.registerSchema(_tableId, getSchema(), getKeySchema()); + } + + /** Register the table's schema (using the specified store) */ + function registerSchema(IStore _store) internal { + _store.registerSchema(_tableId, getSchema(), getKeySchema()); + } + + /** Set the table's metadata */ + function setMetadata() internal { + (string memory _tableName, string[] memory _fieldNames) = getMetadata(); + StoreSwitch.setMetadata(_tableId, _tableName, _fieldNames); + } + + /** Set the table's metadata (using the specified store) */ + function setMetadata(IStore _store) internal { + (string memory _tableName, string[] memory _fieldNames) = getMetadata(); + _store.setMetadata(_tableId, _tableName, _fieldNames); + } + + /** Get num */ + function getNum(uint32 a, bool b, uint256 c, int120 d) internal view returns (int256 num) { + bytes32[] memory _keyTuple = new bytes32[](4); + _keyTuple[0] = bytes32(uint256(a)); + _keyTuple[1] = _boolToBytes32(b); + _keyTuple[2] = bytes32(uint256(c)); + _keyTuple[3] = bytes32(uint256(int256(d))); + + bytes memory _blob = StoreSwitch.getField(_tableId, _keyTuple, 0); + return (int256(uint256(Bytes.slice32(_blob, 0)))); + } + + /** Get num (using the specified store) */ + function getNum(IStore _store, uint32 a, bool b, uint256 c, int120 d) internal view returns (int256 num) { + bytes32[] memory _keyTuple = new bytes32[](4); + _keyTuple[0] = bytes32(uint256(a)); + _keyTuple[1] = _boolToBytes32(b); + _keyTuple[2] = bytes32(uint256(c)); + _keyTuple[3] = bytes32(uint256(int256(d))); + + bytes memory _blob = _store.getField(_tableId, _keyTuple, 0); + return (int256(uint256(Bytes.slice32(_blob, 0)))); + } + + /** Set num */ + function setNum(uint32 a, bool b, uint256 c, int120 d, int256 num) internal { + bytes32[] memory _keyTuple = new bytes32[](4); + _keyTuple[0] = bytes32(uint256(a)); + _keyTuple[1] = _boolToBytes32(b); + _keyTuple[2] = bytes32(uint256(c)); + _keyTuple[3] = bytes32(uint256(int256(d))); + + StoreSwitch.setField(_tableId, _keyTuple, 0, abi.encodePacked((num))); + } + + /** Set num (using the specified store) */ + function setNum(IStore _store, uint32 a, bool b, uint256 c, int120 d, int256 num) internal { + bytes32[] memory _keyTuple = new bytes32[](4); + _keyTuple[0] = bytes32(uint256(a)); + _keyTuple[1] = _boolToBytes32(b); + _keyTuple[2] = bytes32(uint256(c)); + _keyTuple[3] = bytes32(uint256(int256(d))); + + _store.setField(_tableId, _keyTuple, 0, abi.encodePacked((num))); + } + + /** Get value */ + function getValue(uint32 a, bool b, uint256 c, int120 d) internal view returns (bool value) { + bytes32[] memory _keyTuple = new bytes32[](4); + _keyTuple[0] = bytes32(uint256(a)); + _keyTuple[1] = _boolToBytes32(b); + _keyTuple[2] = bytes32(uint256(c)); + _keyTuple[3] = bytes32(uint256(int256(d))); + + bytes memory _blob = StoreSwitch.getField(_tableId, _keyTuple, 1); + return (_toBool(uint8(Bytes.slice1(_blob, 0)))); + } + + /** Get value (using the specified store) */ + function getValue(IStore _store, uint32 a, bool b, uint256 c, int120 d) internal view returns (bool value) { + bytes32[] memory _keyTuple = new bytes32[](4); + _keyTuple[0] = bytes32(uint256(a)); + _keyTuple[1] = _boolToBytes32(b); + _keyTuple[2] = bytes32(uint256(c)); + _keyTuple[3] = bytes32(uint256(int256(d))); + + bytes memory _blob = _store.getField(_tableId, _keyTuple, 1); + return (_toBool(uint8(Bytes.slice1(_blob, 0)))); + } + + /** Set value */ + function setValue(uint32 a, bool b, uint256 c, int120 d, bool value) internal { + bytes32[] memory _keyTuple = new bytes32[](4); + _keyTuple[0] = bytes32(uint256(a)); + _keyTuple[1] = _boolToBytes32(b); + _keyTuple[2] = bytes32(uint256(c)); + _keyTuple[3] = bytes32(uint256(int256(d))); + + StoreSwitch.setField(_tableId, _keyTuple, 1, abi.encodePacked((value))); + } + + /** Set value (using the specified store) */ + function setValue(IStore _store, uint32 a, bool b, uint256 c, int120 d, bool value) internal { + bytes32[] memory _keyTuple = new bytes32[](4); + _keyTuple[0] = bytes32(uint256(a)); + _keyTuple[1] = _boolToBytes32(b); + _keyTuple[2] = bytes32(uint256(c)); + _keyTuple[3] = bytes32(uint256(int256(d))); + + _store.setField(_tableId, _keyTuple, 1, abi.encodePacked((value))); + } + + /** Get the full data */ + function get(uint32 a, bool b, uint256 c, int120 d) internal view returns (MultiData memory _table) { + bytes32[] memory _keyTuple = new bytes32[](4); + _keyTuple[0] = bytes32(uint256(a)); + _keyTuple[1] = _boolToBytes32(b); + _keyTuple[2] = bytes32(uint256(c)); + _keyTuple[3] = bytes32(uint256(int256(d))); + + bytes memory _blob = StoreSwitch.getRecord(_tableId, _keyTuple, getSchema()); + return decode(_blob); + } + + /** Get the full data (using the specified store) */ + function get(IStore _store, uint32 a, bool b, uint256 c, int120 d) internal view returns (MultiData memory _table) { + bytes32[] memory _keyTuple = new bytes32[](4); + _keyTuple[0] = bytes32(uint256(a)); + _keyTuple[1] = _boolToBytes32(b); + _keyTuple[2] = bytes32(uint256(c)); + _keyTuple[3] = bytes32(uint256(int256(d))); + + bytes memory _blob = _store.getRecord(_tableId, _keyTuple, getSchema()); + return decode(_blob); + } + + /** Set the full data using individual values */ + function set(uint32 a, bool b, uint256 c, int120 d, int256 num, bool value) internal { + bytes memory _data = encode(num, value); + + bytes32[] memory _keyTuple = new bytes32[](4); + _keyTuple[0] = bytes32(uint256(a)); + _keyTuple[1] = _boolToBytes32(b); + _keyTuple[2] = bytes32(uint256(c)); + _keyTuple[3] = bytes32(uint256(int256(d))); + + StoreSwitch.setRecord(_tableId, _keyTuple, _data); + } + + /** Set the full data using individual values (using the specified store) */ + function set(IStore _store, uint32 a, bool b, uint256 c, int120 d, int256 num, bool value) internal { + bytes memory _data = encode(num, value); + + bytes32[] memory _keyTuple = new bytes32[](4); + _keyTuple[0] = bytes32(uint256(a)); + _keyTuple[1] = _boolToBytes32(b); + _keyTuple[2] = bytes32(uint256(c)); + _keyTuple[3] = bytes32(uint256(int256(d))); + + _store.setRecord(_tableId, _keyTuple, _data); + } + + /** Set the full data using the data struct */ + function set(uint32 a, bool b, uint256 c, int120 d, MultiData memory _table) internal { + set(a, b, c, d, _table.num, _table.value); + } + + /** Set the full data using the data struct (using the specified store) */ + function set(IStore _store, uint32 a, bool b, uint256 c, int120 d, MultiData memory _table) internal { + set(_store, a, b, c, d, _table.num, _table.value); + } + + /** Decode the tightly packed blob using this table's schema */ + function decode(bytes memory _blob) internal pure returns (MultiData memory _table) { + _table.num = (int256(uint256(Bytes.slice32(_blob, 0)))); + + _table.value = (_toBool(uint8(Bytes.slice1(_blob, 32)))); + } + + /** Tightly pack full data using this table's schema */ + function encode(int256 num, bool value) internal view returns (bytes memory) { + return abi.encodePacked(num, value); + } + + /** Encode keys as a bytes32 array using this table's schema */ + function encodeKeyTuple(uint32 a, bool b, uint256 c, int120 d) internal pure returns (bytes32[] memory _keyTuple) { + _keyTuple = new bytes32[](4); + _keyTuple[0] = bytes32(uint256(a)); + _keyTuple[1] = _boolToBytes32(b); + _keyTuple[2] = bytes32(uint256(c)); + _keyTuple[3] = bytes32(uint256(int256(d))); + } + + /* Delete all data for given keys */ + function deleteRecord(uint32 a, bool b, uint256 c, int120 d) internal { + bytes32[] memory _keyTuple = new bytes32[](4); + _keyTuple[0] = bytes32(uint256(a)); + _keyTuple[1] = _boolToBytes32(b); + _keyTuple[2] = bytes32(uint256(c)); + _keyTuple[3] = bytes32(uint256(int256(d))); + + StoreSwitch.deleteRecord(_tableId, _keyTuple); + } + + /* Delete all data for given keys (using the specified store) */ + function deleteRecord(IStore _store, uint32 a, bool b, uint256 c, int120 d) internal { + bytes32[] memory _keyTuple = new bytes32[](4); + _keyTuple[0] = bytes32(uint256(a)); + _keyTuple[1] = _boolToBytes32(b); + _keyTuple[2] = bytes32(uint256(c)); + _keyTuple[3] = bytes32(uint256(int256(d))); + + _store.deleteRecord(_tableId, _keyTuple); + } +} + +function _toBool(uint8 value) pure returns (bool result) { + assembly { + result := value + } +} + +function _boolToBytes32(bool value) pure returns (bytes32 result) { + assembly { + result := value + } +} diff --git a/e2e/packages/sync-test/data/callWorld.ts b/e2e/packages/sync-test/data/callWorld.ts index d7d9455165..ec8bfa8c59 100644 --- a/e2e/packages/sync-test/data/callWorld.ts +++ b/e2e/packages/sync-test/data/callWorld.ts @@ -8,7 +8,11 @@ type Args = IWorld[Method] extends (...args: any) = export function callWorld(page: Page, method: Method, args: Args) { return page.evaluate( ([_method, _args]) => { - return window["worldSend"](_method, _args).then((tx) => tx.wait()); + return window["worldSend"](_method, _args) + .then((tx) => tx.wait()) + .catch((e) => { + throw new Error([`Error executing ${_method} with args:`, JSON.stringify(_args), e].join("\n\n")); + }); }, [method, args] ); diff --git a/e2e/packages/sync-test/data/encodeTestData.test.ts b/e2e/packages/sync-test/data/encodeTestData.test.ts index 59a5631fa6..90507dc466 100644 --- a/e2e/packages/sync-test/data/encodeTestData.test.ts +++ b/e2e/packages/sync-test/data/encodeTestData.test.ts @@ -2,7 +2,7 @@ import { describe, expect, it } from "vitest"; import { encodeTestData } from "./encodeTestData"; describe("encodeTestData", () => { - it("should encode test data", () => { + it("should encode numbers", () => { expect(encodeTestData({ Number: [{ key: { key: 42 }, value: { value: 1337 } }] })).toStrictEqual({ Number: [{ key: ["0x000000000000000000000000000000000000000000000000000000000000002a"], value: "0x00000539" }], }); diff --git a/e2e/packages/sync-test/data/encodeTestData.ts b/e2e/packages/sync-test/data/encodeTestData.ts index 2661c70681..34dcaa072a 100644 --- a/e2e/packages/sync-test/data/encodeTestData.ts +++ b/e2e/packages/sync-test/data/encodeTestData.ts @@ -1,6 +1,6 @@ import { mapObject } from "@latticexyz/utils"; import { Data, EncodedData } from "./types"; -import { encodeAbiParameters, toHex, encodePacked } from "viem"; +import { encodeAbiParameters, encodePacked } from "viem"; import config from "../../contracts/mud.config"; /** @@ -10,9 +10,9 @@ export function encodeTestData(testData: Data) { return mapObject(testData, (records, table) => records ? records.map((record) => ({ - key: Object.values(record.key).map((key) => - encodeAbiParameters([{ type: "bytes32" }], [toHex(key as any, { size: 32 })]) - ), + key: Object.entries(record.key).map(([keyName, keyValue]) => { + return encodeAbiParameters([{ type: config.tables[table].keySchema[keyName] }], [keyValue]); + }), value: encodePacked(Object.values(config.tables[table].schema), Object.values(record.value)), })) : undefined diff --git a/e2e/packages/sync-test/data/mergeTestData.ts b/e2e/packages/sync-test/data/mergeTestData.ts index e03aa54e08..1ef76b2e75 100644 --- a/e2e/packages/sync-test/data/mergeTestData.ts +++ b/e2e/packages/sync-test/data/mergeTestData.ts @@ -1,5 +1,6 @@ import { mapObject } from "@latticexyz/utils"; import { Data, Datum } from "./types"; +import { serialize } from "./utils"; /** * Merges an array of test data by merging and filtering the records for each table, @@ -12,7 +13,7 @@ export function mergeTestData(...testDatas: Data[]) { for (const [table, records] of Object.entries(testData)) { recordsByTableByKeys[table] ??= {}; for (const record of records) { - recordsByTableByKeys[table][JSON.stringify(record.key)] = record; + recordsByTableByKeys[table][serialize(record.key)] = record; } } } diff --git a/e2e/packages/sync-test/data/readClientStore.ts b/e2e/packages/sync-test/data/readClientStore.ts index 1fb293ab4e..6f9749d5fe 100644 --- a/e2e/packages/sync-test/data/readClientStore.ts +++ b/e2e/packages/sync-test/data/readClientStore.ts @@ -1,7 +1,8 @@ import { Page } from "@playwright/test"; +import { setup } from "../../client-vanilla/src/mud/setup"; +import { deserialize, serialize } from "./utils"; // Extract the storeCache type directly from the client -import { setup } from "../../client-vanilla/src/mud/setup"; type StoreCache = Awaited>["network"]["storeCache"]; /** @@ -9,8 +10,26 @@ type StoreCache = Awaited>["network"]["storeCache"]; * This is necessary because `page.evaluate` can only transmit serialisable data, * so we can't just return the entire client store (which includes functions to read data) */ -export async function readClientStore(page: Page, selector: Parameters): Promise { - return page.evaluate((_selector) => { - return window["storeCache"].get(..._selector); - }, selector); +export async function readClientStore( + page: Page, + [namespace, table, key]: Parameters +): Promise | undefined> { + const args = [namespace, table, serialize(key), serialize.toString(), deserialize.toString()]; + const serializedValue = await page.evaluate(async (_args) => { + const [_namespace, _table, _key, _serializeString, _deserializeString] = _args; + const _serialize = deserializeFunction(_serializeString); + const _deserialize = deserializeFunction(_deserializeString); + const value = await window["storeCache"].get(_namespace, _table, _deserialize(_key)); + const serializedValue = value ? _serialize(value) : undefined; + return serializedValue; + + // Deserialize a serialized function by evaluating a function returning the serialized function. + // This is required to pass in serialized `serialize` and `deserialize` function to avoid having to + // duplicate their logic here. + function deserializeFunction(serializedFunction: string) { + return eval(`(() => ${serializedFunction})()`); + } + }, args); + + return serializedValue ? deserialize(serializedValue) : undefined; } diff --git a/e2e/packages/sync-test/data/testData.ts b/e2e/packages/sync-test/data/testData.ts index 366ff492b5..9c24b99fe6 100644 --- a/e2e/packages/sync-test/data/testData.ts +++ b/e2e/packages/sync-test/data/testData.ts @@ -7,6 +7,12 @@ import { Data } from "./types"; export const testData1 = { Number: [{ key: { key: 1 }, value: { value: 42 } }], Vector: [{ key: { key: 1 }, value: { x: 1, y: 2 } }], + Multi: [ + { + key: { a: 9999, b: true, c: BigInt(42), d: BigInt(-999) }, + value: { num: BigInt(1337), value: true }, + }, + ], } satisfies Data; export const testData2 = { @@ -14,5 +20,18 @@ export const testData2 = { { key: { key: 1 }, value: { value: 24 } }, { key: { key: 2 }, value: { value: 1337 } }, ], - Vector: [{ key: { key: 1 }, value: { x: 1, y: 42 } }], + Vector: [ + { key: { key: 1 }, value: { x: 1, y: 42 } }, + { key: { key: 32 }, value: { x: 1, y: -42 } }, + ], + Multi: [ + { + key: { a: 9999, b: true, c: BigInt(42), d: BigInt(-999) }, + value: { num: BigInt(31337), value: false }, + }, + { + key: { a: 9998, b: true, c: BigInt(42), d: BigInt(-999) }, + value: { num: BigInt(0), value: true }, + }, + ], } satisfies Data; diff --git a/e2e/packages/sync-test/data/utils.ts b/e2e/packages/sync-test/data/utils.ts new file mode 100644 index 0000000000..8098ace152 --- /dev/null +++ b/e2e/packages/sync-test/data/utils.ts @@ -0,0 +1,28 @@ +/** + * Helper to serialize values that are not natively serializable and therefore not transferrable to the page + * For now only `bigint` needs serialization. + */ +export function serialize(obj: unknown): string { + return JSON.stringify(obj, (_, v) => (typeof v === "bigint" ? `bigint(${v.toString()})` : v)); +} + +/** + * Helper to deserialize values that were serialized by `serialize` (because they are not natively serializable). + * For now only `bigint` is serialized and need to be deserialized here. + */ +export function deserialize(blob: string): Record { + const obj = JSON.parse(blob); + + // Check whether the value matches the mattern `bigint(${number}n)` + // (serialization of bigint in `serialize`) + // and turn it back into a bigint + const regex = /^bigint\((-?\d+)\)$/; // Regular expression pattern. + for (const [key, value] of Object.entries(obj)) { + const match = typeof value === "string" && value.match(regex); // Attempt to match the pattern. + if (match) { + obj[key] = BigInt(match[1]); + } + } + + return obj; +} diff --git a/e2e/packages/sync-test/modeSync.test.ts b/e2e/packages/sync-test/modeSync.test.ts index 3341b560e1..da43ba8a56 100644 --- a/e2e/packages/sync-test/modeSync.test.ts +++ b/e2e/packages/sync-test/modeSync.test.ts @@ -110,7 +110,6 @@ describe("Sync from MODE", async () => { await expectClientData(page, { NumberList: [{ key: {}, value: { value: [42, ...range(4999, 1, 0)] } }] }); // Should not have thrown errors - // TODO: uncomment once https://github.com/latticexyz/mud/pull/1048 is merged - // asyncErrorHandler.expectNoAsyncErrors(); + asyncErrorHandler.expectNoAsyncErrors(); }); }); diff --git a/packages/services/pkg/mode/storecore/encoding.go b/packages/services/pkg/mode/storecore/encoding.go index 1ef204b60a..e04ffe7902 100644 --- a/packages/services/pkg/mode/storecore/encoding.go +++ b/packages/services/pkg/mode/storecore/encoding.go @@ -760,30 +760,25 @@ func (schemaType SchemaType) ToSolidityType() string { // //nolint:gocognit // auto-gen + readablity func (schemaType SchemaType) ToPostgresType() string { - const text = "text" + // jsonb is used for storing arrays. const jsonb = "jsonb" - const boolean = "boolean" - const integer = "integer" //nolint:gocritic,nestif // no switch, simplify - if (schemaType >= UINT8 && schemaType <= UINT32) || (schemaType >= INT8 && schemaType <= INT32) { - // Integer. - return integer - } else if (schemaType >= UINT64 && schemaType <= UINT256) || (schemaType >= INT64 && schemaType <= INT256) { - // Big integer. - return text + if (schemaType >= UINT8 && schemaType <= UINT256) || (schemaType >= INT8 && schemaType <= INT256) { + // Integers. + return "numeric(78,0)" } else if (schemaType >= BYTES1 && schemaType <= BYTES32) || (schemaType == BYTES) { // Bytes. - return text + return "text" } else if schemaType == BOOL { // Boolean. - return boolean + return "boolean" } else if schemaType == ADDRESS { // Address. - return text + return "text" } else if schemaType == STRING { // String. - return text + return "text" } else if (schemaType >= UINT8_ARRAY && schemaType <= UINT32_ARRAY) || (schemaType >= INT8_ARRAY && schemaType <= INT32_ARRAY) { // Integer array. @@ -803,6 +798,6 @@ func (schemaType SchemaType) ToPostgresType() string { return jsonb } else { // Default to text. - return text + return "text" } }