-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathrecoveryMusigEth.test.ts
More file actions
158 lines (129 loc) · 4.16 KB
/
Copy pathrecoveryMusigEth.test.ts
File metadata and controls
158 lines (129 loc) · 4.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
import 'should';
import express from 'express';
import nock from 'nock';
import * as request from 'supertest';
import { app as advancedWalletManagerApp } from '../../../advancedWalletManagerApp';
import { AppMode, AdvancedWalletManagerConfig, TlsMode } from '../../../shared/types';
import * as sinon from 'sinon';
import * as configModule from '../../../initConfig';
import { awmData } from '../../mocks/ethRecoveryMusigMockData';
import unsignedSweepRecJSON from '../../mocks/unsigned-sweep-prebuild-hteth-musig-recovery.json';
describe('recoveryMultisigTransaction', () => {
let cfg: AdvancedWalletManagerConfig;
let app: express.Application;
let agent: request.SuperAgentTest;
// test cofig
const kmsUrl = 'http://kms.invalid';
const coin = 'hteth';
const accessToken = 'test-token';
// sinon stubs
let configStub: sinon.SinonStub;
before(() => {
// nock config
nock.disableNetConnect();
nock.enableNetConnect('127.0.0.1');
// app config
cfg = {
appMode: AppMode.ADVANCED_WALLET_MANAGER,
port: 0, // Let OS assign a free port
bind: 'localhost',
timeout: 60000,
httpLoggerFile: '',
kmsUrl: kmsUrl,
tlsMode: TlsMode.DISABLED,
allowSelfSigned: true,
recoveryMode: true,
};
configStub = sinon.stub(configModule, 'initConfig').returns(cfg);
// app setup
app = advancedWalletManagerApp(cfg);
agent = request.agent(app);
});
afterEach(() => {
nock.cleanAll();
});
after(() => {
configStub.restore();
});
it('should generate a successful txHex from unsigned sweep prebuild data', async () => {
const { userPub, backupPub, walletContractAddress, userPrv, backupPrv, txHexResult } = awmData;
const unsignedSweepPrebuildTx = unsignedSweepRecJSON as unknown as any;
const mockKmsUserResponse = {
prv: userPrv,
pub: userPub,
source: 'user',
type: 'independent',
};
const mockKmsBackupResponse = {
prv: backupPrv,
pub: backupPub,
source: 'backup',
type: 'independent',
};
const kmsNockUser = nock(kmsUrl)
.get(`/key/${userPub}`)
.query({ source: 'user' })
.reply(200, mockKmsUserResponse);
const kmsNockBackup = nock(kmsUrl)
.get(`/key/${backupPub}`)
.query({ source: 'backup' })
.reply(200, mockKmsBackupResponse);
const response = await agent
.post(`/api/${coin}/multisig/recovery`)
.set('Authorization', `Bearer ${accessToken}`)
.send({
userPub,
backupPub,
apiKey: 'etherscan-api-token',
unsignedSweepPrebuildTx,
walletContractAddress,
coinSpecificParams: undefined,
});
response.status.should.equal(200);
response.body.should.have.property('txHex', txHexResult);
kmsNockUser.done();
kmsNockBackup.done();
});
it('should fail when prv keys non related to pub keys', async () => {
const { userPub, backupPub, walletContractAddress } = awmData;
const unsignedSweepPrebuildTx = unsignedSweepRecJSON as unknown as any;
// Use invalid private keys
const invalidUserPrv = 'invalid-prv';
const invalidBackupPrv = 'invalid-prv';
const mockKmsUserResponse = {
prv: invalidUserPrv,
pub: userPub,
source: 'user',
type: 'independent',
};
const mockKmsBackupResponse = {
prv: invalidBackupPrv,
pub: backupPub,
source: 'backup',
type: 'independent',
};
const kmsNockUser = nock(kmsUrl)
.get(`/key/${userPub}`)
.query({ source: 'user' })
.reply(200, mockKmsUserResponse);
const kmsNockBackup = nock(kmsUrl)
.get(`/key/${backupPub}`)
.query({ source: 'backup' })
.reply(200, mockKmsBackupResponse);
const response = await agent
.post(`/api/${coin}/multisig/recovery`)
.set('Authorization', `Bearer ${accessToken}`)
.send({
userPub,
backupPub,
apiKey: 'etherscan-api-token',
unsignedSweepPrebuildTx,
walletContractAddress,
coinSpecificParams: undefined,
});
response.status.should.equal(500);
response.body.should.have.property('error');
kmsNockUser.done();
kmsNockBackup.done();
});
});