1
- import algosdk , { ABIAddressType , ABIMethod , ABIType , Account , Address } from 'algosdk'
1
+ import algosdk , { ABIMethod , ABIType , Account , Address } from 'algosdk'
2
2
import invariant from 'tiny-invariant'
3
3
import { afterAll , beforeAll , beforeEach , describe , expect , test } from 'vitest'
4
4
import { APP_SPEC as nestedContractAppSpec } from '../../tests/example-contracts/client/TestContractClient'
@@ -1181,7 +1181,6 @@ describe('abi return', () => {
1181
1181
} )
1182
1182
} )
1183
1183
1184
- // TODO: NC - Switch these tests to not use bare.send(...) once algosdk supports access references
1185
1184
describe ( 'access references' , ( ) => {
1186
1185
const fixture = algorandFixture ( )
1187
1186
beforeEach ( fixture . newScope )
@@ -1251,52 +1250,38 @@ describe('access references', () => {
1251
1250
} , 20_000 ) // Account generation and funding can be slow
1252
1251
1253
1252
test ( 'address reference enables access' , async ( ) => {
1254
- const alice = await fixture . context . generateAccount ( { initialFunds : AlgoAmount . Algo ( 0.1 ) } )
1255
-
1256
- const method = appClient . getABIMethod ( 'addressBalance' ) . getSelector ( )
1257
-
1258
- const addressType = new ABIAddressType ( )
1259
- const aliceAddr = addressType . encode ( alice )
1260
-
1261
- await appClient . send . bare . call ( { args : [ method , aliceAddr ] , populateAppCallResources : false , accessReferences : [ { address : alice } ] } )
1253
+ await appClient . send . call ( {
1254
+ method : 'addressBalance' ,
1255
+ args : [ alice ] ,
1256
+ populateAppCallResources : false ,
1257
+ accessReferences : [ { address : alice } ] ,
1258
+ } )
1262
1259
} )
1263
1260
1264
1261
test ( 'up to 8 non access reference accounts can be used' , async ( ) => {
1265
- const method = appClient . getABIMethod ( 'addressBalance' ) . getSelector ( )
1266
-
1267
- const addressType = new ABIAddressType ( )
1268
- const aliceAddr = addressType . encode ( alice )
1269
-
1270
- await appClient . send . bare . call ( {
1271
- args : [ method , aliceAddr ] ,
1262
+ await appClient . send . call ( {
1263
+ method : 'addressBalance' ,
1264
+ args : [ alice ] ,
1272
1265
populateAppCallResources : false ,
1273
1266
accountReferences : [ alice , bob , charlie , dan , eve , frank , grace , heidi ] ,
1274
1267
} )
1275
1268
} )
1276
1269
1277
1270
test ( 'throws when more than 8 non access reference accounts are supplied' , async ( ) => {
1278
- const method = appClient . getABIMethod ( 'addressBalance' ) . getSelector ( )
1279
-
1280
- const addressType = new ABIAddressType ( )
1281
- const aliceAddr = addressType . encode ( alice )
1282
-
1283
1271
await expect (
1284
- appClient . send . bare . call ( {
1285
- args : [ method , aliceAddr ] ,
1272
+ appClient . send . call ( {
1273
+ method : 'addressBalance' ,
1274
+ args : [ alice ] ,
1286
1275
populateAppCallResources : false ,
1287
1276
accountReferences : [ alice , bob , charlie , dan , eve , frank , grace , heidi , ivan ] ,
1288
1277
} ) ,
1289
1278
) . rejects . toThrow ( / m a x n u m b e r o f a c c o u n t s i s 8 / )
1290
1279
} )
1291
1280
1292
1281
test ( 'up to 16 access addresses can be used' , async ( ) => {
1293
- const method = appClient . getABIMethod ( 'addressBalance' ) . getSelector ( )
1294
-
1295
- const addressType = new ABIAddressType ( )
1296
- const aliceAddr = addressType . encode ( alice )
1297
-
1298
- await appClient . send . bare . call ( {
1299
- args : [ method , aliceAddr ] ,
1282
+ await appClient . send . call ( {
1283
+ method : 'addressBalance' ,
1284
+ args : [ alice ] ,
1300
1285
populateAppCallResources : false ,
1301
1286
accessReferences : [
1302
1287
{ address : alice } ,
@@ -1320,14 +1305,10 @@ describe('access references', () => {
1320
1305
} )
1321
1306
1322
1307
test ( 'throws when more than 16 access addresses are supplied' , async ( ) => {
1323
- const method = appClient . getABIMethod ( 'addressBalance' ) . getSelector ( )
1324
-
1325
- const addressType = new ABIAddressType ( )
1326
- const aliceAddr = addressType . encode ( alice )
1327
-
1328
1308
await expect (
1329
- appClient . send . bare . call ( {
1330
- args : [ method , aliceAddr ] ,
1309
+ appClient . send . call ( {
1310
+ method : 'addressBalance' ,
1311
+ args : [ alice ] ,
1331
1312
populateAppCallResources : false ,
1332
1313
accessReferences : [
1333
1314
{ address : alice } ,
@@ -1353,32 +1334,28 @@ describe('access references', () => {
1353
1334
} )
1354
1335
1355
1336
test ( 'app reference enables access' , async ( ) => {
1356
- const method = appClient . getABIMethod ( 'externalAppCall' ) . getSelector ( )
1357
-
1358
- await appClient . send . bare . call ( {
1359
- args : [ method ] ,
1337
+ await appClient . send . call ( {
1338
+ method : 'externalAppCall' ,
1360
1339
populateAppCallResources : false ,
1361
1340
accessReferences : [ { appId : externalClient . appId } ] ,
1362
1341
staticFee : microAlgo ( 2000 ) ,
1363
1342
} )
1364
1343
} )
1365
1344
1366
1345
test ( 'asset reference enables access' , async ( ) => {
1367
- const method = appClient . getABIMethod ( 'assetTotal' ) . getSelector ( )
1368
1346
const assetId = ( await appClient . getGlobalState ( ) ) . asa . value as bigint
1369
1347
1370
- await appClient . send . bare . call ( {
1371
- args : [ method ] ,
1348
+ await appClient . send . call ( {
1349
+ method : 'assetTotal' ,
1372
1350
populateAppCallResources : false ,
1373
1351
accessReferences : [ { assetId } ] ,
1374
1352
} )
1375
1353
} )
1376
1354
1377
1355
test ( 'box reference enables access' , async ( ) => {
1378
- const method = appClient . getABIMethod ( 'smallBox' ) . getSelector ( )
1379
-
1380
- await appClient . send . bare . call ( {
1381
- args : [ method ] ,
1356
+ await appClient . send . call ( {
1357
+ method : 'smallBox' ,
1358
+ args : [ ] ,
1382
1359
populateAppCallResources : false ,
1383
1360
accessReferences : [ { box : { appId : appClient . appId , name : new Uint8Array ( [ 115 ] ) } } ] ,
1384
1361
} )
@@ -1388,13 +1365,9 @@ describe('access references', () => {
1388
1365
const alice = await fixture . context . generateAccount ( { initialFunds : AlgoAmount . Algo ( 0.1 ) } )
1389
1366
const assetId = ( await appClient . getGlobalState ( ) ) . asa . value as bigint
1390
1367
1391
- const method = appClient . getABIMethod ( 'hasAsset' ) . getSelector ( )
1392
-
1393
- const addressType = new ABIAddressType ( )
1394
- const aliceAddr = addressType . encode ( alice )
1395
-
1396
- await appClient . send . bare . call ( {
1397
- args : [ method , aliceAddr ] ,
1368
+ await appClient . send . call ( {
1369
+ method : 'hasAsset' ,
1370
+ args : [ alice ] ,
1398
1371
populateAppCallResources : false ,
1399
1372
accessReferences : [ { holding : { address : alice , assetId } } ] ,
1400
1373
} )
@@ -1406,13 +1379,9 @@ describe('access references', () => {
1406
1379
// Opt alice into the external app
1407
1380
await fixture . algorand . send . appCallMethodCall ( await externalClient . params . optIn ( { method : 'optInToApplication' , sender : alice } ) )
1408
1381
1409
- const method = appClient . getABIMethod ( 'externalLocal' ) . getSelector ( )
1410
-
1411
- const addressType = new ABIAddressType ( )
1412
- const aliceAddr = addressType . encode ( alice )
1413
-
1414
- await appClient . send . bare . call ( {
1415
- args : [ method , aliceAddr ] ,
1382
+ await appClient . send . call ( {
1383
+ method : 'externalLocal' ,
1384
+ args : [ alice ] ,
1416
1385
populateAppCallResources : false ,
1417
1386
accessReferences : [ { locals : { address : alice , appId : externalClient . appId } } ] ,
1418
1387
} )
0 commit comments