Skip to content

Commit

Permalink
[WIP] Fix eth downloader unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
trinhdn2 committed Jul 7, 2023
1 parent d5beefc commit 482df9a
Show file tree
Hide file tree
Showing 9 changed files with 573 additions and 390 deletions.
2 changes: 1 addition & 1 deletion accounts/abi/bind/base.go
Expand Up @@ -134,7 +134,7 @@ func (c *BoundContract) Call(opts *CallOpts, result interface{}, method string,
return err
}
var (
msg = tomochain.CallMsg{From: opts.From, To: &c.address, Data: input, GasPrice: common.MinGasPrice, Gas: uint64(4200000)}
msg = tomochain.CallMsg{From: opts.From, To: &c.address, Data: input}
ctx = ensureContext(opts.Context)
code []byte
output []byte
Expand Down
9 changes: 8 additions & 1 deletion contracts/chequebook/cheque.go
Expand Up @@ -344,7 +344,14 @@ func (self *Chequebook) Deposit(amount *big.Int) (string, error) {
// The caller must hold self.lock.
func (self *Chequebook) deposit(amount *big.Int) (string, error) {
// since the amount is variable here, we do not use sessions
depositTransactor := bind.NewKeyedTransactor(self.prvKey)
chainID, err := self.backend.ChainID(context.Background())
if err != nil {
return "", err
}
depositTransactor, err := bind.NewKeyedTransactorWithChainID(self.prvKey, chainID)
if err != nil {
return "", err
}
depositTransactor.Value = amount
chbookRaw := &contract.ChequebookRaw{Contract: self.contract}
tx, err := chbookRaw.Transfer(depositTransactor)
Expand Down
11 changes: 3 additions & 8 deletions contracts/randomize/randomize_test.go
Expand Up @@ -57,7 +57,6 @@ func TestRandomize(t *testing.T) {
transactOpts.GasLimit = 1000000

randomizeAddress, randomize, err := DeployRandomize(transactOpts, contractBackend)
t.Log("contract address", randomizeAddress.String())
if err != nil {
t.Fatalf("can't deploy root registry: %v", err)
}
Expand All @@ -66,18 +65,15 @@ func TestRandomize(t *testing.T) {
d := time.Now().Add(1000 * time.Millisecond)
ctx, cancel := context.WithDeadline(context.Background(), d)
defer cancel()
code, _ := contractBackend.CodeAt(ctx, randomizeAddress, nil)
t.Log("contract code", common.ToHex(code))
contractBackend.CodeAt(ctx, randomizeAddress, nil)
f := func(key, val common.Hash) bool {
t.Log(key.Hex(), val.Hex())
return true
}
contractBackend.ForEachStorageAt(ctx, randomizeAddress, nil, f)
s, err := randomize.SetSecret(byte0)
_, err = randomize.SetSecret(byte0)
if err != nil {
t.Fatalf("can't set secret: %v", err)
}
t.Log("tx data", s)
contractBackend.Commit()
}

Expand Down Expand Up @@ -151,8 +147,7 @@ func TestSendTxRandomizeSecretAndOpening(t *testing.T) {
if err != nil {
t.Fatalf("Can't get secret from SC: %v", err)
}
randomize, err := contracts.DecryptRandomizeFromSecretsAndOpening(secrets, opening)
t.Log("randomize", randomize)
_, err = contracts.DecryptRandomizeFromSecretsAndOpening(secrets, opening)
if err != nil {
t.Error("Can't decrypt secret and opening", err)
}
Expand Down
8 changes: 2 additions & 6 deletions contracts/tests/Inherited_test.go
Expand Up @@ -2,7 +2,6 @@ package tests

import (
"context"
"fmt"
"math/big"
"os"
"testing"
Expand Down Expand Up @@ -38,15 +37,12 @@ func TestPriceFeed(t *testing.T) {
t.Fatalf("can't create TransactOpts: %v", err)
}
// deploy payer swap SMC
addr, contract, err := DeployMyInherited(transactOpts, contractBackend)
_, contract, err := DeployMyInherited(transactOpts, contractBackend)
if err != nil {
t.Fatal("can't deploy smart contract: ", err)
}
fmt.Println("addr", addr.Hex())
tx, err := contract.Foo()
_, err = contract.Foo()
if err != nil {
t.Fatal("can't run function Foo() in smart contract: ", err)
}
fmt.Println("tx", tx)

}
40 changes: 21 additions & 19 deletions eth/downloader/downloader.go
Expand Up @@ -56,9 +56,11 @@ var (
qosConfidenceCap = 10 // Number of peers above which not to modify RTT confidence
qosTuningImpact = 0.25 // Impact that a new tuning target has on the previous value

maxQueuedHeaders = 32 * 1024 // [eth/62] Maximum number of headers to queue for import (DOS protection)
maxHeadersProcess = 2048 // Number of header download results to import at once into the chain
maxResultsProcess = 2048 // Number of content download results to import at once into the chain
maxQueuedHeaders = 32 * 1024 // [eth/62] Maximum number of headers to queue for import (DOS protection)
maxHeadersProcess = 2048 // Number of header download results to import at once into the chain
maxResultsProcess = 2048 // Number of content download results to import at once into the chain
fullMaxForkAncestry uint64 = params.FullImmutabilityThreshold // Maximum chain reorganisation (locally redeclared so tests can reduce it)
lightMaxForkAncestry uint64 = params.LightImmutabilityThreshold // Maximum chain reorganisation (locally redeclared so tests can reduce it)

fsHeaderCheckFrequency = 100 // Verification frequency of the downloaded headers during fast sync
fsHeaderSafetyNet = 2048 // Number of headers to discard in case a chain violation is detected
Expand Down Expand Up @@ -975,22 +977,22 @@ func (d *Downloader) fetchReceipts(from uint64) error {
// various callbacks to handle the slight differences between processing them.
//
// The instrumentation parameters:
// - errCancel: error type to return if the fetch operation is cancelled (mostly makes logging nicer)
// - deliveryCh: channel from which to retrieve downloaded data packets (merged from all concurrent peers)
// - deliver: processing callback to deliver data packets into type specific download queues (usually within `queue`)
// - wakeCh: notification channel for waking the fetcher when new tasks are available (or sync completed)
// - expire: task callback method to abort requests that took too long and return the faulty peers (traffic shaping)
// - pending: task callback for the number of requests still needing download (detect completion/non-completability)
// - inFlight: task callback for the number of in-progress requests (wait for all active downloads to finish)
// - throttle: task callback to check if the processing queue is full and activate throttling (bound memory use)
// - reserve: task callback to reserve new download tasks to a particular peer (also signals partial completions)
// - fetchHook: tester callback to notify of new tasks being initiated (allows testing the scheduling logic)
// - fetch: network callback to actually send a particular download request to a physical remote peer
// - cancel: task callback to abort an in-flight download request and allow rescheduling it (in case of lost peer)
// - capacity: network callback to retrieve the estimated type-specific bandwidth capacity of a peer (traffic shaping)
// - idle: network callback to retrieve the currently (type specific) idle peers that can be assigned tasks
// - setIdle: network callback to set a peer back to idle and update its estimated capacity (traffic shaping)
// - kind: textual label of the type being downloaded to display in log mesages
// - errCancel: error type to return if the fetch operation is cancelled (mostly makes logging nicer)
// - deliveryCh: channel from which to retrieve downloaded data packets (merged from all concurrent peers)
// - deliver: processing callback to deliver data packets into type specific download queues (usually within `queue`)
// - wakeCh: notification channel for waking the fetcher when new tasks are available (or sync completed)
// - expire: task callback method to abort requests that took too long and return the faulty peers (traffic shaping)
// - pending: task callback for the number of requests still needing download (detect completion/non-completability)
// - inFlight: task callback for the number of in-progress requests (wait for all active downloads to finish)
// - throttle: task callback to check if the processing queue is full and activate throttling (bound memory use)
// - reserve: task callback to reserve new download tasks to a particular peer (also signals partial completions)
// - fetchHook: tester callback to notify of new tasks being initiated (allows testing the scheduling logic)
// - fetch: network callback to actually send a particular download request to a physical remote peer
// - cancel: task callback to abort an in-flight download request and allow rescheduling it (in case of lost peer)
// - capacity: network callback to retrieve the estimated type-specific bandwidth capacity of a peer (traffic shaping)
// - idle: network callback to retrieve the currently (type specific) idle peers that can be assigned tasks
// - setIdle: network callback to set a peer back to idle and update its estimated capacity (traffic shaping)
// - kind: textual label of the type being downloaded to display in log mesages
func (d *Downloader) fetchParts(errCancel error, deliveryCh chan dataPack, deliver func(dataPack) (int, error), wakeCh chan bool,
expire func() map[string]int, pending func() int, inFlight func() bool, throttle func() bool, reserve func(*peerConnection, int) (*fetchRequest, bool, error),
fetchHook func([]*types.Header), fetch func(*peerConnection, *fetchRequest) error, cancel func(*fetchRequest), capacity func(*peerConnection) int,
Expand Down

0 comments on commit 482df9a

Please sign in to comment.