|
| 1 | +import * as Crypto from '@cardano-sdk/crypto'; |
| 2 | +import { BlockfrostClient, BlockfrostSharedWalletProvider } from '../../src'; |
| 3 | +import { logger } from '@cardano-sdk/util-dev'; |
| 4 | + |
| 5 | +const mockedResponses = [ |
| 6 | + { |
| 7 | + json_metadata: { |
| 8 | + description: 'd mb-s+lnx+tmt02', |
| 9 | + name: 'mb-s+lnx+tmt02', |
| 10 | + participants: {}, |
| 11 | + types: ['payment', 'stake'] |
| 12 | + }, |
| 13 | + tx_hash: 'c59b418d946b08554d8be35994420d0e9ba5b01a3cafb9979496f55b2fd9fda6' |
| 14 | + }, |
| 15 | + { |
| 16 | + json_metadata: { |
| 17 | + description: 'This is really a test wallet, I think with mb-s', |
| 18 | + name: 'Another test ms wallet', |
| 19 | + participants: {}, |
| 20 | + types: ['payment', 'stake'] |
| 21 | + }, |
| 22 | + tx_hash: '6c1a7652b189aaa3efe39e66c0ef8c894c6f6f8e37fceb58dc41064ac628a569' |
| 23 | + }, |
| 24 | + { |
| 25 | + json_metadata: { |
| 26 | + description: 'A Multi-Sig test wallet', |
| 27 | + name: 'MS Test', |
| 28 | + participants: { |
| 29 | + '35769ace6c241e0afe467b0a3577af9adea271fc971ba7770ac88712': { |
| 30 | + name: 'Wallet 1' |
| 31 | + }, |
| 32 | + '962746268ee907e18c895c9943c6684b01fa7a4956b0fe0fa76cfa6f': { |
| 33 | + name: 'Wallet 2' |
| 34 | + }, |
| 35 | + c87b02ef2bed963db3892031ce9387b7d65a83008bad072ddb7409d6: { |
| 36 | + name: 'Wallet 1' |
| 37 | + }, |
| 38 | + ebf94d78fb1b185f5b0136260d9192e1270c8303bba5155e773de3fb: { |
| 39 | + name: 'Wallet 2' |
| 40 | + } |
| 41 | + }, |
| 42 | + types: ['payment', 'stake'] |
| 43 | + }, |
| 44 | + tx_hash: '37bbd91b177e0716d5943fb3de8649c9dcabc844553e7656744ffca1c11efddc' |
| 45 | + }, |
| 46 | + { |
| 47 | + json_metadata: { |
| 48 | + description: 'A simple Multi-Sig wallet with 3/3 signatures needed.', |
| 49 | + name: 'MS Test 3/3', |
| 50 | + participants: { |
| 51 | + '7429c675051bb444a78d0850be2c45a48f8ed3d4ecdb6f059ed19873': { |
| 52 | + name: 'Wallet 3' |
| 53 | + }, |
| 54 | + '35769ace6c241e0afe467b0a3577af9adea271fc971ba7770ac88712': { |
| 55 | + name: 'Wallet 1' |
| 56 | + }, |
| 57 | + '15254521db8f70ac44aa585475361727e918465425d9fb53f0d754e3': { |
| 58 | + name: 'Wallet 3' |
| 59 | + }, |
| 60 | + '962746268ee907e18c895c9943c6684b01fa7a4956b0fe0fa76cfa6f': { |
| 61 | + name: 'Wallet 2' |
| 62 | + }, |
| 63 | + c87b02ef2bed963db3892031ce9387b7d65a83008bad072ddb7409d6: { |
| 64 | + name: 'Wallet 1' |
| 65 | + }, |
| 66 | + ebf94d78fb1b185f5b0136260d9192e1270c8303bba5155e773de3fb: { |
| 67 | + name: 'Wallet 2' |
| 68 | + } |
| 69 | + }, |
| 70 | + types: ['payment', 'stake'] |
| 71 | + }, |
| 72 | + tx_hash: '42c2eed5fabb3500b7b66e84c73d78633df567803f4a8afd38d485f71a7fcf84' |
| 73 | + }, |
| 74 | + { |
| 75 | + json_metadata: { |
| 76 | + description: 'A simple Multi-Sig wallet with 3/3 signatures needed', |
| 77 | + name: 'MS 3/3', |
| 78 | + participants: {}, |
| 79 | + types: ['payment', 'stake'] |
| 80 | + }, |
| 81 | + tx_hash: 'e51c93492c04fc6b8d475c5bbbac483961d1d2ebf592d019619cd199f17ed6f5' |
| 82 | + }, |
| 83 | + { |
| 84 | + json_metadata: { |
| 85 | + description: 'dsfdsfdsf', |
| 86 | + name: 'MS Test', |
| 87 | + participants: { |
| 88 | + '35769ace6c241e0afe467b0a3577af9adea271fc971ba7770ac88712': { |
| 89 | + name: 'sdfdsf' |
| 90 | + }, |
| 91 | + '962746268ee907e18c895c9943c6684b01fa7a4956b0fe0fa76cfa6f': { |
| 92 | + name: 'sdfsdf' |
| 93 | + }, |
| 94 | + c87b02ef2bed963db3892031ce9387b7d65a83008bad072ddb7409d6: { |
| 95 | + name: 'sdfdsf' |
| 96 | + }, |
| 97 | + ebf94d78fb1b185f5b0136260d9192e1270c8303bba5155e773de3fb: { |
| 98 | + name: 'sdfsdf' |
| 99 | + } |
| 100 | + }, |
| 101 | + types: ['payment', 'stake'] |
| 102 | + }, |
| 103 | + tx_hash: '0c746630f885213618db4af244a8d257e8c03a4041a0fcbece10abe0a6526f5d' |
| 104 | + }, |
| 105 | + { |
| 106 | + json_metadata: { |
| 107 | + description: 'L + T + K', |
| 108 | + name: 'HW MS Test', |
| 109 | + participants: { |
| 110 | + '7fb20197bb7e2c3b44539fb9784e70db308640c86a1ef45db711cd28': { |
| 111 | + name: 'Keystone' |
| 112 | + }, |
| 113 | + '9d237cfa3da50b71859ac7045e4d296252c85f7d72d4c5c889a8c22e': { |
| 114 | + name: 'Keystone' |
| 115 | + }, |
| 116 | + a4fb72bcb24a91cb1add70d3158704a4cf14a7909fbbe4edac39efb1: { |
| 117 | + name: 'Ledger' |
| 118 | + }, |
| 119 | + ad773cd4bdb0f775c53d34c48e70bd46f1856e21c8103f8d292fcc7a: { |
| 120 | + name: 'Ledger' |
| 121 | + }, |
| 122 | + afb321dabccdf5ea26ce4ac9c0cd5aaae6cb47a61e12cd8c8b3f41a0: { |
| 123 | + name: 'Trezor' |
| 124 | + }, |
| 125 | + cc9adac917b5a7e191982f1bb979507349e5ae59df8d015a2842f4bd: { |
| 126 | + name: 'Trezor' |
| 127 | + } |
| 128 | + }, |
| 129 | + types: ['payment', 'stake'] |
| 130 | + }, |
| 131 | + tx_hash: 'a160d298a6e49e6b39b33cde296baf171b2ad31c4520cbbc2086d99d3d64bc91' |
| 132 | + } |
| 133 | +]; |
| 134 | + |
| 135 | +describe('BlockfrostSharedWallet', () => { |
| 136 | + let request: jest.Mock; |
| 137 | + let provider: BlockfrostSharedWalletProvider; |
| 138 | + |
| 139 | + beforeEach(async () => { |
| 140 | + request = jest.fn(); |
| 141 | + const client = { request } as unknown as BlockfrostClient; |
| 142 | + provider = new BlockfrostSharedWalletProvider(client, logger); |
| 143 | + }); |
| 144 | + |
| 145 | + describe('discoverWallets', () => { |
| 146 | + it('should return an empty array if no wallets are found', () => { |
| 147 | + request.mockResolvedValueOnce(mockedResponses); |
| 148 | + return expect( |
| 149 | + provider.discoverWallets(Crypto.Ed25519KeyHashHex('0a0ba36b07e61f4b566a99521be1f8b2fdb1ce47246894807b63712b')) |
| 150 | + ).resolves.toEqual([]); |
| 151 | + }); |
| 152 | + |
| 153 | + it('should return all wallets for a given public key', async () => { |
| 154 | + request.mockResolvedValueOnce(mockedResponses); |
| 155 | + const pubKey = '962746268ee907e18c895c9943c6684b01fa7a4956b0fe0fa76cfa6f'; |
| 156 | + const wallets = await provider.discoverWallets(Crypto.Ed25519KeyHashHex(pubKey)); |
| 157 | + expect(wallets.length).toEqual(3); |
| 158 | + for (const wallet of wallets) { |
| 159 | + expect(wallet.json_metadata.participants).toHaveProperty(pubKey); |
| 160 | + } |
| 161 | + }); |
| 162 | + }); |
| 163 | +}); |
0 commit comments