Skip to content

Commit

Permalink
chore(ci): add codecov + fix gosec + cleanup tests (#8)
Browse files Browse the repository at this point in the history
* add

* fix naming

* bing bong

* single workflow

* fix lint

* address gosecs

* remove deadfiles sand bump sdk

* note in beacon.go

* add comments

* add concurrency cancel
  • Loading branch information
itsdevbear committed Feb 3, 2024
1 parent 7dc2a32 commit b6b9c10
Show file tree
Hide file tree
Showing 35 changed files with 216 additions and 470 deletions.
79 changes: 0 additions & 79 deletions .github/workflows/docker_image.yml

This file was deleted.

51 changes: 14 additions & 37 deletions .github/workflows/pipeline.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,58 +31,35 @@ on:
branches:
- main

concurrency:
group: ci-${{ github.ref }}-tests
cancel-in-progress: true

jobs:
ci:
strategy:
matrix:
args: ["build", "lint", "test-unit-race", "test-unit-cover"]
args: ["build", "lint", "gosec", "test-unit-cover"]
os: [ubuntu-latest]
go-version: [1.21.6]
runs-on: ${{ matrix.os }}
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Install Foundry
uses: foundry-rs/foundry-toolchain@v1
- name: Setup Golang
uses: actions/setup-go@v3
with:
go-version: ${{ matrix.go-version }}
- name: Cache Golang Deps
uses: actions/cache@v3
uses: actions/setup-go@v4
with:
path: |
~/.cache/go-build
~/go
key: ${{ runner.os }}-golang-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-golang-
go-version: 'stable'
check-latest: true
- name: Run ${{ matrix.args }}
run: |
make ${{ matrix.args }}
env:
GOPATH: /home/runner/go
# - name: Archive code coverage results
# uses: actions/upload-artifact@v3
# with:
# name: code-coverage-report
# path: coverage-${{ matrix.args }}.txt
# retention-days: 1
# if: ${{ matrix.args == 'test-unit-cover' }}

# TODO: Re-enable later.
# codecov:
# name: codecov(uploader, polaris-linux-latest)
# runs-on: polaris-linux-latest
# needs: ci
# steps:
# - name: Checkout
# uses: actions/checkout@v3
# - name: Download code coverage results
# uses: actions/download-artifact@v2
# with:
# name: code-coverage-report
# - name: Upload to Codecov
# uses: codecov/codecov-action@v2
# with:
# token: ${{ secrets.CODECOV_TOKEN }}
- name: Upload to Codecov
uses: codecov/codecov-action@v2
with:
token: ${{ secrets.CODECOV_TOKEN }}
files: ./coverage-${{ matrix.args }}.txt
if: ${{ matrix.args == 'test-unit-cover' }}
44 changes: 7 additions & 37 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -243,26 +243,16 @@ start-besu:
# unit #
#################

install-ginkgo:
@echo "Installing ginkgo..."
@go install github.com/onsi/ginkgo/v2/ginkgo@latest

test-unit:
@$(MAKE) install-ginkgo forge-test
@$(MAKE) forge-test
@echo "Running unit tests..."
@ginkgo -r --randomize-all --fail-on-pending -trace --skip .*e2e* ./...

test-unit-race:
@$(MAKE) install-ginkgo forge-test
@echo "Running unit tests with race detection..."
@ginkgo --race -r --randomize-all --fail-on-pending -trace --skip .*e2e* ./...
go test ./...

test-unit-cover:
@$(MAKE) install-ginkgo forge-test
@$(MAKE) forge-test
@echo "Running unit tests with coverage..."
@ginkgo -r --randomize-all --fail-on-pending -trace --skip .*e2e* \
--junit-report out.xml --cover --coverprofile "coverage-test-unit-cover.txt" --covermode atomic \
./...
go test -race -coverprofile=coverage-test-unit-cover.txt -covermode=atomic ./...

#################
# forge #
Expand All @@ -280,26 +270,7 @@ test-e2e:
@$(MAKE) test-e2e-no-build

test-e2e-no-build:
@$(MAKE) install-ginkgo
@echo "Running e2e tests..."
@ginkgo -r --randomize-all --fail-on-pending -trace -timeout 30m ./e2e/precompile/...

#################
# localnet #
#################

test-localnet:
@$(MAKE) test-localnet-no-build

test-localnet-no-build:
@$(MAKE) install-ginkgo
@echo "Running localnet tests..."
@ginkgo -r --randomize-all --fail-on-pending -trace -timeout 30m ./e2e/localnet/...


###############################################################################
### Formatting ###
###############################################################################

###############################################################################
### Linting ###
Expand All @@ -309,8 +280,7 @@ format:
@$(MAKE) license-fix buf-lint-fix forge-lint-fix golangci-fix

lint:
@$(MAKE) license buf-lint forge-lint golangci gosec

@$(MAKE) license buf-lint forge-lint golangci

#################
# forge #
Expand Down Expand Up @@ -374,12 +344,12 @@ license-fix:

gosec-install:
@echo "--> Installing gosec"
@go install github.com/securego/gosec/v2/cmd/gosec
@go install github.com/cosmos/gosec/v2/cmd/gosec

gosec:
@$(MAKE) gosec-install
@echo "--> Running gosec"
@gosec -exclude-generated ./...
@gosec ./...


#################
Expand Down
3 changes: 0 additions & 3 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,9 +188,6 @@ func NewBeaconKitApp(
/**** Module Options ****/
app.ModuleManager.RegisterInvariants(app.CrisisKeeper)

// RegisterUpgradeHandlers is used for registering any on-chain upgrades.
app.RegisterUpgradeHandlers()

// Load the app.
if err = app.Load(loadLatest); err != nil {
panic(err)
Expand Down
77 changes: 35 additions & 42 deletions app/beacond/cmd/root_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,53 +36,46 @@ import (

testapp "github.com/itsdevbear/bolaris/app"
"github.com/itsdevbear/bolaris/app/beacond/cmd"

. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
)

func TestCmd(t *testing.T) {
RegisterFailHandler(Fail)
RunSpecs(t, "app/beacond/cmd")
func TestInitCommand(t *testing.T) {
rootCmd := cmd.NewRootCmd()
rootCmd.SetOut(os.NewFile(0, os.DevNull))
rootCmd.SetArgs([]string{
"init", // Test the init cmd
"BeaconApp-test", // Moniker
fmt.Sprintf("--%s=%s", cli.FlagOverwrite, "true"), // Overwrite genesis.json
})

err := svrcmd.Execute(rootCmd, "", testapp.DefaultNodeHome)
if err != nil {
t.Errorf("Expected no error, got %v", err)
}
}

var _ = Describe("Init command", func() {
It("should initialize the app with given options", func() {
stdout := os.Stdout
defer func() { os.Stdout = stdout }()
os.Stdout = os.NewFile(0, os.DevNull)
rootCmd := cmd.NewRootCmd()
rootCmd.SetArgs([]string{
"init", // Test the init cmd
"BeaconApp-test", // Moniker
fmt.Sprintf("--%s=%s", cli.FlagOverwrite, "true"), // Overwrite genesis.json
})
func TestHomeFlagRegistration(t *testing.T) {
stdout := os.Stdout
defer func() { os.Stdout = stdout }()
os.Stdout = os.NewFile(0, os.DevNull)
homeDir := os.TempDir()

err := svrcmd.Execute(rootCmd, "", testapp.DefaultNodeHome)
Expect(err).ToNot(HaveOccurred())
rootCmd := cmd.NewRootCmd()
rootCmd.SetArgs([]string{
"query",
fmt.Sprintf("--%s", flags.FlagHome),
homeDir,
})
})

var _ = Describe("Home flag registration", func() {
It("should set home directory correctly", func() {
// Redirect standard out to null
stdout := os.Stdout
defer func() { os.Stdout = stdout }()
os.Stdout = os.NewFile(0, os.DevNull)
homeDir := os.TempDir()

rootCmd := cmd.NewRootCmd()
rootCmd.SetArgs([]string{
"query",
fmt.Sprintf("--%s", flags.FlagHome),
homeDir,
})
err := svrcmd.Execute(rootCmd, "", testapp.DefaultNodeHome)
if err != nil {
t.Errorf("Expected no error, got %v", err)
}

err := svrcmd.Execute(rootCmd, "", testapp.DefaultNodeHome)
Expect(err).ToNot(HaveOccurred())

result, err := rootCmd.Flags().GetString(flags.FlagHome)
Expect(err).ToNot(HaveOccurred())
Expect(result).To(Equal(homeDir))
})
})
result, err := rootCmd.Flags().GetString(flags.FlagHome)
if err != nil {
t.Errorf("Expected no error, got %v", err)
}
if result != homeDir {
t.Errorf("Expected homeDir to be %s, got %s", homeDir, result)
}
}
2 changes: 1 addition & 1 deletion app/contracts/main/main.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// SPDX-License-Identifier: MIT
//
// # Copyright (c) 2023 Berachain Foundation
// Copyright (c) 2023 Berachain Foundation
//
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation
Expand Down
5 changes: 4 additions & 1 deletion app/contracts/staking.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,10 @@ type StakingCallbacks struct {
}

func (s *StakingCallbacks) ABIEvents() map[string]abi.Event {
x, _ := StakingMetaData.GetAbi()
x, err := StakingMetaData.GetAbi()
if err != nil {
panic(err)
}
return x.Events
}

Expand Down
10 changes: 8 additions & 2 deletions app/export.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,10 @@ func (app *BeaconApp) prepForZeroHeightGenesis(ctx sdk.Context, jailAllowedAddrs
if err != nil {
panic(err)
}
_, _ = app.DistrKeeper.WithdrawValidatorCommission(ctx, valBz)
_, err = app.DistrKeeper.WithdrawValidatorCommission(ctx, valBz)
if err != nil {
panic(err)
}
return false
}); err != nil {
panic(err)
Expand All @@ -131,7 +134,10 @@ func (app *BeaconApp) prepForZeroHeightGenesis(ctx sdk.Context, jailAllowedAddrs

delAddr := sdk.MustAccAddressFromBech32(delegation.DelegatorAddress)

_, _ = app.DistrKeeper.WithdrawDelegationRewards(ctx, delAddr, valAddr)
_, err = app.DistrKeeper.WithdrawDelegationRewards(ctx, delAddr, valAddr)
if err != nil {
panic(err)
}
}

// clear validator slash events
Expand Down
Loading

0 comments on commit b6b9c10

Please sign in to comment.