erc20 0.1.3 → 0.1.4
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/Gemfile +1 -0
- data/Gemfile.lock +12 -0
- data/lib/erc20/erc20.rb +1 -1
- data/lib/erc20/wallet.rb +26 -16
- data/test/erc20/test_fake_wallet.rb +1 -1
- data/test/erc20/test_wallet.rb +65 -17
- data/test/test__helper.rb +3 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 71eb4c1f0b7e6778be6d2b121792c20aa190cdfdfc62948ce39e1c4ea1cb288f
|
4
|
+
data.tar.gz: 9dbb23249587fe95bf6681ab9b87a131b4f946343c515df036c1fa1c7f45b200
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: aeb83a009f276a4ead1a30e1d1cb052816067fb1571cca6cb20cc39a7840422342cbf246b498932be850c2330663d7e08356c2b3f35f2365acc933511462a4ab
|
7
|
+
data.tar.gz: '08b280c073e3d8bd1cc7b335b8d520e1808e190b50aaa227ee5fed17ae78ebc622637cd28c037e5991ea2dd8356cddb4f794ba240313f441cde0e79c3e7163d3'
|
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -12,6 +12,8 @@ PATH
|
|
12
12
|
GEM
|
13
13
|
remote: https://rubygems.org/
|
14
14
|
specs:
|
15
|
+
addressable (2.8.7)
|
16
|
+
public_suffix (>= 2.0.2, < 7.0)
|
15
17
|
ansi (1.5.0)
|
16
18
|
ast (2.4.3)
|
17
19
|
backtrace (0.4.0)
|
@@ -19,6 +21,9 @@ GEM
|
|
19
21
|
bigdecimal (3.1.9)
|
20
22
|
builder (3.3.0)
|
21
23
|
concurrent-ruby (1.3.5)
|
24
|
+
crack (1.0.0)
|
25
|
+
bigdecimal
|
26
|
+
rexml
|
22
27
|
cucumber (9.2.1)
|
23
28
|
builder (~> 3.2)
|
24
29
|
cucumber-ci-environment (> 9, < 11)
|
@@ -81,6 +86,7 @@ GEM
|
|
81
86
|
ffi (>= 1.15.5)
|
82
87
|
rake
|
83
88
|
forwardable (1.3.3)
|
89
|
+
hashdiff (1.1.2)
|
84
90
|
json (2.10.2)
|
85
91
|
jsonrpc-client (0.1.4)
|
86
92
|
faraday
|
@@ -113,6 +119,7 @@ GEM
|
|
113
119
|
racc
|
114
120
|
pkg-config (1.6.1)
|
115
121
|
prism (1.4.0)
|
122
|
+
public_suffix (6.0.1)
|
116
123
|
qbash (0.4.0)
|
117
124
|
backtrace (> 0)
|
118
125
|
elapsed (> 0)
|
@@ -184,6 +191,10 @@ GEM
|
|
184
191
|
unicode-emoji (~> 4.0, >= 4.0.4)
|
185
192
|
unicode-emoji (4.0.4)
|
186
193
|
uri (1.0.3)
|
194
|
+
webmock (3.25.1)
|
195
|
+
addressable (>= 2.8.0)
|
196
|
+
crack (>= 0.3.2)
|
197
|
+
hashdiff (>= 0.4.0, < 2.0.0)
|
187
198
|
websocket-driver (0.7.7)
|
188
199
|
base64
|
189
200
|
websocket-extensions (>= 0.1.0)
|
@@ -222,6 +233,7 @@ DEPENDENCIES
|
|
222
233
|
simplecov-cobertura (~> 2.1)
|
223
234
|
threads (~> 0.4)
|
224
235
|
typhoeus (> 0)
|
236
|
+
webmock (~> 3.23)
|
225
237
|
yard (~> 0.9)
|
226
238
|
|
227
239
|
BUNDLED WITH
|
data/lib/erc20/erc20.rb
CHANGED
data/lib/erc20/wallet.rb
CHANGED
@@ -121,7 +121,7 @@ class ERC20::Wallet
|
|
121
121
|
data = "0x#{func}000000000000000000000000#{address[2..].downcase}"
|
122
122
|
r = jsonrpc.eth_call({ to: @contract, data: data }, 'latest')
|
123
123
|
b = r[2..].to_i(16)
|
124
|
-
|
124
|
+
log_it(:debug, "The balance of #{address} is #{b} ERC20 tokens")
|
125
125
|
b
|
126
126
|
end
|
127
127
|
|
@@ -138,7 +138,7 @@ class ERC20::Wallet
|
|
138
138
|
raise 'Invalid format of the address' unless /^0x[0-9a-fA-F]{40}$/.match?(address)
|
139
139
|
r = jsonrpc.eth_getBalance(address, 'latest')
|
140
140
|
b = r[2..].to_i(16)
|
141
|
-
|
141
|
+
log_it(:debug, "The balance of #{address} is #{b} ETHs")
|
142
142
|
b
|
143
143
|
end
|
144
144
|
|
@@ -159,7 +159,7 @@ class ERC20::Wallet
|
|
159
159
|
raise "Amount (#{amount}) must be an Integer" unless amount.is_a?(Integer)
|
160
160
|
raise "Amount (#{amount}) must be a positive Integer" unless amount.positive?
|
161
161
|
gas = jsonrpc.eth_estimateGas({ from:, to: @contract, data: to_pay_data(to, amount) }, 'latest').to_i(16)
|
162
|
-
|
162
|
+
log_it(:debug, "It would take #{gas} gas units to send #{amount} tokens from #{from} to #{to}")
|
163
163
|
gas
|
164
164
|
end
|
165
165
|
|
@@ -177,7 +177,7 @@ class ERC20::Wallet
|
|
177
177
|
block = jsonrpc.eth_getBlockByNumber('latest', false)
|
178
178
|
raise "Can't get gas price, try again later" if block.nil?
|
179
179
|
gwei = block['baseFeePerGas'].to_i(16)
|
180
|
-
|
180
|
+
log_it(:debug, "The cost of one gas unit is #{gwei} gwei")
|
181
181
|
gwei
|
182
182
|
end
|
183
183
|
|
@@ -235,7 +235,7 @@ class ERC20::Wallet
|
|
235
235
|
hex = "0x#{tx.hex}"
|
236
236
|
jsonrpc.eth_sendRawTransaction(hex)
|
237
237
|
end
|
238
|
-
|
238
|
+
log_it(:debug, "Sent #{amount} ERC20 tokens from #{from} to #{address}: #{tnx}")
|
239
239
|
tnx.downcase
|
240
240
|
end
|
241
241
|
|
@@ -279,7 +279,7 @@ class ERC20::Wallet
|
|
279
279
|
hex = "0x#{tx.hex}"
|
280
280
|
jsonrpc.eth_sendRawTransaction(hex)
|
281
281
|
end
|
282
|
-
|
282
|
+
log_it(:debug, "Sent #{amount} ETHs from #{from} to #{address}: #{tnx}")
|
283
283
|
tnx.downcase
|
284
284
|
end
|
285
285
|
|
@@ -319,16 +319,15 @@ class ERC20::Wallet
|
|
319
319
|
raise 'Subscription ID must be a positive Integer' unless subscription_id.positive?
|
320
320
|
EventMachine.run do
|
321
321
|
u = url(http: false)
|
322
|
-
|
322
|
+
log_it(:debug, "Connecting to #{u.hostname}:#{u.port}...")
|
323
323
|
ws = Faye::WebSocket::Client.new(u.to_s, [], proxy: @proxy ? { origin: @proxy } : {})
|
324
|
-
log = @log
|
325
324
|
contract = @contract
|
326
325
|
attempt = []
|
327
326
|
log_url = "ws#{@ssl ? 's' : ''}://#{u.hostname}:#{u.port}"
|
328
327
|
ws.on(:open) do
|
329
328
|
safe do
|
330
329
|
verbose do
|
331
|
-
|
330
|
+
log_it(:debug, "Connected to #{log_url}")
|
332
331
|
end
|
333
332
|
end
|
334
333
|
end
|
@@ -341,14 +340,15 @@ class ERC20::Wallet
|
|
341
340
|
attempt.each do |a|
|
342
341
|
active.append(a) unless before.include?(a)
|
343
342
|
end
|
344
|
-
|
343
|
+
log_it(
|
344
|
+
:debug,
|
345
345
|
"Subscribed ##{subscription_id} to #{active.to_a.size} addresses at #{log_url}: " \
|
346
346
|
"#{active.to_a.map { |a| a[0..6] }.join(', ')}"
|
347
347
|
)
|
348
348
|
elsif data['method'] == 'eth_subscription' && data.dig('params', 'result')
|
349
349
|
event = data['params']['result']
|
350
350
|
if raw
|
351
|
-
|
351
|
+
log_it(:debug, "New event arrived from #{event['address']}")
|
352
352
|
else
|
353
353
|
event = {
|
354
354
|
amount: event['data'].to_i(16),
|
@@ -356,7 +356,8 @@ class ERC20::Wallet
|
|
356
356
|
to: "0x#{event['topics'][2][26..].downcase}",
|
357
357
|
txn: event['transactionHash'].downcase
|
358
358
|
}
|
359
|
-
|
359
|
+
log_it(
|
360
|
+
:debug,
|
360
361
|
"Payment of #{event[:amount]} tokens arrived " \
|
361
362
|
"from #{event[:from]} to #{event[:to]} in #{event[:txn]}"
|
362
363
|
)
|
@@ -369,14 +370,14 @@ class ERC20::Wallet
|
|
369
370
|
ws.on(:close) do
|
370
371
|
safe do
|
371
372
|
verbose do
|
372
|
-
|
373
|
+
log_it(:debug, "Disconnected from #{log_url}")
|
373
374
|
end
|
374
375
|
end
|
375
376
|
end
|
376
377
|
ws.on(:error) do |e|
|
377
378
|
safe do
|
378
379
|
verbose do
|
379
|
-
|
380
|
+
log_it(:debug, "Error at #{log_url}: #{e.message}")
|
380
381
|
end
|
381
382
|
end
|
382
383
|
end
|
@@ -401,7 +402,8 @@ class ERC20::Wallet
|
|
401
402
|
]
|
402
403
|
}.to_json
|
403
404
|
)
|
404
|
-
|
405
|
+
log_it(
|
406
|
+
:debug,
|
405
407
|
"Requested to subscribe ##{subscription_id} to #{addresses.to_a.size} addresses at #{log_url}: " \
|
406
408
|
"#{addresses.to_a.map { |a| a[0..6] }.join(', ')}"
|
407
409
|
)
|
@@ -420,7 +422,7 @@ class ERC20::Wallet
|
|
420
422
|
def verbose
|
421
423
|
yield
|
422
424
|
rescue StandardError => e
|
423
|
-
|
425
|
+
log_it(:error, Backtrace.new(e).to_s)
|
424
426
|
raise e
|
425
427
|
end
|
426
428
|
|
@@ -460,4 +462,12 @@ class ERC20::Wallet
|
|
460
462
|
amt_padded = ('0' * (64 - amt_hex.size)) + amt_hex
|
461
463
|
"0x#{func}#{to_padded}#{amt_padded}"
|
462
464
|
end
|
465
|
+
|
466
|
+
def log_it(method, msg)
|
467
|
+
if @log.respond_to?(method)
|
468
|
+
@log.__send__(method, msg)
|
469
|
+
elsif @log.respond_to?(:puts)
|
470
|
+
@log.puts(msg)
|
471
|
+
end
|
472
|
+
end
|
463
473
|
end
|
data/test/erc20/test_wallet.rb
CHANGED
@@ -7,7 +7,7 @@ require 'backtrace'
|
|
7
7
|
require 'donce'
|
8
8
|
require 'eth'
|
9
9
|
require 'faraday'
|
10
|
-
require '
|
10
|
+
require 'json'
|
11
11
|
require 'random-port'
|
12
12
|
require 'shellwords'
|
13
13
|
require 'threads'
|
@@ -31,18 +31,21 @@ class TestWallet < ERC20::Test
|
|
31
31
|
WALTER = '91f9111b1744d55361e632771a4e53839e9442a9fef45febc0a5c838c686a15b'
|
32
32
|
|
33
33
|
def test_checks_balance_on_mainnet
|
34
|
+
WebMock.enable_net_connect!
|
34
35
|
b = mainnet.balance(STABLE)
|
35
36
|
refute_nil(b)
|
36
37
|
assert_equal(8_000_000, b) # this is $8 USDT
|
37
38
|
end
|
38
39
|
|
39
40
|
def test_checks_eth_balance_on_mainnet
|
41
|
+
WebMock.enable_net_connect!
|
40
42
|
b = mainnet.eth_balance(STABLE)
|
41
43
|
refute_nil(b)
|
42
44
|
assert_equal(4_200_000_000_000_000, b) # this is 0.0042 ETH
|
43
45
|
end
|
44
46
|
|
45
47
|
def test_checks_balance_of_absent_address
|
48
|
+
WebMock.enable_net_connect!
|
46
49
|
a = '0xEB2fE8872A6f1eDb70a2632Effffffffffffffff'
|
47
50
|
b = mainnet.balance(a)
|
48
51
|
refute_nil(b)
|
@@ -50,6 +53,7 @@ class TestWallet < ERC20::Test
|
|
50
53
|
end
|
51
54
|
|
52
55
|
def test_checks_gas_estimate_on_mainnet
|
56
|
+
WebMock.enable_net_connect!
|
53
57
|
b = mainnet.gas_estimate(STABLE, Eth::Key.new(priv: JEFF).address.to_s, 44_000)
|
54
58
|
refute_nil(b)
|
55
59
|
assert_predicate(b, :positive?)
|
@@ -57,28 +61,45 @@ class TestWallet < ERC20::Test
|
|
57
61
|
end
|
58
62
|
|
59
63
|
def test_fails_with_invalid_infura_key
|
64
|
+
WebMock.enable_net_connect!
|
60
65
|
skip('Apparently, even with invalid key, Infura returns balance')
|
61
66
|
w = ERC20::Wallet.new(
|
62
67
|
contract: ERC20::Wallet.USDT,
|
63
68
|
host: 'mainnet.infura.io',
|
64
69
|
http_path: '/v3/invalid-key-here',
|
65
|
-
log:
|
70
|
+
log: fake_loog
|
66
71
|
)
|
67
|
-
assert_raises(StandardError) {
|
72
|
+
assert_raises(StandardError) { w.balance(STABLE) }
|
73
|
+
end
|
74
|
+
|
75
|
+
def test_logs_to_stdout
|
76
|
+
WebMock.disable_net_connect!
|
77
|
+
stub_request(:post, 'https://example.org/').to_return(
|
78
|
+
body: { jsonrpc: '2.0', id: 42, result: '0x1F1F1F' }.to_json,
|
79
|
+
headers: { 'Content-Type' => 'application/json' }
|
80
|
+
)
|
81
|
+
w = ERC20::Wallet.new(
|
82
|
+
host: 'example.org',
|
83
|
+
http_path: '/',
|
84
|
+
log: $stdout
|
85
|
+
)
|
86
|
+
w.balance(STABLE)
|
68
87
|
end
|
69
88
|
|
70
89
|
def test_checks_balance_on_testnet
|
90
|
+
WebMock.enable_net_connect!
|
71
91
|
b = testnet.balance(STABLE)
|
72
92
|
refute_nil(b)
|
73
93
|
assert_predicate(b, :zero?)
|
74
94
|
end
|
75
95
|
|
76
96
|
def test_checks_balance_on_polygon
|
97
|
+
WebMock.enable_net_connect!
|
77
98
|
w = ERC20::Wallet.new(
|
78
99
|
contract: '0xc2132D05D31c914a87C6611C10748AEb04B58e8F',
|
79
100
|
host: 'polygon-mainnet.infura.io',
|
80
101
|
http_path: "/v3/#{env('INFURA_KEY')}",
|
81
|
-
log:
|
102
|
+
log: fake_loog
|
82
103
|
)
|
83
104
|
b = w.balance(STABLE)
|
84
105
|
refute_nil(b)
|
@@ -86,6 +107,7 @@ class TestWallet < ERC20::Test
|
|
86
107
|
end
|
87
108
|
|
88
109
|
def test_checks_gas_estimate_on_hardhat
|
110
|
+
WebMock.enable_net_connect!
|
89
111
|
sum = 100_000
|
90
112
|
on_hardhat do |wallet|
|
91
113
|
b1 = wallet.gas_estimate(
|
@@ -98,6 +120,7 @@ class TestWallet < ERC20::Test
|
|
98
120
|
end
|
99
121
|
|
100
122
|
def test_checks_balance_on_hardhat
|
123
|
+
WebMock.enable_net_connect!
|
101
124
|
on_hardhat do |wallet|
|
102
125
|
b = wallet.balance(Eth::Key.new(priv: JEFF).address.to_s)
|
103
126
|
assert_equal(123_000_100_000, b)
|
@@ -105,6 +128,7 @@ class TestWallet < ERC20::Test
|
|
105
128
|
end
|
106
129
|
|
107
130
|
def test_checks_eth_balance_on_hardhat
|
131
|
+
WebMock.enable_net_connect!
|
108
132
|
on_hardhat do |wallet|
|
109
133
|
b = wallet.balance(Eth::Key.new(priv: WALTER).address.to_s)
|
110
134
|
assert_equal(456_000_000_000, b)
|
@@ -112,6 +136,7 @@ class TestWallet < ERC20::Test
|
|
112
136
|
end
|
113
137
|
|
114
138
|
def test_checks_balance_on_hardhat_in_threads
|
139
|
+
WebMock.enable_net_connect!
|
115
140
|
on_hardhat do |wallet|
|
116
141
|
Threads.new.assert do
|
117
142
|
b = wallet.balance(Eth::Key.new(priv: JEFF).address.to_s)
|
@@ -121,6 +146,7 @@ class TestWallet < ERC20::Test
|
|
121
146
|
end
|
122
147
|
|
123
148
|
def test_pays_on_hardhat
|
149
|
+
WebMock.enable_net_connect!
|
124
150
|
on_hardhat do |wallet|
|
125
151
|
to = Eth::Key.new(priv: WALTER).address.to_s
|
126
152
|
before = wallet.balance(to)
|
@@ -135,6 +161,7 @@ class TestWallet < ERC20::Test
|
|
135
161
|
end
|
136
162
|
|
137
163
|
def test_eth_pays_on_hardhat
|
164
|
+
WebMock.enable_net_connect!
|
138
165
|
on_hardhat do |wallet|
|
139
166
|
to = Eth::Key.new(priv: WALTER).address.to_s
|
140
167
|
before = wallet.eth_balance(to)
|
@@ -149,6 +176,7 @@ class TestWallet < ERC20::Test
|
|
149
176
|
end
|
150
177
|
|
151
178
|
def test_pays_on_hardhat_in_threads
|
179
|
+
WebMock.enable_net_connect!
|
152
180
|
on_hardhat do |wallet|
|
153
181
|
to = Eth::Key.new(priv: WALTER).address.to_s
|
154
182
|
before = wallet.balance(to)
|
@@ -162,6 +190,7 @@ class TestWallet < ERC20::Test
|
|
162
190
|
end
|
163
191
|
|
164
192
|
def test_pays_eth_on_hardhat_in_threads
|
193
|
+
WebMock.enable_net_connect!
|
165
194
|
on_hardhat do |wallet|
|
166
195
|
to = Eth::Key.new(priv: WALTER).address.to_s
|
167
196
|
before = wallet.eth_balance(to)
|
@@ -175,6 +204,7 @@ class TestWallet < ERC20::Test
|
|
175
204
|
end
|
176
205
|
|
177
206
|
def test_accepts_payments_on_hardhat
|
207
|
+
WebMock.enable_net_connect!
|
178
208
|
walter = Eth::Key.new(priv: WALTER).address.to_s.downcase
|
179
209
|
jeff = Eth::Key.new(priv: JEFF).address.to_s.downcase
|
180
210
|
on_hardhat do |wallet|
|
@@ -186,7 +216,7 @@ class TestWallet < ERC20::Test
|
|
186
216
|
event = e
|
187
217
|
end
|
188
218
|
rescue StandardError => e
|
189
|
-
|
219
|
+
fake_loog.error(Backtrace.new(e))
|
190
220
|
end
|
191
221
|
wait_for { !active.empty? }
|
192
222
|
sum = 77_000
|
@@ -202,6 +232,7 @@ class TestWallet < ERC20::Test
|
|
202
232
|
end
|
203
233
|
|
204
234
|
def test_accepts_many_payments_on_hardhat
|
235
|
+
WebMock.enable_net_connect!
|
205
236
|
walter = Eth::Key.new(priv: WALTER).address.to_s.downcase
|
206
237
|
on_hardhat do |wallet|
|
207
238
|
active = []
|
@@ -213,7 +244,7 @@ class TestWallet < ERC20::Test
|
|
213
244
|
events.add(e)
|
214
245
|
end
|
215
246
|
rescue StandardError => e
|
216
|
-
|
247
|
+
fake_loog.error(Backtrace.new(e))
|
217
248
|
end
|
218
249
|
wait_for { !active.empty? }
|
219
250
|
sum = 1_234
|
@@ -228,6 +259,7 @@ class TestWallet < ERC20::Test
|
|
228
259
|
end
|
229
260
|
|
230
261
|
def test_accepts_payments_with_failures_on_hardhat
|
262
|
+
WebMock.enable_net_connect!
|
231
263
|
walter = Eth::Key.new(priv: WALTER).address.to_s.downcase
|
232
264
|
on_hardhat do |wallet|
|
233
265
|
active = []
|
@@ -253,6 +285,7 @@ class TestWallet < ERC20::Test
|
|
253
285
|
end
|
254
286
|
|
255
287
|
def test_accepts_payments_on_changing_addresses_on_hardhat
|
288
|
+
WebMock.enable_net_connect!
|
256
289
|
walter = Eth::Key.new(priv: WALTER).address.to_s.downcase
|
257
290
|
jeff = Eth::Key.new(priv: JEFF).address.to_s.downcase
|
258
291
|
addresses = Primitivo.new([walter])
|
@@ -265,7 +298,7 @@ class TestWallet < ERC20::Test
|
|
265
298
|
event = e
|
266
299
|
end
|
267
300
|
rescue StandardError => e
|
268
|
-
|
301
|
+
fake_loog.error(Backtrace.new(e))
|
269
302
|
end
|
270
303
|
wait_for { active.to_a.include?(walter) }
|
271
304
|
sum1 = 453_000
|
@@ -285,6 +318,7 @@ class TestWallet < ERC20::Test
|
|
285
318
|
end
|
286
319
|
|
287
320
|
def test_accepts_payments_on_hardhat_via_proxy
|
321
|
+
WebMock.enable_net_connect!
|
288
322
|
via_proxy do |proxy|
|
289
323
|
walter = Eth::Key.new(priv: WALTER).address.to_s.downcase
|
290
324
|
jeff = Eth::Key.new(priv: JEFF).address.to_s.downcase
|
@@ -298,7 +332,7 @@ class TestWallet < ERC20::Test
|
|
298
332
|
event = e
|
299
333
|
end
|
300
334
|
rescue StandardError => e
|
301
|
-
|
335
|
+
fake_loog.error(Backtrace.new(e))
|
302
336
|
end
|
303
337
|
wait_for { !active.empty? }
|
304
338
|
sum = 55_000
|
@@ -312,6 +346,7 @@ class TestWallet < ERC20::Test
|
|
312
346
|
end
|
313
347
|
|
314
348
|
def test_accepts_payments_on_mainnet
|
349
|
+
WebMock.enable_net_connect!
|
315
350
|
active = []
|
316
351
|
failed = false
|
317
352
|
net = mainnet
|
@@ -322,7 +357,7 @@ class TestWallet < ERC20::Test
|
|
322
357
|
end
|
323
358
|
rescue StandardError => e
|
324
359
|
failed = true
|
325
|
-
|
360
|
+
fake_loog.error(Backtrace.new(e))
|
326
361
|
end
|
327
362
|
wait_for { !active.empty? }
|
328
363
|
daemon.kill
|
@@ -331,6 +366,7 @@ class TestWallet < ERC20::Test
|
|
331
366
|
end
|
332
367
|
|
333
368
|
def test_checks_balance_via_proxy
|
369
|
+
WebMock.enable_net_connect!
|
334
370
|
b = nil
|
335
371
|
via_proxy do |proxy|
|
336
372
|
on_hardhat do |w|
|
@@ -342,17 +378,19 @@ class TestWallet < ERC20::Test
|
|
342
378
|
end
|
343
379
|
|
344
380
|
def test_checks_balance_via_proxy_on_mainnet
|
381
|
+
WebMock.enable_net_connect!
|
345
382
|
via_proxy do |proxy|
|
346
383
|
w = ERC20::Wallet.new(
|
347
384
|
host: 'mainnet.infura.io',
|
348
385
|
http_path: "/v3/#{env('INFURA_KEY')}",
|
349
|
-
proxy:, log:
|
386
|
+
proxy:, log: fake_loog
|
350
387
|
)
|
351
388
|
assert_equal(8_000_000, w.balance(STABLE))
|
352
389
|
end
|
353
390
|
end
|
354
391
|
|
355
392
|
def test_pays_on_mainnet
|
393
|
+
WebMock.enable_net_connect!
|
356
394
|
skip('This is live, must be run manually')
|
357
395
|
w = mainnet
|
358
396
|
print 'Enter Ethereum ERC20 private key (64 chars): '
|
@@ -384,7 +422,12 @@ class TestWallet < ERC20::Test
|
|
384
422
|
ws_path: "/#{env('GETBLOCK_WS_KEY')}"
|
385
423
|
}
|
386
424
|
].map do |server|
|
387
|
-
ERC20::Wallet.new(
|
425
|
+
ERC20::Wallet.new(
|
426
|
+
host: server[:host],
|
427
|
+
http_path: server[:http_path],
|
428
|
+
ws_path: server[:ws_path],
|
429
|
+
log: fake_loog
|
430
|
+
)
|
388
431
|
end.sample
|
389
432
|
end
|
390
433
|
|
@@ -401,7 +444,12 @@ class TestWallet < ERC20::Test
|
|
401
444
|
ws_path: "/#{env('GETBLOCK_SEPOILA_KEY')}"
|
402
445
|
}
|
403
446
|
].map do |server|
|
404
|
-
ERC20::Wallet.new(
|
447
|
+
ERC20::Wallet.new(
|
448
|
+
host: server[:host],
|
449
|
+
http_path: server[:http_path],
|
450
|
+
ws_path: server[:ws_path],
|
451
|
+
log: fake_loog
|
452
|
+
)
|
405
453
|
end.sample
|
406
454
|
end
|
407
455
|
|
@@ -409,7 +457,7 @@ class TestWallet < ERC20::Test
|
|
409
457
|
ERC20::Wallet.new(
|
410
458
|
contract: wallet.contract, chain: wallet.chain,
|
411
459
|
host: donce_host, port: wallet.port, http_path: wallet.http_path, ws_path: wallet.ws_path,
|
412
|
-
ssl: wallet.ssl, proxy:, log:
|
460
|
+
ssl: wallet.ssl, proxy:, log: fake_loog
|
413
461
|
)
|
414
462
|
end
|
415
463
|
|
@@ -419,7 +467,7 @@ class TestWallet < ERC20::Test
|
|
419
467
|
image: 'yegor256/squid-proxy:latest',
|
420
468
|
ports: { port => 3128 },
|
421
469
|
env: { 'USERNAME' => 'jeffrey', 'PASSWORD' => 'swordfish' },
|
422
|
-
root: true, log:
|
470
|
+
root: true, log: fake_loog
|
423
471
|
) do
|
424
472
|
yield "http://jeffrey:swordfish@localhost:#{port}"
|
425
473
|
end
|
@@ -432,7 +480,7 @@ class TestWallet < ERC20::Test
|
|
432
480
|
home: File.join(__dir__, '../../hardhat'),
|
433
481
|
ports: { port => 8545 },
|
434
482
|
command: 'npx hardhat node',
|
435
|
-
log:
|
483
|
+
log: fake_loog
|
436
484
|
) do
|
437
485
|
wait_for_port(port)
|
438
486
|
cmd = [
|
@@ -445,13 +493,13 @@ class TestWallet < ERC20::Test
|
|
445
493
|
home: File.join(__dir__, '../../hardhat'),
|
446
494
|
command: "/bin/bash -c #{Shellwords.escape(cmd)}",
|
447
495
|
build_args: { 'HOST' => donce_host, 'PORT' => port },
|
448
|
-
log:
|
496
|
+
log: fake_loog,
|
449
497
|
root: true
|
450
498
|
).split("\n").last
|
451
499
|
wallet = ERC20::Wallet.new(
|
452
500
|
contract:, chain: 4242,
|
453
501
|
host: 'localhost', port:, http_path: '/', ws_path: '/', ssl: false,
|
454
|
-
log:
|
502
|
+
log: fake_loog
|
455
503
|
)
|
456
504
|
yield wallet
|
457
505
|
end
|
data/test/test__helper.rb
CHANGED
@@ -51,12 +51,14 @@ class Primitivo
|
|
51
51
|
end
|
52
52
|
end
|
53
53
|
|
54
|
+
require 'webmock/minitest'
|
55
|
+
|
54
56
|
# Test.
|
55
57
|
# Author:: Yegor Bugayenko (yegor256@gmail.com)
|
56
58
|
# Copyright:: Copyright (c) 2025 Yegor Bugayenko
|
57
59
|
# License:: MIT
|
58
60
|
class ERC20::Test < Minitest::Test
|
59
|
-
def
|
61
|
+
def fake_loog
|
60
62
|
ENV['RAKE'] ? Loog::ERRORS : Loog::VERBOSE
|
61
63
|
end
|
62
64
|
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: erc20
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Yegor Bugayenko
|
8
8
|
bindir: bin
|
9
9
|
cert_chain: []
|
10
|
-
date: 2025-04-
|
10
|
+
date: 2025-04-21 00:00:00.000000000 Z
|
11
11
|
dependencies:
|
12
12
|
- !ruby/object:Gem::Dependency
|
13
13
|
name: eth
|