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

sync tests workflow #68

Merged
merged 3 commits into from
Nov 15, 2024
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
1 change: 1 addition & 0 deletions .github/workflows/historydb.test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ on:
- "develop"
paths:
- "sequencer/database/historydb/**"
- "sequencer/test/til/**"
- "sequencer/database/utils.go"
workflow_dispatch:

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/sequencer.test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name: "SYB all tests"
on:
pull_request:
branches:
- "develop"
- "main"
paths:
- "sequencer/**"

Expand Down
67 changes: 67 additions & 0 deletions .github/workflows/synchronizer.test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
name: "SYB synchronizer test"

on:
push:
branches-ignore:
- "main"
- "develop"
paths:
- "sequencer/synchronizer/**"
- "sequencer/database/historydb/**"
- "sequencer/database/l2db/**"
- "sequencer/database/statedb/**"
- "sequencer/txprocessor/**"
- "sequencer/test/til/**"
workflow_dispatch:

jobs:
syb-synchronizer-test:
strategy:
fail-fast: false
runs-on: ubuntu-latest
timeout-minutes: 10

services:
postgres:
image: postgres
env:
POSTGRES_PASSWORD: postgres
POSTGRES_DB: statedb
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
ports:
- 5432:5432
steps:
- uses: actions/checkout@v4
- name: Setup Go
uses: actions/setup-go@v5
with:
go-version: "1.22.5"
check-latest: true
cache-dependency-path: |
./sequencer/go.sum

- name: Install dependencies
run: |
cd ./sequencer
go mod tidy

- name: Install Task
uses: arduino/setup-task@v2
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}

- name: Run synchronizer tests
run: |
cd ./sequencer
task test-synchronizer
env:
PGHOST: "localhost"
PGPORT: "5432"
PGUSER: "postgres"
PGPASSWORD: "postgres"
PGDATABASE: "statedb"
CI: true
8 changes: 7 additions & 1 deletion sequencer/Taskfile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,14 @@ tasks:
dotenv: [".env"]
cmds:
- go test ./test/til -v

test-synchronizer:
dotenv: [".env"]
cmds:
- go test ./synchronizer -v

test-sequencer:
deps:
- test-historydb
- test-til
- test-til
- test-synchronizer
11 changes: 8 additions & 3 deletions sequencer/database/historydb/historydb_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ func TestMain(m *testing.M) {
apiConnCon := database.NewAPIConnectionController(1, time.Second)
historyDBWithACC = NewHistoryDB(db, db, apiConnCon)

// Reset DB
WipeDB(historyDB.DB())

// Run tests
result := m.Run()
// Close DB
Expand All @@ -68,7 +71,6 @@ func TestBlocks(t *testing.T) {
fromBlock = 0
toBlock = 7
// Reset DB
WipeDB(historyDB.DB())
// Generate blocks using til
set1 := `
Type: Blockchain
Expand Down Expand Up @@ -119,11 +121,11 @@ func TestBlocks(t *testing.T) {
lastBlock, err := historyDB.GetLastBlock()
assert.NoError(t, err)
assertEqualBlock(t, &blocks[len(blocks)-1].Block, lastBlock)

WipeDB(historyDB.DB())
}

func TestBatches(t *testing.T) {
// Reset DB
WipeDB(historyDB.DB())
// Generate batches using til (and blocks for foreign key)
set := `
Type: Blockchain
Expand Down Expand Up @@ -201,6 +203,9 @@ func TestBatches(t *testing.T) {
assert.Equal(t, &batches[0], fetchedBatch)
_, err = historyDB.GetBatch(common.BatchNum(len(batches) + 1))
assert.Equal(t, sql.ErrNoRows, common.Unwrap(err))

// Reset DB
WipeDB(historyDB.DB())
}

func assertEqualBlock(t *testing.T, expected *common.Block, actual *common.Block) {
Expand Down
4 changes: 4 additions & 0 deletions sequencer/synchronizer/synchronizer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,8 @@ var chainID uint16 = 0
var deleteme = []string{}

func TestMain(m *testing.M) {
// TODO: implement WipeDB

exitVal := m.Run()
for _, dir := range deleteme {
if err := os.RemoveAll(dir); err != nil {
Expand Down Expand Up @@ -524,4 +526,6 @@ func TestSyncGeneral(t *testing.T) {
// Set EthBlockNum for Vars to the blockNum in which they were updated (should be 5)
rollupVars.EthBlockNum = syncBlock.Block.Num
assert.Equal(t, rollupVars, dbRollupVars)

// TODO: implement WipeDB
}