Skip to content

Commit 7ff1442

Browse files
committed
Tests for KintoApp
1 parent ea66e1d commit 7ff1442

File tree

1 file changed

+99
-1
lines changed

1 file changed

+99
-1
lines changed

test/KintoApp.t.sol

Lines changed: 99 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,10 +154,108 @@ contract KintoAppTest is Create2Helper, UserOp, AATestScaffolding {
154154
vm.stopPrank();
155155
}
156156

157+
/* ============ DSA Test ============ */
158+
159+
function testOwnerCanEnableDSA() public {
160+
vm.startPrank(_owner);
161+
address parentContract = address(_engenCredits);
162+
address[] memory childContracts = new address[](1);
163+
childContracts[0] = address(8);
164+
uint256[] memory appLimits = new uint256[](4);
165+
appLimits[0] = _kintoApp.RATE_LIMIT_PERIOD();
166+
appLimits[1] = _kintoApp.RATE_LIMIT_THRESHOLD();
167+
appLimits[2] = _kintoApp.GAS_LIMIT_PERIOD();
168+
appLimits[3] = _kintoApp.GAS_LIMIT_THRESHOLD();
169+
_kintoApp.registerApp(
170+
"", parentContract, childContracts, [appLimits[0], appLimits[1], appLimits[2], appLimits[3]]
171+
);
172+
_kintoApp.enableDSA(parentContract);
173+
IKintoApp.Metadata memory metadata = _kintoApp.getAppMetadata(parentContract);
174+
assertEq(metadata.dsaEnabled, true);
175+
vm.stopPrank();
176+
}
177+
178+
function test_Revert_When_User_TriesToEnableDSA() public {
179+
vm.startPrank(_user);
180+
address parentContract = address(_engenCredits);
181+
address[] memory childContracts = new address[](1);
182+
childContracts[0] = address(8);
183+
uint256[] memory appLimits = new uint256[](4);
184+
appLimits[0] = _kintoApp.RATE_LIMIT_PERIOD();
185+
appLimits[1] = _kintoApp.RATE_LIMIT_THRESHOLD();
186+
appLimits[2] = _kintoApp.GAS_LIMIT_PERIOD();
187+
appLimits[3] = _kintoApp.GAS_LIMIT_THRESHOLD();
188+
_kintoApp.registerApp(
189+
"", parentContract, childContracts, [appLimits[0], appLimits[1], appLimits[2], appLimits[3]]
190+
);
191+
bytes memory err = abi.encodePacked(
192+
"AccessControl: account ",
193+
Strings.toHexString(address(_user)),
194+
" is missing role ",
195+
Strings.toHexString(uint256(_kintoApp.DEVELOPER_ADMIN()), 32)
196+
);
197+
vm.expectRevert(err);
198+
_kintoApp.enableDSA(parentContract);
199+
}
200+
201+
/* ============ Sponsored Contracts Test ============ */
202+
203+
function testAppCreatorCanSetSponsoredContracts() public {
204+
vm.startPrank(_user);
205+
address parentContract = address(_engenCredits);
206+
address[] memory childContracts = new address[](1);
207+
childContracts[0] = address(8);
208+
uint256[] memory appLimits = new uint256[](4);
209+
appLimits[0] = _kintoApp.RATE_LIMIT_PERIOD();
210+
appLimits[1] = _kintoApp.RATE_LIMIT_THRESHOLD();
211+
appLimits[2] = _kintoApp.GAS_LIMIT_PERIOD();
212+
appLimits[3] = _kintoApp.GAS_LIMIT_THRESHOLD();
213+
_kintoApp.registerApp(
214+
"", parentContract, childContracts, [appLimits[0], appLimits[1], appLimits[2], appLimits[3]]
215+
);
216+
address[] memory contracts = new address[](2);
217+
contracts[0] = address(8);
218+
contracts[1] = address(9);
219+
bool[] memory flags = new bool[](2);
220+
flags[0] = false;
221+
flags[1] = true;
222+
_kintoApp.setSponsoredContracts(parentContract, contracts, flags);
223+
assertEq(_kintoApp.isContractSponsoredByApp(parentContract, address(8)), true); // child contracts always sponsored
224+
assertEq(_kintoApp.isContractSponsoredByApp(parentContract, address(9)), true);
225+
assertEq(_kintoApp.isContractSponsoredByApp(parentContract, address(10)), false);
226+
vm.stopPrank();
227+
}
228+
229+
function test_Revert_When_NotCreator_TriesToSetSponsoredContracts() public {
230+
vm.startPrank(_user);
231+
address parentContract = address(_engenCredits);
232+
address[] memory childContracts = new address[](1);
233+
childContracts[0] = address(8);
234+
uint256[] memory appLimits = new uint256[](4);
235+
appLimits[0] = _kintoApp.RATE_LIMIT_PERIOD();
236+
appLimits[1] = _kintoApp.RATE_LIMIT_THRESHOLD();
237+
appLimits[2] = _kintoApp.GAS_LIMIT_PERIOD();
238+
appLimits[3] = _kintoApp.GAS_LIMIT_THRESHOLD();
239+
_kintoApp.registerApp(
240+
"", parentContract, childContracts, [appLimits[0], appLimits[1], appLimits[2], appLimits[3]]
241+
);
242+
address[] memory contracts = new address[](2);
243+
contracts[0] = address(8);
244+
contracts[1] = address(9);
245+
bool[] memory flags = new bool[](2);
246+
flags[0] = false;
247+
flags[1] = true;
248+
vm.startPrank(_user2);
249+
vm.expectRevert("Only developer can set sponsored contracts");
250+
_kintoApp.setSponsoredContracts(parentContract, contracts, flags);
251+
vm.stopPrank();
252+
}
253+
157254
/* ============ Transfer Test ============ */
158255

159-
function test_RevertWhen_TransfersAreDisabled(address parentContract) public {
256+
function test_RevertWhen_TransfersAreDisabled() public {
160257
vm.startPrank(_user);
258+
address parentContract = address(_engenCredits);
161259
address[] memory childContracts = new address[](1);
162260
childContracts[0] = address(8);
163261
uint256[] memory appLimits = new uint256[](4);

0 commit comments

Comments
 (0)