Skip to content
This repository has been archived by the owner on Aug 2, 2021. It is now read-only.

Commit

Permalink
swap: fix and rename Peer.getLastSentCumulativePayout (#1769)
Browse files Browse the repository at this point in the history
* swap: return the last sent payout and rename to Peer.getLastSentCumulativePayout
  • Loading branch information
ralph-pichler authored Sep 19, 2019
1 parent fd34ea6 commit bf33304
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
6 changes: 3 additions & 3 deletions swap/peer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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{
Expand Down
18 changes: 18 additions & 0 deletions swap/swap_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{}
Expand Down

0 comments on commit bf33304

Please sign in to comment.