Skip to content

Commit

Permalink
e2e ruby tests of cardano-wallet on public testnet
Browse files Browse the repository at this point in the history
  • Loading branch information
Piotr Stachyra committed Mar 1, 2021
1 parent 1b42a42 commit 10c9141
Show file tree
Hide file tree
Showing 13 changed files with 132,011 additions and 0 deletions.
15 changes: 15 additions & 0 deletions test/e2e/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/.bundle/
/spec/reports/
/tmp/
/configs/
/node_db/
/wallet_db/
/bins/
/cardano-wallet-*/
/binaryDist/
/binary-dist/

Gemfile.lock

# rspec failure tracking
.rspec_status
7 changes: 7 additions & 0 deletions test/e2e/.rakeTasks
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<Settings><!--This file was automatically generated by Ruby plugin.
You are allowed to:
1. Remove rake task
2. Add existing rake tasks
To add existing rake tasks automatically delete this file and reload the project.
--><RakeGroup description="" fullCmd="" taksId="rake" /></Settings>
3 changes: 3 additions & 0 deletions test/e2e/.rspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
--format documentation
--color
--require spec_helper
6 changes: 6 additions & 0 deletions test/e2e/Gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
source 'https://rubygems.org'

gem 'cardano_wallet', '~> 0.3.2'
gem 'bip_mnemonic', '~> 0.0.4'
gem 'rake', '~> 12.3'
gem 'rspec'
141 changes: 141 additions & 0 deletions test/e2e/Rakefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
require "rspec/core/rake_task"
require "cardano_wallet"
require_relative "spec/test_utils"

RSpec::Core::RakeTask.new(:spec)

task :default => :spec

task :wait_until_node_synced do
puts "\n >> Wait for node to be synced"

network = CardanoWallet.new.misc.network
timeout = 180
current_time = Time.now
timeout_treshold = current_time + timeout
puts "Timeout: #{timeout}s"
puts "Threshold: #{timeout_treshold}"
begin
current_time = Time.now
while network.information["sync_progress"]["status"] == "syncing" do
puts "Syncing... #{network.information["sync_progress"]["progress"]["quantity"]}%"
sleep 15
end
rescue
retry if (current_time <= timeout_treshold)
raise("Could not connect to wallet within #{timeout} seconds...")
end

puts "\n>> Cardano-node and cardano-wallet are synced! <<"
end

task :start_node_and_wallet do
puts "\n >> Set up and start cardano-node and cardano-wallet"

if is_win?
cd = Dir.pwd
# create cardano-node.bat file
node_cmd = "#{cd}/cardano-node.exe run --config #{cd}/configs/testnet-config.json --topology #{cd}/configs/testnet-topology.json --database-path #{ENV['NODE_DB']} --socket-path \\\\.\\pipe\\cardano-node-testnet"
File.open("cardano-node.bat", "w") do |f|
f.write(node_cmd)
end

# create cardano-wallet.bat file
wallet_cmd = "#{cd}/cardano-wallet.exe serve --node-socket \\\\.\\pipe\\cardano-node-testnet --testnet #{cd}/configs/testnet-byron-genesis.json --database #{ENV['WALLET_DB']} --token-metadata-server #{ENV['TOKEN_METADATA']}"
File.open("cardano-wallet.bat", "w") do |f|
f.write(wallet_cmd)
end

install_node = "nssm install cardano-node #{cd}/cardano-node.bat"
install_wallet = "nssm install cardano-wallet #{cd}/cardano-wallet.bat"
start_node = "nssm start cardano-node"
start_wallet = "nssm start cardano-wallet"

puts install_node
puts install_wallet
puts start_node
puts start_wallet

puts `#{install_node}`
puts `#{install_wallet}`
puts `#{start_node}`
puts `#{start_wallet}`
else
cd = Dir.pwd
start_node = "#{cd}/bins/cardano-node run --config #{cd}/configs/*-config.json --topology #{cd}/configs/*-topology.json --database-path #{ENV['NODE_DB']} --socket-path #{cd}/node.socket"
start_wallet = "#{cd}/bins/cardano-wallet serve --node-socket #{cd}/node.socket --testnet #{cd}/configs/*-byron-genesis.json --database #{ENV['WALLET_DB']} --token-metadata-server #{ENV['TOKEN_METADATA']}"

puts start_node
puts start_wallet

puts `screen -dmS NODE #{start_node}`
puts `screen -dmS WALLET #{start_wallet}`
puts `screen -ls`
end
end

task :stop_node_and_wallet do
puts "\n >> Stop cardano-node and cardano-wallet"

if is_win?
puts `nssm stop cardano-wallet`
puts `nssm stop cardano-node`
else
puts `screen -XS WALLET`
puts `screen -XS NODE`
end

end

task :get_latest_bins do
puts "\n >> Get latest node and wallet binaries from Hydra"

wget(get_latest_binary_url)
bins_path = Dir.pwd + "/bins"
mk_dir(bins_path)
if is_win?
puts `unzip binary-dist`
puts `dir`

puts "cardano-node version:"
puts `cardano-node.exe version`

puts "cardano-wallet version:"
puts `cardano-wallet.exe version`
else
puts `tar -xvf binary-dist`
puts `cp -r cardano-wallet-*/* #{bins_path}`

puts "cardano-node version:"
puts `#{bins_path}/cardano-node version`

puts "cardano-wallet version:"
puts `#{bins_path}/cardano-wallet version`
end
end

task :get_latest_configs, [:env] do |task, args|
puts "\n >> Get latest configs for '#{args[:env]}'"

base_url = get_latest_configs_base_url
env = args[:env]
path = Dir.pwd + "/configs"
mk_dir(path)
wget("#{base_url}/#{env}-config.json", "#{path}/#{env}-config.json")
wget("#{base_url}/#{env}-byron-genesis.json", "#{path}/#{env}-byron-genesis.json")
wget("#{base_url}/#{env}-shelley-genesis.json", "#{path}/#{env}-shelley-genesis.json")
wget("#{base_url}/#{env}-topology.json", "#{path}/#{env}-topology.json")
end

##
# NODE_DB=./node_db WALLET_DB=./wallet_db TOKEN_METADATA=http://metadata-server-mock.herokuapp.com/ bundle exec rake run_on["testnet"]
task :run_on, [:env] do |task, args|
puts "\n >> Set up env and run all tests"

Rake::Task[:get_latest_bins].invoke
Rake::Task[:get_latest_configs].invoke(args[:env])
Rake::Task[:start_node_and_wallet].invoke
Rake::Task[:wait_until_node_synced].invoke
Rake::Task[:spec].invoke
Rake::Task[:stop_node_and_wallet].invoke
end
6 changes: 6 additions & 0 deletions test/e2e/run_all_tests
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/usr/bin/env bash

NODE_DB=./node_db \
WALLET_DB=./wallet_db \
TOKEN_METADATA=http://metadata-server-mock.herokuapp.com/ \
bundle exec rake run_on["testnet"]
Loading

0 comments on commit 10c9141

Please sign in to comment.