From bf33304d1aedf45ef7a7d83ea003ace5a8373d70 Mon Sep 17 00:00:00 2001 From: Ralph Pichler Date: Thu, 19 Sep 2019 09:57:23 +0200 Subject: [PATCH] swap: fix and rename Peer.getLastSentCumulativePayout (#1769) * swap: return the last sent payout and rename to Peer.getLastSentCumulativePayout --- swap/peer.go | 6 +++--- swap/swap_test.go | 18 ++++++++++++++++++ 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/swap/peer.go b/swap/peer.go index debc23e85a..317abf926c 100644 --- a/swap/peer.go +++ b/swap/peer.go @@ -84,8 +84,8 @@ func (p *Peer) setLastSentCheque(cheque *Cheque) error { return p.swap.saveLastSentCheque(p.ID(), cheque) } -func (p *Peer) getLastCumulativePayout() uint64 { - lastCheque := p.getLastReceivedCheque() +func (p *Peer) getLastSentCumulativePayout() uint64 { + lastCheque := p.getLastSentCheque() if lastCheque != nil { return lastCheque.CumulativePayout } @@ -133,7 +133,7 @@ func (p *Peer) createCheque() (*Cheque, error) { return nil, fmt.Errorf("error getting price from oracle: %v", err) } - total := p.getLastCumulativePayout() + total := p.getLastSentCumulativePayout() cheque = &Cheque{ ChequeParams: ChequeParams{ diff --git a/swap/swap_test.go b/swap/swap_test.go index 5f069bf375..61d8618a23 100644 --- a/swap/swap_test.go +++ b/swap/swap_test.go @@ -1233,6 +1233,24 @@ func TestPeerProcessAndVerifyChequeInvalid(t *testing.T) { } } +func TestPeerGetLastSentCumulativePayout(t *testing.T) { + _, peer, clean := newTestSwapAndPeer(t, ownerKey) + defer clean() + + if peer.getLastSentCumulativePayout() != 0 { + t.Fatalf("last cumulative payout should be 0 in the beginning, was %d", peer.getLastSentCumulativePayout()) + } + + cheque := newTestCheque() + if err := peer.setLastSentCheque(cheque); err != nil { + t.Fatal(err) + } + + if peer.getLastSentCumulativePayout() != cheque.CumulativePayout { + t.Fatalf("last cumulative payout should be the payout of the last sent cheque, was: %d, expected %d", peer.getLastSentCumulativePayout(), cheque.CumulativePayout) + } +} + // dummyMsgRW implements MessageReader and MessageWriter // but doesn't do anything. Useful for dummy message sends type dummyMsgRW struct{}