Initial commit
This commit is contained in:
43
spec/lib/peatio/airdrop_spec.rb
Normal file
43
spec/lib/peatio/airdrop_spec.rb
Normal file
@@ -0,0 +1,43 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
RSpec.describe Peatio::Airdrop do
|
||||
let(:test_file) { File.read(Rails.root.join('spec', 'resources', 'airdrops', file_name)) }
|
||||
let(:file_name) { '1.csv' }
|
||||
let(:src_user) { create(:member, role: :admin) }
|
||||
let(:uids) { %w[UID120 UID121 UID122 UID123 UID124] }
|
||||
|
||||
before do
|
||||
deposit = create(:deposit_btc, member: src_user, amount: 1000)
|
||||
deposit.accept!
|
||||
deposit.process!
|
||||
deposit.dispatch!
|
||||
uids.each do |uid|
|
||||
create(:member, uid: uid)
|
||||
end
|
||||
end
|
||||
|
||||
subject(:airdop) { Peatio::Airdrop.new.process(src_user, { file: { tempfile: test_file } }) }
|
||||
|
||||
it 'credited all users' do
|
||||
expect { airdop }.to change { Transfer.count }.by(5)
|
||||
uids.each do |uid|
|
||||
member = Member.find_by_uid(uid)
|
||||
expect(member.get_account(:btc).balance).to eq 100
|
||||
end
|
||||
end
|
||||
|
||||
it 'doesnt create for unexisting user' do
|
||||
Member.last.delete
|
||||
expect { airdop }.to change { Transfer.count }.by(4)
|
||||
end
|
||||
|
||||
it 'doesnt create transfers if src_user has insufficient funds (enough for the part of airdrop)' do
|
||||
src_user.get_account(:btc).update(balance: 200)
|
||||
expect { airdop }.to change { Transfer.count }.by(0)
|
||||
end
|
||||
|
||||
it 'doesnt create transfers if src_user has insufficient funds (zero balance)' do
|
||||
src_user.get_account(:btc).update(balance: 0)
|
||||
expect { airdop }.to change { Transfer.count }.by(0)
|
||||
end
|
||||
end
|
||||
55
spec/lib/peatio/opendax_spec.rb
Normal file
55
spec/lib/peatio/opendax_spec.rb
Normal file
@@ -0,0 +1,55 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
RSpec.describe Peatio::Upstream::Opendax do
|
||||
let(:upstream_opendax_config) do
|
||||
{
|
||||
"driver": 'opendax',
|
||||
"source": 'btcusd',
|
||||
"target": 'btcusd',
|
||||
"rest": 'http://localhost',
|
||||
"websocket": 'wss://localhost'
|
||||
}.stringify_keys
|
||||
end
|
||||
|
||||
let(:opendax) { Peatio::Upstream::Opendax.new(upstream_opendax_config) }
|
||||
|
||||
let(:msg) do
|
||||
{
|
||||
'btcusd.trades' =>
|
||||
{ 'trades' =>
|
||||
[{ 'tid' => 247_646_537,
|
||||
'taker_type' => 'buy',
|
||||
'date' => 1_584_437_804,
|
||||
'price' => '5194.0',
|
||||
'amount' => '0.01710500' }] }
|
||||
}
|
||||
end
|
||||
|
||||
let(:subscribe_msg) do
|
||||
{
|
||||
'success' =>
|
||||
{ 'message' => 'subscribed',
|
||||
'streams' => ['btcusd.trades'] }
|
||||
}
|
||||
end
|
||||
|
||||
let(:trade) do
|
||||
{
|
||||
tid: 247_646_537,
|
||||
amount: '0.01710500',
|
||||
price: '5194.0',
|
||||
date: 1_584_437_804,
|
||||
taker_type: 'buy'
|
||||
}.stringify_keys
|
||||
end
|
||||
|
||||
it 'detects trade' do
|
||||
opendax.expects(:notify_public_trade).with(trade)
|
||||
opendax.ws_read_public_message(msg)
|
||||
end
|
||||
|
||||
it 'doesnt notify about public trade' do
|
||||
opendax.expects(:notify_public_trade).never
|
||||
opendax.ws_read_public_message(subscribe_msg)
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user