diff --git a/internal/app/kwild/driver.go b/internal/app/kwild/driver.go index 2288e4ca5..2fdc3f350 100644 --- a/internal/app/kwild/driver.go +++ b/internal/app/kwild/driver.go @@ -9,7 +9,6 @@ import ( "github.com/kwilteam/kwil-db/pkg/client" "github.com/kwilteam/kwil-db/pkg/engine/utils" "github.com/kwilteam/kwil-db/pkg/log" - "github.com/kwilteam/kwil-db/pkg/serialize" kTx "github.com/kwilteam/kwil-db/pkg/tx" types "github.com/cometbft/cometbft/abci/types" @@ -17,22 +16,22 @@ import ( "go.uber.org/zap" ) -// GrpcDriver is a grpc driver for integration tests -type GrpcDriver struct { +// KwildDriver is a grpc driver for integration tests +type KwildDriver struct { clt *client.Client logger log.Logger } -type GrpcDriverOpt func(*GrpcDriver) +type GrpcDriverOpt func(*KwildDriver) func WithLogger(logger log.Logger) GrpcDriverOpt { - return func(d *GrpcDriver) { + return func(d *KwildDriver) { d.logger = logger } } -func NewGrpcDriver(clt *client.Client, opts ...GrpcDriverOpt) *GrpcDriver { - driver := &GrpcDriver{ +func NewKwildDriver(clt *client.Client, opts ...GrpcDriverOpt) *KwildDriver { + driver := &KwildDriver{ clt: clt, logger: log.New(log.Config{}), } @@ -44,13 +43,13 @@ func NewGrpcDriver(clt *client.Client, opts ...GrpcDriverOpt) *GrpcDriver { return driver } -func (d *GrpcDriver) GetUserAddress() string { +func (d *KwildDriver) GetUserAddress() string { return ec.PubkeyToAddress(d.clt.PrivateKey.PublicKey).Hex() } // TODO: this likely needs to change; the old Kwild driver is not compatible, since deploy, drop, and execute are asynchronous -func (d *GrpcDriver) DeployDatabase(ctx context.Context, db *serialize.Schema) error { +func (d *KwildDriver) DeployDatabase(ctx context.Context, db *transactions.Schema) error { db.Owner = d.GetUserAddress() rec, err := d.clt.DeployDatabase(ctx, db) if err != nil { @@ -71,7 +70,7 @@ func (d *GrpcDriver) DeployDatabase(ctx context.Context, db *serialize.Schema) e return nil } -func (d *GrpcDriver) DatabaseShouldExists(ctx context.Context, owner string, dbName string) error { +func (d *KwildDriver) DatabaseShouldExists(ctx context.Context, owner string, dbName string) error { dbid := utils.GenerateDBID(dbName, owner) dbSchema, err := d.clt.GetSchema(ctx, dbid) @@ -85,8 +84,8 @@ func (d *GrpcDriver) DatabaseShouldExists(ctx context.Context, owner string, dbN return fmt.Errorf("database does not exist") } -func (d *GrpcDriver) ExecuteAction(ctx context.Context, dbid string, actionName string, actionInputs []map[string]any) (*kTx.Receipt, []map[string]any, error) { - rec, err := d.clt.ExecuteAction(ctx, dbid, actionName, actionInputs) +func (d *KwildDriver) ExecuteAction(ctx context.Context, dbid string, actionName string, actionInputs ...[]any) (*transactions.TransactionStatus, error) { + rec, err := d.clt.ExecuteAction(ctx, dbid, actionName, actionInputs...) if err != nil { return nil, nil, fmt.Errorf("error executing query: %w", err) } @@ -112,7 +111,7 @@ func (d *GrpcDriver) ExecuteAction(ctx context.Context, dbid string, actionName return rec, outputs, nil } -func (d *GrpcDriver) DropDatabase(ctx context.Context, dbName string) error { +func (d *KwildDriver) DropDatabase(ctx context.Context, dbName string) error { rec, err := d.clt.DropDatabase(ctx, dbName) if err != nil { return fmt.Errorf("error dropping database: %w", err) @@ -131,11 +130,11 @@ func (d *GrpcDriver) DropDatabase(ctx context.Context, dbName string) error { return nil } -func (d *GrpcDriver) QueryDatabase(ctx context.Context, dbid, query string) (*client.Records, error) { +func (d *KwildDriver) QueryDatabase(ctx context.Context, dbid, query string) (*client.Records, error) { return d.clt.Query(ctx, dbid, query) } -func (d *GrpcDriver) Call(ctx context.Context, dbid, action string, inputs map[string]any, opts ...client.CallOpt) ([]map[string]any, error) { +func (d *KwildDriver) Call(ctx context.Context, dbid, action string, inputs []any, opts ...client.CallOpt) ([]map[string]any, error) { return d.clt.CallAction(ctx, dbid, action, inputs, opts...) } @@ -148,12 +147,12 @@ func GetTransactionResult(attributes []types.EventAttribute) bool { return false } -func (d *GrpcDriver) ApproveNode(ctx context.Context, joinerPubKey string, approverPrivKey string) error { +func (d *KwildDriver) ApproveNode(ctx context.Context, joinerPubKey string, approverPrivKey string) error { _, err := d.clt.ApproveValidator(ctx, approverPrivKey, joinerPubKey) return err } -func (d *GrpcDriver) ValidatorSetCount(ctx context.Context) (int, error) { +func (d *KwildDriver) ValidatorSetCount(ctx context.Context) (int, error) { vals, err := d.clt.CometBftClient.Validators(ctx, nil, nil, nil) if err != nil { return -1, err @@ -162,7 +161,7 @@ func (d *GrpcDriver) ValidatorSetCount(ctx context.Context) (int, error) { return vals.Count, nil } -func (d *GrpcDriver) ValidatorNodeJoin(ctx context.Context, joiner string, power int64) error { +func (d *KwildDriver) ValidatorNodeJoin(ctx context.Context, joiner string, power int64) error { _, err := d.clt.ValidatorJoin(ctx, string(joiner), power) if err != nil { return fmt.Errorf("error joining validator: %w", err) @@ -171,7 +170,7 @@ func (d *GrpcDriver) ValidatorNodeJoin(ctx context.Context, joiner string, power return nil } -func (d *GrpcDriver) ValidatorNodeLeave(ctx context.Context, joiner string) error { +func (d *KwildDriver) ValidatorNodeLeave(ctx context.Context, joiner string) error { hash, err := d.clt.ValidatorLeave(ctx, joiner, 0) if err != nil { return fmt.Errorf("error joining validator: %w", err) diff --git a/test/acceptance/helper.go b/test/acceptance/helper.go index 0caad909c..1e05af2df 100644 --- a/test/acceptance/helper.go +++ b/test/acceptance/helper.go @@ -182,7 +182,7 @@ func (r *ActHelper) GetAliceDriver(ctx context.Context) KwilAcceptanceDriver { ) require.NoError(r.t, err, "failed to create kwil client") - return kwild.NewGrpcDriver(kwilClt) + return kwild.NewKwildDriver(kwilClt) } func (r *ActHelper) GetBobDriver(ctx context.Context) KwilAcceptanceDriver { @@ -192,5 +192,5 @@ func (r *ActHelper) GetBobDriver(ctx context.Context) KwilAcceptanceDriver { ) require.NoError(r.t, err, "failed to create kwil client") - return kwild.NewGrpcDriver(kwilClt) + return kwild.NewKwildDriver(kwilClt) } diff --git a/test/integration/helper.go b/test/integration/helper.go index 94381bc37..1c2a393c3 100644 --- a/test/integration/helper.go +++ b/test/integration/helper.go @@ -34,7 +34,7 @@ type IntTestConfig struct { // ) // require.NoError(t, err, "failed to create kwil client") // -// kwildDriver := kwild.NewGrpcDriver(kwilClt) +// kwildDriver := kwild.NewKwildDriver(kwilClt) // return kwildDriver //} // @@ -193,7 +193,7 @@ func (r *IntHelper) getDriver(ctx context.Context, ctr *testcontainers.DockerCon ) require.NoError(r.t, err, "failed to create kwil client") - return kwild.NewGrpcDriver(kwilClt) + return kwild.NewKwildDriver(kwilClt) } func (r *IntHelper) GetDrivers(ctx context.Context) []KwilIntDriver {