mirror of
https://github.com/believethehype/nostrdvm.git
synced 2025-04-10 21:00:02 +02:00
added event test functions, updated relays
This commit is contained in:
parent
1fcb877a2c
commit
ec1cc8c913
@ -16,12 +16,11 @@ class DVMConfig:
|
||||
PER_UNIT_COST: float = None
|
||||
|
||||
RELAY_LIST = ["wss://relay.damus.io", "wss://nostr-pub.wellorder.net", "wss://nos.lol", "wss://nostr.wine",
|
||||
"wss://relay.nostfiles.dev", "wss://nostr.mom", "wss://nostr.oxtr.dev", "wss://relay.nostr.bg",
|
||||
"wss://relay.f7z.io", "wss://pablof7z.nostr1.com", "wss://purplepag.es", "wss://nos.lol",
|
||||
"wss://relay.snort.social", "wss://offchain.pub/",
|
||||
"wss://nostr-pub.wellorder.net"]
|
||||
"wss://nostr.mom", "wss://nostr.oxtr.dev", "wss://relay.nostr.bg",
|
||||
"wss://relay.f7z.io", "wss://pablof7z.nostr1.com", "wss://relay.nostr.net", "wss://140.f7z.io",
|
||||
"wss://relay.snort.social", "wss://offchain.pub/", "wss://relay.nostr.band"]
|
||||
|
||||
RELAY_TIMEOUT = 3
|
||||
RELAY_TIMEOUT = 5
|
||||
EXTERNAL_POST_PROCESS_TYPE = PostProcessFunctionType.NONE # Leave this on None, except the DVM is external
|
||||
LNBITS_INVOICE_KEY = '' # Will all automatically generated by default, or read from .env
|
||||
LNBITS_ADMIN_KEY = '' # In order to pay invoices, e.g. from the bot to DVMs, or reimburse users.
|
||||
|
77
tests/test_events.py
Normal file
77
tests/test_events.py
Normal file
@ -0,0 +1,77 @@
|
||||
from datetime import timedelta
|
||||
from pathlib import Path
|
||||
|
||||
import dotenv
|
||||
from nostr_sdk import Keys, Client, Tag, EventBuilder, Filter, HandleNotification, Timestamp, nip04_decrypt, \
|
||||
nip04_encrypt, EventId, Options, PublicKey
|
||||
|
||||
from nostr_dvm.utils import definitions, dvmconfig
|
||||
from nostr_dvm.utils.nostr_utils import check_and_set_private_key
|
||||
|
||||
|
||||
relay_list = dvmconfig.DVMConfig.RELAY_LIST
|
||||
keys = Keys.from_sk_str(check_and_set_private_key("test_client"))
|
||||
wait_for_send = False
|
||||
skip_disconnected_relays = True
|
||||
opts = (Options().wait_for_send(wait_for_send).send_timeout(timedelta(seconds=5))
|
||||
.skip_disconnected_relays(skip_disconnected_relays))
|
||||
|
||||
client = Client.with_opts(keys, opts)
|
||||
for relay in relay_list:
|
||||
client.add_relay(relay)
|
||||
client.connect()
|
||||
|
||||
|
||||
def test_referred_events(event_id, kinds=None):
|
||||
|
||||
if kinds is None:
|
||||
kinds = []
|
||||
|
||||
if len(kinds) > 0:
|
||||
job_id_filter = Filter().kinds(kinds).event(EventId.from_hex(event_id))
|
||||
else:
|
||||
job_id_filter = Filter().event(EventId.from_hex(event_id))
|
||||
|
||||
events = client.get_events_of([job_id_filter], timedelta(seconds=5))
|
||||
|
||||
if len(events) > 0:
|
||||
for event in events:
|
||||
print(event.as_json())
|
||||
return events[0]
|
||||
else:
|
||||
print("None")
|
||||
return None
|
||||
|
||||
|
||||
def test_all_reposts_by_user_since_days(pubkey, days):
|
||||
since_seconds = int(days) * 24 * 60 * 60
|
||||
dif = Timestamp.now().as_secs() - since_seconds
|
||||
since = Timestamp.from_secs(dif)
|
||||
|
||||
filter = Filter().author(PublicKey.from_hex(pubkey)).kinds([6]).since(since)
|
||||
events = client.get_events_of([filter], timedelta(seconds=5))
|
||||
|
||||
if len(events) > 0:
|
||||
for event in events:
|
||||
print(event.as_json())
|
||||
return events[0]
|
||||
else:
|
||||
print("None")
|
||||
return None
|
||||
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
env_path = Path('.env')
|
||||
if env_path.is_file():
|
||||
print(f'loading environment from {env_path.resolve()}')
|
||||
dotenv.load_dotenv(env_path, verbose=True, override=True)
|
||||
else:
|
||||
raise FileNotFoundError(f'.env file not found at {env_path} ')
|
||||
|
||||
# works
|
||||
test_referred_events("c70fbd4dbaad22c427d4359981d3bdddd3971ed1a38227ca2f8e5e760f58103c", definitions.EventDefinitions.ANY_RESULT)
|
||||
|
||||
#shows kind 7000 reaction but not kind 6300 result (d05e7ae9271fe2d8968cccb67c01e3458dbafa4a415e306d49b22729b088c8a1)
|
||||
test_referred_events("5635e5dd930b3c831f6ab1e348bb488f3c9aca2f13190e93ab5e5e1e1ba1835e", None)
|
||||
|
Loading…
x
Reference in New Issue
Block a user