Skip to content

Commit

Permalink
Fix tests, set up CircleCI (ethereum#25)
Browse files Browse the repository at this point in the history
  • Loading branch information
asaj authored Aug 25, 2018
1 parent 0858817 commit 6db3f93
Show file tree
Hide file tree
Showing 11 changed files with 75 additions and 67 deletions.
12 changes: 12 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
version: 2
jobs:
build:
docker:
- image: circleci/golang:1.9

working_directory: /go/src/github.com/celo-org/geth
steps:
- checkout
- run: make lint
# TODO(celo): Use testing.Skip instead
- run: build/env.sh go run build/ci.go test --skip "github.com/ethereum/go-ethereum/cmd/swarm,github.com/ethereum/go-ethereum/swarm/network/simulations/discovery"
20 changes: 20 additions & 0 deletions build/ci.go
Original file line number Diff line number Diff line change
Expand Up @@ -315,13 +315,25 @@ func goToolArch(arch string, cc string, subcmd string, args ...string) *exec.Cmd
return cmd
}

func Filter(vs []string, pred func(string) bool) []string {
filtered := make([]string, 0)
for _, v := range vs {
if pred(v) {
filtered = append(filtered, v)
}
}
return filtered
}

// Running The Tests
//
// "tests" also includes static analysis tools such as vet.

func doTest(cmdline []string) {
var (
coverage = flag.Bool("coverage", false, "Whether to record code coverage")
// TODO(celo): Use testing.Skip instead.
skip = flag.String("skip", "", "Comma separated list of packages to skip")
)
flag.CommandLine.Parse(cmdline)
env := build.Env()
Expand All @@ -332,6 +344,14 @@ func doTest(cmdline []string) {
}
packages = build.ExpandPackagesNoVendor(packages)

skipPackage := make(map[string]bool)
for _, skippedPackage := range strings.Split(*skip, ",") {
skipPackage[skippedPackage] = true
}
packages = Filter(packages, func(p string) bool {
return !skipPackage[p]
})

// Run analysis tools before the tests.
build.MustRun(goTool("vet", packages...))

Expand Down
32 changes: 0 additions & 32 deletions circle.yml

This file was deleted.

2 changes: 1 addition & 1 deletion core/vm/contracts.go
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,7 @@ func (c *textmsg) RequiredGas(input []byte) uint64 {

func (c *textmsg) Run(input []byte) ([]byte, error) {
// TODO(asa): Allow international phone numbers.
r, _ := regexp.Compile("\\+1[0-9]{10}")
r, _ := regexp.Compile(`\+1[0-9]{10}`)
if r.MatchString(string(input)) {
return input, nil
} else {
Expand Down
2 changes: 2 additions & 0 deletions miner/miner.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"sync/atomic"
"time"

"github.com/ethereum/go-ethereum/accounts"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/consensus"
"github.com/ethereum/go-ethereum/core"
Expand All @@ -35,6 +36,7 @@ import (

// Backend wraps all methods required for mining.
type Backend interface {
AccountManager() *accounts.Manager
BlockChain() *core.BlockChain
TxPool() *core.TxPool
}
Expand Down
4 changes: 2 additions & 2 deletions miner/worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ import (
"sync/atomic"
"time"

"github.com/ethereum/go-ethereum/abe"
mapset "github.com/deckarep/golang-set"
"github.com/ethereum/go-ethereum/abe"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/consensus"
"github.com/ethereum/go-ethereum/consensus/misc"
Expand Down Expand Up @@ -931,7 +931,7 @@ func (w *worker) commit(uncles []*types.Header, interval func(), update bool, st

log.Info("Commit new mining work", "number", block.Number(), "uncles", len(uncles), "txs", w.current.tcount,
"gas", block.GasUsed(), "fees", feesEth, "elapsed", common.PrettyDuration(time.Since(start)))
abe.SendVerificationTexts(w.current.receipts, block, self.coinbase, self.eth.AccountManager())
abe.SendVerificationTexts(w.current.receipts, block, w.coinbase, w.eth.AccountManager())

case <-w.exitCh:
log.Info("Worker has exited")
Expand Down
28 changes: 17 additions & 11 deletions miner/worker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"testing"
"time"

"github.com/ethereum/go-ethereum/accounts"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/consensus"
"github.com/ethereum/go-ethereum/consensus/clique"
Expand Down Expand Up @@ -70,11 +71,12 @@ func init() {

// testWorkerBackend implements worker.Backend interfaces and wraps all information needed during the testing.
type testWorkerBackend struct {
db ethdb.Database
txPool *core.TxPool
chain *core.BlockChain
testTxFeed event.Feed
uncleBlock *types.Block
accountManager *accounts.Manager
db ethdb.Database
txPool *core.TxPool
chain *core.BlockChain
testTxFeed event.Feed
uncleBlock *types.Block
}

func newTestWorkerBackend(t *testing.T, chainConfig *params.ChainConfig, engine consensus.Engine) *testWorkerBackend {
Expand All @@ -101,17 +103,21 @@ func newTestWorkerBackend(t *testing.T, chainConfig *params.ChainConfig, engine
blocks, _ := core.GenerateChain(chainConfig, genesis, engine, db, 1, func(i int, gen *core.BlockGen) {
gen.SetCoinbase(acc1Addr)
})
var backends []accounts.Backend
accountManager := accounts.NewManager(backends...)

return &testWorkerBackend{
db: db,
chain: chain,
txPool: txpool,
uncleBlock: blocks[0],
accountManager: accountManager,
db: db,
chain: chain,
txPool: txpool,
uncleBlock: blocks[0],
}
}

func (b *testWorkerBackend) BlockChain() *core.BlockChain { return b.chain }
func (b *testWorkerBackend) TxPool() *core.TxPool { return b.txPool }
func (b *testWorkerBackend) AccountManager() *accounts.Manager { return b.accountManager }
func (b *testWorkerBackend) BlockChain() *core.BlockChain { return b.chain }
func (b *testWorkerBackend) TxPool() *core.TxPool { return b.txPool }
func (b *testWorkerBackend) PostChainEvents(events []interface{}) {
b.chain.PostChainEvents(events, nil)
}
Expand Down
2 changes: 1 addition & 1 deletion p2p/dial.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ const (

// If no peers are found for this amount of time, the initial bootnodes are
// attempted to be connected.
fallbackInterval = 20 * time.Second
fallbackInterval = 6 * time.Second

// Endpoint resolution is throttled with bounded backoff.
initialResolveDelay = 60 * time.Second
Expand Down
12 changes: 6 additions & 6 deletions p2p/dial_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ func runDialTest(t *testing.T, test dialtest) {
i, spew.Sdump(new), spew.Sdump(round.new), spew.Sdump(test.init), spew.Sdump(running))
}

// Time advances by 16 seconds on every round.
vtime = vtime.Add(16 * time.Second)
// Time advances by 6 seconds on every round.
vtime = vtime.Add(6 * time.Second)
running += len(new)
}
}
Expand Down Expand Up @@ -151,7 +151,7 @@ func TestDialStateDynDial(t *testing.T) {
&dialTask{flags: dynDialedConn, dest: &discover.Node{ID: uintID(5)}},
},
new: []task{
&waitExpireTask{Duration: 14 * time.Second},
&waitExpireTask{Duration: 4 * time.Second},
},
},
// In this round, the peer with id 2 drops off. The query
Expand Down Expand Up @@ -485,7 +485,7 @@ func TestDialStateStaticDial(t *testing.T) {
&dialTask{flags: staticDialedConn, dest: &discover.Node{ID: uintID(5)}},
},
new: []task{
&waitExpireTask{Duration: 14 * time.Second},
&waitExpireTask{Duration: 4 * time.Second},
},
},
// Wait a round for dial history to expire, no new tasks should spawn.
Expand Down Expand Up @@ -542,7 +542,7 @@ func TestDialStaticAfterReset(t *testing.T) {
&dialTask{flags: staticDialedConn, dest: &discover.Node{ID: uintID(2)}},
},
new: []task{
&waitExpireTask{Duration: 30 * time.Second},
&waitExpireTask{Duration: 10 * time.Second},
},
},
}
Expand Down Expand Up @@ -603,7 +603,7 @@ func TestDialStateCache(t *testing.T) {
&dialTask{flags: staticDialedConn, dest: &discover.Node{ID: uintID(3)}},
},
new: []task{
&waitExpireTask{Duration: 14 * time.Second},
&waitExpireTask{Duration: 4 * time.Second},
},
},
// Still waiting for node 3's entry to expire in the cache.
Expand Down
26 changes: 13 additions & 13 deletions params/protocol_params.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,19 +66,19 @@ const (

// Precompiled contract gas prices

EcrecoverGas uint64 = 3000 // Elliptic curve sender recovery gas price
Sha256BaseGas uint64 = 60 // Base price for a SHA256 operation
Sha256PerWordGas uint64 = 12 // Per-word price for a SHA256 operation
Ripemd160BaseGas uint64 = 600 // Base price for a RIPEMD160 operation
Ripemd160PerWordGas uint64 = 120 // Per-word price for a RIPEMD160 operation
IdentityBaseGas uint64 = 15 // Base price for a data copy operation
IdentityPerWordGas uint64 = 3 // Per-work price for a data copy operation
ModExpQuadCoeffDiv uint64 = 20 // Divisor for the quadratic particle of the big int modular exponentiation
Bn256AddGas uint64 = 500 // Gas needed for an elliptic curve addition
Bn256ScalarMulGas uint64 = 40000 // Gas needed for an elliptic curve scalar multiplication
Bn256PairingBaseGas uint64 = 100000 // Base price for an elliptic curve pairing check
Bn256PairingPerPointGas uint64 = 80000 // Per-point price for an elliptic curve pairing check
TextmsgGas uint64 = 1000000 // Per-message price for sending an SMS. Not an accurate representation of the real cost of sending an SMS.
EcrecoverGas uint64 = 3000 // Elliptic curve sender recovery gas price
Sha256BaseGas uint64 = 60 // Base price for a SHA256 operation
Sha256PerWordGas uint64 = 12 // Per-word price for a SHA256 operation
Ripemd160BaseGas uint64 = 600 // Base price for a RIPEMD160 operation
Ripemd160PerWordGas uint64 = 120 // Per-word price for a RIPEMD160 operation
IdentityBaseGas uint64 = 15 // Base price for a data copy operation
IdentityPerWordGas uint64 = 3 // Per-work price for a data copy operation
ModExpQuadCoeffDiv uint64 = 20 // Divisor for the quadratic particle of the big int modular exponentiation
Bn256AddGas uint64 = 500 // Gas needed for an elliptic curve addition
Bn256ScalarMulGas uint64 = 40000 // Gas needed for an elliptic curve scalar multiplication
Bn256PairingBaseGas uint64 = 100000 // Base price for an elliptic curve pairing check
Bn256PairingPerPointGas uint64 = 80000 // Per-point price for an elliptic curve pairing check
TextmsgGas uint64 = 1000000 // Per-message price for sending an SMS. Not an accurate representation of the real cost of sending an SMS.
)

var (
Expand Down
2 changes: 1 addition & 1 deletion vendor/vendor.json
Original file line number Diff line number Diff line change
Expand Up @@ -928,5 +928,5 @@
"revisionTime": "2017-08-11T01:42:03Z"
}
],
"rootPath": "go-jem"
"rootPath": "github.com/celo-org/geth"
}

0 comments on commit 6db3f93

Please sign in to comment.