Skip to content

Commit d8c673b

Browse files
committed
missing files
1 parent 7270766 commit d8c673b

File tree

4 files changed

+138
-0
lines changed

4 files changed

+138
-0
lines changed
+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import { ZeroAddress } from 'ethers'
2+
import { createDescriptorOfCaller } from './descriptorOf'
3+
4+
describe('descriptorOf.spec.ts', () => {
5+
describe('createDescriptorOfCaller', () => {
6+
it('call success', async () => {
7+
const value = '0x74657374696e67'
8+
const propertyAddress = ZeroAddress
9+
10+
const devContract = {
11+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
12+
descriptorOf: jest.fn().mockImplementation(async () => value),
13+
}
14+
15+
const expected = value
16+
17+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
18+
const caller = createDescriptorOfCaller(devContract as any)
19+
20+
const result = await caller(propertyAddress)
21+
22+
expect(result).toEqual(expected)
23+
})
24+
25+
it('call failure', async () => {
26+
const propertyAddress = ZeroAddress
27+
const error = 'error'
28+
29+
const devContract = {
30+
descriptorOf: jest
31+
.fn()
32+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
33+
.mockImplementation(async () => Promise.reject(error)),
34+
}
35+
36+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
37+
const caller = createDescriptorOfCaller(devContract as any)
38+
39+
const result = await caller(propertyAddress).catch((err) => err)
40+
41+
expect(result).toEqual(error)
42+
})
43+
})
44+
})

lib/ethereum/s-tokens/descriptorOf.ts

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
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 CreateDescriptorOfCaller = (
6+
contract: ethers.Contract,
7+
) => (propertyAddress: string) => Promise<string>
8+
9+
export const createDescriptorOfCaller: CreateDescriptorOfCaller =
10+
(contract: ethers.Contract) =>
11+
async (propertyAddress: string): Promise<string> => {
12+
const res = execute<QueryOption>({
13+
contract,
14+
method: 'descriptorOf',
15+
args: [propertyAddress],
16+
mutation: false,
17+
})
18+
return res
19+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
import { ZeroAddress, keccak256, toUtf8Bytes, toUtf8String } from 'ethers'
2+
import { createDescriptorOfPropertyByPayloadCaller } from './descriptorOfPropertyByPayload'
3+
4+
describe('descriptorOfPropertyByPayload.spec.ts', () => {
5+
describe('createDescriptorOfPropertyByPayloadCaller', () => {
6+
it('call success', async () => {
7+
const value = '0x74657374696e67'
8+
const propertyAddress = ZeroAddress
9+
const payload = toUtf8Bytes('x')
10+
11+
const devContract = {
12+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
13+
descriptorOfPropertyByPayload: jest
14+
.fn()
15+
.mockImplementation(async () => value),
16+
}
17+
18+
const expected = value
19+
20+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
21+
const caller = createDescriptorOfPropertyByPayloadCaller(
22+
devContract as any,
23+
)
24+
25+
const result = await caller(propertyAddress, payload)
26+
27+
expect(result).toEqual(expected)
28+
})
29+
30+
it('call failure', async () => {
31+
const propertyAddress = ZeroAddress
32+
const payload = toUtf8Bytes('x')
33+
const error = 'error'
34+
35+
const devContract = {
36+
descriptorOfPropertyByPayload: jest
37+
.fn()
38+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
39+
.mockImplementation(async () => Promise.reject(error)),
40+
}
41+
42+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
43+
const caller = createDescriptorOfPropertyByPayloadCaller(
44+
devContract as any,
45+
)
46+
47+
const result = await caller(propertyAddress, payload).catch((err) => err)
48+
49+
expect(result).toEqual(error)
50+
})
51+
})
52+
})
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
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 CreateDescriptorOfPropertyByPayloadCaller = (
6+
contract: ethers.Contract,
7+
) => (propertyAddress: string, payload: string | Uint8Array) => Promise<string>
8+
9+
export const createDescriptorOfPropertyByPayloadCaller: CreateDescriptorOfPropertyByPayloadCaller =
10+
11+
(contract: ethers.Contract) =>
12+
async (
13+
propertyAddress: string,
14+
payload: string | Uint8Array,
15+
): Promise<string> => {
16+
const res = execute<QueryOption>({
17+
contract,
18+
method: 'descriptorOfPropertyByPayload',
19+
args: [propertyAddress, payload],
20+
mutation: false,
21+
})
22+
return res
23+
}

0 commit comments

Comments
 (0)