-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaccelerate.integ.test.ts
More file actions
145 lines (123 loc) · 5.35 KB
/
accelerate.integ.test.ts
File metadata and controls
145 lines (123 loc) · 5.35 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
import 'should';
import { startServices, IntegServices } from './helpers/setup';
import { LOCALHOST } from './helpers/servers';
import { SigningMode } from '../../shared/types';
/**
* Deterministic test keypair derived from Buffer.alloc(64, 0x42) — a public, reproducible seed.
* Not a secret. Never funded. Matches getKeychain.user.json and prebuildTx.tbtc.json.
*/
const USER_XPUB =
'xpub661MyMwAqRbcEvJQx6spkkHLRgtjxmVdyDSvbDt2m9NFpbkHdcu5WJsHHHqFxNATbNHnhMWJiwckoMqF75EpcNhU9xeVM4oDS7urM3os4BH';
const USER_XPRV =
'xprv9s21ZrQH143K2SDwr5LpPcLbsf4FZJmnbzXKnqURCoqGwoR965apxWYoS2DKu2ivcMTB9uTK6XhZDEPfTeNXGf7mmACuMN6cFS5ttmrpZ3i';
const WALLET_ID = 'test-wallet-id';
const CPFP_TX_ID = 'b8a828b98dbf32d9fd1875cbace9640ceb8c82626716b4a64203fdc79bb46d26';
const accelerateRequestBody = {
pubkey: USER_XPUB,
source: 'user' as const,
cpfpTxIds: [CPFP_TX_ID],
cpfpFeeRate: 50,
maxFee: 10000,
};
describe('Accelerate: EXTERNAL signing', () => {
let services: IntegServices;
before(async () => {
services = await startServices({ signingMode: SigningMode.EXTERNAL });
});
after(async () => {
await services.teardown();
});
beforeEach(() => {
services.keyProvider.calls.length = 0;
services.bitgo.calls.length = 0;
});
it('accelerates a tbtc transaction via CPFP using external key provider', async () => {
const res = await fetch(
`http://${LOCALHOST}:${services.mbePort}/api/v1/tbtc/advancedwallet/${WALLET_ID}/accelerate`,
{
method: 'POST',
headers: { 'Content-Type': 'application/json', Authorization: 'Bearer test-token' },
body: JSON.stringify(accelerateRequestBody),
},
);
res.status.should.equal(200);
const body = (await res.json()) as { txid: string; tx: string; status: string };
body.should.have.property('txid', 'test-tx-id');
body.should.have.property('tx', '01000000000101030a0000');
body.should.have.property('status', 'signed');
/**
* In external mode, AWM delegates signing to the key provider.
* POST /sign must be called — not POST /key (no local key retrieval for signing).
*/
services.keyProvider.calls.filter((c) => c.path === '/sign').should.have.length(1);
services.keyProvider.calls.filter((c) => c.path === '/key').should.have.length(0);
/** BitGo must receive tx/build with the correct cpfpTxIds, block/latest, and tx/send */
const buildCalls = services.bitgo.calls.filter((c) => c.path.endsWith('/tx/build'));
buildCalls.should.have.length(1);
const buildBody = buildCalls[0].body as { cpfpTxIds?: string[] };
buildBody.should.have.property('cpfpTxIds').which.deepEqual([CPFP_TX_ID]);
services.bitgo.calls
.filter((c) => c.path.endsWith('/public/block/latest'))
.should.have.length(1);
services.bitgo.calls.filter((c) => c.path.endsWith('/tx/send')).should.have.length(1);
});
});
describe('Accelerate: LOCAL signing', () => {
let services: IntegServices;
before(async () => {
services = await startServices({ signingMode: SigningMode.LOCAL });
/**
* Seed the mock key provider with a known xprv so AWM can retrieve it
* via GET /key/:pub and sign the PSBT locally. The xpub must match
* getKeychain.user.json and prebuildTx.accelerate.tbtc.json.
*/
await fetch(`http://127.0.0.1:${services.keyProvider.port}/key`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
pub: USER_XPUB,
prv: USER_XPRV,
coin: 'tbtc',
source: 'user',
type: 'independent',
}),
});
});
after(async () => {
await services.teardown();
});
beforeEach(() => {
services.keyProvider.calls.length = 0;
services.bitgo.calls.length = 0;
});
it('accelerates a tbtc transaction via CPFP using locally stored xprv', async () => {
const res = await fetch(
`http://${LOCALHOST}:${services.mbePort}/api/v1/tbtc/advancedwallet/${WALLET_ID}/accelerate`,
{
method: 'POST',
headers: { 'Content-Type': 'application/json', Authorization: 'Bearer test-token' },
body: JSON.stringify(accelerateRequestBody),
},
);
res.status.should.equal(200);
const body = (await res.json()) as { txid: string; tx: string; status: string };
body.should.have.property('txid', 'test-tx-id');
body.should.have.property('tx', '01000000000101030a0000');
body.should.have.property('status', 'signed');
/**
* In local mode, AWM retrieves the xprv via GET /key/:pub and signs internally.
* POST /sign must NOT be called — signing happens inside AWM, not in the key provider.
*/
services.keyProvider.calls.filter((c) => c.path === '/sign').should.have.length(0);
services.keyProvider.calls.filter((c) => c.path.startsWith('/key/')).length.should.be.above(0);
/** BitGo must receive tx/build with the correct cpfpTxIds, block/latest, and tx/send */
const buildCalls = services.bitgo.calls.filter((c) => c.path.endsWith('/tx/build'));
buildCalls.should.have.length(1);
const buildBody = buildCalls[0].body as { cpfpTxIds?: string[] };
buildBody.should.have.property('cpfpTxIds').which.deepEqual([CPFP_TX_ID]);
services.bitgo.calls
.filter((c) => c.path.endsWith('/public/block/latest'))
.should.have.length(1);
services.bitgo.calls.filter((c) => c.path.endsWith('/tx/send')).should.have.length(1);
});
});