Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
7e8cde1
Add osusergo build tag
laodouya Jan 23, 2019
15ea0a0
Add HomeDirExpand func in utils for home dir(~) expand
laodouya Jan 23, 2019
fe4c4e9
Remove user params in HomeDirExpand func.
laodouya Jan 23, 2019
fd58b89
Remove unreachable code.
laodouya Jan 23, 2019
cd71df9
Change cql-utils use ~/.cql as config.yaml/private.key default location.
laodouya Jan 23, 2019
a948f24
Update cql-utils docs. Disable keygen params
laodouya Jan 23, 2019
7d6369d
Change cql to use ~/.cql as config.yaml default location.
laodouya Jan 23, 2019
0f1fdd8
Update testnet client test. Format cql-utils command help
laodouya Jan 23, 2019
3cdc4e9
Change cql-adapter to use ~/.cql as config.yaml default location.
laodouya Jan 23, 2019
e142bcc
Change cql-mysql-adapter to use ~/.cql as config.yaml default location.
laodouya Jan 23, 2019
a9cdb89
Change cql-faucet to use ~/.cql as config.yaml default location.
laodouya Jan 23, 2019
2e8a8f2
Change cql-explorer to use ~/.cql as config.yaml default location.
laodouya Jan 23, 2019
9f0b86d
Change cql-fuse to use ~/.cql as config.yaml default location.
laodouya Jan 23, 2019
88fbd89
Change cql-observer to use ~/.cql as config.yaml default location.
laodouya Jan 23, 2019
dd26565
Set errexit pipefail for compatibility-testnet.
laodouya Jan 23, 2019
1fd9871
Remove osusergo build tags. Add build tags for unittest.
laodouya Jan 23, 2019
db97536
Set -x for gitlabci process.
laodouya Jan 24, 2019
682f729
Fix go test unit test tags quote err.
laodouya Jan 24, 2019
48753cb
Set -x for alltest.sh
laodouya Jan 24, 2019
c5e317c
Move set -x location in alltest.sh
laodouya Jan 24, 2019
9d2c700
Change cql-minerd to use ~/.cql as config.yaml default location.
laodouya Jan 24, 2019
54b5d50
Change cqld to use ~/.cql as config.yaml default location.
laodouya Jan 24, 2019
6be5079
Use default config file path(~/.cql/config.yaml) if driver not call I…
laodouya Jan 24, 2019
aea44af
Update client example
laodouya Jan 24, 2019
9b8114c
Fix missing 'linux' building tags.
laodouya Jan 28, 2019
b3e28cf
Fix typo
auxten Jan 28, 2019
520d725
Skip compatibility test if branch name contains '/beta_'
laodouya Jan 28, 2019
733418f
Remove '-x' for test_my_project in gitlabci.
laodouya Jan 28, 2019
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
14 changes: 11 additions & 3 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ variables:
REVIEWDOG_VERSION: 0.9.11
REVIEWDOG_GITLAB_API_TOKEN: $REVIEWDOG_TOKEN
CODECOV_TOKEN: $CODECOV_TOKEN
UNITTESTTAGS: linux sqlite_omit_load_extension

before_script:
# Setup dependency management tool
Expand All @@ -24,12 +25,19 @@ before_script:

test-my-project:
stage: test
script: ./alltest.sh
script:
- ./alltest.sh

compatibility-testnet:
stage: test
script:
- set -o errexit
- set -o pipefail
- commit=$(git rev-parse --short HEAD)
- branch=$(git branch -rv |grep $commit | awk '{print $1}')
- if [[ $branch =~ "/beta_" ]]; then exit 0; fi
- make clean
- make -j8 client
- go test -bench=^BenchmarkTestnetMiner2$ -benchtime=5s -run ^$ ./cmd/cql-minerd/
- bash test/testnet_client/run.sh
- go test -tags "$UNITTESTTAGS" -bench=^BenchmarkTestnetMiner2$ -benchtime=5s -run ^$ ./cmd/cql-minerd/
- set -x
- ./test/testnet_client/run.sh
6 changes: 3 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -120,14 +120,14 @@ builddate := $(shell date +%Y%m%d%H%M%S)

unamestr := $(shell uname)

ifeq ($(unamestr),"Linux")
platform := "linux"
ifeq ($(unamestr),Linux)
platform := linux
endif

version := $(branch)-$(GIT_COMMIT)-$(builddate)

tags := $(platform) sqlite_omit_load_extension
testtags := $(platform) sqlite_omit_load_extension testbinary
testtags := $(tags) testbinary
test_flags := -coverpkg github.com/CovenantSQL/CovenantSQL/... -cover -race -c

ldflags_role_bp := -X main.version=$(version) -X github.com/CovenantSQL/CovenantSQL/conf.RoleTag=B $$GOLDFLAGS
Expand Down
7 changes: 4 additions & 3 deletions alltest.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ test::package() {

local coverage_file="${package//\//.}.cover.out"
echo "[TEST] package=${package}, coverage=${coverage_file}"
go test -race -failfast -parallel 16 -cpu 16 -coverpkg="github.com/CovenantSQL/CovenantSQL/..." -coverprofile "${coverage_file}" "${package}"
go test -tags "$UNITTESTTAGS" -race -failfast -parallel 16 -cpu 16 -coverpkg="github.com/CovenantSQL/CovenantSQL/..." -coverprofile "${coverage_file}" "${package}"
}

main() {
Expand All @@ -26,13 +26,14 @@ main() {
test::package "${package}"
done

set -x
gocovmerge *.cover.out $(find cmd -name "*.cover.out") | grep -F -v '_gen.go' > coverage.txt && rm -f *.cover.out
bash <(curl -s https://codecov.io/bash)

# some benchmarks
go test -bench=^BenchmarkPersistentCaller_Call$ -run ^$ ./rpc/
go test -tags "$UNITTESTTAGS" -bench=^BenchmarkPersistentCaller_Call$ -run ^$ ./rpc/
bash cleanupDB.sh || true
go test -bench=^BenchmarkMinerTwo$ -benchtime=5s -run ^$ ./cmd/cql-minerd/
go test -tags "$UNITTESTTAGS" -bench=^BenchmarkMinerTwo$ -benchtime=5s -run ^$ ./cmd/cql-minerd/
bash cleanupDB.sh || true
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,21 @@ import (
"flag"

"github.com/CovenantSQL/CovenantSQL/client"
"github.com/CovenantSQL/CovenantSQL/utils"
"github.com/CovenantSQL/CovenantSQL/utils/log"
)

func main() {
log.SetLevel(log.DebugLevel)
var config, password, dsn string

flag.StringVar(&config, "config", "./conf/config.yaml", "config file path")
flag.StringVar(&config, "config", "~/.cql/config.yaml", "config file path")
flag.StringVar(&dsn, "dsn", "", "database url")
flag.StringVar(&password, "password", "", "master key password for covenantsql")
flag.Parse()

config = utils.HomeDirExpand(config)

err := client.Init(config, []byte(password))
if err != nil {
log.Fatal(err)
Expand Down
32 changes: 13 additions & 19 deletions client/_example/simple.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,33 +21,27 @@ import (
"flag"
"fmt"

"github.com/CovenantSQL/CovenantSQL/client"
_ "github.com/CovenantSQL/CovenantSQL/client"
"github.com/CovenantSQL/CovenantSQL/utils/log"
)

func main() {
log.SetLevel(log.InfoLevel)
var config, password, dsn string
var dsn string

flag.StringVar(&config, "config", "./conf/config.yaml", "config file path")
flag.StringVar(&dsn, "dsn", "", "database url")
flag.StringVar(&password, "password", "", "master key password for covenantsql")
flag.StringVar(&dsn, "dsn", "", "Database url")
Comment thread
laodouya marked this conversation as resolved.
flag.Parse()

err := client.Init(config, []byte(password))
if err != nil {
log.Fatal(err)
}

if dsn == "" {
meta := client.ResourceMeta{}
meta.Node = 2
dsn, err = client.Create(meta)
if err != nil {
log.Fatal(err)
}
defer client.Drop(dsn)
}
// If your CovenantSQL config.yaml is not in ~/.cql/config.yaml
// Uncomment and edit following code
/*
config := "/data/myconfig/config.yaml"
password := "mypassword"
err := client.Init(config, []byte(password))
if err != nil {
log.Fatal(err)
}
*/

db, err := sql.Open("covenantsql", dsn)
if err != nil {
Expand Down
23 changes: 20 additions & 3 deletions client/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import (
"github.com/CovenantSQL/CovenantSQL/route"
"github.com/CovenantSQL/CovenantSQL/rpc"
"github.com/CovenantSQL/CovenantSQL/types"
"github.com/CovenantSQL/CovenantSQL/utils"
"github.com/CovenantSQL/CovenantSQL/utils/log"
"github.com/pkg/errors"
)
Expand All @@ -63,12 +64,15 @@ var (
connIDAvail []uint64
globalSeqNo uint64
randSource = rand.New(rand.NewSource(time.Now().UnixNano()))

defaultConfigFile = "~/.cql/config.yaml"
)

func init() {
d := new(covenantSQLDriver)
sql.Register(DBScheme, d)
sql.Register(DBSchemeAlias, d)
log.Debug("CovenantSQL driver registered.")
}

// covenantSQLDriver implements sql.Driver interface.
Expand All @@ -83,8 +87,10 @@ func (d *covenantSQLDriver) Open(dsn string) (conn driver.Conn, err error) {
}

if atomic.LoadUint32(&driverInitialized) == 0 {
err = ErrNotInitialized
return
err = defaultInit()
if err != nil && err != ErrAlreadyInitialized {
return
}
}

return newConn(cfg)
Expand All @@ -97,6 +103,18 @@ type ResourceMeta struct {
AdvancePayment uint64
}

func defaultInit() (err error) {
Comment thread
laodouya marked this conversation as resolved.
configFile := utils.HomeDirExpand(defaultConfigFile)
if configFile == defaultConfigFile {
//System not support ~ dir, need Init manually.
log.Debugf("Could not find CovenantSQL default config location: %v", configFile)
return ErrNotInitialized
}

log.Debugf("Using CovenantSQL default config location: %v", configFile)
return Init(configFile, []byte(""))
}

// Init defines init process for client.
func Init(configFile string, masterKey []byte) (err error) {
if !atomic.CompareAndSwapUint32(&driverInitialized, 0, 1) {
Expand Down Expand Up @@ -410,7 +428,6 @@ func WaitTxConfirmation(
return
}
}
return
}

func getNonce(addr proto.AccountAddress) (nonce interfaces.AccountNonce, err error) {
Expand Down
10 changes: 6 additions & 4 deletions cmd/cql-adapter/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,14 @@ Created a new certificate valid for the following names 📜
- "server"

The certificate is at "./server.pem" and the key at "./server-key.pem" ✅

And move them to ~/.cql/ dir.
``````

You can use following interactive command to generate adapter config.

```shell
$ cql-utils -tool adapterconfgen -config config.yaml
$ cql-utils -tool adapterconfgen
ListenAddr (default: 0.0.0.0:4661): ⏎
CertificatePath (default: server.pem): ⏎
PrivateKeyPath (default: server-key.pem): ⏎
Expand All @@ -58,7 +60,7 @@ WriteCerts (default:): ⏎
StorageDriver (default: covenantsql): ⏎
StorageRoot (default:): ⏎

$ tail -n 20 config.yaml
$ tail -n 20 ~/.cql/config.yaml
... skipping irrelevant configuration
Adapter:
ListenAddr: 0.0.0.0:4661
Expand All @@ -79,7 +81,7 @@ Adapter:
Start the adapter by following commands:

```shell
$ cql-adapter -config config.yaml
$ cql-adapter
```

### API
Expand Down Expand Up @@ -266,4 +268,4 @@ curl -v https://e.morenodes.com:11108/v1/query --insecure \

###### Parameters

**database:** database id
**database:** database id
7 changes: 5 additions & 2 deletions cmd/cql-adapter/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
"time"

"github.com/CovenantSQL/CovenantSQL/crypto/asymmetric"
"github.com/CovenantSQL/CovenantSQL/utils"
"github.com/CovenantSQL/CovenantSQL/utils/log"
"golang.org/x/sys/unix"
)
Expand All @@ -40,8 +41,8 @@ var (
)

func init() {
flag.StringVar(&configFile, "config", "./config.yaml", "config file for adapter")
flag.StringVar(&password, "password", "", "master key password")
flag.StringVar(&configFile, "config", "~/.cql/config.yaml", "Config file for adapter")
flag.StringVar(&password, "password", "", "Master key password")
flag.BoolVar(&asymmetric.BypassSignature, "bypass-signature", false,
"Disable signature sign and verify, for testing")
flag.BoolVar(&showVersion, "version", false, "Show version information and exit")
Expand All @@ -55,6 +56,8 @@ func main() {
os.Exit(0)
}

configFile = utils.HomeDirExpand(configFile)

flag.Visit(func(f *flag.Flag) {
log.Infof("args %#v : %s", f.Name, f.Value)
})
Expand Down
12 changes: 6 additions & 6 deletions cmd/cql-explorer/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ Generate the main configuration file. Same as [Generating Default Config File in
Start the explorer by following commands:

```shell
$ cql-explorer -config config.yaml
$ cql-explorer
```

The available options are:
Expand All @@ -30,13 +30,13 @@ The available options are:
$ cql-explorer --help
Usage of cql-explorer:
-config string
config file path (default "./config.yaml")
Config file path (default "~/.cql/config.yaml")
-interval duration
new block check interval for explorer (default 2s)
New block check interval for explorer (default 2s)
-listen string
listen address for http explorer api (default "127.0.0.1:4665")
Listen address for http explorer api (default "127.0.0.1:4665")
-password string
master key password for covenantsql
Master key password for covenantsql
```

### API
Expand Down Expand Up @@ -179,4 +179,4 @@ __hash__: hash of specified tx
}
}
}
```
```
11 changes: 7 additions & 4 deletions cmd/cql-explorer/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (
"time"

"github.com/CovenantSQL/CovenantSQL/client"
"github.com/CovenantSQL/CovenantSQL/utils"
"github.com/CovenantSQL/CovenantSQL/utils/log"
)

Expand All @@ -47,10 +48,10 @@ var (
)

func init() {
flag.StringVar(&configFile, "config", "./config.yaml", "config file path")
flag.StringVar(&listenAddr, "listen", "127.0.0.1:4665", "listen address for http explorer api")
flag.DurationVar(&checkInterval, "interval", time.Second*2, "new block check interval for explorer")
flag.StringVar(&password, "password", "", "master key password for covenantsql")
flag.StringVar(&configFile, "config", "~/.cql/config.yaml", "Config file path")
flag.StringVar(&listenAddr, "listen", "127.0.0.1:4665", "Listen address for http explorer api")
flag.DurationVar(&checkInterval, "interval", time.Second*2, "New block check interval for explorer")
flag.StringVar(&password, "password", "", "Master key password for covenantsql")
flag.BoolVar(&showVersion, "version", false, "Show version information and exit")
}

Expand All @@ -65,6 +66,8 @@ func main() {
os.Exit(0)
}

configFile = utils.HomeDirExpand(configFile)

flag.Visit(func(f *flag.Flag) {
log.Infof("args %#v : %s", f.Name, f.Value)
})
Expand Down
7 changes: 5 additions & 2 deletions cmd/cql-faucet/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (

"github.com/CovenantSQL/CovenantSQL/client"
"github.com/CovenantSQL/CovenantSQL/crypto/asymmetric"
"github.com/CovenantSQL/CovenantSQL/utils"
"github.com/CovenantSQL/CovenantSQL/utils/log"
"golang.org/x/sys/unix"
)
Expand All @@ -42,8 +43,8 @@ var (
)

func init() {
flag.StringVar(&configFile, "config", "config.yaml", "configuration file for covenantsql")
flag.StringVar(&password, "password", "", "master key password for covenantsql")
flag.StringVar(&configFile, "config", "~/.cql/config.yaml", "Configuration file for covenantsql")
flag.StringVar(&password, "password", "", "Master key password for covenantsql")
flag.BoolVar(&asymmetric.BypassSignature, "bypass-signature", false,
"Disable signature sign and verify, for testing")
flag.BoolVar(&showVersion, "version", false, "Show version information and exit")
Expand All @@ -57,6 +58,8 @@ func main() {
os.Exit(0)
}

configFile = utils.HomeDirExpand(configFile)

flag.Visit(func(f *flag.Flag) {
log.Infof("args %#v : %s", f.Name, f.Value)
})
Expand Down
Loading