diff --git a/internal/database/sqlcommon/blob_sql.go b/internal/database/sqlcommon/blob_sql.go index 98a8fb8cb..f702eb7c5 100644 --- a/internal/database/sqlcommon/blob_sql.go +++ b/internal/database/sqlcommon/blob_sql.go @@ -88,7 +88,7 @@ func (s *SQLCommon) InsertBlobs(ctx context.Context, blobs []*core.Blob) (err er } defer s.RollbackTx(ctx, tx, autoCommit) - if s.features.MultiRowInsert { + if s.Features().MultiRowInsert { query := sq.Insert(blobsTable).Columns(blobColumns...) for _, blob := range blobs { query = s.setBlobInsertValues(query, blob) diff --git a/internal/database/sqlcommon/blob_sql_test.go b/internal/database/sqlcommon/blob_sql_test.go index 3c8df1fb2..5324fda69 100644 --- a/internal/database/sqlcommon/blob_sql_test.go +++ b/internal/database/sqlcommon/blob_sql_test.go @@ -1,4 +1,4 @@ -// Copyright © 2021 Kaleido, Inc. +// Copyright © 2023 Kaleido, Inc. // // SPDX-License-Identifier: Apache-2.0 // @@ -124,9 +124,10 @@ func TestInsertBlobsBeginFail(t *testing.T) { } func TestInsertBlobsMultiRowOK(t *testing.T) { - s, mock := newMockProvider().init() - s.features.MultiRowInsert = true + s := newMockProvider() + s.multiRowInsert = true s.fakePSQLInsert = true + s, mock := s.init() blob1 := &core.Blob{Hash: fftypes.NewRandB32(), PayloadRef: "pay1"} blob2 := &core.Blob{Hash: fftypes.NewRandB32(), PayloadRef: "pay2"} @@ -144,9 +145,10 @@ func TestInsertBlobsMultiRowOK(t *testing.T) { } func TestInsertBlobsMultiRowFail(t *testing.T) { - s, mock := newMockProvider().init() - s.features.MultiRowInsert = true + s := newMockProvider() + s.multiRowInsert = true s.fakePSQLInsert = true + s, mock := s.init() blob1 := &core.Blob{Hash: fftypes.NewRandB32(), PayloadRef: "pay1"} mock.ExpectBegin() mock.ExpectQuery("INSERT.*").WillReturnError(fmt.Errorf("pop")) diff --git a/internal/database/sqlcommon/data_sql.go b/internal/database/sqlcommon/data_sql.go index 29e4ba46e..29acf452b 100644 --- a/internal/database/sqlcommon/data_sql.go +++ b/internal/database/sqlcommon/data_sql.go @@ -195,7 +195,7 @@ func (s *SQLCommon) InsertDataArray(ctx context.Context, dataArray core.DataArra } defer s.RollbackTx(ctx, tx, autoCommit) - if s.features.MultiRowInsert { + if s.Features().MultiRowInsert { query := sq.Insert(dataTable).Columns(dataColumnsWithValue...) for _, data := range dataArray { query = s.setDataInsertValues(query, data) diff --git a/internal/database/sqlcommon/data_sql_test.go b/internal/database/sqlcommon/data_sql_test.go index 6162a09ef..a628ba539 100644 --- a/internal/database/sqlcommon/data_sql_test.go +++ b/internal/database/sqlcommon/data_sql_test.go @@ -1,4 +1,4 @@ -// Copyright © 2021 Kaleido, Inc. +// Copyright © 2023 Kaleido, Inc. // // SPDX-License-Identifier: Apache-2.0 // @@ -240,9 +240,10 @@ func TestInsertDataArrayBeginFail(t *testing.T) { } func TestInsertDataArrayMultiRowOK(t *testing.T) { - s, mock := newMockProvider().init() - s.features.MultiRowInsert = true + s := newMockProvider() + s.multiRowInsert = true s.fakePSQLInsert = true + s, mock := s.init() data1 := &core.Data{ID: fftypes.NewUUID(), Namespace: "ns1"} data2 := &core.Data{ID: fftypes.NewUUID(), Namespace: "ns1"} @@ -262,9 +263,10 @@ func TestInsertDataArrayMultiRowOK(t *testing.T) { } func TestInsertDataArrayMultiRowFail(t *testing.T) { - s, mock := newMockProvider().init() - s.features.MultiRowInsert = true + s := newMockProvider() + s.multiRowInsert = true s.fakePSQLInsert = true + s, mock := s.init() data1 := &core.Data{ID: fftypes.NewUUID(), Namespace: "ns1"} mock.ExpectBegin() mock.ExpectQuery("INSERT.*").WillReturnError(fmt.Errorf("pop")) diff --git a/internal/database/sqlcommon/event_sql.go b/internal/database/sqlcommon/event_sql.go index 2af652559..574add68e 100644 --- a/internal/database/sqlcommon/event_sql.go +++ b/internal/database/sqlcommon/event_sql.go @@ -1,4 +1,4 @@ -// Copyright © 2022 Kaleido, Inc. +// Copyright © 2023 Kaleido, Inc. // // SPDX-License-Identifier: Apache-2.0 // @@ -118,7 +118,7 @@ func (p *eventsPCA) PreCommit(ctx context.Context, tx *dbsql.TXWrapper) (err err } } - if p.s.features.MultiRowInsert { + if p.s.Features().MultiRowInsert { query := sq.Insert(eventsTable).Columns(eventColumns...) for _, event := range p.events { query = p.s.setEventInsertValues(query, event) diff --git a/internal/database/sqlcommon/event_sql_test.go b/internal/database/sqlcommon/event_sql_test.go index 59d4264a2..134460deb 100644 --- a/internal/database/sqlcommon/event_sql_test.go +++ b/internal/database/sqlcommon/event_sql_test.go @@ -1,4 +1,4 @@ -// Copyright © 2021 Kaleido, Inc. +// Copyright © 2023 Kaleido, Inc. // // SPDX-License-Identifier: Apache-2.0 // @@ -133,9 +133,10 @@ func TestInsertEventFailCommit(t *testing.T) { } func TestInsertEventsPreCommitMultiRowOK(t *testing.T) { - s, mock := newMockProvider().init() - s.features.MultiRowInsert = true + s := newMockProvider() + s.multiRowInsert = true s.fakePSQLInsert = true + s, mock := s.init() ev1 := &core.Event{ID: fftypes.NewUUID(), Namespace: "ns1"} ev2 := &core.Event{ID: fftypes.NewUUID(), Namespace: "ns1"} @@ -162,9 +163,10 @@ func TestInsertEventsPreCommitMultiRowOK(t *testing.T) { } func TestInsertEventsPreCommitMultiRowFail(t *testing.T) { - s, mock := newMockProvider().init() - s.features.MultiRowInsert = true + s := newMockProvider() + s.multiRowInsert = true s.fakePSQLInsert = true + s, mock := s.init() ev1 := &core.Event{ID: fftypes.NewUUID(), Namespace: "ns1"} mock.ExpectBegin() mock.ExpectExec("").WillReturnResult(driver.ResultNoRows) diff --git a/internal/database/sqlcommon/message_sql.go b/internal/database/sqlcommon/message_sql.go index a3e97659e..e5674f946 100644 --- a/internal/database/sqlcommon/message_sql.go +++ b/internal/database/sqlcommon/message_sql.go @@ -1,4 +1,4 @@ -// Copyright © 2022 Kaleido, Inc. +// Copyright © 2023 Kaleido, Inc. // // SPDX-License-Identifier: Apache-2.0 // @@ -210,8 +210,7 @@ func (s *SQLCommon) InsertMessages(ctx context.Context, messages []*core.Message return err } defer s.RollbackTx(ctx, tx, autoCommit) - - if s.features.MultiRowInsert { + if s.Features().MultiRowInsert { msgQuery := sq.Insert(messagesTable).Columns(msgColumns...) dataRefQuery := sq.Insert(messagesDataJoinTable).Columns( "namespace", diff --git a/internal/database/sqlcommon/message_sql_test.go b/internal/database/sqlcommon/message_sql_test.go index 19ffa8e21..de2227ff6 100644 --- a/internal/database/sqlcommon/message_sql_test.go +++ b/internal/database/sqlcommon/message_sql_test.go @@ -1,4 +1,4 @@ -// Copyright © 2021 Kaleido, Inc. +// Copyright © 2023 Kaleido, Inc. // // SPDX-License-Identifier: Apache-2.0 // @@ -310,9 +310,10 @@ func TestInsertMessagesBeginFail(t *testing.T) { } func TestInsertMessagesMultiRowOK(t *testing.T) { - s, mock := newMockProvider().init() - s.features.MultiRowInsert = true + s := newMockProvider() + s.multiRowInsert = true s.fakePSQLInsert = true + s, mock := s.init() msg1 := &core.Message{Header: core.MessageHeader{ID: fftypes.NewUUID(), Namespace: "ns1"}, LocalNamespace: "ns1", Data: core.DataRefs{{ID: fftypes.NewUUID()}}} msg2 := &core.Message{Header: core.MessageHeader{ID: fftypes.NewUUID(), Namespace: "ns1"}, LocalNamespace: "ns1", Data: core.DataRefs{{ID: fftypes.NewUUID()}}} @@ -340,9 +341,10 @@ func TestInsertMessagesMultiRowOK(t *testing.T) { } func TestInsertMessagesMultiRowDataRefsFail(t *testing.T) { - s, mock := newMockProvider().init() - s.features.MultiRowInsert = true + s := newMockProvider() + s.multiRowInsert = true s.fakePSQLInsert = true + s, mock := s.init() msg1 := &core.Message{Header: core.MessageHeader{ID: fftypes.NewUUID(), Namespace: "ns1"}, Data: core.DataRefs{{ID: fftypes.NewUUID()}}} @@ -356,9 +358,10 @@ func TestInsertMessagesMultiRowDataRefsFail(t *testing.T) { } func TestInsertMessagesMultiRowFail(t *testing.T) { - s, mock := newMockProvider().init() - s.features.MultiRowInsert = true + s := newMockProvider() + s.multiRowInsert = true s.fakePSQLInsert = true + s, mock := s.init() msg1 := &core.Message{Header: core.MessageHeader{ID: fftypes.NewUUID(), Namespace: "ns1"}} mock.ExpectBegin() mock.ExpectQuery("INSERT.*").WillReturnError(fmt.Errorf("pop")) diff --git a/internal/database/sqlcommon/pin_sql.go b/internal/database/sqlcommon/pin_sql.go index ff39fcf70..a2961aa40 100644 --- a/internal/database/sqlcommon/pin_sql.go +++ b/internal/database/sqlcommon/pin_sql.go @@ -1,4 +1,4 @@ -// Copyright © 2022 Kaleido, Inc. +// Copyright © 2023 Kaleido, Inc. // // SPDX-License-Identifier: Apache-2.0 // @@ -124,7 +124,7 @@ func (s *SQLCommon) InsertPins(ctx context.Context, pins []*core.Pin) error { } defer s.RollbackTx(ctx, tx, autoCommit) - if s.features.MultiRowInsert { + if s.Features().MultiRowInsert { query := sq.Insert(pinsTable).Columns(pinColumns...) for _, pin := range pins { query = s.setPinInsertValues(query, pin) diff --git a/internal/database/sqlcommon/pin_sql_test.go b/internal/database/sqlcommon/pin_sql_test.go index 321042b5b..17749cf90 100644 --- a/internal/database/sqlcommon/pin_sql_test.go +++ b/internal/database/sqlcommon/pin_sql_test.go @@ -1,4 +1,4 @@ -// Copyright © 2021 Kaleido, Inc. +// Copyright © 2023 Kaleido, Inc. // // SPDX-License-Identifier: Apache-2.0 // @@ -146,9 +146,10 @@ func TestInsertPinsBeginFail(t *testing.T) { } func TestInsertPinsMultiRowOK(t *testing.T) { - s, mock := newMockProvider().init() - s.features.MultiRowInsert = true + s := newMockProvider() + s.multiRowInsert = true s.fakePSQLInsert = true + s, mock := s.init() pin1 := &core.Pin{Namespace: "ns1", Hash: fftypes.NewRandB32()} pin2 := &core.Pin{Namespace: "ns1", Hash: fftypes.NewRandB32()} @@ -168,9 +169,10 @@ func TestInsertPinsMultiRowOK(t *testing.T) { } func TestInsertPinsMultiRowFail(t *testing.T) { - s, mock := newMockProvider().init() - s.features.MultiRowInsert = true + s := newMockProvider() + s.multiRowInsert = true s.fakePSQLInsert = true + s, mock := s.init() pin1 := &core.Pin{Hash: fftypes.NewRandB32()} mock.ExpectBegin() mock.ExpectQuery("INSERT.*").WillReturnError(fmt.Errorf("pop")) diff --git a/internal/database/sqlcommon/provider_mock_test.go b/internal/database/sqlcommon/provider_mock_test.go index b3cdf5176..38faa5eb9 100644 --- a/internal/database/sqlcommon/provider_mock_test.go +++ b/internal/database/sqlcommon/provider_mock_test.go @@ -1,4 +1,4 @@ -// Copyright © 2021 Kaleido, Inc. +// Copyright © 2023 Kaleido, Inc. // // SPDX-License-Identifier: Apache-2.0 // @@ -45,6 +45,7 @@ type mockProvider struct { openError error getMigrationDriverError error individualSort bool + multiRowInsert bool } func newMockProvider() *mockProvider { @@ -59,6 +60,7 @@ func newMockProvider() *mockProvider { mp.SQLCommon.InitConfig(mp, mp.config) mp.config.Set(SQLConfMaxConnections, 10) mp.mockDB, mp.mdb, _ = sqlmock.New() + mp.multiRowInsert = false return mp } @@ -84,6 +86,7 @@ func (mp *mockProvider) MigrationsDir() string { func (psql *mockProvider) Features() dbsql.SQLFeatures { features := dbsql.DefaultSQLProviderFeatures() features.UseILIKE = true + features.MultiRowInsert = psql.multiRowInsert features.AcquireLock = func(lockName string) string { return fmt.Sprintf(``, lockName) } diff --git a/internal/database/sqlcommon/sqlcommon.go b/internal/database/sqlcommon/sqlcommon.go index 1105604b8..02dbdd8ee 100644 --- a/internal/database/sqlcommon/sqlcommon.go +++ b/internal/database/sqlcommon/sqlcommon.go @@ -1,4 +1,4 @@ -// Copyright © 2022 Kaleido, Inc. +// Copyright © 2023 Kaleido, Inc. // // SPDX-License-Identifier: Apache-2.0 // @@ -33,7 +33,6 @@ type SQLCommon struct { dbsql.Database capabilities *database.Capabilities callbacks callbacks - features dbsql.SQLFeatures } type callbacks struct { diff --git a/test/e2e/multiparty/ethereum_contracts.go b/test/e2e/multiparty/ethereum_contracts.go index 967d65918..2b6385e76 100644 --- a/test/e2e/multiparty/ethereum_contracts.go +++ b/test/e2e/multiparty/ethereum_contracts.go @@ -19,7 +19,7 @@ package multiparty import ( "encoding/json" "fmt" - "io/ioutil" + "io" "os" "os/exec" "testing" @@ -316,7 +316,7 @@ func readContractJSON(t *testing.T, contract string) fftypes.JSONObject { jsonFile, err := os.Open(path) assert.NoError(t, err) defer jsonFile.Close() - byteValue, err := ioutil.ReadAll(jsonFile) + byteValue, err := io.ReadAll(jsonFile) assert.NoError(t, err) var jsonValue fftypes.JSONObject err = json.Unmarshal(byteValue, &jsonValue)