@cardano-sdk/wallet 0.1.4 → 0.1.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +201 -0
- package/NOTICE +5 -0
- package/README.md +8 -0
- package/dist/KeyManagement/InMemoryKeyManager.d.ts +9 -0
- package/dist/KeyManagement/InMemoryKeyManager.d.ts.map +1 -0
- package/dist/KeyManagement/InMemoryKeyManager.js +94 -0
- package/dist/KeyManagement/InMemoryKeyManager.js.map +1 -0
- package/dist/KeyManagement/errors/InvalidMnemonic.d.ts +5 -0
- package/dist/KeyManagement/errors/InvalidMnemonic.d.ts.map +1 -0
- package/dist/KeyManagement/errors/InvalidMnemonic.js +13 -0
- package/dist/KeyManagement/errors/InvalidMnemonic.js.map +1 -0
- package/{src/KeyManagement/errors/index.ts → dist/KeyManagement/errors/index.d.ts} +1 -0
- package/dist/KeyManagement/errors/index.d.ts.map +1 -0
- package/dist/KeyManagement/errors/index.js +6 -0
- package/dist/KeyManagement/errors/index.js.map +1 -0
- package/{src/KeyManagement/index.ts → dist/KeyManagement/index.d.ts} +1 -0
- package/dist/KeyManagement/index.d.ts.map +1 -0
- package/dist/KeyManagement/index.js +30 -0
- package/dist/KeyManagement/index.js.map +1 -0
- package/dist/KeyManagement/types.d.ts +30 -0
- package/dist/KeyManagement/types.d.ts.map +1 -0
- package/dist/KeyManagement/types.js +15 -0
- package/dist/KeyManagement/types.js.map +1 -0
- package/dist/KeyManagement/util.d.ts +6 -0
- package/dist/KeyManagement/util.d.ts.map +1 -0
- package/dist/KeyManagement/util.js +31 -0
- package/dist/KeyManagement/util.js.map +1 -0
- package/dist/SingleAddressWallet.d.ts +45 -0
- package/dist/SingleAddressWallet.d.ts.map +1 -0
- package/dist/SingleAddressWallet.js +158 -0
- package/dist/SingleAddressWallet.js.map +1 -0
- package/dist/Transaction/computeImplicitCoin.d.ts +4 -0
- package/dist/Transaction/computeImplicitCoin.d.ts.map +1 -0
- package/dist/Transaction/computeImplicitCoin.js +21 -0
- package/dist/Transaction/computeImplicitCoin.js.map +1 -0
- package/dist/Transaction/createTransactionInternals.d.ts +16 -0
- package/dist/Transaction/createTransactionInternals.d.ts.map +1 -0
- package/dist/Transaction/createTransactionInternals.js +28 -0
- package/dist/Transaction/createTransactionInternals.js.map +1 -0
- package/dist/Transaction/ensureValidityInterval.d.ts +3 -0
- package/dist/Transaction/ensureValidityInterval.d.ts.map +1 -0
- package/dist/Transaction/ensureValidityInterval.js +6 -0
- package/dist/Transaction/ensureValidityInterval.js.map +1 -0
- package/dist/Transaction/index.d.ts +4 -0
- package/dist/Transaction/index.d.ts.map +1 -0
- package/dist/Transaction/index.js +16 -0
- package/dist/Transaction/index.js.map +1 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +31 -0
- package/dist/index.js.map +1 -0
- package/dist/services/AssetsTracker.d.ts +16 -0
- package/dist/services/AssetsTracker.d.ts.map +1 -0
- package/dist/services/AssetsTracker.js +13 -0
- package/dist/services/AssetsTracker.js.map +1 -0
- package/dist/services/BalanceTracker.d.ts +5 -0
- package/dist/services/BalanceTracker.d.ts.map +1 -0
- package/dist/services/BalanceTracker.js +43 -0
- package/dist/services/BalanceTracker.js.map +1 -0
- package/dist/services/DelegationTracker/DelegationTracker.d.ts +26 -0
- package/dist/services/DelegationTracker/DelegationTracker.d.ts.map +1 -0
- package/dist/services/DelegationTracker/DelegationTracker.js +39 -0
- package/dist/services/DelegationTracker/DelegationTracker.js.map +1 -0
- package/dist/services/DelegationTracker/RewardAccounts.d.ts +36 -0
- package/dist/services/DelegationTracker/RewardAccounts.d.ts.map +1 -0
- package/dist/services/DelegationTracker/RewardAccounts.js +86 -0
- package/dist/services/DelegationTracker/RewardAccounts.js.map +1 -0
- package/dist/services/DelegationTracker/RewardsHistory.d.ts +14 -0
- package/dist/services/DelegationTracker/RewardsHistory.d.ts.map +1 -0
- package/dist/services/DelegationTracker/RewardsHistory.js +27 -0
- package/dist/services/DelegationTracker/RewardsHistory.js.map +1 -0
- package/dist/services/DelegationTracker/index.d.ts +5 -0
- package/dist/services/DelegationTracker/index.d.ts.map +1 -0
- package/dist/services/DelegationTracker/index.js +17 -0
- package/dist/services/DelegationTracker/index.js.map +1 -0
- package/dist/services/DelegationTracker/transactionCertificates.d.ts +9 -0
- package/dist/services/DelegationTracker/transactionCertificates.d.ts.map +1 -0
- package/dist/services/DelegationTracker/transactionCertificates.js +33 -0
- package/dist/services/DelegationTracker/transactionCertificates.js.map +1 -0
- package/dist/services/DelegationTracker/types.d.ts +6 -0
- package/dist/services/DelegationTracker/types.d.ts.map +1 -0
- package/dist/services/DelegationTracker/types.js +3 -0
- package/dist/services/DelegationTracker/types.js.map +1 -0
- package/dist/services/TransactionError.d.ts +15 -0
- package/dist/services/TransactionError.d.ts.map +1 -0
- package/dist/services/TransactionError.js +23 -0
- package/dist/services/TransactionError.js.map +1 -0
- package/dist/services/TransactionsTracker.d.ts +22 -0
- package/dist/services/TransactionsTracker.d.ts.map +1 -0
- package/dist/services/TransactionsTracker.js +75 -0
- package/dist/services/TransactionsTracker.js.map +1 -0
- package/dist/services/UtxoTracker.d.ts +18 -0
- package/dist/services/UtxoTracker.d.ts.map +1 -0
- package/dist/services/UtxoTracker.js +20 -0
- package/dist/services/UtxoTracker.js.map +1 -0
- package/dist/services/index.d.ts +9 -0
- package/dist/services/index.d.ts.map +1 -0
- package/dist/services/index.js +21 -0
- package/dist/services/index.js.map +1 -0
- package/dist/services/types.d.ts +81 -0
- package/dist/services/types.d.ts.map +1 -0
- package/dist/services/types.js +16 -0
- package/dist/services/types.js.map +1 -0
- package/dist/services/util/SyncableIntervalTrackerSubject.d.ts +19 -0
- package/dist/services/util/SyncableIntervalTrackerSubject.d.ts.map +1 -0
- package/dist/services/util/SyncableIntervalTrackerSubject.js +30 -0
- package/dist/services/util/SyncableIntervalTrackerSubject.js.map +1 -0
- package/dist/services/util/TrackerSubject.d.ts +14 -0
- package/dist/services/util/TrackerSubject.d.ts.map +1 -0
- package/dist/services/util/TrackerSubject.js +46 -0
- package/dist/services/util/TrackerSubject.js.map +1 -0
- package/dist/services/util/coldObservableProvider.d.ts +4 -0
- package/dist/services/util/coldObservableProvider.d.ts.map +1 -0
- package/dist/services/util/coldObservableProvider.js +14 -0
- package/dist/services/util/coldObservableProvider.js.map +1 -0
- package/dist/services/util/equals.d.ts +9 -0
- package/dist/services/util/equals.d.ts.map +1 -0
- package/dist/services/util/equals.js +19 -0
- package/dist/services/util/equals.js.map +1 -0
- package/dist/services/util/index.d.ts +6 -0
- package/dist/services/util/index.d.ts.map +1 -0
- package/dist/services/util/index.js +18 -0
- package/dist/services/util/index.js.map +1 -0
- package/dist/services/util/trigger.d.ts +5 -0
- package/dist/services/util/trigger.d.ts.map +1 -0
- package/dist/services/util/trigger.js +9 -0
- package/dist/services/util/trigger.js.map +1 -0
- package/dist/types.d.ts +35 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +3 -0
- package/dist/types.js.map +1 -0
- package/package.json +17 -8
- package/jest.config.js +0 -1
- package/src/Address.ts +0 -12
- package/src/BalanceTracker.ts +0 -62
- package/src/InMemoryTransactionTracker.ts +0 -87
- package/src/InMemoryUtxoRepository.ts +0 -192
- package/src/KeyManagement/InMemoryKeyManager.ts +0 -67
- package/src/KeyManagement/errors/InvalidMnemonic.ts +0 -9
- package/src/KeyManagement/types.ts +0 -15
- package/src/KeyManagement/util.ts +0 -14
- package/src/SingleAddressWallet.ts +0 -120
- package/src/Transaction/CertificateFactory.ts +0 -154
- package/src/Transaction/computeImplicitCoin.ts +0 -36
- package/src/Transaction/createTransactionInternals.ts +0 -60
- package/src/Transaction/index.ts +0 -5
- package/src/Transaction/types.ts +0 -12
- package/src/Transaction/withdrawal.ts +0 -17
- package/src/TransactionError.ts +0 -17
- package/src/index.ts +0 -9
- package/src/tsconfig.json +0 -11
- package/src/types.ts +0 -56
- package/test/.eslintrc.js +0 -7
- package/test/BalanceTracker.test.ts +0 -44
- package/test/InMemoryTransactionTracker.test.ts +0 -108
- package/test/InMemoryUtxoRepository.test.ts +0 -242
- package/test/KeyManagement/InMemoryKeyManager.test.ts +0 -39
- package/test/SingleAddressWallet.test.ts +0 -87
- package/test/Transaction/CertificateFactory.test.ts +0 -89
- package/test/Transaction/computeImplicitCoin.test.ts +0 -26
- package/test/Transaction/createTransactionInternals.test.ts +0 -84
- package/test/Transaction/withdrawal.test.ts +0 -13
- package/test/integration/withdrawal.test.ts +0 -108
- package/test/mocks/MockTransactionTracker.ts +0 -8
- package/test/mocks/MockUtxoRepository.ts +0 -13
- package/test/mocks/ProviderStub.ts +0 -151
- package/test/mocks/index.ts +0 -4
- package/test/mocks/testKeyManager.ts +0 -10
- package/test/tsconfig.json +0 -12
|
@@ -1,89 +0,0 @@
|
|
|
1
|
-
import { CardanoSerializationLib, loadCardanoSerializationLib } from '@cardano-sdk/core';
|
|
2
|
-
import { testKeyManager } from '../mocks';
|
|
3
|
-
import { CertificateFactory } from '../../src/Transaction';
|
|
4
|
-
import { KeyManager } from '../../src/KeyManagement';
|
|
5
|
-
|
|
6
|
-
describe('Transaction.CertificateFactory', () => {
|
|
7
|
-
let csl: CardanoSerializationLib;
|
|
8
|
-
let stakeKey: string;
|
|
9
|
-
let keyManager: KeyManager;
|
|
10
|
-
let certs: CertificateFactory;
|
|
11
|
-
const delegatee = 'pool1qqvukkkfr3ux4qylfkrky23f6trl2l6xjluv36z90ax7gfa8yxt';
|
|
12
|
-
|
|
13
|
-
beforeAll(async () => {
|
|
14
|
-
csl = await loadCardanoSerializationLib();
|
|
15
|
-
keyManager = testKeyManager(csl);
|
|
16
|
-
stakeKey = keyManager.stakeKey.hash().to_bech32('ed25519_pk');
|
|
17
|
-
certs = new CertificateFactory(csl, keyManager);
|
|
18
|
-
});
|
|
19
|
-
|
|
20
|
-
it('stakeKeyRegistration', () =>
|
|
21
|
-
expect(
|
|
22
|
-
certs.stakeKeyRegistration().as_stake_registration()?.stake_credential().to_keyhash()?.to_bech32('ed25519_pk')
|
|
23
|
-
).toBe(stakeKey));
|
|
24
|
-
|
|
25
|
-
it('stakeKeyDeregistration', () =>
|
|
26
|
-
expect(
|
|
27
|
-
certs.stakeKeyDeregistration().as_stake_deregistration()?.stake_credential().to_keyhash()?.to_bech32('ed25519_pk')
|
|
28
|
-
).toBe(stakeKey));
|
|
29
|
-
|
|
30
|
-
it('stakeDelegation', () => {
|
|
31
|
-
const delegation = certs.stakeDelegation(delegatee).as_stake_delegation()!;
|
|
32
|
-
expect(delegation.stake_credential().to_keyhash()?.to_bech32('ed25519_pk')).toBe(stakeKey);
|
|
33
|
-
expect(delegation.pool_keyhash().to_bech32('pool')).toBe(delegatee);
|
|
34
|
-
});
|
|
35
|
-
|
|
36
|
-
it('poolRegistration', () => {
|
|
37
|
-
const owner = keyManager.publicKey.hash().to_bech32('ed25519_pk');
|
|
38
|
-
const vrfKeyHash = 'vrf_vk13hg4gg5fg67399nuz2ldk89kqw9h379cfgtkpvd83ra89f908kcqv2cw3j';
|
|
39
|
-
const rewardAddress = 'addr1uxa5pudxg77g3sdaddecmw8tvc6hmynywn49lltt4fmvn7cmpqcax';
|
|
40
|
-
const poolMetadata = {
|
|
41
|
-
hash: 'pool1ntpzzu5g6xhqkns4csd435lqtgfjqm7e4wquk9v58eqhf0esey9st6vf29',
|
|
42
|
-
url: 'https://example.com'
|
|
43
|
-
};
|
|
44
|
-
const params = certs
|
|
45
|
-
.poolRegistration({
|
|
46
|
-
cost: 1000n,
|
|
47
|
-
pledge: 10_000n,
|
|
48
|
-
margin: { denominator: 5, numerator: 1 },
|
|
49
|
-
owners: [owner],
|
|
50
|
-
poolKeyHash: stakeKey,
|
|
51
|
-
relays: [
|
|
52
|
-
{ relayType: 'singlehost-name', hostname: 'example.com', port: 5000 },
|
|
53
|
-
{
|
|
54
|
-
relayType: 'singlehost-addr',
|
|
55
|
-
port: 6000,
|
|
56
|
-
ipv4: '127.0.0.1'
|
|
57
|
-
},
|
|
58
|
-
{ relayType: 'multihost-name', dnsName: 'example.com' }
|
|
59
|
-
],
|
|
60
|
-
vrfKeyHash,
|
|
61
|
-
rewardAddress,
|
|
62
|
-
poolMetadata
|
|
63
|
-
})
|
|
64
|
-
.as_pool_registration()!
|
|
65
|
-
.pool_params();
|
|
66
|
-
expect(params.cost().to_str()).toBe('1000');
|
|
67
|
-
expect(params.pledge().to_str()).toBe('10000');
|
|
68
|
-
const margin = params.margin();
|
|
69
|
-
expect(margin.numerator().to_str()).toBe('1');
|
|
70
|
-
expect(margin.denominator().to_str()).toBe('5');
|
|
71
|
-
const owners = params.pool_owners();
|
|
72
|
-
expect(owners.len()).toBe(1);
|
|
73
|
-
expect(owners.get(0).to_bech32('ed25519_pk')).toBe(owner);
|
|
74
|
-
expect(params.operator().to_bech32('ed25519_pk')).toBe(stakeKey);
|
|
75
|
-
const relays = params.relays();
|
|
76
|
-
expect(relays.len()).toBe(3);
|
|
77
|
-
expect(params.vrf_keyhash().to_bech32('vrf_vk')).toBe(vrfKeyHash);
|
|
78
|
-
expect(params.reward_account().to_address().to_bech32('addr')).toBe(rewardAddress);
|
|
79
|
-
const metadata = params.pool_metadata()!;
|
|
80
|
-
expect(metadata.url().url()).toBe(poolMetadata.url);
|
|
81
|
-
expect(metadata.pool_metadata_hash().to_bech32('pool')).toBe(poolMetadata.hash);
|
|
82
|
-
});
|
|
83
|
-
|
|
84
|
-
it('poolRetirement', () => {
|
|
85
|
-
const retirement = certs.poolRetirement(stakeKey, 1000).as_pool_retirement()!;
|
|
86
|
-
expect(retirement.pool_keyhash().to_bech32('ed25519_pk')).toEqual(stakeKey);
|
|
87
|
-
expect(retirement.epoch()).toEqual(1000);
|
|
88
|
-
});
|
|
89
|
-
});
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import { loadCardanoSerializationLib, ProtocolParametersRequiredByWallet } from '@cardano-sdk/core';
|
|
2
|
-
import { testKeyManager } from '../mocks';
|
|
3
|
-
import { Transaction } from '../../src';
|
|
4
|
-
import { InitializeTxProps } from '../../src/Transaction';
|
|
5
|
-
|
|
6
|
-
describe('Transaction.computeImplicitCoin', () => {
|
|
7
|
-
it('sums registrations for deposit, withdrawals and deregistrations for input', async () => {
|
|
8
|
-
const protocolParameters = { stakeKeyDeposit: 2, poolDeposit: 3 } as ProtocolParametersRequiredByWallet;
|
|
9
|
-
const csl = await loadCardanoSerializationLib();
|
|
10
|
-
const keyManager = testKeyManager(csl);
|
|
11
|
-
const certs = new Transaction.CertificateFactory(csl, keyManager);
|
|
12
|
-
const certificates = [
|
|
13
|
-
certs.stakeKeyRegistration(),
|
|
14
|
-
certs.stakeKeyDeregistration(),
|
|
15
|
-
certs.stakeKeyRegistration(),
|
|
16
|
-
certs.poolRetirement(keyManager.stakeKey.hash().to_bech32('key'), 1000),
|
|
17
|
-
certs.stakeDelegation('pool1qqvukkkfr3ux4qylfkrky23f6trl2l6xjluv36z90ax7gfa8yxt')
|
|
18
|
-
];
|
|
19
|
-
const withdrawals = [Transaction.withdrawal(csl, keyManager, 5n)];
|
|
20
|
-
const txProps = { certificates, withdrawals } as unknown as InitializeTxProps;
|
|
21
|
-
|
|
22
|
-
const coin = Transaction.computeImplicitCoin(protocolParameters, txProps);
|
|
23
|
-
expect(coin.deposit).toBe(2n + 2n);
|
|
24
|
-
expect(coin.input).toBe(2n + 3n + 5n);
|
|
25
|
-
});
|
|
26
|
-
});
|
|
@@ -1,84 +0,0 @@
|
|
|
1
|
-
import { InputSelector, roundRobinRandomImprove } from '@cardano-sdk/cip2';
|
|
2
|
-
import { loadCardanoSerializationLib, CardanoSerializationLib, CSL, CardanoProvider, Ogmios } from '@cardano-sdk/core';
|
|
3
|
-
import { SelectionConstraints } from '@cardano-sdk/util-dev';
|
|
4
|
-
import { providerStub, txTracker, testKeyManager } from '../mocks';
|
|
5
|
-
import {
|
|
6
|
-
CertificateFactory,
|
|
7
|
-
createTransactionInternals,
|
|
8
|
-
CreateTxInternalsProps,
|
|
9
|
-
Withdrawal
|
|
10
|
-
} from '../../src/Transaction';
|
|
11
|
-
import { UtxoRepository, InMemoryUtxoRepository, KeyManagement } from '../../src';
|
|
12
|
-
|
|
13
|
-
const address =
|
|
14
|
-
'addr_test1qq585l3hyxgj3nas2v3xymd23vvartfhceme6gv98aaeg9muzcjqw982pcftgx53fu5527z2cj2tkx2h8ux2vxsg475q2g7k3g';
|
|
15
|
-
|
|
16
|
-
describe('Transaction.createTransactionInternals', () => {
|
|
17
|
-
let csl: CardanoSerializationLib;
|
|
18
|
-
let provider: CardanoProvider;
|
|
19
|
-
let inputSelector: InputSelector;
|
|
20
|
-
let utxoRepository: UtxoRepository;
|
|
21
|
-
let keyManager: KeyManagement.KeyManager;
|
|
22
|
-
let outputs: Set<CSL.TransactionOutput>;
|
|
23
|
-
|
|
24
|
-
const createSimpleTransactionInternals = async (props?: Partial<CreateTxInternalsProps>) => {
|
|
25
|
-
const result = await utxoRepository.selectInputs(outputs, SelectionConstraints.NO_CONSTRAINTS);
|
|
26
|
-
const ledgerTip = await provider.ledgerTip();
|
|
27
|
-
return await createTransactionInternals(csl, {
|
|
28
|
-
changeAddress: 'addr_test1gz2fxv2umyhttkxyxp8x0dlpdt3k6cwng5pxj3jhsydzerspqgpsqe70et',
|
|
29
|
-
inputSelection: result.selection,
|
|
30
|
-
validityInterval: {
|
|
31
|
-
invalidHereafter: ledgerTip.slot + 3600
|
|
32
|
-
},
|
|
33
|
-
...props
|
|
34
|
-
});
|
|
35
|
-
};
|
|
36
|
-
|
|
37
|
-
beforeEach(async () => {
|
|
38
|
-
csl = await loadCardanoSerializationLib();
|
|
39
|
-
provider = providerStub();
|
|
40
|
-
inputSelector = roundRobinRandomImprove(csl);
|
|
41
|
-
keyManager = testKeyManager(csl);
|
|
42
|
-
|
|
43
|
-
outputs = new Set([
|
|
44
|
-
Ogmios.ogmiosToCsl(csl).txOut({
|
|
45
|
-
address,
|
|
46
|
-
value: { coins: 4_000_000 }
|
|
47
|
-
}),
|
|
48
|
-
Ogmios.ogmiosToCsl(csl).txOut({
|
|
49
|
-
address,
|
|
50
|
-
value: { coins: 2_000_000 }
|
|
51
|
-
})
|
|
52
|
-
]);
|
|
53
|
-
utxoRepository = new InMemoryUtxoRepository({ csl, provider, keyManager, inputSelector, txTracker });
|
|
54
|
-
});
|
|
55
|
-
|
|
56
|
-
test('simple transaction', async () => {
|
|
57
|
-
const { body, hash } = await createSimpleTransactionInternals();
|
|
58
|
-
expect(body).toBeInstanceOf(csl.TransactionBody);
|
|
59
|
-
expect(hash).toBeInstanceOf(csl.TransactionHash);
|
|
60
|
-
});
|
|
61
|
-
|
|
62
|
-
test('transaction with withdrawals', async () => {
|
|
63
|
-
const withdrawal: Withdrawal = {
|
|
64
|
-
address: csl.RewardAddress.new(
|
|
65
|
-
csl.NetworkId.testnet().kind(),
|
|
66
|
-
csl.StakeCredential.from_keyhash(keyManager.stakeKey.hash())
|
|
67
|
-
),
|
|
68
|
-
quantity: csl.BigNum.from_str('5000000')
|
|
69
|
-
};
|
|
70
|
-
const { body } = await createSimpleTransactionInternals({ withdrawals: [withdrawal] });
|
|
71
|
-
const txWithdrawals = body.withdrawals()!;
|
|
72
|
-
expect(txWithdrawals.len()).toBe(1);
|
|
73
|
-
const txWithdrawalQty = txWithdrawals.get(withdrawal.address);
|
|
74
|
-
expect(txWithdrawalQty?.to_str()).toBe(withdrawal.quantity.to_str());
|
|
75
|
-
});
|
|
76
|
-
|
|
77
|
-
test('transaction with certificates', async () => {
|
|
78
|
-
const delegatee = 'pool1qqvukkkfr3ux4qylfkrky23f6trl2l6xjluv36z90ax7gfa8yxt';
|
|
79
|
-
const certFactory = new CertificateFactory(csl, keyManager);
|
|
80
|
-
const certificates = [certFactory.stakeKeyRegistration(), certFactory.stakeDelegation(delegatee)];
|
|
81
|
-
const { body } = await createSimpleTransactionInternals({ certificates });
|
|
82
|
-
expect(body.certs()!.len()).toBe(certificates.length);
|
|
83
|
-
});
|
|
84
|
-
});
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { loadCardanoSerializationLib } from '@cardano-sdk/core';
|
|
2
|
-
import { testKeyManager } from '../mocks';
|
|
3
|
-
import { Transaction } from '../../src';
|
|
4
|
-
|
|
5
|
-
describe('Transaction.withdrawal', () => {
|
|
6
|
-
it('creates objects of correct types', async () => {
|
|
7
|
-
const csl = await loadCardanoSerializationLib();
|
|
8
|
-
const keyManager = await testKeyManager(csl);
|
|
9
|
-
const withdrawal = Transaction.withdrawal(csl, keyManager, 5000n);
|
|
10
|
-
expect(withdrawal.address).toBeInstanceOf(csl.RewardAddress);
|
|
11
|
-
expect(withdrawal.quantity).toBeInstanceOf(csl.BigNum);
|
|
12
|
-
});
|
|
13
|
-
});
|
|
@@ -1,108 +0,0 @@
|
|
|
1
|
-
/* eslint-disable no-fallthrough */
|
|
2
|
-
import { roundRobinRandomImprove } from '@cardano-sdk/cip2';
|
|
3
|
-
import { Cardano, CardanoSerializationLib, loadCardanoSerializationLib } from '@cardano-sdk/core';
|
|
4
|
-
import {
|
|
5
|
-
BalanceTrackerEvent,
|
|
6
|
-
createSingleAddressWallet,
|
|
7
|
-
InMemoryTransactionTracker,
|
|
8
|
-
InMemoryUtxoRepository,
|
|
9
|
-
KeyManagement,
|
|
10
|
-
SingleAddressWallet,
|
|
11
|
-
SingleAddressWalletProps,
|
|
12
|
-
Transaction,
|
|
13
|
-
TransactionError,
|
|
14
|
-
TransactionFailure,
|
|
15
|
-
TransactionTracker,
|
|
16
|
-
UtxoRepository,
|
|
17
|
-
UtxoRepositoryEvent
|
|
18
|
-
} from '@cardano-sdk/wallet';
|
|
19
|
-
// Not testing with a real provider
|
|
20
|
-
import { providerStub } from '../mocks';
|
|
21
|
-
|
|
22
|
-
const walletProps: SingleAddressWalletProps = { name: 'some-wallet' };
|
|
23
|
-
const networkId = Cardano.NetworkId.mainnet;
|
|
24
|
-
const mnemonicWords = KeyManagement.util.generateMnemonicWords();
|
|
25
|
-
const password = 'your_password';
|
|
26
|
-
|
|
27
|
-
describe('integration/withdrawal', () => {
|
|
28
|
-
let csl: CardanoSerializationLib;
|
|
29
|
-
let keyManager: KeyManagement.KeyManager;
|
|
30
|
-
let txTracker: TransactionTracker;
|
|
31
|
-
let utxoRepository: UtxoRepository;
|
|
32
|
-
let wallet: SingleAddressWallet;
|
|
33
|
-
|
|
34
|
-
beforeAll(async () => {
|
|
35
|
-
csl = await loadCardanoSerializationLib();
|
|
36
|
-
keyManager = KeyManagement.createInMemoryKeyManager({ csl, mnemonicWords, password, networkId });
|
|
37
|
-
const provider = providerStub();
|
|
38
|
-
const inputSelector = roundRobinRandomImprove(csl);
|
|
39
|
-
txTracker = new InMemoryTransactionTracker({ csl, provider, pollInterval: 1 });
|
|
40
|
-
utxoRepository = new InMemoryUtxoRepository({ csl, provider, txTracker, inputSelector, keyManager });
|
|
41
|
-
wallet = await createSingleAddressWallet(walletProps, {
|
|
42
|
-
csl,
|
|
43
|
-
keyManager,
|
|
44
|
-
provider,
|
|
45
|
-
utxoRepository,
|
|
46
|
-
txTracker
|
|
47
|
-
});
|
|
48
|
-
|
|
49
|
-
// Call this to sync available balance
|
|
50
|
-
await utxoRepository.sync();
|
|
51
|
-
});
|
|
52
|
-
|
|
53
|
-
it('has balance', () => {
|
|
54
|
-
expect(wallet.balance.total).toBeTruthy();
|
|
55
|
-
expect(wallet.balance.available).toBeTruthy();
|
|
56
|
-
});
|
|
57
|
-
|
|
58
|
-
it('has events', () => {
|
|
59
|
-
wallet.balance.on(BalanceTrackerEvent.Changed, ({ total, available }) => {
|
|
60
|
-
expect(total).toBeTruthy();
|
|
61
|
-
expect(available).toBeTruthy();
|
|
62
|
-
// This is emitted after transaction is submitted and balance is locked before confirmation
|
|
63
|
-
// And after UtxoRepository.sync()
|
|
64
|
-
});
|
|
65
|
-
utxoRepository.on(UtxoRepositoryEvent.OutOfSync, () => {
|
|
66
|
-
// This is emitted when cardano-js-sdk calls sync() internally and it fails.
|
|
67
|
-
// User should attempt to resync using utxoRepository.sync()
|
|
68
|
-
});
|
|
69
|
-
});
|
|
70
|
-
|
|
71
|
-
it('can submit transaction', async () => {
|
|
72
|
-
const certFactory = new Transaction.CertificateFactory(csl, keyManager);
|
|
73
|
-
|
|
74
|
-
const { body, hash } = await wallet.initializeTx({
|
|
75
|
-
certificates: [certFactory.stakeKeyDeregistration()],
|
|
76
|
-
withdrawals: [Transaction.withdrawal(csl, keyManager, utxoRepository.availableRewards || 0n)],
|
|
77
|
-
outputs: new Set() // In a real transaction you would probably want to have some outputs
|
|
78
|
-
});
|
|
79
|
-
// Calculated fee is returned by invoking body.fee()
|
|
80
|
-
const tx = await wallet.signTx(body, hash);
|
|
81
|
-
|
|
82
|
-
const { submitted, confirmed } = wallet.submitTx(tx);
|
|
83
|
-
try {
|
|
84
|
-
// Transaction is submitting. UTxO is locked.
|
|
85
|
-
await submitted;
|
|
86
|
-
// Transaction is successfully submitted, but not confirmed yet
|
|
87
|
-
await confirmed;
|
|
88
|
-
} catch (error) {
|
|
89
|
-
if (error instanceof TransactionError) {
|
|
90
|
-
switch (error.reason) {
|
|
91
|
-
case TransactionFailure.InvalidTransaction:
|
|
92
|
-
// Invalid transaction, probably no validity interval set
|
|
93
|
-
case TransactionFailure.Timeout:
|
|
94
|
-
// Transaction has expired and will not be confirmed. Therefore it's safe to spend the UTxO again.
|
|
95
|
-
case TransactionFailure.FailedToSubmit:
|
|
96
|
-
// Probably attempt to resubmit
|
|
97
|
-
case TransactionFailure.CannotTrack:
|
|
98
|
-
// Failed when attempting to track transaction confirmation.
|
|
99
|
-
// Probably just attempt to track it again by calling txTracker.track(tx)
|
|
100
|
-
case TransactionFailure.Unknown:
|
|
101
|
-
// Most likely a bug in cardano-js-sdk
|
|
102
|
-
}
|
|
103
|
-
} else {
|
|
104
|
-
// Most likely a bug in cardano-js-sdk
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
});
|
|
108
|
-
});
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import Emittery from 'emittery';
|
|
2
|
-
import { delegate, rewards, utxo } from './ProviderStub';
|
|
3
|
-
import { UtxoRepository, UtxoRepositoryEvents } from '../../src';
|
|
4
|
-
|
|
5
|
-
export class MockUtxoRepository extends Emittery<UtxoRepositoryEvents> implements UtxoRepository {
|
|
6
|
-
sync = jest.fn().mockResolvedValue(void 0);
|
|
7
|
-
selectInputs = jest.fn();
|
|
8
|
-
allUtxos = utxo;
|
|
9
|
-
availableUtxos = utxo;
|
|
10
|
-
allRewards = rewards;
|
|
11
|
-
availableRewards = rewards;
|
|
12
|
-
delegation = delegate;
|
|
13
|
-
}
|
|
@@ -1,151 +0,0 @@
|
|
|
1
|
-
/* eslint-disable max-len */
|
|
2
|
-
import * as Schema from '@cardano-ogmios/schema';
|
|
3
|
-
import { PXL, TSLA } from '@cardano-sdk/util-dev/src/assetId';
|
|
4
|
-
|
|
5
|
-
export const stakeKeyHash = 'stake_test1up7pvfq8zn4quy45r2g572290p9vf99mr9tn7r9xrgy2l2qdsf58d';
|
|
6
|
-
|
|
7
|
-
export const utxo: Schema.Utxo = [
|
|
8
|
-
[
|
|
9
|
-
{
|
|
10
|
-
txId: 'bb217abaca60fc0ca68c1555eca6a96d2478547818ae76ce6836133f3cc546e0',
|
|
11
|
-
index: 1
|
|
12
|
-
},
|
|
13
|
-
{
|
|
14
|
-
address:
|
|
15
|
-
'addr_test1qzs0umu0s2ammmpw0hea0w2crtcymdjvvlqngpgqy76gpfnuzcjqw982pcftgx53fu5527z2cj2tkx2h8ux2vxsg475qp3y3vz',
|
|
16
|
-
value: {
|
|
17
|
-
coins: 4_027_026_465,
|
|
18
|
-
assets: {
|
|
19
|
-
[TSLA]: 10n,
|
|
20
|
-
[PXL]: 5n
|
|
21
|
-
}
|
|
22
|
-
},
|
|
23
|
-
datum: null
|
|
24
|
-
}
|
|
25
|
-
],
|
|
26
|
-
[
|
|
27
|
-
{
|
|
28
|
-
txId: 'c7c0973c6bbf1a04a9f306da7814b4fa564db649bf48b0bd93c273bd03143547',
|
|
29
|
-
index: 0
|
|
30
|
-
},
|
|
31
|
-
{
|
|
32
|
-
address:
|
|
33
|
-
'addr_test1qq585l3hyxgj3nas2v3xymd23vvartfhceme6gv98aaeg9muzcjqw982pcftgx53fu5527z2cj2tkx2h8ux2vxsg475q2g7k3g',
|
|
34
|
-
value: {
|
|
35
|
-
coins: 3_289_566,
|
|
36
|
-
assets: {
|
|
37
|
-
[TSLA]: 15n
|
|
38
|
-
}
|
|
39
|
-
},
|
|
40
|
-
datum: null
|
|
41
|
-
}
|
|
42
|
-
],
|
|
43
|
-
[
|
|
44
|
-
{
|
|
45
|
-
txId: 'ea1517b8c36fea3148df9aa1f49bbee66ff59a5092331a67bd8b3c427e1d79d7',
|
|
46
|
-
index: 2
|
|
47
|
-
},
|
|
48
|
-
{
|
|
49
|
-
address:
|
|
50
|
-
'addr_test1qqydn46r6mhge0kfpqmt36m6q43knzsd9ga32n96m89px3nuzcjqw982pcftgx53fu5527z2cj2tkx2h8ux2vxsg475qypp3m9',
|
|
51
|
-
value: {
|
|
52
|
-
coins: 9_825_963
|
|
53
|
-
},
|
|
54
|
-
datum: null
|
|
55
|
-
}
|
|
56
|
-
]
|
|
57
|
-
];
|
|
58
|
-
|
|
59
|
-
export const delegate = 'pool185g59xpqzt7gf0ljr8v8f3akl95qnmardf2f8auwr3ffx7atjj5';
|
|
60
|
-
export const rewards = 33_333n;
|
|
61
|
-
export const delegationAndRewards = { delegate, rewards };
|
|
62
|
-
|
|
63
|
-
export const queryTransactionsResult = [
|
|
64
|
-
{
|
|
65
|
-
hash: 'ea1517b8c36fea3148df9aa1f49bbee66ff59a5092331a67bd8b3c427e1d79d7',
|
|
66
|
-
inputs: [
|
|
67
|
-
{
|
|
68
|
-
txId: 'bb217abaca60fc0ca68c1555eca6a96d2478547818ae76ce6836133f3cc546e0',
|
|
69
|
-
index: 0
|
|
70
|
-
}
|
|
71
|
-
],
|
|
72
|
-
outputs: [
|
|
73
|
-
{
|
|
74
|
-
address:
|
|
75
|
-
'addr_test1qpfhhfy2qgls50r9u4yh0l7z67xpg0a5rrhkmvzcuqrd0znuzcjqw982pcftgx53fu5527z2cj2tkx2h8ux2vxsg475q9gw0lz',
|
|
76
|
-
value: { coins: 5_000_000 }
|
|
77
|
-
},
|
|
78
|
-
{
|
|
79
|
-
address:
|
|
80
|
-
'addr_test1qplfzem2xsc29wxysf8wkdqrm4s4mmncd40qnjq9sk84l3tuzcjqw982pcftgx53fu5527z2cj2tkx2h8ux2vxsg475q52ukj5',
|
|
81
|
-
value: { coins: 5_000_000 }
|
|
82
|
-
},
|
|
83
|
-
{
|
|
84
|
-
address:
|
|
85
|
-
'addr_test1qqydn46r6mhge0kfpqmt36m6q43knzsd9ga32n96m89px3nuzcjqw982pcftgx53fu5527z2cj2tkx2h8ux2vxsg475qypp3m9',
|
|
86
|
-
value: { coins: 9_825_963 }
|
|
87
|
-
}
|
|
88
|
-
]
|
|
89
|
-
}
|
|
90
|
-
];
|
|
91
|
-
const queryTransactions = () => jest.fn().mockResolvedValue(queryTransactionsResult);
|
|
92
|
-
|
|
93
|
-
export const ledgerTip = {
|
|
94
|
-
blockNo: 1_111_111,
|
|
95
|
-
hash: '10d64cc11e9b20e15b6c46aa7b1fed11246f437e62225655a30ea47bf8cc22d0',
|
|
96
|
-
slot: 37_834_496
|
|
97
|
-
};
|
|
98
|
-
|
|
99
|
-
/**
|
|
100
|
-
* Provider stub for testing
|
|
101
|
-
*
|
|
102
|
-
* returns CardanoProvider-compatible object
|
|
103
|
-
*/
|
|
104
|
-
export const providerStub = () => ({
|
|
105
|
-
ledgerTip: jest.fn().mockResolvedValue(ledgerTip),
|
|
106
|
-
networkInfo: async () => ({
|
|
107
|
-
currentEpoch: {
|
|
108
|
-
number: 158,
|
|
109
|
-
start: {
|
|
110
|
-
date: new Date(1_632_255_616)
|
|
111
|
-
},
|
|
112
|
-
end: {
|
|
113
|
-
date: new Date(1_632_687_616)
|
|
114
|
-
}
|
|
115
|
-
},
|
|
116
|
-
lovelaceSupply: {
|
|
117
|
-
circulating: 42_064_399_450_423_723n,
|
|
118
|
-
max: 45_000_000_000_000_000n,
|
|
119
|
-
total: 40_267_211_394_073_980n
|
|
120
|
-
},
|
|
121
|
-
stake: {
|
|
122
|
-
active: 1_060_378_314_781_343n,
|
|
123
|
-
live: 15_001_884_895_856_815n
|
|
124
|
-
}
|
|
125
|
-
}),
|
|
126
|
-
submitTx: jest.fn().mockResolvedValue(void 0),
|
|
127
|
-
stakePoolStats: async () => ({
|
|
128
|
-
qty: {
|
|
129
|
-
active: 1000,
|
|
130
|
-
retired: 500,
|
|
131
|
-
retiring: 5
|
|
132
|
-
}
|
|
133
|
-
}),
|
|
134
|
-
utxoDelegationAndRewards: jest.fn().mockResolvedValue({ utxo, delegationAndRewards }),
|
|
135
|
-
queryTransactionsByAddresses: queryTransactions(),
|
|
136
|
-
queryTransactionsByHashes: queryTransactions(),
|
|
137
|
-
currentWalletProtocolParameters: async () => ({
|
|
138
|
-
minFeeCoefficient: 44,
|
|
139
|
-
minFeeConstant: 155_381,
|
|
140
|
-
stakeKeyDeposit: 2_000_000,
|
|
141
|
-
poolDeposit: 500_000_000,
|
|
142
|
-
protocolVersion: { major: 5, minor: 0 },
|
|
143
|
-
minPoolCost: 340_000_000,
|
|
144
|
-
maxTxSize: 16_384,
|
|
145
|
-
maxValueSize: 1000,
|
|
146
|
-
maxCollateralInputs: 1,
|
|
147
|
-
coinsPerUtxoWord: 34_482
|
|
148
|
-
})
|
|
149
|
-
});
|
|
150
|
-
|
|
151
|
-
export type ProviderStub = ReturnType<typeof providerStub>;
|
package/test/mocks/index.ts
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { Cardano, CardanoSerializationLib } from '@cardano-sdk/core';
|
|
2
|
-
import { KeyManagement } from '../../src';
|
|
3
|
-
|
|
4
|
-
export const testKeyManager = (csl: CardanoSerializationLib) =>
|
|
5
|
-
KeyManagement.createInMemoryKeyManager({
|
|
6
|
-
csl,
|
|
7
|
-
mnemonicWords: KeyManagement.util.generateMnemonicWords(),
|
|
8
|
-
password: '',
|
|
9
|
-
networkId: Cardano.NetworkId.testnet
|
|
10
|
-
});
|
package/test/tsconfig.json
DELETED