Skip to content

Commit

Permalink
change action input format for test driver
Browse files Browse the repository at this point in the history
  • Loading branch information
Yaiba committed Aug 14, 2023
1 parent bb0c18b commit ded329e
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 23 deletions.
37 changes: 18 additions & 19 deletions internal/app/kwild/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,30 +9,29 @@ 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"
ec "github.com/ethereum/go-ethereum/crypto"
"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{}),
}
Expand All @@ -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 {
Expand All @@ -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)
Expand All @@ -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)
}
Expand All @@ -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)
Expand All @@ -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...)
}

Expand All @@ -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
Expand All @@ -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)
Expand All @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions test/acceptance/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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)
}
4 changes: 2 additions & 2 deletions test/integration/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
//}
//
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit ded329e

Please sign in to comment.