erc20 0.1.6 → 0.2.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7843a4cb824e3689fb7a457f8ca0744f1d1059349aa6ea8bfe8805cd597e8b24
4
- data.tar.gz: d11d0eb794c22737519ef5ee2083763ba8244ce91f01f0f120ee8e6970af53c0
3
+ metadata.gz: 6e76d55c6807ddcd06e895bc54cd2edd16ad079b48131eaac1b118005f1b1d5b
4
+ data.tar.gz: 2bd2c637aa1e05d82695eb6581fed32992aabb45ed47dec179b78879380d1869
5
5
  SHA512:
6
- metadata.gz: 135c421a05cbc431e20113e8cd6d63294630588b6ba27a63249313455853b83266d697759764b6f82aae857131237fd5c8c85f4f1432fe74cb73a25935b5ca45
7
- data.tar.gz: ecf62b97b0053bc123de22f600e61a90cbf2e0636c1afa199d96478df0186194a917d27f0234285deb14129715970e2b818be5f6cf7d3a692d131a685a1af41f
6
+ metadata.gz: d9e574760a4e257e5b8e5131b25a8af9cf5b7dcbb4e32e03093f50114cc84d308faa691032d155e6ebe291c4ce4ad838f0253e46942a8b146b324ef6fe72f88d
7
+ data.tar.gz: fad0c35c9e011414a49cc727d5ff3321b74a4c6424463d7f5c947c74c73d0f8e1e22b91702d5341fea0988c6c5b5ed31ee3e625675393cbf7165e4163f0aa70a
@@ -0,0 +1,16 @@
1
+ # SPDX-FileCopyrightText: Copyright (c) 2025 Yegor Bugayenko
2
+ # SPDX-License-Identifier: MIT
3
+ ---
4
+ name: hadolint
5
+ 'on':
6
+ push:
7
+ pull_request:
8
+ jobs:
9
+ hadolint:
10
+ timeout-minutes: 15
11
+ runs-on: ubuntu-24.04
12
+ steps:
13
+ - uses: actions/checkout@v4
14
+ - uses: hadolint/hadolint-action@v3.1.0
15
+ with:
16
+ dockerfile: hardhat/Dockerfile
@@ -0,0 +1,19 @@
1
+ # SPDX-FileCopyrightText: Copyright (c) 2025 Yegor Bugayenko
2
+ # SPDX-License-Identifier: MIT
3
+ ---
4
+ # yamllint disable rule:line-length
5
+ name: typos
6
+ 'on':
7
+ push:
8
+ branches:
9
+ - master
10
+ pull_request:
11
+ branches:
12
+ - master
13
+ jobs:
14
+ typos:
15
+ timeout-minutes: 15
16
+ runs-on: ubuntu-24.04
17
+ steps:
18
+ - uses: actions/checkout@v4
19
+ - uses: crate-ci/typos@v1.32.0
data/.gitignore CHANGED
@@ -1,8 +1,8 @@
1
- *.gem
2
- .DS_Store
3
1
  .bundle/
2
+ .DS_Store
4
3
  .idea/
5
4
  .yardoc/
5
+ *.gem
6
6
  coverage/
7
7
  doc/
8
8
  node_modules/
data/Gemfile.lock CHANGED
@@ -49,7 +49,7 @@ GEM
49
49
  cucumber-messages (> 19, < 28)
50
50
  cucumber-messages (22.0.0)
51
51
  cucumber-tag-expressions (6.1.2)
52
- diff-lcs (1.6.1)
52
+ diff-lcs (1.6.2)
53
53
  docile (1.4.1)
54
54
  donce (0.2.4)
55
55
  backtrace (~> 0.3)
@@ -69,7 +69,7 @@ GEM
69
69
  ethon (0.16.0)
70
70
  ffi (>= 1.15.0)
71
71
  eventmachine (1.2.7)
72
- faraday (2.13.0)
72
+ faraday (2.13.1)
73
73
  faraday-net_http (>= 2.0, < 3.5)
74
74
  json
75
75
  logger
@@ -87,18 +87,19 @@ GEM
87
87
  rake
88
88
  forwardable (1.3.3)
89
89
  hashdiff (1.1.2)
90
- json (2.10.2)
90
+ json (2.12.0)
91
91
  jsonrpc-client (0.1.4)
92
92
  faraday
93
93
  multi_json (>= 1.1.0)
94
94
  keccak (1.3.2)
95
95
  konstructor (1.0.2)
96
- language_server-protocol (3.17.0.4)
96
+ language_server-protocol (3.17.0.5)
97
97
  lint_roller (1.1.0)
98
98
  logger (1.7.0)
99
- loog (0.6.0)
99
+ loog (0.6.1)
100
+ logger (~> 1.0)
100
101
  mini_mime (1.1.5)
101
- mini_portile2 (2.8.8)
102
+ mini_portile2 (2.8.9)
102
103
  minitest (5.25.5)
103
104
  minitest-reporters (1.7.1)
104
105
  ansi
@@ -117,10 +118,10 @@ GEM
117
118
  parser (3.3.8.0)
118
119
  ast (~> 2.4.1)
119
120
  racc
120
- pkg-config (1.6.1)
121
+ pkg-config (1.6.2)
121
122
  prism (1.4.0)
122
- public_suffix (6.0.1)
123
- qbash (0.4.0)
123
+ public_suffix (6.0.2)
124
+ qbash (0.4.5)
124
125
  backtrace (> 0)
125
126
  elapsed (> 0)
126
127
  loog (> 0)
@@ -136,7 +137,7 @@ GEM
136
137
  rubyzip (~> 2.3)
137
138
  regexp_parser (2.10.0)
138
139
  rexml (3.4.1)
139
- rubocop (1.75.3)
140
+ rubocop (1.75.5)
140
141
  json (~> 2.3)
141
142
  language_server-protocol (~> 3.17.0.2)
142
143
  lint_roller (~> 1.1.0)
data/REUSE.toml CHANGED
@@ -4,10 +4,19 @@
4
4
  version = 1
5
5
  [[annotations]]
6
6
  path = [
7
+ ".DS_Store",
8
+ ".gitattributes",
9
+ ".gitignore",
10
+ ".gitleaksignore",
11
+ ".pdd",
7
12
  "**.json",
8
13
  "**.md",
9
14
  "**.png",
10
15
  "**.txt",
16
+ "**/.DS_Store",
17
+ "**/.gitignore",
18
+ "**/.gitleaksignore",
19
+ "**/.pdd",
11
20
  "**/*.csv",
12
21
  "**/*.jpg",
13
22
  "**/*.json",
@@ -17,23 +26,14 @@ path = [
17
26
  "**/*.svg",
18
27
  "**/*.txt",
19
28
  "**/*.vm",
20
- "**/.DS_Store",
21
- "**/.gitignore",
22
- "**/.gitleaksignore",
23
- "**/.pdd",
24
- "**/CNAME",
25
29
  "**/Cargo.toml",
30
+ "**/CNAME",
26
31
  "**/Gemfile.lock",
27
- ".DS_Store",
28
- ".gitattributes",
29
- ".gitignore",
30
- ".gitleaksignore",
31
- ".pdd",
32
32
  "Cargo.toml",
33
33
  "Gemfile.lock",
34
- "README.md",
35
34
  "hardhat/.gitignore",
36
35
  "hardhat/package.json",
36
+ "README.md",
37
37
  "renovate.json",
38
38
  ]
39
39
  precedence = "override"
data/hardhat/Dockerfile CHANGED
@@ -14,14 +14,12 @@ RUN npm install
14
14
  ARG PORT=8080
15
15
  ARG HOST=localhost
16
16
  COPY hardhat.config.js .
17
- RUN sed -i "s/PORT/$PORT/g" hardhat.config.js
18
- RUN sed -i "s/HOST/$HOST/g" hardhat.config.js
17
+ RUN sed -i "s/PORT/$PORT/g" hardhat.config.js \
18
+ && sed -i "s/HOST/$HOST/g" hardhat.config.js
19
19
 
20
20
  COPY contracts contracts
21
21
  COPY ignition ignition
22
22
 
23
- RUN rm -rf ignition/deployments
24
-
25
- RUN npx hardhat compile
26
-
27
- RUN rm -rf cache
23
+ RUN rm -rf ignition/deployments \
24
+ && npx hardhat compile \
25
+ && rm -rf cache
data/lib/erc20/erc20.rb CHANGED
@@ -25,5 +25,5 @@
25
25
  # License:: MIT
26
26
  module ERC20
27
27
  # Current version of the gem (changed by the +.rultor.yml+ on every release)
28
- VERSION = '0.1.6'
28
+ VERSION = '0.2.0'
29
29
  end
@@ -69,6 +69,14 @@ class ERC20::FakeWallet
69
69
  b
70
70
  end
71
71
 
72
+ # Get ERC20 amount (in tokens) that was sent in the given transaction.
73
+ #
74
+ # @param [String] txn Hex of transaction
75
+ # @return [Integer] Balance, in ERC20 tokens
76
+ def sum_of(_txn)
77
+ 42_000_000
78
+ end
79
+
72
80
  # How much gas units is required in order to send ERC20 transaction.
73
81
  #
74
82
  # @param [String] from The departing address, in hex
data/lib/erc20/wallet.rb CHANGED
@@ -142,6 +142,28 @@ class ERC20::Wallet
142
142
  b
143
143
  end
144
144
 
145
+ # Get ERC20 amount (in tokens) that was sent in the given transaction.
146
+ #
147
+ # @param [String] txn Hex of transaction
148
+ # @return [Integer] Balance, in ERC20 tokens
149
+ def sum_of(txn)
150
+ raise 'Transaction hash can\'t be nil' unless txn
151
+ raise 'Transaction hash must be a String' unless txn.is_a?(String)
152
+ raise 'Invalid format of the transaction hash' unless /^0x[0-9a-fA-F]{64}$/.match?(txn)
153
+ receipt = jsonrpc.eth_getTransactionReceipt(txn)
154
+ raise "Transaction not found: #{txn}" if receipt.nil?
155
+ logs = receipt['logs'] || []
156
+ transfer_event = '0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef'
157
+ logs.each do |log|
158
+ next unless log['topics'] && log['topics'][0] == transfer_event
159
+ next unless log['address'].downcase == @contract.downcase
160
+ amount = log['data'].to_i(16)
161
+ log_it(:debug, "Found transfer of #{amount} tokens in transaction #{txn}")
162
+ return amount
163
+ end
164
+ raise "No transfer event found in transaction #{txn}"
165
+ end
166
+
145
167
  # How many gas units are required to send an ERC20 transaction.
146
168
  #
147
169
  # @param [String] from The sending address, in hex
@@ -68,6 +68,11 @@ class TestFakeWallet < ERC20::Test
68
68
  assert_equal(b, w.eth_balance(a))
69
69
  end
70
70
 
71
+ def test_reads_sum_of_payment
72
+ txn = '0xcf0598d640d4bea3367e6af28a08c54342a39156afd292a31453778e4755945d'
73
+ assert_predicate(ERC20::FakeWallet.new.sum_of(txn), :positive?)
74
+ end
75
+
71
76
  def test_returns_host
72
77
  assert_equal('example.com', ERC20::FakeWallet.new.host)
73
78
  end
@@ -103,6 +103,15 @@ class TestWallet < ERC20::Test
103
103
  end
104
104
  end
105
105
 
106
+ def test_reads_payment_amount_on_hardhat
107
+ WebMock.enable_net_connect!
108
+ on_hardhat do |wallet|
109
+ sum = 33_330
110
+ txn = wallet.pay(JEFF, Eth::Key.new(priv: WALTER).address.to_s, sum)
111
+ assert_equal(sum, wallet.sum_of(txn))
112
+ end
113
+ end
114
+
106
115
  def test_eth_pays_on_hardhat
107
116
  WebMock.enable_net_connect!
108
117
  on_hardhat do |wallet|
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.6
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yegor Bugayenko
8
8
  bindir: bin
9
9
  cert_chain: []
10
- date: 2025-04-24 00:00:00.000000000 Z
10
+ date: 1980-01-02 00:00:00.000000000 Z
11
11
  dependencies:
12
12
  - !ruby/object:Gem::Dependency
13
13
  name: eth
@@ -102,19 +102,21 @@ executables:
102
102
  - erc20
103
103
  extensions: []
104
104
  extra_rdoc_files:
105
- - README.md
106
105
  - LICENSE.txt
106
+ - README.md
107
107
  files:
108
108
  - ".0pdd.yml"
109
109
  - ".gitattributes"
110
110
  - ".github/workflows/actionlint.yml"
111
111
  - ".github/workflows/codecov.yml"
112
112
  - ".github/workflows/copyrights.yml"
113
+ - ".github/workflows/hadolint.yml"
113
114
  - ".github/workflows/markdown-lint.yml"
114
115
  - ".github/workflows/pdd.yml"
115
116
  - ".github/workflows/rake.yml"
116
117
  - ".github/workflows/reuse.yml"
117
118
  - ".github/workflows/shellcheck.yml"
119
+ - ".github/workflows/typos.yml"
118
120
  - ".github/workflows/xcop.yml"
119
121
  - ".github/workflows/yamllint.yml"
120
122
  - ".gitignore"
@@ -171,7 +173,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
171
173
  - !ruby/object:Gem::Version
172
174
  version: '0'
173
175
  requirements: []
174
- rubygems_version: 3.6.2
176
+ rubygems_version: 3.6.7
175
177
  specification_version: 4
176
178
  summary: Sending and receiving ERC20 tokens in Ethereum network
177
179
  test_files: []