Skip to content

Commit

Permalink
test fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
rkapka committed Nov 2, 2024
1 parent 3aa75e2 commit 5ffe6fb
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 55 deletions.
46 changes: 25 additions & 21 deletions beacon-chain/core/light-client/lightclient_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,12 +82,12 @@ func TestLightClient_NewLightClientFinalityUpdateFromBeaconState(t *testing.T) {
require.DeepSSZEqual(t, finalizedBlockHeader.Header.ParentRoot, updateFinalizedHeaderBeacon.ParentRoot, "Finalized header parent root is not equal")
require.DeepSSZEqual(t, finalizedBlockHeader.Header.StateRoot, updateFinalizedHeaderBeacon.StateRoot, "Finalized header state root is not equal")
require.DeepSSZEqual(t, finalizedBlockHeader.Header.BodyRoot, updateFinalizedHeaderBeacon.BodyRoot, "Finalized header body root is not equal")
require.Equal(t, lightClient.FinalityBranchNumOfLeaves, len(update.FinalityBranch()), "Invalid finality branch leaves")

finalityBranch, err := l.AttestedState.FinalizedRootProof(l.Ctx)
fb, err := update.FinalityBranch()
require.NoError(t, err)
proof, err := l.AttestedState.FinalizedRootProof(l.Ctx)
require.NoError(t, err)
for i, leaf := range update.FinalityBranch() {
require.DeepSSZEqual(t, finalityBranch[i], leaf[:], "Leaf is not equal")
for i, leaf := range fb {
require.DeepSSZEqual(t, proof[i], leaf[:], "Leaf is not equal")
}
})
})
Expand Down Expand Up @@ -115,11 +115,12 @@ func TestLightClient_NewLightClientFinalityUpdateFromBeaconState(t *testing.T) {
require.DeepSSZEqual(t, finalizedBlockHeader.Header.ParentRoot, updateFinalizedHeaderBeacon.ParentRoot, "Finalized header parent root is not equal")
require.DeepSSZEqual(t, finalizedBlockHeader.Header.StateRoot, updateFinalizedHeaderBeacon.StateRoot, "Finalized header state root is not equal")
require.DeepSSZEqual(t, finalizedBlockHeader.Header.BodyRoot, updateFinalizedHeaderBeacon.BodyRoot, "Finalized header body root is not equal")
require.Equal(t, lightClient.FinalityBranchNumOfLeaves, len(update.FinalityBranch()), "Invalid finality branch leaves")
finalityBranch, err := l.AttestedState.FinalizedRootProof(l.Ctx)
fb, err := update.FinalityBranch()
require.NoError(t, err)
proof, err := l.AttestedState.FinalizedRootProof(l.Ctx)
require.NoError(t, err)
for i, leaf := range update.FinalityBranch() {
require.DeepSSZEqual(t, finalityBranch[i], leaf[:], "Leaf is not equal")
for i, leaf := range fb {
require.DeepSSZEqual(t, proof[i], leaf[:], "Leaf is not equal")
}

// Check Execution BlockHash
Expand Down Expand Up @@ -188,11 +189,12 @@ func TestLightClient_NewLightClientFinalityUpdateFromBeaconState(t *testing.T) {
require.DeepSSZEqual(t, finalizedBlockHeader.Header.ParentRoot, updateFinalizedHeaderBeacon.ParentRoot, "Finalized header parent root is not equal")
require.DeepSSZEqual(t, finalizedBlockHeader.Header.StateRoot, updateFinalizedHeaderBeacon.StateRoot, "Finalized header state root is not equal")
require.DeepSSZEqual(t, finalizedBlockHeader.Header.BodyRoot, updateFinalizedHeaderBeacon.BodyRoot, "Finalized header body root is not equal")
require.Equal(t, lightClient.FinalityBranchNumOfLeaves, len(update.FinalityBranch()), "Invalid finality branch leaves")
finalityBranch, err := l.AttestedState.FinalizedRootProof(l.Ctx)
fb, err := update.FinalityBranch()
require.NoError(t, err)
for i, leaf := range update.FinalityBranch() {
require.DeepSSZEqual(t, finalityBranch[i], leaf[:], "Leaf is not equal")
proof, err := l.AttestedState.FinalizedRootProof(l.Ctx)
require.NoError(t, err)
for i, leaf := range fb {
require.DeepSSZEqual(t, proof[i], leaf[:], "Leaf is not equal")
}
})
})
Expand Down Expand Up @@ -221,11 +223,12 @@ func TestLightClient_NewLightClientFinalityUpdateFromBeaconState(t *testing.T) {
require.DeepSSZEqual(t, finalizedBlockHeader.Header.ParentRoot, updateFinalizedHeaderBeacon.ParentRoot, "Finalized header parent root is not equal")
require.DeepSSZEqual(t, finalizedBlockHeader.Header.StateRoot, updateFinalizedHeaderBeacon.StateRoot, "Finalized header state root is not equal")
require.DeepSSZEqual(t, finalizedBlockHeader.Header.BodyRoot, updateFinalizedHeaderBeacon.BodyRoot, "Finalized header body root is not equal")
require.Equal(t, lightClient.FinalityBranchNumOfLeaves, len(update.FinalityBranch()), "Invalid finality branch leaves")
finalityBranch, err := l.AttestedState.FinalizedRootProof(l.Ctx)
fb, err := update.FinalityBranch()
require.NoError(t, err)
proof, err := l.AttestedState.FinalizedRootProof(l.Ctx)
require.NoError(t, err)
for i, leaf := range update.FinalityBranch() {
require.DeepSSZEqual(t, finalityBranch[i], leaf[:], "Leaf is not equal")
for i, leaf := range fb {
require.DeepSSZEqual(t, proof[i], leaf[:], "Leaf is not equal")
}

// Check Execution BlockHash
Expand Down Expand Up @@ -295,11 +298,12 @@ func TestLightClient_NewLightClientFinalityUpdateFromBeaconState(t *testing.T) {
require.DeepSSZEqual(t, finalizedBlockHeader.Header.ParentRoot, updateFinalizedHeaderBeacon.ParentRoot, "Finalized header parent root is not equal")
require.DeepSSZEqual(t, finalizedBlockHeader.Header.StateRoot, updateFinalizedHeaderBeacon.StateRoot, "Finalized header state root is not equal")
require.DeepSSZEqual(t, finalizedBlockHeader.Header.BodyRoot, updateFinalizedHeaderBeacon.BodyRoot, "Finalized header body root is not equal")
require.Equal(t, lightClient.FinalityBranchNumOfLeaves, len(update.FinalityBranch()), "Invalid finality branch leaves")
finalityBranch, err := l.AttestedState.FinalizedRootProof(l.Ctx)
fb, err := update.FinalityBranch()
require.NoError(t, err)
proof, err := l.AttestedState.FinalizedRootProof(l.Ctx)
require.NoError(t, err)
for i, leaf := range update.FinalityBranch() {
require.DeepSSZEqual(t, finalityBranch[i], leaf[:], "Leaf is not equal")
for i, leaf := range fb {
require.DeepSSZEqual(t, proof[i], leaf[:], "Leaf is not equal")
}

// Check Execution BlockHash
Expand Down
11 changes: 10 additions & 1 deletion beacon-chain/rpc/eth/light-client/handlers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1881,6 +1881,7 @@ func createUpdate(t *testing.T, v int) (interfaces.LightClientUpdate, error) {
config := params.BeaconConfig()
var slot primitives.Slot
var header interfaces.LightClientHeader
var st state.BeaconState
var err error

sampleRoot := make([]byte, 32)
Expand Down Expand Up @@ -1909,6 +1910,8 @@ func createUpdate(t *testing.T, v int) (interfaces.LightClientUpdate, error) {
},
})
require.NoError(t, err)
st, err = util.NewBeaconStateAltair()
require.NoError(t, err)
case version.Capella:
slot = primitives.Slot(config.CapellaForkEpoch * primitives.Epoch(config.SlotsPerEpoch)).Add(1)
header, err = light_client.NewWrappedHeader(&pb.LightClientHeaderCapella{
Expand All @@ -1935,6 +1938,8 @@ func createUpdate(t *testing.T, v int) (interfaces.LightClientUpdate, error) {
ExecutionBranch: sampleExecutionBranch,
})
require.NoError(t, err)
st, err = util.NewBeaconStateCapella()
require.NoError(t, err)
case version.Deneb:
slot = primitives.Slot(config.DenebForkEpoch * primitives.Epoch(config.SlotsPerEpoch)).Add(1)
header, err = light_client.NewWrappedHeader(&pb.LightClientHeaderDeneb{
Expand All @@ -1961,6 +1966,8 @@ func createUpdate(t *testing.T, v int) (interfaces.LightClientUpdate, error) {
ExecutionBranch: sampleExecutionBranch,
})
require.NoError(t, err)
st, err = util.NewBeaconStateDeneb()
require.NoError(t, err)
case version.Electra:
slot = primitives.Slot(config.ElectraForkEpoch * primitives.Epoch(config.SlotsPerEpoch)).Add(1)
header, err = light_client.NewWrappedHeader(&pb.LightClientHeaderDeneb{
Expand All @@ -1987,11 +1994,13 @@ func createUpdate(t *testing.T, v int) (interfaces.LightClientUpdate, error) {
ExecutionBranch: sampleExecutionBranch,
})
require.NoError(t, err)
st, err = util.NewBeaconStateElectra()
require.NoError(t, err)
default:
return nil, fmt.Errorf("unsupported version %s", version.String(v))
}

update, err := lightclient.CreateDefaultLightClientUpdate(slot)
update, err := lightclient.CreateDefaultLightClientUpdate(slot, st)
require.NoError(t, err)
update.SetSignatureSlot(slot - 1)
syncCommitteeBits := make([]byte, 64)
Expand Down
Loading

0 comments on commit 5ffe6fb

Please sign in to comment.