1- import algosdk , { ABIAddressType , ABIMethod , ABIType , Account , Address } from 'algosdk'
1+ import algosdk , { ABIMethod , ABIType , Account , Address } from 'algosdk'
22import invariant from 'tiny-invariant'
33import { afterAll , beforeAll , beforeEach , describe , expect , test } from 'vitest'
44import { APP_SPEC as nestedContractAppSpec } from '../../tests/example-contracts/client/TestContractClient'
@@ -1181,7 +1181,6 @@ describe('abi return', () => {
11811181 } )
11821182} )
11831183
1184- // TODO: NC - Switch these tests to not use bare.send(...) once algosdk supports access references
11851184describe ( 'access references' , ( ) => {
11861185 const fixture = algorandFixture ( )
11871186 beforeEach ( fixture . newScope )
@@ -1251,52 +1250,38 @@ describe('access references', () => {
12511250 } , 20_000 ) // Account generation and funding can be slow
12521251
12531252 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+ } )
12621259 } )
12631260
12641261 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 ] ,
12721265 populateAppCallResources : false ,
12731266 accountReferences : [ alice , bob , charlie , dan , eve , frank , grace , heidi ] ,
12741267 } )
12751268 } )
12761269
12771270 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-
12831271 await expect (
1284- appClient . send . bare . call ( {
1285- args : [ method , aliceAddr ] ,
1272+ appClient . send . call ( {
1273+ method : 'addressBalance' ,
1274+ args : [ alice ] ,
12861275 populateAppCallResources : false ,
12871276 accountReferences : [ alice , bob , charlie , dan , eve , frank , grace , heidi , ivan ] ,
12881277 } ) ,
12891278 ) . rejects . toThrow ( / m a x n u m b e r o f a c c o u n t s i s 8 / )
12901279 } )
12911280
12921281 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 ] ,
13001285 populateAppCallResources : false ,
13011286 accessReferences : [
13021287 { address : alice } ,
@@ -1320,14 +1305,10 @@ describe('access references', () => {
13201305 } )
13211306
13221307 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-
13281308 await expect (
1329- appClient . send . bare . call ( {
1330- args : [ method , aliceAddr ] ,
1309+ appClient . send . call ( {
1310+ method : 'addressBalance' ,
1311+ args : [ alice ] ,
13311312 populateAppCallResources : false ,
13321313 accessReferences : [
13331314 { address : alice } ,
@@ -1353,32 +1334,28 @@ describe('access references', () => {
13531334 } )
13541335
13551336 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' ,
13601339 populateAppCallResources : false ,
13611340 accessReferences : [ { appId : externalClient . appId } ] ,
13621341 staticFee : microAlgo ( 2000 ) ,
13631342 } )
13641343 } )
13651344
13661345 test ( 'asset reference enables access' , async ( ) => {
1367- const method = appClient . getABIMethod ( 'assetTotal' ) . getSelector ( )
13681346 const assetId = ( await appClient . getGlobalState ( ) ) . asa . value as bigint
13691347
1370- await appClient . send . bare . call ( {
1371- args : [ method ] ,
1348+ await appClient . send . call ( {
1349+ method : 'assetTotal' ,
13721350 populateAppCallResources : false ,
13731351 accessReferences : [ { assetId } ] ,
13741352 } )
13751353 } )
13761354
13771355 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 : [ ] ,
13821359 populateAppCallResources : false ,
13831360 accessReferences : [ { box : { appId : appClient . appId , name : new Uint8Array ( [ 115 ] ) } } ] ,
13841361 } )
@@ -1388,13 +1365,9 @@ describe('access references', () => {
13881365 const alice = await fixture . context . generateAccount ( { initialFunds : AlgoAmount . Algo ( 0.1 ) } )
13891366 const assetId = ( await appClient . getGlobalState ( ) ) . asa . value as bigint
13901367
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 ] ,
13981371 populateAppCallResources : false ,
13991372 accessReferences : [ { holding : { address : alice , assetId } } ] ,
14001373 } )
@@ -1406,13 +1379,9 @@ describe('access references', () => {
14061379 // Opt alice into the external app
14071380 await fixture . algorand . send . appCallMethodCall ( await externalClient . params . optIn ( { method : 'optInToApplication' , sender : alice } ) )
14081381
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 ] ,
14161385 populateAppCallResources : false ,
14171386 accessReferences : [ { locals : { address : alice , appId : externalClient . appId } } ] ,
14181387 } )
0 commit comments