-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Prysm rpc: Get payload attestation data
- Loading branch information
1 parent
5ba33f7
commit c45122b
Showing
15 changed files
with
234 additions
and
107 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
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
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
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
76 changes: 76 additions & 0 deletions
76
beacon-chain/rpc/prysm/v1alpha1/validator/ptc_attester_test.go
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,76 @@ | ||
package validator | ||
|
||
import ( | ||
"testing" | ||
"time" | ||
|
||
mock "github.com/prysmaticlabs/prysm/v5/beacon-chain/blockchain/testing" | ||
"github.com/prysmaticlabs/prysm/v5/config/params" | ||
"github.com/prysmaticlabs/prysm/v5/consensus-types/primitives" | ||
ethpb "github.com/prysmaticlabs/prysm/v5/proto/prysm/v1alpha1" | ||
"github.com/prysmaticlabs/prysm/v5/testing/require" | ||
) | ||
|
||
func TestServer_GetPayloadAttestationData(t *testing.T) { | ||
t.Run("Not current slot", func(t *testing.T) { | ||
s := &Server{ | ||
TimeFetcher: &mock.ChainService{Genesis: time.Unix(time.Now().Unix()-int64(params.BeaconConfig().SecondsPerSlot), 0)}, | ||
} | ||
_, err := s.GetPayloadAttestationData(nil, ðpb.GetPayloadAttestationDataRequest{Slot: 2}) | ||
require.ErrorContains(t, "Payload attestation request slot 2 != current slot 1", err) | ||
}) | ||
|
||
t.Run("Last received block is not from current slot", func(t *testing.T) { | ||
s := &Server{ | ||
TimeFetcher: &mock.ChainService{Genesis: time.Unix(time.Now().Unix()-int64(2*params.BeaconConfig().SecondsPerSlot), 0)}, | ||
ForkchoiceFetcher: &mock.ChainService{HighestReceivedSlot: 1}, | ||
} | ||
_, err := s.GetPayloadAttestationData(nil, ðpb.GetPayloadAttestationDataRequest{Slot: 2}) | ||
require.ErrorContains(t, "Did not receive current slot 2 block ", err) | ||
}) | ||
|
||
t.Run("Payload is absent", func(t *testing.T) { | ||
slot := primitives.Slot(2) | ||
root := [32]byte{1} | ||
s := &Server{ | ||
TimeFetcher: &mock.ChainService{Genesis: time.Unix(time.Now().Unix()-int64(2*params.BeaconConfig().SecondsPerSlot), 0)}, | ||
ForkchoiceFetcher: &mock.ChainService{HighestReceivedSlot: slot, HighestReceivedRoot: root}, | ||
ExecutionPayloadReceiver: &mock.ChainService{HasPayload: false}, | ||
} | ||
d, err := s.GetPayloadAttestationData(nil, ðpb.GetPayloadAttestationDataRequest{Slot: slot}) | ||
require.NoError(t, err) | ||
require.DeepEqual(t, root[:], d.BeaconBlockRoot) | ||
require.Equal(t, slot, d.Slot) | ||
require.Equal(t, primitives.PAYLOAD_ABSENT, d.PayloadStatus) | ||
}) | ||
|
||
t.Run("Payload is present", func(t *testing.T) { | ||
slot := primitives.Slot(2) | ||
root := [32]byte{1} | ||
s := &Server{ | ||
TimeFetcher: &mock.ChainService{Genesis: time.Unix(time.Now().Unix()-int64(2*params.BeaconConfig().SecondsPerSlot), 0)}, | ||
ForkchoiceFetcher: &mock.ChainService{HighestReceivedSlot: slot, HighestReceivedRoot: root}, | ||
ExecutionPayloadReceiver: &mock.ChainService{HasPayload: true, PayloadStatus: primitives.PAYLOAD_PRESENT}, | ||
} | ||
d, err := s.GetPayloadAttestationData(nil, ðpb.GetPayloadAttestationDataRequest{Slot: slot}) | ||
require.NoError(t, err) | ||
require.DeepEqual(t, root[:], d.BeaconBlockRoot) | ||
require.Equal(t, slot, d.Slot) | ||
require.Equal(t, primitives.PAYLOAD_PRESENT, d.PayloadStatus) | ||
}) | ||
|
||
t.Run("Payload is withheld", func(t *testing.T) { | ||
slot := primitives.Slot(2) | ||
root := [32]byte{1} | ||
s := &Server{ | ||
TimeFetcher: &mock.ChainService{Genesis: time.Unix(time.Now().Unix()-int64(2*params.BeaconConfig().SecondsPerSlot), 0)}, | ||
ForkchoiceFetcher: &mock.ChainService{HighestReceivedSlot: slot, HighestReceivedRoot: root}, | ||
ExecutionPayloadReceiver: &mock.ChainService{HasPayload: true, PayloadStatus: primitives.PAYLOAD_WITHHELD}, | ||
} | ||
d, err := s.GetPayloadAttestationData(nil, ðpb.GetPayloadAttestationDataRequest{Slot: slot}) | ||
require.NoError(t, err) | ||
require.DeepEqual(t, root[:], d.BeaconBlockRoot) | ||
require.Equal(t, slot, d.Slot) | ||
require.Equal(t, primitives.PAYLOAD_WITHHELD, d.PayloadStatus) | ||
}) | ||
} |
Oops, something went wrong.