@@ -286,3 +286,79 @@ def test_values(arr: int128[2][3], s: String[10]) -> (int128[2][3], String[10]):
286
286
287
287
c = get_contract (code )
288
288
assert c .test_values ([[1 , 2 ], [3 , 4 ], [5 , 6 ]], "abcdef" ) == [[[1 , 2 ], [3 , 4 ], [5 , 6 ]], "abcdef" ]
289
+
290
+
291
+ def test_nested_index_of_returned_array (get_contract ):
292
+ code = """
293
+ @internal
294
+ def inner() -> (int128, int128):
295
+ return 1,2
296
+
297
+ @external
298
+ def outer() -> int128[2]:
299
+ return [333, self.inner()[0]]
300
+ """
301
+
302
+ c = get_contract (code )
303
+ assert c .outer () == [333 , 1 ]
304
+
305
+
306
+ def test_nested_calls_inside_arrays (get_contract ):
307
+ code = """
308
+ @internal
309
+ def _foo(a: uint256, b: uint256[2]) -> (uint256, uint256, uint256, uint256, uint256):
310
+ return 1, a, b[0], b[1], 5
311
+
312
+ @internal
313
+ def _foo2() -> uint256:
314
+ a: uint256[10] = [6,7,8,9,10,11,12,13,15,16]
315
+ return 4
316
+
317
+ @external
318
+ def foo() -> (uint256, uint256, uint256, uint256, uint256):
319
+ return self._foo(2, [3, self._foo2()])
320
+ """
321
+
322
+ c = get_contract (code )
323
+ assert c .foo () == [1 , 2 , 3 , 4 , 5 ]
324
+
325
+
326
+ def test_nested_calls_inside_arrays_with_index_access (get_contract ):
327
+ code = """
328
+ @internal
329
+ def _foo(a: uint256[2], b: uint256[2]) -> (uint256, uint256, uint256, uint256, uint256):
330
+ return a[1]-b[0], 2, a[0]-b[1], 8-b[1], 5
331
+
332
+ @internal
333
+ def _foo2() -> (uint256, uint256):
334
+ a: uint256[10] = [6,7,8,9,10,11,12,13,15,16]
335
+ return a[6], 4
336
+
337
+ @external
338
+ def foo() -> (uint256, uint256, uint256, uint256, uint256):
339
+ return self._foo([7, self._foo2()[0]], [11, self._foo2()[1]])
340
+ """
341
+
342
+ c = get_contract (code )
343
+ assert c .foo () == [1 , 2 , 3 , 4 , 5 ]
344
+
345
+
346
+ def test_so_many_things_you_should_never_do (get_contract ):
347
+ code = """
348
+ @internal
349
+ def _foo(a: uint256[2], b: uint256[2]) -> uint256[5]:
350
+ return [a[1]-b[0], 2, a[0]-b[1], 8-b[1], 5]
351
+
352
+ @internal
353
+ def _foo2() -> (uint256, uint256):
354
+ b: uint256[2] = [5, 8]
355
+ a: uint256[10] = [6,7,8,9,10,11,12,13,self._foo([44,b[0]],b)[4],16]
356
+ return a[6], 4
357
+
358
+ @external
359
+ def foo() -> (uint256, uint256[3], uint256[2]):
360
+ x: uint256[3] = [1, 14-self._foo2()[0], self._foo([7,self._foo2()[0]], [11,self._foo2()[1]])[2]]
361
+ return 666, x, [88, self._foo2()[0]]
362
+ """
363
+ c = get_contract (code )
364
+ assert c .foo () == [666 , [1 , 2 , 3 ], [88 , 12 ]]
0 commit comments