Skip to content

Commit 8d7f095

Browse files
committed
test: update e2e-tests
1 parent 95bf157 commit 8d7f095

File tree

2 files changed

+14
-17
lines changed

2 files changed

+14
-17
lines changed

e2e/zombienet/src/hooks/useContractQuery.test.ts

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
import { beforeAll, describe, expect, it } from 'vitest';
22
import { ALICE, BOB, CHARLIE, deployPsp22Contract, psp22Metadata, wrapper } from '../utils';
33
import { numberToHex } from 'dedot/utils';
4-
import { renderHook, waitFor } from '@testing-library/react';
4+
import { render, renderHook, waitFor } from '@testing-library/react';
55
import { useContractQuery, useContractTx, useRawContract } from 'typink';
66
import { Contract } from 'dedot/contracts';
77
import { Psp22ContractApi } from 'contracts/psp22';
8+
import { AccountId32 } from 'dedot/codecs';
89

910
describe('useContractQuery', () => {
1011
let contractAddress: string, contract: Contract<Psp22ContractApi>;
@@ -29,23 +30,16 @@ describe('useContractQuery', () => {
2930
expect(totalSupply.current.isLoading).toEqual(false);
3031
});
3132

32-
totalSupply.current.refresh();
33-
34-
await waitFor(() => {
35-
expect(totalSupply.current.isRefreshing).toEqual(true);
36-
});
37-
38-
await waitFor(() => {
39-
expect(totalSupply.current.data).toEqual(BigInt(1e20));
40-
expect(totalSupply.current.isRefreshing).toEqual(false);
41-
});
42-
4333
const { result: balanceOf } = renderHook(
44-
() => useContractQuery({ contract, args: ['0x_FAKE_'], fn: 'psp22BalanceOf' }),
34+
({ address }) => useContractQuery({ contract, args: [address], fn: 'psp22BalanceOf' }),
4535
{
4636
wrapper,
37+
initialProps: {
38+
address: '0x__FAKE',
39+
},
4740
},
4841
);
42+
4943
await waitFor(() => {
5044
expect(balanceOf.current.error).toBeDefined();
5145
});

packages/typink/src/hooks/useContractQuery.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ type UseContractQueryReturnType<
1414
M extends keyof ContractQuery<T> = keyof ContractQuery<T>,
1515
> = {
1616
isLoading: boolean;
17-
refresh: () => void;
17+
refresh: () => Promise<void>;
1818
isRefreshing: boolean;
1919
error?: Error;
2020
} & Partial<Awaited<ReturnType<T['query'][M]>>>;
@@ -50,8 +50,8 @@ export function useContractQuery<
5050
} & Args<Pop<Parameters<T['query'][M]>>>,
5151
): UseContractQueryReturnType<T, M> {
5252
// TODO replace loading tracking state with tanstack
53-
54-
const { client } = useTypink();
53+
54+
const { client } = useTypink();
5555

5656
const [isLoading, setIsLoading] = useState<boolean>(true);
5757
const [isRefreshing, setIsRefreshing] = useState<boolean>(false);
@@ -101,11 +101,15 @@ export function useContractQuery<
101101
try {
102102
setIsRefreshing(true);
103103

104+
console.log('Refreshing query:', fn, args, options);
105+
104106
const result = await contract.query[fn](...args, options);
105107

106108
setResult(result);
107109
setError(undefined);
108110
setIsRefreshing(false);
111+
112+
console.log('[DONE]: Refreshing query: ', fn, args, options);
109113
} catch (error: any) {
110114
console.error('Error when refreshing the query:', error);
111115

@@ -151,4 +155,3 @@ export function useContractQuery<
151155
error,
152156
} as any;
153157
}
154-

0 commit comments

Comments
 (0)