Skip to content

Commit

Permalink
fix tests and update gas report
Browse files Browse the repository at this point in the history
  • Loading branch information
alvrs committed Sep 18, 2023
1 parent 8f913f3 commit d8e28e2
Show file tree
Hide file tree
Showing 4 changed files with 144 additions and 109 deletions.
28 changes: 14 additions & 14 deletions packages/store/src/IStoreHook.sol
Original file line number Diff line number Diff line change
Expand Up @@ -19,55 +19,55 @@ bytes4 constant STORE_HOOK_INTERFACE_ID = IStoreHook.onBeforeSetRecord.selector
interface IStoreHook is IERC165 {
function onBeforeSetRecord(
bytes32 tableId,
bytes32[] calldata keyTuple,
bytes calldata staticData,
bytes32[] memory keyTuple,
bytes memory staticData,
PackedCounter encodedLengths,
bytes calldata dynamicData,
bytes memory dynamicData,
FieldLayout fieldLayout
) external;

function onAfterSetRecord(
bytes32 tableId,
bytes32[] calldata keyTuple,
bytes calldata staticData,
bytes32[] memory keyTuple,
bytes memory staticData,
PackedCounter encodedLengths,
bytes calldata dynamicData,
bytes memory dynamicData,
FieldLayout fieldLayout
) external;

function onBeforeSpliceStaticData(
bytes32 tableId,
bytes32[] calldata keyTuple,
bytes32[] memory keyTuple,
uint48 start,
uint40 deleteCount,
bytes calldata data
bytes memory data
) external;

function onAfterSpliceStaticData(
bytes32 tableId,
bytes32[] calldata keyTuple,
bytes32[] memory keyTuple,
uint48 start,
uint40 deleteCount,
bytes calldata data
bytes memory data
) external;

function onBeforeSpliceDynamicData(
bytes32 tableId,
bytes32[] calldata keyTuple,
bytes32[] memory keyTuple,
uint8 dynamicFieldIndex,
uint40 startWithinField,
uint40 deleteCount,
bytes calldata data,
bytes memory data,
PackedCounter encodedLengths
) external;

function onAfterSpliceDynamicData(
bytes32 tableId,
bytes32[] calldata keyTuple,
bytes32[] memory keyTuple,
uint8 dynamicFieldIndex,
uint40 startWithinField,
uint40 deleteCount,
bytes calldata data,
bytes memory data,
PackedCounter encodedLengths
) external;

Expand Down
23 changes: 9 additions & 14 deletions packages/store/test/StoreCore.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { StoreMock } from "../test/StoreMock.sol";
import { IStoreErrors } from "../src/IStoreErrors.sol";
import { IStore } from "../src/IStore.sol";
import { StoreSwitch } from "../src/StoreSwitch.sol";
import { IStoreHook } from "../src/IStoreHook.sol";
import { Tables, TablesTableId } from "../src/codegen/Tables.sol";
import { FieldLayoutEncodeHelper } from "./FieldLayoutEncodeHelper.sol";
import { BEFORE_SET_RECORD, AFTER_SET_RECORD, BEFORE_SPLICE_STATIC_DATA, AFTER_SPLICE_STATIC_DATA, BEFORE_SPLICE_DYNAMIC_DATA, AFTER_SPLICE_DYNAMIC_DATA, BEFORE_DELETE_RECORD, AFTER_DELETE_RECORD } from "../src/storeHookTypes.sol";
Expand Down Expand Up @@ -1113,7 +1114,7 @@ contract StoreCoreTest is Test, StoreMock {
vm.expectEmit(true, true, true, true);
emit HookCalled(
abi.encodeCall(
echoSubscriber.onBeforeSetRecord,
IStoreHook.onBeforeSetRecord,
(tableId, keyTuple, staticData, encodedLengths, dynamicData, fieldLayout)
)
);
Expand All @@ -1122,7 +1123,7 @@ contract StoreCoreTest is Test, StoreMock {
vm.expectEmit(true, true, true, true);
emit HookCalled(
abi.encodeCall(
echoSubscriber.onAfterSetRecord,
IStoreHook.onAfterSetRecord,
(tableId, keyTuple, staticData, encodedLengths, dynamicData, fieldLayout)
)
);
Expand All @@ -1132,19 +1133,13 @@ contract StoreCoreTest is Test, StoreMock {
// Expect a HookCalled event to be emitted when the EchoSubscriber's onBeforeSpliceStaticData hook is called
vm.expectEmit(true, true, true, true);
emit HookCalled(
abi.encodeCall(
echoSubscriber.onBeforeSpliceStaticData,
(tableId, keyTuple, 0, uint40(staticData.length), staticData)
)
abi.encodeCall(IStoreHook.onBeforeSpliceStaticData, (tableId, keyTuple, 0, uint40(staticData.length), staticData))
);

// Expect a HookCalled event to be emitted when the EchoSubscriber's onAfterSpliceStaticData hook is called
vm.expectEmit(true, true, true, true);
emit HookCalled(
abi.encodeCall(
echoSubscriber.onAfterSpliceStaticData,
(tableId, keyTuple, 0, uint40(staticData.length), staticData)
)
abi.encodeCall(IStoreHook.onAfterSpliceStaticData, (tableId, keyTuple, 0, uint40(staticData.length), staticData))
);

IStore(this).setField(tableId, keyTuple, 0, staticData, fieldLayout);
Expand All @@ -1153,7 +1148,7 @@ contract StoreCoreTest is Test, StoreMock {
vm.expectEmit(true, true, true, true);
emit HookCalled(
abi.encodeCall(
echoSubscriber.onBeforeSpliceDynamicData,
IStoreHook.onBeforeSpliceDynamicData,
(tableId, keyTuple, 0, 0, uint40(dynamicData.length), dynamicData, encodedLengths)
)
);
Expand All @@ -1162,7 +1157,7 @@ contract StoreCoreTest is Test, StoreMock {
vm.expectEmit(true, true, true, true);
emit HookCalled(
abi.encodeCall(
echoSubscriber.onAfterSpliceDynamicData,
IStoreHook.onAfterSpliceDynamicData,
(tableId, keyTuple, 0, 0, uint40(dynamicData.length), dynamicData, encodedLengths)
)
);
Expand All @@ -1173,11 +1168,11 @@ contract StoreCoreTest is Test, StoreMock {

// Expect a HookCalled event to be emitted when the EchoSubscriber's onBeforeDeleteRecord hook is called
vm.expectEmit(true, true, true, true);
emit HookCalled(abi.encodeCall(echoSubscriber.onBeforeDeleteRecord, (tableId, keyTuple, fieldLayout)));
emit HookCalled(abi.encodeCall(IStoreHook.onBeforeDeleteRecord, (tableId, keyTuple, fieldLayout)));

// Expect a HookCalled event to be emitted when the EchoSubscriber's onAfterDeleteRecord hook is called
vm.expectEmit(true, true, true, true);
emit HookCalled(abi.encodeCall(echoSubscriber.onAfterDeleteRecord, (tableId, keyTuple, fieldLayout)));
emit HookCalled(abi.encodeCall(IStoreHook.onAfterDeleteRecord, (tableId, keyTuple, fieldLayout)));

IStore(this).deleteRecord(tableId, keyTuple, fieldLayout);
}
Expand Down
Loading

0 comments on commit d8e28e2

Please sign in to comment.