Skip to content

Commit

Permalink
integration test done
Browse files Browse the repository at this point in the history
  • Loading branch information
tedyyan authored and ewagmig committed Oct 30, 2018
1 parent dce4de7 commit 84146cb
Show file tree
Hide file tree
Showing 9 changed files with 79 additions and 64 deletions.
Empty file removed baseapp/data/kvstore.db/000002.log
Empty file.
Binary file removed baseapp/data/kvstore.db/MANIFEST-000003
Binary file not shown.
3 changes: 1 addition & 2 deletions client/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,14 @@ import (
"github.com/QOSGroup/qbase/txs"
"github.com/QOSGroup/qstars/client/context"
"github.com/QOSGroup/qstars/wire"
"github.com/tendermint/tendermint/crypto/ed25519"
)

// SendTx implements a auxiliary handler that facilitates sending a series of
// messages in a signed transaction given a TxContext and a QueryContext. It
// ensures that the account exists, has a proper number and sequence set. In
// addition, it builds and signs a transaction with the supplied messages.
// Finally, it broadcasts the signed transaction to a node.
func SendTx(cliCtx context.CLIContext, cdc *wire.Codec, txStd *txs.TxStd, priv ed25519.PrivKeyEd25519) (string, error) {
func SendTx(cliCtx context.CLIContext, cdc *wire.Codec, txStd *txs.TxStd) (string, error) {

txBytes, err := cdc.MarshalBinaryBare(txStd)
if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions config/cliconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ type QStarsClientContext struct{

type CLIConfig struct {
QOSChainID string `mapstructure:"qos_chain_id"`
ChainID string `mapstructure:"chain_id"`
QSCChainID string `mapstructure:"chain_id"`
RootDir string `mapstructure:"home"`
QOSNodeURI string `mapstructure:"qos_node_uri"`
QSTARSNodeURI string `mapstructure:"qstars_node_uri"`
Expand Down Expand Up @@ -62,7 +62,7 @@ func InterceptLoadConfig() (conf *CLIConfig, err error) {
if _, err := os.Stat(configFilePath); os.IsNotExist(err) {
// the following parse config is needed to create directories
conf, _ = ParseConfig()
conf.ChainID = "abc"
conf.QSCChainID = "abc"
conf.QOSNodeURI = "localhost:1317"
conf.QSTARSNodeURI = "localhost:1317"
WriteConfigFile(configFilePath, conf)
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module github.com/QOSGroup/qstars

require (
github.com/BurntSushi/toml v0.3.1
github.com/QOSGroup/qbase v0.0.4
github.com/QOSGroup/qbase v0.0.5
github.com/bartekn/go-bip39 v0.0.0-20171116152956-a05967ea095d
github.com/bgentry/speakeasy v0.1.0
github.com/brejski/hid v0.0.0-20180408220029-06112dcfcc50 // indirect
Expand Down
4 changes: 3 additions & 1 deletion x/bank/bankstub.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
go_amino "github.com/tendermint/go-amino"
"github.com/QOSGroup/qbase/types"
"github.com/QOSGroup/qbase/context"
"github.com/QOSGroup/qbase/example/basecoin/tx"
)

type BankStub struct {
Expand All @@ -26,7 +27,8 @@ func (kv BankStub) StartX(base *baseapp.QstarsBaseApp) error{
}

func (kv BankStub) RegisterKVCdc(cdc *go_amino.Codec) {
cdc.RegisterConcrete(&SendTx{}, "basecoin/SendTx",nil)
cdc.RegisterConcrete(&tx.SendTx{}, "basecoin/SendTx",nil)
cdc.RegisterConcrete(&WrapperSendTx{}, "qstars/WrapperSendTx",nil)
cdc.RegisterConcrete(&bctypes.AppAccount{}, "basecoin/AppAccount", nil)
}

Expand Down
54 changes: 24 additions & 30 deletions x/bank/handler.go
Original file line number Diff line number Diff line change
@@ -1,34 +1,31 @@
package bank

import (
"bytes"
"fmt"
"github.com/QOSGroup/qbase/context"
"github.com/QOSGroup/qbase/txs"
btypes "github.com/QOSGroup/qbase/types"
"github.com/QOSGroup/qbase/context"
"github.com/tendermint/tendermint/types"
"strconv"
)

type SendTx struct {
From btypes.Address `json:"from"`
To btypes.Address `json:"to"`
Coin btypes.BaseCoin `json:"coin"`
type WrapperSendTx struct {
Wrapper *txs.TxStd
}

var _ txs.ITx = (*SendTx)(nil)
var _ txs.ITx = (*WrapperSendTx)(nil)

func NewSendTx(from btypes.Address, to btypes.Address, coin btypes.BaseCoin) SendTx {
return SendTx{From: from, To: to, Coin: coin}
func NewWrapperSendTx(wrapper *txs.TxStd) WrapperSendTx {
return WrapperSendTx{Wrapper: wrapper}
}

func (tx SendTx) ValidateData(ctx context.Context) bool {
if len(tx.From) == 0 || len(tx.To) == 0 || btypes.NewInt(0).GT(tx.Coin.Amount) {
return false
}
func (tx WrapperSendTx) ValidateData(ctx context.Context) bool {

return true
}


func (tx SendTx) Exec(ctx context.Context) (result btypes.Result, crossTxQcps *txs.TxQcp) {
func (tx WrapperSendTx) Exec(ctx context.Context) (result btypes.Result, crossTxQcps *txs.TxQcp) {
result = btypes.Result{
Code: btypes.ABCICodeOK,
}
Expand All @@ -40,36 +37,33 @@ func (tx SendTx) Exec(ctx context.Context) (result btypes.Result, crossTxQcps *t

}
crossTxQcps = &cross
tt := txs.TxStd{

}
heigth1 := strconv.FormatInt(ctx.BlockHeight(),10)
tx1 := (types.Tx (ctx.TxBytes())).String()

fmt.Println(" heigth: " + heigth1 + " hash:" + tx1)

tt.ITx = tx
crossTxQcps.TxStd = &tt
crossTxQcps.To = "basecoin-chain"
crossTxQcps.TxStd = tx.Wrapper
crossTxQcps.To = "main-chain"

r := btypes.Result{
Code:0,
}
return r, &cross
}

func (tx SendTx) GetSigner() []btypes.Address {
return []btypes.Address{tx.From}
func (tx WrapperSendTx) GetSigner() []btypes.Address {
return nil
}

func (tx SendTx) CalcGas() btypes.BigInt {
func (tx WrapperSendTx) CalcGas() btypes.BigInt {
return btypes.ZeroInt()
}

func (tx SendTx) GetGasPayer() btypes.Address {
return tx.From
func (tx WrapperSendTx) GetGasPayer() btypes.Address {
return nil
}

func (tx SendTx) GetSignData() []byte {
var buf bytes.Buffer
buf.Write(tx.From)
buf.Write(tx.To)
buf.Write([]byte(tx.Coin.String()))
return buf.Bytes()
func (tx WrapperSendTx) GetSignData() []byte {
return nil
}
74 changes: 47 additions & 27 deletions x/bank/process.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
package bank

import (
"github.com/QOSGroup/qbase/example/basecoin/tx"
"github.com/QOSGroup/qbase/account"
"github.com/QOSGroup/qbase/txs"
"github.com/QOSGroup/qstars/client/context"
Expand Down Expand Up @@ -53,26 +54,19 @@ func NewSendOptions(opts ...func(*SendOptions)) *SendOptions {
}

func Send(cdc *wire.Codec, fromstr string, to qbasetypes.Address, coins types.Coins, sopt *SendOptions) (*SendResult, error) {


_, addrben32, priv:= utility.PubAddrRetrieval(fromstr,cdc)



from, err := types.AccAddressFromBech32(addrben32)
key := account.AddressStoreKey(from)
if err != nil {
return nil, err
}
var chainID string

directTOQOS := config.GetCLIContext().Config.DirectTOQOS
var cliCtx context.CLIContext
if directTOQOS==true{
cliCtx = *config.GetCLIContext().QOSCliContext
chainID = config.GetCLIContext().Config.QOSChainID
}else {
cliCtx = *config.GetCLIContext().QSCCliContext
chainID = config.GetCLIContext().Config.ChainID
}

account, err := config.GetCLIContext().QOSCliContext.GetAccount(key,cdc)
Expand Down Expand Up @@ -101,24 +95,29 @@ func Send(cdc *wire.Codec, fromstr string, to qbasetypes.Address, coins types.Co
}

var nn int64
nn = int64(account.Nonce)
//if directTOQOS==true {
// nn = int64(account.Nonce)
//}else {
// qscaccount, err := config.GetCLIContext().QSCCliContext.GetAccount(key,cdc)
// if err != nil{
// if err.Error()=="Account is not exsit." {
// nn = int64(0)
// }else{
// return nil,err
// }
// }else{
// nn = int64(qscaccount.Nonce)
// }
//}
nn++
var msg *txs.TxStd
if directTOQOS==true {
nn = int64(account.Nonce)
}else {
qscaccount, err := config.GetCLIContext().QSCCliContext.GetAccount(key,cdc)
if err != nil{
if err.Error()=="Account is not exsit." {
nn = int64(0)
}else{
return nil,err
}
}else{
nn = int64(qscaccount.Nonce)
}
msg = genStdSendTx(cdc, from, to, cc, priv, nn)
}else{
msg = genStdWrapTx(cdc, from, to, cc, priv, nn)
}
nn++

msg := genStdSendTx(cdc,from,to,cc,priv,nn,chainID)
response, err := utils.SendTx(cliCtx, cdc,msg,priv)
response, err := utils.SendTx(cliCtx, cdc,msg)

result := &SendResult{}
result.Hash = response
Expand All @@ -127,10 +126,10 @@ func Send(cdc *wire.Codec, fromstr string, to qbasetypes.Address, coins types.Co
}

func genStdSendTx(cdc *amino.Codec, sender qbasetypes.Address, receiver qbasetypes.Address, coin qbasetypes.BaseCoin,
priKey ed25519.PrivKeyEd25519, nonce int64, chainid string) *txs.TxStd {
sendTx := NewSendTx(sender, receiver, coin)
priKey ed25519.PrivKeyEd25519, nonce int64) *txs.TxStd {
sendTx := tx.NewSendTx(sender, receiver, coin)
gas := qbasetypes.NewInt(int64(0))
tx := txs.NewTxStd(&sendTx, chainid, gas)
tx := txs.NewTxStd(&sendTx, config.GetCLIContext().Config.QOSChainID, gas)
//priHex, _ := hex.DecodeString(senderPriHex[2:])
//var priKey ed25519.PrivKeyEd25519
//cdc.MustUnmarshalBinaryBare(priHex, &priKey)
Expand All @@ -143,3 +142,24 @@ func genStdSendTx(cdc *amino.Codec, sender qbasetypes.Address, receiver qbasetyp

return tx
}

func genStdWrapTx(cdc *amino.Codec, sender qbasetypes.Address, receiver qbasetypes.Address, coin qbasetypes.BaseCoin,
priKey ed25519.PrivKeyEd25519, nonce int64 ) *txs.TxStd {
sendTx := tx.NewSendTx(sender, receiver, coin)
gas := qbasetypes.NewInt(int64(0))
tx := txs.NewTxStd(&sendTx, config.GetCLIContext().Config.QOSChainID, gas)
//priHex, _ := hex.DecodeString(senderPriHex[2:])
//var priKey ed25519.PrivKeyEd25519
//cdc.MustUnmarshalBinaryBare(priHex, &priKey)
signature, _ := tx.SignTx(priKey, nonce)
tx.Signature = []txs.Signature{txs.Signature{
Pubkey: priKey.PubKey(),
Signature: signature,
Nonce: nonce,
}}


tx2 := txs.NewTxStd(&sendTx, config.GetCLIContext().Config.QSCChainID, gas)
tx2.ITx = NewWrapperSendTx(tx)
return tx2
}
2 changes: 1 addition & 1 deletion x/kvstore/process.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ func SendKV(cdc *wire.Codec, privateKey, key, value string, option *SendKVOption

txStd := wrapToStdTx(key, value, option.chainID)

hash, err := utils.SendTx(cliCtx, cdc, txStd, priv)
hash, err := utils.SendTx(cliCtx, cdc, txStd)
if err != nil {
return nil, err
}
Expand Down

0 comments on commit 84146cb

Please sign in to comment.