Skip to content

Commit

Permalink
Merge pull request #818 from input-output-hk/test/e2e-handle
Browse files Browse the repository at this point in the history
Test/e2e handle
  • Loading branch information
rhyslbw authored Jul 17, 2023
2 parents 7096273 + 3051763 commit 98cccbd
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 12 deletions.
19 changes: 10 additions & 9 deletions packages/e2e/test/wallet/PersonalWallet/handle.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,7 @@ describe('Ada handle', () => {
receivingWallet.shutdown();
});

// eslint-disable-next-line max-statements
it("PersonalWallet discovers it's own handles", async () => {
const tokens = new Map([
[assetIds[0], 1n],
Expand Down Expand Up @@ -242,15 +243,15 @@ describe('Ada handle', () => {
expect(receivingHandles.length).toEqual(1);

// send ada using handle
// const txBuilder2 = wallet.createTxBuilder();
// const { tx: tx2 } = await txBuilder2
// .addOutput(await txBuilder.buildOutput().handle(receivingHandles[0].handle).coin(coins).build())
// .build()
// .sign();
// await wallet.submitTx(tx2);
// await txConfirmed(receivingWallet, tx2);
// const receivingUtxoAfter = await firstValueFrom(receivingWallet.balance.utxo.available$);
// expect(receivingUtxoAfter.coins).toEqual(receivingUtxo.coins + coins);
const txBuilder2 = wallet.createTxBuilder();
const { tx: tx2 } = await txBuilder2
.addOutput(await txBuilder2.buildOutput().handle(receivingHandles[0].handle).coin(coins).build())
.build()
.sign();
await wallet.submitTx(tx2);
await txConfirmed(receivingWallet, tx2);
const receivingUtxoAfter = await firstValueFrom(receivingWallet.balance.utxo.available$);
expect(receivingUtxoAfter.coins).toEqual(receivingUtxo.coins + coins);
});

describe('double mint handling', () => {
Expand Down
6 changes: 3 additions & 3 deletions packages/tx-construction/src/tx-builder/TxBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import { filter, firstValueFrom, lastValueFrom } from 'rxjs';
import { finalizeTx } from './finalizeTx';
import { initializeTx } from './initializeTx';
import minBy from 'lodash/minBy';
import omit from 'lodash/omit';

type BuiltTx = {
tx: Cardano.TxBodyWithHash;
Expand Down Expand Up @@ -117,12 +118,11 @@ export class GenericTxBuilder implements TxBuilder {
}

addOutput(txOut: OutputBuilderTxOut): TxBuilder {
this.partialTxBody = { ...this.partialTxBody, outputs: [...(this.partialTxBody.outputs || []), txOut] };

if (txOut.handle) {
this.#handles = [...this.#handles, txOut.handle];
}

const txOutNoHandle = omit(txOut, 'handle');
this.partialTxBody = { ...this.partialTxBody, outputs: [...(this.partialTxBody.outputs || []), txOutNoHandle] };
return this;
}

Expand Down

0 comments on commit 98cccbd

Please sign in to comment.