Skip to content

Commit b0b5cf2

Browse files
add new function
1 parent 967b8d5 commit b0b5cf2

6 files changed

Lines changed: 101 additions & 4 deletions

File tree

lib/l2/property-factory/abi.ts

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,4 +126,36 @@ export const propertyFactoryAbi = [
126126
stateMutability: 'nonpayable',
127127
type: 'function',
128128
},
129+
{
130+
inputs: [
131+
{
132+
internalType: 'address',
133+
name: '_author',
134+
type: 'address',
135+
},
136+
],
137+
name: 'getPropertiesOfAuthor',
138+
outputs: [
139+
{
140+
internalType: 'address[]',
141+
name: '',
142+
type: 'address[]',
143+
},
144+
],
145+
stateMutability: 'view',
146+
type: 'function',
147+
},
148+
{
149+
inputs: [
150+
{
151+
internalType: 'address',
152+
name: '_property',
153+
type: 'address',
154+
},
155+
],
156+
name: 'setPropertyAddress',
157+
outputs: [],
158+
stateMutability: 'nonpayable',
159+
type: 'function',
160+
},
129161
]

lib/l2/property-factory/createAndAuthenticate.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,7 @@ import { Provider } from '@ethersproject/abstract-provider'
66
import { TransactionResponse } from '@ethersproject/abstract-provider'
77
import { execute, FallbackableOverrides } from '../../common/utils/execute'
88
import { ethers } from 'ethers'
9-
import {
10-
getMetricsProperty,
11-
WaitForEventOptions,
12-
} from '../../ethereum/market/authenticate'
9+
import { WaitForEventOptions } from '../../ethereum/market/authenticate'
1310
import { metricsFactoryAbi } from '../metrics-factory/abi'
1411

1512
export type CreateCreateAndAuthenticateCaller = (
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import { createGetPropertiesOfAuthorCaller } from './getPropertiesOfAuthor'
2+
3+
describe('getPropertiesOfAuthor.spec.ts', () => {
4+
describe('createGetPropertiesOfAuthorrCaller', () => {
5+
it('call success', async () => {
6+
const value = ['0x1', '0x2', '0x3', '0x4', '0x5', '0x6']
7+
8+
const contract = {
9+
getPropertiesOfAuthor: jest
10+
.fn()
11+
.mockImplementation(async () => Promise.resolve(value)),
12+
}
13+
14+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
15+
const caller = createGetPropertiesOfAuthorCaller(contract as any)
16+
17+
const result = await caller('0xAddress')
18+
19+
expect(result).toEqual(value)
20+
})
21+
22+
it('call failure', async () => {
23+
const error = 'error'
24+
25+
const contract = {
26+
getPropertiesOfAuthor: jest
27+
.fn()
28+
.mockImplementation(async () => Promise.reject(error)),
29+
}
30+
31+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
32+
const caller = createGetPropertiesOfAuthorCaller(contract as any)
33+
34+
const result = await caller('0xAddress').catch((err) => err)
35+
36+
expect(result).toEqual(error)
37+
})
38+
})
39+
})
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/* eslint-disable @typescript-eslint/prefer-readonly-parameter-types */
2+
import { ethers } from 'ethers'
3+
import { execute, QueryOption } from '../../common/utils/execute'
4+
5+
export type CreateGetPropertiesOfAuthorCaller = (
6+
contract: ethers.Contract
7+
) => (authorAddress: string) => Promise<readonly string[]>
8+
9+
export const createGetPropertiesOfAuthorCaller: CreateGetPropertiesOfAuthorCaller =
10+
(contract: ethers.Contract) => async (authorAddress: string) => {
11+
const res = await execute<QueryOption, readonly string[]>({
12+
contract,
13+
method: 'getPropertiesOfAuthor',
14+
args: [authorAddress],
15+
mutation: false,
16+
})
17+
return res
18+
}

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,11 @@ import { createPropertyFactoryContract, PropertyFactoryContract } from '.'
33
import { propertyFactoryAbi } from './abi'
44
import { createCreatePropertyCaller } from '../../ethereum/property-factory/create'
55
import { createCreateAndAuthenticateCaller } from './createAndAuthenticate'
6+
import { createGetPropertiesOfAuthorCaller } from './getPropertiesOfAuthor'
67

78
jest.mock('../../ethereum/property-factory/create')
89
jest.mock('./createAndAuthenticate')
10+
jest.mock('./getPropertiesOfAuthor')
911

1012
describe('property-factory/index.ts', () => {
1113
;(createCreatePropertyCaller as jest.Mock).mockImplementation(
@@ -14,6 +16,9 @@ describe('property-factory/index.ts', () => {
1416
;(createCreateAndAuthenticateCaller as jest.Mock).mockImplementation(
1517
(contract) => contract
1618
)
19+
;(createGetPropertiesOfAuthorCaller as jest.Mock).mockImplementation(
20+
(contract) => contract
21+
)
1722
describe('createPropertyFactoryContract', () => {
1823
it('check return object', () => {
1924
const host = 'localhost'
@@ -34,6 +39,7 @@ describe('property-factory/index.ts', () => {
3439
contract,
3540
provider
3641
),
42+
getPropertiesOfAuthor: createGetPropertiesOfAuthorCaller(contract)
3743
}
3844
}
3945

lib/l2/property-factory/index.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { propertyFactoryAbi } from './abi'
55
import { createCreatePropertyCaller } from '../../ethereum/property-factory/create'
66
import { WaitForEventOptions } from '../../ethereum/market/authenticate'
77
import { createCreateAndAuthenticateCaller } from './createAndAuthenticate'
8+
import { createGetPropertiesOfAuthorCaller } from './getPropertiesOfAuthor'
89
import { FallbackableOverrides } from '../../common/utils/execute'
910

1011
export type PropertyFactoryContract = {
@@ -26,6 +27,9 @@ export type PropertyFactoryContract = {
2627
readonly transaction: TransactionResponse
2728
readonly waitForAuthentication: () => Promise<string>
2829
}>
30+
readonly getPropertiesOfAuthor: (
31+
author: string
32+
) => Promise<readonly string[]>
2933
}
3034

3135
export const createPropertyFactoryContract =
@@ -43,5 +47,6 @@ export const createPropertyFactoryContract =
4347
contract,
4448
provider as Provider
4549
),
50+
getPropertiesOfAuthor: createGetPropertiesOfAuthorCaller(contract)
4651
}
4752
}

0 commit comments

Comments
 (0)