Skip to content

Commit

Permalink
slot_actions: fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
marioevz committed Nov 23, 2023
1 parent fd76aab commit fc34e03
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 40 deletions.
10 changes: 5 additions & 5 deletions slot_actions/slot_actions.go
Original file line number Diff line number Diff line change
Expand Up @@ -205,10 +205,10 @@ func (s BlobGossipDelay) Execute(

type EquivocatingBlockAndBlobs struct {
Default
BroadcastBlobsFirst bool
// TODO: ModifyBlobs bool
// TODO: ModifyKZGProofs bool
AlternateRecipients bool
BroadcastBlobsFirst bool `json:"broadcast_blobs_first"`
// TODO: ModifyBlobs bool `json:"modify_blobs"`
// TODO: ModifyKZGProofs bool `json:"modify_kzg_proofs"`
AlternateRecipients bool `json:"alternate_recipients"`
}

func (s EquivocatingBlockAndBlobs) Name() string {
Expand Down Expand Up @@ -282,7 +282,7 @@ func (s EquivocatingBlockAndBlobs) Execute(

type EquivocatingBlockHeaderInBlobs struct {
Default
BroadcastBlobsFirst bool
BroadcastBlobsFirst bool `json:"broadcast_blobs_first"`
}

func (s EquivocatingBlockHeaderInBlobs) Name() string {
Expand Down
82 changes: 47 additions & 35 deletions slot_actions/slot_actions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,44 +40,56 @@ func TestSlotActionsJsonParsing(t *testing.T) {
t.Fatalf("UnmarshallSlotAction() delay_milliseconds = %d", actCast.DelayMilliseconds)
}
}
/*
TODO: Refactor this test

jsonString = `{
"name": "extra_blobs",
"incorrect_kzg_commitment": true
}
`
act, err = slot_actions.UnmarshallSlotAction([]byte(jsonString))
if err != nil {
t.Fatalf("UnmarshallSlotAction() error = %v", err)
}
if extraBlobs, ok := act.(*slot_actions.ExtraBlobs); !ok {
t.Fatalf("UnmarshallSlotAction() wrong type = %t", act)
} else {
if extraBlobs.IncorrectKZGCommitment != true {
t.Fatalf("UnmarshallSlotAction() incorrect_kzg_commitment = %t", extraBlobs.IncorrectKZGCommitment)
}
jsonString = `{
"name": "equivocating_block_and_blobs",
"broadcast_blobs_first": true,
"alternate_recipients": true
}`
act, err = slot_actions.UnmarshallSlotAction([]byte(jsonString))
if err != nil {
t.Fatalf("UnmarshallSlotAction() error = %v", err)
}
if actCast, ok := act.(*slot_actions.EquivocatingBlockAndBlobs); !ok {
t.Fatalf("UnmarshallSlotAction() wrong type = %t", act)
} else {
if actCast.BroadcastBlobsFirst != true {
t.Fatalf("UnmarshallSlotAction() broadcast_blobs_first = %t", actCast.BroadcastBlobsFirst)
}
jsonString = `{
"name": "conflicting_blobs",
"conflicting_blobs_count": 6,
"alternate_blob_recipients": true
if actCast.AlternateRecipients != true {
t.Fatalf("UnmarshallSlotAction() alternate_recipients = %t", actCast.AlternateRecipients)
}
`
act, err = slot_actions.UnmarshallSlotAction([]byte(jsonString))
if err != nil {
t.Fatalf("UnmarshallSlotAction() error = %v", err)
}

jsonString = `{
"name": "equivocating_block_header_in_blobs",
"broadcast_blobs_first": true
}`
act, err = slot_actions.UnmarshallSlotAction([]byte(jsonString))
if err != nil {
t.Fatalf("UnmarshallSlotAction() error = %v", err)
}
if actCast, ok := act.(*slot_actions.EquivocatingBlockHeaderInBlobs); !ok {
t.Fatalf("UnmarshallSlotAction() wrong type = %t", act)
} else {
if actCast.BroadcastBlobsFirst != true {
t.Fatalf("UnmarshallSlotAction() broadcast_blobs_first = %t", actCast.BroadcastBlobsFirst)
}
if conflictingBlobs, ok := act.(*slot_actions.ConflictingBlobs); !ok {
t.Fatalf("UnmarshallSlotAction() wrong type = %t", act)
} else {
if conflictingBlobs.ConflictingBlobsCount != 6 {
t.Fatalf("UnmarshallSlotAction() conflicting_blobs_count = %d", conflictingBlobs.ConflictingBlobsCount)
}
if conflictingBlobs.AlternateBlobRecipients != true {
t.Fatalf("UnmarshallSlotAction() alternate_blob_recipients = %t", conflictingBlobs.AlternateBlobRecipients)
}
}

jsonString = `{
"name": "equivocating_block",
"correct_block_delay_milliseconds": 1000
}`
act, err = slot_actions.UnmarshallSlotAction([]byte(jsonString))
if err != nil {
t.Fatalf("UnmarshallSlotAction() error = %v", err)
}
if actCast, ok := act.(*slot_actions.EquivocatingBlock); !ok {
t.Fatalf("UnmarshallSlotAction() wrong type = %t", act)
} else {
if actCast.CorrectBlockDelayMilliseconds != 1000 {
t.Fatalf("UnmarshallSlotAction() correct_block_delay_milliseconds = %d", actCast.CorrectBlockDelayMilliseconds)
}
*/
}
}

0 comments on commit fc34e03

Please sign in to comment.