Skip to content

Commit 26b2d6e

Browse files
egonelbrekaralabe
authored andcommitted
contracts: fix megacheck errors (#14916)
* contracts: fix megacheck errors * contracts: drop useless sleep, lets see what breaks
1 parent fff6e03 commit 26b2d6e

2 files changed

Lines changed: 7 additions & 11 deletions

File tree

‎contracts/chequebook/cheque.go‎

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -376,12 +376,12 @@ func (self *Chequebook) autoDeposit(interval time.Duration) {
376376
ticker := time.NewTicker(interval)
377377
self.quit = make(chan bool)
378378
quit := self.quit
379+
379380
go func() {
380-
FOR:
381381
for {
382382
select {
383383
case <-quit:
384-
break FOR
384+
return
385385
case <-ticker.C:
386386
self.lock.Lock()
387387
if self.balance.Cmp(self.buffer) < 0 {
@@ -395,7 +395,6 @@ func (self *Chequebook) autoDeposit(interval time.Duration) {
395395
}
396396
}
397397
}()
398-
return
399398
}
400399

401400
// Outbox can issue cheques from a single contract to a single beneficiary.
@@ -436,7 +435,6 @@ type Inbox struct {
436435
sender common.Address // local peer's address to send cashing tx from
437436
signer *ecdsa.PublicKey // peer's public key
438437
txhash string // tx hash of last cashing tx
439-
abigen bind.ContractBackend // blockchain API
440438
session *contract.ChequebookSession // abi contract backend with tx opts
441439
quit chan bool // when closed causes autocash to stop
442440
maxUncashed *big.Int // threshold that triggers autocashing
@@ -525,12 +523,12 @@ func (self *Inbox) autoCash(cashInterval time.Duration) {
525523
ticker := time.NewTicker(cashInterval)
526524
self.quit = make(chan bool)
527525
quit := self.quit
526+
528527
go func() {
529-
FOR:
530528
for {
531529
select {
532530
case <-quit:
533-
break FOR
531+
return
534532
case <-ticker.C:
535533
self.lock.Lock()
536534
if self.cheque != nil && self.cheque.Amount.Cmp(self.cashed) != 0 {
@@ -543,7 +541,6 @@ func (self *Inbox) autoCash(cashInterval time.Duration) {
543541
}
544542
}
545543
}()
546-
return
547544
}
548545

549546
// Receive is called to deposit the latest cheque to the incoming Inbox.

‎contracts/chequebook/cheque_test.go‎

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,6 @@ func TestVerifyErrors(t *testing.T) {
170170
t.Fatalf("expected no error, got %v", err)
171171
}
172172

173-
time.Sleep(5)
174173
chbox, err := NewInbox(key1, contr0, addr1, &key0.PublicKey, backend)
175174
if err != nil {
176175
t.Fatalf("expected no error, got %v", err)
@@ -193,7 +192,7 @@ func TestVerifyErrors(t *testing.T) {
193192
received, err = chbox.Receive(ch1)
194193
t.Logf("correct error: %v", err)
195194
if err == nil {
196-
t.Fatalf("expected receiver error, got none")
195+
t.Fatalf("expected receiver error, got none and value %v", received)
197196
}
198197

199198
ch2, err := chbook1.Issue(addr1, amount)
@@ -203,7 +202,7 @@ func TestVerifyErrors(t *testing.T) {
203202
received, err = chbox.Receive(ch2)
204203
t.Logf("correct error: %v", err)
205204
if err == nil {
206-
t.Fatalf("expected sender error, got none")
205+
t.Fatalf("expected sender error, got none and value %v", received)
207206
}
208207

209208
_, err = chbook1.Issue(addr1, new(big.Int).SetInt64(-1))
@@ -215,7 +214,7 @@ func TestVerifyErrors(t *testing.T) {
215214
received, err = chbox.Receive(ch0)
216215
t.Logf("correct error: %v", err)
217216
if err == nil {
218-
t.Fatalf("expected incorrect amount error, got none")
217+
t.Fatalf("expected incorrect amount error, got none and value %v", received)
219218
}
220219

221220
}

0 commit comments

Comments
 (0)