Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test: Types - ConsensusData #344

Merged
merged 11 commits into from
Jan 16, 2024
46 changes: 32 additions & 14 deletions types/spectest/all_tests.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,20 +39,38 @@ var AllTests = []SpecTest{
encryption.SimpleEncrypt(),
encryption.EncryptBLSSK(),

// TODO: consider removing tests below
consensusdata.Encoding(),
//consensusdata.DutyNil(),
//consensusdata.ValidAttester(),
//consensusdata.NoAttestationData(),
//consensusdata.ValidAggregator(),
//consensusdata.NoAggregatorData(),
//consensusdata.ValidProposer(),
//consensusdata.ValidBlindedProposer(),
//consensusdata.NilBlock(),
//consensusdata.BlockAndBlindedBlock(),
//consensusdata.ValidSyncCommitteeAggregator(),
//consensusdata.EmptySyncCommitteeAggregator(),
// TODO: add new consensusdata tests
consensusdata.InvalidDuty(),

consensusdata.ProposerConsensusDataEncoding(),
consensusdata.BlindedProposerConsensusDataEncoding(),
consensusdata.CapellaBlockValidation(),
consensusdata.CapellaBlindedBlockValidation(),
consensusdata.ProposerNoJustifications(),
consensusdata.InvalidCapellaBlindedBlockValidation(),
consensusdata.InvalidCapellaBlockValidation(),

consensusdata.AttestationConsensusDataEncoding(),
consensusdata.AttestationValidation(),
consensusdata.AttesterJustifications(),
consensusdata.InvalidAttestationValidation(),

consensusdata.AggregatorConsensusDataEncoding(),
consensusdata.AggregatorValidation(),
consensusdata.AggregatorNoJustifications(),
consensusdata.InvalidAggregatorValidation(),

consensusdata.SyncCommitteeConsensusDataEncoding(),
consensusdata.SyncCommitteeJustifications(),
consensusdata.SyncCommitteeNoJustifications(),
consensusdata.InvalidSyncCommitteeBlockValidation(),

consensusdata.SyncCommitteeContributionConsensusDataEncoding(),
consensusdata.SyncCommitteeContributionValidation(),
consensusdata.SyncCommitteeContributionNoJustifications(),
consensusdata.InvalidSyncCommitteeContributionValidation(),

consensusdata.ValidatorRegistration(),
consensusdata.VoluntaryExit(),

consensusdataproposer.VersionedBlockValidation(),
consensusdataproposer.VersionedBlindedBlockValidation(),
Expand Down
2 changes: 1 addition & 1 deletion types/spectest/generate/tests.json

Large diffs are not rendered by default.

6 changes: 6 additions & 0 deletions types/spectest/run_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,12 @@ func TestJson(t *testing.T) {
typedTest := &beacon.DepositDataSpecTest{}
require.NoError(t, json.Unmarshal(byts, &typedTest))
typedTest.Run(t)
case reflect.TypeOf(&consensusdata.ConsensusDataTest{}).String():
byts, err := json.Marshal(test)
require.NoError(t, err)
typedTest := &consensusdata.ConsensusDataTest{}
require.NoError(t, json.Unmarshal(byts, &typedTest))
typedTest.Run(t)
default:
t.Fatalf("unknown test")
}
Expand Down

This file was deleted.

12 changes: 10 additions & 2 deletions types/spectest/tests/consensusdata/aggregator_no_justifications.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
package consensusdata

import "github.com/bloxapp/ssv-spec/types/testingutils"

// AggregatorNoJustifications tests an invalid consensus data with no aggregator pre-consensus justifications
func AggregatorNoJustifications() *SpecTest {
panic("implement")
func AggregatorNoJustifications() *ConsensusDataTest {

// To-do: add error when pre-consensus justification check is added.

return &ConsensusDataTest{
Name: "aggregator without justification",
ConsensusData: *testingutils.TestAggregatorConsensusData,
}
}
11 changes: 9 additions & 2 deletions types/spectest/tests/consensusdata/aggregator_validation.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
package consensusdata

import "github.com/bloxapp/ssv-spec/types/testingutils"

// AggregatorValidation tests a valid consensus data with AggregateAndProof
func AggregatorValidation() *SpecTest {
panic("implement")
func AggregatorValidation() *ConsensusDataTest {
ks := testingutils.Testing4SharesSet()

return &ConsensusDataTest{
Name: "aggregator valid",
ConsensusData: *testingutils.TestAggregatorWithJustificationsConsensusData(ks),
}
}
9 changes: 7 additions & 2 deletions types/spectest/tests/consensusdata/attestation_validation.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
package consensusdata

import "github.com/bloxapp/ssv-spec/types/testingutils"

// AttestationValidation tests a valid consensus data with AttestationData
func AttestationValidation() *SpecTest {
panic("implement")
func AttestationValidation() *ConsensusDataTest {
return &ConsensusDataTest{
Name: "attestation validation",
ConsensusData: *testingutils.TestAttesterConsensusData,
}
}
25 changes: 23 additions & 2 deletions types/spectest/tests/consensusdata/attester_justifications.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,27 @@
package consensusdata

import (
"github.com/bloxapp/ssv-spec/types"
"github.com/bloxapp/ssv-spec/types/testingutils"
)

// AttesterJustifications tests an invalid consensus data with attester pre-consensus justifications
func AttesterJustifications() *SpecTest {
panic("implement")
func AttesterJustifications() *ConsensusDataTest {

ks := testingutils.Testing4SharesSet()

justif := make([]*types.SignedPartialSignatureMessage, 0)
for i := uint64(0); i <= ks.Threshold; i++ {
justif = append(justif, testingutils.PreConsensusRandaoMsg(ks.Shares[i+1], i+1))
}

cd := testingutils.TestAttesterConsensusData

cd.PreConsensusJustifications = justif

return &ConsensusDataTest{
Name: "invalid attestation with justification",
ConsensusData: *cd,
ExpectedError: "attester invalid justifications",
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
package consensusdata

import (
"github.com/attestantio/go-eth2-client/spec"
"github.com/bloxapp/ssv-spec/types/testingutils"
)

// CapellaBlindedBlockValidation tests a valid consensus data with capella blinded block
func CapellaBlindedBlockValidation() *SpecTest {
panic("implement")
func CapellaBlindedBlockValidation() *ConsensusDataTest {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In Deneb PR we should maybe add tests if they are not there?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, we will

ks := testingutils.Testing4SharesSet()

return &ConsensusDataTest{
Name: "valid capella blinded block",
ConsensusData: *testingutils.TestProposerBlindedWithJustificationsConsensusDataV(ks, spec.DataVersionCapella),
}
}
14 changes: 12 additions & 2 deletions types/spectest/tests/consensusdata/capella_block_validation.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
package consensusdata

import (
"github.com/attestantio/go-eth2-client/spec"
"github.com/bloxapp/ssv-spec/types/testingutils"
)

// CapellaBlockValidation tests a valid consensus data with capella block
func CapellaBlockValidation() *SpecTest {
panic("implement")
func CapellaBlockValidation() *ConsensusDataTest {
ks := testingutils.Testing4SharesSet()

return &ConsensusDataTest{
Name: "valid capella block",
ConsensusData: *testingutils.TestProposerWithJustificationsConsensusDataV(ks, spec.DataVersionCapella),
}
}
43 changes: 41 additions & 2 deletions types/spectest/tests/consensusdata/consensus_data_encoding.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,45 @@
package consensusdata

import (
"github.com/attestantio/go-eth2-client/spec"
"github.com/bloxapp/ssv-spec/types"
"github.com/bloxapp/ssv-spec/types/testingutils"
)

// ConsensusDataEncoding tests encoding and decoding ConsensusData for all duties
func ConsensusDataEncoding() *SpecTest {
panic("implement")
func ConsensusDataEncoding(name string, cd *types.ConsensusData) *EncodingTest {

byts, err := cd.Encode()
if err != nil {
panic(err.Error())
}
root, err := cd.HashTreeRoot()
if err != nil {
panic(err.Error())
}

return &EncodingTest{
Name: name,
Data: byts,
ExpectedRoot: root,
}
}

func ProposerConsensusDataEncoding() *EncodingTest {
return ConsensusDataEncoding("proposer encoding", testingutils.TestProposerBlindedBlockConsensusDataV(spec.DataVersionCapella))
}
func BlindedProposerConsensusDataEncoding() *EncodingTest {
return ConsensusDataEncoding("blinded proposer encoding", testingutils.TestProposerBlindedBlockConsensusDataV(spec.DataVersionCapella))
}
func AttestationConsensusDataEncoding() *EncodingTest {
return ConsensusDataEncoding("attestation encoding", testingutils.TestAttesterConsensusData)
}
func AggregatorConsensusDataEncoding() *EncodingTest {
return ConsensusDataEncoding("aggregation encoding", testingutils.TestAggregatorConsensusData)
}
func SyncCommitteeConsensusDataEncoding() *EncodingTest {
return ConsensusDataEncoding("sync committee encoding", testingutils.TestSyncCommitteeConsensusData)
}
func SyncCommitteeContributionConsensusDataEncoding() *EncodingTest {
return ConsensusDataEncoding("sync committee contribution encoding", testingutils.TestSyncCommitteeContributionConsensusData)
}
6 changes: 0 additions & 6 deletions types/spectest/tests/consensusdata/contributions_encoding.go

This file was deleted.

25 changes: 0 additions & 25 deletions types/spectest/tests/consensusdata/encoding.go

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,6 +1,19 @@
package consensusdata

import "github.com/bloxapp/ssv-spec/types/testingutils"

// InvalidAggregatorValidation tests an invalid consensus data with AggregateAndProof
func InvalidAggregatorValidation() *SpecTest {
panic("implement")
func InvalidAggregatorValidation() *ConsensusDataTest {

ks := testingutils.Testing4SharesSet()

cd := testingutils.TestAggregatorWithJustificationsConsensusData(ks)

cd.DataSSZ = testingutils.TestingSyncCommitteeBlockRoot[:]

return &ConsensusDataTest{
Name: "invalid aggregator data",
ConsensusData: *cd,
ExpectedError: "could not unmarshal ssz: incorrect size",
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
package consensusdata

import "github.com/bloxapp/ssv-spec/types/testingutils"

// InvalidAttestationValidation tests an invalid consensus data with AttestationData
func InvalidAttestationValidation() *SpecTest {
panic("implement")
func InvalidAttestationValidation() *ConsensusDataTest {

cd := testingutils.TestAttesterConsensusData
cd.DataSSZ = testingutils.TestAggregatorConsensusDataByts

return &ConsensusDataTest{
Name: "invalid attestation",
ConsensusData: *cd,
ExpectedError: "could not unmarshal ssz: incorrect size",
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,24 @@
package consensusdata

import (
"github.com/attestantio/go-eth2-client/spec"
"github.com/bloxapp/ssv-spec/types"
"github.com/bloxapp/ssv-spec/types/testingutils"
)

// InvalidCapellaBlindedBlockValidation tests an invalid consensus data with capella blinded block
func InvalidCapellaBlindedBlockValidation() *SpecTest {
panic("implement")
func InvalidCapellaBlindedBlockValidation() *ConsensusDataTest {

version := spec.DataVersionCapella

cd := &types.ConsensusData{
Duty: *testingutils.TestingProposerDutyV(version),
Version: version,
DataSSZ: []byte{},
}
return &ConsensusDataTest{
Name: "invalid capella blinded block",
ConsensusData: *cd,
ExpectedError: "could not unmarshal ssz: incorrect size",
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,24 @@
package consensusdata

import (
"github.com/attestantio/go-eth2-client/spec"
"github.com/bloxapp/ssv-spec/types"
"github.com/bloxapp/ssv-spec/types/testingutils"
)

// InvalidCapellaBlockValidation tests an invalid consensus data with capella block
func InvalidCapellaBlockValidation() *SpecTest {
panic("implement")
func InvalidCapellaBlockValidation() *ConsensusDataTest {

version := spec.DataVersionCapella

cd := &types.ConsensusData{
Duty: *testingutils.TestingProposerDutyV(version),
Version: version,
DataSSZ: []byte{},
}
return &ConsensusDataTest{
Name: "invalid capella block",
ConsensusData: *cd,
ExpectedError: "could not unmarshal ssz: incorrect size",
}
}
26 changes: 26 additions & 0 deletions types/spectest/tests/consensusdata/invalid_duty.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package consensusdata

import (
"github.com/attestantio/go-eth2-client/spec"
"github.com/bloxapp/ssv-spec/types"
"github.com/bloxapp/ssv-spec/types/testingutils"
)

// InvalidDuty tests an invalid consensus data with invalid duty
func InvalidDuty() *ConsensusDataTest {

cd := &types.ConsensusData{
Duty: types.Duty{
Type: types.BeaconRole(100),
PubKey: testingutils.TestingValidatorPubKey,
},
Version: spec.DataVersionCapella,
DataSSZ: testingutils.TestingAttestationDataBytes,
}

return &ConsensusDataTest{
Name: "invalid duty",
ConsensusData: *cd,
ExpectedError: "unknown duty role",
}
}
Loading