SendKeys test now buys sessions in all of a circuit

This commit is contained in:
David Vennik
2023-01-14 21:15:42 +00:00
parent 2fb0a559c1
commit 16cc2aa87a
3 changed files with 24 additions and 15 deletions

View File

@@ -141,28 +141,35 @@ func TestSendKeys(t *testing.T) {
quit.Q()
t.Error("SendKeys got stuck")
}()
// Create a new payment and drop on the payment channel.
sess := session.New()
pmt := sess.ToPayment(1000000)
clients[1].PaymentChan <- pmt
var sess [5]*session.OnionSkin
var pmt [5]*node.Payment
for i := range clients[1:] {
// Create a new payment and drop on the payment channel.
sess[i] = session.New()
pmt[i] = sess[i].ToPayment(1000000)
clients[i+1].PaymentChan <- pmt[i]
}
// Send the keys.
var circuit node.Circuit
for i := range circuit {
circuit[i] = clients[0].Sessions[i+1]
}
var hdr, pld [5]*prv.Key
hdr[0], pld[0] = sess.Header, sess.Payload
sk := wire.SendKeys(pmt.ID, hdr, pld, clients[0].Node,
for i := range hdr {
hdr[i], pld[i] = sess[i].Header, sess[i].Payload
}
cnf := nonce.NewID()
sk := wire.SendKeys(cnf, hdr, pld, clients[0].Node,
circuit, clients[0].KeySet)
clients[0].RegisterConfirmation(func(cf nonce.ID) {
log.T.S("received payment confirmation ID", cf)
if cf != pmt.ID {
if cf != cnf {
t.Errorf("did not receive expected confirmation, got:"+
" %x expected: %x", cf, pmt.ID)
" %x expected: %x", cf, cnf)
t.FailNow()
}
quit.Q()
}, pmt.ID)
}, cnf)
o := sk.Assemble()
b := wire.EncodeOnion(o)
clients[0].Send(clients[0].Nodes[0].AddrPort, b)
@@ -170,4 +177,5 @@ func TestSendKeys(t *testing.T) {
for _, v := range clients {
v.Shutdown()
}
}

View File

@@ -86,7 +86,7 @@ func (cl *Client) runner() (out bool) {
log.I.S("unrecognised packet", b)
}
case p := <-cl.PaymentChan:
log.T.S("incoming payment", p)
log.T.S("incoming payment", cl.AddrPort.String(), p)
cl.PendingPayments = cl.PendingPayments.Add(p)
}
return
@@ -98,9 +98,10 @@ func (cl *Client) session(on *session.OnionSkin, b slice.Bytes,
log.T.S("incoming session", on.PreimageHash())
pi := cl.PendingPayments.FindPreimage(on.PreimageHash())
if pi != nil {
log.T.F("Adding session %x", pi.ID)
cl.Sessions = append(cl.Sessions, node.NewSession(pi.ID,
cl.Node, pi.Amount, on.Header, on.Payload))
ss := node.NewSession(pi.ID,
cl.Node, pi.Amount, on.Header, on.Payload)
cl.Sessions = append(cl.Sessions, ss)
log.T.F("Adding session %x\n", pi.ID)
cl.PendingPayments = cl.PendingPayments.Delete(pi.Preimage)
b = append(b[*c:], slice.NoisePad(int(*c))...)
cl.Node.Send(b)

View File

@@ -10,9 +10,9 @@ var (
// GitRef is the gitref, as in refs/heads/branchname.
GitRef = "refs/heads/protocol"
// ParentGitCommit is the commit hash of the parent HEAD.
ParentGitCommit = "c317386793efa27a1a14f4a3c6e65cbf718b236a"
ParentGitCommit = "085c068d47046ba31c911c7ca226be6fcf32634b"
// BuildTime stores the time when the current binary was built.
BuildTime = "2023-01-14T16:39:59Z"
BuildTime = "2023-01-14T21:15:42Z"
// SemVer lists the (latest) git tag on the release.
SemVer = "v0.1.7"
// PathBase is the path base returned from runtime caller.