Skip to content

Commit e98d0f5

Browse files
add same func
1 parent 083ac18 commit e98d0f5

7 files changed

Lines changed: 494 additions & 435 deletions

File tree

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
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+
})
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
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+
})

lib/ethereum/market-behavior/index.spec.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { ethers } from 'ethers'
22
import { createMarketBehaviorContract, CreateMarketBehaviorContract } from '.'
33
import { createGetIdCaller } from './getId'
4+
import { createGetMetricsCaller } from './getMetrics'
45
import { marketBehaviorAbi } from './abi'
56

67
jest.mock('./getId')
@@ -23,6 +24,7 @@ describe('getId/index.ts', () => {
2324
)
2425
return {
2526
getId: createGetIdCaller(contract),
27+
getMetrics: createGetMetricsCaller(contract),
2628
}
2729
}
2830

lib/ethereum/market-behavior/index.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,11 @@ import { Provider } from '@ethersproject/abstract-provider'
33
import { Signer } from '@ethersproject/abstract-signer'
44
import { marketBehaviorAbi } from './abi'
55
import { createGetIdCaller } from './getId'
6+
import { createGetMetricsCaller } from './getMetrics'
67

78
export 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
}

lib/l2/property-factory/index.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff 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

lib/l2/property-factory/index.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff 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

3533
export 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
}

0 commit comments

Comments
 (0)