lnsocket

A minimal C library for connecting to the lightning network
git clone git://jb55.com/lnsocket
Log | Files | Refs | Submodules | README | LICENSE

connection.js (895B)


      1 
      2 
      3 const t = require('tap')
      4 const LNSocket = require('../')
      5 
      6 t.test('connection works', async (t) => {
      7 	const ln = await LNSocket()
      8 
      9 	ln.genkey()
     10 
     11 	const badkey = "0000000000000000000000000000000000000000000000000000000000000000"
     12 	if (ln.setkey(badkey))
     13 		t.ok(false, "expected zero setkey to fail")
     14 
     15 	const goodkey = "9a5419eacf204a917cf06d5f830e48bc1fcb3e33bb60932e837697c8b7718f6f"
     16 	if (!ln.setkey(goodkey))
     17 		t.ok(false, "expected goodkey to succeed")
     18 
     19 	const nodeid = "03f3c108ccd536b8526841f0a5c58212bb9e6584a1eb493080e7c1cc34f82dad71"
     20 	await ln.connect_and_init(nodeid, "24.84.152.187")
     21 
     22 	t.ok(ln.connected, "connection works")
     23 
     24 	const rune = "APaeUhcGPAMQwgV1Kn-hRRs5Bi4-D1nrfsHfCoTLl749MTAmbWV0aG9kPWdldGluZm8="
     25 	const res = await ln.rpc({ method: "getinfo", rune })
     26 
     27 	t.ok(res.result, "didn't get result")
     28 	t.ok(res.result.id === nodeid, "nodeid is wrong!?")
     29 
     30 	ln.destroy()
     31 	t.end()
     32 })