-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
More careful handle of sequences in stage_headers --reset (#4023)
* save * save * save * save
- Loading branch information
1 parent
38e8706
commit 77560b6
Showing
8 changed files
with
217 additions
and
154 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,48 @@ | ||
package core | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
|
||
"github.com/ledgerwatch/erigon-lib/kv" | ||
"github.com/ledgerwatch/erigon-lib/kv/memdb" | ||
"github.com/ledgerwatch/erigon/params" | ||
"github.com/ledgerwatch/erigon/params/networkname" | ||
"github.com/stretchr/testify/require" | ||
"testing" | ||
) | ||
|
||
func TestDefaultBSCGenesisBlock(t *testing.T) { | ||
genesis := DefaultBSCGenesisBlock() | ||
db := memdb.New() | ||
_, block, err := CommitGenesisBlock(db, genesis) | ||
db := memdb.NewTestDB(t) | ||
check := func(network string) { | ||
genesis := DefaultGenesisBlockByChainName(network) | ||
tx, err := db.BeginRw(context.Background()) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
defer tx.Rollback() | ||
_, block, err := WriteGenesisBlock(tx, genesis) | ||
require.NoError(t, err) | ||
expect := params.GenesisHashByChainName(network) | ||
require.NotNil(t, expect, network) | ||
require.Equal(t, block.Hash().Bytes(), expect.Bytes(), network) | ||
} | ||
for _, network := range networkname.All { | ||
check(network) | ||
} | ||
} | ||
|
||
func TestCommitGenesisIdempotency(t *testing.T) { | ||
_, tx := memdb.NewTestTx(t) | ||
genesis := DefaultGenesisBlockByChainName(networkname.MainnetChainName) | ||
_, _, err := WriteGenesisBlock(tx, genesis) | ||
require.NoError(t, err) | ||
seq, err := tx.ReadSequence(kv.EthTx) | ||
require.NoError(t, err) | ||
require.Equal(t, uint64(2), seq) | ||
|
||
_, _, err = WriteGenesisBlock(tx, genesis) | ||
require.NoError(t, err) | ||
seq, err = tx.ReadSequence(kv.EthTx) | ||
require.NoError(t, err) | ||
require.Equal(t, block.Hash(), params.BSCGenesisHash) | ||
require.Equal(t, uint64(2), seq) | ||
} |
Oops, something went wrong.