From e55f67e439b257236e3caf5c7c37ce79fb409324 Mon Sep 17 00:00:00 2001 From: Intizar Date: Fri, 15 Nov 2024 13:21:01 +0900 Subject: [PATCH 1/3] implement synchronizer tests workflow --- .github/workflows/historydb.test.yml | 1 + .github/workflows/synchronizer.test.yml | 67 +++++++++++++++++++++++++ sequencer/Taskfile.yml | 8 ++- 3 files changed, 75 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/synchronizer.test.yml diff --git a/.github/workflows/historydb.test.yml b/.github/workflows/historydb.test.yml index f830280..f65ebd4 100644 --- a/.github/workflows/historydb.test.yml +++ b/.github/workflows/historydb.test.yml @@ -7,6 +7,7 @@ on: - "develop" paths: - "sequencer/database/historydb/**" + - "sequencer/test/til/**" - "sequencer/database/utils.go" workflow_dispatch: diff --git a/.github/workflows/synchronizer.test.yml b/.github/workflows/synchronizer.test.yml new file mode 100644 index 0000000..3c58fba --- /dev/null +++ b/.github/workflows/synchronizer.test.yml @@ -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 \ No newline at end of file diff --git a/sequencer/Taskfile.yml b/sequencer/Taskfile.yml index b5d19a8..c0de16b 100644 --- a/sequencer/Taskfile.yml +++ b/sequencer/Taskfile.yml @@ -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 \ No newline at end of file + - test-til + - test-synchronizer \ No newline at end of file From c55c55a7fe7de163e14b632f2c01ade668a9eff0 Mon Sep 17 00:00:00 2001 From: Intizar Date: Fri, 15 Nov 2024 13:29:47 +0900 Subject: [PATCH 2/3] clean up tables after each test --- sequencer/database/historydb/historydb_test.go | 11 ++++++++--- sequencer/synchronizer/synchronizer_test.go | 4 ++++ 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/sequencer/database/historydb/historydb_test.go b/sequencer/database/historydb/historydb_test.go index 25df443..6ca1108 100644 --- a/sequencer/database/historydb/historydb_test.go +++ b/sequencer/database/historydb/historydb_test.go @@ -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 @@ -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 @@ -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 @@ -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) { diff --git a/sequencer/synchronizer/synchronizer_test.go b/sequencer/synchronizer/synchronizer_test.go index 081ebb7..9f12ed8 100644 --- a/sequencer/synchronizer/synchronizer_test.go +++ b/sequencer/synchronizer/synchronizer_test.go @@ -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 { @@ -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 } From eca42d1c03c5d3b236cd727499243f614a582509 Mon Sep 17 00:00:00 2001 From: Intizar Date: Fri, 15 Nov 2024 15:26:25 +0900 Subject: [PATCH 3/3] run all sequencer tests on PR to main --- .github/workflows/sequencer.test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/sequencer.test.yml b/.github/workflows/sequencer.test.yml index d58930d..a60b7de 100644 --- a/.github/workflows/sequencer.test.yml +++ b/.github/workflows/sequencer.test.yml @@ -3,7 +3,7 @@ name: "SYB all tests" on: pull_request: branches: - - "develop" + - "main" paths: - "sequencer/**"