@portal-hq/web 3.4.2-beta.2 → 3.4.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/commonjs/index.js +2 -0
- package/lib/commonjs/integrations/yield/index.js +16 -0
- package/lib/commonjs/integrations/yield/yieldxyz.js +115 -0
- package/lib/commonjs/integrations/yield/yieldxyz.test.js +154 -0
- package/lib/commonjs/mpc/index.js +122 -1
- package/lib/commonjs/mpc/index.test.js +539 -0
- package/lib/esm/index.js +2 -0
- package/lib/esm/integrations/yield/index.js +10 -0
- package/lib/esm/integrations/yield/yieldxyz.js +112 -0
- package/lib/esm/integrations/yield/yieldxyz.test.js +149 -0
- package/lib/esm/mpc/index.js +122 -1
- package/lib/esm/mpc/index.test.js +540 -1
- package/package.json +2 -3
- package/src/__mocks/constants.ts +319 -0
- package/src/index.ts +25 -2
- package/src/integrations/yield/index.ts +14 -0
- package/src/integrations/yield/yieldxyz.test.ts +220 -0
- package/src/integrations/yield/yieldxyz.ts +122 -0
- package/src/mpc/index.test.ts +645 -0
- package/src/mpc/index.ts +170 -5
- package/tsconfig.json +1 -1
- package/types.d.ts +1 -1
package/src/mpc/index.test.ts
CHANGED
|
@@ -26,6 +26,21 @@ import {
|
|
|
26
26
|
mockSimulationResult,
|
|
27
27
|
mockTransactionToEvaluate,
|
|
28
28
|
mockTransactionToSimulate,
|
|
29
|
+
mockYieldXyzGetYieldsRequest,
|
|
30
|
+
mockYieldXyzGetYieldsResponse,
|
|
31
|
+
mockYieldXyzEnterRequest,
|
|
32
|
+
mockYieldXyzEnterResponse,
|
|
33
|
+
mockYieldXyzExitRequest,
|
|
34
|
+
mockYieldXyzExitResponse,
|
|
35
|
+
mockYieldXyzGetBalancesRequest,
|
|
36
|
+
mockYieldXyzGetBalancesResponse,
|
|
37
|
+
mockYieldXyzGetHistoricalActionsRequest,
|
|
38
|
+
mockYieldXyzGetHistoricalActionsResponse,
|
|
39
|
+
mockYieldXyzManageYieldRequest,
|
|
40
|
+
mockYieldXyzManageYieldResponse,
|
|
41
|
+
mockYieldXyzTrackTransactionRequest,
|
|
42
|
+
mockYieldXyzTrackTransactionResponse,
|
|
43
|
+
mockYieldXyzGetTransactionResponse,
|
|
29
44
|
} from '../__mocks/constants'
|
|
30
45
|
import portalMock from '../__mocks/portal/portal'
|
|
31
46
|
import { PortalMpcError } from './errors'
|
|
@@ -243,6 +258,28 @@ describe('Mpc', () => {
|
|
|
243
258
|
done()
|
|
244
259
|
})
|
|
245
260
|
})
|
|
261
|
+
|
|
262
|
+
it('should error out if backupMethod is invalid', (done) => {
|
|
263
|
+
mpc
|
|
264
|
+
.backup({
|
|
265
|
+
backupMethod: 'INVALID_METHOD' as any,
|
|
266
|
+
backupConfigs: {},
|
|
267
|
+
host: 'web.portalhq.io',
|
|
268
|
+
mpcVersion: 'v6',
|
|
269
|
+
featureFlags: {},
|
|
270
|
+
})
|
|
271
|
+
.then(() => {
|
|
272
|
+
expect(0).toEqual(1)
|
|
273
|
+
done()
|
|
274
|
+
})
|
|
275
|
+
.catch((e) => {
|
|
276
|
+
expect(e).toBeInstanceOf(Error)
|
|
277
|
+
expect(e.message).toEqual(
|
|
278
|
+
'Invalid backup method: INVALID_METHOD. Valid methods are: GDRIVE, PASSWORD, PASSKEY, UNKNOWN',
|
|
279
|
+
)
|
|
280
|
+
done()
|
|
281
|
+
})
|
|
282
|
+
})
|
|
246
283
|
})
|
|
247
284
|
|
|
248
285
|
describe('clearLocalWallet', () => {
|
|
@@ -1988,4 +2025,612 @@ describe('Mpc', () => {
|
|
|
1988
2025
|
})
|
|
1989
2026
|
})
|
|
1990
2027
|
})
|
|
2028
|
+
|
|
2029
|
+
describe('getYieldXyzYields', () => {
|
|
2030
|
+
const args = mockYieldXyzGetYieldsRequest
|
|
2031
|
+
const res = mockYieldXyzGetYieldsResponse
|
|
2032
|
+
|
|
2033
|
+
it('should successfully return the yields', (done) => {
|
|
2034
|
+
jest
|
|
2035
|
+
.spyOn(mpc.iframe?.contentWindow!, 'postMessage')
|
|
2036
|
+
.mockImplementation((message: any, origin?) => {
|
|
2037
|
+
const { type, data } = message
|
|
2038
|
+
|
|
2039
|
+
expect(type).toEqual('portal:yieldxyz:discover')
|
|
2040
|
+
expect(data).toEqual(args)
|
|
2041
|
+
expect(origin).toEqual(mockHostOrigin)
|
|
2042
|
+
|
|
2043
|
+
window.dispatchEvent(
|
|
2044
|
+
new MessageEvent('message', {
|
|
2045
|
+
origin: mockHostOrigin,
|
|
2046
|
+
data: {
|
|
2047
|
+
type: 'portal:yieldxyz:discoverResult',
|
|
2048
|
+
data: res,
|
|
2049
|
+
},
|
|
2050
|
+
}),
|
|
2051
|
+
)
|
|
2052
|
+
})
|
|
2053
|
+
|
|
2054
|
+
mpc
|
|
2055
|
+
.getYieldXyzYields(args)
|
|
2056
|
+
.then((data) => {
|
|
2057
|
+
expect(data).toEqual(res)
|
|
2058
|
+
done()
|
|
2059
|
+
})
|
|
2060
|
+
.catch((_) => {
|
|
2061
|
+
expect(0).toEqual(1)
|
|
2062
|
+
done()
|
|
2063
|
+
})
|
|
2064
|
+
})
|
|
2065
|
+
|
|
2066
|
+
it('should error out if the iframe sends an error message', (done) => {
|
|
2067
|
+
jest
|
|
2068
|
+
.spyOn(mpc.iframe?.contentWindow!, 'postMessage')
|
|
2069
|
+
.mockImplementationOnce((message: any, origin?) => {
|
|
2070
|
+
const { type, data } = message
|
|
2071
|
+
|
|
2072
|
+
expect(type).toEqual('portal:yieldxyz:discover')
|
|
2073
|
+
expect(data).toEqual(args)
|
|
2074
|
+
expect(origin).toEqual(mockHostOrigin)
|
|
2075
|
+
|
|
2076
|
+
window.dispatchEvent(
|
|
2077
|
+
new MessageEvent('message', {
|
|
2078
|
+
origin: mockHostOrigin,
|
|
2079
|
+
data: {
|
|
2080
|
+
type: 'portal:yieldxyz:discoverError',
|
|
2081
|
+
data: {
|
|
2082
|
+
code: 1,
|
|
2083
|
+
message: 'test',
|
|
2084
|
+
},
|
|
2085
|
+
},
|
|
2086
|
+
}),
|
|
2087
|
+
)
|
|
2088
|
+
})
|
|
2089
|
+
|
|
2090
|
+
mpc
|
|
2091
|
+
.getYieldXyzYields(args)
|
|
2092
|
+
.then(() => {
|
|
2093
|
+
expect(0).toEqual(1)
|
|
2094
|
+
done()
|
|
2095
|
+
})
|
|
2096
|
+
.catch((e) => {
|
|
2097
|
+
expect(e).toBeInstanceOf(PortalMpcError)
|
|
2098
|
+
expect(e.message).toEqual('test')
|
|
2099
|
+
expect(e.code).toEqual(1)
|
|
2100
|
+
done()
|
|
2101
|
+
})
|
|
2102
|
+
})
|
|
2103
|
+
})
|
|
2104
|
+
|
|
2105
|
+
describe('enterYieldXyzYield', () => {
|
|
2106
|
+
const args = mockYieldXyzEnterRequest
|
|
2107
|
+
const res = mockYieldXyzEnterResponse
|
|
2108
|
+
|
|
2109
|
+
it('should successfully enter the yield', (done) => {
|
|
2110
|
+
jest
|
|
2111
|
+
.spyOn(mpc.iframe?.contentWindow!, 'postMessage')
|
|
2112
|
+
.mockImplementation((message: any, origin?) => {
|
|
2113
|
+
const { type, data } = message
|
|
2114
|
+
|
|
2115
|
+
expect(type).toEqual('portal:yieldxyz:enter')
|
|
2116
|
+
expect(data).toEqual(args)
|
|
2117
|
+
expect(origin).toEqual(mockHostOrigin)
|
|
2118
|
+
|
|
2119
|
+
window.dispatchEvent(
|
|
2120
|
+
new MessageEvent('message', {
|
|
2121
|
+
origin: mockHostOrigin,
|
|
2122
|
+
data: {
|
|
2123
|
+
type: 'portal:yieldxyz:enterResult',
|
|
2124
|
+
data: res,
|
|
2125
|
+
},
|
|
2126
|
+
}),
|
|
2127
|
+
)
|
|
2128
|
+
})
|
|
2129
|
+
|
|
2130
|
+
mpc
|
|
2131
|
+
.enterYieldXyzYield(args)
|
|
2132
|
+
.then((data) => {
|
|
2133
|
+
expect(data).toEqual(res)
|
|
2134
|
+
done()
|
|
2135
|
+
})
|
|
2136
|
+
.catch((_) => {
|
|
2137
|
+
expect(0).toEqual(1)
|
|
2138
|
+
done()
|
|
2139
|
+
})
|
|
2140
|
+
})
|
|
2141
|
+
|
|
2142
|
+
it('should error out if the iframe sends an error message', (done) => {
|
|
2143
|
+
jest
|
|
2144
|
+
.spyOn(mpc.iframe?.contentWindow!, 'postMessage')
|
|
2145
|
+
.mockImplementationOnce((message: any, origin?) => {
|
|
2146
|
+
const { type, data } = message
|
|
2147
|
+
|
|
2148
|
+
expect(type).toEqual('portal:yieldxyz:enter')
|
|
2149
|
+
expect(data).toEqual(args)
|
|
2150
|
+
expect(origin).toEqual(mockHostOrigin)
|
|
2151
|
+
|
|
2152
|
+
window.dispatchEvent(
|
|
2153
|
+
new MessageEvent('message', {
|
|
2154
|
+
origin: mockHostOrigin,
|
|
2155
|
+
data: {
|
|
2156
|
+
type: 'portal:yieldxyz:enterError',
|
|
2157
|
+
data: {
|
|
2158
|
+
code: 1,
|
|
2159
|
+
message: 'test',
|
|
2160
|
+
},
|
|
2161
|
+
},
|
|
2162
|
+
}),
|
|
2163
|
+
)
|
|
2164
|
+
})
|
|
2165
|
+
|
|
2166
|
+
mpc
|
|
2167
|
+
.enterYieldXyzYield(args)
|
|
2168
|
+
.then(() => {
|
|
2169
|
+
expect(0).toEqual(1)
|
|
2170
|
+
done()
|
|
2171
|
+
})
|
|
2172
|
+
.catch((e) => {
|
|
2173
|
+
expect(e).toBeInstanceOf(PortalMpcError)
|
|
2174
|
+
expect(e.message).toEqual('test')
|
|
2175
|
+
expect(e.code).toEqual(1)
|
|
2176
|
+
done()
|
|
2177
|
+
})
|
|
2178
|
+
})
|
|
2179
|
+
})
|
|
2180
|
+
|
|
2181
|
+
describe('exitYieldXyzYield', () => {
|
|
2182
|
+
const args = mockYieldXyzExitRequest
|
|
2183
|
+
const res = mockYieldXyzExitResponse
|
|
2184
|
+
|
|
2185
|
+
it('should successfully exit the yield', (done) => {
|
|
2186
|
+
jest
|
|
2187
|
+
.spyOn(mpc.iframe?.contentWindow!, 'postMessage')
|
|
2188
|
+
.mockImplementation((message: any, origin?) => {
|
|
2189
|
+
const { type, data } = message
|
|
2190
|
+
|
|
2191
|
+
expect(type).toEqual('portal:yieldxyz:exit')
|
|
2192
|
+
expect(data).toEqual(args)
|
|
2193
|
+
expect(origin).toEqual(mockHostOrigin)
|
|
2194
|
+
|
|
2195
|
+
window.dispatchEvent(
|
|
2196
|
+
new MessageEvent('message', {
|
|
2197
|
+
origin: mockHostOrigin,
|
|
2198
|
+
data: {
|
|
2199
|
+
type: 'portal:yieldxyz:exitResult',
|
|
2200
|
+
data: res,
|
|
2201
|
+
},
|
|
2202
|
+
}),
|
|
2203
|
+
)
|
|
2204
|
+
})
|
|
2205
|
+
|
|
2206
|
+
mpc
|
|
2207
|
+
.exitYieldXyzYield(args)
|
|
2208
|
+
.then((data) => {
|
|
2209
|
+
expect(data).toEqual(res)
|
|
2210
|
+
done()
|
|
2211
|
+
})
|
|
2212
|
+
.catch((_) => {
|
|
2213
|
+
expect(0).toEqual(1)
|
|
2214
|
+
done()
|
|
2215
|
+
})
|
|
2216
|
+
})
|
|
2217
|
+
|
|
2218
|
+
it('should error out if the iframe sends an error message', (done) => {
|
|
2219
|
+
jest
|
|
2220
|
+
.spyOn(mpc.iframe?.contentWindow!, 'postMessage')
|
|
2221
|
+
.mockImplementationOnce((message: any, origin?) => {
|
|
2222
|
+
const { type, data } = message
|
|
2223
|
+
|
|
2224
|
+
expect(type).toEqual('portal:yieldxyz:exit')
|
|
2225
|
+
expect(data).toEqual(args)
|
|
2226
|
+
expect(origin).toEqual(mockHostOrigin)
|
|
2227
|
+
|
|
2228
|
+
window.dispatchEvent(
|
|
2229
|
+
new MessageEvent('message', {
|
|
2230
|
+
origin: mockHostOrigin,
|
|
2231
|
+
data: {
|
|
2232
|
+
type: 'portal:yieldxyz:exitError',
|
|
2233
|
+
data: {
|
|
2234
|
+
code: 1,
|
|
2235
|
+
message: 'test',
|
|
2236
|
+
},
|
|
2237
|
+
},
|
|
2238
|
+
}),
|
|
2239
|
+
)
|
|
2240
|
+
})
|
|
2241
|
+
|
|
2242
|
+
mpc
|
|
2243
|
+
.exitYieldXyzYield(args)
|
|
2244
|
+
.then(() => {
|
|
2245
|
+
expect(0).toEqual(1)
|
|
2246
|
+
done()
|
|
2247
|
+
})
|
|
2248
|
+
.catch((e) => {
|
|
2249
|
+
expect(e).toBeInstanceOf(PortalMpcError)
|
|
2250
|
+
expect(e.message).toEqual('test')
|
|
2251
|
+
expect(e.code).toEqual(1)
|
|
2252
|
+
done()
|
|
2253
|
+
})
|
|
2254
|
+
})
|
|
2255
|
+
})
|
|
2256
|
+
|
|
2257
|
+
describe('getYieldXyzBalances', () => {
|
|
2258
|
+
const args = mockYieldXyzGetBalancesRequest
|
|
2259
|
+
const res = mockYieldXyzGetBalancesResponse
|
|
2260
|
+
|
|
2261
|
+
it('should successfully return the balances', (done) => {
|
|
2262
|
+
jest
|
|
2263
|
+
.spyOn(mpc.iframe?.contentWindow!, 'postMessage')
|
|
2264
|
+
.mockImplementation((message: any, origin?) => {
|
|
2265
|
+
const { type, data } = message
|
|
2266
|
+
|
|
2267
|
+
expect(type).toEqual('portal:yieldxyz:getBalances')
|
|
2268
|
+
expect(data).toEqual(args)
|
|
2269
|
+
expect(origin).toEqual(mockHostOrigin)
|
|
2270
|
+
|
|
2271
|
+
window.dispatchEvent(
|
|
2272
|
+
new MessageEvent('message', {
|
|
2273
|
+
origin: mockHostOrigin,
|
|
2274
|
+
data: {
|
|
2275
|
+
type: 'portal:yieldxyz:getBalancesResult',
|
|
2276
|
+
data: res,
|
|
2277
|
+
},
|
|
2278
|
+
}),
|
|
2279
|
+
)
|
|
2280
|
+
})
|
|
2281
|
+
|
|
2282
|
+
mpc
|
|
2283
|
+
.getYieldXyzBalances(args)
|
|
2284
|
+
.then((data) => {
|
|
2285
|
+
expect(data).toEqual(res)
|
|
2286
|
+
done()
|
|
2287
|
+
})
|
|
2288
|
+
.catch((_) => {
|
|
2289
|
+
expect(0).toEqual(1)
|
|
2290
|
+
done()
|
|
2291
|
+
})
|
|
2292
|
+
})
|
|
2293
|
+
|
|
2294
|
+
it('should error out if the iframe sends an error message', (done) => {
|
|
2295
|
+
jest
|
|
2296
|
+
.spyOn(mpc.iframe?.contentWindow!, 'postMessage')
|
|
2297
|
+
.mockImplementationOnce((message: any, origin?) => {
|
|
2298
|
+
const { type, data } = message
|
|
2299
|
+
|
|
2300
|
+
expect(type).toEqual('portal:yieldxyz:getBalances')
|
|
2301
|
+
expect(data).toEqual(args)
|
|
2302
|
+
expect(origin).toEqual(mockHostOrigin)
|
|
2303
|
+
|
|
2304
|
+
window.dispatchEvent(
|
|
2305
|
+
new MessageEvent('message', {
|
|
2306
|
+
origin: mockHostOrigin,
|
|
2307
|
+
data: {
|
|
2308
|
+
type: 'portal:yieldxyz:getBalancesError',
|
|
2309
|
+
data: {
|
|
2310
|
+
code: 1,
|
|
2311
|
+
message: 'test',
|
|
2312
|
+
},
|
|
2313
|
+
},
|
|
2314
|
+
}),
|
|
2315
|
+
)
|
|
2316
|
+
})
|
|
2317
|
+
|
|
2318
|
+
mpc
|
|
2319
|
+
.getYieldXyzBalances(args)
|
|
2320
|
+
.then(() => {
|
|
2321
|
+
expect(0).toEqual(1)
|
|
2322
|
+
done()
|
|
2323
|
+
})
|
|
2324
|
+
.catch((e) => {
|
|
2325
|
+
expect(e).toBeInstanceOf(PortalMpcError)
|
|
2326
|
+
expect(e.message).toEqual('test')
|
|
2327
|
+
expect(e.code).toEqual(1)
|
|
2328
|
+
done()
|
|
2329
|
+
})
|
|
2330
|
+
})
|
|
2331
|
+
})
|
|
2332
|
+
|
|
2333
|
+
describe('getYieldXyzHistoricalActions', () => {
|
|
2334
|
+
const args = mockYieldXyzGetHistoricalActionsRequest
|
|
2335
|
+
const res = mockYieldXyzGetHistoricalActionsResponse
|
|
2336
|
+
|
|
2337
|
+
it('should successfully return the historical actions', (done) => {
|
|
2338
|
+
jest
|
|
2339
|
+
.spyOn(mpc.iframe?.contentWindow!, 'postMessage')
|
|
2340
|
+
.mockImplementation((message: any, origin?) => {
|
|
2341
|
+
const { type, data } = message
|
|
2342
|
+
|
|
2343
|
+
expect(type).toEqual('portal:yieldxyz:getHistoricalActions')
|
|
2344
|
+
expect(data).toEqual(args)
|
|
2345
|
+
expect(origin).toEqual(mockHostOrigin)
|
|
2346
|
+
|
|
2347
|
+
window.dispatchEvent(
|
|
2348
|
+
new MessageEvent('message', {
|
|
2349
|
+
origin: mockHostOrigin,
|
|
2350
|
+
data: {
|
|
2351
|
+
type: 'portal:yieldxyz:getHistoricalActionsResult',
|
|
2352
|
+
data: res,
|
|
2353
|
+
},
|
|
2354
|
+
}),
|
|
2355
|
+
)
|
|
2356
|
+
})
|
|
2357
|
+
|
|
2358
|
+
mpc
|
|
2359
|
+
.getYieldXyzHistoricalActions(args)
|
|
2360
|
+
.then((data) => {
|
|
2361
|
+
expect(data).toEqual(res)
|
|
2362
|
+
done()
|
|
2363
|
+
})
|
|
2364
|
+
.catch((_) => {
|
|
2365
|
+
expect(0).toEqual(1)
|
|
2366
|
+
done()
|
|
2367
|
+
})
|
|
2368
|
+
})
|
|
2369
|
+
|
|
2370
|
+
it('should error out if the iframe sends an error message', (done) => {
|
|
2371
|
+
jest
|
|
2372
|
+
.spyOn(mpc.iframe?.contentWindow!, 'postMessage')
|
|
2373
|
+
.mockImplementationOnce((message: any, origin?) => {
|
|
2374
|
+
const { type, data } = message
|
|
2375
|
+
|
|
2376
|
+
expect(type).toEqual('portal:yieldxyz:getHistoricalActions')
|
|
2377
|
+
expect(data).toEqual(args)
|
|
2378
|
+
expect(origin).toEqual(mockHostOrigin)
|
|
2379
|
+
|
|
2380
|
+
window.dispatchEvent(
|
|
2381
|
+
new MessageEvent('message', {
|
|
2382
|
+
origin: mockHostOrigin,
|
|
2383
|
+
data: {
|
|
2384
|
+
type: 'portal:yieldxyz:getHistoricalActionsError',
|
|
2385
|
+
data: {
|
|
2386
|
+
code: 1,
|
|
2387
|
+
message: 'test',
|
|
2388
|
+
},
|
|
2389
|
+
},
|
|
2390
|
+
}),
|
|
2391
|
+
)
|
|
2392
|
+
})
|
|
2393
|
+
|
|
2394
|
+
mpc
|
|
2395
|
+
.getYieldXyzHistoricalActions(args)
|
|
2396
|
+
.then(() => {
|
|
2397
|
+
expect(0).toEqual(1)
|
|
2398
|
+
done()
|
|
2399
|
+
})
|
|
2400
|
+
.catch((e) => {
|
|
2401
|
+
expect(e).toBeInstanceOf(PortalMpcError)
|
|
2402
|
+
expect(e.message).toEqual('test')
|
|
2403
|
+
expect(e.code).toEqual(1)
|
|
2404
|
+
done()
|
|
2405
|
+
})
|
|
2406
|
+
})
|
|
2407
|
+
})
|
|
2408
|
+
|
|
2409
|
+
describe('manageYieldXyzYield', () => {
|
|
2410
|
+
const args = mockYieldXyzManageYieldRequest
|
|
2411
|
+
const res = mockYieldXyzManageYieldResponse
|
|
2412
|
+
|
|
2413
|
+
it('should successfully manage the yield', (done) => {
|
|
2414
|
+
jest
|
|
2415
|
+
.spyOn(mpc.iframe?.contentWindow!, 'postMessage')
|
|
2416
|
+
.mockImplementation((message: any, origin?) => {
|
|
2417
|
+
const { type, data } = message
|
|
2418
|
+
|
|
2419
|
+
expect(type).toEqual('portal:yieldxyz:manage')
|
|
2420
|
+
expect(data).toEqual(args)
|
|
2421
|
+
expect(origin).toEqual(mockHostOrigin)
|
|
2422
|
+
|
|
2423
|
+
window.dispatchEvent(
|
|
2424
|
+
new MessageEvent('message', {
|
|
2425
|
+
origin: mockHostOrigin,
|
|
2426
|
+
data: {
|
|
2427
|
+
type: 'portal:yieldxyz:manageYieldResult',
|
|
2428
|
+
data: res,
|
|
2429
|
+
},
|
|
2430
|
+
}),
|
|
2431
|
+
)
|
|
2432
|
+
})
|
|
2433
|
+
|
|
2434
|
+
mpc
|
|
2435
|
+
.manageYieldXyzYield(args)
|
|
2436
|
+
.then((data) => {
|
|
2437
|
+
expect(data).toEqual(res)
|
|
2438
|
+
done()
|
|
2439
|
+
})
|
|
2440
|
+
.catch((_) => {
|
|
2441
|
+
expect(0).toEqual(1)
|
|
2442
|
+
done()
|
|
2443
|
+
})
|
|
2444
|
+
})
|
|
2445
|
+
|
|
2446
|
+
it('should error out if the iframe sends an error message', (done) => {
|
|
2447
|
+
jest
|
|
2448
|
+
.spyOn(mpc.iframe?.contentWindow!, 'postMessage')
|
|
2449
|
+
.mockImplementationOnce((message: any, origin?) => {
|
|
2450
|
+
const { type, data } = message
|
|
2451
|
+
|
|
2452
|
+
expect(type).toEqual('portal:yieldxyz:manage')
|
|
2453
|
+
expect(data).toEqual(args)
|
|
2454
|
+
expect(origin).toEqual(mockHostOrigin)
|
|
2455
|
+
|
|
2456
|
+
window.dispatchEvent(
|
|
2457
|
+
new MessageEvent('message', {
|
|
2458
|
+
origin: mockHostOrigin,
|
|
2459
|
+
data: {
|
|
2460
|
+
type: 'portal:yieldxyz:manageYieldError',
|
|
2461
|
+
data: {
|
|
2462
|
+
code: 1,
|
|
2463
|
+
message: 'test',
|
|
2464
|
+
},
|
|
2465
|
+
},
|
|
2466
|
+
}),
|
|
2467
|
+
)
|
|
2468
|
+
})
|
|
2469
|
+
|
|
2470
|
+
mpc
|
|
2471
|
+
.manageYieldXyzYield(args)
|
|
2472
|
+
.then(() => {
|
|
2473
|
+
expect(0).toEqual(1)
|
|
2474
|
+
done()
|
|
2475
|
+
})
|
|
2476
|
+
.catch((e) => {
|
|
2477
|
+
expect(e).toBeInstanceOf(PortalMpcError)
|
|
2478
|
+
expect(e.message).toEqual('test')
|
|
2479
|
+
expect(e.code).toEqual(1)
|
|
2480
|
+
done()
|
|
2481
|
+
})
|
|
2482
|
+
})
|
|
2483
|
+
})
|
|
2484
|
+
|
|
2485
|
+
describe('trackYieldXyzTransaction', () => {
|
|
2486
|
+
const args = mockYieldXyzTrackTransactionRequest
|
|
2487
|
+
const res = mockYieldXyzTrackTransactionResponse
|
|
2488
|
+
|
|
2489
|
+
it('should successfully track the transaction', (done) => {
|
|
2490
|
+
jest
|
|
2491
|
+
.spyOn(mpc.iframe?.contentWindow!, 'postMessage')
|
|
2492
|
+
.mockImplementation((message: any, origin?) => {
|
|
2493
|
+
const { type, data } = message
|
|
2494
|
+
|
|
2495
|
+
expect(type).toEqual('portal:yieldxyz:track')
|
|
2496
|
+
expect(data).toEqual(args)
|
|
2497
|
+
expect(origin).toEqual(mockHostOrigin)
|
|
2498
|
+
|
|
2499
|
+
window.dispatchEvent(
|
|
2500
|
+
new MessageEvent('message', {
|
|
2501
|
+
origin: mockHostOrigin,
|
|
2502
|
+
data: {
|
|
2503
|
+
type: 'portal:yieldxyz:trackResult',
|
|
2504
|
+
data: res,
|
|
2505
|
+
},
|
|
2506
|
+
}),
|
|
2507
|
+
)
|
|
2508
|
+
})
|
|
2509
|
+
|
|
2510
|
+
mpc
|
|
2511
|
+
.trackYieldXyzTransaction(args)
|
|
2512
|
+
.then((data) => {
|
|
2513
|
+
expect(data).toEqual(res)
|
|
2514
|
+
done()
|
|
2515
|
+
})
|
|
2516
|
+
.catch((_) => {
|
|
2517
|
+
expect(0).toEqual(1)
|
|
2518
|
+
done()
|
|
2519
|
+
})
|
|
2520
|
+
})
|
|
2521
|
+
|
|
2522
|
+
it('should error out if the iframe sends an error message', (done) => {
|
|
2523
|
+
jest
|
|
2524
|
+
.spyOn(mpc.iframe?.contentWindow!, 'postMessage')
|
|
2525
|
+
.mockImplementationOnce((message: any, origin?) => {
|
|
2526
|
+
const { type, data } = message
|
|
2527
|
+
|
|
2528
|
+
expect(type).toEqual('portal:yieldxyz:track')
|
|
2529
|
+
expect(data).toEqual(args)
|
|
2530
|
+
expect(origin).toEqual(mockHostOrigin)
|
|
2531
|
+
|
|
2532
|
+
window.dispatchEvent(
|
|
2533
|
+
new MessageEvent('message', {
|
|
2534
|
+
origin: mockHostOrigin,
|
|
2535
|
+
data: {
|
|
2536
|
+
type: 'portal:yieldxyz:trackError',
|
|
2537
|
+
data: {
|
|
2538
|
+
code: 1,
|
|
2539
|
+
message: 'test',
|
|
2540
|
+
},
|
|
2541
|
+
},
|
|
2542
|
+
}),
|
|
2543
|
+
)
|
|
2544
|
+
})
|
|
2545
|
+
|
|
2546
|
+
mpc
|
|
2547
|
+
.trackYieldXyzTransaction(args)
|
|
2548
|
+
.then(() => {
|
|
2549
|
+
expect(0).toEqual(1)
|
|
2550
|
+
done()
|
|
2551
|
+
})
|
|
2552
|
+
.catch((e) => {
|
|
2553
|
+
expect(e).toBeInstanceOf(PortalMpcError)
|
|
2554
|
+
expect(e.message).toEqual('test')
|
|
2555
|
+
expect(e.code).toEqual(1)
|
|
2556
|
+
done()
|
|
2557
|
+
})
|
|
2558
|
+
})
|
|
2559
|
+
})
|
|
2560
|
+
|
|
2561
|
+
describe('getYieldXyzTransaction', () => {
|
|
2562
|
+
const args = 'test-tx-id'
|
|
2563
|
+
const res = mockYieldXyzGetTransactionResponse
|
|
2564
|
+
|
|
2565
|
+
it('should successfully return the transaction', (done) => {
|
|
2566
|
+
jest
|
|
2567
|
+
.spyOn(mpc.iframe?.contentWindow!, 'postMessage')
|
|
2568
|
+
.mockImplementation((message: any, origin?) => {
|
|
2569
|
+
const { type, data } = message
|
|
2570
|
+
|
|
2571
|
+
expect(type).toEqual('portal:yieldxyz:getTransaction')
|
|
2572
|
+
expect(data).toEqual(args)
|
|
2573
|
+
expect(origin).toEqual(mockHostOrigin)
|
|
2574
|
+
|
|
2575
|
+
window.dispatchEvent(
|
|
2576
|
+
new MessageEvent('message', {
|
|
2577
|
+
origin: mockHostOrigin,
|
|
2578
|
+
data: {
|
|
2579
|
+
type: 'portal:yieldxyz:getTransactionResult',
|
|
2580
|
+
data: res,
|
|
2581
|
+
},
|
|
2582
|
+
}),
|
|
2583
|
+
)
|
|
2584
|
+
})
|
|
2585
|
+
|
|
2586
|
+
mpc
|
|
2587
|
+
.getYieldXyzTransaction(args)
|
|
2588
|
+
.then((data) => {
|
|
2589
|
+
expect(data).toEqual(res)
|
|
2590
|
+
done()
|
|
2591
|
+
})
|
|
2592
|
+
.catch((_) => {
|
|
2593
|
+
expect(0).toEqual(1)
|
|
2594
|
+
done()
|
|
2595
|
+
})
|
|
2596
|
+
})
|
|
2597
|
+
|
|
2598
|
+
it('should error out if the iframe sends an error message', (done) => {
|
|
2599
|
+
jest
|
|
2600
|
+
.spyOn(mpc.iframe?.contentWindow!, 'postMessage')
|
|
2601
|
+
.mockImplementationOnce((message: any, origin?) => {
|
|
2602
|
+
const { type, data } = message
|
|
2603
|
+
|
|
2604
|
+
expect(type).toEqual('portal:yieldxyz:getTransaction')
|
|
2605
|
+
expect(data).toEqual(args)
|
|
2606
|
+
expect(origin).toEqual(mockHostOrigin)
|
|
2607
|
+
|
|
2608
|
+
window.dispatchEvent(
|
|
2609
|
+
new MessageEvent('message', {
|
|
2610
|
+
origin: mockHostOrigin,
|
|
2611
|
+
data: {
|
|
2612
|
+
type: 'portal:yieldxyz:getTransactionError',
|
|
2613
|
+
data: {
|
|
2614
|
+
code: 1,
|
|
2615
|
+
message: 'test',
|
|
2616
|
+
},
|
|
2617
|
+
},
|
|
2618
|
+
}),
|
|
2619
|
+
)
|
|
2620
|
+
})
|
|
2621
|
+
|
|
2622
|
+
mpc
|
|
2623
|
+
.getYieldXyzTransaction(args)
|
|
2624
|
+
.then(() => {
|
|
2625
|
+
expect(0).toEqual(1)
|
|
2626
|
+
done()
|
|
2627
|
+
})
|
|
2628
|
+
.catch((e) => {
|
|
2629
|
+
expect(e).toBeInstanceOf(PortalMpcError)
|
|
2630
|
+
expect(e.message).toEqual('test')
|
|
2631
|
+
expect(e.code).toEqual(1)
|
|
2632
|
+
done()
|
|
2633
|
+
})
|
|
2634
|
+
})
|
|
2635
|
+
})
|
|
1991
2636
|
})
|