@@ -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'
@@ -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