@@ -14,6 +14,8 @@ import { RESOURCE_SYSTEM } from "../src/worldResourceTypes.sol";
1414import { IWorldErrors } from "../src/IWorldErrors.sol " ;
1515import { IBaseWorld } from "../src/codegen/interfaces/IBaseWorld.sol " ;
1616import { SystemCallData, SystemCallFromData } from "../src/modules/init/types.sol " ;
17+ import { BATCH_CALL_SYSTEM_ID } from "../src/modules/init/constants.sol " ;
18+ import { BatchCallSystem } from "../src/modules/init/implementations/BatchCallSystem.sol " ;
1719
1820import { createWorld } from "./createWorld.sol " ;
1921
@@ -175,4 +177,45 @@ contract BatchCallTest is Test, GasReporter {
175177 assertEq (abi.decode (returnDatas[0 ], (address )), delegatee, "wrong delegatee returned " );
176178 assertEq (abi.decode (returnDatas[1 ], (address )), delegator, "wrong delegator returned " );
177179 }
180+
181+ /**
182+ * If all calls come from the same delegation, it should be simpler and cheaper to compose
183+ * calls via `callFrom(batchCall(...))` instead of `batchCallFrom(...)`.
184+ */
185+ function testCallFromBatchCall () public {
186+ // Register a new system
187+ TestSystem system = new TestSystem ();
188+ world.registerSystem (systemId, system, true );
189+
190+ // Try to increment the counter without creating a delegation
191+ SystemCallData[] memory systemCalls = new SystemCallData [](1 );
192+ systemCalls[0 ] = SystemCallData (systemId, abi.encodeCall (TestSystem.increment, ()));
193+
194+ vm.prank (delegatee);
195+ vm.expectRevert (abi.encodeWithSelector (IWorldErrors.World_DelegationNotFound.selector , delegator, delegatee));
196+ world.callFrom (delegator, BATCH_CALL_SYSTEM_ID, abi.encodeCall (BatchCallSystem.batchCall, (systemCalls)));
197+
198+ // Create an unlimited delegation
199+ vm.prank (delegator);
200+ world.registerDelegation (delegatee, UNLIMITED_DELEGATION, new bytes (0 ));
201+
202+ // Try to increment the counter without setting the admin
203+ vm.prank (delegatee);
204+ vm.expectRevert ("sender is not admin " );
205+ world.callFrom (delegator, BATCH_CALL_SYSTEM_ID, abi.encodeCall (BatchCallSystem.batchCall, (systemCalls)));
206+
207+ assertEq (system.admin (), address (0 ));
208+
209+ // Set the admin and increment the counter twice
210+ systemCalls = new SystemCallData [](3 );
211+ systemCalls[0 ] = SystemCallData (systemId, abi.encodeCall (TestSystem.setAdmin, (delegator)));
212+ systemCalls[1 ] = SystemCallData (systemId, abi.encodeCall (TestSystem.increment, ()));
213+ systemCalls[2 ] = SystemCallData (systemId, abi.encodeCall (TestSystem.increment, ()));
214+
215+ vm.prank (delegatee);
216+ world.callFrom (delegator, BATCH_CALL_SYSTEM_ID, abi.encodeCall (BatchCallSystem.batchCall, (systemCalls)));
217+
218+ assertEq (system.admin (), delegator);
219+ assertEq (system.counter (), 2 , "wrong counter value " );
220+ }
178221}
0 commit comments