|
| 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 | +}) |
0 commit comments