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'
@@ -1161,7 +1161,6 @@ describe('abi return', () => {
11611161 } )
11621162} )
11631163
1164- // TODO: NC - Switch these tests to not use bare.send(...) once algosdk supports access references
11651164describe ( 'access references' , ( ) => {
11661165 const fixture = algorandFixture ( )
11671166 beforeEach ( fixture . newScope )
@@ -1231,52 +1230,38 @@ describe('access references', () => {
12311230 } , 20_000 ) // Account generation and funding can be slow
12321231
12331232 test ( 'address reference enables access' , async ( ) => {
1234- const alice = await fixture . context . generateAccount ( { initialFunds : AlgoAmount . Algo ( 0.1 ) } )
1235-
1236- const method = appClient . getABIMethod ( 'addressBalance' ) . getSelector ( )
1237-
1238- const addressType = new ABIAddressType ( )
1239- const aliceAddr = addressType . encode ( alice )
1240-
1241- await appClient . send . bare . call ( { args : [ method , aliceAddr ] , populateAppCallResources : false , accessReferences : [ { address : alice } ] } )
1233+ await appClient . send . call ( {
1234+ method : 'addressBalance' ,
1235+ args : [ alice ] ,
1236+ populateAppCallResources : false ,
1237+ accessReferences : [ { address : alice } ] ,
1238+ } )
12421239 } )
12431240
12441241 test ( 'up to 8 non access reference accounts can be used' , async ( ) => {
1245- const method = appClient . getABIMethod ( 'addressBalance' ) . getSelector ( )
1246-
1247- const addressType = new ABIAddressType ( )
1248- const aliceAddr = addressType . encode ( alice )
1249-
1250- await appClient . send . bare . call ( {
1251- args : [ method , aliceAddr ] ,
1242+ await appClient . send . call ( {
1243+ method : 'addressBalance' ,
1244+ args : [ alice ] ,
12521245 populateAppCallResources : false ,
12531246 accountReferences : [ alice , bob , charlie , dan , eve , frank , grace , heidi ] ,
12541247 } )
12551248 } )
12561249
12571250 test ( 'throws when more than 8 non access reference accounts are supplied' , async ( ) => {
1258- const method = appClient . getABIMethod ( 'addressBalance' ) . getSelector ( )
1259-
1260- const addressType = new ABIAddressType ( )
1261- const aliceAddr = addressType . encode ( alice )
1262-
12631251 await expect (
1264- appClient . send . bare . call ( {
1265- args : [ method , aliceAddr ] ,
1252+ appClient . send . call ( {
1253+ method : 'addressBalance' ,
1254+ args : [ alice ] ,
12661255 populateAppCallResources : false ,
12671256 accountReferences : [ alice , bob , charlie , dan , eve , frank , grace , heidi , ivan ] ,
12681257 } ) ,
12691258 ) . rejects . toThrow ( / m a x n u m b e r o f a c c o u n t s i s 8 / )
12701259 } )
12711260
12721261 test ( 'up to 16 access addresses can be used' , async ( ) => {
1273- const method = appClient . getABIMethod ( 'addressBalance' ) . getSelector ( )
1274-
1275- const addressType = new ABIAddressType ( )
1276- const aliceAddr = addressType . encode ( alice )
1277-
1278- await appClient . send . bare . call ( {
1279- args : [ method , aliceAddr ] ,
1262+ await appClient . send . call ( {
1263+ method : 'addressBalance' ,
1264+ args : [ alice ] ,
12801265 populateAppCallResources : false ,
12811266 accessReferences : [
12821267 { address : alice } ,
@@ -1300,14 +1285,10 @@ describe('access references', () => {
13001285 } )
13011286
13021287 test ( 'throws when more than 16 access addresses are supplied' , async ( ) => {
1303- const method = appClient . getABIMethod ( 'addressBalance' ) . getSelector ( )
1304-
1305- const addressType = new ABIAddressType ( )
1306- const aliceAddr = addressType . encode ( alice )
1307-
13081288 await expect (
1309- appClient . send . bare . call ( {
1310- args : [ method , aliceAddr ] ,
1289+ appClient . send . call ( {
1290+ method : 'addressBalance' ,
1291+ args : [ alice ] ,
13111292 populateAppCallResources : false ,
13121293 accessReferences : [
13131294 { address : alice } ,
@@ -1333,32 +1314,28 @@ describe('access references', () => {
13331314 } )
13341315
13351316 test ( 'app reference enables access' , async ( ) => {
1336- const method = appClient . getABIMethod ( 'externalAppCall' ) . getSelector ( )
1337-
1338- await appClient . send . bare . call ( {
1339- args : [ method ] ,
1317+ await appClient . send . call ( {
1318+ method : 'externalAppCall' ,
13401319 populateAppCallResources : false ,
13411320 accessReferences : [ { appId : externalClient . appId } ] ,
13421321 staticFee : microAlgo ( 2000 ) ,
13431322 } )
13441323 } )
13451324
13461325 test ( 'asset reference enables access' , async ( ) => {
1347- const method = appClient . getABIMethod ( 'assetTotal' ) . getSelector ( )
13481326 const assetId = ( await appClient . getGlobalState ( ) ) . asa . value as bigint
13491327
1350- await appClient . send . bare . call ( {
1351- args : [ method ] ,
1328+ await appClient . send . call ( {
1329+ method : 'assetTotal' ,
13521330 populateAppCallResources : false ,
13531331 accessReferences : [ { assetId } ] ,
13541332 } )
13551333 } )
13561334
13571335 test ( 'box reference enables access' , async ( ) => {
1358- const method = appClient . getABIMethod ( 'smallBox' ) . getSelector ( )
1359-
1360- await appClient . send . bare . call ( {
1361- args : [ method ] ,
1336+ await appClient . send . call ( {
1337+ method : 'smallBox' ,
1338+ args : [ ] ,
13621339 populateAppCallResources : false ,
13631340 accessReferences : [ { box : { appId : appClient . appId , name : new Uint8Array ( [ 115 ] ) } } ] ,
13641341 } )
@@ -1368,13 +1345,9 @@ describe('access references', () => {
13681345 const alice = await fixture . context . generateAccount ( { initialFunds : AlgoAmount . Algo ( 0.1 ) } )
13691346 const assetId = ( await appClient . getGlobalState ( ) ) . asa . value as bigint
13701347
1371- const method = appClient . getABIMethod ( 'hasAsset' ) . getSelector ( )
1372-
1373- const addressType = new ABIAddressType ( )
1374- const aliceAddr = addressType . encode ( alice )
1375-
1376- await appClient . send . bare . call ( {
1377- args : [ method , aliceAddr ] ,
1348+ await appClient . send . call ( {
1349+ method : 'hasAsset' ,
1350+ args : [ alice ] ,
13781351 populateAppCallResources : false ,
13791352 accessReferences : [ { holding : { address : alice , assetId } } ] ,
13801353 } )
@@ -1386,13 +1359,9 @@ describe('access references', () => {
13861359 // Opt alice into the external app
13871360 await fixture . algorand . send . appCallMethodCall ( await externalClient . params . optIn ( { method : 'optInToApplication' , sender : alice } ) )
13881361
1389- const method = appClient . getABIMethod ( 'externalLocal' ) . getSelector ( )
1390-
1391- const addressType = new ABIAddressType ( )
1392- const aliceAddr = addressType . encode ( alice )
1393-
1394- await appClient . send . bare . call ( {
1395- args : [ method , aliceAddr ] ,
1362+ await appClient . send . call ( {
1363+ method : 'externalLocal' ,
1364+ args : [ alice ] ,
13961365 populateAppCallResources : false ,
13971366 accessReferences : [ { locals : { address : alice , appId : externalClient . appId } } ] ,
13981367 } )
0 commit comments