From 1d902adf6d2de16f6e6d036a3c6cf0279bc7e9c6 Mon Sep 17 00:00:00 2001 From: Viktor Vsk Date: Sun, 19 Nov 2023 18:16:54 +0100 Subject: [PATCH] Drop support for NIP-26 because no one uses it literally and it seems not even planning --- README.md | 1 - app/jobs/delete_expired_event_nip40.rb | 2 +- app/models/concerns/nostr/nip1.rb | 39 ++------- app/models/concerns/nostr/nip26.rb | 70 ---------------- app/models/concerns/nostr/nip9.rb | 2 +- app/models/event.rb | 1 - .../subscription_matcher_query_builder.rb | 1 - ...31119170827_drop_event_delegators_table.rb | 16 ++++ db/structure.sql | 80 +------------------ docs/ARCHITECTURE.md | 2 +- spec/factories/event_delegators.rb | 6 -- spec/factories/events.rb | 4 - spec/models/event_spec.rb | 4 +- spec/nips/nip01_spec.rb | 6 +- spec/nips/nip04_spec.rb | 6 +- spec/nips/nip26_spec.rb | 41 ---------- spec/rails_helper.rb | 7 -- 17 files changed, 34 insertions(+), 254 deletions(-) delete mode 100644 app/models/concerns/nostr/nip26.rb create mode 100644 db/migrate/20231119170827_drop_event_delegators_table.rb delete mode 100644 spec/factories/event_delegators.rb delete mode 100644 spec/nips/nip26_spec.rb diff --git a/README.md b/README.md index 8b79aca..3f37fbb 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,6 @@ This is an implementation of the [Nostr protocol](https://github.com/nostr-proto * [NIP-09: Event Deletion](https://github.com/nostr-protocol/nips/blob/master/09.md) * [NIP-11: Relay Information Document](https://github.com/nostr-protocol/nips/blob/master/11.md) * [NIP-13: Proof of Work](https://github.com/nostr-protocol/nips/blob/master/13.md) -* [NIP-26: Delegated Event Signing](https://github.com/nostr-protocol/nips/blob/master/26.md) * [NIP-28: Public Chat](https://github.com/nostr-protocol/nips/blob/master/28.md) Treats kind 41 event as replaceable * [NIP-40: Expiration Timestamp](https://github.com/nostr-protocol/nips/blob/master/40.md) * [NIP-42: Authentication of clients to relays](https://github.com/nostr-protocol/nips/blob/master/42.md) diff --git a/app/jobs/delete_expired_event_nip40.rb b/app/jobs/delete_expired_event_nip40.rb index dfe679d..a0772f7 100644 --- a/app/jobs/delete_expired_event_nip40.rb +++ b/app/jobs/delete_expired_event_nip40.rb @@ -3,6 +3,6 @@ class DeleteExpiredEventNip40 sidekiq_options queue: "nostr.nip40" def perform(sha256) - Event.includes(:event_delegator, :searchable_content).where("LOWER(events.sha256) = ?", sha256).destroy_all + Event.includes(:searchable_content).where("LOWER(events.sha256) = ?", sha256).destroy_all end end diff --git a/app/models/concerns/nostr/nip1.rb b/app/models/concerns/nostr/nip1.rb index 1ac405c..644f1e3 100644 --- a/app/models/concerns/nostr/nip1.rb +++ b/app/models/concerns/nostr/nip1.rb @@ -160,7 +160,7 @@ def delete_older_replaceable Event.where(author_id: author_id, kind: kind, created_at: created_at).where("LOWER(events.sha256) > ?", sha256.downcase).pluck(:id) ].flatten.reject(&:blank?) - Event.includes(:event_delegator, :searchable_content).where(id: to_delete.uniq).destroy_all if to_delete.present? + Event.includes(:searchable_content).where(id: to_delete.uniq).destroy_all if to_delete.present? end def must_not_be_ephemeral @@ -193,7 +193,7 @@ def delete_older_parameterized_replaceable Event.joins(:searchable_tags).where("LOWER(searchable_tags.value) = ?", d_tag_value.downcase).where(author_id: author_id, kind: kind, created_at: created_at, searchable_tags: {name: "d"}).where("LOWER(events.sha256) > ?", sha256.downcase).pluck(:id) ].flatten.reject(&:blank?) - Event.includes(:event_delegator, :searchable_content).where(id: to_delete).destroy_all + Event.includes(:searchable_content).where(id: to_delete).destroy_all end def must_be_newer_than_existing_parameterized_replaceable @@ -247,24 +247,18 @@ def by_nostr_filters(filter_set, subscriber_pubkey = nil, count_request = nil) where_clause = <<~SQL events.kind IN (:kinds) OR ( - events.kind = 4 AND (LOWER(authors.pubkey) = :pubkey OR LOWER(delegator_authors.pubkey) = :pubkey OR LOWER(p_tags.value) = :pubkey) + events.kind = 4 AND (LOWER(authors.pubkey) = :pubkey OR LOWER(p_tags.value) = :pubkey) ) SQL - # NIP-26 - # TODO: check performance rel .joins(:author) .joins("LEFT JOIN searchable_tags AS p_tags ON p_tags.event_id = events.id AND p_tags.name = 'p'") - .joins("LEFT JOIN event_delegators ON event_delegators.event_id = events.id") - .joins("LEFT JOIN authors AS delegator_authors ON delegator_authors.id = event_delegators.author_id") .where(where_clause, kinds: value, pubkey: subscriber_pubkey.downcase) else rel .joins(:author) .joins("LEFT JOIN searchable_tags AS p_tags ON p_tags.event_id = events.id AND p_tags.name = 'p'") - .joins("LEFT JOIN event_delegators ON event_delegators.event_id = events.id") - .joins("LEFT JOIN authors AS delegator_authors ON delegator_authors.id = event_delegators.author_id") - .where("events.kind = 4 AND (LOWER(authors.pubkey) = :pubkey OR LOWER(delegator_authors.pubkey) = :pubkey OR LOWER(p_tags.value) = :pubkey)", pubkey: subscriber_pubkey.downcase) + .where("events.kind = 4 AND (LOWER(authors.pubkey) = :pubkey OR LOWER(p_tags.value) = :pubkey)", pubkey: subscriber_pubkey.downcase) end else rel.where(kind: value) @@ -311,30 +305,7 @@ def by_nostr_filters(filter_set, subscriber_pubkey = nil, count_request = nil) RELAY_CONFIG.default_filter_limit end - if filter_set.key?("authors") - - # NIP-26 - - # pubkey max length is 64 so we don't need a predicate match in this case - where_clause = filter_set["authors"].map { |pubkey| "LOWER(delegator_authors.pubkey) = ?" }.join(" OR ") - - delegator_rel = by_nostr_filters(filter_set.except("authors"), subscriber_pubkey, count_request).joins(:author) - .joins("LEFT JOIN event_delegators ON event_delegators.event_id = events.id") - .joins("LEFT JOIN authors AS delegator_authors ON delegator_authors.id = event_delegators.author_id") - .where(where_clause, *filter_set["authors"].map(&:downcase)) - union = <<~SQL - (#{rel.limit(filter_limit).to_sql}) - - UNION - - (#{delegator_rel.limit(filter_limit).to_sql}) - SQL - - LazySql.new(klass: "Event", sql: union) - - else - rel.limit(filter_limit) - end + rel.limit(filter_limit) end end end diff --git a/app/models/concerns/nostr/nip26.rb b/app/models/concerns/nostr/nip26.rb deleted file mode 100644 index 9b50493..0000000 --- a/app/models/concerns/nostr/nip26.rb +++ /dev/null @@ -1,70 +0,0 @@ -module Nostr - module Nip26 - extend ActiveSupport::Concern - - included do - validate :validate_delegation_nip26 - has_one :event_delegator, dependent: :destroy - before_create do - if tags.any? { |t| t.first === "delegation" } - - delegator_pubkey = tags.find { |t| t.first === "delegation" }.second - - build_event_delegator(author: Author.from_pubkey(delegator_pubkey)) - end - end - - def delegation_tag_pubkey - tags.find { |t| t.first == "delegation" }&.second - end - - private - - def validate_delegation_nip26 - return if tags.none? { |t| t.first === "delegation" } - - delegation_tag = tags.find { |t| t.first === "delegation" } - delegation_pubkey, condition_string, delegation_sig = delegation_tag[1..] - - if condition_string.blank? || delegation_sig.blank? - errors.add(:tags, "'delegation' required elements missing: condition and/or signature") - end - - delegation_string = "nostr:delegation:#{delegation_pubkey}:#{condition_string}" - - schnorr_params = { - message: [Digest::SHA256.hexdigest(delegation_string)].pack("H*"), - pubkey: [delegation_pubkey].pack("H*"), - sig: [delegation_sig].pack("H*") - } - - delegated_kinds = condition_string.scan(/kind=(\d{1,})/) - min_created_at = condition_string.scan(/created_at>(\d{1,})/).flatten.first&.to_i - max_created_at = condition_string.scan(/created_at<(\d{1,})/).flatten.first&.to_i - - if delegated_kinds && !kind.to_s.in?(delegated_kinds.flatten) - errors.add(:tags, "'delegation' kind doesn't allow kind #{kind}") - end - if min_created_at && created_at.to_i < min_created_at - errors.add(:tags, "'delegation' created_at < event created_at minimum") - end - if max_created_at && created_at.to_i > max_created_at - errors.add(:tags, "'delegation' created_at > event created_at maximum") - end - unless /\A[0-9a-f]{64}\Z/.match?(delegation_pubkey) - errors.add(:tags, "'delegation' pubkey must be a valid 64 characters hex") - end - - sig_is_valid = begin - Secp256k1::SchnorrSignature.from_data(schnorr_params[:sig]).verify(schnorr_params[:message], Secp256k1::XOnlyPublicKey.from_data(schnorr_params[:pubkey])) - rescue Secp256k1::DeserializationError - false - end - - unless sig_is_valid - errors.add(:tags, "'delegation' signature must be valid") - end - end - end - end -end diff --git a/app/models/concerns/nostr/nip9.rb b/app/models/concerns/nostr/nip9.rb index 8e47616..918548b 100644 --- a/app/models/concerns/nostr/nip9.rb +++ b/app/models/concerns/nostr/nip9.rb @@ -36,7 +36,7 @@ def process_delete_event_nip_9 if events_ids_to_delete.present? DeleteEvent.upsert_all(delete_events_to_upsert, unique_by: %i[sha256 author_id]) to_delete_events_ids = Event.where(author_id: author.id).where("LOWER(events.sha256) IN (?)", events_ids_to_delete).where.not(kind: 5).pluck(:id) - Event.includes(:event_delegator, :searchable_content).where(id: to_delete_events_ids).destroy_all + Event.includes(:searchable_content).where(id: to_delete_events_ids).destroy_all end end end diff --git a/app/models/event.rb b/app/models/event.rb index ce133ea..50a8375 100644 --- a/app/models/event.rb +++ b/app/models/event.rb @@ -2,7 +2,6 @@ class Event < ApplicationRecord include Nostr::Nip1 include Nostr::Nip9 include Nostr::Nip13 - include Nostr::Nip26 include Nostr::Nip40 include Nostr::Nip42 include Nostr::Nip50 diff --git a/app/models/subscription_matcher_query_builder.rb b/app/models/subscription_matcher_query_builder.rb index 31315f3..649d349 100644 --- a/app/models/subscription_matcher_query_builder.rb +++ b/app/models/subscription_matcher_query_builder.rb @@ -5,7 +5,6 @@ class SubscriptionMatcherQueryBuilder def initialize(event) authors = [ event.pubkey, - event.delegation_tag_pubkey, SubscriptionQueryBuilder::REDIS_SEARCH_TAG_ANY_VALUE ].reject(&:blank?).join(" | ") diff --git a/db/migrate/20231119170827_drop_event_delegators_table.rb b/db/migrate/20231119170827_drop_event_delegators_table.rb new file mode 100644 index 0000000..3ebbf54 --- /dev/null +++ b/db/migrate/20231119170827_drop_event_delegators_table.rb @@ -0,0 +1,16 @@ +class DropEventDelegatorsTable < ActiveRecord::Migration[7.0] + def up + drop_table :event_delegators + end + + def down + create_table :event_delegators do |t| + t.references :event, index: false, foreign_key: true, null: false + t.references :author, index: false, foreign_key: true, null: false + end + + add_index :event_delegators, :event_id, unique: true + add_index :event_delegators, %i[event_id author_id] + execute("CLUSTER event_delegators USING index_event_delegators_on_event_id_and_author_id") + end +end diff --git a/db/structure.sql b/db/structure.sql index 631c57e..5acb151 100644 --- a/db/structure.sql +++ b/db/structure.sql @@ -125,36 +125,6 @@ CREATE TABLE public.delete_events ( ); --- --- Name: event_delegators; Type: TABLE; Schema: public; Owner: - --- - -CREATE TABLE public.event_delegators ( - id bigint NOT NULL, - event_id bigint NOT NULL, - author_id bigint NOT NULL -); - - --- --- Name: event_delegators_id_seq; Type: SEQUENCE; Schema: public; Owner: - --- - -CREATE SEQUENCE public.event_delegators_id_seq - START WITH 1 - INCREMENT BY 1 - NO MINVALUE - NO MAXVALUE - CACHE 1; - - --- --- Name: event_delegators_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: - --- - -ALTER SEQUENCE public.event_delegators_id_seq OWNED BY public.event_delegators.id; - - -- -- Name: events; Type: TABLE; Schema: public; Owner: - -- @@ -447,13 +417,6 @@ ALTER TABLE ONLY public.author_subscriptions ALTER COLUMN id SET DEFAULT nextval ALTER TABLE ONLY public.authors ALTER COLUMN id SET DEFAULT nextval('public.authors_id_seq'::regclass); --- --- Name: event_delegators id; Type: DEFAULT; Schema: public; Owner: - --- - -ALTER TABLE ONLY public.event_delegators ALTER COLUMN id SET DEFAULT nextval('public.event_delegators_id_seq'::regclass); - - -- -- Name: events id; Type: DEFAULT; Schema: public; Owner: - -- @@ -527,14 +490,6 @@ ALTER TABLE ONLY public.authors ADD CONSTRAINT authors_pkey PRIMARY KEY (id); --- --- Name: event_delegators event_delegators_pkey; Type: CONSTRAINT; Schema: public; Owner: - --- - -ALTER TABLE ONLY public.event_delegators - ADD CONSTRAINT event_delegators_pkey PRIMARY KEY (id); - - -- -- Name: events events_pkey; Type: CONSTRAINT; Schema: public; Owner: - -- @@ -650,22 +605,6 @@ CREATE UNIQUE INDEX index_delete_events_on_sha256_and_author_id ON public.delete ALTER TABLE public.delete_events CLUSTER ON index_delete_events_on_sha256_and_author_id; --- --- Name: index_event_delegators_on_event_id; Type: INDEX; Schema: public; Owner: - --- - -CREATE UNIQUE INDEX index_event_delegators_on_event_id ON public.event_delegators USING btree (event_id); - - --- --- Name: index_event_delegators_on_event_id_and_author_id; Type: INDEX; Schema: public; Owner: - --- - -CREATE INDEX index_event_delegators_on_event_id_and_author_id ON public.event_delegators USING btree (event_id, author_id); - -ALTER TABLE public.event_delegators CLUSTER ON index_event_delegators_on_event_id_and_author_id; - - -- -- Name: index_events_for_replaceable; Type: INDEX; Schema: public; Owner: - -- @@ -869,22 +808,6 @@ ALTER TABLE ONLY public.invoices ADD CONSTRAINT fk_rails_32fc3ccfac FOREIGN KEY (author_id) REFERENCES public.authors(id); --- --- Name: event_delegators fk_rails_3df25f44ef; Type: FK CONSTRAINT; Schema: public; Owner: - --- - -ALTER TABLE ONLY public.event_delegators - ADD CONSTRAINT fk_rails_3df25f44ef FOREIGN KEY (author_id) REFERENCES public.authors(id); - - --- --- Name: event_delegators fk_rails_5f94d04b9b; Type: FK CONSTRAINT; Schema: public; Owner: - --- - -ALTER TABLE ONLY public.event_delegators - ADD CONSTRAINT fk_rails_5f94d04b9b FOREIGN KEY (event_id) REFERENCES public.events(id); - - -- -- Name: user_pubkeys fk_rails_66431c7d01; Type: FK CONSTRAINT; Schema: public; Owner: - -- @@ -978,6 +901,7 @@ INSERT INTO "schema_migrations" (version) VALUES ('20230827170307'), ('20231025122455'), ('20231105000145'), -('20231105000543'); +('20231105000543'), +('20231119170827'); diff --git a/docs/ARCHITECTURE.md b/docs/ARCHITECTURE.md index 6535d01..2ae1a76 100644 --- a/docs/ARCHITECTURE.md +++ b/docs/ARCHITECTURE.md @@ -130,7 +130,7 @@ Mirrors is a process that is responsible to launch Websocket Clients that connec ### Database Tested against 14,15 and 16 versions of PostgreSQL but at the moment there are no version-specific SQL so in theory many versions should be compatible. -Database currently has the following core tables: `authors`, `delete_events`, `events`, `searchable_tags`, `event_delegators`, `trusted_authors` which are slightly optimized for storage (by normalizing `authors` public keys for example). +Database currently has the following core tables: `authors`, `delete_events`, `events`, `searchable_tags`, `trusted_authors` which are slightly optimized for storage (by normalizing `authors` public keys for example). And secondary, not Nostr-specific tables: `users`, `user_pubkeys`, `relay_mirrors`, `invoices`, `author_subscriptions`. Proper indexing strategy is a subject to change. diff --git a/spec/factories/event_delegators.rb b/spec/factories/event_delegators.rb deleted file mode 100644 index 2d2ba13..0000000 --- a/spec/factories/event_delegators.rb +++ /dev/null @@ -1,6 +0,0 @@ -FactoryBot.define do - factory :event_delegator do - event - author - end -end diff --git a/spec/factories/events.rb b/spec/factories/events.rb index c5abddd..404d69c 100644 --- a/spec/factories/events.rb +++ b/spec/factories/events.rb @@ -4,10 +4,6 @@ content { "" } created_at { Time.now } - trait :delegated_event do - tags { [["delegation", NIP_26_TAG[:pk], NIP_26_TAG[:conditions], NIP_26_TAG[:sig]]] } - end - after(:build) do |event| if event.pubkey.blank? _random_fake_signer_name, credentials = FAKE_CREDENTIALS.to_a.sample diff --git a/spec/models/event_spec.rb b/spec/models/event_spec.rb index 669c2c0..0a2de05 100644 --- a/spec/models/event_spec.rb +++ b/spec/models/event_spec.rb @@ -19,8 +19,8 @@ it "destroys event" do kind2_event.save! - kind2_event_with_event_delegators_included = Event.includes(:event_delegator, :searchable_content).where(id: kind2_event).first - expect { kind2_event_with_event_delegators_included.destroy }.to change { kind2_event_with_event_delegators_included.persisted? }.from(true).to(false) + kind2_event_with_searchable_content_included = Event.includes(:searchable_content).where(id: kind2_event).first + expect { kind2_event_with_searchable_content_included.destroy }.to change { kind2_event_with_searchable_content_included.persisted? }.from(true).to(false) end context "raises ActiveRecord::ReadOnlyRecord when" do diff --git a/spec/nips/nip01_spec.rb b/spec/nips/nip01_spec.rb index cad334b..863bf16 100644 --- a/spec/nips/nip01_spec.rb +++ b/spec/nips/nip01_spec.rb @@ -126,7 +126,7 @@ # expect(Event.by_nostr_filters({"ids" => ["bf84a73d1e6a1708b1c4dc5555a78f342ef29abfd469a091ca4f34533399c95f", event_with_tagsith_searchable_tags.sha256.first(5)]}).count).to eq(1) expect(Event.by_nostr_filters({"authors" => ["8e0d3"]}).count).to eq(0) - expect(Event.by_nostr_filters({"authors" => ["8e0d3d3eb2881ec137a11debe736a9086715a8c8beeeda615780064d68bc25dd"]}).count).to eq(1) + expect(Event.by_nostr_filters({"authors" => ["8e0d3d3eb2881ec137a11debe736a9086715a8c8beeeda615780064d68bc25dd"]}).count).to eq(0) expect(Event.by_nostr_filters({"authors" => ["09cd08d"]}).count).to eq(0) expect(Event.by_nostr_filters({"authors" => ["09cd08d416b78dd3e1d6c00c9e14087d803df6360fbf0acdb30106ca042ee81e"]}).count).to eq(1) expect(Event.by_nostr_filters({}).count).to eq(3) @@ -343,14 +343,14 @@ expect(MemStore.matching_pubsubs_for(event)).to match_array("C1:S1") end - it "matches author filter when author is delegated" do + it "does not match author filter when author is delegated" do parsed_json = JSON.parse(File.read(Rails.root.join(*%w[spec support nostr_event_delegated.json]))) delegated_event_params = parsed_json.merge("sha256" => parsed_json.delete("id"), "created_at" => Time.at(parsed_json["created_at"])) delegated_event = Event.new(delegated_event_params) MemStore.subscribe(cid: "C1", sid: "S1", filters: ["authors" => ["09cd08d416b78dd3e1d6c00c9e14087d803df6360fbf0acdb30106ca042ee81e"]]) MemStore.subscribe(cid: "C1", sid: "S2", filters: ["authors" => ["8e0d3d3eb2881ec137a11debe736a9086715a8c8beeeda615780064d68bc25dd"]]) - expect(MemStore.matching_pubsubs_for(delegated_event)).to match_array(["C1:S1", "C1:S2"]) + expect(MemStore.matching_pubsubs_for(delegated_event)).to match_array(["C1:S1"]) end it "matches #e and #p filters" do diff --git a/spec/nips/nip04_spec.rb b/spec/nips/nip04_spec.rb index a3be876..9a927e0 100644 --- a/spec/nips/nip04_spec.rb +++ b/spec/nips/nip04_spec.rb @@ -52,16 +52,16 @@ expect(Event.by_nostr_filters({kinds: [4]}, FAKE_CREDENTIALS[:alice][:pk]).to_a.map(&:id).sort).to eq([e1.id, e2.id].sort) end - it "finds kind 4 events by delegation" do + it "does not find kind 4 events by delegation" do tags = [ ["p", FAKE_CREDENTIALS[:alice][:pk]], ["delegation", FAKE_CREDENTIALS[:carl][:pk], "kind=4", "b05bd5636223b546d2a5f0f5875c2558647558ed94df5378ae34ac053c5cd7d40d524b1c763b7cda096eb8da0cd4ff744cd0946e895c39ea54727cb26257df1e"] ] - e1 = create(:event, kind: 4, pubkey: FAKE_CREDENTIALS[:bob][:pk], tags: tags, created_at: Time.at(1688051860)) + create(:event, kind: 4, pubkey: FAKE_CREDENTIALS[:bob][:pk], tags: tags, created_at: Time.at(1688051860)) create(:event, kind: 1, pubkey: FAKE_CREDENTIALS[:alice][:pk]) create(:event, kind: 4, pubkey: FAKE_CREDENTIALS[:alice][:pk]) - expect(Event.by_nostr_filters({kinds: [4]}, FAKE_CREDENTIALS[:carl][:pk]).to_a.map(&:id)).to eq([e1.id]) + expect(Event.by_nostr_filters({kinds: [4]}, FAKE_CREDENTIALS[:carl][:pk]).to_a.map(&:id)).to eq([]) end it "finds kind 4 events by p-tag, author, and delegation" do diff --git a/spec/nips/nip26_spec.rb b/spec/nips/nip26_spec.rb deleted file mode 100644 index b09ae7e..0000000 --- a/spec/nips/nip26_spec.rb +++ /dev/null @@ -1,41 +0,0 @@ -require "rails_helper" - -RSpec.describe "NIP-26" do - describe Event do - context "with valid delegation-tag" do - it "passes" do - parsed_json = JSON.parse(File.read(Rails.root.join(*%w[spec support nostr_event_delegated.json]))) - event_params = parsed_json.merge("sha256" => parsed_json.delete("id"), "created_at" => Time.at(parsed_json["created_at"])) - event = Event.new(event_params) - - expect(event).to be_valid - end - describe SearchableTag do - it "indexes second value" do - event = create(:event, :delegated_event, kind: 1, created_at: Time.at(1687949586 - 100)) - expect(event.event_delegator).to be_present - expect(event.event_delegator.author.pubkey).to eq(NIP_26_TAG[:pk]) - end - end - end - - context "with invalid delegation-tag" do - it "fails to persist" do - too_old_event = build(:event, :delegated_event, kind: 1, created_at: 1.year.ago) - too_new_event = build(:event, :delegated_event, kind: 1, created_at: 1.day.from_now) - invalid_kind_event = build(:event, :delegated_event, kind: 1001, created_at: 1.day.ago) - invalid_delegation_pubkey_event = build(:event, tags: [["delegation", "INVALID", "", ""]]) - - expect(too_old_event).not_to be_valid - expect(too_new_event).not_to be_valid - expect(invalid_kind_event).not_to be_valid - expect(invalid_delegation_pubkey_event).not_to be_valid - - expect(too_old_event.errors[:tags]).to include(%('delegation' created_at < event created_at minimum)) - expect(too_new_event.errors[:tags]).to include(%('delegation' created_at > event created_at maximum)) - expect(invalid_kind_event.errors[:tags]).to include(%('delegation' kind doesn't allow kind 1001)) - expect(invalid_delegation_pubkey_event.errors[:tags]).to include(%('delegation' pubkey must be a valid 64 characters hex)) - end - end - end -end diff --git a/spec/rails_helper.rb b/spec/rails_helper.rb index 2b4909e..b956e91 100644 --- a/spec/rails_helper.rb +++ b/spec/rails_helper.rb @@ -25,13 +25,6 @@ carl: {pk: "477318cfb5427b9cfc66a9fa376150c1ddbc62115ae27cef72417eb959691396", sk: "777e4f60b4aa87937e13acc84f7abcc3c93cc035cb4c1e9f7a9086dd78fffce1"} } -NIP_26_TAG = { - pk: "8e0d3d3eb2881ec137a11debe736a9086715a8c8beeeda615780064d68bc25dd", - sk: "ee35e8bb71131c02c1d7e73231daa48e9953d329a4b701f7133c8f46dd21139c", - conditions: "kind=1&created_at>1680000800&created_at<1687949586", - sig: "d890dc2d9706f0bfeba01a2a67a2b35790ac75dc6b8908dc3cd2a0d1cdf649100c9e4472477819773a3658aa152e6b7a70d6d88e238995de0155c7b1f8623804" -} - # Requires supporting ruby files with custom matchers and macros, etc, in # spec/support/ and its subdirectories. Files matching `spec/**/*_spec.rb` are # run as spec files by default. This means that files in spec/support that end