Skip to content

Commit

Permalink
Check Crypto Addresses against OFAC sanction list (#4423)
Browse files Browse the repository at this point in the history
  • Loading branch information
tsmartt authored Apr 24, 2024
1 parent f7c47d3 commit 088c12a
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 6 deletions.
2 changes: 2 additions & 0 deletions app/models/crypto_address.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ class CryptoAddress < ApplicationRecord
validate :chain_not_changed?
validate :address_not_changed?

validates :address, banned_address: true

scope :sol_addresses, -> { where(chain: "SOL") }
scope :eth_addresses, -> { where(chain: "ETH") }

Expand Down
4 changes: 3 additions & 1 deletion app/validators/banned_address_validator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ def validate_each(record, attribute, value)
banned_addresses = OfacAddress.pluck(:address)

banned_addresses.each do |banned_address|
if !banned_address.blank? && value.to_s.strip.downcase.include?(banned_address.to_s.strip.downcase)
stripped_ba = banned_address.to_s.strip.downcase
stripped_val = value.to_s.strip.downcase
if (stripped_ba.present? && stripped_val.present?) && (stripped_val.include?(stripped_ba) || stripped_ba.include?(stripped_val))
record.errors.add attribute.to_sym, "can't be a banned address"
end
end
Expand Down
10 changes: 8 additions & 2 deletions test/fixtures/crypto_addresses.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html

sol_address:
address: '9VoNhsLUhXVTzmqTE4iRPTTmACREYrKR11HG4J4BKyfp'
address: '9VoNhsLUhXVTzmqTE4iRPTTmACREYrKR11HG4J4BKyfeeep'
verified: true
chain: 'SOL'
publisher: verified
Expand Down Expand Up @@ -34,4 +34,10 @@ other_default_eth_address:
address: '0xFA32b121738bD8d1d5fDD61aC3587533aaA86e67'
verified: true
chain: 'ETH'
publisher: default
publisher: default

banned_sol_address:
address: 'BwG1C3hDdNq2rTDHvcMFwuokefdQvUQUXRQ123321gwjJL86XM'
verified: true
chain: 'SOL'
publisher: verified
6 changes: 3 additions & 3 deletions test/fixtures/ofac_addresses.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
one:
address: '9VoNhsLUhXVTzmqTE4iRPTTmACREYrKR11HG4J4BKyfp'
address: '9VoNhsLUhXVTzmqTE4iRPeeeeeeeeeTTmACREYrKR11HG4J4BKyfp'

two:
address: 'HN7cABqLq46Es1jh92dQQisAq662SmxELLLsHHe4YWrH'
address: 'HN7cABqLq46Es1jh92dQQisAq662SmxELL1231321LsHHe4YWrH'

three:
address: 'BwG1C3hDdNq2rTDHvcMFwuokefdQvUQUXRQgwjJL86XM'
address: 'BwG1C3hDdNq2rTDHvcMFwuokefdQvUQUXRQ123321gwjJL86XM'
7 changes: 7 additions & 0 deletions test/models/crypto_address_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,11 @@
assert_equal "can't be changed", address.errors.messages[:address][0]
assert_equal "can't be changed", address.errors.messages[:chain][0]
end

it "is invalid when using a restricted address" do
address = crypto_addresses(:banned_sol_address)
refute address.valid?

assert address.errors.full_messages.first == "Address can't be a banned address"
end
end

0 comments on commit 088c12a

Please sign in to comment.