diff --git a/cmd/kwil-cli/app/app.go b/cmd/kwil-cli/app/app.go index 8008b2b0c..e0ce05694 100644 --- a/cmd/kwil-cli/app/app.go +++ b/cmd/kwil-cli/app/app.go @@ -3,7 +3,6 @@ package app import ( "github.com/kwilteam/kwil-db/cmd/kwil-cli/cmds/configure" "github.com/kwilteam/kwil-db/cmd/kwil-cli/cmds/database" - "github.com/kwilteam/kwil-db/cmd/kwil-cli/cmds/fund" "github.com/kwilteam/kwil-db/cmd/kwil-cli/cmds/system" "github.com/kwilteam/kwil-db/cmd/kwil-cli/cmds/utils" "github.com/kwilteam/kwil-db/cmd/kwil-cli/config" @@ -21,7 +20,7 @@ var rootCmd = &cobra.Command{ func Execute() error { rootCmd.AddCommand( - fund.NewCmdFund(), + // fund.NewCmdFund(), configure.NewCmdConfigure(), database.NewCmdDatabase(), utils.NewCmdUtils(), diff --git a/cmd/kwil-cli/app/driver.go b/cmd/kwil-cli/app/driver.go index 911fc733f..746684614 100644 --- a/cmd/kwil-cli/app/driver.go +++ b/cmd/kwil-cli/app/driver.go @@ -13,7 +13,7 @@ import ( "strings" "time" - schema "github.com/kwilteam/kwil-db/internal/entity" + "github.com/kwilteam/kwil-db/pkg/serialize" grpc "github.com/kwilteam/kwil-db/pkg/grpc/client/v1" "github.com/kwilteam/kwil-db/pkg/log" @@ -152,7 +152,7 @@ func (d *KwilCliDriver) GetAllowance(ctx context.Context) (*big.Int, error) { return nil, nil } -func (d *KwilCliDriver) DeployDatabase(ctx context.Context, db *schema.Schema) error { +func (d *KwilCliDriver) DeployDatabase(ctx context.Context, db *serialize.Schema) error { schemaFile := path.Join(os.TempDir(), fmt.Sprintf("schema-%s.json", time.Now().Format("20060102150405"))) dbByte, err := json.Marshal(db) diff --git a/cmd/kwil-cli/cmds/common/roundtripper.go b/cmd/kwil-cli/cmds/common/roundtripper.go index 7349f713b..30f1ec86e 100644 --- a/cmd/kwil-cli/cmds/common/roundtripper.go +++ b/cmd/kwil-cli/cmds/common/roundtripper.go @@ -33,17 +33,17 @@ func DialClient(ctx context.Context, flags uint8, fn RoundTripper) error { options := []client.ClientOpt{} - if flags&WithoutProvider != 0 { - options = append(options, client.WithoutProvider()) - } - if flags&WithoutServiceConfig != 0 { - options = append(options, client.WithoutServiceConfig()) - } + // if flags&WithoutProvider != 0 { + // options = append(options, client.WithoutProvider()) + // } + // if flags&WithoutServiceConfig != 0 { + // options = append(options, client.WithoutServiceConfig()) + // } if flags&WithChainClient != 0 { if conf.ClientChainRPCURL == "" { return fmt.Errorf("chain rpc url is required") } - options = append(options, client.WithChainRpcUrl(conf.ClientChainRPCURL)) + options = append(options, client.WithCometBftUrl(conf.ClientChainRPCURL)) } if flags&WithoutPrivateKey == 0 { // this means it needs to use the private key diff --git a/cmd/kwil-cli/cmds/database/deploy.go b/cmd/kwil-cli/cmds/database/deploy.go index 1d2e0d5fd..9dfd27c9d 100644 --- a/cmd/kwil-cli/cmds/database/deploy.go +++ b/cmd/kwil-cli/cmds/database/deploy.go @@ -6,17 +6,18 @@ import ( "context" "encoding/json" "fmt" - "github.com/kwilteam/kuneiform/kfparser" "io" "os" "strings" + "github.com/kwilteam/kuneiform/kfparser" + "github.com/kwilteam/kwil-db/cmd/kwil-cli/cmds/common" "github.com/kwilteam/kwil-db/cmd/kwil-cli/cmds/common/display" "github.com/kwilteam/kwil-db/cmd/kwil-cli/config" - "github.com/kwilteam/kwil-db/internal/entity" "github.com/kwilteam/kwil-db/pkg/client" "github.com/kwilteam/kwil-db/pkg/crypto" + "github.com/kwilteam/kwil-db/pkg/serialize" "github.com/spf13/cobra" ) @@ -36,7 +37,7 @@ func deployCmd() *cobra.Command { } defer file.Close() - var db *entity.Schema + var db *serialize.Schema if fileType == "kf" { db, err = UnmarshalKf(file) } else if fileType == "json" { @@ -67,7 +68,7 @@ func deployCmd() *cobra.Command { return cmd } -func UnmarshalKf(file *os.File) (*entity.Schema, error) { +func UnmarshalKf(file *os.File) (*serialize.Schema, error) { source, err := io.ReadAll(file) if err != nil { return nil, fmt.Errorf("failed to read Kuneiform source file: %w", err) @@ -83,7 +84,7 @@ func UnmarshalKf(file *os.File) (*entity.Schema, error) { return nil, fmt.Errorf("failed to marshal schema: %w", err) } - var db entity.Schema + var db serialize.Schema err = json.Unmarshal(schemaJson, &db) if err != nil { return nil, fmt.Errorf("failed to unmarshal schema json: %w", err) @@ -92,13 +93,13 @@ func UnmarshalKf(file *os.File) (*entity.Schema, error) { return &db, nil } -func UnmarshalJson(file *os.File) (*entity.Schema, error) { +func UnmarshalJson(file *os.File) (*serialize.Schema, error) { bts, err := io.ReadAll(file) if err != nil { return nil, fmt.Errorf("failed to read file: %w", err) } - var db entity.Schema + var db serialize.Schema err = json.Unmarshal(bts, &db) if err != nil { return nil, fmt.Errorf("failed to unmarshal file: %w", err) diff --git a/cmd/kwil-cli/cmds/fund/approve.go b/cmd/kwil-cli/cmds/fund/approve.go index bd9740003..1ebc096d4 100644 --- a/cmd/kwil-cli/cmds/fund/approve.go +++ b/cmd/kwil-cli/cmds/fund/approve.go @@ -1,5 +1,6 @@ package fund +/* import ( "context" "errors" @@ -67,3 +68,4 @@ func approveCmd() *cobra.Command { cmd.Flags().BoolVarP(&assumeYes, "yes", "y", false, "Automatic yes to prompts.") return cmd } +*/ diff --git a/cmd/kwil-cli/cmds/fund/balances.go b/cmd/kwil-cli/cmds/fund/balances.go index d78da53b5..9bb7639cb 100644 --- a/cmd/kwil-cli/cmds/fund/balances.go +++ b/cmd/kwil-cli/cmds/fund/balances.go @@ -1,5 +1,6 @@ package fund +/* import ( "context" "fmt" @@ -60,3 +61,4 @@ func balancesCmd() *cobra.Command { return cmd } +*/ diff --git a/cmd/kwil-cli/cmds/fund/cmd.go b/cmd/kwil-cli/cmds/fund/cmd.go index d746700a2..87056a93b 100644 --- a/cmd/kwil-cli/cmds/fund/cmd.go +++ b/cmd/kwil-cli/cmds/fund/cmd.go @@ -1,5 +1,6 @@ package fund +/* import ( "github.com/spf13/cobra" ) @@ -19,3 +20,4 @@ func NewCmdFund() *cobra.Command { ) return cmd } +*/ diff --git a/cmd/kwil-cli/cmds/fund/deposit.go b/cmd/kwil-cli/cmds/fund/deposit.go index 606ca0137..a007fb614 100644 --- a/cmd/kwil-cli/cmds/fund/deposit.go +++ b/cmd/kwil-cli/cmds/fund/deposit.go @@ -1,5 +1,6 @@ package fund +/* import ( "context" "errors" @@ -67,3 +68,4 @@ func depositCmd() *cobra.Command { return cmd } +*/ diff --git a/deployments/compose/eth_chain.go b/deployments/compose/eth_chain.go index 1ca381dfb..9c6ece457 100644 --- a/deployments/compose/eth_chain.go +++ b/deployments/compose/eth_chain.go @@ -1,5 +1,7 @@ package main +/*xxx + import ( "context" "fmt" @@ -61,3 +63,7 @@ func main() { initContract(chainDeployer) keepMiningBlocks(chainDeployer) } + +*/ + +func main() {} diff --git a/internal/_abci-apps/kwild.go b/internal/_abci-apps/kwild.go index f07e883e0..0bfcd1e4d 100644 --- a/internal/_abci-apps/kwild.go +++ b/internal/_abci-apps/kwild.go @@ -7,18 +7,20 @@ import ( "os" "path/filepath" - "github.com/kwilteam/kwil-db/internal/app/kwild/server" - "github.com/kwilteam/kwil-db/internal/entity" + "github.com/kwilteam/kwil-db/internal/controller/grpc/txsvc/v1" + "github.com/kwilteam/kwil-db/pkg/serialize" + "github.com/kwilteam/kwil-db/pkg/tx" kTx "github.com/kwilteam/kwil-db/pkg/tx" abcitypes "github.com/cometbft/cometbft/abci/types" cryptoenc "github.com/cometbft/cometbft/crypto/encoding" - txsvc "github.com/kwilteam/kwil-db/internal/controller/grpc/txsvc/v1" - "github.com/kwilteam/kwil-db/internal/node" - "github.com/kwilteam/kwil-db/internal/usecases/datasets" + node "github.com/kwilteam/kwil-db/internal/_node" + + // "github.com/kwilteam/kwil-db/internal/usecases/datasets" "github.com/kwilteam/kwil-db/pkg/crypto" "github.com/kwilteam/kwil-db/pkg/engine/utils" + "github.com/kwilteam/kwil-db/pkg/log" utilpkg "github.com/kwilteam/kwil-db/pkg/utils" gowal "github.com/tidwall/wal" "go.uber.org/zap" @@ -32,10 +34,32 @@ type KwildState struct { // "initChain", "precommit", "postcommit", "delivertx" } +// KwilExecutor is the interface to a Kwil dataset execution engine. This is a +// subset of the full DatasetUseCase method set. +// +// TODO: KwilDbApplication methods themselves don't need this *directly*; Kwil +// database business can be encapsulated in a separate type. +type KwilExecutor interface { + txsvc.EngineReader + + // methods for state, apphash, consensus... + StartBlockSession() error + EndBlockSession() ([]byte, error) + InitializeAppHash(appHash []byte) + + // "wrong place" methods for a future encapsulated tx executor type + Spend(ctx context.Context, address string, amount string, nonce int64) error + + Deploy(ctx context.Context, schema *serialize.Schema, tx *tx.Transaction) (*tx.ExecutionResponse, error) + Drop(ctx context.Context, dbid string, tx *tx.Transaction) (*tx.ExecutionResponse, error) + Execute(ctx context.Context, dbid string, action string, params []map[string]any, tx *tx.Transaction) (*tx.ExecutionResponse, error) +} + type KwilDbApplication struct { - state KwildState - server *server.Server - executor datasets.DatasetUseCaseInterface + state KwildState + + log log.Logger + executor KwilExecutor ValUpdates []abcitypes.ValidatorUpdate valInfo *node.ValidatorsInfo @@ -49,7 +73,7 @@ type KwilDbApplication struct { var _ abcitypes.Application = (*KwilDbApplication)(nil) -func NewKwilDbApplication(srv *server.Server, executor datasets.DatasetUseCaseInterface) (*KwilDbApplication, error) { +func NewKwilDbApplication(log log.Logger, executor KwilExecutor) (*KwilDbApplication, error) { CometHomeDir := os.Getenv("COMET_BFT_HOME") blockWalPath := filepath.Join(CometHomeDir, "data", "Block.wal") wal, err := gowal.Open(blockWalPath, nil) @@ -67,7 +91,7 @@ func NewKwilDbApplication(srv *server.Server, executor datasets.DatasetUseCaseIn } kwild := &KwilDbApplication{ - server: srv, + log: log, executor: executor, valInfo: node.NewValidatorsInfo(), joinReqPool: node.NewJoinRequestPool(), @@ -87,14 +111,10 @@ func NewKwilDbApplication(srv *server.Server, executor datasets.DatasetUseCaseIn kwild.recoveryMode = true kwild.state = kwild.RetrieveState() } - kwild.executor.InitalizeAppHash(kwild.state.PrevAppHash) + kwild.executor.InitializeAppHash(kwild.state.PrevAppHash) return kwild, nil } -func (app *KwilDbApplication) Start(ctx context.Context) error { - return app.server.Start(ctx) -} - func (app *KwilDbApplication) Info(info abcitypes.RequestInfo) abcitypes.ResponseInfo { return abcitypes.ResponseInfo{ LastBlockHeight: app.state.PrevBlockHeight, @@ -110,17 +130,17 @@ func (app *KwilDbApplication) CheckTx(req_tx abcitypes.RequestCheckTx) abcitypes var tx kTx.Transaction err := json.Unmarshal(req_tx.Tx, &tx) if err != nil { - app.server.Log.Error("failed to unmarshal CheckTx transaction with ", zap.String("error", err.Error())) + app.log.Error("failed to unmarshal CheckTx transaction with ", zap.String("error", err.Error())) return abcitypes.ResponseCheckTx{Code: 1, Log: err.Error()} } err = tx.Verify() if err != nil { - app.server.Log.Error("failed to verify CheckTx transaction with ", zap.String("error", err.Error())) + app.log.Error("failed to verify CheckTx transaction with ", zap.String("error", err.Error())) return abcitypes.ResponseCheckTx{Code: 1, Log: err.Error()} } //TODO: Move the accounts and nonce verification here: - app.server.Log.Info("transaction verified", zap.String("tx hash", string(tx.Hash))) + app.log.Info("transaction verified", zap.String("tx hash", string(tx.Hash))) return abcitypes.ResponseCheckTx{Code: 0} } @@ -133,7 +153,7 @@ func (app *KwilDbApplication) DeliverTx(req_tx abcitypes.RequestDeliverTx) abcit var tx kTx.Transaction err := json.Unmarshal(req_tx.Tx, &tx) if err != nil { - app.server.Log.Error("failed to unmarshal DeliverTx transaction with ", zap.String("error", err.Error())) + app.log.Error("failed to unmarshal DeliverTx transaction with ", zap.String("error", err.Error())) return abcitypes.ResponseDeliverTx{Code: 1, Log: err.Error()} } @@ -154,7 +174,7 @@ func (app *KwilDbApplication) DeliverTx(req_tx abcitypes.RequestDeliverTx) abcit err = fmt.Errorf("unknown payload type: %s", tx.PayloadType) } - app.server.Log.Error("failed to deliver transaction with ", zap.String("error", err.Error())) + app.log.Error("failed to deliver transaction with ", zap.String("error", err.Error())) return abcitypes.ResponseDeliverTx{Code: 1, Log: err.Error()} } @@ -173,30 +193,27 @@ func addFailedEvent(eventType string, err error, owner string, sender string) ab func (app *KwilDbApplication) deploy_database(tx *kTx.Transaction) abcitypes.ResponseDeliverTx { var events []abcitypes.Event ctx := context.Background() - schema, err := txsvc.UnmarshalSchema(tx.Payload) + schema, err := serialize.UnmarshalSchema(tx.Payload) if err != nil { - app.server.Log.Error("ABCI: failed to unmarshal database schema ", zap.String("error", err.Error())) + app.log.Error("ABCI: failed to unmarshal database schema ", zap.String("error", err.Error())) return abcitypes.ResponseDeliverTx{Code: 1, Log: err.Error(), Events: append(events, addFailedEvent("deploy", err, "", tx.Sender))} } if schema.Owner != tx.Sender { err = fmt.Errorf("sender is not the owner of the dataset") - app.server.Log.Error("ABCI: failed to deploy database with ", zap.String("error", err.Error())) + app.log.Error("ABCI: failed to deploy database with ", zap.String("error", err.Error())) return abcitypes.ResponseDeliverTx{Code: 1, Log: "Sender is not the owner of the dataset", Events: append(events, addFailedEvent("deploy", err, schema.Owner, tx.Sender))} } - resp, err := app.executor.Deploy(ctx, &entity.DeployDatabase{ - Schema: schema, - Tx: tx, - }) + resp, err := app.executor.Deploy(ctx, schema, tx) if err != nil { - app.server.Log.Error("ABCI: failed to deploy database with ", zap.String("error", err.Error())) + app.log.Error("ABCI: failed to deploy database with ", zap.String("error", err.Error())) return abcitypes.ResponseDeliverTx{Code: 1, Log: err.Error(), Events: append(events, addFailedEvent("deploy", err, schema.Owner, tx.Sender))} } data, err := json.Marshal(resp) if err != nil { - app.server.Log.Error("ABCI: failed to marshal deploy database response with ", zap.String("error", err.Error())) + app.log.Error("ABCI: failed to marshal deploy database response with ", zap.String("error", err.Error())) return abcitypes.ResponseDeliverTx{Code: 1, Log: err.Error(), Events: append(events, addFailedEvent("deploy", err, schema.Owner, tx.Sender))} } @@ -210,44 +227,41 @@ func (app *KwilDbApplication) deploy_database(tx *kTx.Transaction) abcitypes.Res {Key: "TxSender", Value: tx.Sender, Index: true}, {Key: "DbName", Value: schema.Name, Index: true}, {Key: "DbId", Value: dbid, Index: true}, - {Key: "GasUsed", Value: resp.Fee, Index: true}, + {Key: "GasUsed", Value: resp.Fee.String(), Index: true}, }, }, } - app.server.Log.Info("ABCI: deployed database", zap.String("db id", dbid), zap.String("db name", schema.Name), zap.String("db owner", schema.Owner), zap.String("tx sender", tx.Sender)) + app.log.Info("ABCI: deployed database", zap.String("db id", dbid), zap.String("db name", schema.Name), zap.String("db owner", schema.Owner), zap.String("tx sender", tx.Sender)) return abcitypes.ResponseDeliverTx{Code: 0, Data: data, Log: "Deployed", Events: events} } func (app *KwilDbApplication) drop_database(tx *kTx.Transaction) abcitypes.ResponseDeliverTx { var events []abcitypes.Event ctx := context.Background() - dsIdent, err := txsvc.UnmarshalDatasetIdentifier(tx.Payload) + dsIdent, err := serialize.UnmarshalDatasetIdentifier(tx.Payload) if err != nil { - app.server.Log.Error("ABCI Drop database: failed to unmarshal dataset identifier ", zap.String("error", err.Error())) + app.log.Error("ABCI Drop database: failed to unmarshal dataset identifier ", zap.String("error", err.Error())) return abcitypes.ResponseDeliverTx{Code: 1, Log: err.Error(), Events: append(events, addFailedEvent("drop", err, "", tx.Sender))} } - app.server.Log.Info("ABCI Drop database: dropping database", zap.String("db name", dsIdent.Name), zap.String("db owner", dsIdent.Owner), zap.String("tx sender", tx.Sender)) + app.log.Info("ABCI Drop database: dropping database", zap.String("db name", dsIdent.Name), zap.String("db owner", dsIdent.Owner), zap.String("tx sender", tx.Sender)) if dsIdent.Owner != tx.Sender { err = fmt.Errorf("sender is not the owner of the dataset") - app.server.Log.Error("ABCI Drop database: failed to drop database with ", zap.String("error", err.Error())) + app.log.Error("ABCI Drop database: failed to drop database with ", zap.String("error", err.Error())) return abcitypes.ResponseDeliverTx{Code: 1, Log: "Sender is not the owner of the dataset", Events: append(events, addFailedEvent("drop", err, dsIdent.Owner, tx.Sender))} } dbid := utils.GenerateDBID(dsIdent.Name, dsIdent.Owner) - resp, err := app.executor.Drop(ctx, &entity.DropDatabase{ - DBID: dbid, - Tx: tx, - }) + resp, err := app.executor.Drop(ctx, dbid, tx) if err != nil { - app.server.Log.Error("ABCI Drop database: failed to drop database with ", zap.String("error", err.Error())) + app.log.Error("ABCI Drop database: failed to drop database with ", zap.String("error", err.Error())) return abcitypes.ResponseDeliverTx{Code: 1, Log: err.Error(), Events: append(events, addFailedEvent("drop", err, dsIdent.Owner, tx.Sender))} } data, err := json.Marshal(resp) if err != nil { - app.server.Log.Error("ABCI Drop database: failed to marshal drop database response with ", zap.String("error", err.Error())) + app.log.Error("ABCI Drop database: failed to marshal drop database response with ", zap.String("error", err.Error())) return abcitypes.ResponseDeliverTx{Code: 1, Log: err.Error(), Events: append(events, addFailedEvent("drop", err, dsIdent.Owner, tx.Sender))} } @@ -260,35 +274,32 @@ func (app *KwilDbApplication) drop_database(tx *kTx.Transaction) abcitypes.Respo {Key: "DbName", Value: dsIdent.Name, Index: true}, {Key: "TxSender", Value: tx.Sender, Index: true}, {Key: "DbId", Value: dbid, Index: true}, - {Key: "GasUsed", Value: resp.Fee, Index: true}, + {Key: "GasUsed", Value: resp.Fee.String(), Index: true}, }, }, } - app.server.Log.Info("ABCI: dropped database", zap.String("db id", dbid), zap.String("db name", dsIdent.Name), zap.String("db owner", dsIdent.Owner), zap.String("tx sender", tx.Sender)) + app.log.Info("ABCI: dropped database", zap.String("db id", dbid), zap.String("db name", dsIdent.Name), zap.String("db owner", dsIdent.Owner), zap.String("tx sender", tx.Sender)) return abcitypes.ResponseDeliverTx{Code: 0, Data: data, Events: events} } func (app *KwilDbApplication) execute_action(tx *kTx.Transaction) abcitypes.ResponseDeliverTx { var events []abcitypes.Event ctx := context.Background() - action, err := txsvc.UnmarshalActionExecution(tx.Payload) + action, err := kTx.UnmarshalExecuteAction(tx.Payload) if err != nil { - app.server.Log.Error("ABCI execute action: failed to unmarshal action execution ", zap.String("error", err.Error())) + app.log.Error("ABCI execute action: failed to unmarshal action execution ", zap.String("error", err.Error())) return abcitypes.ResponseDeliverTx{Code: 1, Log: err.Error(), Events: append(events, addFailedEvent("execute", err, "", tx.Sender))} } - resp, err := app.executor.Execute(ctx, &entity.ExecuteAction{ - Tx: tx, - ExecutionBody: action, - }) + resp, err := app.executor.Execute(ctx, action.DBID, action.Action, action.Params, tx) if err != nil { - app.server.Log.Error("ABCI execute action: failed to execute ", zap.String("action", action.Action), zap.String("error", err.Error())) + app.log.Error("ABCI execute action: failed to execute ", zap.String("action", action.Action), zap.String("error", err.Error())) return abcitypes.ResponseDeliverTx{Code: 1, Log: err.Error(), Events: append(events, addFailedEvent("execute", err, "", tx.Sender))} } data, err := json.Marshal(resp) if err != nil { - app.server.Log.Error("ABCI execute action: failed to marshal execute action response with ", zap.String("error", err.Error())) + app.log.Error("ABCI execute action: failed to marshal execute action response with ", zap.String("error", err.Error())) return abcitypes.ResponseDeliverTx{Code: 1, Log: err.Error(), Events: append(events, addFailedEvent("execute", err, "", tx.Sender))} } @@ -298,7 +309,7 @@ func (app *KwilDbApplication) execute_action(tx *kTx.Transaction) abcitypes.Resp params += fmt.Sprintf("%v:%v,", k, v) } } - app.server.Log.Info("ABCI: executed action", zap.String("db id", action.DBID), zap.String("action", action.Action), zap.String("params", params), zap.String("tx sender", tx.Sender)) + app.log.Info("ABCI: executed action", zap.String("db id", action.DBID), zap.String("action", action.Action), zap.String("params", params), zap.String("tx sender", tx.Sender)) events = []abcitypes.Event{ { Type: "execute", @@ -308,8 +319,8 @@ func (app *KwilDbApplication) execute_action(tx *kTx.Transaction) abcitypes.Resp {Key: "DbId", Value: action.DBID, Index: true}, {Key: "Action", Value: action.Action, Index: true}, {Key: "Params", Value: params, Index: true}, - {Key: "Fee", Value: resp.Fee, Index: true}, - {Key: "TxHash", Value: string(resp.TxHash), Index: true}, + {Key: "Fee", Value: resp.Fee.String(), Index: true}, + // {Key: "TxHash", Value: string(resp.TxHash), Index: true}, }, }, } @@ -361,12 +372,12 @@ func (app *KwilDbApplication) validator_approve(tx *kTx.Transaction) abcitypes.R return abcitypes.ResponseDeliverTx{Code: 0} } -func (app *KwilDbApplication) validator_update(tx *kTx.Transaction, is_join bool) (*entity.Validator, error) { +func (app *KwilDbApplication) validator_update(tx *kTx.Transaction, is_join bool) (*serialize.Validator, error) { ctx := context.Background() validator, err := node.UnmarshalValidator(tx.Payload) if err != nil { - app.server.Log.Error("ABCI validator update: failed to unmarshal validator request ", zap.String("error", err.Error())) + app.log.Error("ABCI validator update: failed to unmarshal validator request ", zap.String("error", err.Error())) return nil, err } @@ -429,7 +440,7 @@ func (app *KwilDbApplication) validator_join(tx *kTx.Transaction) abcitypes.Resp validator, err := app.validator_update(tx, true) if err != nil { - app.server.Log.Error("ABCI validator leave: failed to update validator ", zap.String("error", err.Error())) + app.log.Error("ABCI validator leave: failed to update validator ", zap.String("error", err.Error())) if validator != nil { return abcitypes.ResponseDeliverTx{Code: 1, Log: err.Error(), Events: append(events, addFailedEvent("leave_validator", err, string(validator.PubKey), fmt.Sprintf("%d", validator.Power)))} } else { @@ -444,7 +455,7 @@ func (app *KwilDbApplication) validator_join(tx *kTx.Transaction) abcitypes.Resp Type: "validator_join", Attributes: []abcitypes.EventAttribute{ {Key: "Result", Value: "Success", Index: true}, - {Key: "ValidatorPubKey", Value: string(validator.PubKey), Index: true}, + {Key: "ValidatorPubKey", Value: validator.PubKey, Index: true}, {Key: "ValidatorPower", Value: fmt.Sprintf("%d", validator.Power), Index: true}, }, }, @@ -456,7 +467,7 @@ func (app *KwilDbApplication) validator_leave(tx *kTx.Transaction) abcitypes.Res var events []abcitypes.Event validator, err := app.validator_update(tx, false) if err != nil { - app.server.Log.Error("ABCI validator leave: failed to update validator ", zap.String("error", err.Error())) + app.log.Error("ABCI validator leave: failed to update validator ", zap.String("error", err.Error())) if validator != nil { return abcitypes.ResponseDeliverTx{Code: 1, Log: err.Error(), Events: append(events, addFailedEvent("leave_validator", err, string(validator.PubKey), fmt.Sprintf("%d", validator.Power)))} } else { @@ -471,7 +482,7 @@ func (app *KwilDbApplication) validator_leave(tx *kTx.Transaction) abcitypes.Res Type: "remove_validator", Attributes: []abcitypes.EventAttribute{ {Key: "Result", Value: "Success", Index: true}, - {Key: "ValidatorPubKey", Value: string(validator.PubKey), Index: true}, + {Key: "ValidatorPubKey", Value: validator.PubKey, Index: true}, {Key: "ValidatorPower", Value: fmt.Sprintf("%d", validator.Power), Index: true}, }, }, @@ -531,13 +542,13 @@ func (app *KwilDbApplication) BeginBlock(req abcitypes.RequestBeginBlock) abcity return abcitypes.ResponseBeginBlock{} } app.ValUpdates = append(app.ValUpdates, abcitypes.ValidatorUpdate{PubKey: key, Power: ev.Validator.Power - 1}) - app.server.Log.Info("Decreased val power by 1 because of the equivocation", zap.String("val", addr)) + app.log.Info("Decreased val power by 1 because of the equivocation", zap.String("val", addr)) if (ev.Validator.Power - 1) == 0 { - app.server.Log.Info("Val power is 0, removing it from the validator set", zap.String("val", addr)) + app.log.Info("Val power is 0, removing it from the validator set", zap.String("val", addr)) delete(app.state.CurValidatorSet, addr) } } else { - app.server.Log.Error("Wanted to punish val, but can't find it", zap.String("val", addr)) + app.log.Error("Wanted to punish val, but can't find it", zap.String("val", addr)) } } } @@ -561,7 +572,7 @@ func (app *KwilDbApplication) Commit() abcitypes.ResponseCommit { appHash, err := app.executor.EndBlockSession() if err != nil { - app.server.Log.Error("ABCI: failed to end block session with ", zap.String("error", err.Error())) + app.log.Error("ABCI: failed to end block session with ", zap.String("error", err.Error())) return abcitypes.ResponseCommit{Data: app.state.PrevAppHash} } @@ -577,7 +588,7 @@ func (app *KwilDbApplication) Commit() abcitypes.ResponseCommit { func (app *KwilDbApplication) UpdateState() { stateBts, err := json.Marshal(app.state) if err != nil { - app.server.Log.Error("ABCI: failed to marshal state with ", zap.String("error", err.Error())) + app.log.Error("ABCI: failed to marshal state with ", zap.String("error", err.Error())) } app.StateWal.OverwriteSync(stateBts) } @@ -592,7 +603,7 @@ func (app *KwilDbApplication) RetrieveState() KwildState { var stateObj KwildState err := json.Unmarshal(state, &stateObj) if err != nil { - app.server.Log.Error("ABCI: failed to unmarshal state with ", zap.String("error", err.Error())) + app.log.Error("ABCI: failed to unmarshal state with ", zap.String("error", err.Error())) return KwildState{} } return stateObj diff --git a/internal/_node/validators.go b/internal/_node/validators.go index c257765bb..be012084c 100644 --- a/internal/_node/validators.go +++ b/internal/_node/validators.go @@ -6,6 +6,7 @@ import ( cmtCrypto "github.com/cometbft/cometbft/crypto" cmtjson "github.com/cometbft/cometbft/libs/json" + "github.com/kwilteam/kwil-db/pkg/serialize" ) type ValidatorsInfo struct { @@ -35,9 +36,8 @@ func (vInfo *ValidatorsInfo) IsJoinerApproved(joiner string, approver string) bo return false } -func UnmarshalValidator(payload []byte) (*entity.Validator, error) { - validator := entity.Validator{} - +func UnmarshalValidator(payload []byte) (*serialize.Validator, error) { + var validator serialize.Validator err := json.Unmarshal(payload, &validator) if err != nil { return nil, fmt.Errorf("failed to unmarshal validator: %w", err) diff --git a/internal/app/kwild/client/client.go b/internal/app/kwild/client/client.go index 60917c366..01d843e84 100644 --- a/internal/app/kwild/client/client.go +++ b/internal/app/kwild/client/client.go @@ -16,7 +16,7 @@ type KwildConfig struct { func NewClient(ctx context.Context, cfg *KwildConfig) (*client.Client, error) { options := []client.ClientOpt{} if cfg.ClientChainRPCURL != "" { - options = append(options, client.WithChainRpcUrl(cfg.ClientChainRPCURL)) + options = append(options, client.WithCometBftUrl(cfg.ClientChainRPCURL)) } if cfg.PrivateKey != "" { key, _ := crypto.ECDSAFromHex(cfg.PrivateKey) diff --git a/internal/app/kwild/cmd/server/root.go b/internal/app/kwild/cmd/server/root.go index 4fa772ecc..38a1a5572 100644 --- a/internal/app/kwild/cmd/server/root.go +++ b/internal/app/kwild/cmd/server/root.go @@ -4,8 +4,10 @@ import ( "context" "fmt" "io" + "net" "os" "os/signal" + "sync" "syscall" "time" @@ -23,17 +25,14 @@ import ( "google.golang.org/grpc/health/grpc_health_v1" abci "github.com/cometbft/cometbft/abci/types" - ccfg "github.com/cometbft/cometbft/config" - cmtflags "github.com/cometbft/cometbft/libs/cli/flags" - cmtlog "github.com/cometbft/cometbft/libs/log" nm "github.com/cometbft/cometbft/node" // shorthand for chain client service "github.com/kwilteam/kwil-db/pkg/balances" "github.com/kwilteam/kwil-db/pkg/log" - kwildbapp "github.com/kwilteam/kwil-db/internal/abci-apps" + kwildbapp "github.com/kwilteam/kwil-db/internal/_abci-apps" "github.com/spf13/cobra" "github.com/spf13/viper" @@ -43,6 +42,12 @@ import ( "github.com/kwilteam/kwil-db/internal/pkg/healthcheck" simple_checker "github.com/kwilteam/kwil-db/internal/pkg/healthcheck/simple-checker" grpcServer "github.com/kwilteam/kwil-db/pkg/grpc/server" + + cmtcfg "github.com/cometbft/cometbft/config" + cmtflags "github.com/cometbft/cometbft/libs/cli/flags" + cmtlog "github.com/cometbft/cometbft/libs/log" + cmtclient "github.com/cometbft/cometbft/rpc/client" + cmtlocal "github.com/cometbft/cometbft/rpc/client/local" ) func NewStartCmd() *cobra.Command { @@ -60,54 +65,73 @@ var startCmd = &cobra.Command{ return err } + logger := log.New(cfg.Log) + logger = *logger.Named("kwild") + ctx, cancel := context.WithCancel(ctx) defer cancel() - srv, txSvc, err := initialize_kwil_server(ctx, cfg, logger) + // *** JUST TO BUILD + var data kwildbapp.KwilExecutor + var acct txsvc.AccountReader + // *** + + app, err := kwildbapp.NewKwilDbApplication(logger, data /*, validatorStore*/) if err != nil { - return nil + return err } - app, err := kwildbapp.NewKwilDbApplication(srv, txSvc.GetExecutor()) + // Make the Tendermint node + cometNode, err := newCometNode(app, cfg) if err != nil { - return nil + return err } - go func(ctx context.Context) { - srv.Start(ctx) - }(ctx) - - fmt.Printf("Starting Tendermint node\n") - // Start the Tendermint node - cometNode, err := newCometNode(app, cfg, txSvc) + fmt.Printf("Initializing kwil server") + nodeClient := cmtlocal.New(cometNode) // for txsvc to broadcast + srv, err := initializeKwilServer(ctx, cfg, data, acct, nodeClient, logger) if err != nil { - return nil + return err } - txSvc.BcNode = cometNode - - go func(ctx context.Context) { - cometNode.Start() - defer func() { - cometNode.Stop() - cometNode.Wait() - }() - fmt.Printf("Waiting for any signals\n") - c := make(chan os.Signal, 1) - signal.Notify(c, syscall.SIGINT, syscall.SIGTERM) + var wg sync.WaitGroup + + c := make(chan os.Signal, 1) + signal.Notify(c, os.Interrupt, syscall.SIGTERM) + wg.Add(1) + go func() { + defer wg.Done() <-c + fmt.Println("Shutting down...") + cancel() + }() + + fmt.Printf("Starting kwil server") + wg.Add(1) + go func() { + defer wg.Done() + if err := srv.Start(ctx); err != nil && ctx.Err() == nil { + fmt.Printf("Server died unexpectedly: %v\n", err) + cancel() + } + }() + + fmt.Printf("Starting Tendermint node\n") + wg.Add(1) + go func() { + defer wg.Done() + cometNode.Start() // it's RPC and env will be working here + <-ctx.Done() fmt.Printf("Stopping CometBFT node\n") - }(ctx) + cometNode.Stop() + cometNode.Wait() + }() - fmt.Printf("Waiting for any signals - End of main TADA\n") - c := make(chan os.Signal, 1) - signal.Notify(c, syscall.SIGINT, syscall.SIGTERM) - fmt.Println("Waiting for any signals - End of main") + wg.Wait() - <-c - fmt.Printf("Stopping CometBFT node\n") return nil - }} + }, +} func init() { /* @@ -119,21 +143,39 @@ func init() { config.BindFlagsAndEnv(startCmd.PersistentFlags()) } -func initialize_kwil_server(ctx context.Context, cfg *config.KwildConfig, logger log.Logger) (*server.Server, *txsvc.Service, error) { - // TODO: Move to CometBFT later? or are these different accounts? +/* +func makeDataStores(ctx context.Context, cfg *config.KwildConfig, logger log.Logger) (*datasets.DatasetUseCase, error) { fmt.Printf("Building account repository\n") - accountStore, err := buildAccountRepository(ctx, logger, cfg) + accountStore, err := buildAccountRepository(ctx, logger, cfg) // any use outside of txSvc? if err != nil { - fmt.Printf("Failed to build account repository: %v", err) - return nil, nil, fmt.Errorf("failed to build account repository: %w", err) + return nil, fmt.Errorf("failed to build account repository: %w", err) } - fmt.Printf("Building tx service\n") - txSvc, err := buildTxSvc(ctx, cfg, accountStore, logger) + // buildValidatorStore + + datastores, err := buildDatastores(ctx, logger, cfg, accountStore) if err != nil { - fmt.Printf("Failed to build tx service: %v", err) - return nil, nil, fmt.Errorf("failed to build tx service: %w", err) + return nil, fmt.Errorf("failed to build data stores: %w", err) } + return datastores, nil + } +*/ + +// initializeKwilServer creates the tx and health gRPC services, returning a +// Server that must be started. +func initializeKwilServer(ctx context.Context, cfg *config.KwildConfig, engine txsvc.EngineReader, + acct txsvc.AccountReader, nodeClient cmtclient.Client, logger log.Logger) (*server.Server, error) { + // TODO: Move to CometBFT later? or are these different accounts? + fmt.Printf("Building tx service\n") + txSvc := buildTxSvc(engine, acct, nodeClient, logger) + + // TODO: Move to CometBFT later? or are these different accounts? + // fmt.Printf("Building account repository\n") + // accountStore, err := buildAccountRepository(ctx, logger, cfg) + // if err != nil { + // fmt.Printf("Failed to build account repository: %v", err) + // return nil, fmt.Errorf("failed to build account repository: %w", err) + // } fmt.Printf("Building health service\n") healthSvc := buildHealthSvc(logger) @@ -143,12 +185,12 @@ func initialize_kwil_server(ctx context.Context, cfg *config.KwildConfig, logger gw := server.NewGWServer(runtime.NewServeMux(), cfg, logger) if err := gw.SetupGrpcSvc(ctx); err != nil { fmt.Printf("Failed to setup grpc service: %v", err) - return nil, nil, err + return nil, err } fmt.Printf("Setting up http service\n") if err := gw.SetupHTTPSvc(ctx); err != nil { fmt.Printf("Failed to setup http service: %v", err) - return nil, nil, err + return nil, err } fmt.Printf("Adding middlewares\n") @@ -159,7 +201,11 @@ func initialize_kwil_server(ctx context.Context, cfg *config.KwildConfig, logger ) //grpc server - grpcServer := grpcServer.New(logger) + ln, err := net.Listen("tcp", cfg.GrpcListenAddress) + if err != nil { + return nil, err + } + grpcServer := grpcServer.New(logger, ln) txpb.RegisterTxServiceServer(grpcServer, txSvc) grpc_health_v1.RegisterHealthServer(grpcServer, healthSvc) fmt.Printf("Registering grpc services\n") @@ -170,11 +216,11 @@ func initialize_kwil_server(ctx context.Context, cfg *config.KwildConfig, logger Http: gw, Grpc: grpcServer, } - return server, txSvc, nil + return server, nil } -func newCometNode(app abci.Application, cfg *config.KwildConfig, txSvc *txsvc.Service) (*nm.Node, error) { - config := ccfg.DefaultConfig() +func newCometNode(app abci.Application, cfg *config.KwildConfig) (*nm.Node, error) { + config := cmtcfg.DefaultConfig() CometHomeDir := os.Getenv("COMET_BFT_HOME") fmt.Printf("Home Directory: %v", CometHomeDir) config.SetRoot(CometHomeDir) @@ -203,7 +249,7 @@ func newCometNode(app abci.Application, cfg *config.KwildConfig, txSvc *txsvc.Se } logger := cmtlog.NewTMLogger(cmtlog.NewSyncWriter(os.Stdout)) - logger, err = cmtflags.ParseLogLevel(config.LogLevel, logger, ccfg.DefaultLogLevel) + logger, err = cmtflags.ParseLogLevel(config.LogLevel, logger, cfg.Log.Level) if err != nil { return nil, fmt.Errorf("failed to parse log level: %v", err) } @@ -249,15 +295,13 @@ type AccountStore interface { Spend(ctx context.Context, spend *balances.Spend) error } -func buildTxSvc(ctx context.Context, cfg *config.KwildConfig, as AccountStore, logger log.Logger) (*txsvc.Service, error) { +func buildTxSvc(engine txsvc.EngineReader, acct txsvc.AccountReader, + nodeClient cmtclient.Client, logger log.Logger) *txsvc.Service { opts := []txsvc.TxSvcOpt{ txsvc.WithLogger(*logger.Named("txService")), - txsvc.WithAccountStore(as), - txsvc.WithSqliteFilePath(cfg.SqliteFilePath), - txsvc.WithExtensions(cfg.ExtensionEndpoints...), } - return txsvc.NewService(ctx, cfg, opts...) + return txsvc.NewService(engine, acct, nodeClient, opts...) } func buildHealthSvc(logger log.Logger) *healthsvc.Server { @@ -274,10 +318,6 @@ func buildHealthSvc(logger log.Logger) *healthsvc.Server { return healthsvc.NewServer(ck) } -type starter interface { - Start(ctx context.Context) error -} - func NewStopCmd() *cobra.Command { return &cobra.Command{ Use: "stop", diff --git a/internal/app/kwild/server/server.go b/internal/app/kwild/server/server.go index b99ee3681..60cd9ae6a 100644 --- a/internal/app/kwild/server/server.go +++ b/internal/app/kwild/server/server.go @@ -17,12 +17,7 @@ import ( "golang.org/x/sync/errgroup" ) -type starter interface { - Start(ctx context.Context) error -} - type Server struct { - Ctx context.Context Cfg *config.KwildConfig Log log.Logger Http *GWServer @@ -71,7 +66,7 @@ func (s *Server) Start(ctx context.Context) error { s.Grpc.Stop() }() - return s.Grpc.Serve(ctx, s.Cfg.GrpcListenAddress) + return s.Grpc.Start() }) s.Log.Info("grpc server started", zap.String("address", s.Cfg.GrpcListenAddress)) diff --git a/internal/controller/grpc/txsvc/v1/pricing.go b/internal/controller/grpc/txsvc/v1/pricing.go index 067173a97..142457965 100644 --- a/internal/controller/grpc/txsvc/v1/pricing.go +++ b/internal/controller/grpc/txsvc/v1/pricing.go @@ -60,7 +60,7 @@ func (s *Service) priceDrop(ctx context.Context, tx *kTx.Transaction) (*big.Int, } func (s *Service) priceAction(ctx context.Context, tx *kTx.Transaction) (*big.Int, error) { - executionBody, err := serialize.DeserializeActionPaload(tx.Payload) + executionBody, err := serialize.DeserializeActionPayload(tx.Payload) if err != nil { return nil, fmt.Errorf("failed to deserialize action execution: %w", err) } diff --git a/pkg/balances/datastore.go b/pkg/balances/datastore.go index 6db5ff7ec..a35c89f7d 100644 --- a/pkg/balances/datastore.go +++ b/pkg/balances/datastore.go @@ -12,12 +12,8 @@ import ( type Datastore interface { Savepoint() (sql.Savepoint, error) Close() error - // Execute executes a statement. Execute(ctx context.Context, stmt string, args map[string]any) error - - // Query executes a query and returns the result. Query(ctx context.Context, query string, args map[string]any) ([]map[string]any, error) - TableExists(ctx context.Context, table string) (bool, error) Prepare(stmt string) (sql.Statement, error) ApplyChangeset(reader io.Reader) error CreateSession() (sql.Session, error) diff --git a/pkg/engine/master/master_test.go b/pkg/engine/master/master_test.go index 38d33995d..2b358c910 100644 --- a/pkg/engine/master/master_test.go +++ b/pkg/engine/master/master_test.go @@ -4,7 +4,6 @@ import ( "context" "testing" - "github.com/kwilteam/kwil-db/pkg/sql" sqlTesting "github.com/kwilteam/kwil-db/pkg/sql/testing" "github.com/kwilteam/kwil-db/pkg/engine/master" @@ -154,7 +153,7 @@ func Test_Master(t *testing.T) { } defer td() - datastore, err := master.New(ctx, &databaseAdapter{db}) + datastore, err := master.New(ctx, db) if err != nil { t.Fatal(err) } @@ -164,11 +163,3 @@ func Test_Master(t *testing.T) { }) } } - -type databaseAdapter struct { - sqlTesting.TestSqliteClient -} - -func (d *databaseAdapter) Savepoint() (sql.Savepoint, error) { - return d.TestSqliteClient.Savepoint() -} diff --git a/pkg/engine/testing/engine.go b/pkg/engine/testing/engine.go index 2364dad2b..5ff851c0d 100644 --- a/pkg/engine/testing/engine.go +++ b/pkg/engine/testing/engine.go @@ -31,6 +31,8 @@ func newTestDBOpener() *testDbOpener { } } +var _ engine.Opener = (*testDbOpener)(nil) + // testDbOpener creates real sqlite databases that can be used for testing // it also keeps track of the teardown functions so that they can be called // after the test is complete @@ -38,7 +40,7 @@ type testDbOpener struct { teardowns []func() error } -func (t *testDbOpener) Open(name, path string, l log.Logger) (engine.Datastore, error) { +func (t *testDbOpener) Open(name, _ string, l log.Logger) (engine.Datastore, error) { ds, teardown, err := sqlTesting.OpenTestDB(name) if err != nil { return nil, err @@ -60,23 +62,3 @@ func (t *testDbOpener) Teardown() error { return errors.Join(errs...) } - -// type datastoreAdapter struct { -// sqlTesting.TestSqliteClient -// } - -// func (d *datastoreAdapter) Prepare(query string) (engine.Statement, error) { -// return d.TestSqliteClient.Prepare(query) -// } - -// func (d *datastoreAdapter) Savepoint() (engine.Savepoint, error) { -// return d.TestSqliteClient.Savepoint() -// } - -// func (d *datastoreAdapter) CreateSession() (engine.Session, error) { -// return d.TestSqliteClient.CreateSession() -// } - -// func (d *datastoreAdapter) ApplyChangeset(changeset io.Reader) error { -// return d.TestSqliteClient.ApplyChangeset(changeset) -// } diff --git a/pkg/serialize/consensus.go b/pkg/serialize/consensus.go new file mode 100644 index 000000000..60fa4c60b --- /dev/null +++ b/pkg/serialize/consensus.go @@ -0,0 +1,6 @@ +package serialize + +type Validator struct { + PubKey string `json:"pubKey"` + Power int64 `json:"power"` +} diff --git a/pkg/serialize/schema.go b/pkg/serialize/schema.go index 530feab9e..8633ef14a 100644 --- a/pkg/serialize/schema.go +++ b/pkg/serialize/schema.go @@ -1,6 +1,7 @@ package serialize import ( + "encoding/json" "fmt" "strings" @@ -345,3 +346,21 @@ func convertIndexesToDto(indexes []*Index) []*engineTypes.Index { return entityIndexes } + +func UnmarshalSchema(b []byte) (*Schema, error) { + var schema Schema + err := json.Unmarshal(b, &schema) + if err != nil { + return nil, err + } + return &schema, nil +} + +func UnmarshalDatasetIdentifier(b []byte) (*DatasetIdentifier, error) { + var dsIdent DatasetIdentifier + err := json.Unmarshal(b, &dsIdent) + if err != nil { + return nil, err + } + return &dsIdent, nil +} diff --git a/pkg/serialize/serial.go b/pkg/serialize/serial.go index 6c56931ab..0c2ff5159 100644 --- a/pkg/serialize/serial.go +++ b/pkg/serialize/serial.go @@ -34,7 +34,7 @@ func DeserializeDBID(bts []byte) (string, error) { return utils.GenerateDBID(di.Name, di.Owner), nil } -func DeserializeActionPaload(payload []byte) (*tx.ExecuteActionPayload, error) { +func DeserializeActionPayload(payload []byte) (*tx.ExecuteActionPayload, error) { exec := tx.ExecuteActionPayload{} err := json.Unmarshal(payload, &exec) diff --git a/pkg/sql/client/cursor.go b/pkg/sql/client/cursor.go index e6f6796e0..84a7d9197 100644 --- a/pkg/sql/client/cursor.go +++ b/pkg/sql/client/cursor.go @@ -108,5 +108,5 @@ type sqlResult interface { GetRecord() map[string]any - Reset() error + // Reset() error } diff --git a/pkg/sql/testing/testing.go b/pkg/sql/testing/testing.go index 9ec379c9b..b70aef9d4 100644 --- a/pkg/sql/testing/testing.go +++ b/pkg/sql/testing/testing.go @@ -1,9 +1,7 @@ package client import ( - "context" "errors" - "io" "github.com/kwilteam/kwil-db/pkg/log" "github.com/kwilteam/kwil-db/pkg/sql" @@ -13,7 +11,7 @@ import ( // OpenTestDB opens a test database for use in unit tests. // It returns a SqliteClient, a cleanup function, and an error. -func OpenTestDB(name string) (connection TestSqliteClient, teardown func() error, err error) { +func OpenTestDB(name string) (connection *wrappedSqliteClient, teardown func() error, err error) { db, closeFunc, err := sqlite.OpenDbWithTearDown(name) if err != nil { return nil, nil, err @@ -39,27 +37,6 @@ func (w *wrappedSqliteClient) Savepoint() (sql.Savepoint, error) { return w.SqliteClient.Savepoint() } -// we need to get rid of close and delete since the teardown function will handle that -func (w *wrappedSqliteClient) Close() error { - return nil -} - -func (w *wrappedSqliteClient) Delete() error { - return nil -} - func (w *wrappedSqliteClient) CreateSession() (sql.Session, error) { return w.SqliteClient.CreateSession() } - -type TestSqliteClient interface { - Close() error - Delete() error - Execute(context.Context, string, map[string]any) error - Prepare(string) (sql.Statement, error) - Query(context.Context, string, map[string]any) ([]map[string]any, error) - Savepoint() (sql.Savepoint, error) - TableExists(context.Context, string) (bool, error) - CreateSession() (sql.Session, error) - ApplyChangeset(io.Reader) error -} diff --git a/pkg/tx/message.go b/pkg/tx/message.go index b12aad5d0..b9fb2c32e 100644 --- a/pkg/tx/message.go +++ b/pkg/tx/message.go @@ -106,6 +106,15 @@ func (e *ExecuteActionPayload) Bytes() ([]byte, error) { return json.Marshal(e) } +func UnmarshalExecuteAction(b []byte) (*ExecuteActionPayload, error) { + var exec ExecuteActionPayload + err := json.Unmarshal(b, &exec) + if err != nil { + return nil, err + } + return &exec, nil +} + type DatasetIdentifierPayload struct { Owner string `json:"owner"` Name string `json:"name"` diff --git a/test/acceptance/driver.go b/test/acceptance/driver.go index cf7cccccd..a91719535 100644 --- a/test/acceptance/driver.go +++ b/test/acceptance/driver.go @@ -7,8 +7,6 @@ import ( type KwilAcceptanceDriver interface { specifications.DatabaseDeployDsl specifications.DatabaseDropDsl - specifications.ApproveTokenDsl - specifications.DepositFundDsl specifications.ExecuteQueryDsl specifications.ExecuteCallDsl specifications.NetworkOpsDsl diff --git a/test/acceptance/helper.go b/test/acceptance/helper.go index 80a100d1a..6cfd26f62 100644 --- a/test/acceptance/helper.go +++ b/test/acceptance/helper.go @@ -14,13 +14,11 @@ import ( "time" "github.com/kwilteam/kwil-db/internal/app/kwild" - schema "github.com/kwilteam/kwil-db/internal/entity" - "github.com/kwilteam/kwil-db/pkg/chain/types" "github.com/kwilteam/kwil-db/pkg/client" "github.com/kwilteam/kwil-db/pkg/log" + "github.com/kwilteam/kwil-db/pkg/serialize" "github.com/kwilteam/kwil-db/test/acceptance/adapters" "github.com/kwilteam/kwil-db/test/acceptance/utils/deployer" - eth_deployer "github.com/kwilteam/kwil-db/test/acceptance/utils/deployer/eth-deployer" "github.com/kwilteam/kwil-db/test/specifications" "github.com/ethereum/go-ethereum/crypto" @@ -58,15 +56,15 @@ type TestEnvCfg struct { SecondUserPrivateKeyString string DatabaseDeployerPrivateKeyString string DBSchemaFilePath string - NodeURL string // kwild address + NodeURL string // kwild address -- rm? GatewayURL string // kgw address ChainRPCURL string - ChainSyncWaitTime time.Duration - ChainCode types.ChainCode - InitialFundAmount int64 - denomination *big.Int - LogLevel string - CometBftUrl string + // ChainSyncWaitTime time.Duration + // ChainCode types.ChainCode + InitialFundAmount int64 + denomination *big.Int + LogLevel string + CometBftUrl string // Math extension MathExtensionPort string @@ -111,11 +109,11 @@ func GetTestEnvCfg(t *testing.T, remote bool) TestEnvCfg { NodeURL: os.Getenv("TEST_KWILD_ADDR"), GatewayURL: os.Getenv("TEST_KGW_ADDR"), ChainRPCURL: os.Getenv("TEST_PROVIDER"), - ChainSyncWaitTime: 15 * time.Second, - ChainCode: types.GOERLI, - InitialFundAmount: 1, - denomination: big.NewInt(10000), - LogLevel: "debug", + // ChainSyncWaitTime: 15 * time.Second, + // ChainCode: types.GOERLI, + InitialFundAmount: 1, + denomination: big.NewInt(10000), + LogLevel: "debug", } } else { e = TestEnvCfg{ @@ -126,11 +124,11 @@ func GetTestEnvCfg(t *testing.T, remote bool) TestEnvCfg { NodeURL: "", GatewayURL: "", ChainRPCURL: "", - ChainSyncWaitTime: 2 * time.Second, - ChainCode: types.GOERLI, - InitialFundAmount: 100, - denomination: big.NewInt(1000000000000000000), - LogLevel: "debug", + // ChainSyncWaitTime: 2 * time.Second, + // ChainCode: types.GOERLI, + InitialFundAmount: 100, + denomination: big.NewInt(1000000000000000000), + LogLevel: "debug", } } @@ -138,10 +136,10 @@ func GetTestEnvCfg(t *testing.T, remote bool) TestEnvCfg { return e } -func SetupKwildCluster(ctx context.Context, t *testing.T, cfg TestEnvCfg, path string) (TestEnvCfg, []*testcontainers.DockerContainer, deployer.Deployer) { +func SetupKwildCluster(ctx context.Context, t *testing.T, cfg TestEnvCfg, path string) (TestEnvCfg, []*testcontainers.DockerContainer) { // Create Ganache container fmt.Println("ChainRPCURL: ", cfg.ChainRPCURL) - t.Logf("Create ganache container: %s\n", cfg.ChainCode.ToChainId().String()) + // t.Logf("Create ganache container: %s\n", cfg.ChainCode.ToChainId().String()) dockerComposeId := fmt.Sprintf("%d", time.Now().Unix()) t.Log("dockerComposeId", dockerComposeId) pathG := filepath.Join(path, "/ganache/docker-compose.yml") @@ -174,6 +172,7 @@ func SetupKwildCluster(ctx context.Context, t *testing.T, cfg TestEnvCfg, path s t.Log("unexposedChainRPC", unexposedChainRPC) // Deploy contracts + /* xxx chainDeployer := GetDeployer("eth", exposedChainRPC, cfg.DatabaseDeployerPrivateKeyString, cfg.denomination) tokenAddress, err := chainDeployer.DeployToken(ctx) require.NoError(t, err, "failed to deploy token") @@ -185,6 +184,7 @@ func SetupKwildCluster(ctx context.Context, t *testing.T, cfg TestEnvCfg, path s t.Log("create Kwil cluster container") fmt.Println("ChainRPCURL: ", cfg.ChainRPCURL) time.Sleep(20 * time.Second) + */ // Create Kwil cluster container pathK := filepath.Join(path, "/kwil/docker-compose.yml") @@ -229,7 +229,7 @@ func SetupKwildCluster(ctx context.Context, t *testing.T, cfg TestEnvCfg, path s require.NoError(t, err, "failed to get gateway url for service %s", name) t.Logf("gatewayURL: %s for container name: %s", gatewayURL, name) */ } - return cfg, kwildC, chainDeployer + return cfg, kwildC } func SetupKwildDriver(ctx context.Context, t *testing.T, cfg TestEnvCfg, kwildC *testcontainers.DockerContainer, logger log.Logger) KwilAcceptanceDriver { @@ -248,7 +248,7 @@ func SetupKwildDriver(ctx context.Context, t *testing.T, cfg TestEnvCfg, kwildC t.Logf("nodeURL: %s gatewayURL: %s for container name: %s", nodeURL, gatewayURL, name) kwilClt, err := client.New(ctx, nodeURL, - client.WithChainRpcUrl(cfg.ChainRPCURL), + client.WithCometBftUrl(cfg.ChainRPCURL), client.WithPrivateKey(cfg.UserPrivateKey), client.WithCometBftUrl(cometBftURL), ) @@ -258,7 +258,7 @@ func SetupKwildDriver(ctx context.Context, t *testing.T, cfg TestEnvCfg, kwildC return kwildDriver } -func setupCommon(ctx context.Context, t *testing.T, cfg TestEnvCfg, path string) (TestEnvCfg, deployer.Deployer) { +func setupCommon(ctx context.Context, t *testing.T, cfg TestEnvCfg, path string) TestEnvCfg { // ganache container pathG := filepath.Join(path, "/ganache/docker-compose.yml") composeG, err := compose.NewDockerCompose(pathG) @@ -291,15 +291,18 @@ func setupCommon(ctx context.Context, t *testing.T, cfg TestEnvCfg, path string) t.Log("unexposedMathRPC", unexposedMathRPC) // deploy token and escrow contract + /* xxx t.Logf("create chain deployer to %s", exposedChainRPC) chainDeployer := GetDeployer("eth", exposedChainRPC, cfg.DatabaseDeployerPrivateKeyString, cfg.denomination) tokenAddress, err := chainDeployer.DeployToken(ctx) require.NoError(t, err, "failed to deploy token") escrowAddress, err := chainDeployer.DeployEscrow(ctx, tokenAddress.String()) require.NoError(t, err, "failed to deploy escrow") + */ pathK := filepath.Join(path, "/kwil/docker-compose.yml") - kwildC := adapters.StartKwildDockerComposeService(t, ctx, pathK, unexposedChainRPC, escrowAddress.String(), cfg.DatabaseDeployerPrivateKeyString, unexposedMathRPC) + kwildC := adapters.StartKwildDockerComposeService(t, ctx, pathK, unexposedChainRPC, "", + cfg.DatabaseDeployerPrivateKeyString, unexposedMathRPC) exposedKwildEndpoint, err := kwildC.PortEndpoint(ctx, "50051", "") require.NoError(t, err) exposedKgwEndpoint, err := kwildC.PortEndpoint(ctx, "8080", "") @@ -312,7 +315,7 @@ func setupCommon(ctx context.Context, t *testing.T, cfg TestEnvCfg, path string) cfg.NodeURL = exposedKwildEndpoint cfg.GatewayURL = exposedKgwEndpoint cfg.CometBftUrl = cometBftUrl - return cfg, chainDeployer + return cfg } func arch() string { @@ -326,7 +329,7 @@ func arch() string { func setSchemaLoader(cfg TestEnvCfg) { specifications.SetSchemaLoader( &specifications.FileDatabaseSchemaLoader{ - Modifier: func(db *schema.Schema) { + Modifier: func(db *serialize.Schema) { db.Owner = cfg.UserAddr // NOTE: this is a hack to make sure the db name is temporary unique db.Name = fmt.Sprintf("%s_%s", db.Name, time.Now().Format("20160102")) @@ -352,7 +355,7 @@ func setupCliDriver(ctx context.Context, t *testing.T, cfg TestEnvCfg, logger lo return cliDriver, chainDeployer }*/ -func setupGrpcDriver(ctx context.Context, t *testing.T, cfg TestEnvCfg, logger log.Logger, path string) (KwilAcceptanceDriver, deployer.Deployer, TestEnvCfg) { +func setupGrpcDriver(ctx context.Context, t *testing.T, cfg TestEnvCfg, logger log.Logger, path string) (KwilAcceptanceDriver, TestEnvCfg) { setSchemaLoader(cfg) if cfg.NodeURL != "" { @@ -361,29 +364,29 @@ func setupGrpcDriver(ctx context.Context, t *testing.T, cfg TestEnvCfg, logger l require.NoError(t, err, "failed to create kwil client") kwildDriver := kwild.NewKwildDriver(kwilClt, cfg.UserPrivateKey, cfg.GatewayURL, logger) - return kwildDriver, nil, cfg + return kwildDriver, cfg } - updatedCfg, chainDeployer := setupCommon(ctx, t, cfg, path) + updatedCfg := setupCommon(ctx, t, cfg, path) t.Logf("create kwild driver to %s, (gateway: %s)", updatedCfg.NodeURL, updatedCfg.GatewayURL) kwilClt, err := client.New(ctx, updatedCfg.NodeURL, - client.WithChainRpcUrl(updatedCfg.ChainRPCURL), + client.WithCometBftUrl(updatedCfg.ChainRPCURL), client.WithPrivateKey(updatedCfg.UserPrivateKey), client.WithCometBftUrl(updatedCfg.CometBftUrl), ) require.NoError(t, err, "failed to create kwil client") kwildDriver := kwild.NewKwildDriver(kwilClt, updatedCfg.UserPrivateKey, updatedCfg.GatewayURL, logger) - return kwildDriver, chainDeployer, updatedCfg + return kwildDriver, updatedCfg } // NewClient creates a new client that is a KwilAcceptanceDriver // this can be used to simulate several "wallets" in the same test func newGRPCClient(ctx context.Context, t *testing.T, cfg *TestEnvCfg, logger log.Logger) KwilAcceptanceDriver { kwilClt, err := client.New(ctx, cfg.NodeURL, - client.WithChainRpcUrl(cfg.ChainRPCURL), + client.WithCometBftUrl(cfg.ChainRPCURL), client.WithPrivateKey(cfg.UserPrivateKey), client.WithCometBftUrl(cfg.CometBftUrl), ) @@ -393,7 +396,7 @@ func newGRPCClient(ctx context.Context, t *testing.T, cfg *TestEnvCfg, logger lo return kwildDriver } -func GetDriver(ctx context.Context, t *testing.T, driverType string, cfg TestEnvCfg, logger log.Logger, path string) (KwilAcceptanceDriver, deployer.Deployer, TestEnvCfg) { +func GetDriver(ctx context.Context, t *testing.T, driverType string, cfg TestEnvCfg, logger log.Logger, path string) (KwilAcceptanceDriver, TestEnvCfg) { switch driverType { //case "cli": // return setupCliDriver(ctx, t, cfg, logger) @@ -418,6 +421,7 @@ func NewClient(ctx context.Context, t *testing.T, driverType string, cfg TestEnv } } +/* func GetDeployer(deployerType string, rpcURL string, privateKeyStr string, domination *big.Int) deployer.Deployer { switch deployerType { case "eth": @@ -426,3 +430,4 @@ func GetDeployer(deployerType string, rpcURL string, privateKeyStr string, domin panic("unknown deployer type") } } +*/ diff --git a/test/acceptance/kwild_test.go b/test/acceptance/kwild_test.go index 87413ef82..672bb4c0e 100644 --- a/test/acceptance/kwild_test.go +++ b/test/acceptance/kwild_test.go @@ -5,13 +5,10 @@ import ( "flag" "fmt" "testing" - "time" "github.com/kwilteam/kwil-db/pkg/log" "github.com/kwilteam/kwil-db/test/acceptance" "github.com/kwilteam/kwil-db/test/specifications" - - "github.com/stretchr/testify/assert" ) var remote = flag.Bool("remote", false, "run tests against remote environment") @@ -44,9 +41,10 @@ func TestKwildAcceptance(t *testing.T) { // setup path := "./test-data/" - driver, chainDeployer, runningCfg := acceptance.GetDriver(ctx, t, c.driverType, cfg, tLogger, path) + driver, runningCfg := acceptance.GetDriver(ctx, t, c.driverType, cfg, tLogger, path) secondDriver := acceptance.NewClient(ctx, t, c.driverType, runningCfg, tLogger) + /* xxx // NOTE: only local env test, public network test takes too long // thus here test assume user is funded if !*remote { @@ -70,6 +68,7 @@ func TestKwildAcceptance(t *testing.T) { // chain sync, wait kwil to register user time.Sleep(cfg.ChainSyncWaitTime) + */ // running forever for local development if *dev { diff --git a/test/acceptance/utils/deployer/eth-deployer/deployer.go b/test/acceptance/utils/deployer/eth-deployer/deployer.go index 282ca239e..ea2097fd6 100644 --- a/test/acceptance/utils/deployer/eth-deployer/deployer.go +++ b/test/acceptance/utils/deployer/eth-deployer/deployer.go @@ -1,5 +1,6 @@ package eth_deployer +/* import ( "context" "crypto/ecdsa" @@ -258,3 +259,4 @@ func (d *EthDeployer) getAccountAuth(ctx context.Context) (*bind.TransactOpts, e return d.auth, err } +*/ diff --git a/test/integration-tests/cluster_data/database/eth_chain.go b/test/integration-tests/cluster_data/database/eth_chain.go index 541808bd2..48c6032fd 100644 --- a/test/integration-tests/cluster_data/database/eth_chain.go +++ b/test/integration-tests/cluster_data/database/eth_chain.go @@ -1,5 +1,9 @@ +//go:build ignore + package main +/* xxx + import ( "context" "fmt" @@ -59,3 +63,7 @@ func main() { initContract(chainDeployer) keepMiningBlocks(chainDeployer) } + +*/ + +func main() {} diff --git a/test/integration-tests/cluster_data/network/eth_chain.go b/test/integration-tests/cluster_data/network/eth_chain.go index 541808bd2..9d394fc55 100644 --- a/test/integration-tests/cluster_data/network/eth_chain.go +++ b/test/integration-tests/cluster_data/network/eth_chain.go @@ -1,15 +1,6 @@ package main -import ( - "context" - "fmt" - "log" - "math/big" - "time" - - "github.com/kwilteam/kwil-db/test/acceptance" - "github.com/kwilteam/kwil-db/test/acceptance/utils/deployer" -) +/* xxx var ( chainRpc = "http://127.0.0.1:8545" @@ -59,3 +50,7 @@ func main() { initContract(chainDeployer) keepMiningBlocks(chainDeployer) } + +*/ + +func main() {} diff --git a/test/integration-tests/kwild_test.go b/test/integration-tests/kwild_test.go index 053b97017..0ef247f78 100644 --- a/test/integration-tests/kwild_test.go +++ b/test/integration-tests/kwild_test.go @@ -12,7 +12,6 @@ import ( "github.com/kwilteam/kwil-db/pkg/utils" "github.com/kwilteam/kwil-db/test/acceptance" "github.com/kwilteam/kwil-db/test/specifications" - "github.com/stretchr/testify/assert" ) var remote = flag.Bool("remote", false, "run tests against remote environment") @@ -57,7 +56,7 @@ func TestKwildDatabaseIntegration(t *testing.T) { //setupConfig() fmt.Println("ChainRPCURL: ", cfg.ChainRPCURL) - cfg, kwildC, chainDeployer := acceptance.SetupKwildCluster(ctx, t, cfg, path) + cfg, kwildC := acceptance.SetupKwildCluster(ctx, t, cfg, path) //time.Sleep(30 * time.Second) // Create Kwil DB clients for each node @@ -71,11 +70,12 @@ func TestKwildDatabaseIntegration(t *testing.T) { cfg.UserPrivateKeyString = cfg.SecondUserPrivateKeyString // Create invalid user driver - invalidUserDriver := acceptance.SetupKwildDriver(ctx, t, cfg, kwildC[0], tLogger) + // invalidUserDriver := acceptance.SetupKwildDriver(ctx, t, cfg, kwildC[0], tLogger) cfg.UserPrivateKey = correctPrivateKey cfg.UserPrivateKeyString = correctPrivateKeyString // Fund both the User accounts + /* xxx err := chainDeployer.FundAccount(ctx, cfg.UserAddr, cfg.InitialFundAmount) assert.NoError(t, err, "failed to fund user account") @@ -83,8 +83,10 @@ func TestKwildDatabaseIntegration(t *testing.T) { assert.NoError(t, err, "failed to fund second user account") go acceptance.KeepMiningBlocks(ctx, done, chainDeployer, cfg.UserAddr) + */ // and user pledged fund to validator + /* no more token fmt.Println("Approve token1") specifications.ApproveTokenSpecification(ctx, t, node1Driver) fmt.Print("Deposit fund1") @@ -100,6 +102,7 @@ func TestKwildDatabaseIntegration(t *testing.T) { time.Sleep(cfg.ChainSyncWaitTime) time.Sleep(cfg.ChainSyncWaitTime) + */ // running forever for local development if *dev { @@ -118,7 +121,7 @@ func TestKwildDatabaseIntegration(t *testing.T) { specifications.ExecuteDBUpdateSpecification(ctx, t, node2Driver) specifications.ExecuteDBDeleteSpecification(ctx, t, node3Driver) - specifications.ExecutePermissionedActionSpecification(ctx, t, invalidUserDriver) + // specifications.ExecutePermissionedActionSpecification(ctx, t, invalidUserDriver) specifications.DatabaseDropSpecification(ctx, t, node1Driver) close(done) @@ -144,7 +147,7 @@ func TestKwildNetworkIntegration(t *testing.T) { //setupConfig() fmt.Println("ChainRPCURL: ", cfg.ChainRPCURL) - cfg, kwildC, chainDeployer := acceptance.SetupKwildCluster(ctx, t, cfg, path) + cfg, kwildC := acceptance.SetupKwildCluster(ctx, t, cfg, path) //time.Sleep(30 * time.Second) // Create Kwil DB clients for each node @@ -152,6 +155,7 @@ func TestKwildNetworkIntegration(t *testing.T) { node1Driver := acceptance.SetupKwildDriver(ctx, t, cfg, kwildC[1], tLogger) node2Driver := acceptance.SetupKwildDriver(ctx, t, cfg, kwildC[2], tLogger) + /* no more token // Fund both the User accounts err := chainDeployer.FundAccount(ctx, cfg.UserAddr, cfg.InitialFundAmount) assert.NoError(t, err, "failed to fund user account") @@ -162,6 +166,7 @@ func TestKwildNetworkIntegration(t *testing.T) { go acceptance.KeepMiningBlocks(ctx, done, chainDeployer, cfg.UserAddr) // and user pledged fund to validator + fmt.Println("Approve token1") specifications.ApproveTokenSpecification(ctx, t, node0Driver) fmt.Print("Deposit fund1") @@ -169,6 +174,7 @@ func TestKwildNetworkIntegration(t *testing.T) { specifications.DepositFundSpecification(ctx, t, node0Driver) time.Sleep(cfg.ChainSyncWaitTime) + */ // running forever for local development if *dev { diff --git a/test/specifications/approve_token.go b/test/specifications/approve_token.go index de8527417..c97c3c278 100644 --- a/test/specifications/approve_token.go +++ b/test/specifications/approve_token.go @@ -1,5 +1,6 @@ package specifications +/* import ( "context" grpc "github.com/kwilteam/kwil-db/pkg/grpc/client/v1" @@ -32,3 +33,4 @@ func ApproveTokenSpecification(ctx context.Context, t *testing.T, approve Approv assert.NoError(t, err) assert.Equal(t, amount, allowance) } +*/ diff --git a/test/specifications/deploy_database.go b/test/specifications/deploy_database.go index f20918b7d..90e72d3ce 100644 --- a/test/specifications/deploy_database.go +++ b/test/specifications/deploy_database.go @@ -5,13 +5,13 @@ import ( "testing" "time" - schema "github.com/kwilteam/kwil-db/internal/entity" + "github.com/kwilteam/kwil-db/pkg/serialize" "github.com/stretchr/testify/assert" ) // DatabaseDeployDsl is dsl for database deployment specification type DatabaseDeployDsl interface { - DeployDatabase(ctx context.Context, db *schema.Schema) error + DeployDatabase(ctx context.Context, db *serialize.Schema) error // TODO: verify more than just existence, check schema structure DatabaseShouldExists(ctx context.Context, owner string, dbName string) error } diff --git a/test/specifications/network_ops.go b/test/specifications/network_ops.go index ca0c3e219..8944691bb 100644 --- a/test/specifications/network_ops.go +++ b/test/specifications/network_ops.go @@ -5,7 +5,7 @@ import ( "testing" "time" - schema "github.com/kwilteam/kwil-db/internal/entity" + "github.com/kwilteam/kwil-db/pkg/serialize" "github.com/stretchr/testify/assert" ) @@ -16,7 +16,7 @@ type NetworkOpsDsl interface { ValidatorNodeLeave(ctx context.Context, pubKey string) error // ValidatorJoinStatus(ctx context.Context, pubKey []byte) error ValidatorSetCount(ctx context.Context) (int, error) - DeployDatabase(ctx context.Context, db *schema.Schema) error + DeployDatabase(ctx context.Context, db *serialize.Schema) error DropDatabase(ctx context.Context, dbName string) error } diff --git a/test/specifications/utils.go b/test/specifications/utils.go index 1caee2a8f..52837db2d 100644 --- a/test/specifications/utils.go +++ b/test/specifications/utils.go @@ -6,20 +6,20 @@ import ( "testing" "github.com/kwilteam/kuneiform/kfparser" - schema "github.com/kwilteam/kwil-db/internal/entity" "github.com/kwilteam/kwil-db/pkg/engine/utils" + "github.com/kwilteam/kwil-db/pkg/serialize" ) type DatabaseSchemaLoader interface { - Load(t *testing.T, targetSchema *testSchema) *schema.Schema - LoadWithoutValidation(t *testing.T, targetSchema *testSchema) *schema.Schema + Load(t *testing.T, targetSchema *testSchema) *serialize.Schema + LoadWithoutValidation(t *testing.T, targetSchema *testSchema) *serialize.Schema } type FileDatabaseSchemaLoader struct { - Modifier func(db *schema.Schema) + Modifier func(db *serialize.Schema) } -func (l *FileDatabaseSchemaLoader) Load(t *testing.T, targetSchema *testSchema) *schema.Schema { +func (l *FileDatabaseSchemaLoader) Load(t *testing.T, targetSchema *testSchema) *serialize.Schema { t.Helper() d, err := os.ReadFile(targetSchema.GetFilePath()) @@ -37,7 +37,7 @@ func (l *FileDatabaseSchemaLoader) Load(t *testing.T, targetSchema *testSchema) t.Fatal("failed to marshal schema: %w", err) } - var db *schema.Schema + var db *serialize.Schema err = json.Unmarshal(schemaJson, &db) if err != nil { t.Fatal("failed to unmarshal schema json: %w", err) @@ -47,7 +47,7 @@ func (l *FileDatabaseSchemaLoader) Load(t *testing.T, targetSchema *testSchema) return db } -func (l *FileDatabaseSchemaLoader) LoadWithoutValidation(t *testing.T, targetSchema *testSchema) *schema.Schema { +func (l *FileDatabaseSchemaLoader) LoadWithoutValidation(t *testing.T, targetSchema *testSchema) *serialize.Schema { t.Helper() d, err := os.ReadFile(targetSchema.GetFilePath()) @@ -66,7 +66,7 @@ func (l *FileDatabaseSchemaLoader) LoadWithoutValidation(t *testing.T, targetSch t.Fatal("failed to marshal schema: %w", err) } - var db *schema.Schema + var db *serialize.Schema err = json.Unmarshal(schemaJson, &db) if err != nil { t.Fatal("failed to unmarshal schema json: %w", err)