Skip to content

Commit 3ebcae0

Browse files
chore: pass EthLikeCommon in explainTransaction
TICKET: COIN-2736
1 parent 01f5d55 commit 3ebcae0

File tree

3 files changed

+43
-3
lines changed

3 files changed

+43
-3
lines changed

modules/abstract-eth/src/abstractEthLikeCoin.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/**
22
* @prettier
33
*/
4-
import EthereumCommon from '@ethereumjs/common';
4+
import type * as EthLikeCommon from '@ethereumjs/common';
55
import { CoinFamily, BaseCoin as StaticsBaseCoin } from '@bitgo/statics';
66
import { bip32 } from '@bitgo/utxo-lib';
77
import { randomBytes } from 'crypto';
@@ -58,6 +58,7 @@ export interface ExplainTransactionOptions {
5858
txHex: string;
5959
};
6060
feeInfo: TransactionFee;
61+
common?: EthLikeCommon.default;
6162
}
6263

6364
export interface HalfSignedEthLikeTransaction extends HalfSignedAccountTransaction {
@@ -195,7 +196,7 @@ export abstract class AbstractEthLikeCoin extends BaseCoin {
195196
if (!txHex || !params.feeInfo) {
196197
throw new Error('missing explain tx parameters');
197198
}
198-
const txBuilder = this.getTransactionBuilder();
199+
const txBuilder = this.getTransactionBuilder(params.common);
199200
txBuilder.from(txHex);
200201
const tx = await txBuilder.build();
201202
const outputs = tx.outputs.map((output) => {
@@ -224,5 +225,5 @@ export abstract class AbstractEthLikeCoin extends BaseCoin {
224225
* Create a new transaction builder for the current chain
225226
* @return a new transaction builder
226227
*/
227-
protected abstract getTransactionBuilder(common?: EthereumCommon): TransactionBuilder;
228+
protected abstract getTransactionBuilder(common?: EthLikeCommon.default): TransactionBuilder;
228229
}

modules/sdk-coin-ethlike/test/fixtures/ethlikeCoin.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,11 @@ export const ccr = {
6161
'0xf9012e018541314cf000836acfc0948ce59c2d1702844f8eded451aa103961bc37b4e880b9010439125215000000000000000000000000eeaf0f05f37891ab4a21208b105a0687d12c5af7000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000c00000000000000000000000000000000000000000000000000000000000002710000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000e000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000830cddff8080',
6262
txid: '0xc6cff6f06e0452f85886c1e4f212a3fe444fe981939f80d8aad98e9a8507e526',
6363
},
64+
tbaseeth: {
65+
txHex:
66+
'0x02f9019683014a3402850ba43b740085746a5288008307a1209412fdf58540285273f9ddee9eac6f566418d6e7ac80b9016439125215000000000000000000000000b9f62c71d5f6949cfb211a67fb13ccf079cc760b00000000000000000000000000000000000000000000000000005af3107a400000000000000000000000000000000000000000000000000000000000000000c00000000000000000000000000000000000000000000000000000000066cc72e2000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000e0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000410eddb08026d2d5ba942ed77d4caef5bf3c3d7b4282bd4d2defcbc9c113c5f9af10d803b211fc0ea8b16263a614444abfc5d20dea24db28b833c0e15063400c411c00000000000000000000000000000000000000000000000000000000000000c0808080',
67+
txid: '0x663729bbb68b7638a7a58194e69546d64bb5536422f30557ef0118028317f3a8',
68+
},
6469
};
6570
export const encryptedUserKey =
6671
'{"iv":"VFZ3jvXhxo1Z+Yaf2MtZnA==","v":1,"iter":10000,"ks":256,"ts":64,"mode"\n' +

modules/sdk-coin-ethlike/test/unit/ethlikeCoin.ts

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,40 @@ describe('EthLikeCoin', function () {
213213
assert(fullSignedTxn.txHex);
214214
});
215215

216+
describe('explainTransaction', function () {
217+
const txHex = mockData.ccr[coinName].txHex;
218+
const feeInfo = {
219+
fee: '1000000000',
220+
gasLimit: '100000',
221+
};
222+
223+
it('should explain transaction when common is provided', async function () {
224+
const explanation = await basecoin.explainTransaction({
225+
txHex,
226+
feeInfo,
227+
common: baseChainCommon,
228+
});
229+
230+
explanation.should.have.property('id');
231+
explanation.should.have.property('outputs');
232+
explanation.should.have.property('outputAmount');
233+
explanation.should.have.property('changeOutputs');
234+
explanation.should.have.property('changeAmount');
235+
explanation.should.have.property('fee');
236+
explanation.fee.should.equal(feeInfo);
237+
explanation.outputs.should.be.an.Array();
238+
});
239+
240+
it('should fail to explain transaction when common is not provided', async function () {
241+
await basecoin
242+
.explainTransaction({
243+
txHex,
244+
feeInfo,
245+
})
246+
.should.be.rejectedWith('Common must be provided for EthLikeTransactionBuilder');
247+
});
248+
});
249+
216250
describe('Recovery', function () {
217251
const baseUrl = 'https://api-sepolia.basescan.org/';
218252
const userXpub =

0 commit comments

Comments
 (0)