From 3bf41f7af85740de25762898cb8c8efe11ec4837 Mon Sep 17 00:00:00 2001 From: Al Cutter Date: Mon, 9 Dec 2024 14:05:25 +0000 Subject: [PATCH] Add test for GetEntryBundle --- client/client_test.go | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/client/client_test.go b/client/client_test.go index eb67b2a8..10e34b1b 100644 --- a/client/client_test.go +++ b/client/client_test.go @@ -343,3 +343,44 @@ func TestHandleZeroRoot(t *testing.T) { t.Fatalf("NewProofBuilder: %v", err) } } + +func TestGetEntryBundleAddressing(t *testing.T) { + for _, test := range []struct { + name string + idx, logSize uint64 + wantPartialTileSize uint8 + }{ + { + name: "works - partial tile", + idx: 0, + logSize: 34, + wantPartialTileSize: 34, + }, + { + name: "works - full tile", + idx: 1, + logSize: 256*2 + 45, + wantPartialTileSize: 0, + }, + } { + t.Run(test.name, func(t *testing.T) { + gotIdx := uint64(0) + gotTileSize := uint8(0) + f := func(_ context.Context, i uint64, sz uint8) ([]byte, error) { + gotIdx = i + gotTileSize = sz + return []byte{}, nil + } + _, err := GetEntryBundle(context.Background(), f, test.idx, test.logSize) + if err != nil { + t.Fatalf("GetEntryBundle: %v", err) + } + if gotIdx != test.idx { + t.Errorf("f got idx %d, want %d", gotIdx, test.idx) + } + if gotTileSize != test.wantPartialTileSize { + t.Errorf("f got tileSize %d, want %d", gotTileSize, test.wantPartialTileSize) + } + }) + } +}