Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Travis ci #27

Closed
wants to merge 4 commits into from
Closed
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
7 changes: 7 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
language: ruby

services:
- docker

script:
- docker-compose -f ./tests/integration/docker-compose.yml up --build --exit-code-from omnitest omnitest
25 changes: 23 additions & 2 deletions config/cfg.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package config
import (
"flag"
"log"
"net"
"strings"
"testing"
"time"

Expand All @@ -28,6 +30,15 @@ var (
BootstrapPeers addrList
)

func parseHostname(hostname string) string {
P2pHostIps, err := net.LookupIP(hostname)
if err != nil {
panic("Can't parse hostname")
}

return P2pHostIps[0].String()
}

func Init() {
testing.Init()
flag.Parse()
Expand Down Expand Up @@ -61,7 +72,8 @@ func Init() {
log.Println(err)
return
}
P2P_hostIp = p2pNode.Key("hostIp").String()

P2P_hostIp = parseHostname(p2pNode.Key("hostIp").String())
P2P_sourcePort = p2pNode.Key("sourcePort").MustInt()

//tracker
Expand All @@ -70,5 +82,14 @@ func Init() {
log.Println(err)
return
}
TrackerHost = tracker.Key("host").MustString("localhost:60060")

if len(tracker.Key("host").String()) == 0 {
panic("empty tracker host")
}

RawTrackerHost := tracker.Key("host").MustString("localhost:60060")
RawHostIP := strings.Split(RawTrackerHost, ":")
ParseHostname := parseHostname(RawHostIP[0])
TrackerHost = ParseHostname + ":" + RawHostIP[1]

}
6 changes: 3 additions & 3 deletions config/conf.ini
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ maxFee = 0.01
;Deprecated. OBD does not require a full node since Dec.2020.
;[chainNode]
;main,test,reg
;this is the omnicore node that obd connects.
;this is the omnicore node that obd connects.
;Omnicore in mainnet, testnet or regtest, then obd is in respective mode.
;host = 62.234.216.108:18332
;user = omniwallet
Expand All @@ -24,8 +24,8 @@ sourcePort = 4001

[tracker]
;Trackers offer such anomymous full node services: monitor node service quality, channel balances if the channel is not private, update routing table for connected nodes, broadcaste transactions, etc.
;
;Any one can be a tracker, but deploying a tracker requires synchronizing full node data from the network.
;
;Any one can be a tracker, but deploying a tracker requires synchronizing full node data from the network.
;We suggest you to connect the trackers we deployed for the public:
;https://omnilaboratory.github.io/obd/#/nodes-in-testnet
;
Expand Down
8 changes: 6 additions & 2 deletions conn/tracker_http.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package conn2tracker

import (
"bytes"
"errors"
"github.com/omnilaboratory/obd/config"
"github.com/omnilaboratory/obd/tool"
Expand Down Expand Up @@ -482,9 +483,12 @@ func OmniSendRevoke(fromAddress string, propertyId int64, amount float64, memo s
}

func BtcSignRawTransactionFromJson(data string) (result string, err error) {
url := "http://" + config.TrackerHost + "/api/rpc/btcSignRawTransactionFromJson?data=" + data
url := "http://" + config.TrackerHost + "/api/rpc/btcSignRawTransactionFromJson?data="
log.Println(url)
resp, err := http.Get(url)
client := &http.Client{}
req, _ := http.NewRequest("POST", url, bytes.NewBuffer([]byte(data)))
req.Header.Set("Content-type", "application/json")
resp, err := client.Do(req)
if err != nil {
return "", err
}
Expand Down
4 changes: 3 additions & 1 deletion tests/integration/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,6 @@ ENV OMNI_BOLT_ALICE=omnibolt_alice:60020
ENV OMNI_BOLT_BOB=omnibolt_bob:60020
ENV BITCOIN_CONF=/test/bitcoin.conf

ENTRYPOINT [ "python3.9", "-m", "pytest", "test.py" ]
COPY test_entrypoint.sh /test/test_entrypoint.sh

ENTRYPOINT [ "/test/test_entrypoint.sh" ]
1 change: 1 addition & 0 deletions tests/integration/bitcoin.conf
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ regtest=1
rpcuser=omniwallet
rpcpassword=omnipass123
rpcconnect=omnicore

[regtest]
rpcallowip=0.0.0.0/0
rpcbind=0.0.0.0
Expand Down
7 changes: 5 additions & 2 deletions tests/integration/conf.ini.alice
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ writeTimeout = 30
hostIp = omnibolt_alice
sourcePort = 4001

[htlc]
feeRate = 0.0001
maxFee = 0.01

[tracker]
hostIp = localhost
port = 60060
host = 127.0.0.1:60060
13 changes: 5 additions & 8 deletions tests/integration/conf.ini.bob
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,13 @@ port = 60020
readTimeout = 30
writeTimeout = 30

[chainNode]
netType = reg
host = omnicore:18444
user = omniwallet
pass = omnipass123

[p2p]
hostIp = omnibolt_bob
sourcePort = 4001

[htlc]
feeRate = 0.0001
maxFee = 0.01

[tracker]
hostIp = localhost
port = 60060
host = 127.0.0.1:60060
4 changes: 4 additions & 0 deletions tests/integration/conf.tracker.ini
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,7 @@ netType = reg
host = omnicore:18444
user = omniwallet
pass = omnipass123

[p2p]
localHostIp = 127.0.0.1
sourcePort = 60080
21 changes: 10 additions & 11 deletions tests/integration/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,38 +5,37 @@ services:
image:
johng12345/omnicore:latest
volumes:
- ${PWD}/bitcoin.conf:/root/bitcoin.conf
- ${PWD}/tests/integration/bitcoin.conf:/root/bitcoin.conf
expose:
- "18444"

omnibolt_alice:
volumes:
- ${PWD}/conf.ini.alice:/go/conf.ini
- ${PWD}/tests/integration/conf.ini.alice:/obd/conf.ini
build:
context: ./omnibolt
dockerfile: omnibolt.Dockerfile
context: ../..
dockerfile: ./tests/integration/omnibolt.Dockerfile
depends_on:
- omnicore
expose:
- 60061
expose:
- 4002
- 60021

omnibolt_bob:
volumes:
- ${PWD}/conf.ini.bob:/go/conf.ini
- ${PWD}/tests/integration/conf.ini.bob:/obd/conf.ini
build:
context: ./omnibolt
dockerfile: omnibolt.Dockerfile
context: ../..
dockerfile: ./tests/integration/omnibolt.Dockerfile

expose:
- 60060
- 4001
- 60020
depends_on:
- omnicore
omnitest:
build:
context: ./omnitest
context: .
dockerfile: Dockerfile
depends_on:
- omnibolt_bob
Expand Down
29 changes: 18 additions & 11 deletions tests/integration/omnibolt.Dockerfile
Original file line number Diff line number Diff line change
@@ -1,21 +1,28 @@
FROM golang:1.13-alpine as builder
RUN echo "ABBC"
ARG checkout="working-local-test"

WORKDIR /go
WORKDIR /obd

# Install dependencies and build the binaries.
RUN apk add --no-cache --update alpine-sdk \
git \
make \
gcc \
bash \
&& git clone https://github.com/johng/obd.git \
&& cd obd \
&& git checkout ${checkout}
bash


RUN cd obd && go build obdserver.go && go build tracker_server.go
COPY start.sh .
COPY conf.tracker.ini /go/conf.tracker.ini
ENTRYPOINT [ "./start.sh" ]
COPY bean /obd/bean
COPY config /obd/config
COPY conn /obd/conn
COPY dao /obd/dao
COPY lightclient /obd/lightclient
COPY omnicore /obd/omnicore
COPY service /obd/service
COPY tracker /obd/tracker
COPY tool /obd/tool
COPY obdserver.go /obd/obdserver.go
COPY go.mod /obd/go.mod

RUN go build /obd/obdserver.go && go build /obd/tracker/tracker_server.go
COPY tests/integration/start.sh /obd/start.sh
COPY tests/integration/conf.tracker.ini /obd/conf.tracker.ini
ENTRYPOINT [ "/obd/start.sh" ]
3 changes: 2 additions & 1 deletion tests/integration/omnicore_connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,9 @@ def _generate_omni_currency(self, funder_address):
omnicore-cli -regtest omni_listproperties

"""
is_divisible = 2
return self._bitcoin_connection.omni_sendissuancemanaged(
funder_address, 2, 1, 0, "Companies", "Bitcoin Mining", "Qunatum", "a", "a"
funder_address, 2, is_divisible, 0, "Companies", "Bitcoin Mining", "Qunatum", "a", "a"
)

def list_omnicore_properties(self):
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def setup_basic_workflow(self, channel_size: int) -> int:
omnicore_connection.mine_bitcoin(20, address_miner)

omnicore_connection.mine_bitcoin(20, address_miner)
grant_amount = 999999999999999
grant_amount = "100000.00000000"

omnicore_connection.omni_sendgrant(
address_master_funder,
Expand Down
7 changes: 5 additions & 2 deletions tests/integration/start.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
#!/bin/bash

cd /go/obd && ./tracker_server --trackerConfigPath "/go/conf.tracker.ini" &
# TODO: Replace with healthcheck
sleep 4

cd /obd && ./tracker_server --trackerConfigPath "/obd/conf.tracker.ini" &

sleep 1

cd /go/obd && ./obdserver --configPath "/go/conf.ini"
cd /obd && ./obdserver --configPath "/obd/conf.ini"
4 changes: 4 additions & 0 deletions tests/integration/test_entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/env bash

sleep 5
python3.9 -m pytest test.py
15 changes: 14 additions & 1 deletion tracker/config/cfg.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"flag"
ma "github.com/multiformats/go-multiaddr"
"log"
"net"
"strings"
"testing"
"time"
Expand Down Expand Up @@ -44,6 +45,15 @@ var (
ChainNode_Pass = "cB3]iL2@eZ1?cB2?"
)

func parseHostname(hostname string) string {
P2pHostIps, err := net.LookupIP(hostname)
if err != nil {
panic("Can't parse hostname")
}

return P2pHostIps[0].String()
}

func init() {
testing.Init()
flag.Parse()
Expand Down Expand Up @@ -90,7 +100,10 @@ func init() {
log.Println(err)
return
}
ChainNode_Host = chainNode.Key("host").String()

RawHostIP := strings.Split(chainNode.Key("host").String(), ":")
ParseHostname := parseHostname(RawHostIP[0])
ChainNode_Host = ParseHostname + ":" + RawHostIP[1]
ChainNode_User = chainNode.Key("user").String()
ChainNode_Pass = chainNode.Key("pass").String()
if len(ChainNode_Host) == 0 {
Expand Down
8 changes: 3 additions & 5 deletions tracker/config/conf.ini
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,10 @@ port = 60060
feeRate = 0.0001

[chainNode]
;main,test,reg
;this is the omnicore node that tracker connects.
;Omnicore in mainnet, testnet or regtest, then tracker is in respective mode.
host = 62.234.216.108:18332
netType = reg
host = localhost:18444
user = omniwallet
pass = cB3]iL2@eZ1?cB2?
pass = omnipass123

[p2p]
localHostIp = 127.0.0.1
Expand Down
2 changes: 1 addition & 1 deletion tracker/router/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ func InitRouter() *gin.Engine {
apiv3.GET("omniSendIssuanceManaged", service.RpcService.OmniSendIssuanceManaged)
apiv3.GET("omniSendGrant", service.RpcService.OmniSendGrant)
apiv3.GET("omniSendRevoke", service.RpcService.OmniSendRevoke)
apiv3.GET("btcSignRawTransactionFromJson", service.RpcService.BtcSignRawTransactionFromJson)
apiv3.POST("btcSignRawTransactionFromJson", service.RpcService.BtcSignRawTransactionFromJson)
apiv3.GET("getMiningInfo", service.RpcService.GetMiningInfo)
apiv3.GET("getNetworkInfo", service.RpcService.GetNetworkInfo)
}
Expand Down
9 changes: 1 addition & 8 deletions tracker/rpc/btcclient.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package rpc

import (
"encoding/json"
"errors"
"github.com/omnilaboratory/obd/bean"
"github.com/omnilaboratory/obd/tool"
Expand Down Expand Up @@ -156,13 +155,7 @@ type NeedSignData struct {
Inputs []map[string]interface{} `json:"inputs"`
}

func (client *Client) BtcSignRawTransactionFromJson(dataJson string) (signHex string, err error) {
inputData := &NeedSignData{}
err = json.Unmarshal([]byte(dataJson), inputData)
if err != nil {
return "", err
}

func (client *Client) BtcSignRawTransactionFromJson(inputData *NeedSignData) (signHex string, err error) {
signHexObj, err := client.SignRawTransactionWithKey(inputData.Hex, []string{inputData.Prvkey}, inputData.Inputs, "ALL")
if err != nil {
return "", err
Expand Down
Loading