Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions api/v1/gloas/generate.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,7 @@ types:
output: blockcontents_ssz.go
- name: SignedExecutionPayloadEnvelopeContents
output: signedexecutionpayloadenvelopecontents_ssz.go
- name: PayloadAttestationMessages
output: payloadattestationmessages_ssz.go
- name: SignedProposerPreferencesList
output: signedproposerpreferenceslist_ssz.go
101 changes: 101 additions & 0 deletions api/v1/gloas/lists_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
// Copyright © 2026 Attestant Limited.
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package gloas_test

import (
"testing"

apiv1gloas "github.com/attestantio/go-eth2-client/api/v1/gloas"
"github.com/attestantio/go-eth2-client/spec/gloas"
"github.com/attestantio/go-eth2-client/spec/phase0"
"github.com/stretchr/testify/require"
)

func testPayloadAttestationMessage(i byte) *gloas.PayloadAttestationMessage {
return &gloas.PayloadAttestationMessage{
ValidatorIndex: phase0.ValidatorIndex(i),
Data: &gloas.PayloadAttestationData{
BeaconBlockRoot: phase0.Root{i},
Slot: phase0.Slot(i),
PayloadPresent: i%2 == 0,
BlobDataAvailable: true,
},
Signature: phase0.BLSSignature{i},
}
}

func testSignedProposerPreferences(i byte) *gloas.SignedProposerPreferences {
return &gloas.SignedProposerPreferences{
Message: &gloas.ProposerPreferences{
DependentRoot: phase0.Root{i},
ProposalSlot: phase0.Slot(i),
ValidatorIndex: phase0.ValidatorIndex(i),
FeeRecipient: [20]byte{i},
TargetGasLimit: 60_000_000,
},
Signature: phase0.BLSSignature{i},
}
}

// TestPayloadAttestationMessagesSSZ asserts the List[PayloadAttestationMessage, PTC_SIZE] encoding
// used by POST /eth/v1/beacon/pool/payload_attestations.
func TestPayloadAttestationMessagesSSZ(t *testing.T) {
list := apiv1gloas.PayloadAttestationMessages{testPayloadAttestationMessage(1), testPayloadAttestationMessage(2)}

data, err := list.MarshalSSZ()
require.NoError(t, err)

// The list of fixed size containers is the concatenation of the elements.
first, err := list[0].MarshalSSZ()
require.NoError(t, err)
require.Equal(t, first, data[:len(first)])
require.Len(t, data, 2*len(first))

var decoded apiv1gloas.PayloadAttestationMessages
require.NoError(t, decoded.UnmarshalSSZ(data))
require.Equal(t, list, decoded)

var empty apiv1gloas.PayloadAttestationMessages
require.NoError(t, empty.UnmarshalSSZ(nil))
require.Empty(t, empty)

require.Error(t, decoded.UnmarshalSSZ(data[:len(data)-1]), "misaligned body")

tooMany := make([]byte, (512+1)*len(first))
require.Error(t, decoded.UnmarshalSSZ(tooMany), "over PTC_SIZE")
}

// TestSignedProposerPreferencesListSSZ asserts the
// List[SignedProposerPreferences, (MIN_SEED_LOOKAHEAD + 1) * SLOTS_PER_EPOCH] encoding
// used by POST /eth/v1/validator/proposer_preferences.
func TestSignedProposerPreferencesListSSZ(t *testing.T) {
list := apiv1gloas.SignedProposerPreferencesList{testSignedProposerPreferences(1), testSignedProposerPreferences(2)}

data, err := list.MarshalSSZ()
require.NoError(t, err)

first, err := list[0].MarshalSSZ()
require.NoError(t, err)
require.Equal(t, first, data[:len(first)])
require.Len(t, data, 2*len(first))

var decoded apiv1gloas.SignedProposerPreferencesList
require.NoError(t, decoded.UnmarshalSSZ(data))
require.Equal(t, list, decoded)

require.Error(t, decoded.UnmarshalSSZ(data[:len(data)-1]), "misaligned body")

tooMany := make([]byte, (64+1)*len(first))
require.Error(t, decoded.UnmarshalSSZ(tooMany), "over (MIN_SEED_LOOKAHEAD+1)*SLOTS_PER_EPOCH")
}
38 changes: 38 additions & 0 deletions api/v1/gloas/payloadattestationmessages.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// Copyright © 2026 Attestant Limited.
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package gloas

import (
"encoding/json"
"fmt"

"github.com/attestantio/go-eth2-client/spec/gloas"
"github.com/pk910/dynamic-ssz/sszutils"
)

// PayloadAttestationMessages is the List[PayloadAttestationMessage, PTC_SIZE] submitted to
// POST /eth/v1/beacon/pool/payload_attestations.
type PayloadAttestationMessages []*gloas.PayloadAttestationMessage

var _ = sszutils.Annotate[PayloadAttestationMessages](`ssz-max:"512" dynssz-max:"PTC_SIZE"`)

// String returns a string version of the structure.
func (p *PayloadAttestationMessages) String() string {
data, err := json.Marshal(p)
if err != nil {
return fmt.Sprintf("ERR: %v", err)
}

return string(data)
}
111 changes: 111 additions & 0 deletions api/v1/gloas/payloadattestationmessages_ssz.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

38 changes: 38 additions & 0 deletions api/v1/gloas/signedproposerpreferenceslist.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// Copyright © 2026 Attestant Limited.
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package gloas

import (
"encoding/json"
"fmt"

"github.com/attestantio/go-eth2-client/spec/gloas"
"github.com/pk910/dynamic-ssz/sszutils"
)

// SignedProposerPreferencesList is the List[SignedProposerPreferences, (MIN_SEED_LOOKAHEAD + 1) * SLOTS_PER_EPOCH]
// submitted to POST /eth/v1/validator/proposer_preferences.
type SignedProposerPreferencesList []*gloas.SignedProposerPreferences

var _ = sszutils.Annotate[SignedProposerPreferencesList](`ssz-max:"64" dynssz-max:"(MIN_SEED_LOOKAHEAD+1)*SLOTS_PER_EPOCH"`)

// String returns a string version of the structure.
func (s *SignedProposerPreferencesList) String() string {
data, err := json.Marshal(s)
if err != nil {
return fmt.Sprintf("ERR: %v", err)
}

return string(data)
}
Loading
Loading