Skip to content

Commit

Permalink
[bugfix] Use the right staking api client
Browse files Browse the repository at this point in the history
  • Loading branch information
drohit-cb committed Aug 22, 2024
1 parent 408e36a commit 65113b2
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 5 deletions.
4 changes: 1 addition & 3 deletions lib/coinbase/staking_operation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ def complete(key, interval_seconds: 5, timeout_seconds: 600)

transaction.sign(key)
@model = Coinbase.call_api do
stake_api.broadcast_staking_operation(
wallet_stake_api.broadcast_staking_operation(
wallet_id,
address_id,
id,
Expand All @@ -211,8 +211,6 @@ def complete(key, interval_seconds: 5, timeout_seconds: 600)

sleep interval_seconds
end

self
end

# Fetch the StakingOperation with the provided network, address and staking operation ID.
Expand Down
48 changes: 46 additions & 2 deletions spec/unit/coinbase/staking_operation_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@
build_staking_operation: staking_operation_model
)
allow(wallet_stake_api).to receive_messages(
create_staking_operation: staking_operation_model
create_staking_operation: staking_operation_model,
broadcast_staking_operation: staking_operation_model
)
allow(wallet_stake_api).to receive(:broadcast_staking_operation)
allow(transaction).to receive_messages(signed?: false, raw: raw_tx)
allow(raw_tx).to receive(:hex).and_return(hex_encoded_transaction)
end
Expand Down Expand Up @@ -421,4 +421,48 @@
end
end
end

describe '#complete' do
subject(:complete_operation) { staking_operation.complete(key, interval_seconds: 0.0001 ) }

context 'when the staking operation completes successfully' do
before do
allow(staking_operation).to receive(:terminal_state?).and_return(false, true)
allow(transaction).to receive(:signed?).and_return(false, true)
allow(staking_operation).to receive(:reload)
end

it 'signs the transaction' do
complete_operation
expect(transaction).to have_received(:sign).with(key)
end

it 'broadcasts the transaction' do
complete_operation
expect(wallet_stake_api).to have_received(:broadcast_staking_operation).with(
wallet_id,
address_id,
staking_operation.id,
{ signed_payload: hex_encoded_transaction, transaction_index: 0 }
)
end

it 'returns the staking operation' do
expect(complete_operation).to eq(staking_operation)
end

context 'when the staking operation times out' do
before do
allow(staking_operation).to receive(:terminal_state?).and_return(false)
allow(staking_operation).to receive(:reload)
end

it 'raises a Timeout::Error' do
expect do
staking_operation.complete(key, interval_seconds: 0.0001, timeout_seconds: 0.00001)
end.to raise_error(Timeout::Error, 'Staking Operation timed out')
end
end
end
end
end

0 comments on commit 65113b2

Please sign in to comment.