decodeTx.spec.ts 773 Bytes
Newer Older
Amaury Martiny's avatar
Amaury Martiny committed
1
import { balanceTransfer } from './balanceTransfer';
2
3
4
import { createSignedTx } from './createSignedTx';
import { createSigningPayload } from './createSigningPayload';
import { decodeTx } from './decodeTx';
Amaury Martiny's avatar
Amaury Martiny committed
5
import { metadataRpc, signWithAlice, TEST_TX_INFO } from './util/testUtil';
6

Amaury Martiny's avatar
Amaury Martiny committed
7
describe('decodeTx', () => {
8
9
10
  it('should work', async done => {
    const unsigned = balanceTransfer(TEST_TX_INFO);
    const signingPayload = createSigningPayload(unsigned);
Amaury Martiny's avatar
Amaury Martiny committed
11
    const signature = await signWithAlice(signingPayload);
12

13
    const tx = createSignedTx(unsigned, signature);
14

Amaury Martiny's avatar
Amaury Martiny committed
15
    const txInfo = decodeTx(tx, metadataRpc);
16

Amaury Martiny's avatar
Amaury Martiny committed
17
18
19
    (['address', 'amount', 'nonce', 'tip', 'to'] as const).forEach(key =>
      expect(txInfo[key]).toBe(TEST_TX_INFO[key])
    );
20

Amaury Martiny's avatar
Amaury Martiny committed
21
    done();
22
23
  });
});