Skip to content
This repository was archived by the owner on Aug 2, 2021. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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