|
| 1 | +import { test, expect } from '@playwright/test'; |
| 2 | +import { User, ChainIds } from '@summer_fi/sdk-client'; |
| 3 | +import { sdk } from '../../utils'; |
| 4 | + |
| 5 | +const token = ({ chainId, name }: { chainId: 1 | 8453; name: 'Mainnet' | 'Base' }) => ({ |
| 6 | + symbol: expect.any(String), |
| 7 | + name: expect.any(String), |
| 8 | + chainInfo: { chainId, name }, |
| 9 | + address: { |
| 10 | + value: expect.any(String), |
| 11 | + type: 'Ethereum', |
| 12 | + }, |
| 13 | + decimals: expect.any(Number), |
| 14 | +}); |
| 15 | + |
| 16 | +const expectedResponse = ({ chainId, name }: { chainId: 1 | 8453; name: 'Mainnet' | 'Base' }) => |
| 17 | + expect.arrayContaining([ |
| 18 | + expect.objectContaining({ |
| 19 | + type: 'Armada', |
| 20 | + id: expect.objectContaining({ |
| 21 | + id: expect.stringContaining('0x10649c79428d718621821cf6299e91920284743f-'), |
| 22 | + type: 'Armada', |
| 23 | + user: expect.objectContaining({ |
| 24 | + wallet: { |
| 25 | + address: { |
| 26 | + value: '0x10649c79428d718621821Cf6299e91920284743F', |
| 27 | + type: 'Ethereum', |
| 28 | + }, |
| 29 | + }, |
| 30 | + chainInfo: { chainId, name }, |
| 31 | + }), |
| 32 | + }), |
| 33 | + pool: expect.objectContaining({ |
| 34 | + type: 'Armada', |
| 35 | + id: expect.objectContaining({ |
| 36 | + type: 'Armada', |
| 37 | + chainInfo: { chainId, name }, |
| 38 | + fleetAddress: { value: expect.any(String), type: 'Ethereum' }, |
| 39 | + protocol: { |
| 40 | + chainInfo: { chainId, name }, |
| 41 | + name: 'Armada', |
| 42 | + }, |
| 43 | + }), |
| 44 | + }), |
| 45 | + assets: { |
| 46 | + token: token({ chainId, name }), |
| 47 | + amount: expect.any(String), |
| 48 | + _baseUnitFactor: expect.any(String), |
| 49 | + }, |
| 50 | + assetPriceUSD: { fiat: 'USD', amount: expect.any(String) }, |
| 51 | + assetsUSD: { |
| 52 | + fiat: 'USD', |
| 53 | + amount: expect.any(String), |
| 54 | + }, |
| 55 | + shares: { |
| 56 | + token: token({ chainId, name }), |
| 57 | + amount: expect.any(String), |
| 58 | + _baseUnitFactor: expect.any(String), |
| 59 | + }, |
| 60 | + depositsAmount: { |
| 61 | + token: token({ chainId, name }), |
| 62 | + amount: expect.any(String), |
| 63 | + _baseUnitFactor: expect.any(String), |
| 64 | + }, |
| 65 | + depositsAmountUSD: { |
| 66 | + fiat: 'USD', |
| 67 | + amount: expect.any(String), |
| 68 | + }, |
| 69 | + withdrawalsAmount: { |
| 70 | + token: token({ chainId, name }), |
| 71 | + amount: expect.any(String), |
| 72 | + _baseUnitFactor: expect.any(String), |
| 73 | + }, |
| 74 | + withdrawalsAmountUSD: { fiat: 'USD', amount: expect.any(String) }, |
| 75 | + netDeposits: { |
| 76 | + token: token({ chainId, name }), |
| 77 | + amount: expect.any(String), |
| 78 | + _baseUnitFactor: expect.any(String), |
| 79 | + }, |
| 80 | + netDepositsUSD: { fiat: 'USD', amount: expect.any(String) }, |
| 81 | + earnings: { |
| 82 | + token: token({ chainId, name }), |
| 83 | + amount: expect.any(String), |
| 84 | + _baseUnitFactor: expect.any(String), |
| 85 | + }, |
| 86 | + earningsUSD: { fiat: 'USD', amount: expect.any(String) }, |
| 87 | + claimedSummerToken: { |
| 88 | + token: token({ chainId, name }), |
| 89 | + amount: expect.any(String), |
| 90 | + _baseUnitFactor: expect.any(String), |
| 91 | + }, |
| 92 | + claimableSummerToken: { |
| 93 | + token: token({ chainId, name }), |
| 94 | + amount: expect.any(String), |
| 95 | + _baseUnitFactor: expect.any(String), |
| 96 | + }, |
| 97 | + rewards: [ |
| 98 | + { |
| 99 | + claimed: { |
| 100 | + token: token({ chainId, name }), |
| 101 | + amount: expect.any(String), |
| 102 | + _baseUnitFactor: expect.any(String), |
| 103 | + }, |
| 104 | + claimable: { |
| 105 | + token: token({ chainId, name }), |
| 106 | + amount: expect.any(String), |
| 107 | + _baseUnitFactor: expect.any(String), |
| 108 | + }, |
| 109 | + }, |
| 110 | + ], |
| 111 | + amount: { |
| 112 | + token: token({ chainId, name }), |
| 113 | + amount: expect.any(String), |
| 114 | + _baseUnitFactor: expect.any(String), |
| 115 | + }, |
| 116 | + deposits: [], |
| 117 | + withdrawals: [], |
| 118 | + }), |
| 119 | + ]); |
| 120 | + |
| 121 | +test.describe('getUserPositions', () => { |
| 122 | + test('Mainnet positions', async () => { |
| 123 | + // Create a user using chainId and wallet address |
| 124 | + const user = User.createFromEthereum( |
| 125 | + ChainIds.Mainnet, |
| 126 | + '0x10649c79428d718621821Cf6299e91920284743F', |
| 127 | + ); |
| 128 | + |
| 129 | + // Retrieve all user positions on Mainnet |
| 130 | + const positions = await sdk.armada.users.getUserPositions({ |
| 131 | + user, |
| 132 | + }); |
| 133 | + |
| 134 | + // Validate the response |
| 135 | + expect(positions, 'The response should be defined').toBeDefined(); |
| 136 | + expect(positions.length).toBe(7); |
| 137 | + expect(positions).toEqual(expectedResponse({ chainId: 1, name: 'Mainnet' })); |
| 138 | + }); |
| 139 | + |
| 140 | + test('Base positions', async () => { |
| 141 | + // Create a user using chainId and wallet address |
| 142 | + const user = User.createFromEthereum( |
| 143 | + ChainIds.Base, |
| 144 | + '0x10649c79428d718621821Cf6299e91920284743F', |
| 145 | + ); |
| 146 | + |
| 147 | + // Retrieve all user positions on Mainnet |
| 148 | + const positions = await sdk.armada.users.getUserPositions({ |
| 149 | + user, |
| 150 | + }); |
| 151 | + |
| 152 | + // Validate the response |
| 153 | + expect(positions, 'The response should be defined').toBeDefined(); |
| 154 | + expect(positions.length).toBe(3); |
| 155 | + expect(positions).toEqual(expectedResponse({ chainId: 8453, name: 'Base' })); |
| 156 | + }); |
| 157 | +}); |
| 158 | + |
| 159 | +test.describe('getUserPositions - Negative scenarios', () => { |
| 160 | + test('User undefined', async () => { |
| 161 | + try { |
| 162 | + await sdk.armada.users.getUserPositions({ |
| 163 | + // @ts-ignore |
| 164 | + user: undefined, |
| 165 | + }); |
| 166 | + throw new Error('Should have thrown a TRPCClientError'); |
| 167 | + } catch (error: any) { |
| 168 | + expect(error.name).toBe('TRPCClientError'); |
| 169 | + expect(error.data).toMatchObject({ |
| 170 | + code: 'BAD_REQUEST', |
| 171 | + httpStatus: 400, |
| 172 | + }); |
| 173 | + } |
| 174 | + }); |
| 175 | +}); |
0 commit comments