Skip to content

Commit 08c382f

Browse files
Merge pull request #5755 from BitGo/WP-3966
fix: ensure user params are used for tx verification
2 parents 673245f + b0ec18e commit 08c382f

File tree

2 files changed

+152
-1
lines changed

2 files changed

+152
-1
lines changed
Lines changed: 151 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,151 @@
1+
import * as sinon from 'sinon';
2+
import * as nock from 'nock';
3+
4+
import { Environments, Wallet } from '@bitgo/sdk-core';
5+
import { TestableBG, TestBitGo } from '@bitgo/sdk-test';
6+
7+
import { BitGo } from '../../../src';
8+
9+
nock.disableNetConnect();
10+
11+
describe('PrebuildAndSign', function () {
12+
const bitgo: TestableBG & BitGo = TestBitGo.decorate(BitGo, { env: 'test' });
13+
const bgUrl: string = Environments[bitgo.getEnv()].uri;
14+
15+
before(async function () {
16+
bitgo.initializeTestVars();
17+
});
18+
19+
afterEach(function () {
20+
sinon.restore();
21+
});
22+
23+
after(async function () {
24+
nock.cleanAll();
25+
});
26+
27+
describe('Account Based MultiSig Hot Wallets', function () {
28+
const coin = 'hteth';
29+
const walletId = '65f060a22df7cd8a42958441d4e90a45';
30+
const wallet = new Wallet(bitgo, bitgo.coin(coin), { id: walletId, coin, multisigType: 'on-chain' });
31+
32+
it('should validate build with user params', async function () {
33+
nock(bgUrl)
34+
.post(`/api/v2/${coin}/wallet/${walletId}/tx/build`)
35+
.reply(200, {
36+
feeInfo: {
37+
date: '2025-03-11T16:54:31.174Z',
38+
gasPrice: '2431332',
39+
baseFee: '1431332',
40+
gasUsedRatio: '0.847974014624559',
41+
safeLowMinerTip: '1000000',
42+
normalMinerTip: '1000000',
43+
standardMinerTip: '1000000',
44+
fastestMinerTip: '1000000',
45+
ludicrousMinerTip: '1000000',
46+
},
47+
eip1559: {
48+
maxPriorityFeePerGas: '1150000',
49+
maxFeePerGas: '4012664',
50+
},
51+
recipients: [
52+
{
53+
address: '0xe33e8728f320ccd98af20b19b333857ad2325f07',
54+
amount: '1000000000000000',
55+
},
56+
],
57+
nextContractSequenceId: 21,
58+
gasLimit: 200000,
59+
isBatch: false,
60+
coin: 'hteth',
61+
buildParams: {
62+
recipients: [
63+
{
64+
address: '0xe33e872',
65+
amount: '1000000',
66+
},
67+
],
68+
},
69+
});
70+
sinon.stub(wallet as any, 'getKeychainsAndValidatePassphrase').resolves([]);
71+
72+
await wallet
73+
.prebuildAndSignTransaction({
74+
recipients: [
75+
{
76+
address: '0xe33e872',
77+
amount: '1000000',
78+
},
79+
],
80+
})
81+
.should.be.rejectedWith(
82+
`normal transaction amount in txPrebuild received from BitGo servers does not match txParams supplied by client`
83+
);
84+
});
85+
86+
it('should validate that transaction is going to batcher for multiple recepients', async function () {
87+
nock(bgUrl)
88+
.post(`/api/v2/${coin}/wallet/${walletId}/tx/build`)
89+
.reply(200, {
90+
feeInfo: {
91+
date: '2025-03-12T18:38:11.627Z',
92+
gasPrice: '22051229178',
93+
baseFee: '21051229178',
94+
gasUsedRatio: '0.055718833333333335',
95+
safeLowMinerTip: '1000000000',
96+
normalMinerTip: '1250000000',
97+
standardMinerTip: '1250000000',
98+
fastestMinerTip: '1503782862',
99+
ludicrousMinerTip: '1503782862',
100+
},
101+
eip1559: {
102+
maxPriorityFeePerGas: '1437500000',
103+
maxFeePerGas: '43539958356',
104+
},
105+
recipients: [
106+
{
107+
address: '0xc1b7e7cc1ecafbfd0771a5eb5454ab5b0356980d',
108+
amount: '3000000000000000',
109+
data: '0xc00c4e9e000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000000000020000000000000000000000002669c843ef62adeff9915a36349ce2542f08d9760000000000000000000000003669c843ef62adeff9915a36349ce2542f08d976000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000038d7ea4c6800000000000000000000000000000000000000000000000000000038d7ea4c68000',
110+
},
111+
],
112+
nextContractSequenceId: 22,
113+
gasLimit: 200000,
114+
isBatch: true,
115+
coin: 'hteth',
116+
buildParams: {
117+
comment: '',
118+
recipients: [
119+
{
120+
address: '0x2669c843ef62AdEFF9915a36349cE2542F08D976',
121+
amount: '2000000000000000',
122+
},
123+
{
124+
address: '0x3669c843ef62AdEFF9915a36349cE2542F08D976',
125+
amount: '1000000000000000',
126+
},
127+
],
128+
},
129+
});
130+
sinon.stub(wallet as any, 'getKeychainsAndValidatePassphrase').resolves([]);
131+
132+
await wallet
133+
.prebuildAndSignTransaction({
134+
comment: '',
135+
recipients: [
136+
{
137+
address: '0x2669c843ef62AdEFF9915a36349cE2542F08D976',
138+
amount: '1000000000000000',
139+
},
140+
{
141+
address: '0x3669c843ef62AdEFF9915a36349cE2542F08D976',
142+
amount: '1000000000000000',
143+
},
144+
],
145+
})
146+
.should.be.rejectedWith(
147+
`batch transaction amount in txPrebuild received from BitGo servers does not match txParams supplied by client`
148+
);
149+
});
150+
});
151+
});

modules/sdk-core/src/bitgo/wallet/wallet.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2147,7 +2147,7 @@ export class Wallet implements IWallet {
21472147

21482148
try {
21492149
await this.baseCoin.verifyTransaction({
2150-
txParams: txPrebuild.buildParams || params,
2150+
txParams: { ...txPrebuild.buildParams, ...params },
21512151
txPrebuild,
21522152
wallet: this,
21532153
verification: params.verification ?? {},

0 commit comments

Comments
 (0)