11import { algorandFixture } from '@algorandfoundation/algokit-utils/testing'
2- import { AssetLabelingFactory } from '../smart_contracts/artifacts/asset_labeling/AssetLabelingClient'
3- import { Account } from 'algosdk'
2+ import {
3+ AssetLabelingClient ,
4+ AssetLabelingFactory ,
5+ } from '../smart_contracts/artifacts/asset_labeling/AssetLabelingClient'
6+ import { Account , Address , appendSignMultisigTransaction } from 'algosdk'
47import { Config } from '@algorandfoundation/algokit-utils'
58import { TransactionSignerAccount } from '@algorandfoundation/algokit-utils/types/account'
69import {
@@ -23,14 +26,17 @@ import {
2326// add_op nonexist label should fail
2427// remove_op nonexist label should fail
2528
29+ const config = {
30+ populateAppCallResources : true ,
31+ debug : false ,
32+ traceAll : false ,
33+ }
34+
2635describe ( 'asset labeling contract' , ( ) => {
2736 const localnet = algorandFixture ( )
37+
2838 beforeAll ( ( ) => {
29- Config . configure ( {
30- populateAppCallResources : true ,
31- debug : false ,
32- traceAll : false ,
33- } )
39+ Config . configure ( config )
3440 } )
3541 beforeEach ( localnet . newScope )
3642
@@ -44,33 +50,46 @@ describe('asset labeling contract', () => {
4450 return { adminClient : appClient }
4551 }
4652
47- test ( 'change admin' , async ( ) => {
48- const { testAccount : adminAccount } = localnet . context
49- const { adminClient } = await deploy ( adminAccount )
53+ describe ( 'change admin' , ( ) => {
54+ let adminClient : AssetLabelingClient
55+ let randoClient : AssetLabelingClient
56+ let adminAccount : Address & Account & TransactionSignerAccount
57+ let randoAccount : Address & Account & TransactionSignerAccount
5058
51- const id = 'wo'
52- const name = 'world'
59+ beforeAll ( async ( ) => {
60+ await localnet . newScope ( )
5361
54- const newAdmin = await localnet . context . generateAccount ( { initialFunds : ( 0 ) . algos ( ) } )
62+ adminAccount = localnet . context . testAccount
63+ adminClient = ( await deploy ( adminAccount ) ) . adminClient
5564
56- await adminClient . send . changeAdmin ( { args : { newAdmin : newAdmin . addr . toString ( ) } } )
57- const storedAdmin = await adminClient . state . global . admin ( )
65+ randoAccount = await localnet . context . generateAccount ( { initialFunds : ( 1 ) . algos ( ) } )
66+ randoClient = adminClient . clone ( {
67+ defaultSender : randoAccount ,
68+ defaultSigner : randoAccount . signer ,
69+ } )
70+ } )
5871
59- expect ( storedAdmin . asByteArray ( ) ) . toEqual ( newAdmin . addr . publicKey )
60- } )
61- test ( 'change admin should fail when not called by admin' , async ( ) => {
62- const { testAccount : adminAccount } = localnet . context
63- const { adminClient } = await deploy ( adminAccount )
72+ test ( 'should work' , async ( ) => {
73+ await adminClient . send . changeAdmin ( { args : { newAdmin : randoAccount . addr . toString ( ) } } )
74+ const storedAdmin = await adminClient . state . global . admin ( )
75+ expect ( storedAdmin . asByteArray ( ) ) . toEqual ( randoAccount . addr . publicKey )
6476
65- const rando = await localnet . context . generateAccount ( { initialFunds : ( 0.2 ) . algos ( ) } )
66- const randoClient = adminClient . clone ( {
67- defaultSender : rando ,
68- defaultSigner : rando . signer ,
77+ await randoClient . send . changeAdmin ( { args : { newAdmin : adminAccount . addr . toString ( ) } } )
78+ const revertedAdmin = await adminClient . state . global . admin ( )
79+ expect ( revertedAdmin . asByteArray ( ) ) . toEqual ( adminAccount . addr . publicKey )
6980 } )
7081
71- await expect ( ( ) => randoClient . send . changeAdmin ( { args : { newAdmin : rando . addr . toString ( ) } } ) ) . rejects . toThrow (
72- / E R R : U N A U T H / ,
73- )
82+ test ( 'change admin should fail when not called by admin' , async ( ) => {
83+ await expect ( ( ) =>
84+ randoClient . send . changeAdmin ( { args : { newAdmin : randoAccount . addr . toString ( ) } } ) ,
85+ ) . rejects . toThrow ( / E R R : U N A U T H / )
86+
87+ await adminClient . send . changeAdmin ( { args : { newAdmin : randoAccount . addr . toString ( ) } } )
88+
89+ await expect ( ( ) =>
90+ adminClient . send . changeAdmin ( { args : { newAdmin : randoAccount . addr . toString ( ) } } ) ,
91+ ) . rejects . toThrow ( / E R R : U N A U T H / )
92+ } )
7493 } )
7594
7695 test ( 'add label' , async ( ) => {
0 commit comments