Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix/ci small things #1153

Merged
merged 4 commits into from
Oct 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions .deepsource.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
version = 1

[[analyzers]]
name = "shell"

[[analyzers]]
name = "secrets"

[[analyzers]]
name = "docker"

[[analyzers]]
name = "test-coverage"

[[analyzers]]
name = "go"

Expand Down
17 changes: 9 additions & 8 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -87,22 +87,23 @@ jobs:
with:
go-version: '1.21'
- run: mkdir -p "$PWD/gocoverage-unit/"
- name: Run Go test (and collect code coverage)
# quicker, non-race test in case it's a PR or push to dev
if: github.event_name == 'pull_request' ||
github.ref == 'refs/heads/dev'
run: go test ./...
-cover -coverpkg=./... -covermode=count -args -test.gocoverdir="$PWD/gocoverage-unit/"
- name: Run Go test -race (and collect code coverage)
- name: Run Go test -race
id: go-test-race
# note that -race can easily make the crypto stuff 10x slower
# this is further limited to selected branches at the beginning of this file
if: github.event_name == 'push' &&
if: runner.debug ||
github.event_name == 'push' &&
github.ref != 'refs/heads/dev'
env:
GORACE: atexit_sleep_ms=10 # the default of 1000 makes every Go package test sleep for 1s; see https://go.dev/issues/20364
run: go test ./...
-race -timeout=15m -vet=off
-cover -coverpkg=./... -covermode=atomic -args -test.gocoverdir="$PWD/gocoverage-unit/"
- name: Run Go test
if: steps.go-test-race.outcome == 'skipped'
# quicker, non-race test in case it's a PR or push to dev
run: go test ./...
-cover -coverpkg=./... -covermode=count -args -test.gocoverdir="$PWD/gocoverage-unit/"
- name: Store code coverage artifact (unit)
uses: actions/upload-artifact@v3
with:
Expand Down
6 changes: 5 additions & 1 deletion test/testcommon/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ type APIserver struct {
VochainAPP *vochain.BaseApplication
Indexer *indexer.Indexer
VochainInfo *vochaininfo.VochainInfo
ChainID string
}

// Start starts a basic URL API server for testing
Expand All @@ -38,6 +39,9 @@ func (d *APIserver) Start(t testing.TB, apis ...string) {
if err := d.Account.Generate(); err != nil {
t.Fatal(err)
}
if d.ChainID == "" {
d.ChainID = "test"
}

// create the IPFS storage
d.Storage = &data.DataMockTest{}
Expand All @@ -54,7 +58,7 @@ func (d *APIserver) Start(t testing.TB, apis ...string) {
qt.Assert(t, err, qt.IsNil)

// create vochain application
d.VochainAPP = vochain.TestBaseApplication(t)
d.VochainAPP = vochain.TestBaseApplicationWithChainID(t, d.ChainID)

// create and add balance for the pre-created Account
err = d.VochainAPP.State.CreateAccount(d.Account.Address(), "", nil, 1000000)
Expand Down
25 changes: 22 additions & 3 deletions vochain/apptest.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,14 @@ import (
// Once the application is create, it is the caller's responsibility to call
// app.AdvanceTestBlock() to advance the block height and commit the state.
func TestBaseApplication(tb testing.TB) *BaseApplication {
return TestBaseApplicationWithChainID(tb, "test")
}

// TestBaseApplicationWithChainID creates a new BaseApplication for testing purposes.
// It initializes the State, TransactionHandler and all the callback functions.
// Once the application is create, it is the caller's responsibility to call
// app.AdvanceTestBlock() to advance the block height and commit the state.
func TestBaseApplicationWithChainID(tb testing.TB, chainID string) *BaseApplication {
app, err := NewBaseApplication(metadb.ForTest(), tb.TempDir())
if err != nil {
tb.Fatal(err)
Expand All @@ -31,7 +39,7 @@ func TestBaseApplication(tb testing.TB) *BaseApplication {
}
_, err = app.InitChain(context.TODO(), &abcitypes.RequestInitChain{
Time: time.Now(),
ChainId: "test",
ChainId: chainID,
Validators: []abcitypes.ValidatorUpdate{},
AppStateBytes: genesisDoc.AppState,
})
Expand Down Expand Up @@ -113,10 +121,21 @@ func (app *BaseApplication) AdvanceTestBlock() {
if err != nil {
panic(err)
}
// The next block begins 50ms later
// The next block begins 0.00005 seconds later
newHeight := app.testMockBlockStore.EndBlock()
time.Sleep(time.Millisecond * 50)
time.Sleep(time.Microsecond * 50)
nextStartTime := time.Now()
app.testMockBlockStore.NewBlock(newHeight)
app.beginBlock(nextStartTime, uint32(newHeight))
}

// AdvanceTestBlocksUntilHeight loops over AdvanceTestBlock
// until reaching height n
func (app *BaseApplication) AdvanceTestBlocksUntilHeight(n uint32) {
altergui marked this conversation as resolved.
Show resolved Hide resolved
for {
if uint32(app.testMockBlockStore.Height()) >= n {
return
}
app.AdvanceTestBlock()
}
}