erc20 0.0.17 → 0.0.18
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.
- checksums.yaml +4 -4
- data/lib/erc20/erc20.rb +1 -1
- data/lib/erc20/wallet.rb +11 -9
- data/test/erc20/test_wallet.rb +13 -2
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 37aa39344c429cfd2153f004bd2a92730cd3a22c4f11c04e31573d36a98b2045
|
4
|
+
data.tar.gz: c64d6baecf8256cce26bad81f16608b01098b1c581a1370dedb05b9761a8a6e2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 030bd6e0734bef65820b1c0a63237eed014bc1e1291e7a98f2e8ffe17bffab6aaa3d6cc9685f0901002512376c6ac2bece5d9c564249259700df82ba2bb609c0
|
7
|
+
data.tar.gz: 5836008fa63ea04bc68f7e8cc670f18b17ec887be606fedf1315e1d6e94d6be2b21859693c173d7ecd56e173fcd13f4598e08099fca941fb1bedd6367dc16e80
|
data/lib/erc20/erc20.rb
CHANGED
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
|
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
|
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
|
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
|
177
|
-
gas_estimate(from, to
|
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)
|
data/test/erc20/test_wallet.rb
CHANGED
@@ -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
|
-
|
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,
|
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
|
|