diff --git a/.env b/.env index c1eaff7..882d6fb 100644 --- a/.env +++ b/.env @@ -1,6 +1,10 @@ FIRST_CHAIN_NAME=YOUR_CHAIN_NAME FIRST_CHAIN_MAINTAINER=YOUR_NAME +FIRST_USER_NAME=YOUR_FIRST_USERNAME +FIRST_USER_EMAIL=firstuser@email.com +FIRST_USER_PASSWORD=YOUR_FIRST_USER_PASSWORD CONTRACTS_LIMIT=2 SIGNATURES_LIMIT=5 REDIS_URL=redis://redis:6379 ENV_MACHINE=docker + diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md new file mode 100644 index 0000000..dd84ea7 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/bug_report.md @@ -0,0 +1,38 @@ +--- +name: Bug report +about: Create a report to help us improve +title: '' +labels: '' +assignees: '' + +--- + +**Describe the bug** +A clear and concise description of what the bug is. + +**To Reproduce** +Steps to reproduce the behavior: +1. Go to '...' +2. Click on '....' +3. Scroll down to '....' +4. See error + +**Expected behavior** +A clear and concise description of what you expected to happen. + +**Screenshots** +If applicable, add screenshots to help explain your problem. + +**Desktop (please complete the following information):** + - OS: [e.g. iOS] + - Browser [e.g. chrome, safari] + - Version [e.g. 22] + +**Smartphone (please complete the following information):** + - Device: [e.g. iPhone6] + - OS: [e.g. iOS8.1] + - Browser [e.g. stock browser, safari] + - Version [e.g. 22] + +**Additional context** +Add any other context about the problem here. diff --git a/.github/ISSUE_TEMPLATE/feature_request.md b/.github/ISSUE_TEMPLATE/feature_request.md new file mode 100644 index 0000000..bbcbbe7 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/feature_request.md @@ -0,0 +1,20 @@ +--- +name: Feature request +about: Suggest an idea for this project +title: '' +labels: '' +assignees: '' + +--- + +**Is your feature request related to a problem? Please describe.** +A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] + +**Describe the solution you'd like** +A clear and concise description of what you want to happen. + +**Describe alternatives you've considered** +A clear and concise description of any alternative solutions or features you've considered. + +**Additional context** +Add any other context or screenshots about the feature request here. diff --git a/Dockerfile b/Dockerfile index 3ec26c0..2ec4410 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,5 +1,5 @@ # syntax=docker/dockerfile:1 -FROM ruby:3.0.3 +FROM ruby:3.2.0 RUN apt-get update -qq && apt-get install -y nodejs postgresql-client WORKDIR /myapp COPY Gemfile /myapp/Gemfile diff --git a/Gemfile b/Gemfile index ab9334b..e5fef90 100644 --- a/Gemfile +++ b/Gemfile @@ -1,7 +1,7 @@ source "https://rubygems.org" git_source(:github) { |repo| "https://github.com/#{repo}.git" } -ruby "3.0.3" +ruby "3.2.0" # Bundle edge Rails instead: gem "rails", github: "rails/rails", branch: "main" gem "rails", "~> 7.0" diff --git a/Gemfile.lock b/Gemfile.lock index 60e1f4b..aaceb84 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,69 +1,69 @@ GEM remote: https://rubygems.org/ specs: - actioncable (7.0.4) - actionpack (= 7.0.4) - activesupport (= 7.0.4) + actioncable (7.0.4.1) + actionpack (= 7.0.4.1) + activesupport (= 7.0.4.1) nio4r (~> 2.0) websocket-driver (>= 0.6.1) - actionmailbox (7.0.4) - actionpack (= 7.0.4) - activejob (= 7.0.4) - activerecord (= 7.0.4) - activestorage (= 7.0.4) - activesupport (= 7.0.4) + actionmailbox (7.0.4.1) + actionpack (= 7.0.4.1) + activejob (= 7.0.4.1) + activerecord (= 7.0.4.1) + activestorage (= 7.0.4.1) + activesupport (= 7.0.4.1) mail (>= 2.7.1) net-imap net-pop net-smtp - actionmailer (7.0.4) - actionpack (= 7.0.4) - actionview (= 7.0.4) - activejob (= 7.0.4) - activesupport (= 7.0.4) + actionmailer (7.0.4.1) + actionpack (= 7.0.4.1) + actionview (= 7.0.4.1) + activejob (= 7.0.4.1) + activesupport (= 7.0.4.1) mail (~> 2.5, >= 2.5.4) net-imap net-pop net-smtp rails-dom-testing (~> 2.0) - actionpack (7.0.4) - actionview (= 7.0.4) - activesupport (= 7.0.4) + actionpack (7.0.4.1) + actionview (= 7.0.4.1) + activesupport (= 7.0.4.1) rack (~> 2.0, >= 2.2.0) rack-test (>= 0.6.3) rails-dom-testing (~> 2.0) rails-html-sanitizer (~> 1.0, >= 1.2.0) - actiontext (7.0.4) - actionpack (= 7.0.4) - activerecord (= 7.0.4) - activestorage (= 7.0.4) - activesupport (= 7.0.4) + actiontext (7.0.4.1) + actionpack (= 7.0.4.1) + activerecord (= 7.0.4.1) + activestorage (= 7.0.4.1) + activesupport (= 7.0.4.1) globalid (>= 0.6.0) nokogiri (>= 1.8.5) - actionview (7.0.4) - activesupport (= 7.0.4) + actionview (7.0.4.1) + activesupport (= 7.0.4.1) builder (~> 3.1) erubi (~> 1.4) rails-dom-testing (~> 2.0) rails-html-sanitizer (~> 1.1, >= 1.2.0) - activejob (7.0.4) - activesupport (= 7.0.4) + activejob (7.0.4.1) + activesupport (= 7.0.4.1) globalid (>= 0.3.6) - activemodel (7.0.4) - activesupport (= 7.0.4) - activerecord (7.0.4) - activemodel (= 7.0.4) - activesupport (= 7.0.4) + activemodel (7.0.4.1) + activesupport (= 7.0.4.1) + activerecord (7.0.4.1) + activemodel (= 7.0.4.1) + activesupport (= 7.0.4.1) activerecord-import (1.4.1) activerecord (>= 4.2) - activestorage (7.0.4) - actionpack (= 7.0.4) - activejob (= 7.0.4) - activerecord (= 7.0.4) - activesupport (= 7.0.4) + activestorage (7.0.4.1) + actionpack (= 7.0.4.1) + activejob (= 7.0.4.1) + activerecord (= 7.0.4.1) + activesupport (= 7.0.4.1) marcel (~> 1.0) mini_mime (>= 1.1.0) - activesupport (7.0.4) + activesupport (7.0.4.1) concurrent-ruby (~> 1.0, >= 1.0.2) i18n (>= 1.6, < 2) minitest (>= 5.1) @@ -73,10 +73,10 @@ GEM ast (2.4.2) bcrypt (3.1.18) bindex (0.8.1) - bootsnap (1.13.0) + bootsnap (1.15.0) msgpack (~> 1.2) builder (3.2.4) - capybara (3.37.1) + capybara (3.38.0) addressable matrix mini_mime (>= 0.1.3) @@ -85,7 +85,6 @@ GEM rack-test (>= 0.6.3) regexp_parser (>= 1.5, < 3.0) xpath (~> 3.2) - childprocess (4.1.0) concurrent-ruby (1.1.10) connection_pool (2.3.0) crass (1.0.6) @@ -93,9 +92,8 @@ GEM activerecord (>= 5.a) database_cleaner-core (~> 2.0.0) database_cleaner-core (2.0.1) - debug (1.6.2) - irb (>= 1.3.6) - reline (>= 0.3.1) + date (3.3.3) + debug (1.7.1) devise (4.8.1) bcrypt (~> 3.0) orm_adapter (~> 0.1) @@ -104,7 +102,7 @@ GEM warden (~> 1.2.3) diff-lcs (1.5.0) docile (1.4.0) - erubi (1.11.0) + erubi (1.12.0) factory_bot (6.2.1) activesupport (>= 5.0.0) factory_bot_rails (6.2.0) @@ -112,68 +110,69 @@ GEM railties (>= 5.0.0) faker (2.23.0) i18n (>= 1.8.11, < 2) - globalid (1.0.0) + globalid (1.0.1) activesupport (>= 5.0) i18n (1.12.0) concurrent-ruby (~> 1.0) importmap-rails (1.1.5) actionpack (>= 6.0.0) railties (>= 6.0.0) - io-console (0.5.11) - irb (1.4.2) - reline (>= 0.3.0) jbuilder (2.11.5) actionview (>= 5.0.0) activesupport (>= 5.0.0) - json (2.5.1) - loofah (2.19.0) + json (2.6.3) + loofah (2.19.1) crass (~> 1.0.2) nokogiri (>= 1.5.9) - mail (2.7.1) + mail (2.8.0.1) mini_mime (>= 0.1.1) + net-imap + net-pop + net-smtp marcel (1.0.2) matrix (0.4.2) method_source (1.0.0) mini_mime (1.1.2) - minitest (5.16.3) + minitest (5.17.0) msgpack (1.6.0) - net-imap (0.3.1) + net-imap (0.3.4) + date net-protocol net-pop (0.1.2) net-protocol - net-protocol (0.1.3) + net-protocol (0.2.1) timeout - net-smtp (0.3.2) + net-smtp (0.3.3) net-protocol nio4r (2.5.8) - nokogiri (1.13.9-x86_64-linux) + nokogiri (1.14.0-x86_64-linux) racc (~> 1.4) orm_adapter (0.5.0) parallel (1.22.1) - parser (3.1.2.1) + parser (3.2.0.0) ast (~> 2.4.1) - pg (1.4.4) - public_suffix (5.0.0) + pg (1.4.5) + public_suffix (5.0.1) puma (5.6.5) nio4r (~> 2.0) - racc (1.6.0) - rack (2.2.4) + racc (1.6.2) + rack (2.2.6.2) rack-test (2.0.2) rack (>= 1.3) - rails (7.0.4) - actioncable (= 7.0.4) - actionmailbox (= 7.0.4) - actionmailer (= 7.0.4) - actionpack (= 7.0.4) - actiontext (= 7.0.4) - actionview (= 7.0.4) - activejob (= 7.0.4) - activemodel (= 7.0.4) - activerecord (= 7.0.4) - activestorage (= 7.0.4) - activesupport (= 7.0.4) + rails (7.0.4.1) + actioncable (= 7.0.4.1) + actionmailbox (= 7.0.4.1) + actionmailer (= 7.0.4.1) + actionpack (= 7.0.4.1) + actiontext (= 7.0.4.1) + actionview (= 7.0.4.1) + activejob (= 7.0.4.1) + activemodel (= 7.0.4.1) + activerecord (= 7.0.4.1) + activestorage (= 7.0.4.1) + activesupport (= 7.0.4.1) bundler (>= 1.15.0) - railties (= 7.0.4) + railties (= 7.0.4.1) rails-controller-testing (1.0.5) actionpack (>= 5.0.1.rc1) actionview (>= 5.0.1.rc1) @@ -181,11 +180,11 @@ GEM rails-dom-testing (2.0.3) activesupport (>= 4.2.0) nokogiri (>= 1.6) - rails-html-sanitizer (1.4.3) - loofah (~> 2.3) - railties (7.0.4) - actionpack (= 7.0.4) - activesupport (= 7.0.4) + rails-html-sanitizer (1.4.4) + loofah (~> 2.19, >= 2.19.1) + railties (7.0.4.1) + actionpack (= 7.0.4.1) + activesupport (= 7.0.4.1) method_source rake (>= 12.2) thor (~> 1.0) @@ -193,22 +192,20 @@ GEM rainbow (3.1.1) rake (13.0.6) redis (4.8.0) - regexp_parser (2.6.0) - reline (0.3.1) - io-console (~> 0.5) + regexp_parser (2.6.2) responders (3.0.1) actionpack (>= 5.0) railties (>= 5.0) rexml (3.2.5) - rspec-core (3.11.0) - rspec-support (~> 3.11.0) - rspec-expectations (3.11.1) + rspec-core (3.12.0) + rspec-support (~> 3.12.0) + rspec-expectations (3.12.2) diff-lcs (>= 1.2.0, < 2.0) - rspec-support (~> 3.11.0) - rspec-mocks (3.11.1) + rspec-support (~> 3.12.0) + rspec-mocks (3.12.3) diff-lcs (>= 1.2.0, < 2.0) - rspec-support (~> 3.11.0) - rspec-rails (6.0.0) + rspec-support (~> 3.12.0) + rspec-rails (6.0.1) actionpack (>= 6.1) activesupport (>= 6.1) railties (>= 6.1) @@ -216,39 +213,41 @@ GEM rspec-expectations (~> 3.11) rspec-mocks (~> 3.11) rspec-support (~> 3.11) - rspec-support (3.11.1) - rubocop (1.36.0) + rspec-support (3.12.0) + rubocop (1.43.0) json (~> 2.3) parallel (~> 1.10) - parser (>= 3.1.2.1) + parser (>= 3.2.0.0) rainbow (>= 2.2.2, < 4.0) regexp_parser (>= 1.8, < 3.0) rexml (>= 3.2.5, < 4.0) - rubocop-ast (>= 1.20.1, < 2.0) + rubocop-ast (>= 1.24.1, < 2.0) ruby-progressbar (~> 1.7) - unicode-display_width (>= 1.4.0, < 3.0) - rubocop-ast (1.22.0) + unicode-display_width (>= 2.4.0, < 3.0) + rubocop-ast (1.24.1) parser (>= 3.1.1.0) - rubocop-rails (2.16.1) + rubocop-capybara (2.17.0) + rubocop (~> 1.41) + rubocop-rails (2.17.4) activesupport (>= 4.2.0) rack (>= 1.1) rubocop (>= 1.33.0, < 2.0) - rubocop-rspec (2.13.2) + rubocop-rspec (2.18.1) rubocop (~> 1.33) + rubocop-capybara (~> 2.17) ruby-progressbar (1.11.0) rubyzip (2.3.2) - selenium-webdriver (4.5.0) - childprocess (>= 0.5, < 5.0) + selenium-webdriver (4.7.1) rexml (~> 3.2, >= 3.2.5) rubyzip (>= 1.2.2, < 3.0) websocket (~> 1.0) - shoulda-matchers (5.2.0) + shoulda-matchers (5.3.0) activesupport (>= 5.2.0) - sidekiq (6.5.7) - connection_pool (>= 2.2.5) + sidekiq (6.5.8) + connection_pool (>= 2.2.5, < 3) rack (~> 2.0) redis (>= 4.5.0, < 5) - simplecov (0.21.2) + simplecov (0.22.0) docile (~> 1.1) simplecov-html (~> 0.11) simplecov_json_formatter (~> 0.1) @@ -261,28 +260,28 @@ GEM actionpack (>= 3.1) railties (>= 3.1) slim (>= 3.0, < 5.0) - sprockets (4.1.1) + sprockets (4.2.0) concurrent-ruby (~> 1.0) - rack (> 1, < 3) + rack (>= 2.2.4, < 4) sprockets-rails (3.4.2) actionpack (>= 5.2) activesupport (>= 5.2) sprockets (>= 3.0.0) - stimulus-rails (1.1.0) + stimulus-rails (1.2.1) railties (>= 6.0.0) - tailwindcss-rails (2.0.14-x86_64-linux) + tailwindcss-rails (2.0.21-x86_64-linux) railties (>= 6.0.0) temple (0.8.2) thor (1.2.1) tilt (2.0.11) - timeout (0.3.0) - turbo-rails (1.3.1) + timeout (0.3.1) + turbo-rails (1.3.2) actionpack (>= 6.0.0) activejob (>= 6.0.0) railties (>= 6.0.0) tzinfo (2.0.5) concurrent-ruby (~> 1.0) - unicode-display_width (2.3.0) + unicode-display_width (2.4.2) warden (1.2.9) rack (>= 2.0.9) web-console (4.2.0) @@ -300,7 +299,7 @@ GEM websocket-extensions (0.1.5) xpath (3.2.0) nokogiri (~> 1.8) - zeitwerk (2.6.1) + zeitwerk (2.6.6) PLATFORMS x86_64-linux @@ -337,7 +336,7 @@ DEPENDENCIES webdrivers (~> 5.2) RUBY VERSION - ruby 3.0.3p157 + ruby 3.2.0p0 BUNDLED WITH - 2.2.32 + 2.4.1 diff --git a/README.md b/README.md index 8e44b9c..59e295e 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# Outerspace Blockchain +# Outerspace Blockchain ### A Ruby implementation of web blockchain framework. #### Developed using TDD (Test Driven Development). @@ -12,11 +12,10 @@ #### Rspec is used to test the blockchain. -## Build Version: 0.1.7 +## Build Version: 0.1.9 ### Last Update: -#### Added Open Ticket Api Methods -#### Refactored some methods and tests -#### Removed coverage folder github repo +#### Edited Gemspec +#### Edited Readme ##### TODO ###### Add more tests ###### Add more features @@ -205,4 +204,4 @@ Bug reports and pull requests are welcome on GitHub at https://github.com/JesusG ## License The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT). -* [LICENSE](LICENSE) - MIT License \ No newline at end of file +* [LICENSE](LICENSE) - MIT License diff --git a/app/models/chain.rb b/app/models/chain.rb index 0bba614..8d7d5a9 100755 --- a/app/models/chain.rb +++ b/app/models/chain.rb @@ -1,10 +1,11 @@ # frozen_string_literal: true class Chain < ApplicationRecord - validates :name, presence: true, uniqueness: true, length: { maximum: 20 } + validates :name, presence: true, uniqueness: true, length: { maximum: 40 } validates :maintainer, presence: true, length: { maximum: 50 } validates :chain_version, presence: true, length: { maximum: 20 } validates :description, presence: true, length: { maximum: 1000 } has_many :blocks, dependent: :destroy end + diff --git a/config/initializers/sidekiq.rb b/config/initializers/sidekiq.rb index ae17d27..58d16a7 100644 --- a/config/initializers/sidekiq.rb +++ b/config/initializers/sidekiq.rb @@ -1 +1 @@ -Sidekiq.strict_args! \ No newline at end of file +# Sidekiq.strict_args! diff --git a/db/seeds.rb b/db/seeds.rb index 481b957..9901c77 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -4,6 +4,7 @@ def seed_exec create_first_chain create_acceptable_word_lists create_first_block + create_first_user end def dev_seed_exec @@ -19,16 +20,13 @@ def dev_seed_exec end def create_first_chain - Chain.create( + chain = Chain.find_or_create_by( name: ENV["FIRST_CHAIN_NAME"], maintainer: ENV["FIRST_CHAIN_MAINTAINER"], chain_version: "0.0.1", description: "This is a blockchain project generated with outerspace-blockchain." ) - - puts "Chain created" - puts "Chain name: #{ENV["FIRST_CHAIN_NAME"]}" - puts "Chain maintainer: #{ENV["FIRST_CHAIN_MAINTAINER"]}" + chain.present? ? puts("First chain OK") : puts("Chain seed error") end def create_acceptable_word_lists @@ -36,7 +34,7 @@ def create_acceptable_word_lists create_acceptable_symbol_sequences create_acceptable_number_sequences end - + def create_acceptable_words word_list = %w[the of and to a in is you that it he @@ -93,7 +91,7 @@ def create_acceptable_number_sequences def create_first_block - Block.create( + block = Block.find_or_create_by( chain: Chain.first, previous_hash: "0000000000000000000000000000000000000000000000000000000000000000", block_data: "This is the first block of the blockchain.", @@ -101,10 +99,8 @@ def create_first_block connections: 0, contracts_count: 0, contracts_limit: ENV["CONTRACTS_LIMIT"].to_i, - # timestamp: Time.now ) - - puts "First block created" + block.present? ? puts("First block OK") : puts("Block seed error") end def create_test_users @@ -127,6 +123,17 @@ def create_test_users end end +def create_first_user + if User.find_by(email: ENV["FIRST_USER_EMAIL"], username: ENV["FIRST_USER_USERNAME"]) + puts "First user already exists" + else + User.create( + email: ENV["FIRST_USER_EMAIL"], username: ENV["FIRST_USER_USERNAME"], password: ENV["FIRST_USER_PASSWORD"], password_confirmation: ENV["FIRST_USER_PASSWORD"] + ) + puts "First user created" + end +end + if Rails.env.development? dev_seed_exec else diff --git a/docker-compose.yml b/docker-compose.yml index 791273f..6ef68e1 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -27,9 +27,9 @@ services: - redis - db - sidekiq - - chrome env_file: - .env + tty: true sidekiq: build: . command: bundle exec sidekiq -C config/sidekiq.yml @@ -40,14 +40,14 @@ services: - db env_file: - .env - chrome: - image: selenium/standalone-chrome - ports: - - "4444:4444" - depends_on: - - sidekiq - volumes: - - /dev/shm:/dev/shm + # chrome: + # image: selenium/standalone-chrome + # ports: + # - "4444:4444" + # depends_on: + # - sidekiq + # volumes: + # - /dev/shm:/dev/shm volumes: redis: postgres: \ No newline at end of file diff --git a/outerspace-blockchain.gemspec b/outerspace-blockchain.gemspec index 6ef5d9c..cb229fb 100644 --- a/outerspace-blockchain.gemspec +++ b/outerspace-blockchain.gemspec @@ -12,7 +12,7 @@ Gem::Specification.new do |spec| spec.description = "Blockchain implementation in Ruby using Rails and Docker" spec.homepage = "https://outerspace-blockchain.herokuapp.com/" spec.license = "MIT" - spec.required_ruby_version = ">= 3.0.3" + spec.required_ruby_version = ">= 3.2.0" spec.metadata["allowed_push_host"] = "https://rubygems.org"