@@ -2,7 +2,7 @@ import { getABIEncodedValue } from '@algorandfoundation/algokit-utils/types/app-
22import { Bytes } from '@algorandfoundation/algorand-typescript'
33import { Bool , DynamicArray , interpretAsArc4 , StaticArray , Str , Struct , Tuple , UintN } from '@algorandfoundation/algorand-typescript/arc4'
44import { encodingUtil } from '@algorandfoundation/puya-ts'
5- import { describe , expect , test } from 'vitest'
5+ import { describe , expect , it , test } from 'vitest'
66import type { StubBytesCompat } from '../../src/impl/primitives'
77import { AccountCls } from '../../src/impl/reference'
88import type { DeliberateAny } from '../../src/typescript-helpers'
@@ -21,42 +21,42 @@ class Swapped1 extends Struct<{
2121 c : Bool
2222 d : Str
2323 a : Tuple < [ UintN < 64 > , Bool , Bool ] >
24- } > { }
24+ } > { }
2525
2626class Swapped2 extends Struct < {
2727 b : UintN < 64 >
2828 c : Bool
2929 d : Str
3030 a : Tuple < [ Tuple < [ UintN < 64 > , Bool , Bool ] > , Tuple < [ UintN < 64 > , Bool , Bool ] > ] >
31- } > { }
31+ } > { }
3232
3333class Swapped3 extends Struct < {
3434 b : UintN < 64 >
3535 c : Bool
3636 d : Str
3737 a : Tuple < [ DynamicArray < Str > , DynamicArray < Str > , Str , UintN < 64 > , Bool , StaticArray < UintN < 64 > , 3 > ] >
38- } > { }
38+ } > { }
3939
4040class Swapped4 extends Struct < {
4141 b : UintN < 64 >
4242 c : Bool
4343 d : Str
4444 a : Tuple < [ Tuple < [ Bool , DynamicArray < Str > , Str ] > , UintN < 64 > , StaticArray < UintN < 64 > , 3 > ] >
45- } > { }
45+ } > { }
4646
4747class Swapped5 extends Struct < {
4848 b : UintN < 64 >
4949 c : Bool
5050 d : Str
5151 a : Tuple < [ Tuple < [ Bool , DynamicArray < Str > , Str ] > , Tuple < [ UintN < 64 > , StaticArray < UintN < 64 > , 3 > ] > ] >
52- } > { }
52+ } > { }
5353
5454class Swapped6 extends Struct < {
5555 b : UintN < 64 >
5656 c : Bool
5757 d : Str
5858 a : Tuple < [ Tuple < [ Bool , Tuple < [ DynamicArray < Str > , Str ] > ] > , Tuple < [ UintN < 64 > , StaticArray < UintN < 64 > , 3 > ] > ] >
59- } > { }
59+ } > { }
6060
6161const testData = [
6262 {
@@ -252,6 +252,52 @@ describe('arc4.Struct', async () => {
252252 compareARC4AndABIValue ( result . d , nativeValues [ i ++ ] )
253253 compareARC4AndABIValue ( result . a , nativeValues [ i ++ ] )
254254 } )
255+
256+ it ( 'set item in struct' , async ( ) => {
257+ const data = testData [ 5 ]
258+
259+ const nativeValues = data . nativeValues ( ) as DeliberateAny
260+ nativeValues [ 0 ] = 43
261+ nativeValues [ 2 ] = 'world'
262+ nativeValues [ 3 ] [ 0 ] [ 1 ] [ 0 ] [ 1 ] = 'hello, world'
263+ nativeValues [ 3 ] [ 0 ] [ 1 ] [ 0 ] . push ( 'test' )
264+ nativeValues [ 3 ] [ 1 ] [ 1 ] [ 0 ] = 24
265+
266+ const sdkResult = getABIEncodedValue ( nativeValues , data . abiTypeString , { } )
267+
268+ const abiValues = data . struct ( ) as Swapped6
269+ abiValues . b = new UintN < 64 > ( 43 )
270+ abiValues . d = new Str ( 'world' )
271+ abiValues . a . at ( 0 ) . at ( 1 ) . at ( 0 ) [ 1 ] = new Str ( 'hello, world' )
272+ abiValues . a . at ( 0 ) . at ( 1 ) . at ( 0 ) . push ( new Str ( 'test' ) )
273+ abiValues . a . at ( 1 ) . at ( 1 ) [ 0 ] = new UintN < 64 > ( 24 )
274+ const result = abiValues . bytes
275+
276+ expect ( result ) . toEqual ( Bytes ( sdkResult ) )
277+ } )
278+
279+ it ( 'set item in struct created from bytes' , async ( ) => {
280+ const data = testData [ 5 ]
281+ const nativeValues = data . nativeValues ( ) as DeliberateAny
282+ nativeValues [ 0 ] = 43
283+ nativeValues [ 2 ] = 'world'
284+ nativeValues [ 3 ] [ 0 ] [ 1 ] [ 0 ] [ 1 ] = 'hello, world'
285+ nativeValues [ 3 ] [ 0 ] [ 1 ] [ 0 ] . push ( 'test' )
286+ nativeValues [ 3 ] [ 1 ] [ 1 ] [ 0 ] = 24
287+
288+ const sdkResult = getABIEncodedValue ( nativeValues , data . abiTypeString , { } )
289+ const bytes = Bytes ( getABIEncodedValue ( data . nativeValues ( ) , data . abiTypeString , { } ) )
290+
291+ const abiValues = data . create ( bytes ) as Swapped6
292+ abiValues . b = new UintN < 64 > ( 43 )
293+ abiValues . d = new Str ( 'world' )
294+ abiValues . a . at ( 0 ) . at ( 1 ) . at ( 0 ) [ 1 ] = new Str ( 'hello, world' )
295+ abiValues . a . at ( 0 ) . at ( 1 ) . at ( 0 ) . push ( new Str ( 'test' ) )
296+ abiValues . a . at ( 1 ) . at ( 1 ) [ 0 ] = new UintN < 64 > ( 24 )
297+ const result = abiValues . bytes
298+
299+ expect ( result ) . toEqual ( Bytes ( sdkResult ) )
300+ } )
255301} )
256302
257303const compareARC4AndABIValue = ( arc4Value : DeliberateAny , nativeValue : DeliberateAny ) => {
0 commit comments