Skip to content

Commit

Permalink
ci: unit test and truffle test (#456)
Browse files Browse the repository at this point in the history
* ci: add unit test

fix: failed on test

* ci: add truffle test

* ci: update os version

* ci: add cache for go build
  • Loading branch information
j75689 authored Oct 18, 2021
1 parent aecb612 commit f2f68db
Show file tree
Hide file tree
Showing 40 changed files with 660 additions and 195 deletions.
50 changes: 50 additions & 0 deletions .github/workflows/build-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
name: Build Test

on:
push:
branches:
- master
- develop

pull_request:
branches:
- master
- develop

jobs:
unit-test:
strategy:
matrix:
go-version: [1.16.x]
os: [ubuntu-18.04]
runs-on: ${{ matrix.os }}
steps:
- name: Install Go
uses: actions/setup-go@v2
with:
go-version: ${{ matrix.go-version }}

- name: Checkout code
uses: actions/checkout@v2

- uses: actions/cache@v2
with:
# In order:
# * Module download cache
# * Build cache (Linux)
# * Build cache (Mac)
# * Build cache (Windows)
path: |
~/go/pkg/mod
~/.cache/go-build
~/Library/Caches/go-build
%LocalAppData%\go-build
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-
- name: Test Build
run: |
make geth
25 changes: 25 additions & 0 deletions .github/workflows/integration-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: Integration Test

on:
push:
branches:
- master
- develop

pull_request:
branches:
- master
- develop

jobs:
truffle-test:
strategy:
matrix:
os: [ubuntu-18.04]
runs-on: ${{ matrix.os }}
steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Truffle test
run: make truffle-test
48 changes: 48 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
name: Lint

on:
push:
branches:
- master
- develop

pull_request:
branches:
- master
- develop

jobs:
unit-test:
strategy:
matrix:
go-version: [1.16.x]
os: [ubuntu-18.04]
runs-on: ${{ matrix.os }}
steps:
- name: Install Go
uses: actions/setup-go@v2
with:
go-version: ${{ matrix.go-version }}

- name: Checkout code
uses: actions/checkout@v2

- uses: actions/cache@v2
with:
# In order:
# * Module download cache
# * Build cache (Linux)
# * Build cache (Mac)
# * Build cache (Windows)
path: |
~/go/pkg/mod
~/.cache/go-build
~/Library/Caches/go-build
%LocalAppData%\go-build
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-
- name: Lint
run: |
make lint
26 changes: 21 additions & 5 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
strategy:
matrix:
go-version: [1.16.x]
os: [ubuntu-latest, macos-latest, windows-latest]
os: [ubuntu-18.04, macos-11, windows-2019]
runs-on: ${{ matrix.os }}
steps:
- name: Install Go
Expand All @@ -23,6 +23,22 @@ jobs:
- name: Checkout Code
uses: actions/checkout@v2

- uses: actions/cache@v2
with:
# In order:
# * Module download cache
# * Build cache (Linux)
# * Build cache (Mac)
# * Build cache (Windows)
path: |
~/go/pkg/mod
~/.cache/go-build
~/Library/Caches/go-build
%LocalAppData%\go-build
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-
# ==============================
# Linux/Macos/Windows Build
# ==============================
Expand All @@ -36,29 +52,29 @@ jobs:

- name: Upload Linux Build
uses: actions/upload-artifact@v2
if: matrix.os == 'ubuntu-latest'
if: matrix.os == 'ubuntu-18.04'
with:
name: linux
path: ./build/bin/geth

- name: Upload MacOS Build
uses: actions/upload-artifact@v2
if: matrix.os == 'macos-latest'
if: matrix.os == 'macos-11'
with:
name: macos
path: ./build/bin/geth

- name: Upload Windows Build
uses: actions/upload-artifact@v2
if: matrix.os == 'windows-latest'
if: matrix.os == 'windows-2019'
with:
name: windows
path: ./build/bin/geth.exe

release:
name: Release
needs: build
runs-on: ubuntu-latest
runs-on: ubuntu-18.04
steps:
- name: Set Env
run: echo "RELEASE_VERSION=${GITHUB_REF#refs/*/}" >> $GITHUB_ENV
Expand Down
55 changes: 55 additions & 0 deletions .github/workflows/unit-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
name: Unit Test

on:
push:
branches:
- master
- develop

pull_request:
branches:
- master
- develop

jobs:
unit-test:
strategy:
matrix:
go-version: [1.16.x]
os: [ubuntu-18.04]
runs-on: ${{ matrix.os }}
steps:
- name: Install Go
uses: actions/setup-go@v2
with:
go-version: ${{ matrix.go-version }}

- name: Checkout code
uses: actions/checkout@v2

- uses: actions/cache@v2
with:
# In order:
# * Module download cache
# * Build cache (Linux)
# * Build cache (Mac)
# * Build cache (Windows)
path: |
~/go/pkg/mod
~/.cache/go-build
~/Library/Caches/go-build
%LocalAppData%\go-build
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-
- name: Test Build
run: |
make geth
- name: Uint Test
env:
ANDROID_HOME: "" # Skip android test
run: |
make test
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
*/**/*tx_database*
*/**/*dapps*
build/_vendor/pkg
/tests/truffle/storage

#*
.#*
Expand Down
14 changes: 12 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# with Go source code. If you know what GOPATH is then you probably
# don't need to bother with make.

.PHONY: geth android ios geth-cross evm all test clean
.PHONY: geth android ios geth-cross evm all test truffle-test clean
.PHONY: geth-linux geth-linux-386 geth-linux-amd64 geth-linux-mips64 geth-linux-mips64le
.PHONY: geth-linux-arm geth-linux-arm-5 geth-linux-arm-6 geth-linux-arm-7 geth-linux-arm64
.PHONY: geth-darwin geth-darwin-386 geth-darwin-amd64
Expand Down Expand Up @@ -33,7 +33,17 @@ ios:
@echo "Import \"$(GOBIN)/Geth.framework\" to use the library."

test: all
$(GORUN) build/ci.go test
$(GORUN) build/ci.go test -timeout 1h

truffle-test:
docker build . -f ./docker/Dockerfile --target bsc-genesis -t bsc-genesis
docker build . -f ./docker/Dockerfile --target bsc -t bsc
docker build . -f ./docker/Dockerfile.truffle -t truffle-test
docker-compose -f ./tests/truffle/docker-compose.yml up genesis
docker-compose -f ./tests/truffle/docker-compose.yml up -d bsc-rpc bsc-validator1
sleep 30
docker-compose -f ./tests/truffle/docker-compose.yml up --exit-code-from truffle-test truffle-test
docker-compose -f ./tests/truffle/docker-compose.yml down

lint: ## Run linters.
$(GORUN) build/ci.go lint
Expand Down
4 changes: 4 additions & 0 deletions build/ci.go
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,7 @@ func doTest(cmdline []string) {
cc = flag.String("cc", "", "Sets C compiler binary")
coverage = flag.Bool("coverage", false, "Whether to record code coverage")
verbose = flag.Bool("v", false, "Whether to log verbosely")
timeout = flag.String("timeout", "10m", `Timeout of runing tests`)
)
flag.CommandLine.Parse(cmdline)

Expand All @@ -299,6 +300,9 @@ func doTest(cmdline []string) {
if *verbose {
gotest.Args = append(gotest.Args, "-v")
}
if *timeout != "" {
gotest.Args = append(gotest.Args, []string{"-timeout", *timeout}...)
}

packages := []string{"./accounts/...", "./common/...", "./consensus/...", "./console/...", "./core/...",
"./crypto/...", "./eth/...", "./ethclient/...", "./ethdb/...", "./event/...", "./graphql/...", "./les/...",
Expand Down
2 changes: 1 addition & 1 deletion cmd/puppeth/testdata/stureby_aleth.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"minGasLimit": "0x1388",
"maxGasLimit": "0x7fffffffffffffff",
"tieBreakingGas": false,
"gasLimitBoundDivisor": "0x400",
"gasLimitBoundDivisor": "0x100",
"minimumDifficulty": "0x20000",
"difficultyBoundDivisor": "0x800",
"durationLimit": "0xd",
Expand Down
2 changes: 1 addition & 1 deletion cmd/puppeth/testdata/stureby_parity.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"accountStartNonce": "0x0",
"maximumExtraDataSize": "0x20",
"minGasLimit": "0x1388",
"gasLimitBoundDivisor": "0x400",
"gasLimitBoundDivisor": "0x100",
"networkID": "0x4cb2e",
"chainID": "0x4cb2e",
"maxCodeSize": "0x6000",
Expand Down
12 changes: 10 additions & 2 deletions core/blockchain.go
Original file line number Diff line number Diff line change
Expand Up @@ -2161,8 +2161,16 @@ func (bc *BlockChain) updateHighestVerifiedHeader(header *types.Header) {
return
}

newTD := big.NewInt(0).Add(bc.GetTdByHash(header.ParentHash), header.Difficulty)
oldTD := big.NewInt(0).Add(bc.GetTdByHash(currentHeader.ParentHash), currentHeader.Difficulty)
newParentTD := bc.GetTdByHash(header.ParentHash)
if newParentTD == nil {
newParentTD = big.NewInt(0)
}
oldParentTD := bc.GetTdByHash(currentHeader.ParentHash)
if oldParentTD == nil {
oldParentTD = big.NewInt(0)
}
newTD := big.NewInt(0).Add(newParentTD, header.Difficulty)
oldTD := big.NewInt(0).Add(oldParentTD, currentHeader.Difficulty)

if newTD.Cmp(oldTD) > 0 {
bc.highestVerifiedHeader.Store(types.CopyHeader(header))
Expand Down
8 changes: 0 additions & 8 deletions core/blockchain_diff_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -216,8 +216,6 @@ func rawDataToDiffLayer(data rlp.RawValue) (*types.DiffLayer, error) {
}

func TestProcessDiffLayer(t *testing.T) {
t.Parallel()

blockNum := 128
fullBackend := newTestBackend(blockNum, false)
falseDiff := 5
Expand Down Expand Up @@ -279,8 +277,6 @@ func TestProcessDiffLayer(t *testing.T) {
}

func TestFreezeDiffLayer(t *testing.T) {
t.Parallel()

blockNum := 1024
fullBackend := newTestBackend(blockNum, true)
defer fullBackend.close()
Expand All @@ -302,8 +298,6 @@ func TestFreezeDiffLayer(t *testing.T) {
}

func TestPruneDiffLayer(t *testing.T) {
t.Parallel()

blockNum := 1024
fullBackend := newTestBackend(blockNum, true)
defer fullBackend.close()
Expand Down Expand Up @@ -363,8 +357,6 @@ func TestPruneDiffLayer(t *testing.T) {
}

func TestGetDiffAccounts(t *testing.T) {
t.Parallel()

blockNum := 128
fullBackend := newTestBackend(blockNum, false)
defer fullBackend.close()
Expand Down
2 changes: 1 addition & 1 deletion core/receipt_processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,4 +63,4 @@ func (p *AsyncReceiptBloomGenerator) Close() {
close(p.receipts)
p.isClosed = true
p.wg.Wait()
}
}
9 changes: 4 additions & 5 deletions core/state_processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,10 @@ import (
)

const (
fullProcessCheck = 21 // On diff sync mode, will do full process every fullProcessCheck randomly
minNumberOfAccountPerTask = 5
recentTime = 2048 * 3
recentDiffLayerTimeout = 20
farDiffLayerTimeout = 2
fullProcessCheck = 21 // On diff sync mode, will do full process every fullProcessCheck randomly
recentTime = 2048 * 3
recentDiffLayerTimeout = 20
farDiffLayerTimeout = 2
)

// StateProcessor is a basic Processor, which takes care of transitioning
Expand Down
Loading

0 comments on commit f2f68db

Please sign in to comment.