forked from erigontech/erigon
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added finality consensus-specs-tests (erigontech#6892)
- Loading branch information
1 parent
0c16f4e
commit 733ae63
Showing
6 changed files
with
107 additions
and
19 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
Binary file not shown.
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,42 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/ledgerwatch/erigon/cl/clparams" | ||
"github.com/ledgerwatch/erigon/cmd/erigon-cl/core/transition" | ||
) | ||
|
||
func finalityTestFunction() error { | ||
testState, err := decodeStateFromFile("pre.ssz_snappy") | ||
if err != nil { | ||
return err | ||
} | ||
expectedState, err := decodeStateFromFile("post.ssz_snappy") | ||
if err != nil { | ||
return err | ||
} | ||
blocks, err := testBlocks() | ||
if err != nil { | ||
return err | ||
} | ||
transistor := transition.New(testState, &clparams.MainnetBeaconConfig, nil, false) | ||
startSlot := testState.Slot() | ||
for _, block := range blocks { | ||
if err := transistor.TransitionState(block); err != nil { | ||
return fmt.Errorf("cannot transition state: %s. slot=%d. start_slot=%d", err, block.Block.Slot, startSlot) | ||
} | ||
} | ||
expectedRoot, err := expectedState.HashSSZ() | ||
if err != nil { | ||
return err | ||
} | ||
haveRoot, err := testState.HashSSZ() | ||
if err != nil { | ||
return err | ||
} | ||
if haveRoot != expectedRoot { | ||
return fmt.Errorf("mismatching state roots.") | ||
} | ||
return nil | ||
} |
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,46 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
|
||
"github.com/ledgerwatch/erigon/cl/clparams" | ||
"github.com/ledgerwatch/erigon/cl/cltypes" | ||
"github.com/ledgerwatch/erigon/cl/utils" | ||
"github.com/ledgerwatch/erigon/cmd/erigon-cl/core/state" | ||
) | ||
|
||
func decodeStateFromFile(filepath string) (*state.BeaconState, error) { | ||
sszSnappy, err := os.ReadFile(filepath) | ||
if err != nil { | ||
return nil, err | ||
} | ||
testState := state.New(&clparams.MainnetBeaconConfig) | ||
if err := utils.DecodeSSZSnappyWithVersion(testState, sszSnappy, int(testVersion)); err != nil { | ||
return nil, err | ||
} | ||
return testState, nil | ||
} | ||
|
||
func testBlocks() ([]*cltypes.SignedBeaconBlock, error) { | ||
i := 0 | ||
blocks := []*cltypes.SignedBeaconBlock{} | ||
var err error | ||
for { | ||
var blockBytes []byte | ||
blockBytes, err = os.ReadFile(fmt.Sprintf("blocks_%d.ssz_snappy", i)) | ||
if err != nil { | ||
break | ||
} | ||
blk := &cltypes.SignedBeaconBlock{} | ||
if err = utils.DecodeSSZSnappyWithVersion(blk, blockBytes, int(testVersion)); err != nil { | ||
return nil, err | ||
} | ||
blocks = append(blocks, blk) | ||
i++ | ||
} | ||
if os.IsNotExist(err) { | ||
err = nil | ||
} | ||
return blocks, err | ||
} |
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