/
txChaining.test.ts
49 lines (36 loc) · 1.63 KB
/
txChaining.test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import { ObservableWallet } from '@cardano-sdk/wallet';
import { firstValueFrom } from 'rxjs';
import { getEnv, getWallet, walletVariables } from '../../../src';
import { logger } from '@cardano-sdk/util-dev';
import { submitAndConfirm, walletReady } from '../../util';
const env = getEnv(walletVariables);
describe('SingleAddressWallet/txChaining', () => {
let wallet: ObservableWallet;
beforeAll(async () => {
jest.setTimeout(180_000);
wallet = (await getWallet({ env, logger, name: 'Test Wallet' })).wallet;
await walletReady(wallet, 1_000_000n);
});
afterAll(() => {
wallet.shutdown();
});
test('txChaining', async () => {
const { address } = (await firstValueFrom(wallet.addresses$))[0];
const { coins } = await firstValueFrom(wallet.balance.utxo.available$);
const moreThanHalfOfTheBalanceCoins = (coins * 60n) / 100n;
const tx1 = await wallet.initializeTx({
outputs: new Set([{ address, value: { coins: moreThanHalfOfTheBalanceCoins } }])
});
const finalizedTx1 = await wallet.finalizeTx({ tx: tx1 });
await wallet.submitTx(finalizedTx1);
const tx2 = await wallet.initializeTx({
outputs: new Set([{ address, value: { coins: moreThanHalfOfTheBalanceCoins } }])
});
// Assert attempting to do tx chaining
const usingTx1OutputAsInput = [...tx2.inputSelection.inputs].some(([txIn]) => txIn.txId === finalizedTx1.id);
expect(usingTx1OutputAsInput).toBe(true);
const finalizedTx2 = await wallet.finalizeTx({ tx: tx2 });
// 1st tx must also be confirmed because the 2nd one uses output from the 1st one
await submitAndConfirm(wallet, finalizedTx2);
});
});