99 story_client ,
1010 get_token_id ,
1111 MockERC721 ,
12- MockERC20 ,
13- ZERO_ADDRESS ,
14- ROYALTY_POLICY ,
15- PIL_LICENSE_TEMPLATE ,
1612 CORE_METADATA_MODULE
1713)
1814
@@ -23,8 +19,7 @@ def ip_id(self, story_client):
2319 token_id = get_token_id (MockERC721 , story_client .web3 , story_client .account )
2420 response = story_client .IPAsset .register (
2521 nft_contract = MockERC721 ,
26- token_id = token_id ,
27- tx_options = {"wait_for_transaction" : True }
22+ token_id = token_id
2823 )
2924 assert 'ip_id' in response , "Failed to register IP"
3025 return response ['ip_id' ]
@@ -36,8 +31,7 @@ def test_set_permission(self, story_client, ip_id):
3631 signer = account .address ,
3732 to = CORE_METADATA_MODULE ,
3833 permission = 1 , # ALLOW
39- func = "function setAll(address,string,bytes32,bytes32)" ,
40- tx_options = {"wait_for_transaction" : True }
34+ func = "function setAll(address,string,bytes32,bytes32)"
4135 )
4236
4337 assert response is not None
@@ -50,7 +44,7 @@ def test_set_all_permissions(self, story_client, ip_id):
5044 response = story_client .Permission .set_all_permissions (
5145 ip_id = ip_id ,
5246 signer = account .address ,
53- permission = 1 , # ALLOW
47+ permission = 1 # ALLOW
5448 )
5549
5650 assert response is not None
@@ -68,7 +62,7 @@ def test_create_set_permission_signature(self, story_client, ip_id):
6862 to = CORE_METADATA_MODULE ,
6963 func = "setAll(address,string,bytes32,bytes32)" ,
7064 permission = 1 , # ALLOW
71- deadline = deadline ,
65+ deadline = deadline
7266 )
7367
7468 assert response is not None
@@ -85,7 +79,250 @@ def test_set_permission_invalid_ip(self, story_client):
8579 ip_id = unregistered_ip ,
8680 signer = account .address ,
8781 to = CORE_METADATA_MODULE ,
88- permission = 1 ,
82+ permission = 1
8983 )
9084
9185 assert f"IP id with { unregistered_ip } is not registered" in str (exc_info .value )
86+
87+ def test_set_permission_invalid_addresses (self , story_client , ip_id ):
88+ """Test that set_permission raises proper exceptions for invalid addresses."""
89+ invalid_signer = "0xinvalid_address"
90+
91+ with pytest .raises (Exception ) as exc_info :
92+ story_client .Permission .set_permission (
93+ ip_id = ip_id ,
94+ signer = invalid_signer ,
95+ to = CORE_METADATA_MODULE ,
96+ permission = 1 # ALLOW
97+ )
98+
99+ assert "invalid address" in str (exc_info .value ).lower ()
100+
101+ invalid_to = "not_a_hex_address"
102+
103+ with pytest .raises (Exception ) as exc_info :
104+ story_client .Permission .set_permission (
105+ ip_id = ip_id ,
106+ signer = account .address ,
107+ to = invalid_to ,
108+ permission = 1 # ALLOW
109+ )
110+
111+ assert "invalid address" in str (exc_info .value ).lower ()
112+
113+ lowercase_address = account .address .lower ()
114+ try :
115+ response = story_client .Permission .set_permission (
116+ ip_id = ip_id ,
117+ signer = lowercase_address ,
118+ to = CORE_METADATA_MODULE ,
119+ permission = 1
120+ )
121+ assert 'tx_hash' in response
122+ except Exception as e :
123+ pytest .fail (f"set_permission should accept lowercase addresses, but raised: { e } " )
124+
125+ def test_different_permission_levels (self , story_client , ip_id ):
126+ """Test setting and changing different permission levels."""
127+ DISALLOW = 0
128+ ALLOW = 1
129+ ABSTAIN = 2
130+
131+ response = story_client .Permission .set_permission (
132+ ip_id = ip_id ,
133+ signer = account .address ,
134+ to = CORE_METADATA_MODULE ,
135+ permission = DISALLOW ,
136+ func = "function setAll(address,string,bytes32,bytes32)"
137+ )
138+
139+ assert response is not None
140+ assert 'tx_hash' in response
141+ assert isinstance (response ['tx_hash' ], str )
142+ assert len (response ['tx_hash' ]) > 0
143+
144+ response = story_client .Permission .set_permission (
145+ ip_id = ip_id ,
146+ signer = account .address ,
147+ to = CORE_METADATA_MODULE ,
148+ permission = ALLOW ,
149+ func = "function setAll(address,string,bytes32,bytes32)"
150+ )
151+
152+ assert response is not None
153+ assert 'tx_hash' in response
154+
155+ response = story_client .Permission .set_permission (
156+ ip_id = ip_id ,
157+ signer = account .address ,
158+ to = CORE_METADATA_MODULE ,
159+ permission = ABSTAIN ,
160+ func = "function setAll(address,string,bytes32,bytes32)"
161+ )
162+
163+ assert response is not None
164+ assert 'tx_hash' in response
165+
166+ response = story_client .Permission .set_all_permissions (
167+ ip_id = ip_id ,
168+ signer = account .address ,
169+ permission = DISALLOW
170+ )
171+
172+ assert response is not None
173+ assert 'tx_hash' in response
174+
175+ response = story_client .Permission .set_all_permissions (
176+ ip_id = ip_id ,
177+ signer = account .address ,
178+ permission = ABSTAIN
179+ )
180+
181+ assert response is not None
182+ assert 'tx_hash' in response
183+
184+ def test_different_function_selectors (self , story_client , ip_id ):
185+ """Test setting permissions with different function selectors."""
186+ ALLOW = 1
187+
188+ response = story_client .Permission .set_permission (
189+ ip_id = ip_id ,
190+ signer = account .address ,
191+ to = CORE_METADATA_MODULE ,
192+ permission = 1
193+ # No func parameter provided - should use default
194+ )
195+
196+ assert response is not None
197+ assert 'tx_hash' in response
198+ assert isinstance (response ['tx_hash' ], str )
199+ assert len (response ['tx_hash' ]) > 0
200+
201+ response = story_client .Permission .set_permission (
202+ ip_id = ip_id ,
203+ signer = account .address ,
204+ to = CORE_METADATA_MODULE ,
205+ permission = ALLOW ,
206+ func = "setAll(address,string,bytes32,bytes32)"
207+ )
208+
209+ assert response is not None
210+ assert 'tx_hash' in response
211+
212+ response = story_client .Permission .set_permission (
213+ ip_id = ip_id ,
214+ signer = account .address ,
215+ to = CORE_METADATA_MODULE ,
216+ permission = ALLOW ,
217+ func = "setName(address,string)"
218+ )
219+
220+ assert response is not None
221+ assert 'tx_hash' in response
222+
223+ response = story_client .Permission .set_permission (
224+ ip_id = ip_id ,
225+ signer = account .address ,
226+ to = CORE_METADATA_MODULE ,
227+ permission = ALLOW ,
228+ func = "setDescription(address,string)"
229+ )
230+
231+ assert response is not None
232+ assert 'tx_hash' in response
233+
234+ deadline = web3 .eth .get_block ('latest' )['timestamp' ] + 60000
235+ response = story_client .Permission .create_set_permission_signature (
236+ ip_id = ip_id ,
237+ signer = account .address ,
238+ to = CORE_METADATA_MODULE ,
239+ permission = ALLOW ,
240+ # No func parameter provided
241+ deadline = deadline
242+ )
243+
244+ assert response is not None
245+ assert 'tx_hash' in response
246+
247+ def test_permission_hierarchies_and_overrides (self , story_client , ip_id ):
248+ """Test permission hierarchies and how permissions override each other."""
249+ DISALLOW = 0
250+ ALLOW = 1
251+ ABSTAIN = 2
252+
253+ response = story_client .Permission .set_all_permissions (
254+ ip_id = ip_id ,
255+ signer = account .address ,
256+ permission = DISALLOW
257+ )
258+
259+ assert response is not None
260+ assert 'tx_hash' in response
261+
262+ specific_func = "setName(address,string)"
263+ response = story_client .Permission .set_permission (
264+ ip_id = ip_id ,
265+ signer = account .address ,
266+ to = CORE_METADATA_MODULE ,
267+ permission = ALLOW ,
268+ func = specific_func
269+ )
270+
271+ assert response is not None
272+ assert 'tx_hash' in response
273+
274+ alternate_signer = web3 .eth .account .create ()
275+
276+ response = story_client .Permission .set_all_permissions (
277+ ip_id = ip_id ,
278+ signer = alternate_signer .address ,
279+ permission = ALLOW
280+ )
281+
282+ assert response is not None
283+ assert 'tx_hash' in response
284+
285+ response = story_client .Permission .set_permission (
286+ ip_id = ip_id ,
287+ signer = alternate_signer .address ,
288+ to = CORE_METADATA_MODULE ,
289+ permission = DISALLOW ,
290+ func = specific_func
291+ )
292+
293+ assert response is not None
294+ assert 'tx_hash' in response
295+
296+ deadline = web3 .eth .get_block ('latest' )['timestamp' ] + 60000
297+
298+ response = story_client .Permission .create_set_permission_signature (
299+ ip_id = ip_id ,
300+ signer = account .address ,
301+ to = CORE_METADATA_MODULE ,
302+ permission = ALLOW ,
303+ func = "setDescription(address,string)" ,
304+ deadline = deadline
305+ )
306+
307+ assert response is not None
308+ assert 'tx_hash' in response
309+
310+ response = story_client .Permission .set_all_permissions (
311+ ip_id = ip_id ,
312+ signer = account .address ,
313+ permission = ABSTAIN
314+ )
315+
316+ assert response is not None
317+ assert 'tx_hash' in response
318+
319+ response = story_client .Permission .set_all_permissions (
320+ ip_id = ip_id ,
321+ signer = alternate_signer .address ,
322+ permission = ABSTAIN
323+ )
324+
325+ assert response is not None
326+ assert 'tx_hash' in response
327+
328+
0 commit comments