@portal-hq/web 3.4.2-beta.2 → 3.5.0-alpha
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 -2
- 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
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
*/
|
|
4
4
|
import { BackupMethods, MpcStatuses, PortalCurve } from '../index';
|
|
5
5
|
import Mpc from '.';
|
|
6
|
-
import { mockAddress, mockApikey, mockAssets, mockBackupConfig, mockBackupIds, mockBalances, mockBuiltTransaction, mockCipherText, mockClientResponse, mockEjectResult, mockEjectPrivateKeysResult, mockEvaluationResult, mockHost, mockNFTs, mockOrgBackupShares, mockQuoteArgs, mockRpcUrl, mockSharesOnDevice, mockSimulationResult, mockTransactionToEvaluate, mockTransactionToSimulate, } from '../__mocks/constants';
|
|
6
|
+
import { mockAddress, mockApikey, mockAssets, mockBackupConfig, mockBackupIds, mockBalances, mockBuiltTransaction, mockCipherText, mockClientResponse, mockEjectResult, mockEjectPrivateKeysResult, mockEvaluationResult, mockHost, mockNFTs, mockOrgBackupShares, mockQuoteArgs, mockRpcUrl, mockSharesOnDevice, mockSimulationResult, mockTransactionToEvaluate, mockTransactionToSimulate, mockYieldXyzGetYieldsRequest, mockYieldXyzGetYieldsResponse, mockYieldXyzEnterRequest, mockYieldXyzEnterResponse, mockYieldXyzExitRequest, mockYieldXyzExitResponse, mockYieldXyzGetBalancesRequest, mockYieldXyzGetBalancesResponse, mockYieldXyzGetHistoricalActionsRequest, mockYieldXyzGetHistoricalActionsResponse, mockYieldXyzManageYieldRequest, mockYieldXyzManageYieldResponse, mockYieldXyzTrackTransactionRequest, mockYieldXyzTrackTransactionResponse, mockYieldXyzGetTransactionResponse, } from '../__mocks/constants';
|
|
7
7
|
import portalMock from '../__mocks/portal/portal';
|
|
8
8
|
import { PortalMpcError } from './errors';
|
|
9
9
|
describe('Mpc', () => {
|
|
@@ -192,6 +192,25 @@ describe('Mpc', () => {
|
|
|
192
192
|
done();
|
|
193
193
|
});
|
|
194
194
|
});
|
|
195
|
+
it('should error out if backupMethod is invalid', (done) => {
|
|
196
|
+
mpc
|
|
197
|
+
.backup({
|
|
198
|
+
backupMethod: 'INVALID_METHOD',
|
|
199
|
+
backupConfigs: {},
|
|
200
|
+
host: 'web.portalhq.io',
|
|
201
|
+
mpcVersion: 'v6',
|
|
202
|
+
featureFlags: {},
|
|
203
|
+
})
|
|
204
|
+
.then(() => {
|
|
205
|
+
expect(0).toEqual(1);
|
|
206
|
+
done();
|
|
207
|
+
})
|
|
208
|
+
.catch((e) => {
|
|
209
|
+
expect(e).toBeInstanceOf(Error);
|
|
210
|
+
expect(e.message).toEqual('Invalid backup method: INVALID_METHOD. Valid methods are: GDRIVE, PASSWORD, PASSKEY, UNKNOWN');
|
|
211
|
+
done();
|
|
212
|
+
});
|
|
213
|
+
});
|
|
195
214
|
});
|
|
196
215
|
describe('clearLocalWallet', () => {
|
|
197
216
|
it('should clear local wallet', (done) => {
|
|
@@ -1694,4 +1713,524 @@ describe('Mpc', () => {
|
|
|
1694
1713
|
});
|
|
1695
1714
|
});
|
|
1696
1715
|
});
|
|
1716
|
+
describe('getYieldXyzYields', () => {
|
|
1717
|
+
const args = mockYieldXyzGetYieldsRequest;
|
|
1718
|
+
const res = mockYieldXyzGetYieldsResponse;
|
|
1719
|
+
it('should successfully return the yields', (done) => {
|
|
1720
|
+
var _a;
|
|
1721
|
+
jest
|
|
1722
|
+
.spyOn((_a = mpc.iframe) === null || _a === void 0 ? void 0 : _a.contentWindow, 'postMessage')
|
|
1723
|
+
.mockImplementation((message, origin) => {
|
|
1724
|
+
const { type, data } = message;
|
|
1725
|
+
expect(type).toEqual('portal:yieldxyz:discover');
|
|
1726
|
+
expect(data).toEqual(args);
|
|
1727
|
+
expect(origin).toEqual(mockHostOrigin);
|
|
1728
|
+
window.dispatchEvent(new MessageEvent('message', {
|
|
1729
|
+
origin: mockHostOrigin,
|
|
1730
|
+
data: {
|
|
1731
|
+
type: 'portal:yieldxyz:discoverResult',
|
|
1732
|
+
data: res,
|
|
1733
|
+
},
|
|
1734
|
+
}));
|
|
1735
|
+
});
|
|
1736
|
+
mpc
|
|
1737
|
+
.getYieldXyzYields(args)
|
|
1738
|
+
.then((data) => {
|
|
1739
|
+
expect(data).toEqual(res);
|
|
1740
|
+
done();
|
|
1741
|
+
})
|
|
1742
|
+
.catch((_) => {
|
|
1743
|
+
expect(0).toEqual(1);
|
|
1744
|
+
done();
|
|
1745
|
+
});
|
|
1746
|
+
});
|
|
1747
|
+
it('should error out if the iframe sends an error message', (done) => {
|
|
1748
|
+
var _a;
|
|
1749
|
+
jest
|
|
1750
|
+
.spyOn((_a = mpc.iframe) === null || _a === void 0 ? void 0 : _a.contentWindow, 'postMessage')
|
|
1751
|
+
.mockImplementationOnce((message, origin) => {
|
|
1752
|
+
const { type, data } = message;
|
|
1753
|
+
expect(type).toEqual('portal:yieldxyz:discover');
|
|
1754
|
+
expect(data).toEqual(args);
|
|
1755
|
+
expect(origin).toEqual(mockHostOrigin);
|
|
1756
|
+
window.dispatchEvent(new MessageEvent('message', {
|
|
1757
|
+
origin: mockHostOrigin,
|
|
1758
|
+
data: {
|
|
1759
|
+
type: 'portal:yieldxyz:discoverError',
|
|
1760
|
+
data: {
|
|
1761
|
+
code: 1,
|
|
1762
|
+
message: 'test',
|
|
1763
|
+
},
|
|
1764
|
+
},
|
|
1765
|
+
}));
|
|
1766
|
+
});
|
|
1767
|
+
mpc
|
|
1768
|
+
.getYieldXyzYields(args)
|
|
1769
|
+
.then(() => {
|
|
1770
|
+
expect(0).toEqual(1);
|
|
1771
|
+
done();
|
|
1772
|
+
})
|
|
1773
|
+
.catch((e) => {
|
|
1774
|
+
expect(e).toBeInstanceOf(PortalMpcError);
|
|
1775
|
+
expect(e.message).toEqual('test');
|
|
1776
|
+
expect(e.code).toEqual(1);
|
|
1777
|
+
done();
|
|
1778
|
+
});
|
|
1779
|
+
});
|
|
1780
|
+
});
|
|
1781
|
+
describe('enterYieldXyzYield', () => {
|
|
1782
|
+
const args = mockYieldXyzEnterRequest;
|
|
1783
|
+
const res = mockYieldXyzEnterResponse;
|
|
1784
|
+
it('should successfully enter the yield', (done) => {
|
|
1785
|
+
var _a;
|
|
1786
|
+
jest
|
|
1787
|
+
.spyOn((_a = mpc.iframe) === null || _a === void 0 ? void 0 : _a.contentWindow, 'postMessage')
|
|
1788
|
+
.mockImplementation((message, origin) => {
|
|
1789
|
+
const { type, data } = message;
|
|
1790
|
+
expect(type).toEqual('portal:yieldxyz:enter');
|
|
1791
|
+
expect(data).toEqual(args);
|
|
1792
|
+
expect(origin).toEqual(mockHostOrigin);
|
|
1793
|
+
window.dispatchEvent(new MessageEvent('message', {
|
|
1794
|
+
origin: mockHostOrigin,
|
|
1795
|
+
data: {
|
|
1796
|
+
type: 'portal:yieldxyz:enterResult',
|
|
1797
|
+
data: res,
|
|
1798
|
+
},
|
|
1799
|
+
}));
|
|
1800
|
+
});
|
|
1801
|
+
mpc
|
|
1802
|
+
.enterYieldXyzYield(args)
|
|
1803
|
+
.then((data) => {
|
|
1804
|
+
expect(data).toEqual(res);
|
|
1805
|
+
done();
|
|
1806
|
+
})
|
|
1807
|
+
.catch((_) => {
|
|
1808
|
+
expect(0).toEqual(1);
|
|
1809
|
+
done();
|
|
1810
|
+
});
|
|
1811
|
+
});
|
|
1812
|
+
it('should error out if the iframe sends an error message', (done) => {
|
|
1813
|
+
var _a;
|
|
1814
|
+
jest
|
|
1815
|
+
.spyOn((_a = mpc.iframe) === null || _a === void 0 ? void 0 : _a.contentWindow, 'postMessage')
|
|
1816
|
+
.mockImplementationOnce((message, origin) => {
|
|
1817
|
+
const { type, data } = message;
|
|
1818
|
+
expect(type).toEqual('portal:yieldxyz:enter');
|
|
1819
|
+
expect(data).toEqual(args);
|
|
1820
|
+
expect(origin).toEqual(mockHostOrigin);
|
|
1821
|
+
window.dispatchEvent(new MessageEvent('message', {
|
|
1822
|
+
origin: mockHostOrigin,
|
|
1823
|
+
data: {
|
|
1824
|
+
type: 'portal:yieldxyz:enterError',
|
|
1825
|
+
data: {
|
|
1826
|
+
code: 1,
|
|
1827
|
+
message: 'test',
|
|
1828
|
+
},
|
|
1829
|
+
},
|
|
1830
|
+
}));
|
|
1831
|
+
});
|
|
1832
|
+
mpc
|
|
1833
|
+
.enterYieldXyzYield(args)
|
|
1834
|
+
.then(() => {
|
|
1835
|
+
expect(0).toEqual(1);
|
|
1836
|
+
done();
|
|
1837
|
+
})
|
|
1838
|
+
.catch((e) => {
|
|
1839
|
+
expect(e).toBeInstanceOf(PortalMpcError);
|
|
1840
|
+
expect(e.message).toEqual('test');
|
|
1841
|
+
expect(e.code).toEqual(1);
|
|
1842
|
+
done();
|
|
1843
|
+
});
|
|
1844
|
+
});
|
|
1845
|
+
});
|
|
1846
|
+
describe('exitYieldXyzYield', () => {
|
|
1847
|
+
const args = mockYieldXyzExitRequest;
|
|
1848
|
+
const res = mockYieldXyzExitResponse;
|
|
1849
|
+
it('should successfully exit the yield', (done) => {
|
|
1850
|
+
var _a;
|
|
1851
|
+
jest
|
|
1852
|
+
.spyOn((_a = mpc.iframe) === null || _a === void 0 ? void 0 : _a.contentWindow, 'postMessage')
|
|
1853
|
+
.mockImplementation((message, origin) => {
|
|
1854
|
+
const { type, data } = message;
|
|
1855
|
+
expect(type).toEqual('portal:yieldxyz:exit');
|
|
1856
|
+
expect(data).toEqual(args);
|
|
1857
|
+
expect(origin).toEqual(mockHostOrigin);
|
|
1858
|
+
window.dispatchEvent(new MessageEvent('message', {
|
|
1859
|
+
origin: mockHostOrigin,
|
|
1860
|
+
data: {
|
|
1861
|
+
type: 'portal:yieldxyz:exitResult',
|
|
1862
|
+
data: res,
|
|
1863
|
+
},
|
|
1864
|
+
}));
|
|
1865
|
+
});
|
|
1866
|
+
mpc
|
|
1867
|
+
.exitYieldXyzYield(args)
|
|
1868
|
+
.then((data) => {
|
|
1869
|
+
expect(data).toEqual(res);
|
|
1870
|
+
done();
|
|
1871
|
+
})
|
|
1872
|
+
.catch((_) => {
|
|
1873
|
+
expect(0).toEqual(1);
|
|
1874
|
+
done();
|
|
1875
|
+
});
|
|
1876
|
+
});
|
|
1877
|
+
it('should error out if the iframe sends an error message', (done) => {
|
|
1878
|
+
var _a;
|
|
1879
|
+
jest
|
|
1880
|
+
.spyOn((_a = mpc.iframe) === null || _a === void 0 ? void 0 : _a.contentWindow, 'postMessage')
|
|
1881
|
+
.mockImplementationOnce((message, origin) => {
|
|
1882
|
+
const { type, data } = message;
|
|
1883
|
+
expect(type).toEqual('portal:yieldxyz:exit');
|
|
1884
|
+
expect(data).toEqual(args);
|
|
1885
|
+
expect(origin).toEqual(mockHostOrigin);
|
|
1886
|
+
window.dispatchEvent(new MessageEvent('message', {
|
|
1887
|
+
origin: mockHostOrigin,
|
|
1888
|
+
data: {
|
|
1889
|
+
type: 'portal:yieldxyz:exitError',
|
|
1890
|
+
data: {
|
|
1891
|
+
code: 1,
|
|
1892
|
+
message: 'test',
|
|
1893
|
+
},
|
|
1894
|
+
},
|
|
1895
|
+
}));
|
|
1896
|
+
});
|
|
1897
|
+
mpc
|
|
1898
|
+
.exitYieldXyzYield(args)
|
|
1899
|
+
.then(() => {
|
|
1900
|
+
expect(0).toEqual(1);
|
|
1901
|
+
done();
|
|
1902
|
+
})
|
|
1903
|
+
.catch((e) => {
|
|
1904
|
+
expect(e).toBeInstanceOf(PortalMpcError);
|
|
1905
|
+
expect(e.message).toEqual('test');
|
|
1906
|
+
expect(e.code).toEqual(1);
|
|
1907
|
+
done();
|
|
1908
|
+
});
|
|
1909
|
+
});
|
|
1910
|
+
});
|
|
1911
|
+
describe('getYieldXyzBalances', () => {
|
|
1912
|
+
const args = mockYieldXyzGetBalancesRequest;
|
|
1913
|
+
const res = mockYieldXyzGetBalancesResponse;
|
|
1914
|
+
it('should successfully return the balances', (done) => {
|
|
1915
|
+
var _a;
|
|
1916
|
+
jest
|
|
1917
|
+
.spyOn((_a = mpc.iframe) === null || _a === void 0 ? void 0 : _a.contentWindow, 'postMessage')
|
|
1918
|
+
.mockImplementation((message, origin) => {
|
|
1919
|
+
const { type, data } = message;
|
|
1920
|
+
expect(type).toEqual('portal:yieldxyz:getBalances');
|
|
1921
|
+
expect(data).toEqual(args);
|
|
1922
|
+
expect(origin).toEqual(mockHostOrigin);
|
|
1923
|
+
window.dispatchEvent(new MessageEvent('message', {
|
|
1924
|
+
origin: mockHostOrigin,
|
|
1925
|
+
data: {
|
|
1926
|
+
type: 'portal:yieldxyz:getBalancesResult',
|
|
1927
|
+
data: res,
|
|
1928
|
+
},
|
|
1929
|
+
}));
|
|
1930
|
+
});
|
|
1931
|
+
mpc
|
|
1932
|
+
.getYieldXyzBalances(args)
|
|
1933
|
+
.then((data) => {
|
|
1934
|
+
expect(data).toEqual(res);
|
|
1935
|
+
done();
|
|
1936
|
+
})
|
|
1937
|
+
.catch((_) => {
|
|
1938
|
+
expect(0).toEqual(1);
|
|
1939
|
+
done();
|
|
1940
|
+
});
|
|
1941
|
+
});
|
|
1942
|
+
it('should error out if the iframe sends an error message', (done) => {
|
|
1943
|
+
var _a;
|
|
1944
|
+
jest
|
|
1945
|
+
.spyOn((_a = mpc.iframe) === null || _a === void 0 ? void 0 : _a.contentWindow, 'postMessage')
|
|
1946
|
+
.mockImplementationOnce((message, origin) => {
|
|
1947
|
+
const { type, data } = message;
|
|
1948
|
+
expect(type).toEqual('portal:yieldxyz:getBalances');
|
|
1949
|
+
expect(data).toEqual(args);
|
|
1950
|
+
expect(origin).toEqual(mockHostOrigin);
|
|
1951
|
+
window.dispatchEvent(new MessageEvent('message', {
|
|
1952
|
+
origin: mockHostOrigin,
|
|
1953
|
+
data: {
|
|
1954
|
+
type: 'portal:yieldxyz:getBalancesError',
|
|
1955
|
+
data: {
|
|
1956
|
+
code: 1,
|
|
1957
|
+
message: 'test',
|
|
1958
|
+
},
|
|
1959
|
+
},
|
|
1960
|
+
}));
|
|
1961
|
+
});
|
|
1962
|
+
mpc
|
|
1963
|
+
.getYieldXyzBalances(args)
|
|
1964
|
+
.then(() => {
|
|
1965
|
+
expect(0).toEqual(1);
|
|
1966
|
+
done();
|
|
1967
|
+
})
|
|
1968
|
+
.catch((e) => {
|
|
1969
|
+
expect(e).toBeInstanceOf(PortalMpcError);
|
|
1970
|
+
expect(e.message).toEqual('test');
|
|
1971
|
+
expect(e.code).toEqual(1);
|
|
1972
|
+
done();
|
|
1973
|
+
});
|
|
1974
|
+
});
|
|
1975
|
+
});
|
|
1976
|
+
describe('getYieldXyzHistoricalActions', () => {
|
|
1977
|
+
const args = mockYieldXyzGetHistoricalActionsRequest;
|
|
1978
|
+
const res = mockYieldXyzGetHistoricalActionsResponse;
|
|
1979
|
+
it('should successfully return the historical actions', (done) => {
|
|
1980
|
+
var _a;
|
|
1981
|
+
jest
|
|
1982
|
+
.spyOn((_a = mpc.iframe) === null || _a === void 0 ? void 0 : _a.contentWindow, 'postMessage')
|
|
1983
|
+
.mockImplementation((message, origin) => {
|
|
1984
|
+
const { type, data } = message;
|
|
1985
|
+
expect(type).toEqual('portal:yieldxyz:getHistoricalActions');
|
|
1986
|
+
expect(data).toEqual(args);
|
|
1987
|
+
expect(origin).toEqual(mockHostOrigin);
|
|
1988
|
+
window.dispatchEvent(new MessageEvent('message', {
|
|
1989
|
+
origin: mockHostOrigin,
|
|
1990
|
+
data: {
|
|
1991
|
+
type: 'portal:yieldxyz:getHistoricalActionsResult',
|
|
1992
|
+
data: res,
|
|
1993
|
+
},
|
|
1994
|
+
}));
|
|
1995
|
+
});
|
|
1996
|
+
mpc
|
|
1997
|
+
.getYieldXyzHistoricalActions(args)
|
|
1998
|
+
.then((data) => {
|
|
1999
|
+
expect(data).toEqual(res);
|
|
2000
|
+
done();
|
|
2001
|
+
})
|
|
2002
|
+
.catch((_) => {
|
|
2003
|
+
expect(0).toEqual(1);
|
|
2004
|
+
done();
|
|
2005
|
+
});
|
|
2006
|
+
});
|
|
2007
|
+
it('should error out if the iframe sends an error message', (done) => {
|
|
2008
|
+
var _a;
|
|
2009
|
+
jest
|
|
2010
|
+
.spyOn((_a = mpc.iframe) === null || _a === void 0 ? void 0 : _a.contentWindow, 'postMessage')
|
|
2011
|
+
.mockImplementationOnce((message, origin) => {
|
|
2012
|
+
const { type, data } = message;
|
|
2013
|
+
expect(type).toEqual('portal:yieldxyz:getHistoricalActions');
|
|
2014
|
+
expect(data).toEqual(args);
|
|
2015
|
+
expect(origin).toEqual(mockHostOrigin);
|
|
2016
|
+
window.dispatchEvent(new MessageEvent('message', {
|
|
2017
|
+
origin: mockHostOrigin,
|
|
2018
|
+
data: {
|
|
2019
|
+
type: 'portal:yieldxyz:getHistoricalActionsError',
|
|
2020
|
+
data: {
|
|
2021
|
+
code: 1,
|
|
2022
|
+
message: 'test',
|
|
2023
|
+
},
|
|
2024
|
+
},
|
|
2025
|
+
}));
|
|
2026
|
+
});
|
|
2027
|
+
mpc
|
|
2028
|
+
.getYieldXyzHistoricalActions(args)
|
|
2029
|
+
.then(() => {
|
|
2030
|
+
expect(0).toEqual(1);
|
|
2031
|
+
done();
|
|
2032
|
+
})
|
|
2033
|
+
.catch((e) => {
|
|
2034
|
+
expect(e).toBeInstanceOf(PortalMpcError);
|
|
2035
|
+
expect(e.message).toEqual('test');
|
|
2036
|
+
expect(e.code).toEqual(1);
|
|
2037
|
+
done();
|
|
2038
|
+
});
|
|
2039
|
+
});
|
|
2040
|
+
});
|
|
2041
|
+
describe('manageYieldXyzYield', () => {
|
|
2042
|
+
const args = mockYieldXyzManageYieldRequest;
|
|
2043
|
+
const res = mockYieldXyzManageYieldResponse;
|
|
2044
|
+
it('should successfully manage the yield', (done) => {
|
|
2045
|
+
var _a;
|
|
2046
|
+
jest
|
|
2047
|
+
.spyOn((_a = mpc.iframe) === null || _a === void 0 ? void 0 : _a.contentWindow, 'postMessage')
|
|
2048
|
+
.mockImplementation((message, origin) => {
|
|
2049
|
+
const { type, data } = message;
|
|
2050
|
+
expect(type).toEqual('portal:yieldxyz:manage');
|
|
2051
|
+
expect(data).toEqual(args);
|
|
2052
|
+
expect(origin).toEqual(mockHostOrigin);
|
|
2053
|
+
window.dispatchEvent(new MessageEvent('message', {
|
|
2054
|
+
origin: mockHostOrigin,
|
|
2055
|
+
data: {
|
|
2056
|
+
type: 'portal:yieldxyz:manageYieldResult',
|
|
2057
|
+
data: res,
|
|
2058
|
+
},
|
|
2059
|
+
}));
|
|
2060
|
+
});
|
|
2061
|
+
mpc
|
|
2062
|
+
.manageYieldXyzYield(args)
|
|
2063
|
+
.then((data) => {
|
|
2064
|
+
expect(data).toEqual(res);
|
|
2065
|
+
done();
|
|
2066
|
+
})
|
|
2067
|
+
.catch((_) => {
|
|
2068
|
+
expect(0).toEqual(1);
|
|
2069
|
+
done();
|
|
2070
|
+
});
|
|
2071
|
+
});
|
|
2072
|
+
it('should error out if the iframe sends an error message', (done) => {
|
|
2073
|
+
var _a;
|
|
2074
|
+
jest
|
|
2075
|
+
.spyOn((_a = mpc.iframe) === null || _a === void 0 ? void 0 : _a.contentWindow, 'postMessage')
|
|
2076
|
+
.mockImplementationOnce((message, origin) => {
|
|
2077
|
+
const { type, data } = message;
|
|
2078
|
+
expect(type).toEqual('portal:yieldxyz:manage');
|
|
2079
|
+
expect(data).toEqual(args);
|
|
2080
|
+
expect(origin).toEqual(mockHostOrigin);
|
|
2081
|
+
window.dispatchEvent(new MessageEvent('message', {
|
|
2082
|
+
origin: mockHostOrigin,
|
|
2083
|
+
data: {
|
|
2084
|
+
type: 'portal:yieldxyz:manageYieldError',
|
|
2085
|
+
data: {
|
|
2086
|
+
code: 1,
|
|
2087
|
+
message: 'test',
|
|
2088
|
+
},
|
|
2089
|
+
},
|
|
2090
|
+
}));
|
|
2091
|
+
});
|
|
2092
|
+
mpc
|
|
2093
|
+
.manageYieldXyzYield(args)
|
|
2094
|
+
.then(() => {
|
|
2095
|
+
expect(0).toEqual(1);
|
|
2096
|
+
done();
|
|
2097
|
+
})
|
|
2098
|
+
.catch((e) => {
|
|
2099
|
+
expect(e).toBeInstanceOf(PortalMpcError);
|
|
2100
|
+
expect(e.message).toEqual('test');
|
|
2101
|
+
expect(e.code).toEqual(1);
|
|
2102
|
+
done();
|
|
2103
|
+
});
|
|
2104
|
+
});
|
|
2105
|
+
});
|
|
2106
|
+
describe('trackYieldXyzTransaction', () => {
|
|
2107
|
+
const args = mockYieldXyzTrackTransactionRequest;
|
|
2108
|
+
const res = mockYieldXyzTrackTransactionResponse;
|
|
2109
|
+
it('should successfully track the transaction', (done) => {
|
|
2110
|
+
var _a;
|
|
2111
|
+
jest
|
|
2112
|
+
.spyOn((_a = mpc.iframe) === null || _a === void 0 ? void 0 : _a.contentWindow, 'postMessage')
|
|
2113
|
+
.mockImplementation((message, origin) => {
|
|
2114
|
+
const { type, data } = message;
|
|
2115
|
+
expect(type).toEqual('portal:yieldxyz:track');
|
|
2116
|
+
expect(data).toEqual(args);
|
|
2117
|
+
expect(origin).toEqual(mockHostOrigin);
|
|
2118
|
+
window.dispatchEvent(new MessageEvent('message', {
|
|
2119
|
+
origin: mockHostOrigin,
|
|
2120
|
+
data: {
|
|
2121
|
+
type: 'portal:yieldxyz:trackResult',
|
|
2122
|
+
data: res,
|
|
2123
|
+
},
|
|
2124
|
+
}));
|
|
2125
|
+
});
|
|
2126
|
+
mpc
|
|
2127
|
+
.trackYieldXyzTransaction(args)
|
|
2128
|
+
.then((data) => {
|
|
2129
|
+
expect(data).toEqual(res);
|
|
2130
|
+
done();
|
|
2131
|
+
})
|
|
2132
|
+
.catch((_) => {
|
|
2133
|
+
expect(0).toEqual(1);
|
|
2134
|
+
done();
|
|
2135
|
+
});
|
|
2136
|
+
});
|
|
2137
|
+
it('should error out if the iframe sends an error message', (done) => {
|
|
2138
|
+
var _a;
|
|
2139
|
+
jest
|
|
2140
|
+
.spyOn((_a = mpc.iframe) === null || _a === void 0 ? void 0 : _a.contentWindow, 'postMessage')
|
|
2141
|
+
.mockImplementationOnce((message, origin) => {
|
|
2142
|
+
const { type, data } = message;
|
|
2143
|
+
expect(type).toEqual('portal:yieldxyz:track');
|
|
2144
|
+
expect(data).toEqual(args);
|
|
2145
|
+
expect(origin).toEqual(mockHostOrigin);
|
|
2146
|
+
window.dispatchEvent(new MessageEvent('message', {
|
|
2147
|
+
origin: mockHostOrigin,
|
|
2148
|
+
data: {
|
|
2149
|
+
type: 'portal:yieldxyz:trackError',
|
|
2150
|
+
data: {
|
|
2151
|
+
code: 1,
|
|
2152
|
+
message: 'test',
|
|
2153
|
+
},
|
|
2154
|
+
},
|
|
2155
|
+
}));
|
|
2156
|
+
});
|
|
2157
|
+
mpc
|
|
2158
|
+
.trackYieldXyzTransaction(args)
|
|
2159
|
+
.then(() => {
|
|
2160
|
+
expect(0).toEqual(1);
|
|
2161
|
+
done();
|
|
2162
|
+
})
|
|
2163
|
+
.catch((e) => {
|
|
2164
|
+
expect(e).toBeInstanceOf(PortalMpcError);
|
|
2165
|
+
expect(e.message).toEqual('test');
|
|
2166
|
+
expect(e.code).toEqual(1);
|
|
2167
|
+
done();
|
|
2168
|
+
});
|
|
2169
|
+
});
|
|
2170
|
+
});
|
|
2171
|
+
describe('getYieldXyzTransaction', () => {
|
|
2172
|
+
const args = 'test-tx-id';
|
|
2173
|
+
const res = mockYieldXyzGetTransactionResponse;
|
|
2174
|
+
it('should successfully return the transaction', (done) => {
|
|
2175
|
+
var _a;
|
|
2176
|
+
jest
|
|
2177
|
+
.spyOn((_a = mpc.iframe) === null || _a === void 0 ? void 0 : _a.contentWindow, 'postMessage')
|
|
2178
|
+
.mockImplementation((message, origin) => {
|
|
2179
|
+
const { type, data } = message;
|
|
2180
|
+
expect(type).toEqual('portal:yieldxyz:getTransaction');
|
|
2181
|
+
expect(data).toEqual(args);
|
|
2182
|
+
expect(origin).toEqual(mockHostOrigin);
|
|
2183
|
+
window.dispatchEvent(new MessageEvent('message', {
|
|
2184
|
+
origin: mockHostOrigin,
|
|
2185
|
+
data: {
|
|
2186
|
+
type: 'portal:yieldxyz:getTransactionResult',
|
|
2187
|
+
data: res,
|
|
2188
|
+
},
|
|
2189
|
+
}));
|
|
2190
|
+
});
|
|
2191
|
+
mpc
|
|
2192
|
+
.getYieldXyzTransaction(args)
|
|
2193
|
+
.then((data) => {
|
|
2194
|
+
expect(data).toEqual(res);
|
|
2195
|
+
done();
|
|
2196
|
+
})
|
|
2197
|
+
.catch((_) => {
|
|
2198
|
+
expect(0).toEqual(1);
|
|
2199
|
+
done();
|
|
2200
|
+
});
|
|
2201
|
+
});
|
|
2202
|
+
it('should error out if the iframe sends an error message', (done) => {
|
|
2203
|
+
var _a;
|
|
2204
|
+
jest
|
|
2205
|
+
.spyOn((_a = mpc.iframe) === null || _a === void 0 ? void 0 : _a.contentWindow, 'postMessage')
|
|
2206
|
+
.mockImplementationOnce((message, origin) => {
|
|
2207
|
+
const { type, data } = message;
|
|
2208
|
+
expect(type).toEqual('portal:yieldxyz:getTransaction');
|
|
2209
|
+
expect(data).toEqual(args);
|
|
2210
|
+
expect(origin).toEqual(mockHostOrigin);
|
|
2211
|
+
window.dispatchEvent(new MessageEvent('message', {
|
|
2212
|
+
origin: mockHostOrigin,
|
|
2213
|
+
data: {
|
|
2214
|
+
type: 'portal:yieldxyz:getTransactionError',
|
|
2215
|
+
data: {
|
|
2216
|
+
code: 1,
|
|
2217
|
+
message: 'test',
|
|
2218
|
+
},
|
|
2219
|
+
},
|
|
2220
|
+
}));
|
|
2221
|
+
});
|
|
2222
|
+
mpc
|
|
2223
|
+
.getYieldXyzTransaction(args)
|
|
2224
|
+
.then(() => {
|
|
2225
|
+
expect(0).toEqual(1);
|
|
2226
|
+
done();
|
|
2227
|
+
})
|
|
2228
|
+
.catch((e) => {
|
|
2229
|
+
expect(e).toBeInstanceOf(PortalMpcError);
|
|
2230
|
+
expect(e.message).toEqual('test');
|
|
2231
|
+
expect(e.code).toEqual(1);
|
|
2232
|
+
done();
|
|
2233
|
+
});
|
|
2234
|
+
});
|
|
2235
|
+
});
|
|
1697
2236
|
});
|
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"description": "Portal MPC Support for Web",
|
|
4
4
|
"author": "Portal Labs, Inc.",
|
|
5
5
|
"homepage": "https://portalhq.io/",
|
|
6
|
-
"version": "3.
|
|
6
|
+
"version": "3.5.0-alpha",
|
|
7
7
|
"license": "MIT",
|
|
8
8
|
"main": "lib/commonjs/index",
|
|
9
9
|
"module": "lib/esm/index",
|
|
@@ -50,5 +50,5 @@
|
|
|
50
50
|
"dependencies": {
|
|
51
51
|
"@solana/web3.js": "^1.91.8"
|
|
52
52
|
},
|
|
53
|
-
"stableVersion": "3.4.
|
|
53
|
+
"stableVersion": "3.4.1"
|
|
54
54
|
}
|