@@ -4,6 +4,7 @@ pragma solidity 0.8.26;
4
4
5
5
// external
6
6
import { Strings } from "@openzeppelin/contracts/utils/Strings.sol " ;
7
+ import { Errors as CoreErrors } from "@storyprotocol/core/lib/Errors.sol " ;
7
8
import { ICoreMetadataModule } from "@storyprotocol/core/interfaces/modules/metadata/ICoreMetadataModule.sol " ;
8
9
import { IIPAccount } from "@storyprotocol/core/interfaces/IIPAccount.sol " ;
9
10
import { ILicensingModule } from "@storyprotocol/core/interfaces/modules/licensing/ILicensingModule.sol " ;
@@ -158,4 +159,118 @@ contract LicenseAttachmentWorkflowsTest is BaseTest {
158
159
sigAttach: WorkflowStructs.SignatureData ({ signer: u.alice, deadline: deadline, signature: sigAttach })
159
160
});
160
161
}
162
+
163
+ function test_LicenseAttachmentWorkflows_registerPILTermsAndAttach_idempotency ()
164
+ public
165
+ withCollection
166
+ withIp (u.alice)
167
+ {
168
+ address payable ipId = ipAsset[1 ].ipId;
169
+ uint256 deadline = block .timestamp + 1000 ;
170
+
171
+ (bytes memory signature , , bytes memory data ) = _getSetPermissionSigForPeriphery ({
172
+ ipId: ipId,
173
+ to: address (licenseAttachmentWorkflows),
174
+ module: address (licensingModule),
175
+ selector: ILicensingModule.attachLicenseTerms.selector ,
176
+ deadline: deadline,
177
+ state: IIPAccount (ipId).state (),
178
+ signerSk: sk.alice
179
+ });
180
+
181
+ IIPAccount (ipId).executeWithSig ({
182
+ to: address (accessController),
183
+ value: 0 ,
184
+ data: data,
185
+ signer: u.alice,
186
+ deadline: deadline,
187
+ signature: signature
188
+ });
189
+
190
+ uint256 licenseTermsId1 = licenseAttachmentWorkflows.registerPILTermsAndAttach ({
191
+ ipId: ipId,
192
+ terms: PILFlavors.commercialUse ({
193
+ mintingFee: 100 ,
194
+ currencyToken: address (mockToken),
195
+ royaltyPolicy: address (royaltyPolicyLAP)
196
+ })
197
+ });
198
+
199
+ // attach the same license terms to the IP again, but it shouldn't revert
200
+ uint256 licenseTermsId2 = licenseAttachmentWorkflows.registerPILTermsAndAttach ({
201
+ ipId: ipId,
202
+ terms: PILFlavors.commercialUse ({
203
+ mintingFee: 100 ,
204
+ currencyToken: address (mockToken),
205
+ royaltyPolicy: address (royaltyPolicyLAP)
206
+ })
207
+ });
208
+
209
+ assertEq (licenseTermsId1, licenseTermsId2);
210
+ }
211
+
212
+ function test_revert_registerPILTermsAndAttach_DerivativesCannotAddLicenseTerms ()
213
+ public
214
+ withCollection
215
+ whenCallerHasMinterRole
216
+ withEnoughTokens (address (licenseAttachmentWorkflows))
217
+ {
218
+ (address ipIdParent , , uint256 licenseTermsIdParent ) = licenseAttachmentWorkflows
219
+ .mintAndRegisterIpAndAttachPILTerms ({
220
+ spgNftContract: address (nftContract),
221
+ recipient: caller,
222
+ ipMetadata: ipMetadataDefault,
223
+ terms: PILFlavors.nonCommercialSocialRemixing ()
224
+ });
225
+
226
+ address [] memory parentIpIds = new address [](1 );
227
+ parentIpIds[0 ] = ipIdParent;
228
+
229
+ uint256 [] memory licenseTermsIds = new uint256 [](1 );
230
+ licenseTermsIds[0 ] = licenseTermsIdParent;
231
+
232
+ (address ipIdChild , uint256 tokenIdChild ) = derivativeWorkflows.mintAndRegisterIpAndMakeDerivative ({
233
+ spgNftContract: address (nftContract),
234
+ derivData: WorkflowStructs.MakeDerivative ({
235
+ parentIpIds: parentIpIds,
236
+ licenseTemplate: address (pilTemplate),
237
+ licenseTermsIds: licenseTermsIds,
238
+ royaltyContext: ""
239
+ }),
240
+ ipMetadata: ipMetadataDefault,
241
+ recipient: caller
242
+ });
243
+
244
+ uint256 deadline = block .timestamp + 1000 ;
245
+
246
+ (bytes memory signature , , bytes memory data ) = _getSetPermissionSigForPeriphery ({
247
+ ipId: ipIdChild,
248
+ to: address (licenseAttachmentWorkflows),
249
+ module: address (licensingModule),
250
+ selector: ILicensingModule.attachLicenseTerms.selector ,
251
+ deadline: deadline,
252
+ state: IIPAccount (payable (ipIdChild)).state (),
253
+ signerSk: sk.alice
254
+ });
255
+
256
+ IIPAccount (payable (ipIdChild)).executeWithSig ({
257
+ to: address (accessController),
258
+ value: 0 ,
259
+ data: data,
260
+ signer: u.alice,
261
+ deadline: deadline,
262
+ signature: signature
263
+ });
264
+
265
+ // attach a different license terms to the child ip, should revert with the correct error
266
+ vm.expectRevert (CoreErrors.LicensingModule__DerivativesCannotAddLicenseTerms.selector );
267
+ licenseAttachmentWorkflows.registerPILTermsAndAttach ({
268
+ ipId: ipIdChild,
269
+ terms: PILFlavors.commercialUse ({
270
+ mintingFee: 100 ,
271
+ currencyToken: address (mockToken),
272
+ royaltyPolicy: address (royaltyPolicyLAP)
273
+ })
274
+ });
275
+ }
161
276
}
0 commit comments