207 lines
6.9 KiB
Ruby
207 lines
6.9 KiB
Ruby
require 'rails_helper'
|
|
|
|
RSpec.describe NostrManager::VerifyZapRequest, type: :model do
|
|
describe "Signature invalid" do
|
|
let(:event) {
|
|
Nostr::Event.new(
|
|
id: "3cf02d7f0ccd9711c25098fc50b3a7ab880326e4e51cc8c7a7b59f147cff4fff",
|
|
pubkey: "730b43e6f62c2ab22710b046e481802c8ac1108ed2cb9c21dff808d57ba24b6c",
|
|
created_at: 1712487443,
|
|
kind: 9734,
|
|
tags: [
|
|
["relays", "wss://nostr.kosmos.org", "wss://relay.example.com"],
|
|
["p", "07e188a1ff87ce171d517b8ed2bb7a31b1d3453a0db3b15379ec07b724d232f3"]],
|
|
content: "",
|
|
sig: "1234562bac4267a107ab5c3368f504b4f11b8e3b5ae875a1d63c74d6934138d2521dc35815b6f534fc5d803cbf633736d871886368bb8f92c4ad3837a68a06f2"
|
|
)
|
|
}
|
|
|
|
subject {
|
|
NostrManager::VerifyZapRequest.call(amount: 100000, event: event, lnurl: nil)
|
|
}
|
|
|
|
it "returns false" do
|
|
expect(subject).to be(false)
|
|
end
|
|
end
|
|
|
|
describe "p tag missing" do
|
|
let(:event) {
|
|
Nostr::Event.new(
|
|
id: "eb53c5e728b625831e318c7ab09373502dd4a41ed11c17f80f32fd1c3fe1252b",
|
|
pubkey: "730b43e6f62c2ab22710b046e481802c8ac1108ed2cb9c21dff808d57ba24b6c",
|
|
created_at: 1712580669,
|
|
kind: 9734,
|
|
tags: [["relays", "wss://nostr.kosmos.org","wss://relay.example.com"]],
|
|
content: "",
|
|
sig: "8e22dcb3e91d080c9549ea0808b018194cc352dde3056a4911796d6f0239de7e1955f287c7e6769909e59ab0ffa09e307178c32128dc451823fb00102ed7e80a"
|
|
)
|
|
}
|
|
|
|
subject {
|
|
NostrManager::VerifyZapRequest.call(amount: 100000, event: event, lnurl: nil)
|
|
}
|
|
|
|
it "returns false" do
|
|
expect(subject).to be(false)
|
|
end
|
|
end
|
|
|
|
describe "p tag not a valid pubkey" do
|
|
let(:event) {
|
|
Nostr::Event.new(
|
|
id: "f2c23f038cf4d0307147d40ddceb87e34ee94acf632f5a67217a55a0b41c5d95",
|
|
pubkey: "730b43e6f62c2ab22710b046e481802c8ac1108ed2cb9c21dff808d57ba24b6c",
|
|
created_at: 1712581702,
|
|
kind: 9734,
|
|
tags: [
|
|
["relays", "wss://nostr.kosmos.org","wss://relay.example.com"],
|
|
["p","123456abcdef"]
|
|
],
|
|
content: "",
|
|
sig: "b33e6b231273d38629f5efb86325ce3b4e02a7d84dfa1f37167ca2de8392cea654ae34000fc365ddfc6e21dc8ce2365fcb000ccb9064fbbcd54c7ea4a943955b"
|
|
)
|
|
}
|
|
|
|
subject {
|
|
NostrManager::VerifyZapRequest.call(amount: 100000, event: event, lnurl: nil)
|
|
}
|
|
|
|
it "returns false" do
|
|
expect(subject).to be(false)
|
|
end
|
|
end
|
|
|
|
describe "Minimum valid request" do
|
|
let(:event) {
|
|
Nostr::Event.new(
|
|
id: "3cf02d7f0ccd9711c25098fc50b3a7ab880326e4e51cc8c7a7b59f147cff4fff",
|
|
pubkey: "730b43e6f62c2ab22710b046e481802c8ac1108ed2cb9c21dff808d57ba24b6c",
|
|
created_at: 1712487443,
|
|
kind: 9734,
|
|
tags: [
|
|
["relays", "wss://nostr.kosmos.org", "wss://relay.example.com"],
|
|
["p", "07e188a1ff87ce171d517b8ed2bb7a31b1d3453a0db3b15379ec07b724d232f3"]],
|
|
content: "",
|
|
sig: "e9e9bb2bac4267a107ab5c3368f504b4f11b8e3b5ae875a1d63c74d6934138d2521dc35815b6f534fc5d803cbf633736d871886368bb8f92c4ad3837a68a06f2"
|
|
)
|
|
}
|
|
|
|
subject {
|
|
NostrManager::VerifyZapRequest.call(amount: 100000, event: event, lnurl: nil)
|
|
}
|
|
|
|
it "returns true" do
|
|
expect(subject).to be(true)
|
|
end
|
|
end
|
|
|
|
describe "Optional amount property" do
|
|
describe "does not match given amount" do
|
|
let(:event) {
|
|
Nostr::Event.new(
|
|
id: "be3d3ba15a257546f6fbba849d4717641fd4ea9f21ae6e9278a045f31d212c5e",
|
|
pubkey: "730b43e6f62c2ab22710b046e481802c8ac1108ed2cb9c21dff808d57ba24b6c",
|
|
created_at: 1712579812,
|
|
kind: 9734,
|
|
tags: [
|
|
["relays", "wss://nostr.kosmos.org","wss://relay.example.com"],
|
|
["p", "07e188a1ff87ce171d517b8ed2bb7a31b1d3453a0db3b15379ec07b724d232f3"],
|
|
["amount", "21000"]
|
|
],
|
|
content: "",
|
|
sig: "2ca9cfd0fdaf43dd8a50ab586e83da4bd9d592def8ed198536f5e3e7aad3537818687e42d98eb61d60e33dbd848c1eecf72b68fd98376bbabdab7e029e810869"
|
|
)
|
|
}
|
|
|
|
subject {
|
|
NostrManager::VerifyZapRequest.call(amount: 100000, event: event, lnurl: nil)
|
|
}
|
|
|
|
it "returns false" do
|
|
expect(subject).to be(false)
|
|
end
|
|
end
|
|
|
|
describe "matches given amount" do
|
|
let(:event) {
|
|
Nostr::Event.new(
|
|
id: "be3d3ba15a257546f6fbba849d4717641fd4ea9f21ae6e9278a045f31d212c5e",
|
|
pubkey: "730b43e6f62c2ab22710b046e481802c8ac1108ed2cb9c21dff808d57ba24b6c",
|
|
created_at: 1712579812,
|
|
kind: 9734,
|
|
tags: [
|
|
["relays", "wss://nostr.kosmos.org","wss://relay.example.com"],
|
|
["p", "07e188a1ff87ce171d517b8ed2bb7a31b1d3453a0db3b15379ec07b724d232f3"],
|
|
["amount", "21000"]
|
|
],
|
|
content: "",
|
|
sig: "2ca9cfd0fdaf43dd8a50ab586e83da4bd9d592def8ed198536f5e3e7aad3537818687e42d98eb61d60e33dbd848c1eecf72b68fd98376bbabdab7e029e810869"
|
|
)
|
|
}
|
|
|
|
subject {
|
|
NostrManager::VerifyZapRequest.call(amount: 21000, event: event, lnurl: nil)
|
|
}
|
|
|
|
it "returns true" do
|
|
expect(subject).to be(true)
|
|
end
|
|
end
|
|
end
|
|
|
|
describe "Optional amount property" do
|
|
describe "does not match given amount" do
|
|
let(:event) {
|
|
Nostr::Event.new(
|
|
id: "be3d3ba15a257546f6fbba849d4717641fd4ea9f21ae6e9278a045f31d212c5e",
|
|
pubkey: "730b43e6f62c2ab22710b046e481802c8ac1108ed2cb9c21dff808d57ba24b6c",
|
|
created_at: 1712579812,
|
|
kind: 9734,
|
|
tags: [
|
|
["relays", "wss://nostr.kosmos.org","wss://relay.example.com"],
|
|
["p", "07e188a1ff87ce171d517b8ed2bb7a31b1d3453a0db3b15379ec07b724d232f3"],
|
|
["amount", "21000"]
|
|
],
|
|
content: "",
|
|
sig: "2ca9cfd0fdaf43dd8a50ab586e83da4bd9d592def8ed198536f5e3e7aad3537818687e42d98eb61d60e33dbd848c1eecf72b68fd98376bbabdab7e029e810869"
|
|
)
|
|
}
|
|
|
|
subject {
|
|
NostrManager::VerifyZapRequest.call(amount: 100000, event: event, lnurl: nil)
|
|
}
|
|
|
|
it "returns false" do
|
|
expect(subject).to be(false)
|
|
end
|
|
end
|
|
|
|
describe "matches given amount" do
|
|
let(:event) {
|
|
Nostr::Event.new(
|
|
id: "be3d3ba15a257546f6fbba849d4717641fd4ea9f21ae6e9278a045f31d212c5e",
|
|
pubkey: "730b43e6f62c2ab22710b046e481802c8ac1108ed2cb9c21dff808d57ba24b6c",
|
|
created_at: 1712579812,
|
|
kind: 9734,
|
|
tags: [
|
|
["relays", "wss://nostr.kosmos.org","wss://relay.example.com"],
|
|
["p", "07e188a1ff87ce171d517b8ed2bb7a31b1d3453a0db3b15379ec07b724d232f3"],
|
|
["amount", "21000"]
|
|
],
|
|
content: "",
|
|
sig: "2ca9cfd0fdaf43dd8a50ab586e83da4bd9d592def8ed198536f5e3e7aad3537818687e42d98eb61d60e33dbd848c1eecf72b68fd98376bbabdab7e029e810869"
|
|
)
|
|
}
|
|
|
|
subject {
|
|
NostrManager::VerifyZapRequest.call(amount: 21000, event: event, lnurl: nil)
|
|
}
|
|
|
|
it "returns true" do
|
|
expect(subject).to be(true)
|
|
end
|
|
end
|
|
end
|
|
end
|