@bananapus/core-v6 0.0.37 → 0.0.38

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (287) hide show
  1. package/foundry.lock +1 -7
  2. package/foundry.toml +1 -1
  3. package/package.json +19 -7
  4. package/src/JBController.sol +19 -1
  5. package/src/JBMultiTerminal.sol +68 -34
  6. package/src/JBTerminalStore.sol +6 -6
  7. package/src/interfaces/IJBController.sol +4 -1
  8. package/src/libraries/JBFees.sol +47 -9
  9. package/src/libraries/JBPayoutSplitGroupLib.sol +2 -2
  10. package/src/periphery/JBMatchingPriceFeed.sol +1 -1
  11. package/test/mock/MockMaliciousBeneficiary.sol +15 -15
  12. package/ADMINISTRATION.md +0 -103
  13. package/ARCHITECTURE.md +0 -133
  14. package/AUDIT_INSTRUCTIONS.md +0 -139
  15. package/RISKS.md +0 -215
  16. package/SKILLS.md +0 -55
  17. package/STYLE_GUIDE.md +0 -610
  18. package/USER_JOURNEYS.md +0 -215
  19. package/script/Deploy.s.sol +0 -124
  20. package/script/DeployPeriphery.s.sol +0 -354
  21. package/slither-ci.config.json +0 -10
  22. package/test/AuditFixes.t.sol +0 -808
  23. package/test/ComprehensiveInvariant.t.sol +0 -306
  24. package/test/CoreExploitTests.t.sol +0 -2741
  25. package/test/EconomicSimulation.t.sol +0 -348
  26. package/test/EntryPointPermutations.t.sol +0 -684
  27. package/test/FlashLoanAttacks.t.sol +0 -797
  28. package/test/PermissionEscalation.t.sol +0 -711
  29. package/test/PermissionsInvariant.t.sol +0 -403
  30. package/test/RulesetTransitions.t.sol +0 -713
  31. package/test/SplitLoopTests.t.sol +0 -752
  32. package/test/TestAccessToFunds.sol +0 -2683
  33. package/test/TestAuditResponseDesignProofs.sol +0 -434
  34. package/test/TestCashOut.sol +0 -198
  35. package/test/TestCashOutCountFor.sol +0 -271
  36. package/test/TestCashOutHooks.sol +0 -351
  37. package/test/TestCashOutTimingEdge.sol +0 -241
  38. package/test/TestDataHookFuzzing.sol +0 -524
  39. package/test/TestDurationUnderflow.sol +0 -233
  40. package/test/TestFeeFreeCashOutBypass.sol +0 -949
  41. package/test/TestFeeProcessingFailure.sol +0 -218
  42. package/test/TestFees.sol +0 -619
  43. package/test/TestForwardedTokenConsumption.sol +0 -425
  44. package/test/TestInterfaceSupport.sol +0 -81
  45. package/test/TestJBERC20Inheritance.sol +0 -103
  46. package/test/TestL2SequencerPriceFeed.sol +0 -292
  47. package/test/TestLaunchProject.sol +0 -188
  48. package/test/TestMetaTx.sol +0 -217
  49. package/test/TestMetadataOffsetOverflow.sol +0 -179
  50. package/test/TestMetadataParserLib.sol +0 -471
  51. package/test/TestMigrationHeldFees.sol +0 -255
  52. package/test/TestMintTokensOf.sol +0 -185
  53. package/test/TestMultiTerminalSurplus.sol +0 -348
  54. package/test/TestMultiTokenSurplus.sol +0 -202
  55. package/test/TestMultipleAccessLimits.sol +0 -664
  56. package/test/TestPayBurnRedeemFlow.sol +0 -195
  57. package/test/TestPayHooks.sol +0 -209
  58. package/test/TestPermissions.sol +0 -324
  59. package/test/TestPermissionsEdge.sol +0 -290
  60. package/test/TestPermit2DataHook.t.sol +0 -360
  61. package/test/TestPermit2Terminal.sol +0 -372
  62. package/test/TestRulesetQueueing.sol +0 -1025
  63. package/test/TestRulesetQueuingStress.sol +0 -806
  64. package/test/TestRulesetWeightCaching.sol +0 -178
  65. package/test/TestSplits.sol +0 -391
  66. package/test/TestTerminalMigration.sol +0 -274
  67. package/test/TestTerminalPreviewParity.sol +0 -208
  68. package/test/TestTokenFlow.sol +0 -191
  69. package/test/TestWeightCacheStaleAfterRejection.sol +0 -303
  70. package/test/WeirdTokenTests.t.sol +0 -817
  71. package/test/audit/CashOutReenterPay.t.sol +0 -501
  72. package/test/audit/CodexHeldFeeRounding.t.sol +0 -159
  73. package/test/audit/CodexMigrationFeeFailure.t.sol +0 -163
  74. package/test/audit/CrossTerminalSurplusSpoof.t.sol +0 -140
  75. package/test/audit/CycledSurplusAllowanceReset.t.sol +0 -184
  76. package/test/audit/FeeFreeSurplusLifecycle.t.sol +0 -399
  77. package/test/audit/FeeFreeSurplusStale.t.sol +0 -248
  78. package/test/audit/USDTVoidReturnCompat.t.sol +0 -525
  79. package/test/fork/TestChainlinkPriceFeedFork.sol +0 -254
  80. package/test/fork/TestSequencerPriceFeedFork.sol +0 -168
  81. package/test/fork/TestTerminalPreviewParityFork.sol +0 -108
  82. package/test/formal/BondingCurveProperties.t.sol +0 -420
  83. package/test/formal/FeeProperties.t.sol +0 -252
  84. package/test/invariants/Phase3DeepInvariant.t.sol +0 -412
  85. package/test/invariants/RulesetsInvariant.t.sol +0 -125
  86. package/test/invariants/TerminalStoreInvariant.t.sol +0 -227
  87. package/test/invariants/TokensInvariant.t.sol +0 -195
  88. package/test/invariants/handlers/ComprehensiveHandler.sol +0 -303
  89. package/test/invariants/handlers/EconomicHandler.sol +0 -377
  90. package/test/invariants/handlers/Phase3Handler.sol +0 -443
  91. package/test/invariants/handlers/RulesetsHandler.sol +0 -115
  92. package/test/invariants/handlers/TerminalStoreHandler.sol +0 -151
  93. package/test/invariants/handlers/TokensHandler.sol +0 -126
  94. package/test/regression/HoldFeesCashOutReserved.t.sol +0 -415
  95. package/test/regression/WeightCacheBoundary.t.sol +0 -291
  96. package/test/trees/JBController/burnTokensOf.tree +0 -9
  97. package/test/trees/JBController/claimTokensFor.tree +0 -5
  98. package/test/trees/JBController/deployERC20For.tree +0 -5
  99. package/test/trees/JBController/getRulesetOf.tree +0 -5
  100. package/test/trees/JBController/launchProjectFor.tree +0 -12
  101. package/test/trees/JBController/launchRulesetsFor.tree +0 -8
  102. package/test/trees/JBController/migrateController.tree +0 -12
  103. package/test/trees/JBController/mintTokensOf.tree +0 -12
  104. package/test/trees/JBController/payReservedTokenToTerminal.tree +0 -8
  105. package/test/trees/JBController/receiveMigrationFrom.tree +0 -4
  106. package/test/trees/JBController/sendReservedTokensToSplitsOf.tree +0 -12
  107. package/test/trees/JBController/setMetadataOf.tree +0 -5
  108. package/test/trees/JBController/setSplitGroupsOf.tree +0 -5
  109. package/test/trees/JBController/setTokenFor.tree +0 -5
  110. package/test/trees/JBController/transferCreditsFrom.tree +0 -8
  111. package/test/trees/JBDirectory/primaryTerminalOf.tree +0 -8
  112. package/test/trees/JBDirectory/setControllerOf.tree +0 -11
  113. package/test/trees/JBDirectory/setPrimaryTerminalOf.tree +0 -15
  114. package/test/trees/JBDirectory/setTerminalsOf.tree +0 -11
  115. package/test/trees/JBERC20/initialize.tree +0 -7
  116. package/test/trees/JBERC20/name.tree +0 -5
  117. package/test/trees/JBERC20/nonces.tree +0 -5
  118. package/test/trees/JBERC20/symbol.tree +0 -5
  119. package/test/trees/JBFeelessAddresses/setFeelessAddress.tree +0 -5
  120. package/test/trees/JBFeelessAddresses/supportsInterface.tree +0 -5
  121. package/test/trees/JBFundAccessLimits/payoutLimitOf.tree +0 -5
  122. package/test/trees/JBFundAccessLimits/payoutLimitsOf.tree +0 -8
  123. package/test/trees/JBFundAccessLimits/setFundAccessLimitsFor.tree +0 -18
  124. package/test/trees/JBFundAccessLimits/surplusAllowanceOf.tree +0 -5
  125. package/test/trees/JBFundAccessLimits/surplusAllowancesOf.tree +0 -8
  126. package/test/trees/JBMetadataResolver/getDataFor.tree +0 -8
  127. package/test/trees/JBMultiTerminal/accountingContextsOf.tree +0 -5
  128. package/test/trees/JBMultiTerminal/addAccountingContextsFor.tree +0 -10
  129. package/test/trees/JBMultiTerminal/addToBalanceOf.tree +0 -23
  130. package/test/trees/JBMultiTerminal/cashOutTokensOf.tree +0 -23
  131. package/test/trees/JBMultiTerminal/executePayout.tree +0 -32
  132. package/test/trees/JBMultiTerminal/executeProcessFee.tree +0 -14
  133. package/test/trees/JBMultiTerminal/migrateBalanceOf.tree +0 -12
  134. package/test/trees/JBMultiTerminal/pay.tree +0 -23
  135. package/test/trees/JBMultiTerminal/processHeldFeesOf.tree +0 -8
  136. package/test/trees/JBMultiTerminal/sendPayoutsOf.tree +0 -34
  137. package/test/trees/JBMultiTerminal/useAllowanceOf.tree +0 -16
  138. package/test/trees/JBPermissions/hasPermission.tree +0 -8
  139. package/test/trees/JBPermissions/hasPermissions.tree +0 -8
  140. package/test/trees/JBPermissions/setPermissionsFor.tree +0 -5
  141. package/test/trees/JBPrices/addPriceFeedFor.tree +0 -14
  142. package/test/trees/JBPrices/pricePerUnitOf.tree +0 -11
  143. package/test/trees/JBProjects/createFor.tree +0 -11
  144. package/test/trees/JBProjects/setTokenUriResolver.tree +0 -5
  145. package/test/trees/JBProjects/supportsInterface.tree +0 -9
  146. package/test/trees/JBProjects/tokenURI.tree +0 -5
  147. package/test/trees/JBRulesets/currentApprovalStatusForLatestRulesetOf.tree +0 -8
  148. package/test/trees/JBRulesets/currentOf.tree +0 -12
  149. package/test/trees/JBRulesets/getRulesetOf.tree +0 -5
  150. package/test/trees/JBRulesets/latestQueuedRulesetOf.tree +0 -10
  151. package/test/trees/JBRulesets/rulesetsOf.tree +0 -11
  152. package/test/trees/JBRulesets/upcomingRulesetOf.tree +0 -20
  153. package/test/trees/JBRulesets/updateRulesetWeightCache.tree +0 -5
  154. package/test/trees/JBSplits/setSplitGroupsOf.tree +0 -17
  155. package/test/trees/JBSplits/splitsOf.tree +0 -5
  156. package/test/trees/JBTerminalStore/currentReclaimableSurplusOf.tree +0 -16
  157. package/test/trees/JBTerminalStore/currentSurplusOf.tree +0 -25
  158. package/test/trees/JBTerminalStore/currentTotalSurplusOf.tree +0 -5
  159. package/test/trees/JBTerminalStore/recordCashOutsFor.tree +0 -16
  160. package/test/trees/JBTerminalStore/recordPaymentFrom.tree +0 -14
  161. package/test/trees/JBTerminalStore/recordPayoutFor.tree +0 -10
  162. package/test/trees/JBTerminalStore/recordTerminalMigration.tree +0 -5
  163. package/test/trees/JBTerminalStore/recordUsedAllowanceOf.tree +0 -10
  164. package/test/trees/JBTokens/burnFrom.tree +0 -10
  165. package/test/trees/JBTokens/claimTokensFor.tree +0 -10
  166. package/test/trees/JBTokens/deployERC20For.tree +0 -12
  167. package/test/trees/JBTokens/mintFor.tree +0 -10
  168. package/test/trees/JBTokens/setTokenFor.tree +0 -11
  169. package/test/trees/JBTokens/totalBalanceOf.tree +0 -5
  170. package/test/trees/JBTokens/totalSupplyOf.tree +0 -5
  171. package/test/trees/JBTokens/transferCreditsFrom.tree +0 -8
  172. package/test/trees/mintTokensOf.tree +0 -12
  173. package/test/units/static/JBChainlinkV3PriceFeed/TestPriceFeed.sol +0 -223
  174. package/test/units/static/JBController/JBControllerSetup.sol +0 -50
  175. package/test/units/static/JBController/TestBurnTokensOf.sol +0 -114
  176. package/test/units/static/JBController/TestClaimTokensFor.sol +0 -63
  177. package/test/units/static/JBController/TestDeployErc20For.sol +0 -86
  178. package/test/units/static/JBController/TestLaunchProjectFor.sol +0 -302
  179. package/test/units/static/JBController/TestLaunchRulesetsFor.sol +0 -342
  180. package/test/units/static/JBController/TestMigrateController.sol +0 -157
  181. package/test/units/static/JBController/TestMintTokensOfUnits.sol +0 -111
  182. package/test/units/static/JBController/TestOmnichainRulesetOperator.sol +0 -324
  183. package/test/units/static/JBController/TestPayReservedTokenToTerminal.sol +0 -74
  184. package/test/units/static/JBController/TestPreviewMintOf.sol +0 -117
  185. package/test/units/static/JBController/TestReceiveMigrationFrom.sol +0 -99
  186. package/test/units/static/JBController/TestRulesetViews.sol +0 -225
  187. package/test/units/static/JBController/TestSendReservedTokensToSplitsOf.sol +0 -615
  188. package/test/units/static/JBController/TestSetSplitGroupsOf.sol +0 -68
  189. package/test/units/static/JBController/TestSetTokenFor.sol +0 -239
  190. package/test/units/static/JBController/TestSetUriOf.sol +0 -57
  191. package/test/units/static/JBController/TestTransferCreditsFrom.sol +0 -169
  192. package/test/units/static/JBDeadline/TestDeadlineFuzz.sol +0 -211
  193. package/test/units/static/JBDirectory/JBDirectorySetup.sol +0 -26
  194. package/test/units/static/JBDirectory/TestPrimaryTerminalOf.sol +0 -126
  195. package/test/units/static/JBDirectory/TestSetControllerOf.sol +0 -183
  196. package/test/units/static/JBDirectory/TestSetControllerOfMigrationOrder.sol +0 -104
  197. package/test/units/static/JBDirectory/TestSetPrimaryTerminalOf.sol +0 -179
  198. package/test/units/static/JBDirectory/TestSetTerminalsOf.sol +0 -137
  199. package/test/units/static/JBERC20/JBERC20Setup.sol +0 -34
  200. package/test/units/static/JBERC20/SigUtils.sol +0 -36
  201. package/test/units/static/JBERC20/TestInitialize.sol +0 -60
  202. package/test/units/static/JBERC20/TestName.sol +0 -30
  203. package/test/units/static/JBERC20/TestNonces.sol +0 -62
  204. package/test/units/static/JBERC20/TestSymbol.sol +0 -31
  205. package/test/units/static/JBFeelessAdresses/JBFeelessSetup.sol +0 -22
  206. package/test/units/static/JBFeelessAdresses/TestInterfaces.sol +0 -30
  207. package/test/units/static/JBFeelessAdresses/TestSetFeelessAddress.sol +0 -35
  208. package/test/units/static/JBFees/TestFeesFuzz.sol +0 -79
  209. package/test/units/static/JBFixedPointNumber/TestAdjustDecimals.sol +0 -16
  210. package/test/units/static/JBFixedPointNumber/TestAdjustDecimalsFuzz.sol +0 -71
  211. package/test/units/static/JBFundAccessLimits/JBFundAccessSetup.sol +0 -24
  212. package/test/units/static/JBFundAccessLimits/TestFundAccessLimitsEdge.sol +0 -163
  213. package/test/units/static/JBFundAccessLimits/TestPayoutLimitOf.sol +0 -59
  214. package/test/units/static/JBFundAccessLimits/TestPayoutLimitsOf.sol +0 -101
  215. package/test/units/static/JBFundAccessLimits/TestSetFundAccessLimitsFor.sol +0 -189
  216. package/test/units/static/JBFundAccessLimits/TestSurplusAllowanceOf.sol +0 -64
  217. package/test/units/static/JBFundAccessLimits/TestSurplusAllowancesOf.sol +0 -102
  218. package/test/units/static/JBMetadataResolver/TestGetDataFor.sol +0 -90
  219. package/test/units/static/JBMetadataResolver/TestMetadataResolverEdgeCases.sol +0 -247
  220. package/test/units/static/JBMetadataResolver/TestMetadataResolverFuzz.sol +0 -229
  221. package/test/units/static/JBMultiTerminal/JBMultiTerminalSetup.sol +0 -50
  222. package/test/units/static/JBMultiTerminal/TestAccountingContextsOf.sol +0 -72
  223. package/test/units/static/JBMultiTerminal/TestAddAccountingContextsFor.sol +0 -289
  224. package/test/units/static/JBMultiTerminal/TestAddToBalanceOf.sol +0 -474
  225. package/test/units/static/JBMultiTerminal/TestCashOutTokensOf.sol +0 -624
  226. package/test/units/static/JBMultiTerminal/TestExecutePayout.sol +0 -578
  227. package/test/units/static/JBMultiTerminal/TestExecuteProcessFee.sol +0 -202
  228. package/test/units/static/JBMultiTerminal/TestMigrateBalanceOf.sol +0 -222
  229. package/test/units/static/JBMultiTerminal/TestPay.sol +0 -604
  230. package/test/units/static/JBMultiTerminal/TestPreviewCashOutFrom.sol +0 -117
  231. package/test/units/static/JBMultiTerminal/TestPreviewPayFor.sol +0 -114
  232. package/test/units/static/JBMultiTerminal/TestProcessHeldFeesOf.sol +0 -228
  233. package/test/units/static/JBMultiTerminal/TestSelfPayRevert.sol +0 -55
  234. package/test/units/static/JBMultiTerminal/TestSendPayoutsOf.sol +0 -257
  235. package/test/units/static/JBMultiTerminal/TestUseAllowanceOf.sol +0 -611
  236. package/test/units/static/JBPermissions/JBPermissionsSetup.sol +0 -20
  237. package/test/units/static/JBPermissions/TestHasPermission.sol +0 -50
  238. package/test/units/static/JBPermissions/TestHasPermissions.sol +0 -93
  239. package/test/units/static/JBPermissions/TestSetPermissionsFor.sol +0 -64
  240. package/test/units/static/JBPrices/JBPricesSetup.sol +0 -32
  241. package/test/units/static/JBPrices/TestAddPriceFeedFor.sol +0 -107
  242. package/test/units/static/JBPrices/TestPricePerUnitOf.sol +0 -132
  243. package/test/units/static/JBPrices/TestPrices.sol +0 -265
  244. package/test/units/static/JBProjects/JBProjectsSetup.sol +0 -22
  245. package/test/units/static/JBProjects/TestCreateFor.sol +0 -71
  246. package/test/units/static/JBProjects/TestInitialProject.sol +0 -21
  247. package/test/units/static/JBProjects/TestInterfaces.sol +0 -26
  248. package/test/units/static/JBProjects/TestSetResolver.sol +0 -37
  249. package/test/units/static/JBProjects/TestTokenUri.sol +0 -40
  250. package/test/units/static/JBRulesetMetadataResolver/TestSetCashOutTaxRateTo.sol +0 -108
  251. package/test/units/static/JBRulesets/JBRulesetsSetup.sol +0 -24
  252. package/test/units/static/JBRulesets/TestCurrentApprovalStatusForLatestRulesetOf.sol +0 -265
  253. package/test/units/static/JBRulesets/TestCurrentOf.sol +0 -242
  254. package/test/units/static/JBRulesets/TestGetRulesetOf.sol +0 -100
  255. package/test/units/static/JBRulesets/TestLatestQueuedRulesetOf.sol +0 -260
  256. package/test/units/static/JBRulesets/TestRulesets.sol +0 -632
  257. package/test/units/static/JBRulesets/TestRulesetsOf.sol +0 -37
  258. package/test/units/static/JBRulesets/TestUpcomingRulesetOf.sol +0 -522
  259. package/test/units/static/JBRulesets/TestUpdateRulesetWeightCache.sol +0 -96
  260. package/test/units/static/JBSplits/JBSplitsSetup.sol +0 -26
  261. package/test/units/static/JBSplits/TestSelfManagedSplitGroups.sol +0 -552
  262. package/test/units/static/JBSplits/TestSetSplitGroupsOf.sol +0 -377
  263. package/test/units/static/JBSplits/TestSplitsLockedEdge.sol +0 -267
  264. package/test/units/static/JBSplits/TestSplitsOf.sol +0 -24
  265. package/test/units/static/JBSplits/TestSplitsPacking.sol +0 -36
  266. package/test/units/static/JBSurplus/TestSurplusFuzz.sol +0 -160
  267. package/test/units/static/JBTerminalStore/JBTerminalStoreSetup.sol +0 -45
  268. package/test/units/static/JBTerminalStore/TestCurrentReclaimableSurplusOf.sol +0 -536
  269. package/test/units/static/JBTerminalStore/TestCurrentSurplusOf.sol +0 -463
  270. package/test/units/static/JBTerminalStore/TestCurrentTotalSurplusOf.sol +0 -135
  271. package/test/units/static/JBTerminalStore/TestPreviewCashOutFrom.sol +0 -476
  272. package/test/units/static/JBTerminalStore/TestPreviewPayFrom.sol +0 -494
  273. package/test/units/static/JBTerminalStore/TestRecordCashOutsFor.sol +0 -652
  274. package/test/units/static/JBTerminalStore/TestRecordPaymentFrom.sol +0 -744
  275. package/test/units/static/JBTerminalStore/TestRecordPayoutFor.sol +0 -289
  276. package/test/units/static/JBTerminalStore/TestRecordTerminalMigration.sol +0 -138
  277. package/test/units/static/JBTerminalStore/TestRecordUsedAllowanceOf.sol +0 -415
  278. package/test/units/static/JBTerminalStore/TestUint224Overflow.sol +0 -219
  279. package/test/units/static/JBTokens/JBTokensSetup.sol +0 -32
  280. package/test/units/static/JBTokens/TestBurnFrom.sol +0 -107
  281. package/test/units/static/JBTokens/TestClaimTokensFor.sol +0 -110
  282. package/test/units/static/JBTokens/TestDeployERC20ForUnits.sol +0 -92
  283. package/test/units/static/JBTokens/TestMintFor.sol +0 -100
  284. package/test/units/static/JBTokens/TestSetTokenFor.sol +0 -98
  285. package/test/units/static/JBTokens/TestTotalBalanceOf.sol +0 -65
  286. package/test/units/static/JBTokens/TestTotalSupplyOf.sol +0 -56
  287. package/test/units/static/JBTokens/TestTransferCreditsFrom.sol +0 -56
@@ -1,102 +0,0 @@
1
- // SPDX-License-Identifier: MIT
2
- pragma solidity 0.8.28;
3
-
4
- import {IJBDirectory} from "../../../../src/interfaces/IJBDirectory.sol";
5
- import {JBConstants} from "../../../../src/libraries/JBConstants.sol";
6
- import {JBCurrencyAmount} from "../../../../src/structs/JBCurrencyAmount.sol";
7
- import {JBFundAccessLimitGroup} from "../../../../src/structs/JBFundAccessLimitGroup.sol";
8
- import {JBFundAccessSetup} from "./JBFundAccessSetup.sol";
9
-
10
- contract TestSurplusAllowancesOf_Local is JBFundAccessSetup {
11
- uint256 _projectId = 1;
12
- address _terminal = address(1);
13
- address _terminal2 = address(2);
14
- address _someToken = makeAddr("someToken");
15
-
16
- function setUp() public {
17
- super.fundAccessSetup();
18
- }
19
-
20
- modifier whenAProjectHasSpecifiedSurplusAllowances() {
21
- bytes memory _controllerCall = abi.encodeCall(IJBDirectory.controllerOf, (1));
22
- bytes memory _return = abi.encode(address(this));
23
-
24
- mockExpect(address(directory), _controllerCall, _return);
25
-
26
- // Fund Access config
27
- JBFundAccessLimitGroup[] memory _fundAccessLimitGroup = new JBFundAccessLimitGroup[](2);
28
- {
29
- // Specify a payout limit.
30
- JBCurrencyAmount[] memory _payoutLimits = new JBCurrencyAmount[](0);
31
-
32
- // Specify a surplus allowance.
33
- JBCurrencyAmount[] memory _surplusAllowances = new JBCurrencyAmount[](2);
34
- _surplusAllowances[0] =
35
- JBCurrencyAmount({amount: 1e18, currency: uint32(uint160(JBConstants.NATIVE_TOKEN))});
36
-
37
- // forge-lint: disable-next-line(unsafe-typecast)
38
- _surplusAllowances[1] = JBCurrencyAmount({amount: 2e18, currency: uint32(uint160(_someToken))});
39
-
40
- _fundAccessLimitGroup[0] = JBFundAccessLimitGroup({
41
- terminal: _terminal,
42
- token: JBConstants.NATIVE_TOKEN,
43
- payoutLimits: _payoutLimits,
44
- surplusAllowances: _surplusAllowances
45
- });
46
-
47
- _fundAccessLimitGroup[1] = JBFundAccessLimitGroup({
48
- terminal: _terminal2,
49
- token: _someToken,
50
- payoutLimits: _payoutLimits,
51
- surplusAllowances: _surplusAllowances
52
- });
53
- }
54
-
55
- _fundAccess.setFundAccessLimitsFor(_projectId, block.timestamp, _fundAccessLimitGroup);
56
- _fundAccess.setFundAccessLimitsFor(_projectId, block.timestamp + 1, _fundAccessLimitGroup);
57
-
58
- _;
59
- }
60
-
61
- function test_GivenTheyAreSpecifiedForASpecificRuleset() external whenAProjectHasSpecifiedSurplusAllowances {
62
- // it will return them
63
-
64
- JBCurrencyAmount[] memory surplusLimits =
65
- _fundAccess.surplusAllowancesOf(_projectId, block.timestamp, _terminal, JBConstants.NATIVE_TOKEN);
66
-
67
- JBCurrencyAmount[] memory surplusLimits2 =
68
- _fundAccess.surplusAllowancesOf(_projectId, block.timestamp + 1, _terminal, JBConstants.NATIVE_TOKEN);
69
-
70
- assertEq(surplusLimits[0].currency, uint32(uint160(JBConstants.NATIVE_TOKEN)));
71
- assertEq(surplusLimits[0].amount, 1e18);
72
- // forge-lint: disable-next-line(unsafe-typecast)
73
- assertEq(surplusLimits[1].currency, uint32(uint160(_someToken)));
74
- assertEq(surplusLimits[1].amount, 2e18);
75
-
76
- assertEq(surplusLimits2[0].currency, uint32(uint160(JBConstants.NATIVE_TOKEN)));
77
- assertEq(surplusLimits2[0].amount, 1e18);
78
- // forge-lint: disable-next-line(unsafe-typecast)
79
- assertEq(surplusLimits2[1].currency, uint32(uint160(_someToken)));
80
- assertEq(surplusLimits2[1].amount, 2e18);
81
- }
82
-
83
- function test_GivenTheyAreSpecifiedForASpecificTerminal() external whenAProjectHasSpecifiedSurplusAllowances {
84
- // it will return them
85
-
86
- JBCurrencyAmount[] memory surplusLimits =
87
- _fundAccess.surplusAllowancesOf(_projectId, block.timestamp, _terminal2, _someToken);
88
-
89
- assertEq(surplusLimits[0].currency, uint32(uint160(JBConstants.NATIVE_TOKEN)));
90
- assertEq(surplusLimits[0].amount, 1e18);
91
- }
92
-
93
- function test_GivenTheyAreSpecifiedForASpecificToken() external whenAProjectHasSpecifiedSurplusAllowances {
94
- // it will return them
95
-
96
- JBCurrencyAmount[] memory surplusLimits =
97
- _fundAccess.surplusAllowancesOf(_projectId, block.timestamp, _terminal, JBConstants.NATIVE_TOKEN);
98
-
99
- assertEq(surplusLimits[0].currency, uint32(uint160(JBConstants.NATIVE_TOKEN)));
100
- assertEq(surplusLimits[0].amount, 1e18);
101
- }
102
- }
@@ -1,90 +0,0 @@
1
- // SPDX-License-Identifier: MIT
2
- pragma solidity 0.8.28;
3
-
4
- import {JBTest} from "../../../helpers/JBTest.sol";
5
- import {JBMetadataResolver} from "../../../../src/libraries/JBMetadataResolver.sol";
6
-
7
- contract TestGetDataFor_Local is JBTest {
8
- bytes4 _id1 = bytes4(0x10101010);
9
- bytes4 _id2 = bytes4(0x20202020);
10
-
11
- function setUp() external {}
12
-
13
- function test_WhenMetadataLengthLTEQMIN_METADATA_LENGTH() external view {
14
- // it will return false and empty bytes
15
-
16
- // malformed data only contains the padding intended for the protocol
17
- bytes memory _malformed = abi.encodePacked(bytes32(uint256(type(uint256).max)));
18
-
19
- (bool _found, bytes memory _data) = JBMetadataResolver.getDataFor(_id1, _malformed);
20
-
21
- // check
22
- assertEq(_found, false);
23
- assertEq("", _data);
24
- }
25
-
26
- // forge-lint: disable-next-line(mixed-case-function)
27
- modifier whenMetadataLengthGTMIN_METADATA_LENGTH() {
28
- _;
29
- }
30
-
31
- function test_GivenIdIsFound() external view whenMetadataLengthGTMIN_METADATA_LENGTH {
32
- // it will return found EQ true and targetData
33
-
34
- uint256 _data1 = 10_000_000;
35
- bytes memory _data2 = new bytes(100);
36
-
37
- // malformed data only contains the padding intended for the protocol
38
- bytes memory _metadata = abi.encodePacked(
39
- // -- offset 0 --
40
- bytes32(uint256(type(uint256).max)), // First 32B reserved
41
- // -- offset 1 --
42
- _id1, // First id
43
- uint8(2), // First data offset == 2
44
- _id2, // Second id == _id
45
- uint8(3), // Second data offset == 3
46
- bytes22(0), // Rest of the word is 0-padded
47
- // -- offset 2 --
48
- _data1, // First data
49
- // -- offset 3 --
50
- _data2 // Second data
51
- );
52
-
53
- (bool _found, bytes memory _returnedData) = JBMetadataResolver.getDataFor(_id1, _metadata);
54
-
55
- // check
56
- assertEq(_found, true);
57
- assertEq(abi.decode(_returnedData, (uint256)), _data1);
58
- }
59
-
60
- function test_GivenIdIsNotFound() external view whenMetadataLengthGTMIN_METADATA_LENGTH {
61
- // it will return found EQ false and empty bytes targetData
62
-
63
- uint256 _data1 = 10_000_000;
64
- bytes memory _data2 = new bytes(100);
65
-
66
- // malformed data only contains the padding intended for the protocol
67
- bytes memory _metadata = abi.encodePacked(
68
- // -- offset 0 --
69
- bytes32(uint256(type(uint256).max)), // First 32B reserved
70
- // -- offset 1 --
71
- _id1, // First id
72
- uint8(2), // First data offset == 2
73
- _id2, // Second id == _id
74
- uint8(3), // Second data offset == 3
75
- bytes22(0), // Rest of the word is 0-padded
76
- // -- offset 2 --
77
- _data1, // First data
78
- // -- offset 3 --
79
- _data2 // Second data
80
- );
81
-
82
- bytes4 _invalidId = bytes4(0x40404040);
83
-
84
- (bool _found, bytes memory _returnedData) = JBMetadataResolver.getDataFor(_invalidId, _metadata);
85
-
86
- // check
87
- assertEq(_found, false);
88
- assertEq("", _returnedData);
89
- }
90
- }
@@ -1,247 +0,0 @@
1
- // SPDX-License-Identifier: MIT
2
- pragma solidity 0.8.28;
3
-
4
- import {JBTest} from "../../../helpers/JBTest.sol";
5
- import {JBMetadataResolver} from "../../../../src/libraries/JBMetadataResolver.sol";
6
-
7
- /// @notice Harness that exposes JBMetadataResolver internals and adds a combined operation
8
- /// to test memory corruption from _sliceBytes within a single execution context.
9
- contract MetadataResolverEdgeCaseHarness {
10
- function createMetadata(bytes4[] memory ids, bytes[] memory datas) external pure returns (bytes memory) {
11
- return JBMetadataResolver.createMetadata(ids, datas);
12
- }
13
-
14
- function getDataFor(bytes4 id, bytes memory metadata) external pure returns (bool found, bytes memory targetData) {
15
- return JBMetadataResolver.getDataFor(id, metadata);
16
- }
17
-
18
- function addToMetadata(
19
- bytes memory originalMetadata,
20
- bytes4 idToAdd,
21
- bytes memory dataToAdd
22
- )
23
- external
24
- pure
25
- returns (bytes memory)
26
- {
27
- return JBMetadataResolver.addToMetadata(originalMetadata, idToAdd, dataToAdd);
28
- }
29
-
30
- /// @notice Adds an entry then immediately verifies all entries in one execution context.
31
- /// This catches memory corruption from _sliceBytes that wouldn't be visible across external calls.
32
- function addAndVerifyAll(
33
- bytes memory metadata,
34
- bytes4 newId,
35
- bytes memory newData,
36
- bytes4[] memory allIds,
37
- bytes32[] memory expectedValues
38
- )
39
- external
40
- pure
41
- returns (bool allCorrect)
42
- {
43
- // Add the new entry — this internally calls _sliceBytes with start > 0
44
- bytes memory updated = JBMetadataResolver.addToMetadata(metadata, newId, newData);
45
-
46
- // Verify all entries within the same execution context (same memory space)
47
- allCorrect = true;
48
- for (uint256 i; i < allIds.length; i++) {
49
- (bool found, bytes memory data) = JBMetadataResolver.getDataFor(allIds[i], updated);
50
- if (!found) {
51
- allCorrect = false;
52
- break;
53
- }
54
- if (
55
- keccak256(abi.encodePacked(bytes32(abi.decode(data, (uint256)))))
56
- != keccak256(abi.encodePacked(expectedValues[i]))
57
- ) {
58
- allCorrect = false;
59
- break;
60
- }
61
- }
62
- }
63
- }
64
-
65
- /// @notice Tests for _sliceBytes over-copy and addToMetadata offset overflow.
66
- contract TestMetadataResolverEdgeCases is JBTest {
67
- MetadataResolverEdgeCaseHarness harness;
68
-
69
- function setUp() external {
70
- harness = new MetadataResolverEdgeCaseHarness();
71
- }
72
-
73
- //*********************************************************************//
74
- // --- _sliceBytes memory over-copy --------------------------------- //
75
- //*********************************************************************//
76
-
77
- /// @notice Verifies that addToMetadata preserves all entries when adding to metadata with
78
- /// multiple existing entries. The _sliceBytes call at line 129 uses start > 0, which on
79
- /// the buggy code would over-copy and corrupt subsequent memory operations.
80
- function test_addToMetadataPreservesAllEntries() external view {
81
- bytes4 id1 = bytes4(0x11111111);
82
- bytes4 id2 = bytes4(0x22222222);
83
- bytes4 id3 = bytes4(0x33333333);
84
-
85
- uint256 val1 = 111;
86
- uint256 val2 = 222;
87
- uint256 val3 = 333;
88
-
89
- // Create metadata with 2 entries
90
- bytes4[] memory ids = new bytes4[](2);
91
- ids[0] = id1;
92
- ids[1] = id2;
93
-
94
- bytes[] memory datas = new bytes[](2);
95
- datas[0] = abi.encodePacked(bytes32(val1));
96
- datas[1] = abi.encodePacked(bytes32(val2));
97
-
98
- bytes memory metadata = harness.createMetadata(ids, datas);
99
-
100
- // Add a 3rd entry — this exercises _sliceBytes with start > 0
101
- bytes4[] memory allIds = new bytes4[](3);
102
- allIds[0] = id1;
103
- allIds[1] = id2;
104
- allIds[2] = id3;
105
-
106
- bytes32[] memory expectedValues = new bytes32[](3);
107
- expectedValues[0] = bytes32(val1);
108
- expectedValues[1] = bytes32(val2);
109
- expectedValues[2] = bytes32(val3);
110
-
111
- bool allCorrect =
112
- harness.addAndVerifyAll(metadata, id3, abi.encodePacked(bytes32(val3)), allIds, expectedValues);
113
-
114
- assertTrue(allCorrect, "All entries should be retrievable after addToMetadata");
115
- }
116
-
117
- /// @notice Test with 4 sequential addToMetadata calls, each exercising _sliceBytes.
118
- /// More entries = more start > 0 cases = more chances for memory corruption.
119
- function test_multipleSequentialAdds() external view {
120
- bytes4[5] memory ids =
121
- [bytes4(0x11111111), bytes4(0x22222222), bytes4(0x33333333), bytes4(0x44444444), bytes4(0x55555555)];
122
- uint256[5] memory vals = [uint256(100), uint256(200), uint256(300), uint256(400), uint256(500)];
123
-
124
- // Start with 1 entry via createMetadata
125
- bytes4[] memory initIds = new bytes4[](1);
126
- initIds[0] = ids[0];
127
- bytes[] memory initDatas = new bytes[](1);
128
- initDatas[0] = abi.encodePacked(bytes32(vals[0]));
129
- bytes memory metadata = harness.createMetadata(initIds, initDatas);
130
-
131
- // Add 4 more entries sequentially
132
- for (uint256 i = 1; i < 5; i++) {
133
- metadata = harness.addToMetadata(metadata, ids[i], abi.encodePacked(bytes32(vals[i])));
134
- }
135
-
136
- // Verify ALL entries are still correct
137
- for (uint256 i; i < 5; i++) {
138
- (bool found, bytes memory data) = harness.getDataFor(ids[i], metadata);
139
- assertTrue(found, string.concat("Entry ", vm.toString(i), " should be found"));
140
- assertEq(abi.decode(data, (uint256)), vals[i], string.concat("Entry ", vm.toString(i), " data mismatch"));
141
- }
142
- }
143
-
144
- /// @notice Verify that getDataFor returns the exact expected length for non-first entries.
145
- /// On buggy code, _sliceBytes copies more than needed, but the returned length should still
146
- /// be correct. This test verifies both length and content.
147
- function test_getDataForReturnsCorrectLength() external view {
148
- bytes4 id1 = bytes4(0xAAAAAAAA);
149
- bytes4 id2 = bytes4(0xBBBBBBBB);
150
-
151
- // Entry 1: 2 words (64 bytes). Entry 2: 1 word (32 bytes).
152
- bytes4[] memory ids = new bytes4[](2);
153
- ids[0] = id1;
154
- ids[1] = id2;
155
-
156
- bytes[] memory datas = new bytes[](2);
157
- datas[0] = abi.encodePacked(bytes32(uint256(0xAA)), bytes32(uint256(0xBB))); // 64 bytes
158
- datas[1] = abi.encodePacked(bytes32(uint256(0xCC))); // 32 bytes
159
-
160
- bytes memory metadata = harness.createMetadata(ids, datas);
161
-
162
- // Get entry 1 (first entry, start = firstOffset * 32)
163
- (bool found1, bytes memory data1) = harness.getDataFor(id1, metadata);
164
- assertTrue(found1, "Entry 1 should be found");
165
- assertEq(data1.length, 64, "Entry 1 should be 64 bytes");
166
-
167
- // Get entry 2 (second entry, start > firstOffset * 32)
168
- (bool found2, bytes memory data2) = harness.getDataFor(id2, metadata);
169
- assertTrue(found2, "Entry 2 should be found");
170
- assertEq(data2.length, 32, "Entry 2 should be exactly 32 bytes");
171
- assertEq(abi.decode(data2, (uint256)), 0xCC, "Entry 2 data should be 0xCC");
172
- }
173
-
174
- //*********************************************************************//
175
- // --- addToMetadata offset overflow -------------------------------- //
176
- //*********************************************************************//
177
-
178
- /// @notice Verifies that addToMetadata reverts when the new offset would exceed 255.
179
- /// Uses 6 entries (table = 1 word, 30 bytes) with data totaling 253 words → total 255 words.
180
- /// Adding a 7th entry via addToMetadata forces the table from 1→2 words, incrementing all
181
- /// offsets by 1. This pushes newOffset from 255 to 256, triggering the overflow check.
182
- function test_addToMetadataRevertsOnOffsetOverflow() external {
183
- // 6 entries: table = ceil(6*5/32) = 1 word. firstOffset = 2.
184
- // 5 entries × 42 words + 1 entry × 43 words = 253 words of data.
185
- // Total = 1 (reserved) + 1 (table) + 253 (data) = 255 words.
186
- // createMetadata final offset check: 255 > 255 → false → succeeds.
187
- bytes4[] memory ids = new bytes4[](6);
188
- ids[0] = bytes4(0x11111111);
189
- ids[1] = bytes4(0x22222222);
190
- ids[2] = bytes4(0x33333333);
191
- ids[3] = bytes4(0x44444444);
192
- ids[4] = bytes4(0x55555555);
193
- ids[5] = bytes4(0x66666666);
194
-
195
- bytes[] memory datas = new bytes[](6);
196
- // 5 entries of 42 words (1344 bytes) + 1 entry of 43 words (1376 bytes)
197
- for (uint256 i; i < 5; i++) {
198
- datas[i] = new bytes(1344);
199
- // forge-lint: disable-next-line(unsafe-typecast)
200
- datas[i][0] = bytes1(uint8(i + 1));
201
- }
202
- datas[5] = new bytes(1376);
203
- datas[5][0] = 0x06;
204
-
205
- bytes memory metadata = harness.createMetadata(ids, datas);
206
-
207
- // Adding a 7th entry: table grows from 30 bytes (1 word) to 35 bytes (2 words).
208
- // All offsets += 1. lastOffset (212) becomes 213.
209
- // newOffset = 213 + 43 = 256 > 255 → revert.
210
- vm.expectRevert(JBMetadataResolver.JBMetadataResolver_MetadataTooLong.selector);
211
- harness.addToMetadata(metadata, bytes4(0x77777777), abi.encodePacked(bytes32(uint256(7))));
212
- }
213
-
214
- /// @notice Verifies that addToMetadata works when the offset is exactly at the boundary (255).
215
- /// Same 6-entry table expansion setup but with 1 less data word (total 254 words),
216
- /// so the expanded offset is exactly 255 — the maximum valid value.
217
- function test_addToMetadataSucceedsAtBoundary() external view {
218
- // 6 entries × 42 words each = 252 words of data.
219
- // Total = 1 (reserved) + 1 (table) + 252 (data) = 254 words.
220
- bytes4[] memory ids = new bytes4[](6);
221
- ids[0] = bytes4(0x11111111);
222
- ids[1] = bytes4(0x22222222);
223
- ids[2] = bytes4(0x33333333);
224
- ids[3] = bytes4(0x44444444);
225
- ids[4] = bytes4(0x55555555);
226
- ids[5] = bytes4(0x66666666);
227
-
228
- bytes[] memory datas = new bytes[](6);
229
- for (uint256 i; i < 6; i++) {
230
- datas[i] = new bytes(1344); // 42 words each
231
- // forge-lint: disable-next-line(unsafe-typecast)
232
- datas[i][0] = bytes1(uint8(i + 1));
233
- }
234
-
235
- bytes memory metadata = harness.createMetadata(ids, datas);
236
-
237
- // Adding 7th entry: table expands, all offsets += 1.
238
- // lastOffset (212) becomes 213. newOffset = 213 + 42 = 255 ≤ 255 → succeeds.
239
- bytes memory updated =
240
- harness.addToMetadata(metadata, bytes4(0x77777777), abi.encodePacked(bytes32(uint256(7))));
241
-
242
- // Verify the new entry is retrievable.
243
- (bool found, bytes memory data) = harness.getDataFor(bytes4(0x77777777), updated);
244
- assertTrue(found, "New entry should be found at boundary offset 255");
245
- assertEq(abi.decode(data, (uint256)), 7, "Boundary entry data should match");
246
- }
247
- }
@@ -1,229 +0,0 @@
1
- // SPDX-License-Identifier: MIT
2
- pragma solidity 0.8.28;
3
-
4
- import {JBTest} from "../../../helpers/JBTest.sol";
5
- import {JBMetadataResolver} from "../../../../src/libraries/JBMetadataResolver.sol";
6
-
7
- /// @notice Wrapper contract to expose JBMetadataResolver internal functions for testing.
8
- contract MetadataResolverHarness {
9
- function createMetadata(bytes4[] memory ids, bytes[] memory datas) external pure returns (bytes memory) {
10
- return JBMetadataResolver.createMetadata(ids, datas);
11
- }
12
-
13
- function getDataFor(bytes4 id, bytes memory metadata) external pure returns (bool found, bytes memory targetData) {
14
- return JBMetadataResolver.getDataFor(id, metadata);
15
- }
16
-
17
- function addToMetadata(
18
- bytes memory originalMetadata,
19
- bytes4 idToAdd,
20
- bytes memory dataToAdd
21
- )
22
- external
23
- pure
24
- returns (bytes memory)
25
- {
26
- return JBMetadataResolver.addToMetadata(originalMetadata, idToAdd, dataToAdd);
27
- }
28
-
29
- function getId(string memory purpose, address target) external pure returns (bytes4) {
30
- return JBMetadataResolver.getId(purpose, target);
31
- }
32
- }
33
-
34
- /// @notice Fuzz tests for JBMetadataResolver library.
35
- contract TestMetadataResolverFuzz_Local is JBTest {
36
- MetadataResolverHarness harness;
37
-
38
- function setUp() external {
39
- harness = new MetadataResolverHarness();
40
- }
41
-
42
- //*********************************************************************//
43
- // --- Single Entry Round-Trip -------------------------------------- //
44
- //*********************************************************************//
45
-
46
- /// @notice createMetadata with 1 entry, then getDataFor retrieves it.
47
- function testFuzz_singleEntry_roundTrip(bytes4 id, uint256 value) external view {
48
- vm.assume(id != bytes4(0)); // 0 ID would be confused with padding
49
-
50
- bytes4[] memory ids = new bytes4[](1);
51
- ids[0] = id;
52
-
53
- bytes[] memory datas = new bytes[](1);
54
- datas[0] = abi.encodePacked(bytes32(value)); // Padded to 32 bytes
55
-
56
- bytes memory metadata = harness.createMetadata(ids, datas);
57
-
58
- (bool found, bytes memory result) = harness.getDataFor(id, metadata);
59
- assertTrue(found, "ID should be found");
60
- assertEq(abi.decode(result, (uint256)), value, "data should match");
61
- }
62
-
63
- /// @notice Missing ID returns (false, "").
64
- function testFuzz_missingId_returnsEmpty(bytes4 id, bytes4 searchId, uint256 value) external view {
65
- vm.assume(id != bytes4(0));
66
- vm.assume(searchId != bytes4(0));
67
- vm.assume(id != searchId);
68
-
69
- bytes4[] memory ids = new bytes4[](1);
70
- ids[0] = id;
71
-
72
- bytes[] memory datas = new bytes[](1);
73
- datas[0] = abi.encodePacked(bytes32(value));
74
-
75
- bytes memory metadata = harness.createMetadata(ids, datas);
76
-
77
- (bool found, bytes memory result) = harness.getDataFor(searchId, metadata);
78
- assertFalse(found, "non-existent ID should not be found");
79
- assertEq(result.length, 0, "data should be empty");
80
- }
81
-
82
- //*********************************************************************//
83
- // --- Two Entry Round-Trip ----------------------------------------- //
84
- //*********************************************************************//
85
-
86
- /// @notice createMetadata with 2 entries, both are retrievable.
87
- function testFuzz_twoEntries_roundTrip(bytes4 id1, bytes4 id2, uint256 value1, uint256 value2) external view {
88
- vm.assume(id1 != bytes4(0) && id2 != bytes4(0));
89
- vm.assume(id1 != id2);
90
-
91
- bytes4[] memory ids = new bytes4[](2);
92
- ids[0] = id1;
93
- ids[1] = id2;
94
-
95
- bytes[] memory datas = new bytes[](2);
96
- datas[0] = abi.encodePacked(bytes32(value1));
97
- datas[1] = abi.encodePacked(bytes32(value2));
98
-
99
- bytes memory metadata = harness.createMetadata(ids, datas);
100
-
101
- // Check first entry
102
- (bool found1, bytes memory result1) = harness.getDataFor(id1, metadata);
103
- assertTrue(found1, "first ID should be found");
104
- assertEq(abi.decode(result1, (uint256)), value1, "first data should match");
105
-
106
- // Check second entry
107
- (bool found2, bytes memory result2) = harness.getDataFor(id2, metadata);
108
- assertTrue(found2, "second ID should be found");
109
- assertEq(abi.decode(result2, (uint256)), value2, "second data should match");
110
- }
111
-
112
- //*********************************************************************//
113
- // --- addToMetadata Round-Trip ------------------------------------- //
114
- //*********************************************************************//
115
-
116
- /// @notice addToMetadata on empty metadata creates valid entry.
117
- function testFuzz_addToEmpty_roundTrip(bytes4 id, uint256 value) external view {
118
- vm.assume(id != bytes4(0));
119
-
120
- bytes memory empty = new bytes(0);
121
- bytes memory dataToAdd = abi.encodePacked(bytes32(value));
122
-
123
- bytes memory metadata = harness.addToMetadata(empty, id, dataToAdd);
124
-
125
- (bool found, bytes memory result) = harness.getDataFor(id, metadata);
126
- assertTrue(found, "added ID should be found");
127
- assertEq(abi.decode(result, (uint256)), value, "added data should match");
128
- }
129
-
130
- /// @notice addToMetadata preserves existing entries.
131
- function testFuzz_addPreservesExisting(bytes4 id1, bytes4 id2, uint256 value1, uint256 value2) external view {
132
- vm.assume(id1 != bytes4(0) && id2 != bytes4(0));
133
- vm.assume(id1 != id2);
134
-
135
- // Create metadata with first entry
136
- bytes4[] memory ids = new bytes4[](1);
137
- ids[0] = id1;
138
-
139
- bytes[] memory datas = new bytes[](1);
140
- datas[0] = abi.encodePacked(bytes32(value1));
141
-
142
- bytes memory metadata = harness.createMetadata(ids, datas);
143
-
144
- // Add second entry
145
- metadata = harness.addToMetadata(metadata, id2, abi.encodePacked(bytes32(value2)));
146
-
147
- // Both should be retrievable
148
- (bool found1, bytes memory result1) = harness.getDataFor(id1, metadata);
149
- assertTrue(found1, "original ID should still be found");
150
- assertEq(abi.decode(result1, (uint256)), value1, "original data should be preserved");
151
-
152
- (bool found2, bytes memory result2) = harness.getDataFor(id2, metadata);
153
- assertTrue(found2, "added ID should be found");
154
- assertEq(abi.decode(result2, (uint256)), value2, "added data should match");
155
- }
156
-
157
- //*********************************************************************//
158
- // --- Edge Cases --------------------------------------------------- //
159
- //*********************************************************************//
160
-
161
- /// @notice Empty/short metadata returns (false, "").
162
- function testFuzz_shortMetadata_returnsEmpty(bytes4 id, uint8 length) external view {
163
- vm.assume(id != bytes4(0));
164
- length = uint8(bound(uint256(length), 0, 37)); // <= MIN_METADATA_LENGTH
165
-
166
- bytes memory shortData = new bytes(length);
167
-
168
- (bool found, bytes memory result) = harness.getDataFor(id, shortData);
169
- assertFalse(found, "short metadata should return false");
170
- assertEq(result.length, 0, "short metadata should return empty bytes");
171
- }
172
-
173
- /// @notice getId produces deterministic results.
174
- function testFuzz_getId_deterministic(string memory purpose, address target) external view {
175
- bytes4 id1 = harness.getId(purpose, target);
176
- bytes4 id2 = harness.getId(purpose, target);
177
- assertEq(id1, id2, "same inputs should produce same ID");
178
- }
179
-
180
- /// @notice getId with very different targets produces different IDs.
181
- /// @dev Only tests addresses that differ in the first 4 bytes to avoid XOR collision.
182
- function testFuzz_getId_differentTargets(uint256 seed1, uint256 seed2) external view {
183
- vm.assume(seed1 != seed2);
184
- // forge-lint: disable-next-line(unsafe-typecast)
185
- address target1 = address(uint160(seed1));
186
- // forge-lint: disable-next-line(unsafe-typecast)
187
- address target2 = address(uint160(seed2));
188
- vm.assume(target1 != target2);
189
-
190
- bytes4 id1 = harness.getId("test", target1);
191
- bytes4 id2 = harness.getId("test", target2);
192
-
193
- // Due to 4-byte truncation, collisions are possible but statistically rare
194
- // for truly random addresses. We just verify they're computed without reverting.
195
- // If they happen to collide, that's fine - it's a 1/2^32 chance per pair.
196
- if (bytes4(bytes20(target1)) != bytes4(bytes20(target2))) {
197
- assertTrue(id1 != id2, "IDs with different high-4-byte addresses should differ");
198
- }
199
- }
200
-
201
- //*********************************************************************//
202
- // --- Length Mismatch ---------------------------------------------- //
203
- //*********************************************************************//
204
-
205
- /// @notice createMetadata with mismatched lengths reverts.
206
- function test_lengthMismatch_reverts() external {
207
- bytes4[] memory ids = new bytes4[](2);
208
- ids[0] = bytes4(0x11111111);
209
- ids[1] = bytes4(0x22222222);
210
-
211
- bytes[] memory datas = new bytes[](1);
212
- datas[0] = abi.encodePacked(bytes32(uint256(100)));
213
-
214
- vm.expectRevert(JBMetadataResolver.JBMetadataResolver_LengthMismatch.selector);
215
- harness.createMetadata(ids, datas);
216
- }
217
-
218
- /// @notice createMetadata with unpadded data reverts.
219
- function test_unpaddedData_reverts() external {
220
- bytes4[] memory ids = new bytes4[](1);
221
- ids[0] = bytes4(0x11111111);
222
-
223
- bytes[] memory datas = new bytes[](1);
224
- datas[0] = abi.encodePacked(uint8(42)); // Only 1 byte, not padded
225
-
226
- vm.expectRevert(JBMetadataResolver.JBMetadataResolver_DataNotPadded.selector);
227
- harness.createMetadata(ids, datas);
228
- }
229
- }