erc20 0.2.0 → 0.2.2

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.
data/test/test__helper.rb DELETED
@@ -1,206 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- # SPDX-FileCopyrightText: Copyright (c) 2025 Yegor Bugayenko
4
- # SPDX-License-Identifier: MIT
5
-
6
- $stdout.sync = true
7
-
8
- require 'simplecov'
9
- require 'simplecov-cobertura'
10
- unless SimpleCov.running
11
- SimpleCov.command_name('test')
12
- SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter.new(
13
- [
14
- SimpleCov::Formatter::HTMLFormatter,
15
- SimpleCov::Formatter::CoberturaFormatter
16
- ]
17
- )
18
- SimpleCov.minimum_coverage 90
19
- SimpleCov.minimum_coverage_by_file 90
20
- SimpleCov.start do
21
- add_filter 'test/'
22
- add_filter 'vendor/'
23
- add_filter 'target/'
24
- track_files 'lib/**/*.rb'
25
- track_files '*.rb'
26
- end
27
- end
28
-
29
- require 'minitest/autorun'
30
- require 'minitest/reporters'
31
- Minitest::Reporters.use! [Minitest::Reporters::SpecReporter.new]
32
-
33
- # To make tests retry on failure:
34
- if ENV['RAKE']
35
- require 'minitest/retry'
36
- Minitest::Retry.use!
37
- end
38
-
39
- # Primitive array.
40
- class Primitivo
41
- def initialize(array)
42
- @array = array
43
- end
44
-
45
- def clear
46
- @array.clear
47
- end
48
-
49
- def to_a
50
- @array.to_a
51
- end
52
-
53
- def append(item)
54
- @array.append(item)
55
- end
56
- end
57
-
58
- require 'webmock/minitest'
59
-
60
- # Test.
61
- # Author:: Yegor Bugayenko (yegor256@gmail.com)
62
- # Copyright:: Copyright (c) 2025 Yegor Bugayenko
63
- # License:: MIT
64
- class ERC20::Test < Minitest::Test
65
- def fake_loog
66
- ENV['RAKE'] ? Loog::ERRORS : Loog::VERBOSE
67
- end
68
-
69
- def wait_for(seconds = 30)
70
- start = Time.now
71
- loop do
72
- sleep(0.1)
73
- break if yield
74
- passed = Time.now - start
75
- raise "Giving up after #{passed} seconds of waiting" if passed > seconds
76
- rescue Errno::ECONNREFUSED
77
- retry
78
- end
79
- end
80
-
81
- def wait_for_port(port)
82
- wait_for { Typhoeus::Request.get("http://localhost:#{port}").code == 200 }
83
- end
84
-
85
- def env(var)
86
- key = ENV.fetch(var, nil)
87
- skip("The #{var} environment variable is not set") if key.nil?
88
- skip("The #{var} environment variable is empty") if key.empty?
89
- key
90
- end
91
-
92
- def mainnet
93
- [
94
- {
95
- host: 'mainnet.infura.io',
96
- http_path: "/v3/#{env('INFURA_KEY')}",
97
- ws_path: "/ws/v3/#{env('INFURA_KEY')}"
98
- },
99
- {
100
- host: 'go.getblock.io',
101
- http_path: "/#{env('GETBLOCK_KEY')}",
102
- ws_path: "/#{env('GETBLOCK_WS_KEY')}"
103
- }
104
- ].map do |server|
105
- ERC20::Wallet.new(
106
- host: server[:host],
107
- http_path: server[:http_path],
108
- ws_path: server[:ws_path],
109
- log: fake_loog
110
- )
111
- end.sample
112
- end
113
-
114
- def testnet
115
- [
116
- {
117
- host: 'sepolia.infura.io',
118
- http_path: "/v3/#{env('INFURA_KEY')}",
119
- ws_path: "/ws/v3/#{env('INFURA_KEY')}"
120
- },
121
- {
122
- host: 'go.getblock.io',
123
- http_path: "/#{env('GETBLOCK_SEPOILA_KEY')}",
124
- ws_path: "/#{env('GETBLOCK_SEPOILA_KEY')}"
125
- }
126
- ].map do |server|
127
- ERC20::Wallet.new(
128
- host: server[:host],
129
- http_path: server[:http_path],
130
- ws_path: server[:ws_path],
131
- log: fake_loog
132
- )
133
- end.sample
134
- end
135
-
136
- def through_proxy(wallet, proxy)
137
- ERC20::Wallet.new(
138
- contract: wallet.contract, chain: wallet.chain,
139
- host: donce_host, port: wallet.port, http_path: wallet.http_path, ws_path: wallet.ws_path,
140
- ssl: wallet.ssl, proxy:, log: fake_loog
141
- )
142
- end
143
-
144
- def via_proxy
145
- RandomPort::Pool::SINGLETON.acquire do |port|
146
- donce(
147
- image: 'yegor256/squid-proxy:latest',
148
- ports: { port => 3128 },
149
- env: { 'USERNAME' => 'jeffrey', 'PASSWORD' => 'swordfish' },
150
- root: true, log: fake_loog
151
- ) do
152
- yield "http://jeffrey:swordfish@localhost:#{port}"
153
- end
154
- end
155
- end
156
-
157
- def on_hardhat(port: nil, die: nil)
158
- RandomPort::Pool::SINGLETON.acquire do |rnd|
159
- port = rnd if port.nil?
160
- if die
161
- killer = [
162
- '&',
163
- 'HARDHAT_PID=$!;',
164
- 'export HARDHAT_PID;',
165
- 'while true; do',
166
- " if [ -e #{Shellwords.escape(File.join('/die', File.basename(die)))} ]; then",
167
- ' kill -9 "${HARDHAT_PID}";',
168
- ' break;',
169
- ' else',
170
- ' sleep 0.1;',
171
- ' fi;',
172
- 'done'
173
- ].join(' ')
174
- end
175
- cmd = "npx hardhat node #{killer if die}"
176
- donce(
177
- home: File.join(__dir__, '../hardhat'),
178
- ports: { port => 8545 },
179
- volumes: die ? { File.dirname(die) => '/die' } : {},
180
- command: "/bin/bash -c #{Shellwords.escape(cmd)}",
181
- log: fake_loog
182
- ) do
183
- wait_for_port(port)
184
- cmd = [
185
- '(cat hardhat.config.js)',
186
- '(ls -al)',
187
- '(echo y | npx hardhat ignition deploy ./ignition/modules/Foo.ts --network foo --deployment-id foo)',
188
- '(npx hardhat ignition status foo | tail -1 | cut -d" " -f3)'
189
- ].join(' && ')
190
- contract = donce(
191
- home: File.join(__dir__, '../hardhat'),
192
- command: "/bin/bash -c #{Shellwords.escape(cmd)}",
193
- build_args: { 'HOST' => donce_host, 'PORT' => port },
194
- log: fake_loog,
195
- root: true
196
- ).split("\n").last
197
- wallet = ERC20::Wallet.new(
198
- contract:, chain: 4242,
199
- host: 'localhost', port:, http_path: '/', ws_path: '/', ssl: false,
200
- log: fake_loog
201
- )
202
- yield wallet
203
- end
204
- end
205
- end
206
- end