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

Update Wallet::Data to be keyword initialized #21

Merged
merged 2 commits into from
Apr 30, 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: 3 additions & 3 deletions lib/coinbase/wallet.rb
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ def transfer(amount, asset_id, destination)
# Exports the Wallet's data to a Data object.
# @return [Data] The Wallet data
def export
Data.new(wallet_id, @master.seed_hex)
Data.new(wallet_id: wallet_id, seed: @master.seed_hex)
end

# The data required to recreate a Wallet.
Expand All @@ -159,7 +159,7 @@ class Data
# Returns a new Data object.
# @param wallet_id [String] The ID of the Wallet
# @param seed [String] The seed of the Wallet
def initialize(wallet_id, seed)
def initialize(wallet_id:, seed:)
@wallet_id = wallet_id
@seed = seed
end
Expand All @@ -174,7 +174,7 @@ def to_hash
# @param data [Hash] The Hash to create the Data object from
# @return [Data] The new Data object
def self.from_hash(data)
Data.new(data['wallet_id'], data['seed'])
Data.new(wallet_id: data['wallet_id'], seed: data['seed'])
end
end

Expand Down
31 changes: 16 additions & 15 deletions spec/unit/coinbase/user_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -86,31 +86,32 @@
let(:address_list_model) do
Coinbase::Client::AddressList.new({ 'data' => [address_model], 'total_count' => 1 })
end
let(:wallet_export_data) do
Coinbase::Wallet::Data.new(
wallet_id: wallet_id,
seed: MoneyTree::Master.new.seed_hex
)
end
subject(:imported_wallet) { user.import_wallet(wallet_export_data) }

before do
allow(Coinbase::Client::AddressesApi).to receive(:new).and_return(addresses_api)
allow(Coinbase::Client::WalletsApi).to receive(:new).and_return(wallets_api)
expect(wallets_api).to receive(:create_wallet).with(opts).and_return(wallet_model)
expect(addresses_api)
.to receive(:create_address)
.with(wallet_id, satisfy do |opts|
public_key_present = opts[:create_address_request][:public_key].is_a?(String)
attestation_present = opts[:create_address_request][:attestation].is_a?(String)
public_key_present && attestation_present
end)
expect(wallets_api).to receive(:get_wallet).with(wallet_id).and_return(wallet_model_with_default_address)
expect(wallets_api).to receive(:get_wallet).with(wallet_id).and_return(wallet_model)
expect(addresses_api).to receive(:list_addresses).with(wallet_id).and_return(address_list_model)
expect(addresses_api).to receive(:get_address).and_return(address_model)
end

it 'imports an exported Wallet' do
wallet = user.create_wallet
data = wallet.export
new_wallet = user.import_wallet(data)
it 'imports an exported wallet' do
expect(imported_wallet.wallet_id).to eq(wallet_id)
end

it 'loads the wallet addresses' do
expect(imported_wallet.list_addresses.length).to eq(address_list_model.total_count)
end

expect(new_wallet.wallet_id).to eq(wallet.wallet_id)
expect(new_wallet.list_addresses.length).to eq(wallet.list_addresses.length)
it 'contains the same seed when re-exported' do
expect(imported_wallet.export.seed).to eq(wallet_export_data.seed)
end
end

Expand Down
Loading