Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix specs, add GH Actions workflow #13

Merged
merged 8 commits into from
Aug 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 0 additions & 30 deletions .circleci/config.yml

This file was deleted.

27 changes: 27 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -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
14 changes: 12 additions & 2 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -44,7 +53,8 @@ PLATFORMS
ruby

DEPENDENCIES
minitest (~> 5.0)
minitest (= 5.15)
pry-byebug (~> 3.10)
rake (~> 13.0)
zilliqa!

Expand Down
10 changes: 0 additions & 10 deletions lib/zilliqa/util/validator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
20 changes: 2 additions & 18 deletions test/account/transaction_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
{
Expand Down Expand Up @@ -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'])
Expand Down Expand Up @@ -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'
Expand All @@ -259,7 +244,6 @@ def test_devnet

signed = signer.sign(tx)
payload = signed.to_payload
puts payload

provider.CreateTransaction(payload)
end
Expand Down
16 changes: 0 additions & 16 deletions test/account/wallet_test.rb
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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 = {
Expand Down Expand Up @@ -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 = {
Expand Down
12 changes: 3 additions & 9 deletions test/contract/contract_factory_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand Down Expand Up @@ -135,15 +134,14 @@ 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'
end

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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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',
Expand Down
1 change: 1 addition & 0 deletions test/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
require "zilliqa"

require "minitest/autorun"
require "pry-byebug"
7 changes: 0 additions & 7 deletions test/util/validator_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand Down
6 changes: 5 additions & 1 deletion zilliqa.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down