essential-eth 0.9.0 → 0.9.1-next.0

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 (106) hide show
  1. package/dist/cjs/classes/Contract.js +38 -34
  2. package/dist/cjs/classes/test/Contract/crv.test.js +146 -339
  3. package/dist/cjs/classes/test/Contract/ens-abi.d.ts +1 -1
  4. package/dist/cjs/classes/test/Contract/ens.test.js +9 -66
  5. package/dist/cjs/classes/test/Contract/fei.test.js +11 -11
  6. package/dist/cjs/classes/test/Contract/foo-abi.d.ts +1 -1
  7. package/dist/cjs/classes/test/Contract/uni.test.js +66 -164
  8. package/dist/cjs/classes/utils/clean-block.js +4 -4
  9. package/dist/cjs/classes/utils/clean-log.js +4 -4
  10. package/dist/cjs/classes/utils/clean-transaction-receipt.js +4 -4
  11. package/dist/cjs/classes/utils/clean-transaction.js +4 -4
  12. package/dist/cjs/classes/utils/encode-decode-transaction.js +10 -10
  13. package/dist/cjs/classes/utils/fetchers.d.ts +8 -2
  14. package/dist/cjs/classes/utils/fetchers.js +20 -12
  15. package/dist/cjs/classes/utils/prepare-transaction.js +4 -4
  16. package/dist/cjs/index.d.ts +21 -22
  17. package/dist/cjs/index.js +21 -22
  18. package/dist/cjs/index.umd.js +1 -1
  19. package/dist/cjs/index.umd.js.map +1 -1
  20. package/dist/cjs/logger/logger.js +79 -41
  21. package/dist/cjs/logger/package-version.d.ts +1 -1
  22. package/dist/cjs/logger/package-version.js +1 -1
  23. package/dist/cjs/providers/AlchemyProvider.js +22 -22
  24. package/dist/cjs/providers/BaseProvider.js +471 -404
  25. package/dist/cjs/providers/FallthroughProvider.js +62 -30
  26. package/dist/cjs/providers/JsonRpcProvider.js +52 -31
  27. package/dist/cjs/providers/test/fallthrough-provider/get-gas-price.test.js +9 -9
  28. package/dist/cjs/providers/test/get-transaction-count.test.js +54 -91
  29. package/dist/cjs/providers/test/json-rpc-provider/call.test.js +87 -148
  30. package/dist/cjs/providers/test/json-rpc-provider/estimate-gas.test.js +45 -116
  31. package/dist/cjs/providers/test/json-rpc-provider/get-balance.test.js +36 -74
  32. package/dist/cjs/providers/test/json-rpc-provider/get-block-number.test.js +13 -9
  33. package/dist/cjs/providers/test/json-rpc-provider/get-block.test.js +191 -254
  34. package/dist/cjs/providers/test/json-rpc-provider/get-code.test.js +106 -135
  35. package/dist/cjs/providers/test/json-rpc-provider/get-fee-data.test.js +48 -73
  36. package/dist/cjs/providers/test/json-rpc-provider/get-gas-price.test.js +11 -8
  37. package/dist/cjs/providers/test/json-rpc-provider/get-logs/get-logs.test.js +219 -0
  38. package/dist/cjs/providers/test/json-rpc-provider/get-logs/mocks.d.ts +14 -0
  39. package/dist/cjs/providers/test/json-rpc-provider/get-logs/mocks.js +149 -0
  40. package/dist/cjs/providers/test/json-rpc-provider/get-network.test.js +37 -79
  41. package/dist/cjs/providers/test/json-rpc-provider/get-transaction-receipt.test.js +136 -157
  42. package/dist/cjs/providers/test/json-rpc-provider/get-transaction.test.js +121 -162
  43. package/dist/cjs/providers/test/mock-of.js +0 -5
  44. package/dist/cjs/providers/test/rpc-urls.d.ts +1 -0
  45. package/dist/cjs/providers/test/rpc-urls.js +5 -4
  46. package/dist/cjs/providers/test/test-alchemy-provider.test.js +5 -5
  47. package/dist/cjs/providers/utils/chains-info.d.ts +5 -448
  48. package/dist/cjs/providers/utils/chains-info.js +13 -1344
  49. package/dist/cjs/shared/tiny-big/helpers.js +18 -18
  50. package/dist/cjs/shared/tiny-big/tiny-big.js +96 -56
  51. package/dist/cjs/shared/tiny-big/tiny-big.test.js +2 -2
  52. package/dist/cjs/shared/validate-type.d.ts +1 -1
  53. package/dist/cjs/shared/validate-type.js +4 -4
  54. package/dist/cjs/types/Block.types.d.ts +3 -3
  55. package/dist/cjs/types/Contract.types.d.ts +4 -4
  56. package/dist/cjs/types/Transaction.types.d.ts +5 -5
  57. package/dist/cjs/utils/bytes.d.ts +4 -4
  58. package/dist/cjs/utils/bytes.js +3 -3
  59. package/dist/cjs/utils/tests/bytes/arrayify.test.js +48 -24
  60. package/dist/cjs/utils/tests/bytes/concat.test.js +5 -3
  61. package/dist/cjs/utils/tests/bytes/hex-concat.test.js +15 -13
  62. package/dist/cjs/utils/tests/bytes/hex-data-length.test.js +49 -32
  63. package/dist/cjs/utils/tests/bytes/hex-data-slice.test.js +15 -16
  64. package/dist/cjs/utils/tests/bytes/hex-strip-zeros.test.js +57 -40
  65. package/dist/cjs/utils/tests/bytes/hex-value.test.js +118 -62
  66. package/dist/cjs/utils/tests/bytes/hex-zero-pad.test.js +71 -33
  67. package/dist/cjs/utils/tests/bytes/hexlify.test.js +45 -29
  68. package/dist/cjs/utils/tests/bytes/is-bytes-like.test.js +10 -11
  69. package/dist/cjs/utils/tests/bytes/is-bytes.test.js +70 -27
  70. package/dist/cjs/utils/tests/bytes/is-hex-string.test.js +37 -28
  71. package/dist/cjs/utils/tests/bytes/strip-zeros.test.js +94 -45
  72. package/dist/cjs/utils/tests/bytes/zero-pad.test.js +98 -34
  73. package/dist/cjs/utils/tests/compute-address.test.js +42 -20
  74. package/dist/cjs/utils/tests/compute-public-key.test.js +20 -9
  75. package/dist/cjs/utils/tests/ether-to-wei.test.js +5 -13
  76. package/dist/cjs/utils/tests/hash-message.test.js +26 -15
  77. package/dist/cjs/utils/tests/is-address.test.js +2 -9
  78. package/dist/cjs/utils/tests/keccak256.test.js +36 -12
  79. package/dist/cjs/utils/tests/solidity-keccak256.test.js +43 -42
  80. package/dist/cjs/utils/tests/split-signature.test.js +29 -8
  81. package/dist/cjs/utils/tests/to-checksum-address.test.js +1 -4
  82. package/dist/cjs/utils/tests/to-utf8-bytes.test.js +28 -8
  83. package/dist/cjs/utils/tests/wei-to-ether.test.js +10 -20
  84. package/dist/esm/classes/test/Contract/ens-abi.d.ts +1 -1
  85. package/dist/esm/classes/test/Contract/foo-abi.d.ts +1 -1
  86. package/dist/esm/classes/utils/fetchers.d.ts +8 -2
  87. package/dist/esm/classes/utils/fetchers.js +6 -3
  88. package/dist/esm/index.d.ts +21 -22
  89. package/dist/esm/index.js +16 -17
  90. package/dist/esm/logger/package-version.d.ts +1 -1
  91. package/dist/esm/logger/package-version.js +1 -1
  92. package/dist/esm/providers/FallthroughProvider.js +3 -3
  93. package/dist/esm/providers/test/json-rpc-provider/get-logs/mocks.d.ts +14 -0
  94. package/dist/esm/providers/test/json-rpc-provider/get-logs/mocks.js +142 -0
  95. package/dist/esm/providers/test/rpc-urls.d.ts +1 -0
  96. package/dist/esm/providers/test/rpc-urls.js +7 -4
  97. package/dist/esm/providers/utils/chains-info.d.ts +5 -448
  98. package/dist/esm/providers/utils/chains-info.js +13 -1344
  99. package/dist/esm/shared/validate-type.d.ts +1 -1
  100. package/dist/esm/types/Block.types.d.ts +3 -3
  101. package/dist/esm/types/Contract.types.d.ts +4 -4
  102. package/dist/esm/types/Transaction.types.d.ts +5 -5
  103. package/dist/esm/utils/bytes.d.ts +4 -4
  104. package/package.json +22 -50
  105. package/readme.md +15 -38
  106. package/dist/cjs/providers/test/json-rpc-provider/get-logs.test.js +0 -361
@@ -1,19 +1,46 @@
1
- function _assertThisInitialized(self) {
1
+ function _assert_this_initialized(self) {
2
2
  if (self === void 0) {
3
3
  throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
4
4
  }
5
5
  return self;
6
6
  }
7
- function _classCallCheck(instance, Constructor) {
7
+ function _class_call_check(instance, Constructor) {
8
8
  if (!(instance instanceof Constructor)) {
9
9
  throw new TypeError("Cannot call a class as a function");
10
10
  }
11
11
  }
12
- function _getPrototypeOf(o) {
13
- _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) {
12
+ function _defineProperties(target, props) {
13
+ for(var i = 0; i < props.length; i++){
14
+ var descriptor = props[i];
15
+ descriptor.enumerable = descriptor.enumerable || false;
16
+ descriptor.configurable = true;
17
+ if ("value" in descriptor) descriptor.writable = true;
18
+ Object.defineProperty(target, descriptor.key, descriptor);
19
+ }
20
+ }
21
+ function _create_class(Constructor, protoProps, staticProps) {
22
+ if (protoProps) _defineProperties(Constructor.prototype, protoProps);
23
+ if (staticProps) _defineProperties(Constructor, staticProps);
24
+ return Constructor;
25
+ }
26
+ function _define_property(obj, key, value) {
27
+ if (key in obj) {
28
+ Object.defineProperty(obj, key, {
29
+ value: value,
30
+ enumerable: true,
31
+ configurable: true,
32
+ writable: true
33
+ });
34
+ } else {
35
+ obj[key] = value;
36
+ }
37
+ return obj;
38
+ }
39
+ function _get_prototype_of(o) {
40
+ _get_prototype_of = Object.setPrototypeOf ? Object.getPrototypeOf : function getPrototypeOf(o) {
14
41
  return o.__proto__ || Object.getPrototypeOf(o);
15
42
  };
16
- return _getPrototypeOf(o);
43
+ return _get_prototype_of(o);
17
44
  }
18
45
  function _inherits(subClass, superClass) {
19
46
  if (typeof superClass !== "function" && superClass !== null) {
@@ -26,26 +53,26 @@ function _inherits(subClass, superClass) {
26
53
  configurable: true
27
54
  }
28
55
  });
29
- if (superClass) _setPrototypeOf(subClass, superClass);
56
+ if (superClass) _set_prototype_of(subClass, superClass);
30
57
  }
31
- function _possibleConstructorReturn(self, call) {
32
- if (call && (_typeof(call) === "object" || typeof call === "function")) {
58
+ function _possible_constructor_return(self, call) {
59
+ if (call && (_type_of(call) === "object" || typeof call === "function")) {
33
60
  return call;
34
61
  }
35
- return _assertThisInitialized(self);
62
+ return _assert_this_initialized(self);
36
63
  }
37
- function _setPrototypeOf(o, p) {
38
- _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) {
64
+ function _set_prototype_of(o, p) {
65
+ _set_prototype_of = Object.setPrototypeOf || function setPrototypeOf(o, p) {
39
66
  o.__proto__ = p;
40
67
  return o;
41
68
  };
42
- return _setPrototypeOf(o, p);
69
+ return _set_prototype_of(o, p);
43
70
  }
44
- var _typeof = function(obj) {
71
+ function _type_of(obj) {
45
72
  "@swc/helpers - typeof";
46
73
  return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj;
47
- };
48
- function _isNativeReflectConstruct() {
74
+ }
75
+ function _is_native_reflect_construct() {
49
76
  if (typeof Reflect === "undefined" || !Reflect.construct) return false;
50
77
  if (Reflect.construct.sham) return false;
51
78
  if (typeof Proxy === "function") return true;
@@ -56,17 +83,17 @@ function _isNativeReflectConstruct() {
56
83
  return false;
57
84
  }
58
85
  }
59
- function _createSuper(Derived) {
60
- var hasNativeReflectConstruct = _isNativeReflectConstruct();
86
+ function _create_super(Derived) {
87
+ var hasNativeReflectConstruct = _is_native_reflect_construct();
61
88
  return function _createSuperInternal() {
62
- var Super = _getPrototypeOf(Derived), result;
89
+ var Super = _get_prototype_of(Derived), result;
63
90
  if (hasNativeReflectConstruct) {
64
- var NewTarget = _getPrototypeOf(this).constructor;
91
+ var NewTarget = _get_prototype_of(this).constructor;
65
92
  result = Reflect.construct(Super, arguments, NewTarget);
66
93
  } else {
67
94
  result = Super.apply(this, arguments);
68
95
  }
69
- return _possibleConstructorReturn(this, result);
96
+ return _possible_constructor_return(this, result);
70
97
  };
71
98
  }
72
99
  import { logger } from "../logger/logger";
@@ -93,10 +120,10 @@ var DEFAULT_TIMEOUT_DURATION = 8000;
93
120
  */ export var FallthroughProvider = /*#__PURE__*/ function(BaseProvider) {
94
121
  "use strict";
95
122
  _inherits(FallthroughProvider, BaseProvider);
96
- var _super = _createSuper(FallthroughProvider);
123
+ var _super = _create_super(FallthroughProvider);
97
124
  function FallthroughProvider(rpcUrls) {
98
125
  var options = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {};
99
- _classCallCheck(this, FallthroughProvider);
126
+ _class_call_check(this, FallthroughProvider);
100
127
  var _this;
101
128
  if (!Array.isArray(rpcUrls)) {
102
129
  logger.throwError("Array required", {
@@ -112,10 +139,11 @@ var DEFAULT_TIMEOUT_DURATION = 8000;
112
139
  // index of current trusted rpc url
113
140
  /**
114
141
  * @ignore
115
- */ _this.rpcUrlCounter = 0;
142
+ */ _define_property(_assert_this_initialized(_this), "rpcUrlCounter", 0);
143
+ _define_property(_assert_this_initialized(_this), "timeoutDuration", void 0);
116
144
  /**
117
145
  * @ignore
118
- */ _this.post = function(body) {
146
+ */ _define_property(_assert_this_initialized(_this), "post", function(body) {
119
147
  // while failing post, add to rpcUrlCounter and post again
120
148
  var genesisCount = _this.rpcUrlCounter;
121
149
  var recursivePostRetry = function() {
@@ -136,15 +164,19 @@ var DEFAULT_TIMEOUT_DURATION = 8000;
136
164
  return res;
137
165
  };
138
166
  return recursivePostRetry();
139
- };
167
+ });
140
168
  _this.timeoutDuration = options.timeoutDuration || DEFAULT_TIMEOUT_DURATION;
141
169
  return _this;
142
170
  }
143
- var _proto = FallthroughProvider.prototype;
144
- /**
171
+ _create_class(FallthroughProvider, [
172
+ {
173
+ key: "selectRpcUrl",
174
+ value: /**
145
175
  * @ignore
146
- */ _proto.selectRpcUrl = function selectRpcUrl() {
147
- return this._rpcUrls[this.rpcUrlCounter];
148
- };
176
+ */ function selectRpcUrl() {
177
+ return this._rpcUrls[this.rpcUrlCounter];
178
+ }
179
+ }
180
+ ]);
149
181
  return FallthroughProvider;
150
182
  }(BaseProvider);
@@ -1,19 +1,33 @@
1
- function _assertThisInitialized(self) {
1
+ function _assert_this_initialized(self) {
2
2
  if (self === void 0) {
3
3
  throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
4
4
  }
5
5
  return self;
6
6
  }
7
- function _classCallCheck(instance, Constructor) {
7
+ function _class_call_check(instance, Constructor) {
8
8
  if (!(instance instanceof Constructor)) {
9
9
  throw new TypeError("Cannot call a class as a function");
10
10
  }
11
11
  }
12
- function _getPrototypeOf(o) {
13
- _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) {
12
+ function _defineProperties(target, props) {
13
+ for(var i = 0; i < props.length; i++){
14
+ var descriptor = props[i];
15
+ descriptor.enumerable = descriptor.enumerable || false;
16
+ descriptor.configurable = true;
17
+ if ("value" in descriptor) descriptor.writable = true;
18
+ Object.defineProperty(target, descriptor.key, descriptor);
19
+ }
20
+ }
21
+ function _create_class(Constructor, protoProps, staticProps) {
22
+ if (protoProps) _defineProperties(Constructor.prototype, protoProps);
23
+ if (staticProps) _defineProperties(Constructor, staticProps);
24
+ return Constructor;
25
+ }
26
+ function _get_prototype_of(o) {
27
+ _get_prototype_of = Object.setPrototypeOf ? Object.getPrototypeOf : function getPrototypeOf(o) {
14
28
  return o.__proto__ || Object.getPrototypeOf(o);
15
29
  };
16
- return _getPrototypeOf(o);
30
+ return _get_prototype_of(o);
17
31
  }
18
32
  function _inherits(subClass, superClass) {
19
33
  if (typeof superClass !== "function" && superClass !== null) {
@@ -26,26 +40,26 @@ function _inherits(subClass, superClass) {
26
40
  configurable: true
27
41
  }
28
42
  });
29
- if (superClass) _setPrototypeOf(subClass, superClass);
43
+ if (superClass) _set_prototype_of(subClass, superClass);
30
44
  }
31
- function _possibleConstructorReturn(self, call) {
32
- if (call && (_typeof(call) === "object" || typeof call === "function")) {
45
+ function _possible_constructor_return(self, call) {
46
+ if (call && (_type_of(call) === "object" || typeof call === "function")) {
33
47
  return call;
34
48
  }
35
- return _assertThisInitialized(self);
49
+ return _assert_this_initialized(self);
36
50
  }
37
- function _setPrototypeOf(o, p) {
38
- _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) {
51
+ function _set_prototype_of(o, p) {
52
+ _set_prototype_of = Object.setPrototypeOf || function setPrototypeOf(o, p) {
39
53
  o.__proto__ = p;
40
54
  return o;
41
55
  };
42
- return _setPrototypeOf(o, p);
56
+ return _set_prototype_of(o, p);
43
57
  }
44
- var _typeof = function(obj) {
58
+ function _type_of(obj) {
45
59
  "@swc/helpers - typeof";
46
60
  return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj;
47
- };
48
- function _isNativeReflectConstruct() {
61
+ }
62
+ function _is_native_reflect_construct() {
49
63
  if (typeof Reflect === "undefined" || !Reflect.construct) return false;
50
64
  if (Reflect.construct.sham) return false;
51
65
  if (typeof Proxy === "function") return true;
@@ -56,42 +70,49 @@ function _isNativeReflectConstruct() {
56
70
  return false;
57
71
  }
58
72
  }
59
- function _createSuper(Derived) {
60
- var hasNativeReflectConstruct = _isNativeReflectConstruct();
73
+ function _create_super(Derived) {
74
+ var hasNativeReflectConstruct = _is_native_reflect_construct();
61
75
  return function _createSuperInternal() {
62
- var Super = _getPrototypeOf(Derived), result;
76
+ var Super = _get_prototype_of(Derived), result;
63
77
  if (hasNativeReflectConstruct) {
64
- var NewTarget = _getPrototypeOf(this).constructor;
78
+ var NewTarget = _get_prototype_of(this).constructor;
65
79
  result = Reflect.construct(Super, arguments, NewTarget);
66
80
  } else {
67
81
  result = Super.apply(this, arguments);
68
82
  }
69
- return _possibleConstructorReturn(this, result);
83
+ return _possible_constructor_return(this, result);
70
84
  };
71
85
  }
72
86
  import { BaseProvider } from "./BaseProvider";
73
87
  export var JsonRpcProvider = /*#__PURE__*/ function(BaseProvider) {
74
88
  "use strict";
75
89
  _inherits(JsonRpcProvider, BaseProvider);
76
- var _super = _createSuper(JsonRpcProvider);
90
+ var _super = _create_super(JsonRpcProvider);
77
91
  function JsonRpcProvider() {
78
92
  var rpcUrl = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : "https://free-eth-node.com/api/eth";
79
- _classCallCheck(this, JsonRpcProvider);
93
+ _class_call_check(this, JsonRpcProvider);
80
94
  return _super.call(this, [
81
95
  rpcUrl
82
96
  ]);
83
97
  }
84
- var _proto = JsonRpcProvider.prototype;
85
- /**
98
+ _create_class(JsonRpcProvider, [
99
+ {
100
+ /**
86
101
  * @ignore
87
- */ _proto.selectRpcUrl = function selectRpcUrl() {
88
- return this._rpcUrls[0];
89
- };
90
- /**
102
+ */ key: "selectRpcUrl",
103
+ value: function selectRpcUrl() {
104
+ return this._rpcUrls[0];
105
+ }
106
+ },
107
+ {
108
+ /**
91
109
  * @ignore
92
- */ _proto.post = function post(body) {
93
- return this._post(body);
94
- };
110
+ */ key: "post",
111
+ value: function post(body) {
112
+ return this._post(body);
113
+ }
114
+ }
115
+ ]);
95
116
  return JsonRpcProvider;
96
117
  }(BaseProvider);
97
118
  /**
@@ -13,7 +13,7 @@ function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
13
13
  Promise.resolve(value).then(_next, _throw);
14
14
  }
15
15
  }
16
- function _asyncToGenerator(fn) {
16
+ function _async_to_generator(fn) {
17
17
  return function() {
18
18
  var self = this, args = arguments;
19
19
  return new Promise(function(resolve, reject) {
@@ -28,7 +28,7 @@ function _asyncToGenerator(fn) {
28
28
  });
29
29
  };
30
30
  }
31
- var __generator = this && this.__generator || function(thisArg, body) {
31
+ function _ts_generator(thisArg, body) {
32
32
  var f, y, t, g, _ = {
33
33
  label: 0,
34
34
  sent: function() {
@@ -122,7 +122,7 @@ var __generator = this && this.__generator || function(thisArg, body) {
122
122
  done: true
123
123
  };
124
124
  }
125
- };
125
+ }
126
126
  import { performance } from "perf_hooks";
127
127
  import { FallthroughProvider } from "../../../index";
128
128
  import { rpcUrls } from "../rpc-urls";
@@ -135,9 +135,9 @@ function timePromise(fn) {
135
135
  return fn().then(onPromiseDone, onPromiseDone);
136
136
  }
137
137
  describe("provider.getGasPrice", function() {
138
- it("should fallthrough on several types of invalid urls", /*#__PURE__*/ _asyncToGenerator(function() {
138
+ it("should fallthrough on several types of invalid urls", /*#__PURE__*/ _async_to_generator(function() {
139
139
  var essentialEthProvider, block;
140
- return __generator(this, function(_state) {
140
+ return _ts_generator(this, function(_state) {
141
141
  switch(_state.label){
142
142
  case 0:
143
143
  essentialEthProvider = new FallthroughProvider([
@@ -158,9 +158,9 @@ describe("provider.getGasPrice", function() {
158
158
  }
159
159
  });
160
160
  }));
161
- it("should fallthrough after timeout linearly", /*#__PURE__*/ _asyncToGenerator(function() {
161
+ it("should fallthrough after timeout linearly", /*#__PURE__*/ _async_to_generator(function() {
162
162
  var essentialEthProvider;
163
- return __generator(this, function(_state) {
163
+ return _ts_generator(this, function(_state) {
164
164
  switch(_state.label){
165
165
  case 0:
166
166
  essentialEthProvider = new FallthroughProvider([
@@ -191,9 +191,9 @@ describe("provider.getGasPrice", function() {
191
191
  }
192
192
  });
193
193
  }));
194
- it("should mutex the current rpc selection properly", /*#__PURE__*/ _asyncToGenerator(function() {
194
+ it("should mutex the current rpc selection properly", /*#__PURE__*/ _async_to_generator(function() {
195
195
  var providers, allBlocks;
196
- return __generator(this, function(_state) {
196
+ return _ts_generator(this, function(_state) {
197
197
  switch(_state.label){
198
198
  case 0:
199
199
  providers = [
@@ -1,11 +1,3 @@
1
- function _arrayLikeToArray(arr, len) {
2
- if (len == null || len > arr.length) len = arr.length;
3
- for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i];
4
- return arr2;
5
- }
6
- function _arrayWithHoles(arr) {
7
- if (Array.isArray(arr)) return arr;
8
- }
9
1
  function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
10
2
  try {
11
3
  var info = gen[key](arg);
@@ -20,7 +12,7 @@ function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
20
12
  Promise.resolve(value).then(_next, _throw);
21
13
  }
22
14
  }
23
- function _asyncToGenerator(fn) {
15
+ function _async_to_generator(fn) {
24
16
  return function() {
25
17
  var self = this, args = arguments;
26
18
  return new Promise(function(resolve, reject) {
@@ -35,45 +27,7 @@ function _asyncToGenerator(fn) {
35
27
  });
36
28
  };
37
29
  }
38
- function _iterableToArrayLimit(arr, i) {
39
- var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"];
40
- if (_i == null) return;
41
- var _arr = [];
42
- var _n = true;
43
- var _d = false;
44
- var _s, _e;
45
- try {
46
- for(_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true){
47
- _arr.push(_s.value);
48
- if (i && _arr.length === i) break;
49
- }
50
- } catch (err) {
51
- _d = true;
52
- _e = err;
53
- } finally{
54
- try {
55
- if (!_n && _i["return"] != null) _i["return"]();
56
- } finally{
57
- if (_d) throw _e;
58
- }
59
- }
60
- return _arr;
61
- }
62
- function _nonIterableRest() {
63
- throw new TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
64
- }
65
- function _slicedToArray(arr, i) {
66
- return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest();
67
- }
68
- function _unsupportedIterableToArray(o, minLen) {
69
- if (!o) return;
70
- if (typeof o === "string") return _arrayLikeToArray(o, minLen);
71
- var n = Object.prototype.toString.call(o).slice(8, -1);
72
- if (n === "Object" && o.constructor) n = o.constructor.name;
73
- if (n === "Map" || n === "Set") return Array.from(n);
74
- if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
75
- }
76
- var __generator = this && this.__generator || function(thisArg, body) {
30
+ function _ts_generator(thisArg, body) {
77
31
  var f, y, t, g, _ = {
78
32
  label: 0,
79
33
  sent: function() {
@@ -167,48 +121,47 @@ var __generator = this && this.__generator || function(thisArg, body) {
167
121
  done: true
168
122
  };
169
123
  }
170
- };
171
- import { ethers } from "ethers";
172
- import Web3 from "web3";
173
- import { jsonRpcProvider } from "../..";
124
+ }
125
+ import * as unfetch from "isomorphic-unfetch";
126
+ import { jsonRpcProvider, tinyBig } from "../..";
127
+ import { buildFetchInit, buildRPCPostBody } from "../../classes/utils/fetchers";
128
+ import { mockOf } from "./mock-of";
174
129
  import { rpcUrls } from "./rpc-urls";
175
- // coinbase 1 hotwallet
130
+ jest.mock("isomorphic-unfetch");
176
131
  var address = "0x71660c4005ba85c37ccec55d0c4493e66fe775d3";
177
132
  function testGetTC(rpcUrl, blockTag) {
178
133
  return _testGetTC.apply(this, arguments);
179
134
  }
180
135
  function _testGetTC() {
181
- _testGetTC = /**
182
- *
183
- * @param rpcUrl
184
- * @param blockTag
185
- */ _asyncToGenerator(function(rpcUrl, blockTag) {
186
- var eeProvider, ethersProvider, web3Provider, _ref, eeTC, ethersTC, web3TC;
187
- return __generator(this, function(_state) {
136
+ _testGetTC = _async_to_generator(function(rpcUrl, blockTag) {
137
+ var provider, mockPostResponse, spy, transactionCount, expectedBlockTag;
138
+ return _ts_generator(this, function(_state) {
188
139
  switch(_state.label){
189
140
  case 0:
190
- eeProvider = jsonRpcProvider(rpcUrl);
191
- ethersProvider = new ethers.providers.StaticJsonRpcProvider(rpcUrl);
192
- web3Provider = new Web3(rpcUrl);
141
+ provider = jsonRpcProvider(rpcUrl);
142
+ mockPostResponse = JSON.stringify({
143
+ jsonrpc: "2.0",
144
+ id: 1,
145
+ result: "0xa"
146
+ });
147
+ mockOf(unfetch.default).mockResolvedValueOnce({
148
+ text: function() {
149
+ return Promise.resolve(mockPostResponse);
150
+ }
151
+ });
152
+ spy = jest.spyOn(unfetch, "default");
193
153
  return [
194
154
  4,
195
- Promise.all([
196
- eeProvider.getTransactionCount(address, blockTag),
197
- ethersProvider.getTransactionCount(address, blockTag),
198
- web3Provider.eth.getTransactionCount(address, blockTag)
199
- ])
155
+ provider.getTransactionCount(address, blockTag)
200
156
  ];
201
157
  case 1:
202
- _ref = _slicedToArray.apply(void 0, [
203
- _state.sent(),
204
- 3
205
- ]), eeTC = _ref[0], ethersTC = _ref[1], web3TC = _ref[2];
206
- if (typeof blockTag === "number") {
207
- // a magic-number, no significance
208
- expect(eeTC).toBe(1053312);
209
- }
210
- expect(eeTC).toBe(ethersTC);
211
- expect(eeTC).toBe(web3TC);
158
+ transactionCount = _state.sent();
159
+ expect(transactionCount.toString()).toBe("10");
160
+ expectedBlockTag = typeof blockTag === "number" ? tinyBig(blockTag).toHexString() : blockTag !== null && blockTag !== void 0 ? blockTag : "latest";
161
+ expect(spy).toHaveBeenCalledWith(rpcUrl, buildFetchInit(buildRPCPostBody("eth_getTransactionCount", [
162
+ address,
163
+ expectedBlockTag
164
+ ])));
212
165
  return [
213
166
  2
214
167
  ];
@@ -217,10 +170,10 @@ function _testGetTC() {
217
170
  });
218
171
  return _testGetTC.apply(this, arguments);
219
172
  }
220
- describe("provider.getBalance mainnet", function() {
173
+ describe("provider.getTransactionCount matic", function() {
221
174
  var rpcUrl = rpcUrls.matic;
222
- it("should get latest equal to ethers and web3", /*#__PURE__*/ _asyncToGenerator(function() {
223
- return __generator(this, function(_state) {
175
+ it("should get the latest by the latest block", /*#__PURE__*/ _async_to_generator(function() {
176
+ return _ts_generator(this, function(_state) {
224
177
  switch(_state.label){
225
178
  case 0:
226
179
  return [
@@ -235,8 +188,8 @@ describe("provider.getBalance mainnet", function() {
235
188
  }
236
189
  });
237
190
  }));
238
- it("should get default latest equal to ethers and web3", /*#__PURE__*/ _asyncToGenerator(function() {
239
- return __generator(this, function(_state) {
191
+ it("should get transaction count by default latest block", /*#__PURE__*/ _async_to_generator(function() {
192
+ return _ts_generator(this, function(_state) {
240
193
  switch(_state.label){
241
194
  case 0:
242
195
  return [
@@ -251,8 +204,8 @@ describe("provider.getBalance mainnet", function() {
251
204
  }
252
205
  });
253
206
  }));
254
- it("should get earliest equal to ethers and web3", /*#__PURE__*/ _asyncToGenerator(function() {
255
- return __generator(this, function(_state) {
207
+ it("should get transaction count by earliest block", /*#__PURE__*/ _async_to_generator(function() {
208
+ return _ts_generator(this, function(_state) {
256
209
  switch(_state.label){
257
210
  case 0:
258
211
  return [
@@ -267,10 +220,20 @@ describe("provider.getBalance mainnet", function() {
267
220
  }
268
221
  });
269
222
  }));
270
- // re-enable when we have an archive node
271
- // fast-sync nodes are cheap and cannot compute old block data like this
272
- // Yields Error "missing trie node"
273
- // it('should tx count up to block number equal to ethers and web3', async () => {
274
- // await testGetTC(rpcUrl, 14649390);
275
- // });
223
+ it("should get TC by block number", /*#__PURE__*/ _async_to_generator(function() {
224
+ return _ts_generator(this, function(_state) {
225
+ switch(_state.label){
226
+ case 0:
227
+ return [
228
+ 4,
229
+ testGetTC(rpcUrl, 14649390)
230
+ ];
231
+ case 1:
232
+ _state.sent();
233
+ return [
234
+ 2
235
+ ];
236
+ }
237
+ });
238
+ }));
276
239
  });