Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,12 @@ jobs:
if: ${{ !env.ACT }} # skip during local actions testing
uses: golangci/golangci-lint-action@v4
with:
args: --timeout=30m --config=.golangci.yml --issues-exit-code=0
args: --timeout=30m --issues-exit-code=0
skip-cache: true

- name: Run Go Tests
run: |
go test ./internal/extensions/...
go test ./internal/...

- name: Docker Compose Up
# docker compose up --wait makes it exit with 1 even for a successful run
Expand Down
4 changes: 0 additions & 4 deletions .golangci.yml

This file was deleted.

43 changes: 19 additions & 24 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# Contributing

Thanks for taking the time to contribute to kwil-db!
Thanks for taking the time to contribute to tsn-db!

Please follow the guidelines below when contributing. If you have any questions, please feel free to reach out to us on [Discord](https://discord.com/invite/HzRPZ59Kay) or use the [discussions](https://github.com/kwilteam/kwil-db/discussions) feature on GitHub.
Please follow the guidelines below when contributing. If you have any questions, please feel free to reach out to us on [Discord](https://discord.com/invite/5AMCBYxfW4) or use the [discussions](https://github.com/truflation/tsn-db/discussions) feature on GitHub.

## Table of Contents

Expand All @@ -16,35 +16,34 @@ Please follow the guidelines below when contributing. If you have any questions,

## Discussions

Discussions are for general discussions related to kwil-db. This can be to discuss kwil-db architecture, important tradeoffs / considerations, or any topics that cannot be directly closed by a pull request.
Discussions are for general discussions related to tsn-db. This can be to discuss tsn-db architecture, important tradeoffs / considerations, or any topics that cannot be directly closed by a pull request.

Examples of good discussions:

- Discussing potental ways to price queries in kwil-db
- Discussing the tradeoffs of using postgres vs sqlite.
- Discussing potental ways to price queries in tsn-db
- Discussing potential procedures for handling consensus failures & changes (and a future issue if the discussion determines we need a feature, bug fix, or documentation change).

Discussions can lead to an issue if they determine that a feature, bug fix, or documentation change is needed.

## Issues

Issues are for reporting bugs, requesting features, requesting repository documentation, or discussing any other changes that can be directly resolved with a pull request to the kwil-db repository.
Issues are for reporting bugs, requesting features, requesting repository documentation, or discussing any other changes that can be directly resolved with a pull request to the tsn-db repository.

For general discussions, or discussions where it is unclear how the discussion would be closed by a pull request, please use the [discussion](https://github.com/kwilteam/kwil-db/discussions) section.
For general discussions, or discussions where it is unclear how the discussion would be closed by a pull request, please use the [discussion](https://github.com/truflation/tsn-db/discussions) section.

For opening issues, please follow the following guidelines:

- **Use templates** for creating issues about bugs, feature requests, or documentation requests.
- **Search** the issue tracker before opening an issue to avoid duplicates.
- **Be clear & detailed** about what you are reporting. If reporting a bug, please include a minimal reproducible example, a detailed explanation of your KwilD configuration, and any logs or error messages that may be relevant.

We strongly recommended submitting an issue before submitting a pull request, especially for pull requests that will require significant effort on your part. This is to ensure that the issue is not already being worked on and that your pull request will be accepted. Some features or fixes are intentionally not included in kwil-db - use issues to check with maintainers and save time!
We strongly recommended submitting an issue before submitting a pull request, especially for pull requests that will require significant effort on your part. This is to ensure that the issue is not already being worked on and that your pull request will be accepted. Some features or fixes are intentionally not included in tsn-db - use issues to check with maintainers and save time!

## Pull Requests

### Commit Messages

kwil-db uses recommended [Go commit messages](https://go.dev/doc/contribute#commit_messages), with breaking changes and deprecations to be noted in the commit message footer. Commits should follow the following format:
tsn-db uses recommended [Go commit messages](https://go.dev/doc/contribute#commit_messages), with breaking changes and deprecations to be noted in the commit message footer. Commits should follow the following format:

```
[Package/File/Directory Name]: [Concise and concrete description of the PR/Issue]
Expand All @@ -57,18 +56,18 @@ kwil-db uses recommended [Go commit messages](https://go.dev/doc/contribute#comm
For example:

```
cmd/kwil-cli: Add new command to do something
feat: Add new exntension to do something

This PR adds a new command to do something. It also adds a new flag to the existing command to do something else.
This PR adds a new exntension to do something. It also adds a new flag to the existing command to do something else.

Resolves #123

BREAKING CHANGE: This PR changes the behavior of the foo command. It now does something else.
```

There are two types of breaking changes: API breaking changes and consensus breaking changes. API breaking changes are any changes that effect the external API of packages that are consumed outside of kwil-db (i.e. proto, core, extensions, and cmd). Consensus breaking changes are any changes that effect the consensus protocol of kwil-db (i.e. changes to the database, or changes to the consensus protocol in internal).
There are two types of breaking changes: API breaking changes and consensus breaking changes. API breaking changes are any changes that effect the external API of packages that are consumed outside of tsn-db. Consensus breaking changes are any changes that effect the consensus protocol of tsn-db (i.e. changes to the extension, or changes to the consensus protocol in internal).

Changes to internal packages (i.e. deployments, internal, parse, scripts, and test) that do not affect the database or consensus are not considered breaking changes and do not need to be tagged in the commit footer.
Changes to internal packages (i.e. deployments, internal, and scripts) that do not affect the database or consensus are not considered breaking changes and do not need to be tagged in the commit footer.

### Coding Style

Expand All @@ -80,11 +79,11 @@ Please ensure that your contributions adhere to the following coding guidelines:

### Pull Request Process

1. Fork the repository by clicking the "Fork" button on the top right of the repository page. Clone the kwil-db repository and add your fork as a remote.
1. Fork the repository by clicking the "Fork" button on the top right of the repository page. Clone the tsn-db repository and add your fork as a remote.

```bash
git clone https://github.com/kwilteam/kwil-db
cd kwil-db
git clone https://github.com/truflation/tsn-db
cd tsn-db
git checkout main
git remote add <your-origin-name> <your-fork-url>
git fetch <your-origin-name>
Expand All @@ -101,12 +100,8 @@ git checkout -b <branch-name>
3. Ensure that your PR is ready to be merged and all unit and acceptance tests pass:

```bash
task install:deps # If first time contributing
task fmt
task lint
task tidy
task test:unit
task test:act
task lint
task coverage
```

4. Push your branch to github.
Expand All @@ -120,10 +115,10 @@ git push -u <your-origin-name> <branch-name>

Please ensure that all the commits in your git history match the commit message [guidelines](#commit-messages) above. You can use `git rebase -i` to edit your commit history.

5. Open a pull request to the `main` branch of the kwil-db repository. Please follow the PR template. If `main` updates while the PR is open, please update the branch with latest `main` (rebase or merge).
5. Open a pull request to the `main` branch of the tsn-db repository. Please follow the PR template. If `main` updates while the PR is open, please update the branch with latest `main` (rebase or merge).

6. Wait for a maintainer to review your PR. If there are any issues, you will be notified and you can make the necessary changes.

## License

By contributing to kwil-db, you agree that your contributions will be licensed under its [Apache 2.0 License](https://www.apache.org/licenses/LICENSE-2.0).
By contributing to tsn-db, you agree that your contributions will be licensed under its [Apache 2.0 License](https://www.apache.org/licenses/LICENSE-2.0).
2 changes: 1 addition & 1 deletion LICENSE.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Copyright 2024 Kwil, Inc.
Copyright 2024 Tru Labs Inc.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion NOTICE.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Copyright (c) 2024 Kwil, Inc. All Rights Reserved.
Copyright (c) 2024 Tru Labs Inc. All Rights Reserved.

This product statically links to the go-ethereum library (https://github.com/ethereum/go-ethereum), which is licensed under the LGPLv3 license.
A full text of the license can be found here: https://www.gnu.org/licenses/lgpl-3.0.en.html.
70 changes: 34 additions & 36 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,60 +1,71 @@
# Kwil DB
# TSN DB

The database for Web3.
The database for Truflation Stream Network (TSN). It is built on top of the Kwil framework.

## Overview

Learn more about Kwil at [kwil.com](https://kwil.com).
Learn more about Truflation at [Truflation.com](https://truflation.com)

## Build instructions

### Prerequisites

To build Kwil, you will need to install:
To build and run the TSN-DB, you will need the following installed on your system:

1. [Go](https://golang.org/doc/install)
2. [Taskfile](https://taskfile.dev/installation)
3. [Docker Compose](https://docs.docker.com/compose)
4. [Python](https://www.python.org/downloads) (optional for running the seed script)
5. [Pandas](https://pandas.pydata.org) (optional for running the seed script)

### Build
### Build Locally

Invoke `task` command to see all available tasks. The `build` task will compile `kwild`. They will be generated in `.build/`:
#### Run With Docker Compose (Recommended)

```shell
task build
To run the TSN-DB using Docker Compose, run the following command:
```
task compose
```
It will build and start the TSN-DB in Docker containers, which is already seeded.

#### Build and Run the TSN-DB without Docker Compose

## Local deployment
Alternatively, you can build and run the TSN-DB without Docker Compose.
This is useful if you want to run the TSN-DB locally without Docker. i.e. for development or debugging purposes.
To build and run the TSN-DB without Docker Compose, follow the steps below:

### Run Postgres
##### Build the binary
Invoke `task` command to see all available tasks. The `build` task will compile the binary for you. They will be generated in `.build/`:

Before running the custom kwild binary, you will have to start Postgres.
The Kwil team has provided a default image with the necessary configurations.
For more information on how to configure your own Postgres database, please refer to the [Postgres setup guide](https://docs.kwil.com/docs/daemon/installation#postgresql).
```shell
task # list all available tasks
task build # build the binary
```

##### Run Postgres

Before running the, you will have to start Postgres. You can start Postgres using the following command:
```
docker run -d -p 5432:5432 --name kwil-postgres -e "POSTGRES_HOST_AUTH_METHOD=trust" \
kwildb/postgres:latest
task postgres
```

### Run Kwild
##### Run Kwild

You can start a single node network using the `kwild` binary built in the step above:

```shell
task kwild
```

For more information on running nodes, and how to run a multi-node network, refer to the Kwil [documentation](<https://docs.kwil.com/docs/node/quickstart>).

### Resetting local deployments
##### Resetting local deployments

You can clear the local Kwil data by running the following command:
You can clear the local data by running the following command:

```shell
task clear-data
```

### Configure the kwil-cli
##### Configure the kwil-cli

To interact with the the TSN-DB, you will need to configure the kwil-cli.
```shell
Expand All @@ -67,25 +78,12 @@ Private Key: <any ethereum private key>
# use private key 0000000000000000000000000000000000000000000000000000000000000001 for testing
```

## Docker Compose Deployment

### Run TSN-DB with Postgres using Docker Compose

To run the TSN-DB with Postgres using Docker Compose, run the following command:
```shell
task compose
```

This will start the TSN-DB and Postgres in Docker containers, which is already seeded.

#### Seed Data
##### Seed Data
If you need to manually seed data into the TSN-DB, run the following command:
```shell
task seed
```

## License

The kwil-db repository (i.e. everything outside of the `core` directory) is licensed under the Apache License, Version 2.0. See [LICENSE](LICENSE) for more details.

The kwil golang SDK (i.e. everything inside of the `core` directory) is licensed under the MIT License. See [core/LICENSE.md](core/LICENSE.md) for more details.
The tsn-db repository is licensed under the Apache License, Version 2.0. See [LICENSE](LICENSE) for more details.
23 changes: 23 additions & 0 deletions internal/extensions/basestream/basestream_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,29 @@ func Test_Index(t *testing.T) {

returned, err = b.index(scope, app, "2024-01-01", nil)
assert.NoError(t, err)
assert.Equal(t, []utils.ValueWithDate{{Date: "2024-01-01", Value: 200000}}, returned)

t.Run("validation - it should return an error expected single value when base value is not a single value", func(t *testing.T) {
mockSql := map[string]*sql.ResultSet{
b.sqlGetBaseValue(): mockDateScalar("value", []utils.ValueWithDate{
{Date: "2024-01-01", Value: 75000},
{Date: "2024-01-02", Value: 150000},
}),
}
app.Engine = newEngine(t, mockSql)
_, err = b.index(scope, app, "2024-01-01", nil)
assert.Error(t, err)
assert.Contains(t, err.Error(), "expected single value")
})

t.Run("error - it should return an error if b.value returns an error", func(t *testing.T) {
mockSql := map[string]*sql.ResultSet{
b.sqlGetBaseValue(): mockDateScalar("value", []utils.ValueWithDate{{Date: "2024-01-01", Value: 75000}}), // 75.000
}
app.Engine = newEngine(t, mockSql)
_, err = b.index(scope, app, "2024-01-01", nil)
assert.Error(t, err)
})
}

func Test_Value(t *testing.T) {
Expand Down
Loading