Skip to content

Commit ee34da3

Browse files
committed
test(e2e): valueNotConserved error is mapped
1 parent f34f0ad commit ee34da3

File tree

1 file changed

+30
-8
lines changed

1 file changed

+30
-8
lines changed

packages/e2e/test/wallet/PersonalWallet/txChainHistory.test.ts

Lines changed: 30 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { Cardano, CardanoNodeUtil, ProviderError } from '@cardano-sdk/core';
12
import { PersonalWallet } from '@cardano-sdk/wallet';
23
import { filter, firstValueFrom, map, take } from 'rxjs';
34
import { getEnv, getWallet, normalizeTxBody, walletReady, walletVariables } from '../../../src';
@@ -8,16 +9,10 @@ const env = getEnv(walletVariables);
89

910
describe('PersonalWallet/txChainHistory', () => {
1011
let wallet: PersonalWallet;
12+
let signedTx: Cardano.Tx<Cardano.TxBody>;
1113

1214
beforeEach(async () => {
1315
({ wallet } = await getWallet({ env, logger, name: 'Sending Wallet', polling: { interval: 50 } }));
14-
});
15-
16-
afterEach(() => {
17-
wallet.shutdown();
18-
});
19-
20-
it('submit a transaction and find it in chain history', async () => {
2116
const tAdaToSend = 10_000_000n;
2217
// Make sure the wallet has sufficient funds to run this test
2318
await walletReady(wallet, tAdaToSend);
@@ -32,7 +27,7 @@ describe('PersonalWallet/txChainHistory', () => {
3227
// Send 10 tADA to the same wallet.
3328
const txBuilder = wallet.createTxBuilder();
3429
const txOutput = await txBuilder.buildOutput().address(receivingAddress).coin(tAdaToSend).build();
35-
const { tx: signedTx } = await txBuilder.addOutput(txOutput).build().sign();
30+
signedTx = (await txBuilder.addOutput(txOutput).build().sign()).tx;
3631
await wallet.submitTx(signedTx);
3732

3833
logger.info(
@@ -42,7 +37,13 @@ describe('PersonalWallet/txChainHistory', () => {
4237
signedTx.body.outputs.map((txOut) => [txOut.address, Number.parseInt(txOut.value.coins.toString())])
4338
)}.`
4439
);
40+
});
41+
42+
afterEach(() => {
43+
wallet.shutdown();
44+
});
4545

46+
it('submit a transaction and find it in chain history', async () => {
4647
// Search chain history to see if the transaction is there.
4748
const txFoundInHistory = await firstValueFrom(
4849
wallet.transactions.history$.pipe(
@@ -59,4 +60,25 @@ describe('PersonalWallet/txChainHistory', () => {
5960
expect(txFoundInHistory.id).toEqual(signedTx.id);
6061
expect(normalizeTxBody(txFoundInHistory.body)).toEqual(normalizeTxBody(signedTx.body));
6162
});
63+
64+
it('can detect a ValueNotConserved error', async () => {
65+
expect.assertions(1);
66+
// Search chain history to see if the transaction is there.
67+
await firstValueFrom(
68+
wallet.transactions.history$.pipe(
69+
map((txs) => txs.find((tx) => tx.id === signedTx.id)),
70+
filter(isNotNil),
71+
take(1)
72+
)
73+
);
74+
75+
try {
76+
// Submit the same transaction again.
77+
await wallet.submitTx(signedTx);
78+
} catch (error) {
79+
if (error instanceof ProviderError) {
80+
expect(CardanoNodeUtil.isValueNotConservedError(error?.innerError)).toBeTruthy();
81+
}
82+
}
83+
});
6284
});

0 commit comments

Comments
 (0)