From 45a20cd2999ed0a4976a159393603ec949227984 Mon Sep 17 00:00:00 2001 From: classicalliu Date: Thu, 2 Aug 2018 15:46:32 +0800 Subject: [PATCH] remove test dir --- .travis.yml | 1 - test/application_system_test_case.rb | 5 - test/controllers/.keep | 0 .../controllers/api/blocks_controller_test.rb | 7 - .../api/statistics_controller_test.rb | 7 - .../api/transactions_controller_test.rb | 7 - test/fixtures/.keep | 0 test/fixtures/balances.yml | 6 - test/fixtures/blocks.yml | 6 - test/fixtures/files/.keep | 0 test/fixtures/meta_data.yml | 7 - test/fixtures/transactions.yml | 6 - test/helpers/.keep | 0 test/integration/.keep | 0 test/mailers/.keep | 0 test/models/.keep | 0 test/models/abi_test.rb | 7 - test/models/balance_test.rb | 7 - test/models/block_test.rb | 7 - test/models/cita_sync/api_test.rb | 43 ---- test/models/cita_sync/persist_test.rb | 201 ------------------ test/models/meta_data_test.rb | 7 - test/models/transaction_test.rb | 7 - test/system/.keep | 0 test/test_helper.rb | 28 --- 25 files changed, 359 deletions(-) delete mode 100644 test/application_system_test_case.rb delete mode 100644 test/controllers/.keep delete mode 100644 test/controllers/api/blocks_controller_test.rb delete mode 100644 test/controllers/api/statistics_controller_test.rb delete mode 100644 test/controllers/api/transactions_controller_test.rb delete mode 100644 test/fixtures/.keep delete mode 100644 test/fixtures/balances.yml delete mode 100644 test/fixtures/blocks.yml delete mode 100644 test/fixtures/files/.keep delete mode 100644 test/fixtures/meta_data.yml delete mode 100644 test/fixtures/transactions.yml delete mode 100644 test/helpers/.keep delete mode 100644 test/integration/.keep delete mode 100644 test/mailers/.keep delete mode 100644 test/models/.keep delete mode 100644 test/models/abi_test.rb delete mode 100644 test/models/balance_test.rb delete mode 100644 test/models/block_test.rb delete mode 100644 test/models/cita_sync/api_test.rb delete mode 100644 test/models/cita_sync/persist_test.rb delete mode 100644 test/models/meta_data_test.rb delete mode 100644 test/models/transaction_test.rb delete mode 100644 test/system/.keep delete mode 100644 test/test_helper.rb diff --git a/.travis.yml b/.travis.yml index 624c8cf..16d1f23 100644 --- a/.travis.yml +++ b/.travis.yml @@ -38,5 +38,4 @@ install: script: - bundle exec rails db:migrate - - bundle exec rails test - bundle exec rails spec diff --git a/test/application_system_test_case.rb b/test/application_system_test_case.rb deleted file mode 100644 index d19212a..0000000 --- a/test/application_system_test_case.rb +++ /dev/null @@ -1,5 +0,0 @@ -require "test_helper" - -class ApplicationSystemTestCase < ActionDispatch::SystemTestCase - driven_by :selenium, using: :chrome, screen_size: [1400, 1400] -end diff --git a/test/controllers/.keep b/test/controllers/.keep deleted file mode 100644 index e69de29..0000000 diff --git a/test/controllers/api/blocks_controller_test.rb b/test/controllers/api/blocks_controller_test.rb deleted file mode 100644 index b7117ad..0000000 --- a/test/controllers/api/blocks_controller_test.rb +++ /dev/null @@ -1,7 +0,0 @@ -require 'test_helper' - -class Api::BlocksControllerTest < ActionDispatch::IntegrationTest - # test "the truth" do - # assert true - # end -end diff --git a/test/controllers/api/statistics_controller_test.rb b/test/controllers/api/statistics_controller_test.rb deleted file mode 100644 index b5237b4..0000000 --- a/test/controllers/api/statistics_controller_test.rb +++ /dev/null @@ -1,7 +0,0 @@ -require 'test_helper' - -class Api::StatisticsControllerTest < ActionDispatch::IntegrationTest - # test "the truth" do - # assert true - # end -end diff --git a/test/controllers/api/transactions_controller_test.rb b/test/controllers/api/transactions_controller_test.rb deleted file mode 100644 index b42c438..0000000 --- a/test/controllers/api/transactions_controller_test.rb +++ /dev/null @@ -1,7 +0,0 @@ -require 'test_helper' - -class Api::TransactionsControllerTest < ActionDispatch::IntegrationTest - # test "the truth" do - # assert true - # end -end diff --git a/test/fixtures/.keep b/test/fixtures/.keep deleted file mode 100644 index e69de29..0000000 diff --git a/test/fixtures/balances.yml b/test/fixtures/balances.yml deleted file mode 100644 index d5dce1b..0000000 --- a/test/fixtures/balances.yml +++ /dev/null @@ -1,6 +0,0 @@ -# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html - -# This model initially had no columns defined. If you add columns to the -# model remove the '{}' from the fixture names and add the columns immediately -# below each fixture, per the syntax in the comments below -# diff --git a/test/fixtures/blocks.yml b/test/fixtures/blocks.yml deleted file mode 100644 index d5dce1b..0000000 --- a/test/fixtures/blocks.yml +++ /dev/null @@ -1,6 +0,0 @@ -# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html - -# This model initially had no columns defined. If you add columns to the -# model remove the '{}' from the fixture names and add the columns immediately -# below each fixture, per the syntax in the comments below -# diff --git a/test/fixtures/files/.keep b/test/fixtures/files/.keep deleted file mode 100644 index e69de29..0000000 diff --git a/test/fixtures/meta_data.yml b/test/fixtures/meta_data.yml deleted file mode 100644 index f0e9bbd..0000000 --- a/test/fixtures/meta_data.yml +++ /dev/null @@ -1,7 +0,0 @@ -# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html - -# This model initially had no columns defined. If you add columns to the -# model remove the '{}' from the fixture names and add the columns immediately -# below each fixture, per the syntax in the comments below -# - diff --git a/test/fixtures/transactions.yml b/test/fixtures/transactions.yml deleted file mode 100644 index d5dce1b..0000000 --- a/test/fixtures/transactions.yml +++ /dev/null @@ -1,6 +0,0 @@ -# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html - -# This model initially had no columns defined. If you add columns to the -# model remove the '{}' from the fixture names and add the columns immediately -# below each fixture, per the syntax in the comments below -# diff --git a/test/helpers/.keep b/test/helpers/.keep deleted file mode 100644 index e69de29..0000000 diff --git a/test/integration/.keep b/test/integration/.keep deleted file mode 100644 index e69de29..0000000 diff --git a/test/mailers/.keep b/test/mailers/.keep deleted file mode 100644 index e69de29..0000000 diff --git a/test/models/.keep b/test/models/.keep deleted file mode 100644 index e69de29..0000000 diff --git a/test/models/abi_test.rb b/test/models/abi_test.rb deleted file mode 100644 index 7cc4411..0000000 --- a/test/models/abi_test.rb +++ /dev/null @@ -1,7 +0,0 @@ -require 'test_helper' - -class AbiTest < ActiveSupport::TestCase - # test "the truth" do - # assert true - # end -end diff --git a/test/models/balance_test.rb b/test/models/balance_test.rb deleted file mode 100644 index f9e9e05..0000000 --- a/test/models/balance_test.rb +++ /dev/null @@ -1,7 +0,0 @@ -require 'test_helper' - -class BalanceTest < ActiveSupport::TestCase - # test "the truth" do - # assert true - # end -end diff --git a/test/models/block_test.rb b/test/models/block_test.rb deleted file mode 100644 index 2a028c7..0000000 --- a/test/models/block_test.rb +++ /dev/null @@ -1,7 +0,0 @@ -require 'test_helper' - -class BlockTest < ActiveSupport::TestCase - # test "the truth" do - # assert true - # end -end diff --git a/test/models/cita_sync/api_test.rb b/test/models/cita_sync/api_test.rb deleted file mode 100644 index 860054e..0000000 --- a/test/models/cita_sync/api_test.rb +++ /dev/null @@ -1,43 +0,0 @@ -require 'test_helper' - -class CitaSync::ApiTest < ActiveSupport::TestCase - setup do - stub_request_wrapper("blockNumber", nil, "0x7781") - - result = { - "version" => 0, - "hash" => "0xa18f9c384107d9a4fcd2fae656415928bd921047519fea5650cba394f6b6142b", - "header" => { - "timestamp" => 1528702183591, - "prevHash" => "0xda8991b9cbc7f7bc56e94abbd7056dffc501603a4ab6bcaa7e2ed08b3e58e554", - "number" => "0x1", - "stateRoot" => "0x048523e8326427968d05673210cc77a8f76e60d0b9170d1bdc1d49c131da9c85", - "transactionsRoot" => "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421", - "receiptsRoot" => "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421", - "gasUsed" => "0x0", - "proof" => nil, - "proposer" => "0x91827976af27e1fd405469b00dc8d3b0ea2203f6" - }, - "body" => { - "transactions" => [] - } - } - - stub_request_wrapper("getBlockByNumber", ["0x1", true], result) - end - - test "cita_blockNumber" do - resp = CitaSync::Api.block_number - - assert resp["jsonrpc"], "2.0" - assert resp["id"], 83 - assert resp["result"], "0x7781" - end - - test "cita_getBlockByNumber" do - resp = CitaSync::Api.get_block_by_number("0x1", true) - - assert resp.dig("result", "hash"), "0xa18f9c384107d9a4fcd2fae656415928bd921047519fea5650cba394f6b6142b" - end - -end diff --git a/test/models/cita_sync/persist_test.rb b/test/models/cita_sync/persist_test.rb deleted file mode 100644 index e3a7207..0000000 --- a/test/models/cita_sync/persist_test.rb +++ /dev/null @@ -1,201 +0,0 @@ -require 'test_helper' - -class CitaSync::ApiTest < ActiveSupport::TestCase - def mock_block_number - stub_request_wrapper("blockNumber", nil, "0x1") - end - - def mock_get_block_by_number_zero - result = { - "version": 0, - "hash": "0x542ff7aeccbd2b269c36e134e3c0a1be103b389dc9ed90a55c1d506e00b77b81", - "header": { - "timestamp": 1529377997246, - "prevHash": "0x0000000000000000000000000000000000000000000000000000000000000000", - "number": "0x0", - "stateRoot": "0x9b3609aca48d23cadcbab0d768fa0d2187807a23f4ae19742db128a9a64f3bfc", - "transactionsRoot": "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421", - "receiptsRoot": "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421", - "gasUsed": "0x0", - "proof": nil, - "proposer": "0x0000000000000000000000000000000000000000" - }, - "body": { - "transactions": [] - } - } - - stub_request_wrapper("getBlockByNumber", ["0x0", true], result) - end - - def mock_get_block_by_number_one - result = { - "version" => 0, - "hash" => "0xa18f9c384107d9a4fcd2fae656415928bd921047519fea5650cba394f6b6142b", - "header" => { - "timestamp" => 1528702183591, - "prevHash" => "0xda8991b9cbc7f7bc56e94abbd7056dffc501603a4ab6bcaa7e2ed08b3e58e554", - "number" => "0x1", - "stateRoot" => "0x048523e8326427968d05673210cc77a8f76e60d0b9170d1bdc1d49c131da9c85", - "transactionsRoot" => "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421", - "receiptsRoot" => "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421", - "gasUsed" => "0x0", - "proof" => nil, - "proposer" => "0x91827976af27e1fd405469b00dc8d3b0ea2203f6" - }, - "body" => { - "transactions" => [ - { - "hash": "0xee969624a87a51fc4acc958a3bb83ca32539ee54ebb4215668fe1029eeab59d4", - "content": "0x0a1d186420e7192a14627306090abab3a6e1400e9345bc60c78a8bef57380112410422a3159ad636e779ad530dfca184ed3f88183f1be05be6dda4ad820791b0798fe1382cb0396c3563cc6d41f743722ea3918beb8fd343079c2b79eb085f699401" - } - ] - } - } - - stub_request_wrapper("getBlockByNumber", ["0x1", true], result) - end - - def mock_get_transaction - result = { - "hash": "0xee969624a87a51fc4acc958a3bb83ca32539ee54ebb4215668fe1029eeab59d4", - "content": "0x0a1d186420e7192a14627306090abab3a6e1400e9345bc60c78a8bef57380112410422a3159ad636e779ad530dfca184ed3f88183f1be05be6dda4ad820791b0798fe1382cb0396c3563cc6d41f743722ea3918beb8fd343079c2b79eb085f699401", - "blockNumber": "0x1", - "blockHash": "0xa18f9c384107d9a4fcd2fae656415928bd921047519fea5650cba394f6b6142b", - "index": "0x0" - } - - stub_request_wrapper("getTransaction", ["0xee969624a87a51fc4acc958a3bb83ca32539ee54ebb4215668fe1029eeab59d4"], result) - end - - def mock_get_transaction_receipt - result = { - "contractAddress": "0x89be88054e2ee94911549be521ab1241c7700a1b", - "gasUsed": "0x2d483" - } - - stub_request_wrapper("getTransactionReceipt", ["0xee969624a87a51fc4acc958a3bb83ca32539ee54ebb4215668fe1029eeab59d4"], result) - end - - def mock_get_meta_data - result = { - "blockInterval": 3000, - "chainId": 1, - "chainName": "test-chain", - "genesisTimestamp": 1530164125967, - "operator": "test-operator", - "tokenAvatar": "https://avatars1.githubusercontent.com/u/35361817", - "tokenName": "Nervos", - "tokenSymbol": "NOS", - "validators": [ - "0x365d339609728590ec0803a73b95c24fde718846", - "0xf1551b918a4f43c1b72d322b8f91d4caebc249de", - "0x6e66c49ed7cf07754cd5794a43d41704b7c1e217", - "0xb4061fa8e18654a7d51fef3866d45bb1dc688717" - ], - "website": "https://www.example.com" - } - - stub_request_wrapper("getMetaData", ["0x0"], result) - stub_request_wrapper("getMetaData", ["0x1"], result) - end - - def mock_get_balance - result = "0x0" - - stub_request_wrapper("getBalance", ["0x0dcf740686de1fe9e9faa4b519767a872e1cf69e", "0x0"], result) - end - - def mock_get_abi - result = "0x" - - stub_request_wrapper("getAbi", ["0x0dcf740686de1fe9e9faa4b519767a872e1cf69e", "0x0"], result) - end - - setup do - mock_block_number - mock_get_block_by_number_zero - mock_get_block_by_number_one - mock_get_transaction - mock_get_transaction_receipt - mock_get_meta_data - mock_get_balance - mock_get_abi - end - - test "save_block" do - block = CitaSync::Persist.save_block("0x1") - assert block.block_number, 1 - end - - def hash - "0xee969624a87a51fc4acc958a3bb83ca32539ee54ebb4215668fe1029eeab59d4" - end - - test "save transaction" do - block = CitaSync::Persist.save_block("0x1") - transaction = CitaSync::Persist.save_transaction(hash) - assert transaction.cita_hash, hash - assert transaction.errors.full_messages.empty? - assert block, transaction.block - end - - test "save transaction with block param" do - block = CitaSync::Persist.save_block("0x1") - transaction = CitaSync::Persist.save_transaction(hash, block) - assert transaction.cita_hash, hash - assert transaction.errors.full_messages.empty? - assert block, transaction.block - end - - test "save transaction without block will be fail" do - transaction = CitaSync::Persist.save_transaction(hash) - assert_not transaction.errors.full_messages.empty? - end - - test "save meta data" do - CitaSync::Persist.save_block("0x0") - meta_data = CitaSync::Persist.save_meta_data("0x0") - ap "----------------------- meta data --------------------" - ap meta_data - assert meta_data.errors.full_messages.empty? - end - - test "save balance" do - balance, = CitaSync::Persist.save_balance("0x0dcf740686de1fe9e9faa4b519767a872e1cf69e", "0x0") - ap balance - assert balance.errors.full_messages.empty? - end - - test "save abi" do - abi, = CitaSync::Persist.save_abi("0x0dcf740686de1fe9e9faa4b519767a872e1cf69e", "0x0") - ap abi - assert abi.errors.full_messages.empty? - end - - test "save block with infos" do - CitaSync::Persist.save_block_with_infos("0x1") - block = Block.first - transaction = Transaction.first - meta_data = MetaData.first - assert Block.count, 1 - assert Transaction.count, 1 - assert transaction.block_number, block.header["number"] - assert transaction.block, block - assert meta_data.block, block - end - - test "save blocks with transactions with empty db" do - CitaSync::Persist.save_blocks_with_infos - assert Block.count, 2 - assert Transaction.count, 1 - assert MetaData.count, Block.count - end - - test "save blocks with transactions with exist block" do - CitaSync::Persist.save_block("0x0") - CitaSync::Persist.save_blocks_with_infos - assert Block.count, 2 - assert Transaction.count, 1 - end -end diff --git a/test/models/meta_data_test.rb b/test/models/meta_data_test.rb deleted file mode 100644 index f0cc40c..0000000 --- a/test/models/meta_data_test.rb +++ /dev/null @@ -1,7 +0,0 @@ -require 'test_helper' - -class MetaDataTest < ActiveSupport::TestCase - # test "the truth" do - # assert true - # end -end diff --git a/test/models/transaction_test.rb b/test/models/transaction_test.rb deleted file mode 100644 index f2b87fe..0000000 --- a/test/models/transaction_test.rb +++ /dev/null @@ -1,7 +0,0 @@ -require 'test_helper' - -class TransactionTest < ActiveSupport::TestCase - # test "the truth" do - # assert true - # end -end diff --git a/test/system/.keep b/test/system/.keep deleted file mode 100644 index e69de29..0000000 diff --git a/test/test_helper.rb b/test/test_helper.rb deleted file mode 100644 index a9b5078..0000000 --- a/test/test_helper.rb +++ /dev/null @@ -1,28 +0,0 @@ -ENV['RAILS_ENV'] ||= 'test' -require_relative '../config/environment' -require 'rails/test_help' -require 'webmock/minitest' - -class ActiveSupport::TestCase - # Setup all fixtures in test/fixtures/*.yml for all tests in alphabetical order. - fixtures :all - - # Add more helper methods to be used by all tests here... -end - -module MockHelper - def stub_request_wrapper(method, params, result) - include_hash = if params.nil? - { method: method } - else - { method: method, params: params } - end - stub_request(:post, "www.cita.com"). - with(body: hash_including(include_hash), headers: { "Content-Type": "application/json" }). - to_return(status: 200, body: { jsonrpc: "2.0", id: 83, result: result }.to_json) - end -end - -class ActiveSupport::TestCase - include MockHelper -end