From 124fa8af785f30c17250c5e137b82364459cf2eb Mon Sep 17 00:00:00 2001 From: Martin Hutchinson Date: Mon, 11 Dec 2023 12:20:37 +0000 Subject: [PATCH] Make uninitializedBegin test accurately test its intention This was previously creating and initializing a tree, and then testing what happened if you created a transaction on a tree ID that definitely didn't exist. What it was trying to test was something different, which is the case where a tree had been created/defined, but was not initialized with an empty log root yet. The test now reflects that. This allows #3201 to avoid a nil check for something that otherwise will be guaranteed to exist. --- integration/storagetest/logtests.go | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/integration/storagetest/logtests.go b/integration/storagetest/logtests.go index 8dcaef20fb..aafd8bad22 100644 --- a/integration/storagetest/logtests.go +++ b/integration/storagetest/logtests.go @@ -146,23 +146,22 @@ func (*logTests) TestSnapshot(ctx context.Context, t *testing.T, s storage.LogSt func (*logTests) TestReadWriteTransaction(ctx context.Context, t *testing.T, s storage.LogStorage, as storage.AdminStorage) { activeLog := mustCreateTree(ctx, t, as, storageto.LogTree) - mustSignAndStoreLogRoot(ctx, t, s, activeLog, &types.LogRootV1{RootHash: []byte{0}}) tests := []struct { desc string - tree *trillian.Tree + doBefore func() wantNeedsInit bool wantErr bool wantLogRoot []byte }{ { desc: "uninitializedBegin", - tree: logTree(-1), + doBefore: func() {}, wantNeedsInit: true, }, { - desc: "activeLogBegin", - tree: activeLog, + desc: "activeLogBegin", + doBefore: func() { mustSignAndStoreLogRoot(ctx, t, s, activeLog, &types.LogRootV1{RootHash: []byte{0}}) }, wantLogRoot: func() []byte { b, err := (&types.LogRootV1{RootHash: []byte{0}}).MarshalBinary() if err != nil { @@ -175,7 +174,8 @@ func (*logTests) TestReadWriteTransaction(ctx context.Context, t *testing.T, s s for _, test := range tests { t.Run(test.desc, func(t *testing.T) { - err := s.ReadWriteTransaction(ctx, test.tree, func(ctx context.Context, tx storage.LogTreeTX) error { + test.doBefore() + err := s.ReadWriteTransaction(ctx, activeLog, func(ctx context.Context, tx storage.LogTreeTX) error { root, err := tx.LatestSignedLogRoot(ctx) if err != nil && !(err == storage.ErrTreeNeedsInit && test.wantNeedsInit) { t.Fatalf("%v: LatestSignedLogRoot() returned err = %v", test.desc, err)