github.com/ethereum/go-ethereum@v1.14.4-0.20240516095835-473ee8fc07a3/core/txpool/blobpool/slotter_test.go (about) 1 // Copyright 2023 The go-ethereum Authors 2 // This file is part of the go-ethereum library. 3 // 4 // The go-ethereum library is free software: you can redistribute it and/or modify 5 // it under the terms of the GNU Lesser General Public License as published by 6 // the Free Software Foundation, either version 3 of the License, or 7 // (at your option) any later version. 8 // 9 // The go-ethereum library is distributed in the hope that it will be useful, 10 // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 // GNU Lesser General Public License for more details. 13 // 14 // You should have received a copy of the GNU Lesser General Public License 15 // along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>. 16 17 package blobpool 18 19 import "testing" 20 21 // Tests that the slotter creates the expected database shelves. 22 func TestNewSlotter(t *testing.T) { 23 // Generate the database shelve sizes 24 slotter := newSlotter() 25 26 var shelves []uint32 27 for { 28 shelf, done := slotter() 29 shelves = append(shelves, shelf) 30 if done { 31 break 32 } 33 } 34 // Compare the database shelves to the expected ones 35 want := []uint32{ 36 0*blobSize + txAvgSize, // 0 blob + some expected tx infos 37 1*blobSize + txAvgSize, // 1 blob + some expected tx infos 38 2*blobSize + txAvgSize, // 2 blob + some expected tx infos (could be fewer blobs and more tx data) 39 3*blobSize + txAvgSize, // 3 blob + some expected tx infos (could be fewer blobs and more tx data) 40 4*blobSize + txAvgSize, // 4 blob + some expected tx infos (could be fewer blobs and more tx data) 41 5*blobSize + txAvgSize, // 1-6 blobs + unexpectedly large tx infos < 4 blobs + max tx metadata size 42 6*blobSize + txAvgSize, // 1-6 blobs + unexpectedly large tx infos < 4 blobs + max tx metadata size 43 7*blobSize + txAvgSize, // 1-6 blobs + unexpectedly large tx infos < 4 blobs + max tx metadata size 44 8*blobSize + txAvgSize, // 1-6 blobs + unexpectedly large tx infos < 4 blobs + max tx metadata size 45 9*blobSize + txAvgSize, // 1-6 blobs + unexpectedly large tx infos < 4 blobs + max tx metadata size 46 10*blobSize + txAvgSize, // 1-6 blobs + unexpectedly large tx infos < 4 blobs + max tx metadata size 47 11*blobSize + txAvgSize, // 1-6 blobs + unexpectedly large tx infos < 4 blobs + max tx metadata size 48 12*blobSize + txAvgSize, // 1-6 blobs + unexpectedly large tx infos < 4 blobs + max tx metadata size 49 13*blobSize + txAvgSize, // 1-6 blobs + unexpectedly large tx infos < 4 blobs + max tx metadata size 50 14*blobSize + txAvgSize, // 1-6 blobs + unexpectedly large tx infos >= 4 blobs + max tx metadata size 51 } 52 if len(shelves) != len(want) { 53 t.Errorf("shelves count mismatch: have %d, want %d", len(shelves), len(want)) 54 } 55 for i := 0; i < len(shelves) && i < len(want); i++ { 56 if shelves[i] != want[i] { 57 t.Errorf("shelf %d mismatch: have %d, want %d", i, shelves[i], want[i]) 58 } 59 } 60 }