File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ import { createGetMetricsCaller } from './getMetrics'
2+
3+ describe ( 'getMetrics.spec.ts' , ( ) => {
4+ describe ( 'createGetMetricsCaller' , ( ) => {
5+ it ( 'call success' , async ( ) => {
6+ const value = '0x12345..........'
7+
8+ const contract = {
9+ getMetrics : jest
10+ . fn ( )
11+ . mockImplementation ( async ( ) => Promise . resolve ( value ) ) ,
12+ }
13+
14+ const expected = value
15+
16+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
17+ const caller = createGetMetricsCaller ( contract as any )
18+
19+ const result = await caller ( 'hogehoge/hugahuga' )
20+
21+ expect ( result ) . toEqual ( expected )
22+ } )
23+
24+ it ( 'call failure' , async ( ) => {
25+ const error = 'error'
26+
27+ const contract = {
28+ getMetrics : jest
29+ . fn ( )
30+ . mockImplementation ( async ( ) => Promise . reject ( error ) ) ,
31+ }
32+
33+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
34+ const caller = createGetMetricsCaller ( contract as any )
35+
36+ const result = await caller ( 'hogehoge/hugahuga' ) . catch ( ( err ) => err )
37+
38+ expect ( result ) . toEqual ( error )
39+ } )
40+ } )
41+ } )
Original file line number Diff line number Diff line change 1+ import { ethers } from 'ethers'
2+ import { execute , QueryOption } from '../../common/utils/execute'
3+
4+ export type CreateGetMetricsCaller = (
5+ contract : ethers . Contract
6+ ) => ( id : string ) => Promise < string >
7+
8+ export const createGetMetricsCaller : CreateGetMetricsCaller =
9+ ( contract : ethers . Contract ) => ( id : string ) =>
10+ execute < QueryOption > ( {
11+ contract,
12+ method : 'getMetrics' ,
13+ args : [ id ] ,
14+ mutation : false ,
15+ } )
Original file line number Diff line number Diff line change 11import { ethers } from 'ethers'
22import { createMarketBehaviorContract , CreateMarketBehaviorContract } from '.'
33import { createGetIdCaller } from './getId'
4+ import { createGetMetricsCaller } from './getMetrics'
45import { marketBehaviorAbi } from './abi'
56
67jest . mock ( './getId' )
@@ -23,6 +24,7 @@ describe('getId/index.ts', () => {
2324 )
2425 return {
2526 getId : createGetIdCaller ( contract ) ,
27+ getMetrics : createGetMetricsCaller ( contract ) ,
2628 }
2729 }
2830
Original file line number Diff line number Diff line change @@ -3,9 +3,11 @@ import { Provider } from '@ethersproject/abstract-provider'
33import { Signer } from '@ethersproject/abstract-signer'
44import { marketBehaviorAbi } from './abi'
55import { createGetIdCaller } from './getId'
6+ import { createGetMetricsCaller } from './getMetrics'
67
78export type CreateMarketBehaviorContract = {
89 readonly getId : ( metricsAddress : string ) => Promise < string >
10+ readonly getMetrics : ( id : string ) => Promise < string >
911}
1012
1113// eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
@@ -20,5 +22,6 @@ export const createMarketBehaviorContract =
2022
2123 return {
2224 getId : createGetIdCaller ( contract ) ,
25+ getMetrics : createGetMetricsCaller ( contract ) ,
2326 }
2427 }
Original file line number Diff line number Diff line change @@ -39,7 +39,7 @@ describe('property-factory/index.ts', () => {
3939 contract ,
4040 provider
4141 ) ,
42- getPropertiesOfAuthor : createGetPropertiesOfAuthorCaller ( contract )
42+ getPropertiesOfAuthor : createGetPropertiesOfAuthorCaller ( contract ) ,
4343 }
4444 }
4545
Original file line number Diff line number Diff line change @@ -27,9 +27,7 @@ export type PropertyFactoryContract = {
2727 readonly transaction : TransactionResponse
2828 readonly waitForAuthentication : ( ) => Promise < string >
2929 } >
30- readonly getPropertiesOfAuthor : (
31- author : string
32- ) => Promise < readonly string [ ] >
30+ readonly getPropertiesOfAuthor : ( author : string ) => Promise < readonly string [ ] >
3331}
3432
3533export const createPropertyFactoryContract =
@@ -47,6 +45,6 @@ export const createPropertyFactoryContract =
4745 contract ,
4846 provider as Provider
4947 ) ,
50- getPropertiesOfAuthor : createGetPropertiesOfAuthorCaller ( contract )
48+ getPropertiesOfAuthor : createGetPropertiesOfAuthorCaller ( contract ) ,
5149 }
5250 }
You can’t perform that action at this time.
0 commit comments