forked from faker-ruby/faker
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Faker::Blockchain::Aeternity (faker-ruby#1742)
* add aeternity * update readme
- Loading branch information
Showing
4 changed files
with
108 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
|
||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |