|
| 1 | +import 'should'; |
| 2 | +import { ApiVersion, IWallet } from '../../../../src'; |
| 3 | +import { getTxRequestApiVersion } from '../../../../src/bitgo/utils/txRequest'; |
| 4 | + |
| 5 | +describe('txRequest utils', () => { |
| 6 | + describe('getTxRequestApiVersion', function () { |
| 7 | + const testCases = [ |
| 8 | + { |
| 9 | + wallet: { |
| 10 | + baseCoin: { getMPCAlgorithm: () => 'ecdsa' }, |
| 11 | + type: () => 'hot', |
| 12 | + multisigType: () => 'tss', |
| 13 | + } as any as IWallet, |
| 14 | + requestedApiVersion: 'lite', |
| 15 | + expectedApiVersion: '', |
| 16 | + expectedErrorMessage: 'For ECDSA tss wallets, parameter `apiVersion` must be `full`.', |
| 17 | + }, |
| 18 | + { |
| 19 | + wallet: { |
| 20 | + baseCoin: { getMPCAlgorithm: () => 'eddsa' }, |
| 21 | + type: () => 'cold', |
| 22 | + multisigType: () => 'tss', |
| 23 | + } as any as IWallet, |
| 24 | + requestedApiVersion: 'lite', |
| 25 | + expectedApiVersion: '', |
| 26 | + expectedErrorMessage: 'For non self-custodial (hot) tss wallets, parameter `apiVersion` must be `full`.', |
| 27 | + }, |
| 28 | + { |
| 29 | + wallet: { |
| 30 | + baseCoin: { getMPCAlgorithm: () => 'eddsa' }, |
| 31 | + type: () => 'hot', |
| 32 | + multisigType: () => 'tss', |
| 33 | + } as any as IWallet, |
| 34 | + requestedApiVersion: undefined, |
| 35 | + expectedApiVersion: 'lite', |
| 36 | + expectedErrorMessage: '', |
| 37 | + }, |
| 38 | + ...['hot', 'cold', 'custodial', 'backing'].map((walletType) => { |
| 39 | + return { |
| 40 | + wallet: { |
| 41 | + baseCoin: { getMPCAlgorithm: () => 'ecdsa' }, |
| 42 | + type: () => walletType, |
| 43 | + multisigType: () => 'tss', |
| 44 | + } as any as IWallet, |
| 45 | + requestedApiVersion: 'full', |
| 46 | + expectedApiVersion: 'full', |
| 47 | + expectedErrorMessage: '', |
| 48 | + shouldThrow: false, |
| 49 | + }; |
| 50 | + }), |
| 51 | + ...['hot', 'cold', 'custodial', 'backing'].map((walletType) => { |
| 52 | + return { |
| 53 | + wallet: { |
| 54 | + baseCoin: { getMPCAlgorithm: () => 'ecdsa' }, |
| 55 | + type: () => walletType, |
| 56 | + multisigType: () => 'tss', |
| 57 | + } as any as IWallet, |
| 58 | + requestedApiVersion: undefined, |
| 59 | + expectedApiVersion: 'full', |
| 60 | + expectedErrorMessage: '', |
| 61 | + shouldThrow: false, |
| 62 | + }; |
| 63 | + }), |
| 64 | + ...['hot', 'cold', 'custodial', 'backing'].map((walletType) => { |
| 65 | + return { |
| 66 | + wallet: { |
| 67 | + baseCoin: { getMPCAlgorithm: () => 'eddsa' }, |
| 68 | + type: () => walletType, |
| 69 | + multisigType: () => 'tss', |
| 70 | + } as any as IWallet, |
| 71 | + requestedApiVersion: 'full', |
| 72 | + expectedApiVersion: 'full', |
| 73 | + expectedErrorMessage: '', |
| 74 | + shouldThrow: false, |
| 75 | + }; |
| 76 | + }), |
| 77 | + ...['cold', 'custodial', 'backing'].map((walletType) => { |
| 78 | + return { |
| 79 | + wallet: { |
| 80 | + baseCoin: { getMPCAlgorithm: () => 'eddsa' }, |
| 81 | + type: () => walletType, |
| 82 | + multisigType: () => 'tss', |
| 83 | + } as any as IWallet, |
| 84 | + requestedApiVersion: undefined, |
| 85 | + expectedApiVersion: 'full', |
| 86 | + expectedErrorMessage: '', |
| 87 | + shouldThrow: false, |
| 88 | + }; |
| 89 | + }), |
| 90 | + ]; |
| 91 | + |
| 92 | + testCases.forEach((testCase) => { |
| 93 | + if (testCase.expectedErrorMessage) { |
| 94 | + it(`should throw an error if requested apiVersion is ${ |
| 95 | + testCase.requestedApiVersion |
| 96 | + } for wallet type ${testCase.wallet.type()} for a ${testCase.wallet.baseCoin.getMPCAlgorithm()} wallet`, () => { |
| 97 | + (() => |
| 98 | + getTxRequestApiVersion( |
| 99 | + testCase.wallet, |
| 100 | + testCase.requestedApiVersion as ApiVersion | undefined |
| 101 | + )).should.throw(testCase.expectedErrorMessage); |
| 102 | + }); |
| 103 | + } else { |
| 104 | + it(`should return ${testCase.expectedApiVersion} if requested apiVersion is ${ |
| 105 | + testCase.requestedApiVersion |
| 106 | + } for wallet type ${testCase.wallet.type()} for a ${testCase.wallet.baseCoin.getMPCAlgorithm()} wallet`, () => { |
| 107 | + getTxRequestApiVersion(testCase.wallet, testCase.requestedApiVersion as ApiVersion | undefined).should.equal( |
| 108 | + testCase.expectedApiVersion |
| 109 | + ); |
| 110 | + }); |
| 111 | + } |
| 112 | + }); |
| 113 | + }); |
| 114 | +}); |
0 commit comments