From b0c45f87305b7ae80c43a4c09c084cdfc8066f48 Mon Sep 17 00:00:00 2001 From: Kevin Ingersoll Date: Thu, 21 Mar 2024 11:44:16 +0000 Subject: [PATCH] test(store,world): update protocol version tests (#2493) --- .../store/ts/protocol-snapshots/2.0.0.snap | 31 +++++++++-- packages/store/ts/protocolVersions.test.ts | 15 +++++- .../world/ts/protocol-snapshots/2.0.0.snap | 51 ++++++++++++++++--- packages/world/ts/protocolVersions.test.ts | 15 +++++- 4 files changed, 98 insertions(+), 14 deletions(-) diff --git a/packages/store/ts/protocol-snapshots/2.0.0.snap b/packages/store/ts/protocol-snapshots/2.0.0.snap index c8092e625b..21c6ecc745 100644 --- a/packages/store/ts/protocol-snapshots/2.0.0.snap +++ b/packages/store/ts/protocol-snapshots/2.0.0.snap @@ -1,6 +1,26 @@ [ + "error EncodedLengths_InvalidLength(uint256 length)", + "error FieldLayout_Empty()", + "error FieldLayout_InvalidStaticDataLength(uint256 staticDataLength, uint256 computedStaticDataLength)", + "error FieldLayout_StaticLengthDoesNotFitInAWord(uint256 index)", + "error FieldLayout_StaticLengthIsNotZero(uint256 index)", + "error FieldLayout_StaticLengthIsZero(uint256 index)", + "error FieldLayout_TooManyDynamicFields(uint256 numFields, uint256 maxFields)", + "error FieldLayout_TooManyFields(uint256 numFields, uint256 maxFields)", + "error Schema_InvalidLength(uint256 length)", + "error Schema_StaticTypeAfterDynamicType()", + "error Slice_OutOfBounds(bytes data, uint256 start, uint256 end)", "error Store_IndexOutOfBounds(uint256 length, uint256 accessedIndex)", "error Store_InvalidBounds(uint256 start, uint256 end)", + "error Store_InvalidFieldNamesLength(uint256 expected, uint256 received)", + "error Store_InvalidKeyNamesLength(uint256 expected, uint256 received)", + "error Store_InvalidResourceType(bytes2 expected, bytes32 resourceId, string resourceIdString)", + "error Store_InvalidSplice(uint40 startWithinField, uint40 deleteCount, uint40 fieldLength)", + "error Store_InvalidStaticDataLength(uint256 expected, uint256 received)", + "error Store_InvalidValueSchemaDynamicLength(uint256 expected, uint256 received)", + "error Store_InvalidValueSchemaLength(uint256 expected, uint256 received)", + "error Store_InvalidValueSchemaStaticLength(uint256 expected, uint256 received)", + "error Store_TableAlreadyExists(bytes32 tableId, string tableIdString)", "error Store_TableNotFound(bytes32 tableId, string tableIdString)", "event HelloStore(bytes32 indexed storeVersion)", "event Store_DeleteRecord(bytes32 indexed tableId, bytes32[] keyTuple)", @@ -8,9 +28,9 @@ "event Store_SpliceDynamicData(bytes32 indexed tableId, bytes32[] keyTuple, uint8 dynamicFieldIndex, uint48 start, uint40 deleteCount, bytes32 encodedLengths, bytes data)", "event Store_SpliceStaticData(bytes32 indexed tableId, bytes32[] keyTuple, uint48 start, bytes data)", "function deleteRecord(bytes32 tableId, bytes32[] keyTuple)", - "function getDynamicField(bytes32 tableId, bytes32[] keyTuple, uint8 dynamicFieldIndex) view returns (bytes data)", + "function getDynamicField(bytes32 tableId, bytes32[] keyTuple, uint8 dynamicFieldIndex) view returns (bytes)", "function getDynamicFieldLength(bytes32 tableId, bytes32[] keyTuple, uint8 dynamicFieldIndex) view returns (uint256)", - "function getDynamicFieldSlice(bytes32 tableId, bytes32[] keyTuple, uint8 dynamicFieldIndex, uint256 start, uint256 end) view returns (bytes)", + "function getDynamicFieldSlice(bytes32 tableId, bytes32[] keyTuple, uint8 dynamicFieldIndex, uint256 start, uint256 end) view returns (bytes data)", "function getField(bytes32 tableId, bytes32[] keyTuple, uint8 fieldIndex, bytes32 fieldLayout) view returns (bytes data)", "function getField(bytes32 tableId, bytes32[] keyTuple, uint8 fieldIndex) view returns (bytes data)", "function getFieldLayout(bytes32 tableId) view returns (bytes32 fieldLayout)", @@ -19,10 +39,12 @@ "function getKeySchema(bytes32 tableId) view returns (bytes32 keySchema)", "function getRecord(bytes32 tableId, bytes32[] keyTuple, bytes32 fieldLayout) view returns (bytes staticData, bytes32 encodedLengths, bytes dynamicData)", "function getRecord(bytes32 tableId, bytes32[] keyTuple) view returns (bytes staticData, bytes32 encodedLengths, bytes dynamicData)", - "function getStaticField(bytes32 tableId, bytes32[] keyTuple, uint8 fieldIndex, bytes32 fieldLayout) view returns (bytes32 data)", + "function getStaticField(bytes32 tableId, bytes32[] keyTuple, uint8 fieldIndex, bytes32 fieldLayout) view returns (bytes32)", "function getValueSchema(bytes32 tableId) view returns (bytes32 valueSchema)", "function popFromDynamicField(bytes32 tableId, bytes32[] keyTuple, uint8 dynamicFieldIndex, uint256 byteLengthToPop)", "function pushToDynamicField(bytes32 tableId, bytes32[] keyTuple, uint8 dynamicFieldIndex, bytes dataToPush)", + "function registerStoreHook(bytes32 tableId, address hookAddress, uint8 enabledHooksBitmap)", + "function registerTable(bytes32 tableId, bytes32 fieldLayout, bytes32 keySchema, bytes32 valueSchema, string[] keyNames, string[] fieldNames)", "function setDynamicField(bytes32 tableId, bytes32[] keyTuple, uint8 dynamicFieldIndex, bytes data)", "function setField(bytes32 tableId, bytes32[] keyTuple, uint8 fieldIndex, bytes data, bytes32 fieldLayout)", "function setField(bytes32 tableId, bytes32[] keyTuple, uint8 fieldIndex, bytes data)", @@ -30,5 +52,6 @@ "function setStaticField(bytes32 tableId, bytes32[] keyTuple, uint8 fieldIndex, bytes data, bytes32 fieldLayout)", "function spliceDynamicData(bytes32 tableId, bytes32[] keyTuple, uint8 dynamicFieldIndex, uint40 startWithinField, uint40 deleteCount, bytes data)", "function spliceStaticData(bytes32 tableId, bytes32[] keyTuple, uint48 start, bytes data)", - "function storeVersion() pure returns (bytes32)", + "function storeVersion() view returns (bytes32 version)", + "function unregisterStoreHook(bytes32 tableId, address hookAddress)", ] \ No newline at end of file diff --git a/packages/store/ts/protocolVersions.test.ts b/packages/store/ts/protocolVersions.test.ts index dbf3648785..5ea35f76be 100644 --- a/packages/store/ts/protocolVersions.test.ts +++ b/packages/store/ts/protocolVersions.test.ts @@ -1,9 +1,22 @@ import { describe, expect, it } from "vitest"; import fs from "node:fs"; -import StoreAbi from "../out/StoreData.sol/StoreData.abi.json"; +import StoreAbi from "../out/IStore.sol/IStore.abi.json"; import { formatAbi } from "abitype"; import { protocolVersions } from "./protocolVersions"; +/** + * If these tests fail, it's because the protocol changed since the last ABI + version snapshot. + * + * The fix for this depends on your needs: + * + * - If the change was an intentional iteration of the protocol, increment the `version.sol` file according to semver. + * A new protocol snapshot will be created when you run this test again, which you should check into git. + * + * - If the protocol change is for a yet-to-be-release version (i.e. the version was bumped but packages not yet published), + * or if _only_ parameter/return value names changed (which do not affect calldata), then it's safe to just + * update the protocol snapshot for this version (`vitest -u`). + */ + const [, currentVersion] = fs.readFileSync(`${__dirname}/../src/version.sol`, "utf8").match(/VERSION = "(.*?)"/) ?? []; const currentAbi = formatAbi(StoreAbi).sort((a, b) => a.localeCompare(b)); diff --git a/packages/world/ts/protocol-snapshots/2.0.0.snap b/packages/world/ts/protocol-snapshots/2.0.0.snap index c5356865a4..aed3400889 100644 --- a/packages/world/ts/protocol-snapshots/2.0.0.snap +++ b/packages/world/ts/protocol-snapshots/2.0.0.snap @@ -1,15 +1,30 @@ [ - "constructor()", "error EncodedLengths_InvalidLength(uint256 length)", + "error FieldLayout_Empty()", + "error FieldLayout_InvalidStaticDataLength(uint256 staticDataLength, uint256 computedStaticDataLength)", + "error FieldLayout_StaticLengthDoesNotFitInAWord(uint256 index)", + "error FieldLayout_StaticLengthIsNotZero(uint256 index)", + "error FieldLayout_StaticLengthIsZero(uint256 index)", + "error FieldLayout_TooManyDynamicFields(uint256 numFields, uint256 maxFields)", + "error FieldLayout_TooManyFields(uint256 numFields, uint256 maxFields)", "error Module_AlreadyInstalled()", "error Module_MissingDependency(address dependency)", "error Module_NonRootInstallNotSupported()", "error Module_RootInstallNotSupported()", + "error Schema_InvalidLength(uint256 length)", + "error Schema_StaticTypeAfterDynamicType()", "error Slice_OutOfBounds(bytes data, uint256 start, uint256 end)", "error Store_IndexOutOfBounds(uint256 length, uint256 accessedIndex)", "error Store_InvalidBounds(uint256 start, uint256 end)", + "error Store_InvalidFieldNamesLength(uint256 expected, uint256 received)", + "error Store_InvalidKeyNamesLength(uint256 expected, uint256 received)", "error Store_InvalidResourceType(bytes2 expected, bytes32 resourceId, string resourceIdString)", "error Store_InvalidSplice(uint40 startWithinField, uint40 deleteCount, uint40 fieldLength)", + "error Store_InvalidStaticDataLength(uint256 expected, uint256 received)", + "error Store_InvalidValueSchemaDynamicLength(uint256 expected, uint256 received)", + "error Store_InvalidValueSchemaLength(uint256 expected, uint256 received)", + "error Store_InvalidValueSchemaStaticLength(uint256 expected, uint256 received)", + "error Store_TableAlreadyExists(bytes32 tableId, string tableIdString)", "error Store_TableNotFound(bytes32 tableId, string tableIdString)", "error World_AccessDenied(string resource, address caller)", "error World_AlreadyInitialized()", @@ -32,14 +47,15 @@ "event Store_SetRecord(bytes32 indexed tableId, bytes32[] keyTuple, bytes staticData, bytes32 encodedLengths, bytes dynamicData)", "event Store_SpliceDynamicData(bytes32 indexed tableId, bytes32[] keyTuple, uint8 dynamicFieldIndex, uint48 start, uint40 deleteCount, bytes32 encodedLengths, bytes data)", "event Store_SpliceStaticData(bytes32 indexed tableId, bytes32[] keyTuple, uint48 start, bytes data)", - "fallback()", + "function batchCall((bytes32 systemId, bytes callData)[] systemCalls) returns (bytes[] returnDatas)", + "function batchCallFrom((address from, bytes32 systemId, bytes callData)[] systemCalls) returns (bytes[] returnDatas)", "function call(bytes32 systemId, bytes callData) payable returns (bytes)", "function callFrom(address delegator, bytes32 systemId, bytes callData) payable returns (bytes)", "function creator() view returns (address)", "function deleteRecord(bytes32 tableId, bytes32[] keyTuple)", - "function getDynamicField(bytes32 tableId, bytes32[] keyTuple, uint8 dynamicFieldIndex) view returns (bytes data)", + "function getDynamicField(bytes32 tableId, bytes32[] keyTuple, uint8 dynamicFieldIndex) view returns (bytes)", "function getDynamicFieldLength(bytes32 tableId, bytes32[] keyTuple, uint8 dynamicFieldIndex) view returns (uint256)", - "function getDynamicFieldSlice(bytes32 tableId, bytes32[] keyTuple, uint8 dynamicFieldIndex, uint256 start, uint256 end) view returns (bytes)", + "function getDynamicFieldSlice(bytes32 tableId, bytes32[] keyTuple, uint8 dynamicFieldIndex, uint256 start, uint256 end) view returns (bytes data)", "function getField(bytes32 tableId, bytes32[] keyTuple, uint8 fieldIndex, bytes32 fieldLayout) view returns (bytes data)", "function getField(bytes32 tableId, bytes32[] keyTuple, uint8 fieldIndex) view returns (bytes data)", "function getFieldLayout(bytes32 tableId) view returns (bytes32 fieldLayout)", @@ -48,12 +64,25 @@ "function getKeySchema(bytes32 tableId) view returns (bytes32 keySchema)", "function getRecord(bytes32 tableId, bytes32[] keyTuple, bytes32 fieldLayout) view returns (bytes staticData, bytes32 encodedLengths, bytes dynamicData)", "function getRecord(bytes32 tableId, bytes32[] keyTuple) view returns (bytes staticData, bytes32 encodedLengths, bytes dynamicData)", - "function getStaticField(bytes32 tableId, bytes32[] keyTuple, uint8 fieldIndex, bytes32 fieldLayout) view returns (bytes32 data)", + "function getStaticField(bytes32 tableId, bytes32[] keyTuple, uint8 fieldIndex, bytes32 fieldLayout) view returns (bytes32)", "function getValueSchema(bytes32 tableId) view returns (bytes32 valueSchema)", + "function grantAccess(bytes32 resourceId, address grantee)", "function initialize(address initModule)", + "function installModule(address module, bytes encodedArgs)", "function installRootModule(address module, bytes encodedArgs)", "function popFromDynamicField(bytes32 tableId, bytes32[] keyTuple, uint8 dynamicFieldIndex, uint256 byteLengthToPop)", "function pushToDynamicField(bytes32 tableId, bytes32[] keyTuple, uint8 dynamicFieldIndex, bytes dataToPush)", + "function registerDelegation(address delegatee, bytes32 delegationControlId, bytes initCallData)", + "function registerFunctionSelector(bytes32 systemId, string systemFunctionSignature) returns (bytes4 worldFunctionSelector)", + "function registerNamespace(bytes32 namespaceId)", + "function registerNamespaceDelegation(bytes32 namespaceId, bytes32 delegationControlId, bytes initCallData)", + "function registerRootFunctionSelector(bytes32 systemId, string worldFunctionSignature, string systemFunctionSignature) returns (bytes4 worldFunctionSelector)", + "function registerStoreHook(bytes32 tableId, address hookAddress, uint8 enabledHooksBitmap)", + "function registerSystem(bytes32 systemId, address system, bool publicAccess)", + "function registerSystemHook(bytes32 systemId, address hookAddress, uint8 enabledHooksBitmap)", + "function registerTable(bytes32 tableId, bytes32 fieldLayout, bytes32 keySchema, bytes32 valueSchema, string[] keyNames, string[] fieldNames)", + "function renounceOwnership(bytes32 namespaceId)", + "function revokeAccess(bytes32 resourceId, address grantee)", "function setDynamicField(bytes32 tableId, bytes32[] keyTuple, uint8 dynamicFieldIndex, bytes data)", "function setField(bytes32 tableId, bytes32[] keyTuple, uint8 fieldIndex, bytes data, bytes32 fieldLayout)", "function setField(bytes32 tableId, bytes32[] keyTuple, uint8 fieldIndex, bytes data)", @@ -61,7 +90,13 @@ "function setStaticField(bytes32 tableId, bytes32[] keyTuple, uint8 fieldIndex, bytes data, bytes32 fieldLayout)", "function spliceDynamicData(bytes32 tableId, bytes32[] keyTuple, uint8 dynamicFieldIndex, uint40 startWithinField, uint40 deleteCount, bytes data)", "function spliceStaticData(bytes32 tableId, bytes32[] keyTuple, uint48 start, bytes data)", - "function storeVersion() pure returns (bytes32)", - "function worldVersion() pure returns (bytes32)", - "receive() external payable", + "function storeVersion() view returns (bytes32 version)", + "function transferBalanceToAddress(bytes32 fromNamespaceId, address toAddress, uint256 amount)", + "function transferBalanceToNamespace(bytes32 fromNamespaceId, bytes32 toNamespaceId, uint256 amount)", + "function transferOwnership(bytes32 namespaceId, address newOwner)", + "function unregisterDelegation(address delegatee)", + "function unregisterNamespaceDelegation(bytes32 namespaceId)", + "function unregisterStoreHook(bytes32 tableId, address hookAddress)", + "function unregisterSystemHook(bytes32 systemId, address hookAddress)", + "function worldVersion() view returns (bytes32)", ] \ No newline at end of file diff --git a/packages/world/ts/protocolVersions.test.ts b/packages/world/ts/protocolVersions.test.ts index cefd591e94..646db0930c 100644 --- a/packages/world/ts/protocolVersions.test.ts +++ b/packages/world/ts/protocolVersions.test.ts @@ -1,9 +1,22 @@ import { describe, expect, it } from "vitest"; import fs from "node:fs"; -import WorldAbi from "../out/World.sol/World.abi.json"; +import WorldAbi from "../out/IBaseWorld.sol/IBaseWorld.abi.json"; import { formatAbi } from "abitype"; import { protocolVersions } from "./protocolVersions"; +/** + * If these tests fail, it's because the protocol changed since the last ABI + version snapshot. + * + * The fix for this depends on your needs: + * + * - If the change was an intentional iteration of the protocol, increment the `version.sol` file according to semver. + * A new protocol snapshot will be created when you run this test again, which you should check into git. + * + * - If the protocol change is for a yet-to-be-release version (i.e. the version was bumped but packages not yet published), + * or if _only_ parameter/return value names changed (which do not affect calldata), then it's safe to just + * update the protocol snapshot for this version (`vitest -u`). + */ + const [, currentVersion] = fs.readFileSync(`${__dirname}/../src/version.sol`, "utf8").match(/VERSION = "(.*?)"/) ?? []; const currentAbi = formatAbi(WorldAbi).sort((a, b) => a.localeCompare(b));