erc20 0.0.17 → 0.0.18

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 53d1ed4b12b1b7e295242f5345c3ebd4f22e8fe83af31bd2bcb4f27ec8a0b4ca
4
- data.tar.gz: e377b3185614081e92f72a7fda5c9a8019de72a3497b9d28259e13f17a5f1ab0
3
+ metadata.gz: 37aa39344c429cfd2153f004bd2a92730cd3a22c4f11c04e31573d36a98b2045
4
+ data.tar.gz: c64d6baecf8256cce26bad81f16608b01098b1c581a1370dedb05b9761a8a6e2
5
5
  SHA512:
6
- metadata.gz: 892709a9568e7837a708feefd8d7880d309fae9f921d1a8266e1b7b995acb1575a6305af92a1dd5dab7b9e7a7f3da9cc5b0b2539a9984eac91d291f59c5d86d1
7
- data.tar.gz: d945d2ec483e4cc14ff76683294941cfaf9603963baf8c3acbf64189ee59aead1ec70e6b2d292c889d790c8f8f6fcd59c5327bb2a5223a138821fd5592971178
6
+ metadata.gz: 030bd6e0734bef65820b1c0a63237eed014bc1e1291e7a98f2e8ffe17bffab6aaa3d6cc9685f0901002512376c6ac2bece5d9c564249259700df82ba2bb609c0
7
+ data.tar.gz: 5836008fa63ea04bc68f7e8cc670f18b17ec887be606fedf1315e1d6e94d6be2b21859693c173d7ecd56e173fcd13f4598e08099fca941fb1bedd6367dc16e80
data/lib/erc20/erc20.rb CHANGED
@@ -42,5 +42,5 @@
42
42
  # License:: MIT
43
43
  module ERC20
44
44
  # Current version of the gem (changed by the +.rultor.yml+ on every release)
45
- VERSION = '0.0.17'
45
+ VERSION = '0.0.18'
46
46
  end
data/lib/erc20/wallet.rb CHANGED
@@ -159,22 +159,22 @@ class ERC20::Wallet
159
159
  b
160
160
  end
161
161
 
162
- # How much ETH gas is required in order to send this ETH transaction.
162
+ # How much ETH gas is required in order to send ERC20 transaction.
163
163
  #
164
164
  # @param [String] from The departing address, in hex
165
- # @param [String] to Arriving address, in hex
165
+ # @param [String] to Arriving address, in hex (it's OK to skip it)
166
166
  # @return [Integer] How many ETH required
167
- def eth_gas_required(from, to)
168
- gas_estimate(from, to)
167
+ def gas_required(from, to = from)
168
+ gas_estimate(from, to, to_pay_data(from, 100_000))
169
169
  end
170
170
 
171
- # How much ETH gas is required in order to send this ERC20 transaction.
171
+ # How much ETH gas is required in order to send this ETH transaction.
172
172
  #
173
173
  # @param [String] from The departing address, in hex
174
- # @param [String] to Arriving address, in hex
174
+ # @param [String] to Arriving address, in hex (it's OK to skip it)
175
175
  # @return [Integer] How many ETH required
176
- def gas_required(from, to)
177
- gas_estimate(from, to, to_pay_data(from, 100_000))
176
+ def eth_gas_required(from, to = from)
177
+ gas_estimate(from, to)
178
178
  end
179
179
 
180
180
  # Send a single ERC20 payment from a private address to a public one.
@@ -430,7 +430,9 @@ class ERC20::Wallet
430
430
  # public address to another public address, possible carrying some data
431
431
  # inside the transaction.
432
432
  def gas_estimate(from, to, data = '')
433
- jsonrpc.eth_estimateGas({ from:, to:, data: }, 'latest').to_i(16)
433
+ gas = jsonrpc.eth_estimateGas({ from:, to:, data: }, 'latest').to_i(16)
434
+ @log.debug("Estimated gas is #{gas} ETH#{data.empty? ? '' : ', for ERC20 transfer'}")
435
+ gas
434
436
  end
435
437
 
436
438
  def to_pay_data(address, amount)
@@ -73,6 +73,12 @@ class TestWallet < Minitest::Test
73
73
  assert_predicate(b, :positive?)
74
74
  end
75
75
 
76
+ def test_checks_same_address_gas_required_on_mainnet
77
+ b = mainnet.gas_required(STABLE, STABLE)
78
+ refute_nil(b)
79
+ assert_predicate(b, :positive?)
80
+ end
81
+
76
82
  def test_fails_with_invalid_infura_key
77
83
  skip('Apparently, even with invalid key, Infura returns balance')
78
84
  w = ERC20::Wallet.new(
@@ -102,11 +108,16 @@ class TestWallet < Minitest::Test
102
108
 
103
109
  def test_checks_gas_required_on_hardhat
104
110
  on_hardhat do |wallet|
105
- b = wallet.gas_required(
111
+ b1 = wallet.gas_required(
106
112
  Eth::Key.new(priv: JEFF).address.to_s,
107
113
  Eth::Key.new(priv: WALTER).address.to_s
108
114
  )
109
- assert_equal(21_597, b)
115
+ assert_equal(21_597, b1)
116
+ b2 = wallet.gas_required(
117
+ Eth::Key.new(priv: JEFF).address.to_s,
118
+ Eth::Key.new(priv: JEFF).address.to_s
119
+ )
120
+ assert_equal(b1, b2)
110
121
  end
111
122
  end
112
123
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: erc20
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.17
4
+ version: 0.0.18
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yegor Bugayenko