diff --git a/lib/glueby/contract/tx_builder.rb b/lib/glueby/contract/tx_builder.rb index 8806e5d..db2efab 100644 --- a/lib/glueby/contract/tx_builder.rb +++ b/lib/glueby/contract/tx_builder.rb @@ -206,7 +206,7 @@ def create_multi_transfer_tx(color_id:, sender:, receivers:, fee_estimator: FeeE tx = Tapyrus::Tx.new amount = receivers.reduce(0) { |sum, r| sum + r[:amount].to_i } - utxos = sender.internal_wallet.list_unspent(color_id, only_finalized) + utxos = sender.internal_wallet.list_unspent(only_finalized, color_id: color_id) sum_token, outputs = collect_colored_outputs(utxos, amount) fill_input(tx, outputs) @@ -247,7 +247,7 @@ def create_multi_transfer_tx(color_id:, sender:, receivers:, fee_estimator: FeeE def create_burn_tx(color_id:, sender:, amount: 0, fee_estimator: FeeEstimator::Fixed.new, only_finalized: true) tx = Tapyrus::Tx.new - utxos = sender.internal_wallet.list_unspent(color_id, only_finalized) + utxos = sender.internal_wallet.list_unspent(only_finalized, color_id: color_id) sum_token, outputs = collect_colored_outputs(utxos, amount) fill_input(tx, outputs) diff --git a/lib/glueby/fee_provider/tasks.rb b/lib/glueby/fee_provider/tasks.rb index 31b2b2c..00f2df4 100644 --- a/lib/glueby/fee_provider/tasks.rb +++ b/lib/glueby/fee_provider/tasks.rb @@ -114,7 +114,7 @@ def collect_outputs def current_utxo_pool_size wallet - .list_unspent(nil, false) + .list_unspent(false) .count { |o| !o[:color_id] && o[:amount] == fee_provider.fixed_fee } end diff --git a/lib/glueby/internal/wallet.rb b/lib/glueby/internal/wallet.rb index 0e4d1d7..66a11be 100644 --- a/lib/glueby/internal/wallet.rb +++ b/lib/glueby/internal/wallet.rb @@ -89,20 +89,29 @@ def balance(only_finalized = true) wallet_adapter.balance(id, only_finalized) end - def list_unspent_with_count(color_id = nil, only_finalized = true, label = nil, page = 1, per = 25) - wallet_adapter.list_unspent_with_count(id, color_id, only_finalized, label, page, per) - end - + # @param only_finalized [Boolean] The flag to get a UTXO with status only finalized + # @param label [String] This label is used to filtered the UTXOs with labeled if a key or Utxo is labeled. + # - If label is nil or :unlabeled, only unlabeled UTXOs will be returned. + # - If label=:all, all UTXOs will be returned. # @param color_id [Tapyrus::Color::ColorIdentifier] The color identifier associated with UTXO. # It will return only UTXOs with specified color_id. If color_id is nil, it will return all UTXOs. # If Tapyrus::Color::ColorIdentifier.default is specified, it will return uncolored UTXOs(i.e. TPC) + # @param page [Integer] The page parameter is responsible for specifying the current page being viewed within the paginated results. default is 1. + # @param per [Integer] The per parameter is used to determine the number of items to display per page. default is 25. + def list_unspent_with_count(only_finalized = true, label = nil, color_id: nil, page: 1, per: 25) + wallet_adapter.list_unspent_with_count(id, only_finalized, label, color_id: color_id, page: page, per: per) + end + # @param only_finalized [Boolean] The flag to get a UTXO with status only finalized # @param label [String] This label is used to filtered the UTXOs with labeled if a key or Utxo is labeled. # - If label is nil or :unlabeled, only unlabeled UTXOs will be returned. # - If label=:all, all UTXOs will be returned. - def list_unspent(color_id = nil, only_finalized = true, label = :unlabeled) + # @param color_id [Tapyrus::Color::ColorIdentifier] The color identifier associated with UTXO. + # It will return only UTXOs with specified color_id. If color_id is nil, it will return all UTXOs. + # If Tapyrus::Color::ColorIdentifier.default is specified, it will return uncolored UTXOs(i.e. TPC) + def list_unspent(only_finalized = true, label = :unlabeled, color_id: nil ) label = :unlabeled unless label - wallet_adapter.list_unspent(id, color_id, only_finalized, label) + wallet_adapter.list_unspent(id, only_finalized, label, color_id: color_id) end def lock_unspent(utxo) @@ -302,7 +311,7 @@ def collect_utxos( collect_all = amount.nil? raise Glueby::ArgumentError, 'amount must be positive' unless collect_all || amount.positive? - utxos = list_unspent(color_id, only_finalized, label) + utxos = list_unspent(only_finalized, label, color_id: color_id) utxos = utxos.shuffle if shuffle r = utxos.inject([0, []]) do |(sum, outputs), output| diff --git a/lib/glueby/internal/wallet/abstract_wallet_adapter.rb b/lib/glueby/internal/wallet/abstract_wallet_adapter.rb index 1df7b64..9300e8c 100644 --- a/lib/glueby/internal/wallet/abstract_wallet_adapter.rb +++ b/lib/glueby/internal/wallet/abstract_wallet_adapter.rb @@ -68,15 +68,15 @@ def balance(wallet_id, only_finalized = true) # Returns all tokens with specified color_id # # @param [String] wallet_id - The wallet id that is offered by `create_wallet()` method. + # @param [Boolean] only_finalized - includes only finalized UTXO value if it + # is true. Default is true. # @param [Tapyrus::Color::ColorIdentifier] color_id The color identifier associated with UTXO. # It will return only UTXOs with specified color_id. If color_id is nil, it will return all UTXOs. # If Tapyrus::Color::ColorIdentifier.default is specified, it will return uncolored UTXOs(i.e. TPC) - # @param [Boolean] only_finalized - includes only finalized UTXO value if it - # is true. Default is true. # @param [Integer] page - The page parameter is responsible for specifying the current page being viewed within the paginated results. default is 1. # @param [Integer] per - The per parameter is used to determine the number of items to display per page. default is 25. # @return [Array] The array of the utxos with specified color_id - def list_unspent_with_count(wallet_id, color_id = nil, only_finalized = true, label = nil, page = 1, per = 25) + def list_unspent_with_count(wallet_id, only_finalized = true, label = nil, color_id: nil, page: 1, per: 25) raise NotImplementedError, "You must implement #{self.class}##{__method__}" end @@ -84,14 +84,14 @@ def list_unspent_with_count(wallet_id, color_id = nil, only_finalized = true, la # If label is specified, return UTXOs filtered with label # # @param [String] wallet_id - The wallet id that is offered by `create_wallet()` method. - # @param [Tapyrus::Color::ColorIdentifier] color_id - The color identifier. - # It will return only UTXOs with specified color_id. If color_id is nil, it will return all UTXOs. - # If Tapyrus::Color::ColorIdentifier.default is specified, it will return uncolored UTXOs(i.e. TPC) # @param [Boolean] only_finalized - The UTXOs includes only finalized UTXO value if it # is true. Default is true. # @param [String] label - Label for filtering UTXOs # - If label is nil or :unlabeled, only unlabeled UTXOs will be returned. # - If label=:all, it will return all utxos + # @param [Tapyrus::Color::ColorIdentifier] color_id - The color identifier. + # It will return only UTXOs with specified color_id. If color_id is nil, it will return all UTXOs. + # If Tapyrus::Color::ColorIdentifier.default is specified, it will return uncolored UTXOs(i.e. TPC) # @return [Array of UTXO] # # ## The UTXO structure @@ -102,7 +102,7 @@ def list_unspent_with_count(wallet_id, color_id = nil, only_finalized = true, la # - finalized: [Boolean] Whether the UTXO is finalized # - color_id: [String] Color id of the UTXO. If it is TPC UTXO, color_id is nil. # - script_pubkey: [String] Script pubkey of the UTXO - def list_unspent(wallet_id, color_id = nil, only_finalized = true, label = nil) + def list_unspent(wallet_id, only_finalized = true, label = nil, color_id: nil) raise NotImplementedError, "You must implement #{self.class}##{__method__}" end diff --git a/lib/glueby/internal/wallet/active_record_wallet_adapter.rb b/lib/glueby/internal/wallet/active_record_wallet_adapter.rb index 1654bd0..7ec891a 100644 --- a/lib/glueby/internal/wallet/active_record_wallet_adapter.rb +++ b/lib/glueby/internal/wallet/active_record_wallet_adapter.rb @@ -90,7 +90,7 @@ def balance(wallet_id, only_finalized = true) utxos.sum(&:value) end - def list_unspent_with_count(wallet_id, color_id = nil, only_finalized = true, label = nil, page = 1, per = 25) + def list_unspent_with_count(wallet_id, only_finalized = true, label = nil, color_id: nil, page: 1, per: 25) utxos = list_unspent_internal(wallet_id, color_id, only_finalized, label) utxos = utxos.page(page).per(per) if per > 0 { @@ -99,7 +99,7 @@ def list_unspent_with_count(wallet_id, color_id = nil, only_finalized = true, la } end - def list_unspent(wallet_id, color_id = nil, only_finalized = true, label = nil) + def list_unspent(wallet_id, only_finalized = true, label = nil, color_id: nil) utxos = list_unspent_internal(wallet_id, color_id, only_finalized, label) utxos_to_h(utxos) end diff --git a/lib/glueby/internal/wallet/tapyrus_core_wallet_adapter.rb b/lib/glueby/internal/wallet/tapyrus_core_wallet_adapter.rb index 586bf70..e6025d8 100644 --- a/lib/glueby/internal/wallet/tapyrus_core_wallet_adapter.rb +++ b/lib/glueby/internal/wallet/tapyrus_core_wallet_adapter.rb @@ -84,7 +84,7 @@ def balance(wallet_id, only_finalized = true) # If label=nil, it will return unlabeled utxos to protect labeled utxos for specific purpose # If label=:all, it will return all utxos - def list_unspent(wallet_id, color_id = nil, only_finalized = true, label = nil) + def list_unspent(wallet_id, only_finalized = true, label = nil, color_id: nil) perform_as(wallet_id) do |client| min_conf = only_finalized ? 1 : 0 res = client.listunspent(min_conf) diff --git a/lib/glueby/utxo_provider.rb b/lib/glueby/utxo_provider.rb index 1cc7043..af05181 100644 --- a/lib/glueby/utxo_provider.rb +++ b/lib/glueby/utxo_provider.rb @@ -114,7 +114,7 @@ def tpc_amount def current_utxo_pool_size wallet - .list_unspent(nil, false) + .list_unspent(false) .count { |o| !o[:color_id] && o[:amount] == default_value } end diff --git a/lib/glueby/wallet.rb b/lib/glueby/wallet.rb index b681fab..fc8f0af 100644 --- a/lib/glueby/wallet.rb +++ b/lib/glueby/wallet.rb @@ -37,7 +37,7 @@ def id # @return [HashMap] hash of balances which key is color_id or empty string, and value is amount def balances(only_finalized = true) - utxos = @internal_wallet.list_unspent(nil, only_finalized) + utxos = @internal_wallet.list_unspent(only_finalized) utxos.inject({}) do |balances, output| key = output[:color_id] || '' balances[key] ||= 0 @@ -47,7 +47,7 @@ def balances(only_finalized = true) end def token_utxos(color_id = nil, only_finalized = true, page = 1, per = 25) - @internal_wallet.list_unspent_with_count(color_id, only_finalized, nil, page, per) + @internal_wallet.list_unspent_with_count(only_finalized, nil, color_id: color_id, page: page, per: per) end private diff --git a/spec/functional/payment_spec.rb b/spec/functional/payment_spec.rb index c553e95..8b2dcb5 100644 --- a/spec/functional/payment_spec.rb +++ b/spec/functional/payment_spec.rb @@ -29,8 +29,8 @@ end.to raise_error(Glueby::Contract::Errors::InsufficientFunds) # should not consume 'labeled' utxos - expect(sender.internal_wallet.list_unspent(nil, false, 'labeled').size).to eq(1) - expect(sender.internal_wallet.list_unspent(nil, false, 'labeled')[0][:amount]).to eq(5_000_000_000) + expect(sender.internal_wallet.list_unspent(false, 'labeled').size).to eq(1) + expect(sender.internal_wallet.list_unspent(false, 'labeled')[0][:amount]).to eq(5_000_000_000) # create a usable utxo for payment process_block(to_address: sender.internal_wallet.receive_address) @@ -48,8 +48,8 @@ # receiver got the sent amount expect(receiver.balances(false)['']).to eq(10_000) # should not consume 'labeled' utxos - expect(sender.internal_wallet.list_unspent(nil, false, 'labeled').size).to eq(1) - expect(sender.internal_wallet.list_unspent(nil, false, 'labeled')[0][:amount]).to eq(5_000_000_000) + expect(sender.internal_wallet.list_unspent(false, 'labeled').size).to eq(1) + expect(sender.internal_wallet.list_unspent(false, 'labeled')[0][:amount]).to eq(5_000_000_000) end end @@ -74,8 +74,8 @@ end.to raise_error(Glueby::Contract::Errors::InsufficientFunds) # should not consume 'labeled' utxos - expect(sender.internal_wallet.list_unspent(nil, false, 'labeled').size).to eq(1) - expect(sender.internal_wallet.list_unspent(nil, false, 'labeled')[0][:amount]).to eq(5_000_000_000 + fixed_fee) + expect(sender.internal_wallet.list_unspent(false, 'labeled').size).to eq(1) + expect(sender.internal_wallet.list_unspent(false, 'labeled')[0][:amount]).to eq(5_000_000_000 + fixed_fee) # create a usable utxo for payment process_block(to_address: sender.internal_wallet.receive_address) @@ -92,8 +92,8 @@ # receiver got the sent amount expect(receiver.balances(false)['']).to eq(10_000) # should not consume 'labeled' utxos - expect(sender.internal_wallet.list_unspent(nil, false, 'labeled').size).to eq(1) - expect(sender.internal_wallet.list_unspent(nil, false, 'labeled')[0][:amount]).to eq(5_000_000_000 + fixed_fee) + expect(sender.internal_wallet.list_unspent(false, 'labeled').size).to eq(1) + expect(sender.internal_wallet.list_unspent(false, 'labeled')[0][:amount]).to eq(5_000_000_000 + fixed_fee) sighashtype = tx.inputs[-1].script_sig.chunks.first.pushed_data[-1].unpack1('C') expect(sighashtype).to eq(Tapyrus::SIGHASH_TYPE[:all]) diff --git a/spec/functional/token_spec.rb b/spec/functional/token_spec.rb index ec327fd..1236133 100644 --- a/spec/functional/token_spec.rb +++ b/spec/functional/token_spec.rb @@ -386,7 +386,7 @@ expect(sender.balances(false)['']).to be_nil expect(sender.balances(false)[token2.color_id.to_hex]).to eq(10_000) - expect(sender.internal_wallet.list_unspent(nil, false).select {|i| i[:color_id] == token2.color_id.to_hex}.size).to eq(100) + expect(sender.internal_wallet.list_unspent(false).select {|i| i[:color_id] == token2.color_id.to_hex}.size).to eq(100) # Specify metadata option token3, _txs = Glueby::Contract::Token.issue!( @@ -457,7 +457,7 @@ expect(sender.balances(false)[token.color_id.to_hex]).to be_nil expect(receiver.balances(false)[token.color_id.to_hex]).to eq(10_000) - expect(receiver.internal_wallet.list_unspent(nil, false).select {|i| i[:color_id] == token.color_id.to_hex}.size).to eq(100) + expect(receiver.internal_wallet.list_unspent(false).select {|i| i[:color_id] == token.color_id.to_hex}.size).to eq(100) end it 'doesn\'t raise insufficient error in too much split number' do diff --git a/spec/glueby/contract/timestamp_spec.rb b/spec/glueby/contract/timestamp_spec.rb index 44fa78d..daf4d21 100644 --- a/spec/glueby/contract/timestamp_spec.rb +++ b/spec/glueby/contract/timestamp_spec.rb @@ -358,7 +358,7 @@ it 'the wallet never store the UTXO of the created trackable timestamp' do subject - result = wallet.internal_wallet.list_unspent(nil, false, :all).find { |i| i[:txid] == contract.txid && i[:vout] == 0 } + result = wallet.internal_wallet.list_unspent(false, :all).find { |i| i[:txid] == contract.txid && i[:vout] == 0 } expect(result).to be_nil end end diff --git a/spec/glueby/contract/token_spec.rb b/spec/glueby/contract/token_spec.rb index 48c4bad..d9f060e 100644 --- a/spec/glueby/contract/token_spec.rb +++ b/spec/glueby/contract/token_spec.rb @@ -86,16 +86,16 @@ before do allow(internal_wallet).to receive(:list_unspent).and_return([]) - allow(internal_wallet).to receive(:list_unspent).with(Tapyrus::Color::ColorIdentifier.default, true, nil).and_return(unspents.select{ |i| !i[:color_id] && i[:finalized] }) - allow(internal_wallet).to receive(:list_unspent).with(Tapyrus::Color::ColorIdentifier.default, false, nil).and_return(unspents.select{ |i| !i[:color_id] }) + allow(internal_wallet).to receive(:list_unspent).with(true, nil, color_id: Tapyrus::Color::ColorIdentifier.default).and_return(unspents.select{ |i| !i[:color_id] && i[:finalized] }) + allow(internal_wallet).to receive(:list_unspent).with(false, nil, color_id: Tapyrus::Color::ColorIdentifier.default).and_return(unspents.select{ |i| !i[:color_id] }) [ "c3eb2b846463430b7be9962843a97ee522e3dc0994a0f5e2fc0aa82e20e67fe893", "c2dbbebb191128de429084246fa3215f7ccc36d6abde62984eb5a42b1f2253a016", "c150ad685ec8638543b2356cb1071cf834fb1c84f5fa3a71699c3ed7167dfcdbb3", ].each do |color_id_hex| color_id = Tapyrus::Color::ColorIdentifier.parse_from_payload(color_id_hex.htb) - allow(internal_wallet).to receive(:list_unspent).with(color_id, true, nil).and_return(unspents.select{ |i| i[:color_id] == color_id_hex && i[:finalized] }) - allow(internal_wallet).to receive(:list_unspent).with(color_id, false, nil).and_return(unspents.select{ |i| i[:color_id] == color_id_hex }) + allow(internal_wallet).to receive(:list_unspent).with(true, nil, color_id: color_id).and_return(unspents.select{ |i| i[:color_id] == color_id_hex && i[:finalized] }) + allow(internal_wallet).to receive(:list_unspent).with(false, nil, color_id: color_id).and_return(unspents.select{ |i| i[:color_id] == color_id_hex }) end allow(Glueby::Internal::RPC).to receive(:client).and_return(rpc) allow(rpc).to receive(:sendrawtransaction).and_return('') diff --git a/spec/glueby/contract/tx_builder_spec.rb b/spec/glueby/contract/tx_builder_spec.rb index 07efa0f..2cd2de7 100644 --- a/spec/glueby/contract/tx_builder_spec.rb +++ b/spec/glueby/contract/tx_builder_spec.rb @@ -387,7 +387,7 @@ class TxBuilderMock let(:amount) { 100_001 } before do - allow(internal_wallet).to receive(:list_unspent).with(color_id, true) + allow(internal_wallet).to receive(:list_unspent).with(true, color_id: color_id) .and_return(unspents.select { |utxo| utxo[:color_id] == 'c150ad685ec8638543b2356cb1071cf834fb1c84f5fa3a71699c3ed7167dfcdbb3' }) end it { expect(subject.inputs.size).to eq 3 } @@ -395,6 +395,8 @@ class TxBuilderMock it { expect(subject.inputs[0].out_point.index).to eq 0 } it { expect(subject.inputs[1].out_point.txid).to eq 'a3f20bc94c8d77c35ba1770116d2b34375475a4194d15f76442636e9f77d50d9' } it { expect(subject.inputs[1].out_point.index).to eq 2 } + it { expect(subject.inputs[2].out_point.txid).to eq '5c3d79041ff4974282b8ab72517d2ef15d8b6273cb80a01077145afb3d5e7cc5' } + it { expect(subject.inputs[2].out_point.index).to eq 0 } it { expect(subject.outputs.size).to eq 3 } it { expect(subject.outputs[0].value).to eq 100_001 } it { expect(subject.outputs[0].colored?).to be_truthy } @@ -426,7 +428,7 @@ class TxBuilderMock end before do - allow(internal_wallet).to receive(:list_unspent).with(color_id, true) + allow(internal_wallet).to receive(:list_unspent).with(true, color_id: color_id) .and_return(unspents.select { |utxo| utxo[:color_id] == 'c150ad685ec8638543b2356cb1071cf834fb1c84f5fa3a71699c3ed7167dfcdbb3' }) end @@ -488,7 +490,7 @@ class TxBuilderMock before do - allow(internal_wallet).to receive(:list_unspent).with(color_id, true) + allow(internal_wallet).to receive(:list_unspent).with(true, color_id: color_id) .and_return(unspents.select { |utxo| utxo[:color_id] == 'c150ad685ec8638543b2356cb1071cf834fb1c84f5fa3a71699c3ed7167dfcdbb3' }) end diff --git a/spec/glueby/internal/wallet/active_record_wallet_adapter_spec.rb b/spec/glueby/internal/wallet/active_record_wallet_adapter_spec.rb index a0911ac..c9c6246 100644 --- a/spec/glueby/internal/wallet/active_record_wallet_adapter_spec.rb +++ b/spec/glueby/internal/wallet/active_record_wallet_adapter_spec.rb @@ -149,7 +149,7 @@ it { expect(subject[1][:label]).to eq nil } end - subject { adapter.list_unspent(wallet.wallet_id, color_id, only_finalized, label) } + subject { adapter.list_unspent(wallet.wallet_id, only_finalized, label, color_id: color_id) } let(:other_wallet) { Glueby::Internal::Wallet::AR::Wallet.create(wallet_id: adapter.create_wallet) } let(:only_finalized) { true } @@ -525,7 +525,7 @@ end describe '#list_unspent_with_count' do - subject { adapter.list_unspent_with_count(wallet_id, color_id, only_finalized, label, page, per) } + subject { adapter.list_unspent_with_count(wallet_id, only_finalized, label, color_id: color_id, page: page, per: per) } let(:wallet_id) { wallet.wallet_id } let(:color_id) { Tapyrus::Color::ColorIdentifier.parse_from_payload('c185856a84c483fb108b1cdf79ff53aa7d54d1a137a5178684bd89ca31f906b2bd'.htb) } diff --git a/spec/glueby/internal/wallet/tapyrus_core_wallet_adapter_spec.rb b/spec/glueby/internal/wallet/tapyrus_core_wallet_adapter_spec.rb index f9bfd36..f00eef2 100644 --- a/spec/glueby/internal/wallet/tapyrus_core_wallet_adapter_spec.rb +++ b/spec/glueby/internal/wallet/tapyrus_core_wallet_adapter_spec.rb @@ -255,7 +255,7 @@ end end - subject { adapter.list_unspent(wallet_id, color_id, only_finalized) } + subject { adapter.list_unspent(wallet_id, only_finalized, color_id: color_id) } let(:wallet_id) { ARBITRARY_WALLET_ID } let(:color_id) { nil } @@ -350,7 +350,7 @@ end context 'with label' do - subject { adapter.list_unspent(wallet_id, color_id, true, "Glueby-Contract-Tracking") } + subject { adapter.list_unspent(wallet_id, true, "Glueby-Contract-Tracking", color_id: color_id) } it 'should call listunspent RPC with label and parse the results.' do expect(rpc).to receive(:listunspent).and_return(response) expect(subject).to eq([ @@ -368,15 +368,15 @@ end context 'with unlabeled by assign :unlabeled' do - subject { adapter.list_unspent(wallet_id, color_id, true, :unlabeled) } + subject { adapter.list_unspent(wallet_id, true, :unlabeled, color_id: color_id) } it_behaves_like 'executes the common unlabeled validation' end context 'with unlabeled by default' do - subject { adapter.list_unspent(wallet_id, color_id, true, :unlabeled) } + subject { adapter.list_unspent(wallet_id, true, :unlabeled, color_id: color_id) } it_behaves_like 'executes the common unlabeled validation' end context 'with all utxos' do - subject { adapter.list_unspent(wallet_id, color_id, true, :all) } + subject { adapter.list_unspent(wallet_id, true, :all, color_id: color_id) } it 'should call listunspent RPC with all utxos and parse the results.' do expect(rpc).to receive(:listunspent).and_return(response) expect(subject).to eq([ diff --git a/spec/glueby/internal/wallet_spec.rb b/spec/glueby/internal/wallet_spec.rb index 7bba385..5e8de7f 100644 --- a/spec/glueby/internal/wallet_spec.rb +++ b/spec/glueby/internal/wallet_spec.rb @@ -206,7 +206,7 @@ def load_wallet(wallet_id); end let(:only_finalized) { false } it do - allow(internal_wallet).to receive(:list_unspent).with(Tapyrus::Color::ColorIdentifier.default, false, nil).and_return(unspents.select{ |u| !u[:color_id]}) + allow(internal_wallet).to receive(:list_unspent).with(false, nil, color_id: Tapyrus::Color::ColorIdentifier.default).and_return(unspents.select{ |u| !u[:color_id]}) expect(subject[0]).to eq 250_000_000 expect(subject[1].size).to eq 3 end @@ -223,7 +223,7 @@ def load_wallet(wallet_id); end let(:only_finalized) { false } it 'returns one output' do - allow(internal_wallet).to receive(:list_unspent).with(Tapyrus::Color::ColorIdentifier.default, false, nil).and_return(unspents.select{ |u| !u[:color_id]}) + allow(internal_wallet).to receive(:list_unspent).with(false, nil, color_id: Tapyrus::Color::ColorIdentifier.default).and_return(unspents.select{ |u| !u[:color_id]}) expect(subject[0]).to eq 250_000_000 expect(subject[1].size).to eq 3 end @@ -303,8 +303,8 @@ def load_wallet(wallet_id); end before do allow(internal_wallet).to receive(:list_unspent).and_return(unspents) - allow(internal_wallet).to receive(:list_unspent).with(Tapyrus::Color::ColorIdentifier.default, false, nil).and_return(unspents.select{ |u| !u[:color_id]}) - allow(internal_wallet).to receive(:list_unspent).with(color_id, false, nil).and_return(unspents.select{ |u| u[:color_id] == color_id.to_hex }) + allow(internal_wallet).to receive(:list_unspent).with(false, nil, color_id: Tapyrus::Color::ColorIdentifier.default).and_return(unspents.select{ |u| !u[:color_id]}) + allow(internal_wallet).to receive(:list_unspent).with(false, nil, color_id: color_id).and_return(unspents.select{ |u| u[:color_id] == color_id.to_hex }) end it 'returns one output' do @@ -542,7 +542,7 @@ def load_wallet(wallet_id); end end describe "#list_unspent_with_count" do - subject { wallet.list_unspent_with_count(color_id) } + subject { wallet.list_unspent_with_count(color_id: color_id) } let(:color_id) { Tapyrus::Color::ColorIdentifier.parse_from_payload('c150ad685ec8638543b2356cb1071cf834fb1c84f5fa3a71699c3ed7167dfcdbb3'.htb) } @@ -551,7 +551,7 @@ def load_wallet(wallet_id); end subject - expect(Glueby::Internal::Wallet.wallet_adapter).to have_received(:list_unspent_with_count).with(wallet.id, color_id, true, nil, 1, 25) + expect(Glueby::Internal::Wallet.wallet_adapter).to have_received(:list_unspent_with_count).with(wallet.id, true, nil, color_id: color_id, page: 1, per: 25) end end end \ No newline at end of file diff --git a/spec/glueby/wallet_spec.rb b/spec/glueby/wallet_spec.rb index fb031af..d9578f9 100644 --- a/spec/glueby/wallet_spec.rb +++ b/spec/glueby/wallet_spec.rb @@ -5,7 +5,7 @@ class TestWalletAdapter < Glueby::Internal::Wallet::AbstractWalletAdapter def create_wallet(wallet_id = nil) "wallet_id:1" end - def list_unspent(wallet_id, color_id = nil, only_finalized = true, label = nil) + def list_unspent(wallet_id, only_finalized = true, label = nil, color_id: nil) utxos = [ { txid: '1d49c8038943d37c2723c9c7a1c4ea5c3738a9bad5827ddc41e144ba6aef36db', @@ -157,7 +157,7 @@ def token_utxos(wallet_id, color_id, only_finalized, per, page) it do allow(Glueby::Internal::Wallet.wallet_adapter).to receive(:list_unspent_with_count).and_return([]) subject - expect(Glueby::Internal::Wallet.wallet_adapter).to have_received(:list_unspent_with_count).with("wallet_id:1", color_id, only_finalized, nil, 1, 25) + expect(Glueby::Internal::Wallet.wallet_adapter).to have_received(:list_unspent_with_count).with("wallet_id:1", only_finalized, nil, color_id: color_id, page: 1, per: 25) end end end \ No newline at end of file diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index e90c103..2389007 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -250,7 +250,7 @@ def receive_address(label = nil) '1DBgMCNBdjQ1Ntz1vpwx2HMYJmc9kw88iT' end - def list_unspent(color_id = nil, only_finalized = true, label = nil) + def list_unspent(only_finalized = true, label = nil, color_id: nil) [] end