Skip to content
Draft
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
3 changes: 2 additions & 1 deletion core/types/tx_blob.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,9 @@ func (sc *BlobTxSidecar) ToV1() error {
}
sc.Version = BlobSidecarVersion1
sc.Proofs = proofs
return nil
}
return nil
return fmt.Errorf("unsupported blob sidecar version %d", sc.Version)
}

// encodedSize computes the RLP size of the sidecar elements. This does NOT return the
Expand Down
77 changes: 77 additions & 0 deletions core/types/tx_blob_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,3 +105,80 @@
}
return blobtx
}

func TestBlobTxSidecarToV1(t *testing.T) {

Check failure on line 109 in core/types/tx_blob_test.go

View workflow job for this annotation

GitHub Actions / Lint

unnecessary leading newline (whitespace)

// Standard case, converting from v0 to v1
t.Run("V0ToV1", func(t *testing.T) {
sidecar := NewBlobTxSidecar(
BlobSidecarVersion0,
[]kzg4844.Blob{*emptyBlob},
[]kzg4844.Commitment{emptyBlobCommit},
[]kzg4844.Proof{emptyBlobProof},
)

if err := sidecar.ToV1(); err != nil {
t.Fatalf("failed: %v", err)
}

if sidecar.Version != BlobSidecarVersion1 {
t.Errorf("expected version %d, got %d", BlobSidecarVersion1, sidecar.Version)
}

// Version 1 should have 128 cell proofs per blob
expectedProofs := len(sidecar.Blobs) * kzg4844.CellProofsPerBlob
if len(sidecar.Proofs) != expectedProofs {
t.Errorf("expected %d proofs, got %d", expectedProofs, len(sidecar.Proofs))
}
})

// Already v1 so its a noop
t.Run("AlreadyV1", func(t *testing.T) {
cellProofs, err := kzg4844.ComputeCellProofs(emptyBlob)
if err != nil {
t.Fatalf("ComputeCellProofs failed: %v", err)
}

sidecar := NewBlobTxSidecar(
BlobSidecarVersion1,
[]kzg4844.Blob{*emptyBlob},
[]kzg4844.Commitment{emptyBlobCommit},
cellProofs,
)

originalProofs := len(sidecar.Proofs)

if err := sidecar.ToV1(); err != nil {
t.Fatalf("failed: %v", err)
}

if sidecar.Version != BlobSidecarVersion1 {
t.Errorf("expected version %d, got %d", BlobSidecarVersion1, sidecar.Version)
}

if len(sidecar.Proofs) != originalProofs {
t.Errorf("proofs were modified: expected %d, got %d", originalProofs, len(sidecar.Proofs))
}
})

// Invalid version should return error
t.Run("InvalidVersion", func(t *testing.T) {
invalidVersion := byte(2)
sidecar := NewBlobTxSidecar(
invalidVersion,
[]kzg4844.Blob{*emptyBlob},
[]kzg4844.Commitment{emptyBlobCommit},
[]kzg4844.Proof{emptyBlobProof},
)

err := sidecar.ToV1()
if err == nil {
t.Errorf("Invalid version %d should return error, but got nil", invalidVersion)
}

// The version shouldn't change on error
if sidecar.Version != invalidVersion {
t.Errorf("version changed from %d to %d on error", invalidVersion, sidecar.Version)
}
})
}
Loading