Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 68 additions & 0 deletions modules/bitgo/test/v2/unit/pendingApproval.ts
Original file line number Diff line number Diff line change
Expand Up @@ -382,4 +382,72 @@ describe('Pending Approvals:', () => {
sandbox.verify();
});
});

describe('recreateAndSignTransaction', function () {
it('should preserve the verifyTokenEnablement verification flag when rebuilding an enabletoken pending approval (CSHLD-1358)', async () => {
const enableTokenPendingApprovalData: PendingApprovalData = {
id: 'pa-enabletoken',
info: {
type: Type.TRANSACTION_REQUEST,
transactionRequest: {
coinSpecific: {
[coin]: {},
},
recipients: [],
buildParams: {
type: 'enabletoken',
},
sourceWallet: walletId,
},
},
state: State.PENDING,
creator: 'test',
};
const pendingApproval = new PendingApproval(bitgo, basecoin, enableTokenPendingApprovalData, wallet);

const prebuildAndSignStub = sandbox
.stub(Wallet.prototype, 'prebuildAndSignTransaction')
.resolves({ txHex: 'signed-tx-hex' });
sandbox.stub(basecoin, 'parseTransaction').resolves({});

await pendingApproval.recreateAndSignTransaction({});

prebuildAndSignStub.calledOnce.should.be.true();
const prebuildParamsArg = prebuildAndSignStub.getCall(0).args[0]!;
prebuildParamsArg.verification!.should.have.property('verifyTokenEnablement', true);
});

it('should not set verifyTokenEnablement for non-enabletoken pending approvals', async () => {
const fanoutPendingApprovalData: PendingApprovalData = {
id: 'pa-fanout',
info: {
type: Type.TRANSACTION_REQUEST,
transactionRequest: {
coinSpecific: {
[coin]: {},
},
recipients: [],
buildParams: {
type: 'fanout',
},
sourceWallet: walletId,
},
},
state: State.PENDING,
creator: 'test',
};
const pendingApproval = new PendingApproval(bitgo, basecoin, fanoutPendingApprovalData, wallet);

const prebuildAndSignStub = sandbox
.stub(Wallet.prototype, 'prebuildAndSignTransaction')
.resolves({ txHex: 'signed-tx-hex' });
sandbox.stub(basecoin, 'parseTransaction').resolves({});

await pendingApproval.recreateAndSignTransaction({});

prebuildAndSignStub.calledOnce.should.be.true();
const prebuildParamsArg = prebuildAndSignStub.getCall(0).args[0]!;
(prebuildParamsArg.verification === undefined).should.be.true();
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export interface PendingApprovalInfo {
coinSpecific: { [key: string]: any };
recipients: any;
buildParams: {
type?: 'fanout' | 'consolidate';
type?: 'fanout' | 'consolidate' | 'enabletoken';
[index: string]: any;
};
sourceWallet?: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,14 @@ export class PendingApproval implements IPendingApproval {
prebuildParams.hop = true;
}

if (transactionRequest.buildParams && transactionRequest.buildParams.type === 'enabletoken') {
// preserve the verification mode used for the original enable-token build so that
// verifyTransaction() takes the trustline verification path instead of falling through
// to the generic createAccount/payment check, which has no matching operations to verify
// for a changeTrust transaction (see CSHLD-1358)
prebuildParams.verification = _.extend({}, prebuildParams.verification, { verifyTokenEnablement: true });
}

const reqTracer = reqId || new RequestTracer();
if (transactionRequest.buildParams && transactionRequest.buildParams.type === 'consolidate') {
// consolidate tag is in the build params - this is a consolidation transaction, so
Expand Down
Loading