Skip to content

Commit

Permalink
Support for settings
Browse files Browse the repository at this point in the history
  • Loading branch information
Piotr Stachyra committed Oct 8, 2020
1 parent c117146 commit ea3cc76
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 0 deletions.
27 changes: 27 additions & 0 deletions lib/cardano_wallet/misc.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,33 @@ def utils
def proxy
Proxy.new @opt
end

# @see https://input-output-hk.github.io/cardano-wallet/api/edge/#tag/Settings
def settings
Settings.new @opt
end
end

# API for Network
# @see https://input-output-hk.github.io/cardano-wallet/api/edge/#tag/Settings
class Settings < Base
def initialize opt
super
end

# @see https://input-output-hk.github.io/cardano-wallet/api/edge/#operation/getSettings
def get
self.class.get("/settings")
end

# @see https://input-output-hk.github.io/cardano-wallet/api/edge/#operation/putSettings
def update(params)
CardanoWallet::Utils.verify_param_is_hash!(params)
self.class.put("/settings",
:body => {"settings" => params}.to_json,
:headers => { 'Content-Type' => 'application/json' }
)
end
end

# API for Network
Expand Down
21 changes: 21 additions & 0 deletions spec/misc_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -83,4 +83,25 @@
end
end

describe CardanoWallet::Misc::Settings do
before(:all) do
SETTINGS = CardanoWallet.new.misc.settings
end

after(:all) do
SETTINGS.update({:pool_metadata_source => "none"})
end

["direct", "https://smash.pl", "none"].each do |strategy|
it "I can read and update settings to #{strategy}" do
s = SETTINGS.update({:pool_metadata_source => strategy})
expect(s.code).to eq 204

g = SETTINGS.get
expect(g['pool_metadata_source']).to eq strategy
expect(g.code).to eq 200
end
end
end

end
24 changes: 24 additions & 0 deletions spec/shelley_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
end

after(:all) do
settings = CardanoWallet.new.misc.settings
s = settings.update({:pool_metadata_source => "none"})
teardown
end

Expand Down Expand Up @@ -167,6 +169,28 @@
tx['status'] == "in_ledger"
end
end

it "Pool metadata is updated when settings are updated" do
settings = CardanoWallet.new.misc.settings
pools = SHELLEY.stake_pools

s = settings.update({:pool_metadata_source => "direct"})
expect(s.code).to eq 204

eventually "Pools have metadata when 'pool_metadata_source' => 'direct'" do
sps = pools.list({stake: 1000})
sps.select{|p| p['metadata']}.size > 0
end

s = settings.update({:pool_metadata_source => "none"})
expect(s.code).to eq 204

eventually "Pools have no metadata when 'pool_metadata_source' => 'none'" do
sps = pools.list({stake: 1000})
sps.select{|p| p['metadata']}.size == 0
end

end
end

describe CardanoWallet::Shelley::Wallets do
Expand Down

0 comments on commit ea3cc76

Please sign in to comment.