forked from 0xPolygonHermez/zkevm-node
-
Notifications
You must be signed in to change notification settings - Fork 216
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #174 from okx/zjg/upstream-v0.6.5
upstream zkevm v0.6.5
- Loading branch information
Showing
52 changed files
with
1,567 additions
and
291 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
-- +migrate Up | ||
ALTER TABLE state.block | ||
ADD COLUMN IF NOT EXISTS checked BOOL NOT NULL DEFAULT FALSE; | ||
|
||
-- set block.checked to true for all blocks below max - 100 | ||
UPDATE state.block SET checked = true WHERE block_num <= (SELECT MAX(block_num) - 1000 FROM state.block); | ||
|
||
-- +migrate Down | ||
ALTER TABLE state.block | ||
DROP COLUMN IF EXISTS checked; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
package migrations_test | ||
|
||
import ( | ||
"database/sql" | ||
"testing" | ||
"time" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
type migrationTest0018 struct{} | ||
|
||
func (m migrationTest0018) InsertData(db *sql.DB) error { | ||
const addBlock = "INSERT INTO state.block (block_num, received_at, block_hash) VALUES ($1, $2, $3)" | ||
if _, err := db.Exec(addBlock, 1, time.Now(), "0x29e885edaf8e4b51e1d2e05f9da28161d2fb4f6b1d53827d9b80a23cf2d7d9f1"); err != nil { | ||
return err | ||
} | ||
if _, err := db.Exec(addBlock, 50, time.Now(), "0x29e885edaf8e4b51e1d2e05f9da28161d2fb4f6b1d53827d9b80a23cf2d7d9f1"); err != nil { | ||
return err | ||
} | ||
if _, err := db.Exec(addBlock, 1050, time.Now(), "0x29e885edaf8e4b51e1d2e05f9da28161d2fb4f6b1d53827d9b80a23cf2d7d9f1"); err != nil { | ||
return err | ||
} | ||
return nil | ||
} | ||
|
||
func (m migrationTest0018) RunAssertsAfterMigrationUp(t *testing.T, db *sql.DB) { | ||
var checked bool | ||
row := db.QueryRow("SELECT checked FROM state.block WHERE block_num = $1", 1) | ||
assert.NoError(t, row.Scan(&checked)) | ||
assert.Equal(t, true, checked) | ||
row = db.QueryRow("SELECT checked FROM state.block WHERE block_num = $1", 50) | ||
assert.NoError(t, row.Scan(&checked)) | ||
assert.Equal(t, true, checked) | ||
row = db.QueryRow("SELECT checked FROM state.block WHERE block_num = $1", 1050) | ||
assert.NoError(t, row.Scan(&checked)) | ||
assert.Equal(t, false, checked) | ||
|
||
const addBlock = "INSERT INTO state.block (block_num, received_at, block_hash, checked) VALUES ($1, $2, $3, $4)" | ||
_, err := db.Exec(addBlock, 2, time.Now(), "0x29e885edaf8e4b51e1d2e05f9da28161d2fb4f6b1d53827d9b80a23cf2d7d9f1", true) | ||
assert.NoError(t, err) | ||
_, err = db.Exec(addBlock, 3, time.Now(), "0x29e885edaf8e4b51e1d2e05f9da28161d2fb4f6b1d53827d9b80a23cf2d7d9f1", false) | ||
assert.NoError(t, err) | ||
const sql = `SELECT count(*) FROM state.block WHERE checked = true` | ||
row = db.QueryRow(sql) | ||
var result int | ||
assert.NoError(t, row.Scan(&result)) | ||
assert.Equal(t, 3, result, "must be 1,50 per migration and 2 by insert") | ||
|
||
const sqlCheckedFalse = `SELECT count(*) FROM state.block WHERE checked = false` | ||
row = db.QueryRow(sqlCheckedFalse) | ||
|
||
assert.NoError(t, row.Scan(&result)) | ||
assert.Equal(t, 2, result, "must be 150 by migration, and 3 by insert") | ||
} | ||
|
||
func (m migrationTest0018) RunAssertsAfterMigrationDown(t *testing.T, db *sql.DB) { | ||
var result int | ||
|
||
// Check column wip doesn't exists in state.batch table | ||
const sql = `SELECT count(*) FROM state.block` | ||
row := db.QueryRow(sql) | ||
assert.NoError(t, row.Scan(&result)) | ||
assert.Equal(t, 5, result) | ||
} | ||
|
||
func TestMigration0018(t *testing.T) { | ||
runMigrationTest(t, 18, migrationTest0018{}) | ||
} |
Oops, something went wrong.