Skip to content

Commit 352cafc

Browse files
committed
feat: update integration tests to utilize new wallet management and client creation
- Refactored integration tests to include the use of `kwilcrypto` for wallet management. - Updated client creation logic to ensure proper context handling and error checking. - Enhanced test setup by authorizing wallets for stream deployment across multiple test files. - Adjusted loop conditions in batch operations tests for inclusive iteration. - Improved overall type safety and clarity in test implementations.
1 parent 7877494 commit 352cafc

File tree

7 files changed

+69
-29
lines changed

7 files changed

+69
-29
lines changed

tests/integration/batch_operations_test.go

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,26 +6,32 @@ import (
66
"testing"
77
"time"
88

9+
kwilcrypto "github.com/kwilteam/kwil-db/core/crypto"
10+
"github.com/kwilteam/kwil-db/core/crypto/auth"
911
kwiltypes "github.com/kwilteam/kwil-db/core/types"
1012

1113
"github.com/stretchr/testify/assert"
1214
"github.com/stretchr/testify/require"
15+
"github.com/trufnetwork/sdk-go/core/tnclient"
1316
"github.com/trufnetwork/sdk-go/core/types"
1417
"github.com/trufnetwork/sdk-go/core/util"
1518
)
1619

1720
func TestBatchOperations(t *testing.T) {
21+
ctx := context.Background()
1822
fixture := NewServerFixture(t)
1923
err := fixture.Setup()
2024
t.Cleanup(func() {
2125
fixture.Teardown()
2226
})
2327
require.NoError(t, err, "Failed to setup server fixture")
2428

25-
tnClient := fixture.Client()
26-
require.NotNil(t, tnClient, "Client from fixture should not be nil")
29+
deployerWallet, err := kwilcrypto.Secp256k1PrivateKeyFromHex(AnonWalletPK)
30+
require.NoError(t, err, "failed to parse anon wallet private key")
31+
tnClient, err := tnclient.NewClient(ctx, TestKwilProvider, tnclient.WithSigner(auth.GetUserSigner(deployerWallet)))
32+
require.NoError(t, err, "failed to create client")
2733

28-
ctx := context.Background()
34+
authorizeWalletToDeployStreams(t, ctx, fixture, deployerWallet)
2935

3036
t.Run("TestSequentialSmallBatches", func(t *testing.T) {
3137
streamId := util.GenerateStreamId("test-sequential-small")
@@ -54,7 +60,7 @@ func TestBatchOperations(t *testing.T) {
5460
txHashes := make([]kwiltypes.Hash, 0, numBatches)
5561
startTime := time.Now()
5662

57-
for batch := 0; batch < numBatches; batch++ {
63+
for batch := 0; batch <= numBatches; batch++ {
5864
records := make([]types.InsertRecordInput, recordsPerBatch)
5965
for i := 0; i < recordsPerBatch; i++ {
6066
records[i] = types.InsertRecordInput{
@@ -126,7 +132,7 @@ func TestBatchOperations(t *testing.T) {
126132
txHashes := make([]kwiltypes.Hash, 0, numBatches)
127133
startTime := time.Now()
128134

129-
for batch := 0; batch < numBatches; batch++ {
135+
for batch := 0; batch <= numBatches; batch++ {
130136
records := make([]types.InsertRecordInput, recordsPerBatch)
131137
for i := 0; i < recordsPerBatch; i++ {
132138
records[i] = types.InsertRecordInput{
@@ -197,7 +203,7 @@ func TestBatchOperations(t *testing.T) {
197203
txHashes := make([]kwiltypes.Hash, 0, numRecords)
198204
startTime := time.Now()
199205

200-
for i := 0; i < numRecords; i++ {
206+
for i := 0; i <= numRecords; i++ {
201207
records := []types.InsertRecordInput{
202208
{
203209
DataProvider: streamLocator.DataProvider.Address(),

tests/integration/batch_stream_creation_test.go

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,12 @@ import (
77
"testing"
88
"time"
99

10-
// kwilcrypto "github.com/kwilteam/kwil-db/core/crypto" // Will be removed if not used elsewhere
11-
// "github.com/kwilteam/kwil-db/core/crypto/auth" // Will be removed if not used elsewhere
10+
kwilcrypto "github.com/kwilteam/kwil-db/core/crypto"
11+
"github.com/kwilteam/kwil-db/core/crypto/auth"
1212
kwiltypes "github.com/kwilteam/kwil-db/core/types"
1313
"github.com/stretchr/testify/assert"
1414
"github.com/stretchr/testify/require"
15+
"github.com/trufnetwork/sdk-go/core/tnclient"
1516
"github.com/trufnetwork/sdk-go/core/types"
1617
"github.com/trufnetwork/sdk-go/core/util"
1718
)
@@ -24,10 +25,14 @@ func TestBatchDeployAndExistenceOperations(t *testing.T) {
2425
})
2526
require.NoError(t, err, "Failed to setup server fixture")
2627

27-
tnClient := fixture.Client()
28-
require.NotNil(t, tnClient, "Client from fixture should not be nil")
29-
3028
ctx := context.Background()
29+
deployerWallet, err := kwilcrypto.Secp256k1PrivateKeyFromHex(AnonWalletPK)
30+
require.NoError(t, err, "failed to parse anon wallet private key")
31+
tnClient, err := tnclient.NewClient(ctx, TestKwilProvider, tnclient.WithSigner(auth.GetUserSigner(deployerWallet)))
32+
require.NoError(t, err, "failed to create client")
33+
34+
authorizeWalletToDeployStreams(t, ctx, fixture, deployerWallet)
35+
3136
signerAddress := tnClient.Address()
3237

3338
// =========================================================================

tests/integration/composed_actions_test.go

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,11 @@ import (
44
"context"
55
"testing"
66

7+
kwilcrypto "github.com/kwilteam/kwil-db/core/crypto"
8+
"github.com/kwilteam/kwil-db/core/crypto/auth"
79
"github.com/stretchr/testify/assert"
810
"github.com/stretchr/testify/require"
11+
"github.com/trufnetwork/sdk-go/core/tnclient"
912
"github.com/trufnetwork/sdk-go/core/types"
1013
"github.com/trufnetwork/sdk-go/core/util"
1114
)
@@ -17,17 +20,21 @@ import (
1720
// TestComposedStream demonstrates the process of deploying, initializing, and querying
1821
// a composed stream that aggregates data from multiple primitive streams in the TN using the TN SDK.
1922
func TestComposedActions(t *testing.T) {
23+
ctx := context.Background()
2024
fixture := NewServerFixture(t)
2125
err := fixture.Setup()
2226
t.Cleanup(func() {
2327
fixture.Teardown()
2428
})
2529
require.NoError(t, err, "Failed to setup server fixture")
2630

27-
tnClient := fixture.Client()
28-
require.NotNil(t, tnClient, "Client from fixture should not be nil")
31+
deployerWallet, err := kwilcrypto.Secp256k1PrivateKeyFromHex(AnonWalletPK)
32+
require.NoError(t, err, "failed to parse anon wallet private key")
33+
tnClient, err := tnclient.NewClient(ctx, TestKwilProvider, tnclient.WithSigner(auth.GetUserSigner(deployerWallet)))
34+
require.NoError(t, err, "failed to create client")
35+
36+
authorizeWalletToDeployStreams(t, ctx, fixture, deployerWallet)
2937

30-
ctx := context.Background()
3138
signerAddress := tnClient.Address()
3239

3340
// Generate a unique stream ID and locator for the composed stream and its child streams

tests/integration/deploy_composed_streams_with_taxonomy_test.go

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,24 +6,30 @@ import (
66
"time"
77

88
"github.com/golang-sql/civil"
9+
kwilcrypto "github.com/kwilteam/kwil-db/core/crypto"
10+
"github.com/kwilteam/kwil-db/core/crypto/auth"
911
"github.com/stretchr/testify/assert"
1012
"github.com/stretchr/testify/require"
13+
"github.com/trufnetwork/sdk-go/core/tnclient"
1114
"github.com/trufnetwork/sdk-go/core/types"
1215
"github.com/trufnetwork/sdk-go/core/util"
1316
)
1417

1518
func TestDeployComposedStreamsWithTaxonomy(t *testing.T) {
19+
ctx := context.Background()
1620
fixture := NewServerFixture(t)
1721
err := fixture.Setup()
1822
t.Cleanup(func() {
1923
fixture.Teardown()
2024
})
2125
require.NoError(t, err, "Failed to setup server fixture")
2226

23-
tnClient := fixture.Client()
24-
require.NotNil(t, tnClient, "Client from fixture should not be nil")
27+
deployerWallet, err := kwilcrypto.Secp256k1PrivateKeyFromHex(AnonWalletPK)
28+
require.NoError(t, err, "failed to parse anon wallet private key")
29+
tnClient, err := tnclient.NewClient(ctx, TestKwilProvider, tnclient.WithSigner(auth.GetUserSigner(deployerWallet)))
30+
require.NoError(t, err, "failed to create client")
2531

26-
ctx := context.Background()
32+
authorizeWalletToDeployStreams(t, ctx, fixture, deployerWallet)
2733

2834
// Generate unique stream IDs and locators
2935
primitiveStreamId := util.GenerateStreamId("test-primitive-stream-one")
@@ -68,7 +74,7 @@ func TestDeployComposedStreamsWithTaxonomy(t *testing.T) {
6874
waitTxToBeMinedWithSuccess(t, ctx, tnClient, deployTxHash)
6975

7076
// List all streams
71-
streams, err := tnClient.ListStreams(ctx, types.ListStreamsInput{ BlockHeight: 0 })
77+
streams, err := tnClient.ListStreams(ctx, types.ListStreamsInput{BlockHeight: 0})
7278
assertNoErrorOrFail(t, err, "Failed to list all streams")
7379

7480
//Check that only the primitive and composed streams are listed

tests/integration/list_streams_test.go

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,25 +4,31 @@ import (
44
"context"
55
"testing"
66

7+
kwilcrypto "github.com/kwilteam/kwil-db/core/crypto"
8+
"github.com/kwilteam/kwil-db/core/crypto/auth"
79
"github.com/stretchr/testify/assert"
810
"github.com/stretchr/testify/require"
11+
"github.com/trufnetwork/sdk-go/core/tnclient"
912

1013
"github.com/trufnetwork/sdk-go/core/types"
1114
"github.com/trufnetwork/sdk-go/core/util"
1215
)
1316

1417
func TestListStreams(t *testing.T) {
18+
ctx := context.Background()
1519
fixture := NewServerFixture(t)
1620
err := fixture.Setup()
1721
t.Cleanup(func() {
1822
fixture.Teardown()
1923
})
2024
require.NoError(t, err, "Failed to setup server fixture")
2125

22-
tnClient := fixture.Client()
23-
require.NotNil(t, tnClient, "Client from fixture should not be nil")
26+
deployerWallet, err := kwilcrypto.Secp256k1PrivateKeyFromHex(AnonWalletPK)
27+
require.NoError(t, err, "failed to parse anon wallet private key")
28+
tnClient, err := tnclient.NewClient(ctx, TestKwilProvider, tnclient.WithSigner(auth.GetUserSigner(deployerWallet)))
29+
require.NoError(t, err, "failed to create client")
2430

25-
ctx := context.Background()
31+
authorizeWalletToDeployStreams(t, ctx, fixture, deployerWallet)
2632

2733
// Generate unique stream IDs and locators
2834
primitiveStreamId := util.GenerateStreamId("test-allstreams-primitive-stream")
@@ -49,7 +55,7 @@ func TestListStreams(t *testing.T) {
4955
waitTxToBeMinedWithSuccess(t, ctx, tnClient, deployTxHash)
5056

5157
//// List all streams
52-
streams, err := tnClient.ListStreams(ctx, types.ListStreamsInput{ BlockHeight: 0 })
58+
streams, err := tnClient.ListStreams(ctx, types.ListStreamsInput{BlockHeight: 0})
5359
assertNoErrorOrFail(t, err, "Failed to list all streams")
5460

5561
// Check that only the primitive and composed streams are listed

tests/integration/permission_test.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77

88
"github.com/golang-sql/civil"
99
"github.com/kwilteam/kwil-db/core/crypto"
10+
kwilcrypto "github.com/kwilteam/kwil-db/core/crypto"
1011
"github.com/kwilteam/kwil-db/core/crypto/auth"
1112
"github.com/stretchr/testify/assert"
1213
"github.com/stretchr/testify/require"
@@ -17,18 +18,21 @@ import (
1718

1819
// TestPermissions demonstrates the deployment and permission management of primitive and composed streams in TN.
1920
func TestPermissions(t *testing.T) {
21+
ctx := context.Background()
2022
fixture := NewServerFixture(t)
2123
err := fixture.Setup()
2224
t.Cleanup(func() {
2325
fixture.Teardown()
2426
})
2527
require.NoError(t, err, "Failed to setup server fixture")
2628

27-
ownerTnClient := fixture.Client()
28-
require.NotNil(t, ownerTnClient, "Owner client from fixture should not be nil")
29-
streamOwnerAddress := ownerTnClient.Address()
29+
ownerWallet, err := kwilcrypto.Secp256k1PrivateKeyFromHex(AnonWalletPK)
30+
require.NoError(t, err, "failed to parse anon wallet private key")
31+
authorizeWalletToDeployStreams(t, ctx, fixture, ownerWallet)
3032

31-
ctx := context.Background()
33+
ownerTnClient, err := tnclient.NewClient(ctx, TestKwilProvider, tnclient.WithSigner(auth.GetUserSigner(ownerWallet)))
34+
require.NoError(t, err, "failed to create client")
35+
streamOwnerAddress := ownerTnClient.Address()
3236

3337
// Set up reader assets
3438
// The reader represents a separate entity that will attempt to access the streams

tests/integration/primitive_actions_test.go

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,11 @@ import (
44
"context"
55
"testing"
66

7+
kwilcrypto "github.com/kwilteam/kwil-db/core/crypto"
8+
"github.com/kwilteam/kwil-db/core/crypto/auth"
79
"github.com/stretchr/testify/assert"
810
"github.com/stretchr/testify/require"
11+
"github.com/trufnetwork/sdk-go/core/tnclient"
912

1013
"github.com/trufnetwork/sdk-go/core/types"
1114
"github.com/trufnetwork/sdk-go/core/util"
@@ -14,17 +17,20 @@ import (
1417
// TestPrimitiveActions demonstrates the process of deploying, initializing, writing to,
1518
// and reading from a primitive action in TN using the TN SDK.
1619
func TestPrimitiveActions(t *testing.T) {
20+
ctx := context.Background()
1721
fixture := NewServerFixture(t)
1822
err := fixture.Setup()
1923
t.Cleanup(func() {
2024
fixture.Teardown()
2125
})
2226
require.NoError(t, err, "Failed to setup server fixture")
2327

24-
tnClient := fixture.Client()
25-
require.NotNil(t, tnClient, "Client from fixture should not be nil")
28+
deployerWallet, err := kwilcrypto.Secp256k1PrivateKeyFromHex(AnonWalletPK)
29+
require.NoError(t, err, "failed to parse anon wallet private key")
30+
tnClient, err := tnclient.NewClient(ctx, TestKwilProvider, tnclient.WithSigner(auth.GetUserSigner(deployerWallet)))
31+
require.NoError(t, err, "failed to create client")
2632

27-
ctx := context.Background()
33+
authorizeWalletToDeployStreams(t, ctx, fixture, deployerWallet)
2834

2935
// Generate a unique stream ID and locator
3036
// The stream ID is used to uniquely identify the stream within TN

0 commit comments

Comments
 (0)