Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion lib/l2/market/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@ import { createMarketContract, MarketContract } from '.'
import { createSchemaCaller } from '../../ethereum/market/schema'
import { createVoteCaller } from '../../ethereum/market/vote'
import { createAuthenticateCaller } from './authenticate'
import { createNameCaller } from './name'
import { createBehaviorCaller } from '../../ethereum/market/behavior'
import { createGetAuthenticatedPropertiesCaller } from './getAuthenticatedProperties'
import { marketAbi } from './abi'

jest.mock('../../ethereum/market/schema')
jest.mock('../../ethereum/market/vote')
jest.mock('./authenticate')
jest.mock('./name')
jest.mock('../../ethereum/market/behavior')
jest.mock('./getAuthenticatedProperties')

Expand All @@ -25,7 +27,9 @@ describe('market/index.ts', () => {
;(createGetAuthenticatedPropertiesCaller as jest.Mock).mockImplementation(
(contract) => contract
)

;(createNameCaller as jest.Mock).mockImplementation(
(contract) => contract
)
describe('createMarketContract', () => {
it('check return object', () => {
const host = 'localhost'
Expand All @@ -41,6 +45,7 @@ describe('market/index.ts', () => {
schema: createSchemaCaller(contract),
authenticate: createAuthenticateCaller(contract, provider),
behavior: createBehaviorCaller(contract),
name: createNameCaller(contract),
getAuthenticatedProperties:
createGetAuthenticatedPropertiesCaller(contract),
}
Expand Down
3 changes: 3 additions & 0 deletions lib/l2/market/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { marketAbi } from './abi'
import { createSchemaCaller } from '../../ethereum/market/schema'
import { createVoteCaller } from '../../ethereum/market/vote'
import { createAuthenticateCaller } from './authenticate'
import { createNameCaller } from './name'
import { createBehaviorCaller } from '../../ethereum/market/behavior'
import { createGetAuthenticatedPropertiesCaller } from './getAuthenticatedProperties'
import { FallbackableOverrides } from '../../common/utils/execute'
Expand All @@ -26,6 +27,7 @@ export type MarketContract = {
overrides?: FallbackableOverrides
) => Promise<string>
readonly behavior: () => Promise<string>
readonly name: () => Promise<string>
readonly getAuthenticatedProperties: () => Promise<readonly string[]>
}

Expand All @@ -38,6 +40,7 @@ export const createMarketContract =
schema: createSchemaCaller(contract),
authenticate: createAuthenticateCaller(contract, provider),
behavior: createBehaviorCaller(contract),
name: createNameCaller(contract),
getAuthenticatedProperties:
createGetAuthenticatedPropertiesCaller(contract),
}
Expand Down
37 changes: 37 additions & 0 deletions lib/l2/market/name.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { createNameCaller } from './name'

describe('name.spec.ts', () => {
describe('createNameCaller', () => {
it('call success', async () => {
const value = 'value'

const contract = {
name: jest.fn().mockImplementation(async () => Promise.resolve(value)),
}

const expected = value

// eslint-disable-next-line @typescript-eslint/no-explicit-any
const caller = createNameCaller(contract as any)

const result = await caller()

expect(result).toEqual(expected)
})

it('call failure', async () => {
const error = 'error'

const contract = {
name: jest.fn().mockImplementation(async () => Promise.reject(error)),
}

// eslint-disable-next-line @typescript-eslint/no-explicit-any
const caller = createNameCaller(contract as any)

const result = await caller().catch((err) => err)

expect(result).toEqual(error)
})
})
})
16 changes: 16 additions & 0 deletions lib/l2/market/name.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { ethers } from 'ethers'
import { execute, QueryOption } from '../../common/utils/execute'
import { always } from 'ramda'

export type CreateNameCaller = (
contract: ethers.Contract
) => () => Promise<string>

export const createNameCaller: CreateNameCaller = (contract: ethers.Contract) =>
always(
execute<QueryOption>({
contract,
method: 'name',
mutation: false,
})
)