Skip to content

Commit

Permalink
Feat/add blockchain tezos keys (#2208)
Browse files Browse the repository at this point in the history
* Faker::Tezos: add block faker

* Faker::Blockhain::Tezos: add documentation for #block

* Faker::Blockchain::Tezos: add secret_key and public_key

Co-authored-by: Abdelkader <akettal@users.noreply.github.com>
  • Loading branch information
Pierre-Michard and akettal committed Nov 28, 2020
1 parent 766c4ef commit e6604d0
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 0 deletions.
4 changes: 4 additions & 0 deletions doc/blockchain/tezos.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,8 @@ Faker::Blockchain::Tezos.operation #=> "onygWYXJX3xNstFLv9PcCrhQdCkENC795xwSinmT
Faker::Blockchain::Tezos.block #=> "BMbhs2rkY1dvAkAyRytvPsjFQ2RiPrBhYkxvWpY65dzkdSuw58a"

Faker::Blockchain::Tezos.signature #=> "edsigu165B7VFf3Dpw2QABVzEtCxJY2gsNBNcE3Ti7rRxtDUjqTFRpg67EdAQmY6YWPE5tKJDMnSTJDFu65gic8uLjbW2YwGvAZ"

Faker::Blockchain::Tezos.public_key #=> "edpkuib9x8QXRc5nWwHUg7U1dXsVmaUrUNU5sX9pVEEvwbMVdfMCeq"

Faker::Blockchain::Tezos.secret_key #=> "edsk3HZCAGEGpzQPnQUwQeFY4ESanFhQCgLpKriQw8GHyhKCrjHawv"
```
28 changes: 28 additions & 0 deletions lib/faker/blockchain/tezos.rb
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,34 @@ def signature
encode_tz(:edsig, 64)
end

##
# Produces a random Tezos public key
#
# @return [String]
#
# @example
# Faker::Blockchain::Tezos.public_key
# #=> "edpkuib9x8QXRc5nWwHUg7U1dXsVmaUrUNU5sX9pVEEvwbMVdfMCeq"
#
# @faker.version 2.15.2
def public_key
encode_tz(:edpk, 32)
end

##
# Produces a random Tezos public key
#
# @return [String]
#
# @example
# Faker::Blockchain::Tezos.secret_key
# #=> "edsk3HZCAGEGpzQPnQUwQeFY4ESanFhQCgLpKriQw8GHyhKCrjHawv"
#
# @faker.version 2.15.2
def secret_key
encode_tz(:edsk, 32)
end

protected

##
Expand Down
8 changes: 8 additions & 0 deletions test/faker/blockchain/test_tezos.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,14 @@ def test_signature
assert Faker::Blockchain::Tezos.signature.match(/^edsig[1-9A-Za-z][^OIl]{20,40}/)
end

def test_public_key
assert Faker::Blockchain::Tezos.public_key.match(/^edpk[1-9A-Za-z][^OIl]{20,40}/)
end

def test_secret_key
assert Faker::Blockchain::Tezos.secret_key.match(/^edsk[1-9A-Za-z][^OIl]{20,40}/)
end

def test_deterministic_contract
Faker::Config.random = Random.new(42)
v = Faker::Blockchain::Tezos.contract
Expand Down

0 comments on commit e6604d0

Please sign in to comment.