Relay acid test

This commit is contained in:
Alex Gleason 2024-03-20 18:42:40 -05:00
parent 569d38a137
commit 48eb90770a
No known key found for this signature in database
GPG Key ID: 7211D1F99744FBB7
2 changed files with 61 additions and 0 deletions

60
acid.go Normal file
View File

@ -0,0 +1,60 @@
package main
import (
"context"
"fmt"
"github.com/nbd-wtf/go-nostr"
"github.com/nbd-wtf/go-nostr/nip11"
"github.com/urfave/cli/v2"
)
var acid = &cli.Command{
Name: "acid",
Usage: "tests a relay for spec compliance",
Description: `example:
nak acid nostr.wine`,
ArgsUsage: "<relay-url>",
Action: func(c *cli.Context) error {
url := c.Args().Get(0)
if url == "" {
return fmt.Errorf("specify the <relay-url>")
}
ctx := context.Background()
relay, err := nostr.RelayConnect(ctx, url)
if err != nil {
panic(err)
}
sk := nostr.GeneratePrivateKey()
pub, _ := nostr.GetPublicKey(sk)
// Test 1: Get the relay's information document
_, err11 := nip11.Fetch(c.Context, url)
if err11 != nil {
fmt.Println("NIP-11... FAIL")
} else {
fmt.Println("NIP-11... PASS")
}
// Test 2: Publish an event
ev := nostr.Event{
PubKey: pub,
CreatedAt: nostr.Now(),
Kind: nostr.KindTextNote,
Tags: nil,
Content: "Hello World!",
}
ev.Sign(sk)
if publishErr := relay.Publish(ctx, ev); publishErr != nil {
fmt.Println("Publish event... FAIL")
} else {
fmt.Println("Publish event... PASS")
}
return nil
},
}

View File

@ -24,6 +24,7 @@ var app = &cli.App{
verify,
relay,
bunker,
acid,
},
Flags: []cli.Flag{
&cli.BoolFlag{