Skip to content

test: add integration test for tx acceleration#222

Merged
danielpeng1 merged 2 commits into
masterfrom
WCN-768/accelerate-integ-test
Jun 5, 2026
Merged

test: add integration test for tx acceleration#222
danielpeng1 merged 2 commits into
masterfrom
WCN-768/accelerate-integ-test

Conversation

@danielpeng1
Copy link
Copy Markdown
Contributor

Adding end-to-end accelerate integration tests for tbtc CPFP in both local and external signing modes.

  • accelerate.integ.test.ts with EXTERNAL and LOCAL describes, asserting txid/tx and key provider + BitGo call counts
  • Added accelerate-specific prebuild fixture (prebuildTx.accelerate.tbtc.json) since accelerate builds via CPFP/RBF params, not recipients, so verifyTransaction runs with an empty recipient list
  • mockBitgoServer returns the accelerate prebuild when tx/build includes cpfpTxIds or rbfTxIds (although I think this could use a small refactor if something is added to this next time)
  • Tests pass (npm run docker:test:integration shown here):
Screenshot 2026-06-04 at 11 32 30 PM

Ticket: WCN-768

@danielpeng1 danielpeng1 self-assigned this Jun 5, 2026
@linear-code
Copy link
Copy Markdown

linear-code Bot commented Jun 5, 2026

WCN-768

@danielpeng1 danielpeng1 marked this pull request as ready for review June 5, 2026 04:42
@danielpeng1 danielpeng1 requested a review from a team as a code owner June 5, 2026 04:42
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) };
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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]);

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks; changed here and for local signing.

Copy link
Copy Markdown
Contributor

@pranishnepal pranishnepal left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚀

@danielpeng1 danielpeng1 merged commit 2d9da33 into master Jun 5, 2026
21 checks passed
@danielpeng1 danielpeng1 deleted the WCN-768/accelerate-integ-test branch June 5, 2026 14:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants