Skip to content

Commit

Permalink
Fix test
Browse files Browse the repository at this point in the history
  • Loading branch information
pav-kv committed Mar 11, 2021
1 parent a24fa8e commit 7c06486
Showing 1 changed file with 20 additions and 17 deletions.
37 changes: 20 additions & 17 deletions storage/mysql/storage_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ func TestNodeRoundTrip(t *testing.T) {
if err := tx.SetMerkleNodes(ctx, tc.store); err != nil {
t.Fatalf("Failed to store nodes: %s", err)
}
return nil
return storeLogRoot(ctx, tx, uint64(len(tc.store)), uint64(writeRev), []byte{1, 2, 3})
})

runLogTX(s, tree, t, func(ctx context.Context, tx storage.LogTreeTX) error {
Expand All @@ -107,8 +107,9 @@ func TestLogNodeRoundTripMultiSubtree(t *testing.T) {
tree := mustCreateTree(ctx, t, as, storageto.LogTree)
s := NewLogStorage(DB, nil)

const writeRevision = int64(100)
nodesToStore, err := createLogNodesForTreeAtSize(t, 871, writeRevision)
const writeRev = int64(100)
const size = 871
nodesToStore, err := createLogNodesForTreeAtSize(t, size, writeRev)
if err != nil {
t.Fatalf("failed to create test tree: %v", err)
}
Expand All @@ -119,7 +120,7 @@ func TestLogNodeRoundTripMultiSubtree(t *testing.T) {

{
runLogTX(s, tree, t, func(ctx context.Context, tx storage.LogTreeTX) error {
forceWriteRevision(writeRevision, tx)
forceWriteRevision(writeRev, tx)

// Need to read nodes before attempting to write
if _, err := tx.GetMerkleNodes(ctx, nodeIDsToRead); err != nil {
Expand All @@ -128,7 +129,7 @@ func TestLogNodeRoundTripMultiSubtree(t *testing.T) {
if err := tx.SetMerkleNodes(ctx, nodesToStore); err != nil {
t.Fatalf("Failed to store nodes: %s", err)
}
return nil
return storeLogRoot(ctx, tx, uint64(size), uint64(writeRev), []byte{1, 2, 3})
})
}

Expand Down Expand Up @@ -283,21 +284,23 @@ func getVersion(db *sql.DB) (string, error) {

func mustSignAndStoreLogRoot(ctx context.Context, t *testing.T, l storage.LogStorage, tree *trillian.Tree, treeSize uint64) {
t.Helper()
signer := tcrypto.NewSigner(0, testonly.NewSignerWithFixedSig(nil, []byte("notnil")), crypto.SHA256)
if err := l.ReadWriteTransaction(ctx, tree, func(ctx context.Context, tx storage.LogTreeTX) error {
return storeLogRoot(ctx, tx, treeSize, 0, []byte{0})
}); err != nil {
t.Fatalf("ReadWriteTransaction: %v", err)
}
}

err := l.ReadWriteTransaction(ctx, tree, func(ctx context.Context, tx storage.LogTreeTX) error {
root, err := signer.SignLogRoot(&types.LogRootV1{TreeSize: treeSize, RootHash: []byte{0}})
if err != nil {
return fmt.Errorf("error creating new SignedLogRoot: %v", err)
}
if err := tx.StoreSignedLogRoot(ctx, root); err != nil {
return fmt.Errorf("error storing new SignedLogRoot: %v", err)
}
return nil
})
func storeLogRoot(ctx context.Context, tx storage.LogTreeTX, size, rev uint64, hash []byte) error {
signer := tcrypto.NewSigner(0, testonly.NewSignerWithFixedSig(nil, []byte("notnil")), crypto.SHA256)
root, err := signer.SignLogRoot(&types.LogRootV1{TreeSize: size, Revision: rev, RootHash: hash})
if err != nil {
t.Fatalf("ReadWriteTransaction() = %v", err)
return fmt.Errorf("error creating new SignedLogRoot: %v", err)
}
if err := tx.StoreSignedLogRoot(ctx, root); err != nil {
return fmt.Errorf("error storing new SignedLogRoot: %v", err)
}
return nil
}

// mustCreateTree creates the specified tree using AdminStorage.
Expand Down

0 comments on commit 7c06486

Please sign in to comment.