essential-eth 0.9.1-next.0 → 0.9.1-next.1

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 (104) hide show
  1. package/dist/cjs/classes/Contract.js +66 -311
  2. package/dist/cjs/classes/test/Contract/crv-abi.js +256 -252
  3. package/dist/cjs/classes/test/Contract/ens-abi.js +212 -497
  4. package/dist/cjs/classes/test/Contract/fei-abi.js +284 -605
  5. package/dist/cjs/classes/test/Contract/foo-abi.js +21 -44
  6. package/dist/cjs/classes/test/Contract/uniswap-abi.js +68 -64
  7. package/dist/cjs/classes/utils/clean-block.js +30 -52
  8. package/dist/cjs/classes/utils/clean-log.js +20 -42
  9. package/dist/cjs/classes/utils/clean-transaction-receipt.js +30 -51
  10. package/dist/cjs/classes/utils/clean-transaction.js +30 -52
  11. package/dist/cjs/classes/utils/encode-decode-transaction.js +107 -148
  12. package/dist/cjs/classes/utils/fetchers.js +44 -166
  13. package/dist/cjs/classes/utils/hex-to-decimal.js +6 -1
  14. package/dist/cjs/classes/utils/prepare-transaction.js +36 -59
  15. package/dist/cjs/index.js +56 -25
  16. package/dist/cjs/index.umd.js +1 -1
  17. package/dist/cjs/index.umd.js.map +1 -1
  18. package/dist/cjs/logger/logger.js +29 -123
  19. package/dist/cjs/logger/package-version.d.ts +1 -1
  20. package/dist/cjs/logger/package-version.js +4 -1
  21. package/dist/cjs/providers/AlchemyProvider.js +9 -82
  22. package/dist/cjs/providers/BaseProvider.js +520 -958
  23. package/dist/cjs/providers/FallthroughProvider.js +47 -156
  24. package/dist/cjs/providers/JsonRpcProvider.js +28 -114
  25. package/dist/cjs/providers/test/json-rpc-provider/get-logs/mocks.js +104 -101
  26. package/dist/cjs/providers/test/mock-of.js +6 -3
  27. package/dist/cjs/providers/test/rpc-urls.js +23 -15
  28. package/dist/cjs/providers/utils/chains-info.js +3 -1
  29. package/dist/cjs/shared/tiny-big/helpers.js +42 -93
  30. package/dist/cjs/shared/tiny-big/tiny-big.js +81 -210
  31. package/dist/cjs/shared/validate-type.js +7 -7
  32. package/dist/cjs/types/Block.types.js +2 -1
  33. package/dist/cjs/types/Contract.types.js +2 -1
  34. package/dist/cjs/types/FeeData.types.js +2 -1
  35. package/dist/cjs/types/Filter.types.js +2 -1
  36. package/dist/cjs/types/Network.types.js +2 -3
  37. package/dist/cjs/types/Transaction.types.js +2 -1
  38. package/dist/cjs/utils/bytes.js +318 -286
  39. package/dist/cjs/utils/compute-address.js +15 -8
  40. package/dist/cjs/utils/compute-public-key.js +10 -5
  41. package/dist/cjs/utils/ether-to-gwei.js +11 -10
  42. package/dist/cjs/utils/ether-to-wei.js +11 -10
  43. package/dist/cjs/utils/gwei-to-ether.js +11 -10
  44. package/dist/cjs/utils/hash-message.js +16 -11
  45. package/dist/cjs/utils/is-address.js +12 -8
  46. package/dist/cjs/utils/keccak256.js +14 -8
  47. package/dist/cjs/utils/solidity-keccak256.js +60 -49
  48. package/dist/cjs/utils/split-signature.js +73 -55
  49. package/dist/cjs/utils/to-checksum-address.js +20 -15
  50. package/dist/cjs/utils/to-utf8-bytes.js +6 -1
  51. package/dist/cjs/utils/wei-to-ether.js +15 -13
  52. package/dist/esm/logger/package-version.d.ts +1 -1
  53. package/dist/esm/logger/package-version.js +1 -1
  54. package/package.json +2 -2
  55. package/readme.md +1 -1
  56. package/dist/cjs/classes/test/Contract/crv.test.js +0 -497
  57. package/dist/cjs/classes/test/Contract/ens.test.js +0 -160
  58. package/dist/cjs/classes/test/Contract/fei.test.js +0 -224
  59. package/dist/cjs/classes/test/Contract/foo.test.js +0 -33
  60. package/dist/cjs/classes/test/Contract/uni.test.js +0 -289
  61. package/dist/cjs/providers/test/fallthrough-provider/get-gas-price.test.js +0 -228
  62. package/dist/cjs/providers/test/get-transaction-count.test.js +0 -239
  63. package/dist/cjs/providers/test/json-rpc-provider/call.test.js +0 -375
  64. package/dist/cjs/providers/test/json-rpc-provider/estimate-gas.test.js +0 -217
  65. package/dist/cjs/providers/test/json-rpc-provider/get-balance.test.js +0 -223
  66. package/dist/cjs/providers/test/json-rpc-provider/get-block-number.test.js +0 -163
  67. package/dist/cjs/providers/test/json-rpc-provider/get-block.test.js +0 -414
  68. package/dist/cjs/providers/test/json-rpc-provider/get-code.test.js +0 -282
  69. package/dist/cjs/providers/test/json-rpc-provider/get-fee-data.test.js +0 -187
  70. package/dist/cjs/providers/test/json-rpc-provider/get-gas-price.test.js +0 -167
  71. package/dist/cjs/providers/test/json-rpc-provider/get-logs/get-logs.test.js +0 -219
  72. package/dist/cjs/providers/test/json-rpc-provider/get-network.test.js +0 -232
  73. package/dist/cjs/providers/test/json-rpc-provider/get-transaction-receipt.test.js +0 -280
  74. package/dist/cjs/providers/test/json-rpc-provider/get-transaction.test.js +0 -266
  75. package/dist/cjs/providers/test/test-alchemy-provider.test.js +0 -151
  76. package/dist/cjs/shared/tiny-big/helpers.test.js +0 -29
  77. package/dist/cjs/shared/tiny-big/tiny-big.test.js +0 -34
  78. package/dist/cjs/utils/tests/bytes/arrayify.test.js +0 -64
  79. package/dist/cjs/utils/tests/bytes/concat.test.js +0 -17
  80. package/dist/cjs/utils/tests/bytes/hex-concat.test.js +0 -65
  81. package/dist/cjs/utils/tests/bytes/hex-data-length.test.js +0 -66
  82. package/dist/cjs/utils/tests/bytes/hex-data-slice.test.js +0 -51
  83. package/dist/cjs/utils/tests/bytes/hex-strip-zeros.test.js +0 -75
  84. package/dist/cjs/utils/tests/bytes/hex-value.test.js +0 -141
  85. package/dist/cjs/utils/tests/bytes/hex-zero-pad.test.js +0 -100
  86. package/dist/cjs/utils/tests/bytes/hexlify.test.js +0 -78
  87. package/dist/cjs/utils/tests/bytes/is-bytes-like.test.js +0 -68
  88. package/dist/cjs/utils/tests/bytes/is-bytes.test.js +0 -76
  89. package/dist/cjs/utils/tests/bytes/is-hex-string.test.js +0 -97
  90. package/dist/cjs/utils/tests/bytes/strip-zeros.test.js +0 -106
  91. package/dist/cjs/utils/tests/bytes/zero-pad.test.js +0 -144
  92. package/dist/cjs/utils/tests/compute-address.test.js +0 -49
  93. package/dist/cjs/utils/tests/compute-public-key.test.js +0 -26
  94. package/dist/cjs/utils/tests/ether-to-gwei.test.js +0 -26
  95. package/dist/cjs/utils/tests/ether-to-wei.test.js +0 -36
  96. package/dist/cjs/utils/tests/gwei-to-ether.test.js +0 -28
  97. package/dist/cjs/utils/tests/hash-message.test.js +0 -32
  98. package/dist/cjs/utils/tests/is-address.test.js +0 -48
  99. package/dist/cjs/utils/tests/keccak256.test.js +0 -121
  100. package/dist/cjs/utils/tests/solidity-keccak256.test.js +0 -311
  101. package/dist/cjs/utils/tests/split-signature.test.js +0 -46
  102. package/dist/cjs/utils/tests/to-checksum-address.test.js +0 -39
  103. package/dist/cjs/utils/tests/to-utf8-bytes.test.js +0 -34
  104. package/dist/cjs/utils/tests/wei-to-ether.test.js +0 -41
@@ -1,266 +0,0 @@
1
- function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
2
- try {
3
- var info = gen[key](arg);
4
- var value = info.value;
5
- } catch (error) {
6
- reject(error);
7
- return;
8
- }
9
- if (info.done) {
10
- resolve(value);
11
- } else {
12
- Promise.resolve(value).then(_next, _throw);
13
- }
14
- }
15
- function _async_to_generator(fn) {
16
- return function() {
17
- var self = this, args = arguments;
18
- return new Promise(function(resolve, reject) {
19
- var gen = fn.apply(self, args);
20
- function _next(value) {
21
- asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
22
- }
23
- function _throw(err) {
24
- asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
25
- }
26
- _next(undefined);
27
- });
28
- };
29
- }
30
- function _define_property(obj, key, value) {
31
- if (key in obj) {
32
- Object.defineProperty(obj, key, {
33
- value: value,
34
- enumerable: true,
35
- configurable: true,
36
- writable: true
37
- });
38
- } else {
39
- obj[key] = value;
40
- }
41
- return obj;
42
- }
43
- function _object_spread(target) {
44
- for(var i = 1; i < arguments.length; i++){
45
- var source = arguments[i] != null ? arguments[i] : {};
46
- var ownKeys = Object.keys(source);
47
- if (typeof Object.getOwnPropertySymbols === "function") {
48
- ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
49
- return Object.getOwnPropertyDescriptor(source, sym).enumerable;
50
- }));
51
- }
52
- ownKeys.forEach(function(key) {
53
- _define_property(target, key, source[key]);
54
- });
55
- }
56
- return target;
57
- }
58
- function ownKeys(object, enumerableOnly) {
59
- var keys = Object.keys(object);
60
- if (Object.getOwnPropertySymbols) {
61
- var symbols = Object.getOwnPropertySymbols(object);
62
- if (enumerableOnly) {
63
- symbols = symbols.filter(function(sym) {
64
- return Object.getOwnPropertyDescriptor(object, sym).enumerable;
65
- });
66
- }
67
- keys.push.apply(keys, symbols);
68
- }
69
- return keys;
70
- }
71
- function _object_spread_props(target, source) {
72
- source = source != null ? source : {};
73
- if (Object.getOwnPropertyDescriptors) {
74
- Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
75
- } else {
76
- ownKeys(Object(source)).forEach(function(key) {
77
- Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
78
- });
79
- }
80
- return target;
81
- }
82
- function _ts_generator(thisArg, body) {
83
- var f, y, t, g, _ = {
84
- label: 0,
85
- sent: function() {
86
- if (t[0] & 1) throw t[1];
87
- return t[1];
88
- },
89
- trys: [],
90
- ops: []
91
- };
92
- return g = {
93
- next: verb(0),
94
- "throw": verb(1),
95
- "return": verb(2)
96
- }, typeof Symbol === "function" && (g[Symbol.iterator] = function() {
97
- return this;
98
- }), g;
99
- function verb(n) {
100
- return function(v) {
101
- return step([
102
- n,
103
- v
104
- ]);
105
- };
106
- }
107
- function step(op) {
108
- if (f) throw new TypeError("Generator is already executing.");
109
- while(_)try {
110
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
111
- if (y = 0, t) op = [
112
- op[0] & 2,
113
- t.value
114
- ];
115
- switch(op[0]){
116
- case 0:
117
- case 1:
118
- t = op;
119
- break;
120
- case 4:
121
- _.label++;
122
- return {
123
- value: op[1],
124
- done: false
125
- };
126
- case 5:
127
- _.label++;
128
- y = op[1];
129
- op = [
130
- 0
131
- ];
132
- continue;
133
- case 7:
134
- op = _.ops.pop();
135
- _.trys.pop();
136
- continue;
137
- default:
138
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
139
- _ = 0;
140
- continue;
141
- }
142
- if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
143
- _.label = op[1];
144
- break;
145
- }
146
- if (op[0] === 6 && _.label < t[1]) {
147
- _.label = t[1];
148
- t = op;
149
- break;
150
- }
151
- if (t && _.label < t[2]) {
152
- _.label = t[2];
153
- _.ops.push(op);
154
- break;
155
- }
156
- if (t[2]) _.ops.pop();
157
- _.trys.pop();
158
- continue;
159
- }
160
- op = body.call(thisArg, _);
161
- } catch (e) {
162
- op = [
163
- 6,
164
- e
165
- ];
166
- y = 0;
167
- } finally{
168
- f = t = 0;
169
- }
170
- if (op[0] & 5) throw op[1];
171
- return {
172
- value: op[0] ? op[1] : void 0,
173
- done: true
174
- };
175
- }
176
- }
177
- import * as unfetch from "isomorphic-unfetch";
178
- import { buildFetchInit, buildRPCPostBody } from "../../../classes/utils/fetchers";
179
- import { JsonRpcProvider, tinyBig } from "../../../index";
180
- import { mockOf } from "../mock-of";
181
- import { rpcUrls } from "../rpc-urls";
182
- jest.mock("isomorphic-unfetch");
183
- var rpcUrl = rpcUrls.mainnet;
184
- var mockBlocksBetween = 10;
185
- var mockTransactionResponse = {
186
- blockHash: "0x876810a013dbcd140f6fd6048c1dc33abbb901f1f96b394c2fa63aef3cb40b5d",
187
- blockNumber: 14578286,
188
- from: "0xdfD9dE5f6FA60BD70636c0900752E93a6144AEd4",
189
- gas: "112163",
190
- gasPrice: "48592426858",
191
- maxPriorityFeePerGas: "1500000000",
192
- maxFeePerGas: "67681261618",
193
- hash: "0x9014ae6ef92464338355a79e5150e542ff9a83e2323318b21f40d6a3e65b4789",
194
- input: "0x83259f170000000000000000000000000000000000000000000000000000000000000080000000000000000000000000dfd9de5f6fa60bd70636c0900752e93a6144aed400000000000000000000000000000000000000000000000000000000000000c0000000000000000000000000000000000000000000000000000000000000024000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000003000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000009e99ad11a214fd016b19dc3648678c5944859ae292b21c24ca94f857836c4596f1950c82dd0c23dd621af4763edc2f66466e63c5df9de0c1107b1cd16bf460fe93e43fd308e3444bc79c3d88a4cb961dc8367ab6ad048867afc76d193bca99cf3a068864ed4a7df1dbf1d4c52238eced3e5e05644b4040fc2b3ccb8557b0e99fff6131305a0ea2b8061b90bd418db5bbdd2e92129f52d93f90531465e309c4caec5b85285822b6196398d36f16f511811b61bbda6461e80e29210cd303118bdcee8df6fa0505ffbe8642094fd2ba4dd458496fe3b459ac880bbf71877c713e969ccf5ed7efab8a84ebc07e3939901371ca427e1192e455a8f35a6a1d7ad09e1475dd1758b36fa631dab5d70e99316b23c4c43094188d360cd9c3457355904e07c00000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000162074a7047f",
195
- nonce: "129",
196
- to: "0x39B72d136ba3e4ceF35F48CD09587ffaB754DD8B",
197
- transactionIndex: 29,
198
- value: "0",
199
- type: 2,
200
- accessList: [],
201
- chainId: 1,
202
- v: 0,
203
- r: "0x59a7c15b12c18cd68d6c440963d959bff3e73831ffc938e75ecad07f7ee43fbc",
204
- s: "0x1ebaf05f0d9273b16c2a7748b150a79d22533a8cd74552611cbe620fee3dcf1c",
205
- confirmations: mockBlocksBetween
206
- };
207
- var mockRpcTransactionResponse = JSON.stringify({
208
- jsonrpc: "2.0",
209
- id: 1,
210
- result: mockTransactionResponse
211
- });
212
- var mockRpcBlockResponse = JSON.stringify({
213
- jsonrpc: "2.0",
214
- id: 1,
215
- result: {
216
- number: mockTransactionResponse.blockNumber + mockBlocksBetween - 1
217
- }
218
- });
219
- var mockTransaction = _object_spread_props(_object_spread({}, mockTransactionResponse), {
220
- value: tinyBig(mockTransactionResponse.value),
221
- nonce: tinyBig(mockTransactionResponse.nonce),
222
- maxPriorityFeePerGas: tinyBig(mockTransactionResponse.maxPriorityFeePerGas),
223
- gasPrice: tinyBig(mockTransactionResponse.gasPrice),
224
- maxFeePerGas: tinyBig(mockTransactionResponse.maxFeePerGas),
225
- gas: tinyBig(mockTransactionResponse.gas)
226
- });
227
- describe("provider.getTransaction", function() {
228
- it("should fetch transaction and add confirmations properly", /*#__PURE__*/ _async_to_generator(function() {
229
- var transactionHash, provider, spy, transaction;
230
- return _ts_generator(this, function(_state) {
231
- switch(_state.label){
232
- case 0:
233
- transactionHash = "0x9014ae6ef92464338355a79e5150e542ff9a83e2323318b21f40d6a3e65b4789";
234
- provider = new JsonRpcProvider(rpcUrl);
235
- mockOf(unfetch.default).mockResolvedValueOnce({
236
- text: function() {
237
- return Promise.resolve(mockRpcTransactionResponse);
238
- }
239
- });
240
- mockOf(unfetch.default).mockResolvedValueOnce({
241
- text: function() {
242
- return Promise.resolve(mockRpcBlockResponse);
243
- }
244
- });
245
- spy = jest.spyOn(unfetch, "default");
246
- return [
247
- 4,
248
- provider.getTransaction(transactionHash)
249
- ];
250
- case 1:
251
- transaction = _state.sent();
252
- expect(spy).toHaveBeenCalledWith(rpcUrl, buildFetchInit(buildRPCPostBody("eth_getTransactionByHash", [
253
- transactionHash
254
- ])));
255
- expect(spy).toHaveBeenCalledWith(rpcUrl, buildFetchInit(buildRPCPostBody("eth_getBlockByNumber", [
256
- "latest",
257
- false
258
- ])));
259
- expect(JSON.stringify(transaction)).toBe(JSON.stringify(mockTransaction));
260
- return [
261
- 2
262
- ];
263
- }
264
- });
265
- }));
266
- });
@@ -1,151 +0,0 @@
1
- function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
2
- try {
3
- var info = gen[key](arg);
4
- var value = info.value;
5
- } catch (error) {
6
- reject(error);
7
- return;
8
- }
9
- if (info.done) {
10
- resolve(value);
11
- } else {
12
- Promise.resolve(value).then(_next, _throw);
13
- }
14
- }
15
- function _async_to_generator(fn) {
16
- return function() {
17
- var self = this, args = arguments;
18
- return new Promise(function(resolve, reject) {
19
- var gen = fn.apply(self, args);
20
- function _next(value) {
21
- asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
22
- }
23
- function _throw(err) {
24
- asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
25
- }
26
- _next(undefined);
27
- });
28
- };
29
- }
30
- function _ts_generator(thisArg, body) {
31
- var f, y, t, g, _ = {
32
- label: 0,
33
- sent: function() {
34
- if (t[0] & 1) throw t[1];
35
- return t[1];
36
- },
37
- trys: [],
38
- ops: []
39
- };
40
- return g = {
41
- next: verb(0),
42
- "throw": verb(1),
43
- "return": verb(2)
44
- }, typeof Symbol === "function" && (g[Symbol.iterator] = function() {
45
- return this;
46
- }), g;
47
- function verb(n) {
48
- return function(v) {
49
- return step([
50
- n,
51
- v
52
- ]);
53
- };
54
- }
55
- function step(op) {
56
- if (f) throw new TypeError("Generator is already executing.");
57
- while(_)try {
58
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
59
- if (y = 0, t) op = [
60
- op[0] & 2,
61
- t.value
62
- ];
63
- switch(op[0]){
64
- case 0:
65
- case 1:
66
- t = op;
67
- break;
68
- case 4:
69
- _.label++;
70
- return {
71
- value: op[1],
72
- done: false
73
- };
74
- case 5:
75
- _.label++;
76
- y = op[1];
77
- op = [
78
- 0
79
- ];
80
- continue;
81
- case 7:
82
- op = _.ops.pop();
83
- _.trys.pop();
84
- continue;
85
- default:
86
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
87
- _ = 0;
88
- continue;
89
- }
90
- if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
91
- _.label = op[1];
92
- break;
93
- }
94
- if (op[0] === 6 && _.label < t[1]) {
95
- _.label = t[1];
96
- t = op;
97
- break;
98
- }
99
- if (t && _.label < t[2]) {
100
- _.label = t[2];
101
- _.ops.push(op);
102
- break;
103
- }
104
- if (t[2]) _.ops.pop();
105
- _.trys.pop();
106
- continue;
107
- }
108
- op = body.call(thisArg, _);
109
- } catch (e) {
110
- op = [
111
- 6,
112
- e
113
- ];
114
- y = 0;
115
- } finally{
116
- f = t = 0;
117
- }
118
- if (op[0] & 5) throw op[1];
119
- return {
120
- value: op[0] ? op[1] : void 0,
121
- done: true
122
- };
123
- }
124
- }
125
- import { z } from "zod";
126
- import { AlchemyProvider, TinyBig } from "../../index";
127
- var ALCHEMY_API_KEY = process.env.ALCHEMY_API_KEY;
128
- if (!ALCHEMY_API_KEY) {
129
- throw new Error("ALCHEMY_API_KEY is not defined in the environment variables.");
130
- }
131
- var provider = new AlchemyProvider(ALCHEMY_API_KEY);
132
- describe("alchemyProvider.getGasPrice", function() {
133
- it("should return the current gas price", /*#__PURE__*/ _async_to_generator(function() {
134
- var gasPrice;
135
- return _ts_generator(this, function(_state) {
136
- switch(_state.label){
137
- case 0:
138
- return [
139
- 4,
140
- provider.getGasPrice()
141
- ];
142
- case 1:
143
- gasPrice = _state.sent();
144
- expect(z.instanceof(TinyBig).safeParse(gasPrice).success).toBe(true);
145
- return [
146
- 2
147
- ];
148
- }
149
- });
150
- }));
151
- });
@@ -1,29 +0,0 @@
1
- import { scientificStrToDecimalStr } from "./helpers";
2
- describe("scientificStrToDecimalStr", function() {
3
- it("not even scientific", function() {
4
- expect(scientificStrToDecimalStr("010")).toBe("10");
5
- expect(scientificStrToDecimalStr("-010")).toBe("-10");
6
- });
7
- it("zero power", function() {
8
- expect(scientificStrToDecimalStr("10e0")).toBe("10");
9
- expect(scientificStrToDecimalStr("1.0e0")).toBe("1");
10
- expect(scientificStrToDecimalStr("-10e-0")).toBe("-10");
11
- expect(scientificStrToDecimalStr("-1.0e-0")).toBe("-1");
12
- expect(scientificStrToDecimalStr("-1.10e-0")).toBe("-1.1");
13
- expect(scientificStrToDecimalStr("-1.e-0")).toBe("-1");
14
- expect(scientificStrToDecimalStr(".10e-0")).toBe("0.1");
15
- expect(scientificStrToDecimalStr("00.0010e-0")).toBe("0.001");
16
- });
17
- it("negative power", function() {
18
- expect(scientificStrToDecimalStr("0100e-2")).toBe("1");
19
- expect(scientificStrToDecimalStr("0100e-4")).toBe("0.01");
20
- expect(scientificStrToDecimalStr("010.1e-3")).toBe("0.0101");
21
- expect(scientificStrToDecimalStr("-010.1e-3")).toBe("-0.0101");
22
- expect(scientificStrToDecimalStr("09.1e-51")).toBe("0.".concat("0".repeat(50), "91"));
23
- });
24
- it("positive power", function() {
25
- expect(scientificStrToDecimalStr("01e2")).toBe("100");
26
- expect(scientificStrToDecimalStr("-01e2")).toBe("-100");
27
- expect(scientificStrToDecimalStr("09.1e51")).toBe("91".concat("0".repeat(50)));
28
- });
29
- });
@@ -1,34 +0,0 @@
1
- import BN from "bn.js";
2
- import { tinyBig } from "./tiny-big";
3
- describe("tiny-big", function() {
4
- it("allows hex string input", function() {
5
- expect(tinyBig("0xa").toString()).toBe("10");
6
- expect(tinyBig("10").toString()).toBe("10");
7
- });
8
- it("performs toHexString properly", function() {
9
- expect(tinyBig(0).toHexString()).toBe("0x0");
10
- expect(tinyBig(1).toHexString()).toBe("0x1");
11
- expect(tinyBig(15).toHexString()).toBe("0xf");
12
- expect(tinyBig(16).toHexString()).toBe("0x10");
13
- });
14
- it("performs twosComplement", function() {
15
- var inputs = [
16
- {
17
- num: -3,
18
- bitCount: 3
19
- },
20
- {
21
- num: 0,
22
- bitCount: 3
23
- },
24
- {
25
- num: 3,
26
- bitCount: 3
27
- }
28
- ];
29
- inputs.forEach(function(param) {
30
- var num = param.num, bitCount = param.bitCount;
31
- expect(tinyBig(num).toTwos(bitCount).toString()).toBe(new BN(num).toTwos(bitCount).toString());
32
- });
33
- });
34
- });
@@ -1,64 +0,0 @@
1
- import { arrayify, tinyBig } from "../../..";
2
- describe("arrayify", function() {
3
- it("should correctly arrayify - values", function() {
4
- var testCases = [
5
- {
6
- input: 0,
7
- expected: new Uint8Array([
8
- 0
9
- ])
10
- },
11
- {
12
- input: 1,
13
- expected: new Uint8Array([
14
- 1
15
- ])
16
- },
17
- {
18
- input: "0x1234",
19
- expected: new Uint8Array([
20
- 18,
21
- 52
22
- ])
23
- },
24
- {
25
- input: new Uint8Array(2),
26
- expected: new Uint8Array(2)
27
- },
28
- {
29
- input: tinyBig(17),
30
- expected: new Uint8Array([
31
- 17
32
- ])
33
- }
34
- ];
35
- testCases.forEach(function(testCase) {
36
- expect(arrayify(testCase.input)).toStrictEqual(testCase.expected);
37
- });
38
- });
39
- it("should correctly arrayify - values with options", function() {
40
- expect(arrayify("12", {
41
- allowMissingPrefix: true
42
- })).toStrictEqual(new Uint8Array([
43
- 18
44
- ]));
45
- expect(arrayify("0x1", {
46
- hexPad: "left"
47
- })).toStrictEqual(new Uint8Array([
48
- 1
49
- ]));
50
- expect(arrayify("0x1", {
51
- hexPad: "right"
52
- })).toStrictEqual(new Uint8Array([
53
- 16
54
- ]));
55
- });
56
- it("should throw for invalid values", function() {
57
- expect(function() {
58
- return arrayify(tinyBig(15));
59
- }).toThrow(); // hex data is odd-length
60
- expect(function() {
61
- return arrayify(false);
62
- }).toThrow(); // invalid arrayify value
63
- });
64
- });
@@ -1,17 +0,0 @@
1
- import { concat } from "../../..";
2
- describe("concat", function() {
3
- it("matches expected result", function() {
4
- var inputs = [
5
- [
6
- 0,
7
- 1
8
- ]
9
- ];
10
- inputs.forEach(function(input) {
11
- expect(concat(input)).toStrictEqual(new Uint8Array([
12
- 0,
13
- 1
14
- ]));
15
- });
16
- });
17
- });
@@ -1,65 +0,0 @@
1
- import { hexConcat } from "../../bytes";
2
- describe("utils.hexConcat", function() {
3
- it("should correctly concatenate - hex values", function() {
4
- var values = [
5
- "0x2048",
6
- "0x6917",
7
- "0x85616379"
8
- ];
9
- var expected = "0x2048691785616379";
10
- expect(hexConcat(values)).toBe(expected);
11
- });
12
- it("should correctly concatenate - UInt8Array values", function() {
13
- var values = [
14
- new Uint8Array([
15
- 5,
16
- 10,
17
- 247,
18
- 22
19
- ]),
20
- new Uint8Array([
21
- 50,
22
- 255,
23
- 3
24
- ]),
25
- new Uint8Array([
26
- 59,
27
- 36,
28
- 18,
29
- 46,
30
- 198,
31
- 234
32
- ])
33
- ];
34
- var expected = "0x050af71632ff033b24122ec6ea";
35
- expect(hexConcat(values)).toStrictEqual(expected);
36
- });
37
- it("should correctly concatenate - hex & UInt8Array values", function() {
38
- var values = [
39
- "0x2048",
40
- [
41
- 5,
42
- 10,
43
- 247,
44
- 22
45
- ],
46
- "0x6917",
47
- [
48
- 50,
49
- 255,
50
- 3
51
- ],
52
- "0x85616379",
53
- [
54
- 59,
55
- 36,
56
- 18,
57
- 46,
58
- 198,
59
- 234
60
- ]
61
- ];
62
- var expected = "0x2048050af716691732ff03856163793b24122ec6ea";
63
- expect(hexConcat(values)).toStrictEqual(expected);
64
- });
65
- });
@@ -1,66 +0,0 @@
1
- import { hexDataLength } from "../../bytes";
2
- describe("utils.hexDataLength", function() {
3
- it("should match expected value - hex values", function() {
4
- var testCases = [
5
- {
6
- value: "0x9347",
7
- expected: 2
8
- },
9
- {
10
- value: "0x185754",
11
- expected: 3
12
- },
13
- {
14
- value: "0x00005823",
15
- expected: 4
16
- }
17
- ];
18
- testCases.forEach(function(testCase) {
19
- expect(hexDataLength(testCase.value)).toStrictEqual(testCase.expected);
20
- });
21
- });
22
- it("should match expected value - UInt8Array values", function() {
23
- var testCases = [
24
- {
25
- value: new Uint8Array([
26
- 9,
27
- 58,
28
- 29,
29
- 24
30
- ]),
31
- expected: 4
32
- },
33
- {
34
- value: new Uint8Array([
35
- 185,
36
- 203
37
- ]),
38
- expected: 2
39
- },
40
- {
41
- value: new Uint8Array([
42
- 239,
43
- 30,
44
- 49,
45
- 41,
46
- 5,
47
- 10,
48
- 42
49
- ]),
50
- expected: 7
51
- }
52
- ];
53
- testCases.forEach(function(testCase) {
54
- expect(hexDataLength(testCase.value)).toStrictEqual(testCase.expected);
55
- });
56
- });
57
- it("should return null - non-hex values or hex values not divisible by 2", function() {
58
- var values = [
59
- "0x383",
60
- "non-hex string"
61
- ];
62
- values.forEach(function(value) {
63
- expect(hexDataLength(value)).toBeNull();
64
- });
65
- });
66
- });