-
Notifications
You must be signed in to change notification settings - Fork 54
/
SingleAddressWallet.test.ts
75 lines (66 loc) · 2.75 KB
/
SingleAddressWallet.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
/* eslint-disable max-len */
import { createSingleAddressWallet, SingleAddressWallet } from '@src/SingleAddressWallet';
import * as KeyManagement from '@src/KeyManagement';
import { Cardano, CardanoProvider } from '@cardano-sdk/core';
import { createInMemoryKeyManager, util } from '@cardano-sdk/in-memory-key-manager';
import { loadCardanoSerializationLib, CardanoSerializationLib } from '@cardano-sdk/cardano-serialization-lib';
import { InMemoryUtxoRepository } from '@src/InMemoryUtxoRepository';
import { UtxoRepository } from '@src/UtxoRepository';
import { InputSelector, roundRobinRandomImprove } from '@cardano-sdk/cip2';
import { providerStub } from './ProviderStub';
describe('Wallet', () => {
let csl: CardanoSerializationLib;
let inputSelector: InputSelector;
let keyManager: KeyManagement.KeyManager;
let provider: CardanoProvider;
let utxoRepository: UtxoRepository;
beforeEach(async () => {
csl = await loadCardanoSerializationLib();
keyManager = createInMemoryKeyManager({
mnemonic: util.generateMnemonic(),
networkId: Cardano.NetworkId.testnet,
password: '123'
});
provider = providerStub();
inputSelector = roundRobinRandomImprove(csl);
utxoRepository = new InMemoryUtxoRepository(provider, keyManager, inputSelector);
});
test('createWallet', async () => {
const wallet = await createSingleAddressWallet(csl, provider, keyManager, utxoRepository);
expect(wallet.address).toBeDefined();
expect(typeof wallet.initializeTx).toBe('function');
expect(typeof wallet.signTx).toBe('function');
});
describe('wallet behaviour', () => {
let wallet: SingleAddressWallet;
const props = {
outputs: [
{
address:
'addr_test1qpu5vlrf4xkxv2qpwngf6cjhtw542ayty80v8dyr49rf5ewvxwdrt70qlcpeeagscasafhffqsxy36t90ldv06wqrk2qum8x5w',
value: { coins: 11_111_111 }
}
]
};
beforeEach(async () => {
wallet = await createSingleAddressWallet(csl, provider, keyManager, utxoRepository);
});
test('initializeTx', async () => {
const txInternals = await wallet.initializeTx(props);
expect(txInternals.body).toBeInstanceOf(csl.TransactionBody);
expect(txInternals.hash).toBeInstanceOf(csl.TransactionHash);
});
test('signTx', async () => {
const { body, hash } = await wallet.initializeTx(props);
const tx = await wallet.signTx(body, hash);
await expect(tx.body().outputs().len()).toBe(1);
await expect(tx.body().inputs().len()).toBeGreaterThan(0);
});
test('submitTx', async () => {
const { body, hash } = await wallet.initializeTx(props);
const tx = await wallet.signTx(body, hash);
const result = await wallet.submitTx(tx);
expect(result).toBe(true);
});
});
});