Skip to content

Commit 6d29a4c

Browse files
add name func to market contract
1 parent 1808390 commit 6d29a4c

4 files changed

Lines changed: 62 additions & 1 deletion

File tree

lib/l2/market/index.spec.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,15 @@ import { createMarketContract, MarketContract } from '.'
33
import { createSchemaCaller } from '../../ethereum/market/schema'
44
import { createVoteCaller } from '../../ethereum/market/vote'
55
import { createAuthenticateCaller } from './authenticate'
6+
import { createNameCaller } from './name'
67
import { createBehaviorCaller } from '../../ethereum/market/behavior'
78
import { createGetAuthenticatedPropertiesCaller } from './getAuthenticatedProperties'
89
import { marketAbi } from './abi'
910

1011
jest.mock('../../ethereum/market/schema')
1112
jest.mock('../../ethereum/market/vote')
1213
jest.mock('./authenticate')
14+
jest.mock('./name')
1315
jest.mock('../../ethereum/market/behavior')
1416
jest.mock('./getAuthenticatedProperties')
1517

@@ -25,7 +27,9 @@ describe('market/index.ts', () => {
2527
;(createGetAuthenticatedPropertiesCaller as jest.Mock).mockImplementation(
2628
(contract) => contract
2729
)
28-
30+
;(createNameCaller as jest.Mock).mockImplementation(
31+
(contract) => contract
32+
)
2933
describe('createMarketContract', () => {
3034
it('check return object', () => {
3135
const host = 'localhost'
@@ -41,6 +45,7 @@ describe('market/index.ts', () => {
4145
schema: createSchemaCaller(contract),
4246
authenticate: createAuthenticateCaller(contract, provider),
4347
behavior: createBehaviorCaller(contract),
48+
name: createNameCaller(contract),
4449
getAuthenticatedProperties:
4550
createGetAuthenticatedPropertiesCaller(contract),
4651
}

lib/l2/market/index.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { marketAbi } from './abi'
66
import { createSchemaCaller } from '../../ethereum/market/schema'
77
import { createVoteCaller } from '../../ethereum/market/vote'
88
import { createAuthenticateCaller } from './authenticate'
9+
import { createNameCaller } from './name'
910
import { createBehaviorCaller } from '../../ethereum/market/behavior'
1011
import { createGetAuthenticatedPropertiesCaller } from './getAuthenticatedProperties'
1112
import { FallbackableOverrides } from '../../common/utils/execute'
@@ -26,6 +27,7 @@ export type MarketContract = {
2627
overrides?: FallbackableOverrides
2728
) => Promise<string>
2829
readonly behavior: () => Promise<string>
30+
readonly name: () => Promise<string>
2931
readonly getAuthenticatedProperties: () => Promise<readonly string[]>
3032
}
3133

@@ -38,6 +40,7 @@ export const createMarketContract =
3840
schema: createSchemaCaller(contract),
3941
authenticate: createAuthenticateCaller(contract, provider),
4042
behavior: createBehaviorCaller(contract),
43+
name: createNameCaller(contract),
4144
getAuthenticatedProperties:
4245
createGetAuthenticatedPropertiesCaller(contract),
4346
}

lib/l2/market/name.spec.ts

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import { createNameCaller } from './name'
2+
3+
describe('name.spec.ts', () => {
4+
describe('createNameCaller', () => {
5+
it('call success', async () => {
6+
const value = 'value'
7+
8+
const contract = {
9+
name: jest.fn().mockImplementation(async () => Promise.resolve(value)),
10+
}
11+
12+
const expected = value
13+
14+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
15+
const caller = createNameCaller(contract as any)
16+
17+
const result = await caller()
18+
19+
expect(result).toEqual(expected)
20+
})
21+
22+
it('call failure', async () => {
23+
const error = 'error'
24+
25+
const contract = {
26+
name: jest.fn().mockImplementation(async () => Promise.reject(error)),
27+
}
28+
29+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
30+
const caller = createNameCaller(contract as any)
31+
32+
const result = await caller().catch((err) => err)
33+
34+
expect(result).toEqual(error)
35+
})
36+
})
37+
})

lib/l2/market/name.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import { ethers } from 'ethers'
2+
import { execute, QueryOption } from '../../common/utils/execute'
3+
import { always } from 'ramda'
4+
5+
export type CreateNameCaller = (
6+
contract: ethers.Contract
7+
) => () => Promise<string>
8+
9+
export const createNameCaller: CreateNameCaller = (contract: ethers.Contract) =>
10+
always(
11+
execute<QueryOption>({
12+
contract,
13+
method: 'name',
14+
mutation: false,
15+
})
16+
)

0 commit comments

Comments
 (0)