Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: dev-protocol/dev-kit-js
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v5.11.1
Choose a base ref
...
head repository: dev-protocol/dev-kit-js
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v5.11.2
Choose a head ref
  • 5 commits
  • 9 files changed
  • 2 contributors

Commits on Jan 26, 2022

  1. Copy the full SHA
    f31d73e View commit details

Commits on Jan 27, 2022

  1. Copy the full SHA
    083ac18 View commit details
  2. add same func

    Akira-Taniguchi committed Jan 27, 2022
    Copy the full SHA
    e98d0f5 View commit details
  3. Merge pull request #752 from dev-protocol/add-same-func

    add get metrics func
    Akira-Taniguchi authored Jan 27, 2022
    Copy the full SHA
    8fa0acc View commit details
  4. 5.11.2

    Akira-Taniguchi committed Jan 27, 2022
    Copy the full SHA
    1808390 View commit details
41 changes: 41 additions & 0 deletions lib/ethereum/market-behavior/getMetrics.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import { createGetMetricsCaller } from './getMetrics'

describe('getMetrics.spec.ts', () => {
describe('createGetMetricsCaller', () => {
it('call success', async () => {
const value = '0x12345..........'

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

const expected = value

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

const result = await caller('hogehoge/hugahuga')

expect(result).toEqual(expected)
})

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

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

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

const result = await caller('hogehoge/hugahuga').catch((err) => err)

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

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

export const createGetMetricsCaller: CreateGetMetricsCaller =
(contract: ethers.Contract) => (id: string) =>
execute<QueryOption>({
contract,
method: 'getMetrics',
args: [id],
mutation: false,
})
2 changes: 2 additions & 0 deletions lib/ethereum/market-behavior/index.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { ethers } from 'ethers'
import { createMarketBehaviorContract, CreateMarketBehaviorContract } from '.'
import { createGetIdCaller } from './getId'
import { createGetMetricsCaller } from './getMetrics'
import { marketBehaviorAbi } from './abi'

jest.mock('./getId')
@@ -23,6 +24,7 @@ describe('getId/index.ts', () => {
)
return {
getId: createGetIdCaller(contract),
getMetrics: createGetMetricsCaller(contract),
}
}

3 changes: 3 additions & 0 deletions lib/ethereum/market-behavior/index.ts
Original file line number Diff line number Diff line change
@@ -3,9 +3,11 @@ import { Provider } from '@ethersproject/abstract-provider'
import { Signer } from '@ethersproject/abstract-signer'
import { marketBehaviorAbi } from './abi'
import { createGetIdCaller } from './getId'
import { createGetMetricsCaller } from './getMetrics'

export type CreateMarketBehaviorContract = {
readonly getId: (metricsAddress: string) => Promise<string>
readonly getMetrics: (id: string) => Promise<string>
}

// eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
@@ -20,5 +22,6 @@ export const createMarketBehaviorContract =

return {
getId: createGetIdCaller(contract),
getMetrics: createGetMetricsCaller(contract),
}
}
2 changes: 1 addition & 1 deletion lib/l2/property-factory/index.spec.ts
Original file line number Diff line number Diff line change
@@ -39,7 +39,7 @@ describe('property-factory/index.ts', () => {
contract,
provider
),
getPropertiesOfAuthor: createGetPropertiesOfAuthorCaller(contract)
getPropertiesOfAuthor: createGetPropertiesOfAuthorCaller(contract),
}
}

6 changes: 2 additions & 4 deletions lib/l2/property-factory/index.ts
Original file line number Diff line number Diff line change
@@ -27,9 +27,7 @@ export type PropertyFactoryContract = {
readonly transaction: TransactionResponse
readonly waitForAuthentication: () => Promise<string>
}>
readonly getPropertiesOfAuthor: (
author: string
) => Promise<readonly string[]>
readonly getPropertiesOfAuthor: (author: string) => Promise<readonly string[]>
}

export const createPropertyFactoryContract =
@@ -47,6 +45,6 @@ export const createPropertyFactoryContract =
contract,
provider as Provider
),
getPropertiesOfAuthor: createGetPropertiesOfAuthorCaller(contract)
getPropertiesOfAuthor: createGetPropertiesOfAuthorCaller(contract),
}
}
Loading