From ea3cc76526e74670a80bfeac8c2ec8260f573f8a Mon Sep 17 00:00:00 2001 From: Piotr Stachyra Date: Thu, 8 Oct 2020 09:21:43 +0200 Subject: [PATCH 1/2] Support for settings --- lib/cardano_wallet/misc.rb | 27 +++++++++++++++++++++++++++ spec/misc_spec.rb | 21 +++++++++++++++++++++ spec/shelley_spec.rb | 24 ++++++++++++++++++++++++ 3 files changed, 72 insertions(+) diff --git a/lib/cardano_wallet/misc.rb b/lib/cardano_wallet/misc.rb index 47a068e..c9c47ae 100644 --- a/lib/cardano_wallet/misc.rb +++ b/lib/cardano_wallet/misc.rb @@ -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 diff --git a/spec/misc_spec.rb b/spec/misc_spec.rb index 33c1a7f..de7efc2 100644 --- a/spec/misc_spec.rb +++ b/spec/misc_spec.rb @@ -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 diff --git a/spec/shelley_spec.rb b/spec/shelley_spec.rb index cca6b2b..4d29077 100644 --- a/spec/shelley_spec.rb +++ b/spec/shelley_spec.rb @@ -17,6 +17,8 @@ end after(:all) do + settings = CardanoWallet.new.misc.settings + s = settings.update({:pool_metadata_source => "none"}) teardown end @@ -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 From cb0fcd41d90dd1a2768f3f00f5dade9ed0bb3bb1 Mon Sep 17 00:00:00 2001 From: Piotr Stachyra Date: Thu, 8 Oct 2020 09:55:55 +0200 Subject: [PATCH 2/2] Version to 0.2.1 --- lib/cardano_wallet/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/cardano_wallet/version.rb b/lib/cardano_wallet/version.rb index 2f13762..f6380a5 100644 --- a/lib/cardano_wallet/version.rb +++ b/lib/cardano_wallet/version.rb @@ -1,3 +1,3 @@ module CardanoWallet - VERSION = "0.2.0" + VERSION = "0.2.1" end