Skip to content

Commit

Permalink
Add Faker::Blockchain::Aeternity (faker-ruby#1742)
Browse files Browse the repository at this point in the history
* add aeternity

* update readme
  • Loading branch information
2pd authored and michebble committed Feb 16, 2020
1 parent 59dd3af commit 8581d7b
Show file tree
Hide file tree
Showing 4 changed files with 108 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,7 @@ gem 'faker', :git => 'https://github.com/faker-ruby/faker.git', :branch => 'mast
- [Faker::WorldCup](doc/default/world_cup.md)

### Blockchain
- [Faker::Blockchain::Aeternity](doc/blockchain/aeternity.md)
- [Faker::Blockchain::Bitcoin](doc/blockchain/bitcoin.md)
- [Faker::Blockchain::Ethereum](doc/blockchain/ethereum.md)
- [Faker::Blockchain::Tezos](doc/blockchain/tezos.md)
Expand Down
12 changes: 12 additions & 0 deletions doc/blockchain/aeternity.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Faker::Blockchain::Aeternity

```ruby
Faker::Blockchain::Aeternity.address #=> "ak_zvU8YQLagjcfng7Tg8yCdiZ1rpiWNp1PBn3vtUs44utSvbJVR"

Faker::Blockchain::Aeternity.transaction #=> "th_147nDP22h3pHrLt2qykTH4txUwQh1ccaXp"

Faker::Blockchain::Aeternity.contract #=> "ct_Hk2JsNeWGEYQEHHQCfcBeGrwbhtYSwFTPdDhW2SvjFYVojyhW"

Faker::Blockchain::Aeternity.oracle #=> "ok_28QDg7fkF5qiKueSdUvUBtCYPJdmMEoS73CztzXCRAwMGKHKZh"

```
70 changes: 70 additions & 0 deletions lib/faker/blockchain/aeternity.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
# frozen_string_literal: true

module Faker
class Blockchain
class Aeternity < Base
class << self
##
# Produces a random Aeternity wallet address
#
# @return [String]
#
# @example
# Faker::Blockchain::Aeternity.address
# #=> "ak_zvU8YQLagjcfng7Tg8yCdiZ1rpiWNp1PBn3vtUs44utSvbJVR"
#
def address
'ak_' + rand_strings
end

##
# Produces a random Aeternity transaction
#
# @return [String]
#
# @example
# Faker::Blockchain::Aeternity.transaction
# #=> "th_147nDP22h3pHrLt2qykTH4txUwQh1ccaXp"
#
def transaction
'th_' + rand_strings(51)
end

##
# Produces a random Aeternity contract
#
# @return [String]
#
# @example
# Faker::Blockchain::Aeternity.contract
# #=> "ct_Hk2JsNeWGEYQEHHQCfcBeGrwbhtYSwFTPdDhW2SvjFYVojyhW"
#
def contract
'ct_' + rand_strings
end

##
# Produces a random Aeternity oracle
#
# @return [String]
#
# @example
# Faker::Blockchain::Aeternity.oracle
# #=> "ok_28QDg7fkF5qiKueSdUvUBtCYPJdmMEoS73CztzXCRAwMGKHKZh"
#
def oracle
'ok_' + rand_strings(51)
end

protected

def rand_strings(length = 50)
hex_alphabet = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'
var = +''
length.times { var << sample(shuffle(hex_alphabet.split(''))) }
var
end
end
end
end
end
25 changes: 25 additions & 0 deletions test/faker/blockchain/aeternity.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# frozen_string_literal: true

require_relative '../../test_helper'

class TestFakerAeternity < Test::Unit::TestCase
def setup
@tester = Faker::Blockchain::Aeternity
end

def test_address
assert_match(/ak_([0-9a-zA-Z]{50}$)/, @tester.address)
end

def test_transaction
assert_match(/th_([0-9a-zA-Z]{51}$)/, @tester.transaction)
end

def test_contract
assert_match(/ct_([0-9a-zA-Z]{50}$)/, @tester.contract)
end

def test_oracle
assert_match(/ok_([0-9a-zA-Z]{51}$)/, @tester.oracle)
end
end

0 comments on commit 8581d7b

Please sign in to comment.