Skip to content

Commit 7f1f5fb

Browse files
committed
feat: add tests for setting items in struct back in
1 parent c71995b commit 7f1f5fb

File tree

3 files changed

+57
-11
lines changed

3 files changed

+57
-11
lines changed

package-lock.json

Lines changed: 8 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,8 @@
6666
"vitest": "3.0.8"
6767
},
6868
"dependencies": {
69-
"@algorandfoundation/algorand-typescript": "^1.0.0-beta.23",
70-
"@algorandfoundation/puya-ts": "^1.0.0-beta.41",
69+
"@algorandfoundation/algorand-typescript": "^1.0.0-beta.25",
70+
"@algorandfoundation/puya-ts": "^1.0.0-beta.43",
7171
"elliptic": "^6.5.7",
7272
"js-sha256": "^0.11.0",
7373
"js-sha3": "^0.9.3",

tests/arc4/struct.spec.ts

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { getABIEncodedValue } from '@algorandfoundation/algokit-utils/types/app-
22
import { Bytes } from '@algorandfoundation/algorand-typescript'
33
import { Bool, DynamicArray, interpretAsArc4, StaticArray, Str, Struct, Tuple, UintN } from '@algorandfoundation/algorand-typescript/arc4'
44
import { encodingUtil } from '@algorandfoundation/puya-ts'
5-
import { describe, expect, test } from 'vitest'
5+
import { describe, expect, it, test } from 'vitest'
66
import type { StubBytesCompat } from '../../src/impl/primitives'
77
import { AccountCls } from '../../src/impl/reference'
88
import 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

257303
const compareARC4AndABIValue = (arc4Value: DeliberateAny, nativeValue: DeliberateAny) => {

0 commit comments

Comments
 (0)