test: add integration test for tx acceleration#222
Merged
Conversation
pranishnepal
requested changes
Jun 5, 2026
Comment on lines
4
to
129
| import { listen, close } from './servers'; | ||
|
|
||
| export interface MockBitgoCall { | ||
| method: string; | ||
| path: string; | ||
| body: unknown; | ||
| } | ||
|
|
||
| export interface MockBitgoServer { | ||
| port: number; | ||
| calls: MockBitgoCall[]; | ||
| close(): Promise<void>; | ||
| } | ||
|
|
||
| const FIXTURES_DIR = path.resolve(__dirname, '../fixtures/bitgo'); | ||
|
|
||
| function loadFixture(name: string): Record<string, unknown> { | ||
| return require(`${FIXTURES_DIR}/${name}.json`); | ||
| } | ||
|
|
||
| type SendManyFixtureMethod = 'getWallet' | 'prebuildTx' | 'sendTx'; | ||
| type SupportedCoin = 'hteth' | 'tbtc'; | ||
| type CoinToFixtures<C extends SupportedCoin> = { | ||
| [K in SendManyFixtureMethod]: `${K}.${C}`; | ||
| }; | ||
| } & { acceleratePrebuildTx: string }; | ||
|
|
||
| /** Registry — add a new coin here to support it across all sendMany integ test routes */ | ||
| const COIN_FIXTURES: { [C in SupportedCoin]: CoinToFixtures<C> } = { | ||
| hteth: { getWallet: 'getWallet.hteth', prebuildTx: 'prebuildTx.hteth', sendTx: 'sendTx.hteth' }, | ||
| tbtc: { getWallet: 'getWallet.tbtc', prebuildTx: 'prebuildTx.tbtc', sendTx: 'sendTx.tbtc' }, | ||
| hteth: { | ||
| getWallet: 'getWallet.hteth', | ||
| prebuildTx: 'prebuildTx.hteth', | ||
| sendTx: 'sendTx.hteth', | ||
| acceleratePrebuildTx: 'prebuildTx.hteth', // CPFP/RBF not applicable to EVM; reuses standard prebuild | ||
| }, | ||
| tbtc: { | ||
| getWallet: 'getWallet.tbtc', | ||
| prebuildTx: 'prebuildTx.tbtc', | ||
| sendTx: 'sendTx.tbtc', | ||
| acceleratePrebuildTx: 'prebuildTx.accelerate.tbtc', | ||
| }, | ||
| }; | ||
|
|
||
| function coinFixtures(coin: string): CoinToFixtures<SupportedCoin> { | ||
| const fixtures = COIN_FIXTURES[coin as SupportedCoin]; | ||
| if (!fixtures) throw new Error(`No fixtures registered for coin: ${coin}`); | ||
| return fixtures; | ||
| } | ||
|
|
||
| export async function startMockBitgoServer(): Promise<MockBitgoServer> { | ||
| const calls: MockBitgoCall[] = []; | ||
|
|
||
| const app = express(); | ||
| app.use(express.json()); | ||
|
|
||
| app.use((req, _res, next) => { | ||
| calls.push({ method: req.method, path: req.path, body: req.body }); | ||
| next(); | ||
| }); | ||
|
|
||
| /** SDK calls this on every BitGo instance initialisation */ | ||
| app.get('/api/v1/client/constants', (_req, res) => { | ||
| res.json({ ttl: 3600, constants: {} }); | ||
| }); | ||
|
|
||
| /** Add keychain — source distinguishes user / backup / bitgo */ | ||
| app.post('/api/v2/:coin/key', (req, res) => { | ||
| const { coin } = req.params; | ||
| const source = req.body?.source; | ||
| const fixtureName = | ||
| source === 'user' ? 'addKey.user' : source === 'backup' ? 'addKey.backup' : 'addKey.bitgo'; | ||
| const fixture = loadFixture(fixtureName); | ||
| return res.json({ ...fixture, coin }); | ||
| }); | ||
|
|
||
| /** Create wallet */ | ||
| app.post('/api/v2/:coin/wallet/add', (req, res) => { | ||
| const { coin } = req.params; | ||
| const fixture = loadFixture('createWallet'); | ||
| res.json({ ...fixture, coin }); | ||
| }); | ||
|
|
||
| /** Get wallet — coin-specific fixture */ | ||
| app.get('/api/v2/:coin/wallet/:walletId', (req, res) => { | ||
| const { coin } = req.params; | ||
| const fixture = loadFixture(coinFixtures(coin).getWallet); | ||
| res.json({ ...fixture, coin }); | ||
| }); | ||
|
|
||
| /** Get keychain — matched by keyId */ | ||
| app.get('/api/v2/:coin/key/:keyId', (req, res) => { | ||
| const { keyId, coin } = req.params; | ||
| const fixtureName = | ||
| keyId === 'user-key-id' | ||
| ? 'getKeychain.user' | ||
| : keyId === 'backup-key-id' | ||
| ? 'getKeychain.backup' | ||
| : 'getKeychain.bitgo'; | ||
| const fixture = loadFixture(fixtureName); | ||
| res.json({ ...fixture, coin }); | ||
| }); | ||
|
|
||
| /** Block height for fee estimation */ | ||
| app.get('/api/v2/:coin/public/block/latest', (_req, res) => { | ||
| res.json(loadFixture('blockLatest')); | ||
| }); | ||
|
|
||
| /** Transaction prebuild — coin-specific fixture */ | ||
| app.post('/api/v2/:coin/wallet/:walletId/tx/build', (req, res) => { | ||
| res.json(loadFixture(coinFixtures(req.params.coin).prebuildTx)); | ||
| const { coin } = req.params; | ||
| const isAccelerate = req.body?.cpfpTxIds?.length || req.body?.rbfTxIds?.length; | ||
| const fixtureName = isAccelerate | ||
| ? coinFixtures(coin).acceleratePrebuildTx | ||
| : coinFixtures(coin).prebuildTx; | ||
| res.json(loadFixture(fixtureName)); | ||
| }); | ||
|
|
||
| /** Transaction submit — coin-specific fixture */ | ||
| app.post('/api/v2/:coin/wallet/:walletId/tx/send', (req, res) => { | ||
| res.json(loadFixture(coinFixtures(req.params.coin).sendTx)); | ||
| }); | ||
|
|
||
| const server = http.createServer(app); | ||
| const port = await listen(server); | ||
|
|
||
| return { port, calls, close: () => close(server) }; | ||
| } |
Contributor
There was a problem hiding this comment.
type CoinToFixtures<C extends SupportedCoin> = {
[K in SendManyFixtureMethod]: `${K}.${C}`;
acceleratePrebuildTx: `prebuildTx.accelerate.${C}` | `prebuildTx.${C}`;
};
keeps makes this type safe - let's keep it consistent with the pattern i set before
Contributor
Author
There was a problem hiding this comment.
thanks for the correct type!
| services.keyProvider.calls.filter((c) => c.path === '/key').should.have.length(0); | ||
|
|
||
| /** BitGo must receive tx/build, block/latest, and tx/send */ | ||
| services.bitgo.calls.filter((c) => c.path.endsWith('/tx/build')).should.have.length(1); |
Contributor
There was a problem hiding this comment.
can assert on what was passed here, for example:
const buildBody = buildCalls[0].body as { cpfpTxIds?: string[] };
buildBody.should.have.property('cpfpTxIds').which.deepEqual([CPFP_TX_ID]);
Contributor
Author
There was a problem hiding this comment.
Thanks; changed here and for local signing.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adding end-to-end accelerate integration tests for tbtc CPFP in both local and external signing modes.
accelerate.integ.test.tswith EXTERNAL and LOCAL describes, asserting txid/tx and key provider + BitGo call countsprebuildTx.accelerate.tbtc.json) since accelerate builds via CPFP/RBF params, notrecipients, soverifyTransactionruns with an empty recipient listmockBitgoServerreturns the accelerate prebuild whentx/buildincludescpfpTxIdsorrbfTxIds(although I think this could use a small refactor if something is added to this next time)npm run docker:test:integrationshown here):Ticket: WCN-768