@cardano-sdk/e2e 0.16.6-patch.3 → 0.16.7

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.
Files changed (130) hide show
  1. package/.env.example +4 -6
  2. package/CHANGELOG.md +9 -15
  3. package/README.md +2 -18
  4. package/dist/cjs/environment.d.ts +1 -1
  5. package/dist/cjs/environment.d.ts.map +1 -1
  6. package/dist/cjs/environment.js +1 -15
  7. package/dist/cjs/environment.js.map +1 -1
  8. package/dist/cjs/factories.d.ts +0 -2
  9. package/dist/cjs/factories.d.ts.map +1 -1
  10. package/dist/cjs/factories.js +6 -12
  11. package/dist/cjs/factories.js.map +1 -1
  12. package/dist/cjs/index.d.ts +0 -1
  13. package/dist/cjs/index.d.ts.map +1 -1
  14. package/dist/cjs/index.js +0 -1
  15. package/dist/cjs/index.js.map +1 -1
  16. package/dist/cjs/scripts/is-local-network-ready.js +5 -28
  17. package/dist/cjs/scripts/is-local-network-ready.js.map +1 -1
  18. package/dist/cjs/tools/multi-delegation-data-gen/index.js +13 -3
  19. package/dist/cjs/tools/multi-delegation-data-gen/index.js.map +1 -1
  20. package/dist/cjs/tools/multi-delegation-data-gen/utils/config.d.ts +1 -0
  21. package/dist/cjs/tools/multi-delegation-data-gen/utils/config.d.ts.map +1 -1
  22. package/dist/cjs/tools/multi-delegation-data-gen/utils/config.js +12 -0
  23. package/dist/cjs/tools/multi-delegation-data-gen/utils/config.js.map +1 -1
  24. package/dist/cjs/tools/multi-delegation-data-gen/utils/utils.d.ts +2 -5
  25. package/dist/cjs/tools/multi-delegation-data-gen/utils/utils.d.ts.map +1 -1
  26. package/dist/cjs/tools/multi-delegation-data-gen/utils/utils.js +12 -49
  27. package/dist/cjs/tools/multi-delegation-data-gen/utils/utils.js.map +1 -1
  28. package/dist/cjs/tsconfig.tsbuildinfo +1 -1
  29. package/dist/cjs/util/util.d.ts +0 -1
  30. package/dist/cjs/util/util.d.ts.map +1 -1
  31. package/dist/cjs/util/util.js +2 -43
  32. package/dist/cjs/util/util.js.map +1 -1
  33. package/dist/esm/environment.d.ts +1 -1
  34. package/dist/esm/environment.d.ts.map +1 -1
  35. package/dist/esm/environment.js +1 -15
  36. package/dist/esm/environment.js.map +1 -1
  37. package/dist/esm/factories.d.ts +0 -2
  38. package/dist/esm/factories.d.ts.map +1 -1
  39. package/dist/esm/factories.js +6 -12
  40. package/dist/esm/factories.js.map +1 -1
  41. package/dist/esm/index.d.ts +0 -1
  42. package/dist/esm/index.d.ts.map +1 -1
  43. package/dist/esm/index.js +0 -1
  44. package/dist/esm/index.js.map +1 -1
  45. package/dist/esm/scripts/is-local-network-ready.js +5 -5
  46. package/dist/esm/scripts/is-local-network-ready.js.map +1 -1
  47. package/dist/esm/tools/multi-delegation-data-gen/index.js +14 -4
  48. package/dist/esm/tools/multi-delegation-data-gen/index.js.map +1 -1
  49. package/dist/esm/tools/multi-delegation-data-gen/utils/config.d.ts +1 -0
  50. package/dist/esm/tools/multi-delegation-data-gen/utils/config.d.ts.map +1 -1
  51. package/dist/esm/tools/multi-delegation-data-gen/utils/config.js +12 -0
  52. package/dist/esm/tools/multi-delegation-data-gen/utils/config.js.map +1 -1
  53. package/dist/esm/tools/multi-delegation-data-gen/utils/utils.d.ts +2 -5
  54. package/dist/esm/tools/multi-delegation-data-gen/utils/utils.d.ts.map +1 -1
  55. package/dist/esm/tools/multi-delegation-data-gen/utils/utils.js +11 -45
  56. package/dist/esm/tools/multi-delegation-data-gen/utils/utils.js.map +1 -1
  57. package/dist/esm/tsconfig.tsbuildinfo +1 -1
  58. package/dist/esm/util/util.d.ts +0 -1
  59. package/dist/esm/util/util.d.ts.map +1 -1
  60. package/dist/esm/util/util.js +3 -20
  61. package/dist/esm/util/util.js.map +1 -1
  62. package/docker-compose.yml +3 -21
  63. package/local-network/scripts/mint-handles.sh +108 -6
  64. package/local-network/scripts/mint-tokens.sh +21 -2
  65. package/local-network/scripts/mnemonic_keys.sh +14 -0
  66. package/local-network/scripts/setup-wallets.sh +18 -0
  67. package/local-network/scripts/start.sh +1 -2
  68. package/package.json +22 -20
  69. package/src/environment.ts +1 -19
  70. package/src/factories.ts +5 -13
  71. package/src/index.ts +0 -1
  72. package/src/scripts/is-local-network-ready.ts +6 -8
  73. package/src/tools/multi-delegation-data-gen/example.json +1 -0
  74. package/src/tools/multi-delegation-data-gen/index.ts +18 -8
  75. package/src/tools/multi-delegation-data-gen/utils/config.ts +13 -0
  76. package/src/tools/multi-delegation-data-gen/utils/utils.ts +13 -110
  77. package/src/util/util.ts +2 -29
  78. package/test/k6/endpoints/asset/get-asset.test.js +15 -14
  79. package/test/k6/endpoints/asset/get-assets.test.js +269 -269
  80. package/test/k6/endpoints/chain-history/blocks/by-hashes.test.js +12 -11
  81. package/test/k6/endpoints/chain-history/txs/by-addresses.test.js +18 -15
  82. package/test/k6/endpoints/chain-history/txs/by-hashes.test.js +12 -11
  83. package/test/k6/endpoints/network-info/era-summaries.test.js +11 -10
  84. package/test/k6/endpoints/network-info/genesis-parameters.test.js +11 -10
  85. package/test/k6/endpoints/network-info/ledger-tip.test.js +11 -10
  86. package/test/k6/endpoints/network-info/lovelace-supply.test.js +11 -10
  87. package/test/k6/endpoints/network-info/protocol-parameters.test.js +11 -10
  88. package/test/k6/endpoints/network-info/stake.test.js +11 -10
  89. package/test/k6/endpoints/rewards/account-balance.test.js +12 -11
  90. package/test/k6/endpoints/stake-pool/stats.test.js +11 -10
  91. package/test/k6/endpoints/utxo/utxo-by-addresses.test.js +16 -11
  92. package/test/k6/scenarios/tx-submission.test.js +47 -46
  93. package/test/k6/scenarios/wallet-creation.test.js +127 -120
  94. package/test/k6/scenarios/wallet-restoration.test.js +264 -126
  95. package/test/long-running/cache-invalidation.test.ts +64 -13
  96. package/test/providers/HandleProvider.test.ts +39 -0
  97. package/test/wallet/PersonalWallet/handle.test.ts +38 -16
  98. package/test/web-extension/webpack.config.base.js +0 -4
  99. package/dist/cjs/FaucetProvider/index.d.ts +0 -3
  100. package/dist/cjs/FaucetProvider/index.d.ts.map +0 -1
  101. package/dist/cjs/FaucetProvider/index.js +0 -19
  102. package/dist/cjs/FaucetProvider/index.js.map +0 -1
  103. package/dist/cjs/FaucetProvider/providers/cardanoWalletFaucetProvider.d.ts +0 -15
  104. package/dist/cjs/FaucetProvider/providers/cardanoWalletFaucetProvider.d.ts.map +0 -1
  105. package/dist/cjs/FaucetProvider/providers/cardanoWalletFaucetProvider.js +0 -148
  106. package/dist/cjs/FaucetProvider/providers/cardanoWalletFaucetProvider.js.map +0 -1
  107. package/dist/cjs/FaucetProvider/types.d.ts +0 -22
  108. package/dist/cjs/FaucetProvider/types.d.ts.map +0 -1
  109. package/dist/cjs/FaucetProvider/types.js +0 -14
  110. package/dist/cjs/FaucetProvider/types.js.map +0 -1
  111. package/dist/esm/FaucetProvider/index.d.ts +0 -3
  112. package/dist/esm/FaucetProvider/index.d.ts.map +0 -1
  113. package/dist/esm/FaucetProvider/index.js +0 -3
  114. package/dist/esm/FaucetProvider/index.js.map +0 -1
  115. package/dist/esm/FaucetProvider/providers/cardanoWalletFaucetProvider.d.ts +0 -15
  116. package/dist/esm/FaucetProvider/providers/cardanoWalletFaucetProvider.d.ts.map +0 -1
  117. package/dist/esm/FaucetProvider/providers/cardanoWalletFaucetProvider.js +0 -141
  118. package/dist/esm/FaucetProvider/providers/cardanoWalletFaucetProvider.js.map +0 -1
  119. package/dist/esm/FaucetProvider/types.d.ts +0 -22
  120. package/dist/esm/FaucetProvider/types.d.ts.map +0 -1
  121. package/dist/esm/FaucetProvider/types.js +0 -10
  122. package/dist/esm/FaucetProvider/types.js.map +0 -1
  123. package/local-network/faucet/README.md +0 -12
  124. package/local-network/faucet/faucet-addresses.json +0 -45
  125. package/local-network/faucet/faucet-mnemonic.json +0 -6
  126. package/local-network/faucet/faucet-send-funds.json +0 -23
  127. package/local-network/scripts/is-faucet-ready.sh +0 -29
  128. package/src/FaucetProvider/index.ts +0 -2
  129. package/src/FaucetProvider/providers/cardanoWalletFaucetProvider.ts +0 -233
  130. package/src/FaucetProvider/types.ts +0 -94
@@ -1,10 +0,0 @@
1
- export var FaucetRequestTransactionStatus;
2
- (function (FaucetRequestTransactionStatus) {
3
- FaucetRequestTransactionStatus[FaucetRequestTransactionStatus["Pending"] = 0] = "Pending";
4
- FaucetRequestTransactionStatus[FaucetRequestTransactionStatus["Submitted"] = 1] = "Submitted";
5
- FaucetRequestTransactionStatus[FaucetRequestTransactionStatus["InLedger"] = 2] = "InLedger";
6
- FaucetRequestTransactionStatus[FaucetRequestTransactionStatus["Expired"] = 3] = "Expired";
7
- })(FaucetRequestTransactionStatus || (FaucetRequestTransactionStatus = {}));
8
- export class FaucetRequestResult {
9
- }
10
- //# sourceMappingURL=types.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/FaucetProvider/types.ts"],"names":[],"mappings":"AAOA,MAAM,CAAN,IAAY,8BAKX;AALD,WAAY,8BAA8B;IACxC,yFAAO,CAAA;IACP,6FAAS,CAAA;IACT,2FAAQ,CAAA;IACR,yFAAO,CAAA;AACT,CAAC,EALW,8BAA8B,KAA9B,8BAA8B,QAKzC;AAKD,MAAM,OAAO,mBAAmB;CAqB/B"}
@@ -1,12 +0,0 @@
1
- # Create Faucet wallet
2
- curl http://localhost:8090/v2/wallets -H 'Content-Type: application/json' -H 'Accept: application/json' -d @./faucet/faucet-mnemonic.json
3
-
4
- # Get Faucet wallet
5
- curl http://localhost:8090/v2/wallets/7991322ed68894d0f1fb645a74576c3780ab312c -H 'Content-Type: application/json' -H 'Accept: application/json'
6
-
7
- # Transfer Funds from wallet
8
- curl http://localhost:8090/v2/wallets/7991322ed68894d0f1fb645a74576c3780ab312c/transactions -H 'Content-Type: application/json' -H 'Accept: application/json' -d @./faucet/faucet-send-funds.json
9
-
10
- # Track Transaction
11
- curl http://localhost:8090/v2/wallets/7991322ed68894d0f1fb645a74576c3780ab312c/transactions/927e2e95d78ef331b3b67f0d8f24123e5356972f0589202a725eda690349afa1 -H 'Content-Type: application/json' -H 'Accept: application/json'
12
-
@@ -1,45 +0,0 @@
1
- [{
2
- "id": "addr_test1qqen0wpmhg7fhkus45lyv4wju26cecgu6avplrnm6dgvuk6qel5hu3u3q0fht53ly97yx95hkt56j37ch07pesf6s4pqh5gd4e",
3
- "state": "unused",
4
- "derivation_path": ["1852H", "1815H", "0H", "0", "0"]
5
- }, {
6
- "id": "addr_test1qqmer3kgnlthg8k4gm9aljmmyfln47cgh2rf8aje5y79eazqel5hu3u3q0fht53ly97yx95hkt56j37ch07pesf6s4pqxzvaqz",
7
- "state": "unused",
8
- "derivation_path": ["1852H", "1815H", "0H", "0", "1"]
9
- }, {
10
- "id": "addr_test1qpxc7yqpqegw7f4pqf9m63ake95k2q9dfqlzhmwkwuell0jqel5hu3u3q0fht53ly97yx95hkt56j37ch07pesf6s4pq5f4xje",
11
- "state": "unused",
12
- "derivation_path": ["1852H", "1815H", "0H", "0", "2"]
13
- }, {
14
- "id": "addr_test1qpc3gp8ysrapwtax6hdav4s268meg8h8cu8609luzk74xqjqel5hu3u3q0fht53ly97yx95hkt56j37ch07pesf6s4pq8svsgq",
15
- "state": "unused",
16
- "derivation_path": ["1852H", "1815H", "0H", "0", "3"]
17
- }, {
18
- "id": "addr_test1qqk84jm7tll463syq0gln0q3z4c7rq2mlcwn47uwk22qs4zqel5hu3u3q0fht53ly97yx95hkt56j37ch07pesf6s4pqlpe473",
19
- "state": "unused",
20
- "derivation_path": ["1852H", "1815H", "0H", "0", "4"]
21
- }, {
22
- "id": "addr_test1qphcpmtp2kj78mcu78ezjqnawxzp29yvnh8mdd9ywvw7h56qel5hu3u3q0fht53ly97yx95hkt56j37ch07pesf6s4pq4nwldc",
23
- "state": "unused",
24
- "derivation_path": ["1852H", "1815H", "0H", "0", "5"]
25
- }, {
26
- "id": "addr_test1qp3v6hunrj5aj2j78lepl003wttye5znphynx6epmg8m3r6qel5hu3u3q0fht53ly97yx95hkt56j37ch07pesf6s4pqjejcv4",
27
- "state": "unused",
28
- "derivation_path": ["1852H", "1815H", "0H", "0", "6"]
29
- }, {
30
- "id": "addr_test1qzfawep8h3vls60qudr7zeuhjhv2mrg5sjj5r0yyrs4thr6qel5hu3u3q0fht53ly97yx95hkt56j37ch07pesf6s4pqqdmtyh",
31
- "state": "unused",
32
- "derivation_path": ["1852H", "1815H", "0H", "0", "7"]
33
- }, {
34
- "id": "addr_test1qzknu4uqjss6sda2jpt9pne95u2mhg82vtfeq4xdxk9jah2qel5hu3u3q0fht53ly97yx95hkt56j37ch07pesf6s4pqfv2ftn",
35
- "state": "unused",
36
- "derivation_path": ["1852H", "1815H", "0H", "0", "8"]
37
- }, {
38
- "id": "addr_test1qpx986ct0jrqdhs924s5qsk629vuzw7mpadmwke7hsk3z5zqel5hu3u3q0fht53ly97yx95hkt56j37ch07pesf6s4pqmhx5xw",
39
- "state": "unused",
40
- "derivation_path": ["1852H", "1815H", "0H", "0", "9"]
41
- }, {
42
- "id": "addr_test1qrlmds0rl093pg2ywtqr4p5hjagm40a397r8whalwqmw4czqel5hu3u3q0fht53ly97yx95hkt56j37ch07pesf6s4pqz45ud0",
43
- "state": "unused",
44
- "derivation_path": ["1852H", "1815H", "0H", "0", "10"]
45
- }]
@@ -1,6 +0,0 @@
1
- {
2
- "name": "Faucet",
3
- "mnemonic_sentence": ["fire", "method", "repair", "aware", "foot", "tray", "accuse", "brother", "popular", "olive", "find", "account", "sick", "rocket", "next"],
4
- "passphrase": "passphrase",
5
- "address_pool_gap": 20
6
- }
@@ -1,23 +0,0 @@
1
- {
2
- "passphrase": "passphrase",
3
- "payments": [{
4
- "address": "addr_test1vrgylrse49du60jdy7h46mg5mwft6kw8r0l4v5pklkj324cm247gf",
5
- "amount": {
6
- "quantity": 42000000,
7
- "unit": "lovelace"
8
- },
9
- "assets": []
10
- }],
11
- "withdrawal": "self",
12
- "metadata": {
13
- "0": {},
14
- "1": {},
15
- "2": {},
16
- "3": {},
17
- "4": {}
18
- },
19
- "time_to_live": {
20
- "quantity": 10,
21
- "unit": "second"
22
- }
23
- }
@@ -1,29 +0,0 @@
1
- #!/usr/bin/env bash
2
-
3
- set -euo pipefail
4
-
5
- here="$(cd "$(dirname "$0")" >/dev/null 2>&1 && pwd)"
6
- root="$(cd "$here/.." && pwd)"
7
-
8
- cd "$root"
9
-
10
- export PATH=$PWD/bin:$PATH
11
-
12
- WALLET_ID="7991322ed68894d0f1fb645a74576c3780ab312c"
13
- PORT=8090
14
- FAUCET_WALLET='{"name": "Faucet", "mnemonic_sentence": ["fire", "method", "repair", "aware", "foot", "tray", "accuse", "brother", "popular", "olive", "find", "account", "sick", "rocket", "next"], "passphrase": "passphrase", "address_pool_gap": 20 }'
15
-
16
- # Add Faucet wallet
17
- curl -s http://localhost:"$PORT"/v2/wallets -H 'Content-Type: application/json' -H 'Accept: application/json' -d "$FAUCET_WALLET" > /dev/null
18
-
19
- # Get wallet status
20
- status=$(curl -s http://localhost:"$PORT"/v2/wallets/"$WALLET_ID" -H 'Content-Type: application/json' -H 'Accept: application/json' | jq .state.status)
21
- epoch=$(curl -s http://localhost:"$PORT"/v2/wallets/"$WALLET_ID" -H 'Content-Type: application/json' -H 'Accept: application/json' | jq .tip.epoch_number)
22
- totalBalance=$(curl -s http://localhost:"$PORT"/v2/wallets/"$WALLET_ID" -H 'Content-Type: application/json' -H 'Accept: application/json' | jq .balance.total.quantity)
23
-
24
- if [[ "$status" == "\"ready\"" && $epoch -gt 4 && $totalBalance -gt 100000000 ]]; then # Faucet will be marked unhealthy if 100 or less tADA remains in the faucet wallet (initial balance is 13.5 billion tADA)
25
- exit 0
26
- fi
27
-
28
- exit 9
29
-
@@ -1,2 +0,0 @@
1
- export * from './types';
2
- export * from './providers/cardanoWalletFaucetProvider';
@@ -1,233 +0,0 @@
1
- import {
2
- AddressWallet,
3
- ApiNetworkInformationSyncProgressStatusEnum,
4
- ApiTransactionStatusEnum,
5
- TransactionWallet,
6
- WalletServer
7
- } from 'cardano-wallet-js';
8
- import { Cardano, HealthCheckResponse } from '@cardano-sdk/core';
9
- import { FaucetProvider, FaucetRequestResult, FaucetRequestTransactionStatus } from '../types';
10
- import { Stopwatch } from 'ts-stopwatch';
11
- import Process from 'process';
12
-
13
- // Constants
14
- const FAUCET_PASSPHRASE = 'passphrase';
15
- const FAUCET_WALLET_NAME = 'faucet';
16
- const HTTP_ERROR_CODE_IN_CONFLICT = 409;
17
- const DEFAULT_TIMEOUT = 10_000;
18
- const DEFAULT_CONFIRMATIONS = 0;
19
- const PARAM_NAME_URL = 'baseUrl';
20
- const PARAM_NAME_MNEMONICS = 'mnemonic';
21
-
22
- const sleep = (ms: number) => new Promise((resolve) => setTimeout(resolve, ms));
23
-
24
- /**
25
- * Cardano Wallet implementation of the faucet provider. This provider utlizes the Cardano Wallet HTTP service
26
- * to construct, sign, submit and track the transaction generated by the faucet.
27
- */
28
- export class CardanoWalletFaucetProvider implements FaucetProvider {
29
- #serviceUrl = '';
30
- #seedPhrases = '';
31
- #faucetWalletId = '';
32
- #walletServer: WalletServer;
33
-
34
- /**
35
- * Initializes a new instance of the CardanoWalletFaucetService class.
36
- *
37
- * @param url The cardano wallet server REST endpoint.
38
- * @param seedPhrases The seedphrases of the faucet wallet.
39
- */
40
- constructor(url: string, seedPhrases: string) {
41
- this.#serviceUrl = url;
42
- this.#seedPhrases = seedPhrases;
43
- }
44
-
45
- /**
46
- * Request tAda to be transferred to a single given address.
47
- *
48
- * @param address The address where the tAda must be deposited.
49
- * @param amount The amount of tAda to be deposited at the given address address (in lovelace).
50
- * @param confirmations The number of blocks that has passed since our transaction was added to the blockchain.
51
- * @param timeout The time we are willing to wait (in milliseconds) for the faucet request
52
- * transaction to be confirmed.
53
- */
54
- public async request(
55
- address: string,
56
- amount: number,
57
- confirmations: number = DEFAULT_CONFIRMATIONS,
58
- timeout: number = DEFAULT_TIMEOUT
59
- ): Promise<FaucetRequestResult> {
60
- return this.multiRequest([address], [amount], confirmations, timeout);
61
- }
62
-
63
- /**
64
- * Request tAda to be transferred to the given address.
65
- *
66
- * @param addresses The addresses where the tAda must be deposited.
67
- * @param amounts The amounts of tAda to be deposited at each address (in lovelace).
68
- * @param confirmations The number of blocks that has passed since our transaction was added to the blockchain.
69
- * @param timeout The time we are willing to wait (in milliseconds) for the faucet request
70
- * transaction to be confirmed.
71
- */
72
- public async multiRequest(
73
- addresses: string[],
74
- amounts: number[],
75
- confirmations: number = DEFAULT_CONFIRMATIONS,
76
- timeout: number = DEFAULT_TIMEOUT
77
- ): Promise<FaucetRequestResult> {
78
- const faucetWallet = await this.#walletServer.getShelleyWallet(this.#faucetWalletId);
79
-
80
- const receiverAddress = addresses.map((strAddress) => new AddressWallet(strAddress));
81
-
82
- const stopwatch = new Stopwatch();
83
- stopwatch.start();
84
-
85
- let transaction: TransactionWallet = await faucetWallet.sendPayment(FAUCET_PASSPHRASE, receiverAddress, amounts);
86
-
87
- let isTransactionConfirmed = false;
88
- while (
89
- (transaction.status === ApiTransactionStatusEnum.Pending || !isTransactionConfirmed) &&
90
- stopwatch.getTime() < timeout
91
- ) {
92
- transaction = await faucetWallet.getTransaction(transaction.id);
93
- isTransactionConfirmed = transaction.depth !== undefined && transaction.depth.quantity >= confirmations;
94
- }
95
-
96
- stopwatch.stop();
97
-
98
- if (stopwatch.getTime() >= timeout) throw new Error(`The transaction ${transaction.id} was not confirmed on time`);
99
-
100
- return {
101
- confirmations: transaction.depth?.quantity,
102
- id: Cardano.TransactionId(transaction.id),
103
- status: this.mapStatus(transaction.status),
104
- time: transaction.inserted_at?.time
105
- };
106
- }
107
-
108
- /**
109
- * Starts the provider.
110
- */
111
- public async start(): Promise<void> {
112
- const walletInfo = {
113
- mnemonic_sentence: this.#seedPhrases.split(' '),
114
- name: FAUCET_WALLET_NAME,
115
- passphrase: FAUCET_PASSPHRASE
116
- };
117
-
118
- this.#walletServer = WalletServer.init(this.#serviceUrl);
119
-
120
- const axiosResponse = await this.#walletServer.walletsApi.postWallet(walletInfo).catch((error) => {
121
- if (error.response === undefined) throw error;
122
-
123
- // This seed phrases already exists on the cardano wallet service.
124
- if (error.response.status === HTTP_ERROR_CODE_IN_CONFLICT) {
125
- // TODO: If the seedphrases were already added to Cardano Wallet, the id of the wallet
126
- // will be returned in an error message, we can then extract the id from the message, however
127
- // this extremely brittle. We must find a better way to get the wallet id given a set of seed phrases.
128
- this.#faucetWalletId = error.response.data.message.match(/(?<=: ).*(?= H)/g)[0];
129
- } else {
130
- throw error.response.data;
131
- }
132
- });
133
-
134
- if (axiosResponse) this.#faucetWalletId = axiosResponse.data.id;
135
-
136
- const start = Date.now() / 1000;
137
- const waitTime = Process.env.LOCAL_NETWORK_READY_WAIT_TIME ? Process.env.LOCAL_NETWORK_READY_WAIT_TIME : 1200;
138
- let isReady = false;
139
- let currentElapsed = 0;
140
-
141
- while (!isReady && currentElapsed < waitTime) {
142
- try {
143
- isReady = (await this.healthCheck()).ok;
144
- } catch {
145
- // continue
146
- } finally {
147
- currentElapsed = Date.now() / 1000 - start;
148
- await sleep(5000);
149
- }
150
- }
151
-
152
- if (currentElapsed > waitTime) {
153
- throw new Error('Wait time expired. The faucet was not ready on time.');
154
- }
155
- }
156
-
157
- /**
158
- * Gets the remaining balance on the faucet.
159
- */
160
- public async getBalance(): Promise<number> {
161
- if (this.#faucetWalletId === undefined) throw new Error('Faucet is not running.');
162
-
163
- const axiosResponse = await this.#walletServer.walletsApi.getWallet(this.#faucetWalletId);
164
- return axiosResponse.data.balance.total.quantity;
165
- }
166
-
167
- /**
168
- * Closes the provider.
169
- */
170
- public async close(): Promise<void> {
171
- this.#faucetWalletId = '';
172
- }
173
-
174
- /**
175
- * Performs a health check on the provider.
176
- *
177
- * @returns A promise with the healthcheck reponse.
178
- */
179
- public async healthCheck(): Promise<HealthCheckResponse> {
180
- const networkInfo = await this.#walletServer.getNetworkInformation();
181
-
182
- return {
183
- ok:
184
- networkInfo.sync_progress.status === ApiNetworkInformationSyncProgressStatusEnum.Ready &&
185
- this.#faucetWalletId !== '' &&
186
- (await this.getBalance()) > 100_000_000 // Faucet must have more than 100 tADA to be considered healthy
187
- };
188
- }
189
-
190
- /**
191
- * Converts the cardano wallet transaction result enum to our FaucetRequestTransactionStatus enum.
192
- *
193
- * @param status The cardano wallet enum to be converted.
194
- * @returns The FaucetRequestTransactionStatus equivalent enum value.
195
- */
196
- private mapStatus(status: ApiTransactionStatusEnum): FaucetRequestTransactionStatus {
197
- let mappedStatus: FaucetRequestTransactionStatus = FaucetRequestTransactionStatus.Expired;
198
- switch (status) {
199
- case ApiTransactionStatusEnum.Expired:
200
- mappedStatus = FaucetRequestTransactionStatus.Expired;
201
- break;
202
- case ApiTransactionStatusEnum.InLedger:
203
- mappedStatus = FaucetRequestTransactionStatus.InLedger;
204
- break;
205
- case ApiTransactionStatusEnum.Pending:
206
- mappedStatus = FaucetRequestTransactionStatus.Pending;
207
- break;
208
- }
209
-
210
- return mappedStatus;
211
- }
212
-
213
- /**
214
- * Create a new faucet provider.
215
- *
216
- * @param params The parameters to be passed to the concrete implementation constructor.
217
- * @returns The new Faucet provider.
218
- * @throws if The give provider name is not registered, or the constructor parameters of
219
- * the providers are either missing or invalid.
220
- */
221
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
222
- public static create(params: any): Promise<FaucetProvider> {
223
- if (!params.hasOwnProperty(PARAM_NAME_URL))
224
- throw new Error(`${CardanoWalletFaucetProvider.name} missing argument: ${PARAM_NAME_URL}`);
225
-
226
- if (!params.hasOwnProperty(PARAM_NAME_MNEMONICS))
227
- throw new Error(`${CardanoWalletFaucetProvider.name} missing argument: ${PARAM_NAME_MNEMONICS}`);
228
-
229
- return new Promise<FaucetProvider>((resolve) => {
230
- resolve(new CardanoWalletFaucetProvider(params[PARAM_NAME_URL], params[PARAM_NAME_MNEMONICS]));
231
- });
232
- }
233
- }
@@ -1,94 +0,0 @@
1
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
2
- // @ts-ignore
3
- import { Cardano, HealthCheckResponse, Provider } from '@cardano-sdk/core';
4
-
5
- /**
6
- * Faucet request transaction status.
7
- */
8
- export enum FaucetRequestTransactionStatus {
9
- Pending,
10
- Submitted,
11
- InLedger,
12
- Expired
13
- }
14
-
15
- /**
16
- * Result for a faucet request.
17
- */
18
- export class FaucetRequestResult {
19
- /**
20
- * The transaction id of the transaction generated by this request.
21
- */
22
- id: Cardano.TransactionId;
23
-
24
- /**
25
- * Current status of the transaction generated by this request in the local chain .
26
- */
27
- status: FaucetRequestTransactionStatus;
28
-
29
- /**
30
- * Absolute time at which the transaction generated by this reuqest was inserted in a block.
31
- */
32
- time: string;
33
-
34
- /**
35
- * How many blocks has passed since our transaction was added to the Cardano blockchain. The more
36
- * confirmations that have occured, the more secure the transaction is.
37
- */
38
- confirmations: number;
39
- }
40
-
41
- /**
42
- * The faucet provider enable clients to request arbitrary amounts of tAda from current local network
43
- * to fund any address. This is useful for the setup of preconditions for end-to-end tests.
44
- */
45
- export interface FaucetProvider extends Provider {
46
- /**
47
- * Request tAda to be transferred to a single given address.
48
- *
49
- * @param address The address where the tAda must be deposited.
50
- * @param amount The amount of tAda to be deposited at the given address address (in lovelace).
51
- * @param timeout The time we are willing to wait (in milliseconds) for the faucet request
52
- * transaction to be confirmed.
53
- * @param confirmations The number of blocks that has passed since our transaction was added to the blockchain.
54
- */
55
- request(address: string, amount: number, confirmations?: number, timeout?: number): Promise<FaucetRequestResult>;
56
-
57
- /**
58
- * Request tAda to be transferred to several given addresses.
59
- *
60
- * @param addresses The addresses where the tAda must be deposited.
61
- * @param amounts The amounts of tAda to be deposited at each address (in lovelace).
62
- * @param timeout The time we are willing to wait (in milliseconds) for the faucet request
63
- * transaction to be confirmed.
64
- * @param confirmations The number of blocks that has passed since our transaction was added to the blockchain.
65
- */
66
- multiRequest(
67
- addresses: string[],
68
- amounts: number[],
69
- confirmations?: number,
70
- timeout?: number
71
- ): Promise<FaucetRequestResult>;
72
-
73
- /**
74
- * Initializes the faucet provider.
75
- */
76
- start(): Promise<void>;
77
-
78
- /**
79
- * Finalizes the faucet provider.
80
- */
81
- close(): Promise<void>;
82
-
83
- /**
84
- * Gets the remaining balance on the faucet.
85
- */
86
- getBalance(): Promise<number>;
87
-
88
- /**
89
- * Performs a health check on the provider.
90
- *
91
- * @returns A promise with the healthcheck reponse.
92
- */
93
- healthCheck(): Promise<HealthCheckResponse>;
94
- }