@@ -24,6 +24,7 @@ import (
24
24
"fmt"
25
25
"math"
26
26
"math/big"
27
+ "math/rand"
27
28
"os"
28
29
"path/filepath"
29
30
"reflect"
@@ -41,6 +42,7 @@ import (
41
42
"github.com/ethereum/go-ethereum/core/types"
42
43
"github.com/ethereum/go-ethereum/crypto"
43
44
"github.com/ethereum/go-ethereum/crypto/kzg4844"
45
+ "github.com/ethereum/go-ethereum/internal/testrand"
44
46
"github.com/ethereum/go-ethereum/params"
45
47
"github.com/ethereum/go-ethereum/rlp"
46
48
"github.com/holiman/billy"
@@ -1814,10 +1816,10 @@ func TestGetBlobs(t *testing.T) {
1814
1816
}
1815
1817
1816
1818
cases := []struct {
1817
- start int
1818
- limit int
1819
- version byte
1820
- expErr bool
1819
+ start int
1820
+ limit int
1821
+ fillRandom bool
1822
+ version byte
1821
1823
}{
1822
1824
{
1823
1825
start : 0 , limit : 6 ,
@@ -1827,6 +1829,14 @@ func TestGetBlobs(t *testing.T) {
1827
1829
start : 0 , limit : 6 ,
1828
1830
version : types .BlobSidecarVersion1 ,
1829
1831
},
1832
+ {
1833
+ start : 0 , limit : 6 , fillRandom : true ,
1834
+ version : types .BlobSidecarVersion0 ,
1835
+ },
1836
+ {
1837
+ start : 0 , limit : 6 , fillRandom : true ,
1838
+ version : types .BlobSidecarVersion1 ,
1839
+ },
1830
1840
{
1831
1841
start : 3 , limit : 9 ,
1832
1842
version : types .BlobSidecarVersion0 ,
@@ -1835,6 +1845,14 @@ func TestGetBlobs(t *testing.T) {
1835
1845
start : 3 , limit : 9 ,
1836
1846
version : types .BlobSidecarVersion1 ,
1837
1847
},
1848
+ {
1849
+ start : 3 , limit : 9 , fillRandom : true ,
1850
+ version : types .BlobSidecarVersion0 ,
1851
+ },
1852
+ {
1853
+ start : 3 , limit : 9 , fillRandom : true ,
1854
+ version : types .BlobSidecarVersion1 ,
1855
+ },
1838
1856
{
1839
1857
start : 3 , limit : 15 ,
1840
1858
version : types .BlobSidecarVersion0 ,
@@ -1843,6 +1861,14 @@ func TestGetBlobs(t *testing.T) {
1843
1861
start : 3 , limit : 15 ,
1844
1862
version : types .BlobSidecarVersion1 ,
1845
1863
},
1864
+ {
1865
+ start : 3 , limit : 15 , fillRandom : true ,
1866
+ version : types .BlobSidecarVersion0 ,
1867
+ },
1868
+ {
1869
+ start : 3 , limit : 15 , fillRandom : true ,
1870
+ version : types .BlobSidecarVersion1 ,
1871
+ },
1846
1872
{
1847
1873
start : 0 , limit : 18 ,
1848
1874
version : types .BlobSidecarVersion0 ,
@@ -1852,58 +1878,79 @@ func TestGetBlobs(t *testing.T) {
1852
1878
version : types .BlobSidecarVersion1 ,
1853
1879
},
1854
1880
{
1855
- start : 18 , limit : 20 ,
1881
+ start : 0 , limit : 18 , fillRandom : true ,
1856
1882
version : types .BlobSidecarVersion0 ,
1857
- expErr : true ,
1883
+ },
1884
+ {
1885
+ start : 0 , limit : 18 , fillRandom : true ,
1886
+ version : types .BlobSidecarVersion1 ,
1858
1887
},
1859
1888
}
1860
1889
for i , c := range cases {
1861
- var vhashes []common.Hash
1890
+ var (
1891
+ vhashes []common.Hash
1892
+ filled = make (map [int ]struct {})
1893
+ )
1894
+ if c .fillRandom {
1895
+ filled [len (vhashes )] = struct {}{}
1896
+ vhashes = append (vhashes , testrand .Hash ())
1897
+ }
1862
1898
for j := c .start ; j < c .limit ; j ++ {
1863
1899
vhashes = append (vhashes , testBlobVHashes [j ])
1900
+ if c .fillRandom && rand .Intn (2 ) == 0 {
1901
+ filled [len (vhashes )] = struct {}{}
1902
+ vhashes = append (vhashes , testrand .Hash ())
1903
+ }
1904
+ }
1905
+ if c .fillRandom {
1906
+ filled [len (vhashes )] = struct {}{}
1907
+ vhashes = append (vhashes , testrand .Hash ())
1864
1908
}
1865
1909
blobs , _ , proofs , err := pool .GetBlobs (vhashes , c .version )
1910
+ if err != nil {
1911
+ t .Errorf ("Unexpected error for case %d, %v" , i , err )
1912
+ }
1866
1913
1867
- if c .expErr {
1868
- if err == nil {
1869
- t .Errorf ("Unexpected return, want error for case %d" , i )
1914
+ // Cross validate what we received vs what we wanted
1915
+ length := c .limit - c .start
1916
+ wantLen := length + len (filled )
1917
+ if len (blobs ) != wantLen || len (proofs ) != wantLen {
1918
+ t .Errorf ("retrieved blobs/proofs size mismatch: have %d/%d, want %d" , len (blobs ), len (proofs ), wantLen )
1919
+ continue
1920
+ }
1921
+
1922
+ var unknown int
1923
+ for j := 0 ; j < len (blobs ); j ++ {
1924
+ if _ , exist := filled [j ]; exist {
1925
+ if blobs [j ] != nil || proofs [j ] != nil {
1926
+ t .Errorf ("Unexpected blob and proof, item %d" , j )
1927
+ }
1928
+ unknown ++
1929
+ continue
1870
1930
}
1871
- } else {
1872
- if err != nil {
1873
- t .Errorf ("Unexpected error for case %d, %v" , i , err )
1931
+ // If an item is missing, but shouldn't, error
1932
+ if blobs [j ] == nil || proofs [j ] == nil {
1933
+ t .Errorf ("tracked blob retrieval failed: item %d, hash %x" , j , vhashes [j ])
1934
+ continue
1874
1935
}
1875
- // Cross validate what we received vs what we wanted
1876
- length := c .limit - c .start
1877
- if len (blobs ) != length || len (proofs ) != length {
1878
- t .Errorf ("retrieved blobs/proofs size mismatch: have %d/%d, want %d" , len (blobs ), len (proofs ), length )
1936
+ // Item retrieved, make sure the blob matches the expectation
1937
+ if * blobs [j ] != * testBlobs [c .start + j - unknown ] {
1938
+ t .Errorf ("retrieved blob mismatch: item %d, hash %x" , j , vhashes [j ])
1879
1939
continue
1880
1940
}
1881
- for j := 0 ; j < len (blobs ); j ++ {
1882
- // If an item is missing, but shouldn't, error
1883
- if blobs [j ] == nil || proofs [j ] == nil {
1884
- t .Errorf ("tracked blob retrieval failed: item %d, hash %x" , j , vhashes [j ])
1885
- continue
1941
+ // Item retrieved, make sure the proof matches the expectation
1942
+ if c .version == types .BlobSidecarVersion0 {
1943
+ if proofs [j ][0 ] != testBlobProofs [c .start + j - unknown ] {
1944
+ t .Errorf ("retrieved proof mismatch: item %d, hash %x" , j , vhashes [j ])
1886
1945
}
1887
- // Item retrieved, make sure the blob matches the expectation
1888
- if * blobs [j ] != * testBlobs [c .start + j ] {
1889
- t .Errorf ("retrieved blob mismatch: item %d, hash %x" , j , vhashes [j ])
1890
- continue
1891
- }
1892
- // Item retrieved, make sure the proof matches the expectation
1893
- if c .version == types .BlobSidecarVersion0 {
1894
- if proofs [j ][0 ] != testBlobProofs [c .start + j ] {
1895
- t .Errorf ("retrieved proof mismatch: item %d, hash %x" , j , vhashes [j ])
1896
- }
1897
- } else {
1898
- want , _ := kzg4844 .ComputeCellProofs (blobs [j ])
1899
- if ! reflect .DeepEqual (want , proofs [j ]) {
1900
- t .Errorf ("retrieved proof mismatch: item %d, hash %x" , j , vhashes [j ])
1901
- }
1946
+ } else {
1947
+ want , _ := kzg4844 .ComputeCellProofs (blobs [j ])
1948
+ if ! reflect .DeepEqual (want , proofs [j ]) {
1949
+ t .Errorf ("retrieved proof mismatch: item %d, hash %x" , j , vhashes [j ])
1902
1950
}
1903
1951
}
1904
1952
}
1905
1953
}
1906
-
1907
1954
pool .Close ()
1908
1955
}
1909
1956
0 commit comments