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

[bugfix] use the right staking api client #164

Merged
merged 2 commits into from
Aug 22, 2024
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
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [0.1.1] - 2024-08-22

### Fixed

- Incorrect stake client api being used for staking_operation.complete when calling `broadcast_staking_operation`

## [0.1.0] - 2024-08-22

- Expose all networks as constants, e.g. `Coinbase::Network::ETHEREUM_MAINNET`
Expand Down
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
2 changes: 1 addition & 1 deletion lib/coinbase/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# frozen_string_literal: true

module Coinbase
VERSION = '0.1.0'
VERSION = '0.1.1'
end
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
Loading