11import { beforeAll , describe , expect , it } from 'vitest' ;
2- import { ALICE , deployPsp22Contract , psp22Metadata } from '../utils' ;
2+ import { ALICE , deployPsp22Contract , psp22Metadata , wrapper } from '../utils' ;
33import { numberToHex } from 'dedot/utils' ;
44import { Contract } from 'dedot/contracts' ;
55import { Psp22ContractApi } from '../contracts/psp22' ;
6+ import { renderHook , waitFor } from '@testing-library/react' ;
7+ import { usePSP22Balance } from 'typink' ;
68
79describe ( 'useContract2' , ( ) => {
810 let contract : Contract < Psp22ContractApi > ;
@@ -26,4 +28,19 @@ describe('useContract2', () => {
2628 console . log ( `alice balance` , state ) ;
2729 expect ( state ) . toBeDefined ( ) ;
2830 } ) ;
31+
32+ it ( 'should load balance properly' , async ( ) => {
33+ const { result } = renderHook (
34+ ( ) => usePSP22Balance ( { contractAddress : contract . address . address ( ) , address : ALICE } ) , // prettier-end-here
35+ { wrapper } ,
36+ ) ;
37+
38+ expect ( result . current . data ) . toBeUndefined ( ) ;
39+
40+ await waitFor ( ( ) => {
41+ expect ( result . current . data ) . toBeDefined ( ) ;
42+ } ) ;
43+
44+ expect ( result . current . data ) . toBeGreaterThan ( 0n ) ;
45+ } ) ;
2946} ) ;
0 commit comments