diff --git a/.circleci/config.yml b/.circleci/config.yml deleted file mode 100644 index edbcd3d..0000000 --- a/.circleci/config.yml +++ /dev/null @@ -1,30 +0,0 @@ -version: 2.1 -jobs: - build: - docker: - - image: circleci/ruby:2.6.1 - environment: - RAILS_ENV: test - steps: - - checkout - - run: - name: Which bundler? - command: bundle -v - - - restore_cache: - keys: - - zilliqa{{ checksum "Gemfile.lock" }} - - zilliqa - - - run: - name: Install libsecp256k1-dev dependency - command: sudo apt-get update -y && sudo apt-get install -y libsecp256k1-dev - - - run: - name: Bundle Install - command: bundle install - - save_cache: - key: zilliqa{{ checksum "Gemfile.lock" }} - paths: - - vendor/bundle - - run: bundle exec rake test diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..128bc32 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,27 @@ +name: CI + +on: + pull_request: + types: [opened, labeled, reopened, synchronize] + push: + branches: [master] + +defaults: + run: + shell: bash + +jobs: + test: + runs-on: ubuntu-latest + name: test + steps: + - name: Setup Ruby + uses: ruby/setup-ruby@v1 + with: + ruby-version: 2.7.3 + rubygems: latest + bundler-cache: true + - uses: actions/checkout@v3 + - run: sudo apt-get update -y && sudo apt-get install -y libsecp256k1-dev + - run: bundle install + - run: bundle exec rake test diff --git a/Gemfile.lock b/Gemfile.lock index 6f237c4..1b1cad5 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -17,6 +17,8 @@ GEM eventmachine ffi scrypt + byebug (11.1.3) + coderay (1.1.3) eventmachine (1.2.7) faraday (2.7.10) faraday-net_http (>= 2.0, < 3.1) @@ -30,9 +32,16 @@ GEM jsonrpc-client (0.1.4) faraday multi_json (>= 1.1.0) - minitest (5.16.1) + method_source (1.0.0) + minitest (5.15.0) multi_json (1.15.0) pbkdf2-ruby (0.2.1) + pry (0.14.2) + coderay (~> 1.1) + method_source (~> 1.0) + pry-byebug (3.10.1) + byebug (~> 11.0) + pry (>= 0.13, < 0.15) rake (13.0.6) ruby-bitcoin-secp256k1 (0.5.2) ffi (>= 1.9.25) @@ -44,7 +53,8 @@ PLATFORMS ruby DEPENDENCIES - minitest (~> 5.0) + minitest (= 5.15) + pry-byebug (~> 3.10) rake (~> 13.0) zilliqa! diff --git a/lib/zilliqa/util/validator.rb b/lib/zilliqa/util/validator.rb index 92a4037..3875f42 100644 --- a/lib/zilliqa/util/validator.rb +++ b/lib/zilliqa/util/validator.rb @@ -22,16 +22,6 @@ def self.signature?(signature) m != nil end - # checksum_address? - # - # takes hex-encoded string and returns boolean if address is checksumed - # - # @param {string} address - # @returns {boolean} - def self.checksum_address?(address) - self.address?(address) && Zilliqa::Account::Wallet::to_checksum_address(address) == address - end - def self.bech32?(address) m = /^zil1[qpzry9x8gf2tvdw0s3jn54khce6mua7l]{38}/ =~ address m != nil diff --git a/test/account/transaction_test.rb b/test/account/transaction_test.rb index 798c64f..553ebac 100644 --- a/test/account/transaction_test.rb +++ b/test/account/transaction_test.rb @@ -12,19 +12,6 @@ def setup end end - def test_return_a_checksummed_address_from_tx_params - tx_params = { - version: 0, - amount: '0', - gas_price: '1000', - gas_limit: 1000, - to_addr: '2E3C9B415B19AE4035503A06192A0FAD76E04243' - } - - tx = Zilliqa::Account::Transaction.new(tx_params, nil) - assert Zilliqa::Util::Validator.checksum_address?(tx.to_payload[:toAddr]) - end - def test_should_poll_and_call_queued_handlers_on_confirmation responses = [ { @@ -66,7 +53,6 @@ def test_should_poll_and_call_queued_handlers_on_confirmation tx = Zilliqa::Account::Transaction.new(tx_params, @provider) @provider.expect("GetBalance", responses[0], [@address]) - @provider.expect("testnet?", false) pending = @wallet.sign(tx) @provider.expect("GetTransaction", responses[2], ['some_hash']) @@ -229,15 +215,14 @@ def test_encode_transaction_proto_for_null_code_and_null_data def test_devnet id = nil version = 21_823_489 - gas_price = '1000000000' - gas_limit = 1 + gas_price = '2000000000' + gas_limit = 50 sender_pub_key = '027eaa76955940798e22ec4007b00dbf0002fcd34f501f58c04b06c604f2228076' to_addr = '0xFeEd7997A0a45682CD4D8CEda27f2d81F6ba587c' amount = '1000000000000' provider = Zilliqa::Jsonrpc::Provider.new('https://dev-api.zilliqa.com') - @provider.expect("testnet?", true) signer = Zilliqa::Account::Wallet.new(provider) private_key = '7e78c742bca06824e4a5f0591260a2646339507c231daa5a47bf91d801f98239' @@ -259,7 +244,6 @@ def test_devnet signed = signer.sign(tx) payload = signed.to_payload - puts payload provider.CreateTransaction(payload) end diff --git a/test/account/wallet_test.rb b/test/account/wallet_test.rb index ca8638d..97b61d9 100644 --- a/test/account/wallet_test.rb +++ b/test/account/wallet_test.rb @@ -1,19 +1,6 @@ require 'test_helper' class WalletTest < Minitest::Test - def test_to_checksum_address - assert_equal Zilliqa::Account::Wallet.to_checksum_address('4BAF5FADA8E5DB92C3D3242618C5B47133AE003C'), '0x4BAF5faDA8e5Db92C3d3242618c5B47133AE003C' - assert_equal Zilliqa::Account::Wallet.to_checksum_address('448261915A80CDE9BDE7C7A791685200D3A0BF4E'), '0x448261915a80cdE9BDE7C7a791685200D3A0bf4E' - assert_equal Zilliqa::Account::Wallet.to_checksum_address('DED02FD979FC2E55C0243BD2F52DF022C40ADA1E'), '0xDed02fD979fC2e55c0243bd2F52df022c40ADa1E' - assert_equal Zilliqa::Account::Wallet.to_checksum_address('13F06E60297BEA6A3C402F6F64C416A6B31E586E'), '0x13F06E60297bea6A3c402F6f64c416A6b31e586e' - assert_equal Zilliqa::Account::Wallet.to_checksum_address('1A90C25307C3CC71958A83FA213A2362D859CF33'), '0x1a90C25307C3Cc71958A83fa213A2362D859CF33' - assert_equal Zilliqa::Account::Wallet.to_checksum_address('625ABAEBD87DAE9AB128F3B3AE99688813D9C5DF'), '0x625ABAebd87daE9ab128f3B3AE99688813d9C5dF' - assert_equal Zilliqa::Account::Wallet.to_checksum_address('36BA34097F861191C48C839C9B1A8B5912F583CF'), '0x36Ba34097f861191C48C839c9b1a8B5912f583cF' - assert_equal Zilliqa::Account::Wallet.to_checksum_address('D2453AE76C9A86AAE544FCA699DBDC5C576AEF3A'), '0xD2453Ae76C9A86AAe544fca699DbDC5c576aEf3A' - assert_equal Zilliqa::Account::Wallet.to_checksum_address('72220E84947C36118CDBC580454DFAA3B918CD97'), '0x72220e84947c36118cDbC580454DFaa3b918cD97' - assert_equal Zilliqa::Account::Wallet.to_checksum_address('50F92304C892D94A385CA6CE6CD6950CE9A36839'), '0x50f92304c892D94A385cA6cE6CD6950ce9A36839' - end - def test_create wallet = Zilliqa::Account::Wallet.new(nil, {}) address = wallet.create @@ -42,7 +29,6 @@ def test_sign provider = Minitest::Mock.new wallet = Zilliqa::Account::Wallet.new(provider, {}) - provider.expect("testnet?", false) wallet.add_by_private_key(private_key) tx_params = { @@ -90,11 +76,9 @@ def test_invalid_signature account = Zilliqa::Account::Account.new(private_key) wallet.add_by_private_key(private_key) - provider.expect('testnet?', false) provider.expect('GetBalance', response, [address]) 100.times do |i| - provider.expect('testnet?', false) provider.expect('GetBalance', response, [address]) tx_params = { diff --git a/test/contract/contract_factory_test.rb b/test/contract/contract_factory_test.rb index fb5ada2..b68cdcf 100644 --- a/test/contract/contract_factory_test.rb +++ b/test/contract/contract_factory_test.rb @@ -85,7 +85,6 @@ def test_should_be_able_to_deploy_a_contract @provider.expect("GetBalance", responses[0], [@address]) @provider.expect("CreateTransaction", responses[1], [Hash]) @provider.expect("GetTransaction", responses[2], ['some_hash']) - @provider.expect("testnet?", false) deploy_params = Zilliqa::Contract::DeployParams.new(nil, Zilliqa::Util.pack(8, 8), nil, 1000, 1000, nil) tx, deployed = contract.deploy(deploy_params) @@ -96,7 +95,7 @@ def test_should_be_able_to_deploy_a_contract assert deployed.deployed? assert_equal Zilliqa::Contract::ContractStatus::DEPLOYED, deployed.status - assert /[A-F0-9]+/ =~ contract.address + assert(/[A-F0-9]+/ =~ contract.address) end def test_should_not_swallow_network_errors @@ -135,7 +134,6 @@ def test_should_not_swallow_network_errors end @provider.expect("GetBalance", responses[0], [@address]) - @provider.expect("testnet?", false) def @provider.CreateTransaction(payload) raise 'something bad happened' @@ -143,7 +141,7 @@ def @provider.CreateTransaction(payload) deploy_params = Zilliqa::Contract::DeployParams.new(nil, Zilliqa::Util.pack(8, 8), nil, 1000, 1000, nil) assert_raises 'something bad happened.' do - tx, deployed = contract.deploy(deploy_params) + contract.deploy(deploy_params) end @provider.verify @@ -186,7 +184,6 @@ def test_if_the_underlying_transaction_is_rejected_contract_status_should_be_rej @provider.expect("GetBalance", responses[0], [@address]) @provider.expect("CreateTransaction", responses[1], [Hash]) - @provider.expect("testnet?", false) deploy_params = Zilliqa::Contract::DeployParams.new(nil, Zilliqa::Util.pack(8, 8), nil, 1000, 1000, nil) tx, contract = contract.deploy(deploy_params) @@ -246,7 +243,6 @@ def test_if_the_transaction_receipt_success_equal_false_contract_status_should_b @provider.expect("GetBalance", responses[0], [@address]) @provider.expect("CreateTransaction", responses[1], [Hash]) @provider.expect("GetTransaction", responses[2], ['some_hash']) - @provider.expect("testnet?", false) deploy_params = Zilliqa::Contract::DeployParams.new(nil, Zilliqa::Util.pack(8, 8), nil, 1000, 1000, nil) tx, contract = contract.deploy(deploy_params) @@ -329,17 +325,15 @@ def test_should_be_able_to_call_a_transition JSON.parse(JSON.generate(res)) end - @provider.expect("testnet?", false) @provider.expect("GetBalance", responses[0], [@address]) @provider.expect("CreateTransaction", responses[1], [Hash]) @provider.expect("GetTransaction", responses[2], ['some_hash']) @provider.expect("GetBalance", responses[3], [@address]) @provider.expect("CreateTransaction", responses[4], [Hash]) @provider.expect("GetTransaction", responses[5], ['some_hash']) - @provider.expect("testnet?", false) deploy_params = Zilliqa::Contract::DeployParams.new(nil, Zilliqa::Util.pack(8, 8), nil, 1000, 1000, nil) - tx, contract = contract.deploy(deploy_params) + _, contract = contract.deploy(deploy_params) call_tx = contract.call( 'myTransition', diff --git a/test/test_helper.rb b/test/test_helper.rb index d786b29..8802967 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -2,3 +2,4 @@ require "zilliqa" require "minitest/autorun" +require "pry-byebug" diff --git a/test/util/validator_test.rb b/test/util/validator_test.rb index 9d1b456..0783291 100644 --- a/test/util/validator_test.rb +++ b/test/util/validator_test.rb @@ -30,13 +30,6 @@ def test_address? assert Zilliqa::Util::Validator.address?(address) end - def test_checksum_address? - checksum_address = '0x4BAF5faDA8e5Db92C3d3242618c5B47133AE003C' - assert Zilliqa::Util::Validator.checksum_address?(checksum_address) - assert !Zilliqa::Util::Validator.checksum_address?(checksum_address[0..-2]) - assert !Zilliqa::Util::Validator.checksum_address?(checksum_address.upcase) - end - def test_bech32? address = 'zil1ej8wy3mnux6t9zeuc4vkhww0csctfpznzt4s76' diff --git a/zilliqa.gemspec b/zilliqa.gemspec index d1fa937..bbf89dc 100644 --- a/zilliqa.gemspec +++ b/zilliqa.gemspec @@ -36,7 +36,11 @@ Gem::Specification.new do |spec| spec.add_dependency "bundler", ">= 2.2.33" spec.add_development_dependency "rake", "~> 13.0" - spec.add_development_dependency "minitest", "~> 5.0" + # FIXME starting with 5.16 minitest supports kwargs in mocks, + # and that breaks our tests, e.g in contract/contract_factory_test.rb:186, + # where we expect hash as mock argument, but minitest treat this hash as kwargs + spec.add_development_dependency "minitest", "5.15" + spec.add_development_dependency "pry-byebug", "~> 3.10" spec.add_dependency "ruby-bitcoin-secp256k1" spec.add_dependency "scrypt" spec.add_dependency "pbkdf2-ruby"