Merge pull request #64 from meshplus/refactor/tester
refactor(tester): rm gosdk and use core api
This commit is contained in:
commit
1f8c8a29a6
|
@ -65,9 +65,6 @@ jobs:
|
|||
run: |
|
||||
export PATH=$PATH:$(go env GOPATH)/bin
|
||||
make prepare
|
||||
cd scripts
|
||||
bash integration.sh
|
||||
cd ..
|
||||
make tester
|
||||
|
||||
build:
|
||||
|
|
|
@ -1,186 +0,0 @@
|
|||
package client
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
|
||||
rpcx "github.com/meshplus/go-bitxhub-client"
|
||||
"github.com/urfave/cli"
|
||||
)
|
||||
|
||||
func appchainCMD() cli.Command {
|
||||
return cli.Command{
|
||||
Name: "appchain",
|
||||
Usage: "Command about appchain",
|
||||
Flags: []cli.Flag{
|
||||
cli.StringFlag{
|
||||
Name: "key",
|
||||
Usage: "Specific key.json path",
|
||||
Required: true,
|
||||
},
|
||||
},
|
||||
Subcommands: []cli.Command{
|
||||
{
|
||||
Name: "register",
|
||||
Usage: "Register appchain in bitxhub",
|
||||
Flags: []cli.Flag{
|
||||
cli.StringFlag{
|
||||
Name: "name",
|
||||
Usage: "Specific appchain name",
|
||||
Required: true,
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "type",
|
||||
Usage: "Specific appchain type",
|
||||
Required: true,
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "desc",
|
||||
Usage: "Specific appchain description",
|
||||
Required: true,
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "version",
|
||||
Usage: "Specific appchain version",
|
||||
Required: true,
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "validators",
|
||||
Usage: "Specific appchain validators path",
|
||||
Required: true,
|
||||
},
|
||||
},
|
||||
Action: registerAppchain,
|
||||
},
|
||||
{
|
||||
Name: "audit",
|
||||
Usage: "Audit appchain in bitxhub",
|
||||
Flags: []cli.Flag{
|
||||
cli.StringFlag{
|
||||
Name: "id",
|
||||
Usage: "Specific appchain id",
|
||||
Required: true,
|
||||
},
|
||||
},
|
||||
Action: auditAppchain,
|
||||
},
|
||||
{
|
||||
Name: "get",
|
||||
Usage: "Get appchain info",
|
||||
Flags: []cli.Flag{
|
||||
cli.StringFlag{
|
||||
Name: "id",
|
||||
Usage: "Specific appchain id",
|
||||
Required: true,
|
||||
},
|
||||
},
|
||||
Action: getAppchain,
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func registerAppchain(ctx *cli.Context) error {
|
||||
keyPath := ctx.GlobalString("key")
|
||||
grpcAddr := ctx.GlobalString("grpc")
|
||||
name := ctx.String("name")
|
||||
typ := ctx.String("type")
|
||||
desc := ctx.String("desc")
|
||||
version := ctx.String("version")
|
||||
validatorsPath := ctx.String("validators")
|
||||
|
||||
data, err := ioutil.ReadFile(validatorsPath)
|
||||
if err != nil {
|
||||
return fmt.Errorf("read validators file: %w", err)
|
||||
}
|
||||
|
||||
client, err := loadClient(keyPath, grpcAddr)
|
||||
if err != nil {
|
||||
return fmt.Errorf("load client: %w", err)
|
||||
}
|
||||
|
||||
receipt, err := client.InvokeBVMContract(
|
||||
rpcx.InterchainContractAddr,
|
||||
"Register", rpcx.String(string(data)),
|
||||
rpcx.Int32(1),
|
||||
rpcx.String(typ),
|
||||
rpcx.String(name),
|
||||
rpcx.String(desc),
|
||||
rpcx.String(version),
|
||||
)
|
||||
if err != nil {
|
||||
return fmt.Errorf("invoke bvm contract: %w", err)
|
||||
}
|
||||
|
||||
if !receipt.IsSuccess() {
|
||||
return fmt.Errorf("invoke register: %s", receipt.Ret)
|
||||
}
|
||||
|
||||
appchain := &rpcx.Appchain{}
|
||||
if err := json.Unmarshal(receipt.Ret, appchain); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
fmt.Printf("appchain register successfully, id is %s\n", appchain.ID)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func auditAppchain(ctx *cli.Context) error {
|
||||
keyPath := ctx.GlobalString("key")
|
||||
grpcAddr := ctx.GlobalString("grpc")
|
||||
id := ctx.String("id")
|
||||
|
||||
client, err := loadClient(keyPath, grpcAddr)
|
||||
if err != nil {
|
||||
return fmt.Errorf("load client: %w", err)
|
||||
}
|
||||
|
||||
receipt, err := client.InvokeBVMContract(
|
||||
rpcx.InterchainContractAddr,
|
||||
"Audit",
|
||||
rpcx.String(id),
|
||||
rpcx.Int32(1),
|
||||
rpcx.String("Audit passed"),
|
||||
)
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if !receipt.IsSuccess() {
|
||||
return fmt.Errorf("invoke audit: %s", receipt.Ret)
|
||||
}
|
||||
|
||||
fmt.Printf("audit appchain %s successfully\n", id)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func getAppchain(ctx *cli.Context) error {
|
||||
keyPath := ctx.GlobalString("key")
|
||||
grpcAddr := ctx.GlobalString("grpc")
|
||||
|
||||
client, err := loadClient(keyPath, grpcAddr)
|
||||
if err != nil {
|
||||
return fmt.Errorf("load client: %w", err)
|
||||
}
|
||||
|
||||
receipt, err := client.InvokeBVMContract(
|
||||
rpcx.InterchainContractAddr,
|
||||
"Appchain",
|
||||
)
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if !receipt.IsSuccess() {
|
||||
return fmt.Errorf("get appchain: %s", receipt.Ret)
|
||||
}
|
||||
|
||||
fmt.Println(string(receipt.Ret))
|
||||
|
||||
return nil
|
||||
}
|
|
@ -19,14 +19,11 @@ var clientCMD = cli.Command{
|
|||
},
|
||||
Subcommands: cli.Commands{
|
||||
accountCMD(),
|
||||
appchainCMD(),
|
||||
chainCMD(),
|
||||
blockCMD(),
|
||||
networkCMD(),
|
||||
receiptCMD(),
|
||||
ruleCMD(),
|
||||
txCMD(),
|
||||
interchainCMD(),
|
||||
validatorsCMD(),
|
||||
},
|
||||
}
|
||||
|
|
|
@ -1,23 +0,0 @@
|
|||
package client
|
||||
|
||||
import (
|
||||
"github.com/meshplus/bitxhub-kit/key"
|
||||
rpcx "github.com/meshplus/go-bitxhub-client"
|
||||
)
|
||||
|
||||
func loadClient(keyPath, grpcAddr string) (rpcx.Client, error) {
|
||||
key, err := key.LoadKey(keyPath)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
privateKey, err := key.GetPrivateKey("bitxhub")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return rpcx.New(
|
||||
rpcx.WithAddrs([]string{grpcAddr}),
|
||||
rpcx.WithPrivateKey(privateKey),
|
||||
)
|
||||
}
|
|
@ -1,71 +0,0 @@
|
|||
package client
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/meshplus/bitxhub-kit/types"
|
||||
|
||||
rpcx "github.com/meshplus/go-bitxhub-client"
|
||||
"github.com/urfave/cli"
|
||||
)
|
||||
|
||||
func interchainCMD() cli.Command {
|
||||
return cli.Command{
|
||||
Name: "interchain",
|
||||
Usage: "Query interchain info",
|
||||
Flags: []cli.Flag{
|
||||
cli.StringFlag{
|
||||
Name: "key",
|
||||
Usage: "Specific key.json path",
|
||||
Required: true,
|
||||
},
|
||||
},
|
||||
Subcommands: []cli.Command{
|
||||
{
|
||||
Name: "ibtp",
|
||||
Usage: "Query ibtp by id",
|
||||
Flags: []cli.Flag{
|
||||
cli.StringFlag{
|
||||
Name: "id",
|
||||
Usage: "Specific ibtp id",
|
||||
Required: true,
|
||||
},
|
||||
},
|
||||
Action: getIBTP,
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func getIBTP(ctx *cli.Context) error {
|
||||
keyPath := ctx.GlobalString("key")
|
||||
grpcAddr := ctx.GlobalString("grpc")
|
||||
id := ctx.String("id")
|
||||
|
||||
client, err := loadClient(keyPath, grpcAddr)
|
||||
if err != nil {
|
||||
return fmt.Errorf("laod client: %w", err)
|
||||
}
|
||||
|
||||
receipt, err := client.InvokeBVMContract(
|
||||
rpcx.InterchainContractAddr,
|
||||
"GetIBTPByID",
|
||||
rpcx.String(id),
|
||||
)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
hash := types.Bytes2Hash(receipt.Ret)
|
||||
|
||||
fmt.Printf("Tx hash: %s\n", hash.Hex())
|
||||
|
||||
response, err := client.GetTransaction(hash.Hex())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
fmt.Println(response)
|
||||
|
||||
return nil
|
||||
}
|
|
@ -1,81 +0,0 @@
|
|||
package client
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
|
||||
"github.com/tidwall/gjson"
|
||||
|
||||
"github.com/meshplus/bitxhub/internal/constant"
|
||||
rpcx "github.com/meshplus/go-bitxhub-client"
|
||||
"github.com/urfave/cli"
|
||||
)
|
||||
|
||||
func ruleCMD() cli.Command {
|
||||
return cli.Command{
|
||||
Name: "rule",
|
||||
Usage: "Command about rule",
|
||||
Flags: []cli.Flag{
|
||||
cli.StringFlag{
|
||||
Name: "key",
|
||||
Usage: "Specific key.json path",
|
||||
Required: true,
|
||||
},
|
||||
},
|
||||
Subcommands: cli.Commands{
|
||||
{
|
||||
Name: "deploy",
|
||||
Usage: "Deploy validation rule",
|
||||
Flags: []cli.Flag{
|
||||
cli.StringFlag{
|
||||
Name: "path",
|
||||
Usage: "Specific rule path",
|
||||
Required: true,
|
||||
},
|
||||
},
|
||||
Action: deployRule,
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func deployRule(ctx *cli.Context) error {
|
||||
keyPath := ctx.GlobalString("key")
|
||||
grpcAddr := ctx.GlobalString("grpc")
|
||||
rulePath := ctx.String("path")
|
||||
|
||||
contract, err := ioutil.ReadFile(rulePath)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
client, err := loadClient(keyPath, grpcAddr)
|
||||
if err != nil {
|
||||
return fmt.Errorf("load client: %w", err)
|
||||
}
|
||||
|
||||
data, err := ioutil.ReadFile(keyPath)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
address := gjson.Get(string(data), "address")
|
||||
|
||||
contractAddr, err := client.DeployContract(contract)
|
||||
if err != nil {
|
||||
return fmt.Errorf("deploy rule: %w", err)
|
||||
}
|
||||
|
||||
_, err = client.InvokeBVMContract(
|
||||
constant.RuleManagerContractAddr.Address(),
|
||||
"RegisterRule",
|
||||
rpcx.String(address.String()),
|
||||
rpcx.String(contractAddr.String()))
|
||||
if err != nil {
|
||||
return fmt.Errorf("register rule")
|
||||
}
|
||||
|
||||
fmt.Println("Deploy rule to bitxhub successfully")
|
||||
|
||||
return nil
|
||||
}
|
1
go.mod
1
go.mod
|
@ -22,7 +22,6 @@ require (
|
|||
github.com/meshplus/bitxhub-core v0.1.0-rc1.0.20200429064226-95effbd4b140
|
||||
github.com/meshplus/bitxhub-kit v1.0.1-0.20200429033154-8736253c8460
|
||||
github.com/meshplus/bitxhub-model v1.0.0-rc4.0.20200427024612-57b479c1d610
|
||||
github.com/meshplus/go-bitxhub-client v1.0.0-rc4.0.20200427032046-a06a72f3d286
|
||||
github.com/miekg/pkcs11 v1.0.3 // indirect
|
||||
github.com/mitchellh/go-homedir v1.1.0
|
||||
github.com/multiformats/go-multiaddr v0.2.0
|
||||
|
|
4
go.sum
4
go.sum
|
@ -499,16 +499,12 @@ github.com/meshplus/bitxhub-core v0.1.0-rc1.0.20200429064226-95effbd4b140 h1:AQo
|
|||
github.com/meshplus/bitxhub-core v0.1.0-rc1.0.20200429064226-95effbd4b140/go.mod h1:4T05X9Rk5Qr7zA5NkXvy/7GmUh4BkrOMDbuDShfZOFg=
|
||||
github.com/meshplus/bitxhub-kit v1.0.0-rc1 h1:gNi8IFU5CMHT3KE2I4ACj5alMW9h/4cV8xOxn7wSmtA=
|
||||
github.com/meshplus/bitxhub-kit v1.0.0-rc1/go.mod h1:ra/AhOkPvpElI+wXrB9G6DjdcrdxFU3vMwA5MYKr9D0=
|
||||
github.com/meshplus/bitxhub-kit v1.0.0 h1:+RHGTqW50CLZlEQAUm89fQHicYcjqkdYa+QMAktxGd4=
|
||||
github.com/meshplus/bitxhub-kit v1.0.0/go.mod h1:7cWyhXWZfrQ3+EaxkRoXfuiG3Y5R9DXYJomeZKkETW8=
|
||||
github.com/meshplus/bitxhub-kit v1.0.1-0.20200429033154-8736253c8460 h1:bL+s+LBhGr4g+28DNtqyj4WoVkYdZ5CPoGjdF6Ll0sk=
|
||||
github.com/meshplus/bitxhub-kit v1.0.1-0.20200429033154-8736253c8460/go.mod h1:7cWyhXWZfrQ3+EaxkRoXfuiG3Y5R9DXYJomeZKkETW8=
|
||||
github.com/meshplus/bitxhub-model v1.0.0-rc3 h1:oTyaDnhmMPKYifkV2Z5fH2OeY2RE7b6Bk6TzoOT9n4c=
|
||||
github.com/meshplus/bitxhub-model v1.0.0-rc3/go.mod h1:ZCctQIYTlE3vJ8Lhkrgs9bWwNA+Dw4JzojOSIzLVU6E=
|
||||
github.com/meshplus/bitxhub-model v1.0.0-rc4.0.20200427024612-57b479c1d610 h1:BOR7Kgllgx8rpJrqiG2NBU5cUn1ec9NoYozquXwLSLM=
|
||||
github.com/meshplus/bitxhub-model v1.0.0-rc4.0.20200427024612-57b479c1d610/go.mod h1:ZCctQIYTlE3vJ8Lhkrgs9bWwNA+Dw4JzojOSIzLVU6E=
|
||||
github.com/meshplus/go-bitxhub-client v1.0.0-rc4.0.20200427032046-a06a72f3d286 h1:ggQhaSdIpnvWEAlmbTZCk3AmwI25Uk8YzSSs9mTke1Q=
|
||||
github.com/meshplus/go-bitxhub-client v1.0.0-rc4.0.20200427032046-a06a72f3d286/go.mod h1:ASPLxiQekCTMEGkoej7Tm9VUzL8qhYZJcjfX+naPA+M=
|
||||
github.com/mgutz/ansi v0.0.0-20170206155736-9520e82c474b/go.mod h1:01TrycV0kFyexm33Z7vhZRXopbI8J3TDReVlkTgMUxE=
|
||||
github.com/miekg/dns v1.1.12/go.mod h1:W1PPwlIAgtquWBMBEV9nkV9Cazfe8ScdGz/Lj7v3Nrg=
|
||||
github.com/miekg/pkcs11 v1.0.3 h1:iMwmD7I5225wv84WxIG/bmxz9AXjWvTWIbM/TYHvWtw=
|
||||
|
|
|
@ -5,6 +5,8 @@ import (
|
|||
"fmt"
|
||||
"time"
|
||||
|
||||
"github.com/meshplus/bitxhub/pkg/order/etcdraft"
|
||||
|
||||
"github.com/meshplus/bitxhub/pkg/order"
|
||||
|
||||
"github.com/common-nighthawk/go-figure"
|
||||
|
@ -37,6 +39,56 @@ type BitXHub struct {
|
|||
|
||||
func NewBitXHub(rep *repo.Repo) (*BitXHub, error) {
|
||||
repoRoot := rep.Config.RepoRoot
|
||||
|
||||
bxh, err := generateBitXHubWithoutOrder(rep)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
chainMeta := bxh.Ledger.GetChainMeta()
|
||||
|
||||
m := make(map[uint64]types.Address)
|
||||
|
||||
if !rep.Config.Solo {
|
||||
for i, node := range rep.NetworkConfig.Nodes {
|
||||
m[node.ID] = types.String2Address(rep.Config.Genesis.Addresses[i])
|
||||
}
|
||||
}
|
||||
|
||||
order, err := orderplg.New(
|
||||
order.WithRepoRoot(repoRoot),
|
||||
order.WithStoragePath(repo.GetStoragePath(repoRoot, "order")),
|
||||
order.WithPluginPath(rep.Config.Plugin),
|
||||
order.WithNodes(m),
|
||||
order.WithID(rep.NetworkConfig.ID),
|
||||
order.WithPeerManager(bxh.PeerMgr),
|
||||
order.WithLogger(loggers.Logger(loggers.Order)),
|
||||
order.WithApplied(chainMeta.Height),
|
||||
order.WithDigest(chainMeta.BlockHash.Hex()),
|
||||
order.WithGetChainMetaFunc(bxh.Ledger.GetChainMeta),
|
||||
order.WithGetTransactionFunc(bxh.Ledger.GetTransaction),
|
||||
)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
r, err := router.New(loggers.Logger(loggers.Router), rep, bxh.Ledger, bxh.PeerMgr, order.Quorum())
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("create InterchainRouter: %w", err)
|
||||
}
|
||||
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
|
||||
bxh.ctx = ctx
|
||||
bxh.cancel = cancel
|
||||
bxh.Order = order
|
||||
bxh.Router = r
|
||||
|
||||
return bxh, nil
|
||||
}
|
||||
|
||||
func generateBitXHubWithoutOrder(rep *repo.Repo) (*BitXHub, error) {
|
||||
repoRoot := rep.Config.RepoRoot
|
||||
logger := loggers.Logger(loggers.App)
|
||||
|
||||
if err := storages.Initialize(repoRoot); err != nil {
|
||||
|
@ -67,13 +119,30 @@ func NewBitXHub(rep *repo.Repo) (*BitXHub, error) {
|
|||
return nil, fmt.Errorf("create BlockExecutor: %w", err)
|
||||
}
|
||||
|
||||
chainMeta := ldg.GetChainMeta()
|
||||
|
||||
peerMgr, err := peermgr.New(rep, loggers.Logger(loggers.P2P), ldg)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("create peer manager: %w", err)
|
||||
}
|
||||
|
||||
return &BitXHub{
|
||||
repo: rep,
|
||||
logger: logger,
|
||||
Ledger: ldg,
|
||||
Executor: exec,
|
||||
PeerMgr: peerMgr,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func NewTesterBitXHub(rep *repo.Repo) (*BitXHub, error) {
|
||||
repoRoot := rep.Config.RepoRoot
|
||||
|
||||
bxh, err := generateBitXHubWithoutOrder(rep)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
chainMeta := bxh.Ledger.GetChainMeta()
|
||||
|
||||
m := make(map[uint64]types.Address)
|
||||
|
||||
if !rep.Config.Solo {
|
||||
|
@ -81,42 +150,38 @@ func NewBitXHub(rep *repo.Repo) (*BitXHub, error) {
|
|||
m[node.ID] = types.String2Address(rep.Config.Genesis.Addresses[i])
|
||||
}
|
||||
}
|
||||
order, err := orderplg.New(
|
||||
|
||||
order, err := etcdraft.NewNode(
|
||||
order.WithRepoRoot(repoRoot),
|
||||
order.WithStoragePath(repo.GetStoragePath(repoRoot, "order")),
|
||||
order.WithPluginPath(rep.Config.Plugin),
|
||||
order.WithNodes(m),
|
||||
order.WithID(rep.NetworkConfig.ID),
|
||||
order.WithPeerManager(peerMgr),
|
||||
order.WithPrivKey(nil),
|
||||
order.WithPeerManager(bxh.PeerMgr),
|
||||
order.WithLogger(loggers.Logger(loggers.Order)),
|
||||
order.WithApplied(chainMeta.Height),
|
||||
order.WithDigest(chainMeta.BlockHash.Hex()),
|
||||
order.WithGetChainMetaFunc(ldg.GetChainMeta),
|
||||
order.WithGetTransactionFunc(ldg.GetTransaction),
|
||||
order.WithGetChainMetaFunc(bxh.Ledger.GetChainMeta),
|
||||
order.WithGetTransactionFunc(bxh.Ledger.GetTransaction),
|
||||
)
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
r, err := router.New(loggers.Logger(loggers.Router), rep, ldg, peerMgr, order.Quorum())
|
||||
r, err := router.New(loggers.Logger(loggers.Router), rep, bxh.Ledger, bxh.PeerMgr, order.Quorum())
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("create InterchainRouter: %w", err)
|
||||
}
|
||||
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
|
||||
return &BitXHub{
|
||||
repo: rep,
|
||||
logger: logger,
|
||||
Ledger: ldg,
|
||||
Executor: exec,
|
||||
Router: r,
|
||||
Order: order,
|
||||
PeerMgr: peerMgr,
|
||||
ctx: ctx,
|
||||
cancel: cancel,
|
||||
}, nil
|
||||
bxh.ctx = ctx
|
||||
bxh.cancel = cancel
|
||||
bxh.Order = order
|
||||
bxh.Router = r
|
||||
|
||||
return bxh, nil
|
||||
}
|
||||
|
||||
func (bxh *BitXHub) Start() error {
|
||||
|
|
|
@ -22,12 +22,12 @@ func New(opts ...order.Option) (order.Order, error) {
|
|||
|
||||
p, err := plugin.Open(pluginPath)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("plugin open error: %s", err)
|
||||
return nil, fmt.Errorf("plugin open: %s", err)
|
||||
}
|
||||
|
||||
m, err := p.Lookup("NewNode")
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("plugin lookup error: %s", err)
|
||||
return nil, fmt.Errorf("plugin lookup: %s", err)
|
||||
}
|
||||
|
||||
NewNode, ok := m.(func(...order.Option) (order.Order, error))
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
storage
|
|
@ -9,14 +9,14 @@ import (
|
|||
"github.com/meshplus/bitxhub-kit/crypto/asym"
|
||||
"github.com/meshplus/bitxhub-kit/types"
|
||||
"github.com/meshplus/bitxhub-model/pb"
|
||||
rpcx "github.com/meshplus/go-bitxhub-client"
|
||||
|
||||
"github.com/meshplus/bitxhub/internal/constant"
|
||||
"github.com/meshplus/bitxhub/internal/coreapi/api"
|
||||
"github.com/stretchr/testify/suite"
|
||||
)
|
||||
|
||||
type API struct {
|
||||
suite.Suite
|
||||
client rpcx.Client
|
||||
api api.CoreAPI
|
||||
privKey crypto.PrivateKey
|
||||
from types.Address
|
||||
}
|
||||
|
@ -25,16 +25,9 @@ func (suite *API) SetupSuite() {
|
|||
privKey, err := asym.GenerateKey(asym.ECDSASecp256r1)
|
||||
suite.Assert().Nil(err)
|
||||
|
||||
client, err := rpcx.New(
|
||||
rpcx.WithPrivateKey(privKey),
|
||||
rpcx.WithAddrs(grpcAddresses()),
|
||||
)
|
||||
suite.Assert().Nil(err)
|
||||
|
||||
from, err := privKey.PublicKey().Address()
|
||||
suite.Assert().Nil(err)
|
||||
|
||||
suite.client = client
|
||||
suite.privKey = privKey
|
||||
suite.from = from
|
||||
}
|
||||
|
@ -53,7 +46,7 @@ func (suite *API) TestSendTransaction() {
|
|||
|
||||
tx := &pb.Transaction{
|
||||
From: suite.from,
|
||||
To: rpcx.StoreContractAddr,
|
||||
To: constant.StoreContractAddr.Address(),
|
||||
Timestamp: time.Now().UnixNano(),
|
||||
Data: &pb.TransactionData{
|
||||
Type: pb.TransactionData_INVOKE,
|
||||
|
@ -64,62 +57,11 @@ func (suite *API) TestSendTransaction() {
|
|||
}
|
||||
err = tx.Sign(suite.privKey)
|
||||
suite.Nil(err)
|
||||
hash, err := suite.client.SendTransaction(tx)
|
||||
|
||||
tx.TransactionHash = tx.Hash()
|
||||
|
||||
err = suite.api.Broker().HandleTransaction(tx)
|
||||
suite.Nil(err)
|
||||
suite.NotEmpty(hash)
|
||||
}
|
||||
|
||||
func (suite *API) TestSendWrongTransaction() {
|
||||
tx := &pb.Transaction{
|
||||
To: suite.from,
|
||||
TransactionHash: types.Hash{},
|
||||
Nonce: rand.Int63(),
|
||||
}
|
||||
|
||||
_, err := suite.client.SendTransaction(tx)
|
||||
suite.Require().NotNil(err)
|
||||
suite.Contains(err.Error(), "tx data can't be empty")
|
||||
|
||||
tx.Data = &pb.TransactionData{}
|
||||
_, err = suite.client.SendTransaction(tx)
|
||||
suite.Require().NotNil(err)
|
||||
suite.Contains(err.Error(), "amount can't be 0 in transfer tx")
|
||||
|
||||
tx.Data = &pb.TransactionData{Amount: 10}
|
||||
_, err = suite.client.SendTransaction(tx)
|
||||
suite.Require().NotNil(err)
|
||||
suite.Contains(err.Error(), "from can't be empty")
|
||||
|
||||
tx.From = suite.from
|
||||
_, err = suite.client.SendTransaction(tx)
|
||||
suite.Require().NotNil(err)
|
||||
suite.Contains(err.Error(), "from can`t be the same as to")
|
||||
|
||||
tx.To = rpcx.StoreContractAddr
|
||||
_, err = suite.client.SendTransaction(tx)
|
||||
suite.Require().NotNil(err)
|
||||
suite.Contains(err.Error(), "timestamp is illegal")
|
||||
|
||||
tx.Nonce = -100
|
||||
tx.Timestamp = time.Now().UnixNano()
|
||||
_, err = suite.client.SendTransaction(tx)
|
||||
suite.Require().NotNil(err)
|
||||
suite.Contains(err.Error(), "nonce is illegal")
|
||||
|
||||
tx.Nonce = rand.Int63()
|
||||
|
||||
_, err = suite.client.SendTransaction(tx)
|
||||
suite.Require().NotNil(err)
|
||||
suite.Contains(err.Error(), "signature can't be empty")
|
||||
|
||||
err = tx.Sign(suite.privKey)
|
||||
suite.Require().Nil(err)
|
||||
hash, err := suite.client.SendTransaction(tx)
|
||||
suite.Require().Nil(err)
|
||||
suite.Assert().NotEmpty(hash)
|
||||
}
|
||||
|
||||
func (suite *API) TestGetBlockByHash() {
|
||||
}
|
||||
|
||||
func TestAPI(t *testing.T) {
|
||||
|
|
|
@ -6,103 +6,107 @@ import (
|
|||
|
||||
"github.com/meshplus/bitxhub-kit/crypto"
|
||||
"github.com/meshplus/bitxhub-kit/crypto/asym/ecdsa"
|
||||
"github.com/meshplus/bitxhub-kit/types"
|
||||
"github.com/meshplus/bitxhub-model/pb"
|
||||
rpcx "github.com/meshplus/go-bitxhub-client"
|
||||
"github.com/meshplus/bitxhub/internal/constant"
|
||||
"github.com/meshplus/bitxhub/internal/coreapi/api"
|
||||
"github.com/stretchr/testify/suite"
|
||||
"github.com/tidwall/gjson"
|
||||
)
|
||||
|
||||
type RegisterAppchain struct {
|
||||
suite.Suite
|
||||
api api.CoreAPI
|
||||
privKey crypto.PrivateKey
|
||||
pubKey crypto.PublicKey
|
||||
client rpcx.Client
|
||||
from types.Address
|
||||
}
|
||||
|
||||
func (suite *RegisterAppchain) SetupSuite() {
|
||||
var err error
|
||||
suite.privKey, err = ecdsa.GenerateKey(ecdsa.Secp256r1)
|
||||
suite.Assert().Nil(err)
|
||||
suite.Require().Nil(err)
|
||||
|
||||
suite.pubKey = suite.privKey.PublicKey()
|
||||
|
||||
suite.client, err = rpcx.New(
|
||||
rpcx.WithPrivateKey(suite.privKey),
|
||||
rpcx.WithAddrs(grpcAddresses()),
|
||||
)
|
||||
suite.Assert().Nil(err)
|
||||
suite.from, err = suite.privKey.PublicKey().Address()
|
||||
suite.Require().Nil(err)
|
||||
}
|
||||
|
||||
// Appchain registers in bitxhub
|
||||
func (suite *RegisterAppchain) TestRegisterAppchain() {
|
||||
suite.client.SetPrivateKey(suite.privKey)
|
||||
pubKey, err := suite.pubKey.Bytes()
|
||||
suite.Assert().Nil(err)
|
||||
pub, err := suite.privKey.PublicKey().Bytes()
|
||||
suite.Require().Nil(err)
|
||||
|
||||
args := []*pb.Arg{
|
||||
rpcx.String(""),
|
||||
rpcx.Int32(0),
|
||||
rpcx.String("hyperchain"),
|
||||
rpcx.String("税务链"),
|
||||
rpcx.String("趣链税务链"),
|
||||
rpcx.String("1.8"),
|
||||
rpcx.String(string(pubKey)),
|
||||
pb.String(""),
|
||||
pb.Int32(0),
|
||||
pb.String("hyperchain"),
|
||||
pb.String("税务链"),
|
||||
pb.String("趣链税务链"),
|
||||
pb.String("1.8"),
|
||||
pb.String(string(pub)),
|
||||
}
|
||||
ret, err := suite.client.InvokeBVMContract(rpcx.InterchainContractAddr, "Register", args...)
|
||||
suite.Assert().Nil(err)
|
||||
suite.Assert().Equal("hyperchain", gjson.Get(string(ret.Ret), "chain_type").String())
|
||||
|
||||
ret, err := invokeBVMContract(suite.api, suite.privKey, constant.InterchainContractAddr.Address(), "Register", args...)
|
||||
suite.Require().Nil(err)
|
||||
suite.Require().True(ret.IsSuccess(), string(ret.Ret))
|
||||
suite.Require().Equal("hyperchain", gjson.Get(string(ret.Ret), "chain_type").String())
|
||||
}
|
||||
|
||||
func (suite *RegisterAppchain) TestFetchAppchains() {
|
||||
k1, err := ecdsa.GenerateKey(ecdsa.Secp256r1)
|
||||
suite.Assert().Nil(err)
|
||||
suite.Require().Nil(err)
|
||||
k2, err := ecdsa.GenerateKey(ecdsa.Secp256r1)
|
||||
suite.Assert().Nil(err)
|
||||
suite.Require().Nil(err)
|
||||
|
||||
pub1, err := k1.PublicKey().Bytes()
|
||||
suite.Require().Nil(err)
|
||||
pub2, err := k2.PublicKey().Bytes()
|
||||
suite.Require().Nil(err)
|
||||
|
||||
suite.client.SetPrivateKey(k1)
|
||||
pk1, err := k1.PublicKey().Bytes()
|
||||
suite.Assert().Nil(err)
|
||||
args := []*pb.Arg{
|
||||
rpcx.String(""),
|
||||
rpcx.Int32(0),
|
||||
rpcx.String("hyperchain"),
|
||||
rpcx.String("税务链"),
|
||||
rpcx.String("趣链税务链"),
|
||||
rpcx.String("1.8"),
|
||||
rpcx.String(string(pk1)),
|
||||
pb.String(""),
|
||||
pb.Int32(0),
|
||||
pb.String("hyperchain"),
|
||||
pb.String("税务链"),
|
||||
pb.String("趣链税务链"),
|
||||
pb.String("1.8"),
|
||||
pb.String(string(pub1)),
|
||||
}
|
||||
_, err = suite.client.InvokeBVMContract(rpcx.InterchainContractAddr, "Register", args...)
|
||||
suite.Assert().Nil(err)
|
||||
ret, err := invokeBVMContract(suite.api, k1, constant.InterchainContractAddr.Address(), "Register", args...)
|
||||
suite.Require().Nil(err)
|
||||
suite.Require().True(ret.IsSuccess(), string(ret.Ret))
|
||||
|
||||
suite.client.SetPrivateKey(k2)
|
||||
pk2, err := k2.PublicKey().Bytes()
|
||||
suite.Assert().Nil(err)
|
||||
args = []*pb.Arg{
|
||||
rpcx.String(""),
|
||||
rpcx.Int32(0),
|
||||
rpcx.String("fabric"),
|
||||
rpcx.String("政务链"),
|
||||
rpcx.String("fabric政务"),
|
||||
rpcx.String("1.4"),
|
||||
rpcx.String(string(pk2)),
|
||||
pb.String(""),
|
||||
pb.Int32(0),
|
||||
pb.String("fabric"),
|
||||
pb.String("政务链"),
|
||||
pb.String("fabric政务"),
|
||||
pb.String("1.4"),
|
||||
pb.String(string(pub2)),
|
||||
}
|
||||
_, err = suite.client.InvokeBVMContract(rpcx.InterchainContractAddr, "Register", args...)
|
||||
|
||||
suite.Assert().Nil(err)
|
||||
receipt, err := suite.client.InvokeBVMContract(rpcx.InterchainContractAddr, "Appchains")
|
||||
suite.Assert().Nil(err)
|
||||
ret, err = invokeBVMContract(suite.api, k2, constant.InterchainContractAddr.Address(), "Register", args...)
|
||||
suite.Require().True(ret.IsSuccess(), string(ret.Ret))
|
||||
suite.Require().Nil(err)
|
||||
|
||||
rec, err := suite.client.InvokeBVMContract(rpcx.InterchainContractAddr, "CountAppchains")
|
||||
suite.Assert().Nil(err)
|
||||
ret, err = invokeBVMContract(suite.api, k2, constant.InterchainContractAddr.Address(), "Appchains")
|
||||
suite.Require().Nil(err)
|
||||
suite.Require().True(ret.IsSuccess())
|
||||
|
||||
rec, err := invokeBVMContract(suite.api, k2, constant.InterchainContractAddr.Address(), "CountAppchains")
|
||||
suite.Require().Nil(err)
|
||||
suite.Require().True(ret.IsSuccess())
|
||||
num, err := strconv.Atoi(string(rec.Ret))
|
||||
suite.Assert().Nil(err)
|
||||
result := gjson.Parse(string(receipt.Ret))
|
||||
suite.Assert().EqualValues(num, len(result.Array()))
|
||||
suite.Require().Nil(err)
|
||||
result := gjson.Parse(string(ret.Ret))
|
||||
suite.Require().GreaterOrEqual(num, len(result.Array()))
|
||||
|
||||
r, err := suite.client.InvokeBVMContract(rpcx.InterchainContractAddr, "CountApprovedAppchains")
|
||||
suite.Assert().Nil(err)
|
||||
num, err = strconv.Atoi(string(r.Ret))
|
||||
suite.Assert().Nil(err)
|
||||
suite.Assert().EqualValues(0, num)
|
||||
ret, err = invokeBVMContract(suite.api, k2, constant.InterchainContractAddr.Address(), "CountApprovedAppchains")
|
||||
suite.Require().Nil(err)
|
||||
suite.Require().True(ret.IsSuccess())
|
||||
num, err = strconv.Atoi(string(ret.Ret))
|
||||
suite.Require().Nil(err)
|
||||
suite.Require().EqualValues(0, num)
|
||||
}
|
||||
|
||||
func TestRegisterAppchain(t *testing.T) {
|
||||
|
|
|
@ -5,16 +5,16 @@ import (
|
|||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/meshplus/bitxhub/internal/constant"
|
||||
|
||||
"github.com/meshplus/bitxhub-kit/crypto/asym/ecdsa"
|
||||
"github.com/meshplus/bitxhub-model/pb"
|
||||
rpcx "github.com/meshplus/go-bitxhub-client"
|
||||
"github.com/meshplus/bitxhub/internal/constant"
|
||||
"github.com/meshplus/bitxhub/internal/coreapi/api"
|
||||
"github.com/stretchr/testify/suite"
|
||||
)
|
||||
|
||||
type Interchain struct {
|
||||
suite.Suite
|
||||
api api.CoreAPI
|
||||
}
|
||||
|
||||
func (suite *Interchain) SetupSuite() {
|
||||
|
@ -22,156 +22,137 @@ func (suite *Interchain) SetupSuite() {
|
|||
|
||||
func (suite *Interchain) TestHandleIBTP() {
|
||||
k1, err := ecdsa.GenerateKey(ecdsa.Secp256r1)
|
||||
suite.Assert().Nil(err)
|
||||
suite.Require().Nil(err)
|
||||
k2, err := ecdsa.GenerateKey(ecdsa.Secp256r1)
|
||||
suite.Assert().Nil(err)
|
||||
suite.Require().Nil(err)
|
||||
f, err := k1.PublicKey().Address()
|
||||
suite.Require().Nil(err)
|
||||
t, err := k2.PublicKey().Address()
|
||||
suite.Require().Nil(err)
|
||||
|
||||
c1, err := rpcx.New(
|
||||
rpcx.WithPrivateKey(k1),
|
||||
rpcx.WithAddrs([]string{
|
||||
"localhost:60011",
|
||||
"localhost:60012",
|
||||
"localhost:60013",
|
||||
"localhost:60014",
|
||||
}),
|
||||
)
|
||||
suite.Assert().Nil(err)
|
||||
pub1, err := k1.PublicKey().Bytes()
|
||||
suite.Require().Nil(err)
|
||||
pub2, err := k2.PublicKey().Bytes()
|
||||
suite.Require().Nil(err)
|
||||
|
||||
c2, err := rpcx.New(
|
||||
rpcx.WithPrivateKey(k2),
|
||||
rpcx.WithAddrs([]string{
|
||||
"localhost:60011",
|
||||
"localhost:60012",
|
||||
"localhost:60013",
|
||||
"localhost:60014",
|
||||
}),
|
||||
ret, err := invokeBVMContract(suite.api, k1, constant.InterchainContractAddr.Address(), "Register",
|
||||
pb.String(""),
|
||||
pb.Int32(0),
|
||||
pb.String("hyperchain"),
|
||||
pb.String("婚姻链"),
|
||||
pb.String("趣链婚姻链"),
|
||||
pb.String("1.8"),
|
||||
pb.String(string(pub1)),
|
||||
)
|
||||
suite.Assert().Nil(err)
|
||||
suite.Require().Nil(err)
|
||||
suite.Require().True(ret.IsSuccess(), string(ret.Ret))
|
||||
|
||||
pk1, err := k1.PublicKey().Bytes()
|
||||
suite.Assert().Nil(err)
|
||||
_, err = c1.InvokeBVMContract(constant.InterchainContractAddr.Address(), "Register",
|
||||
rpcx.String(""),
|
||||
rpcx.Int32(0),
|
||||
rpcx.String("hyperchain"),
|
||||
rpcx.String("婚姻链"),
|
||||
rpcx.String("趣链婚姻链"),
|
||||
rpcx.String("1.8"),
|
||||
rpcx.String(string(pk1)),
|
||||
ret, err = invokeBVMContract(suite.api, k2, constant.InterchainContractAddr.Address(), "Register",
|
||||
pb.String(""),
|
||||
pb.Int32(0),
|
||||
pb.String("fabric"),
|
||||
pb.String("税务链"),
|
||||
pb.String("fabric婚姻链"),
|
||||
pb.String("1.4"),
|
||||
pb.String(string(pub2)),
|
||||
)
|
||||
suite.Assert().Nil(err)
|
||||
pk2, err := k2.PublicKey().Bytes()
|
||||
suite.Assert().Nil(err)
|
||||
_, err = c2.InvokeBVMContract(constant.InterchainContractAddr.Address(), "Register",
|
||||
rpcx.String(""),
|
||||
rpcx.Int32(0),
|
||||
rpcx.String("fabric"),
|
||||
rpcx.String("税务链"),
|
||||
rpcx.String("fabric婚姻链"),
|
||||
rpcx.String("1.4"),
|
||||
rpcx.String(string(pk2)),
|
||||
)
|
||||
suite.Assert().Nil(err)
|
||||
suite.Require().Nil(err)
|
||||
suite.Require().True(ret.IsSuccess())
|
||||
|
||||
// deploy rule
|
||||
bytes, err := ioutil.ReadFile("./test_data/hpc_rule.wasm")
|
||||
suite.Require().Nil(err)
|
||||
addr, err := deployContract(suite.api, k1, bytes)
|
||||
suite.Require().Nil(err)
|
||||
|
||||
// register rule
|
||||
_, err = c1.InvokeBVMContract(constant.RuleManagerContractAddr.Address(), "RegisterRule", rpcx.String(f.Hex()), rpcx.String(""))
|
||||
suite.Assert().Nil(err)
|
||||
ret, err = invokeBVMContract(suite.api, k1, constant.RuleManagerContractAddr.Address(), "RegisterRule", pb.String(f.Hex()), pb.String(addr.Hex()))
|
||||
suite.Require().Nil(err)
|
||||
suite.Require().True(ret.IsSuccess())
|
||||
|
||||
ib := &pb.IBTP{From: f.Hex(), To: t.Hex(), Index: 1, Timestamp: time.Now().UnixNano()}
|
||||
data, err := ib.Marshal()
|
||||
suite.Require().Nil(err)
|
||||
_, err = c1.InvokeBVMContract(rpcx.InterchainContractAddr, "HandleIBTP", rpcx.Bytes(data))
|
||||
|
||||
ret, err = invokeBVMContract(suite.api, k1, constant.InterchainContractAddr.Address(), "HandleIBTP", pb.Bytes(data))
|
||||
suite.Require().Nil(err)
|
||||
suite.Require().True(ret.IsSuccess(), string(ret.Ret))
|
||||
}
|
||||
|
||||
func (suite *Interchain) TestGetIBTPByID() {
|
||||
k1, err := ecdsa.GenerateKey(ecdsa.Secp256r1)
|
||||
suite.Assert().Nil(err)
|
||||
suite.Require().Nil(err)
|
||||
k2, err := ecdsa.GenerateKey(ecdsa.Secp256r1)
|
||||
suite.Assert().Nil(err)
|
||||
suite.Require().Nil(err)
|
||||
f, err := k1.PublicKey().Address()
|
||||
suite.Require().Nil(err)
|
||||
t, err := k2.PublicKey().Address()
|
||||
suite.Require().Nil(err)
|
||||
|
||||
c1, err := rpcx.New(
|
||||
rpcx.WithPrivateKey(k1),
|
||||
rpcx.WithAddrs([]string{
|
||||
"localhost:60011",
|
||||
}),
|
||||
)
|
||||
suite.Assert().Nil(err)
|
||||
|
||||
c2, err := rpcx.New(
|
||||
rpcx.WithPrivateKey(k2),
|
||||
rpcx.WithAddrs([]string{
|
||||
"localhost:60011",
|
||||
}),
|
||||
)
|
||||
suite.Assert().Nil(err)
|
||||
pub1, err := k1.PublicKey().Bytes()
|
||||
suite.Require().Nil(err)
|
||||
pub2, err := k2.PublicKey().Bytes()
|
||||
suite.Require().Nil(err)
|
||||
|
||||
confByte, err := ioutil.ReadFile("./test_data/validator")
|
||||
suite.Assert().Nil(err)
|
||||
pk1, err := k1.PublicKey().Bytes()
|
||||
suite.Assert().Nil(err)
|
||||
_, err = c1.InvokeBVMContract(rpcx.InterchainContractAddr, "Register",
|
||||
rpcx.String(string(confByte)),
|
||||
rpcx.Int32(0),
|
||||
rpcx.String("hyperchain"),
|
||||
rpcx.String("婚姻链"),
|
||||
rpcx.String("趣链婚姻链"),
|
||||
rpcx.String("1.8"),
|
||||
rpcx.String(string(pk1)),
|
||||
suite.Require().Nil(err)
|
||||
|
||||
ret, err := invokeBVMContract(suite.api, k1, constant.InterchainContractAddr.Address(), "Register",
|
||||
pb.String(string(confByte)),
|
||||
pb.Int32(0),
|
||||
pb.String("hyperchain"),
|
||||
pb.String("婚姻链"),
|
||||
pb.String("趣链婚姻链"),
|
||||
pb.String("1.8"),
|
||||
pb.String(string(pub1)),
|
||||
)
|
||||
suite.Assert().Nil(err)
|
||||
pk2, err := k2.PublicKey().Bytes()
|
||||
suite.Assert().Nil(err)
|
||||
_, err = c2.InvokeBVMContract(rpcx.InterchainContractAddr, "Register",
|
||||
rpcx.String(""),
|
||||
rpcx.Int32(0),
|
||||
rpcx.String("fabric"),
|
||||
rpcx.String("税务链"),
|
||||
rpcx.String("fabric税务链"),
|
||||
rpcx.String("1.8"),
|
||||
rpcx.String(string(pk2)),
|
||||
suite.Require().Nil(err)
|
||||
suite.Require().True(ret.IsSuccess(), string(ret.Ret))
|
||||
|
||||
ret, err = invokeBVMContract(suite.api, k2, constant.InterchainContractAddr.Address(), "Register",
|
||||
pb.String(""),
|
||||
pb.Int32(0),
|
||||
pb.String("fabric"),
|
||||
pb.String("税务链"),
|
||||
pb.String("fabric税务链"),
|
||||
pb.String("1.8"),
|
||||
pb.String(string(pub2)),
|
||||
)
|
||||
suite.Assert().Nil(err)
|
||||
suite.Require().Nil(err)
|
||||
suite.Require().True(ret.IsSuccess(), string(ret.Ret))
|
||||
|
||||
contractByte, err := ioutil.ReadFile("./test_data/fabric_policy.wasm")
|
||||
suite.Assert().Nil(err)
|
||||
addr, err := c1.DeployContract(contractByte)
|
||||
suite.Assert().Nil(err)
|
||||
suite.Require().Nil(err)
|
||||
addr, err := deployContract(suite.api, k1, contractByte)
|
||||
suite.Require().Nil(err)
|
||||
|
||||
// register rule
|
||||
_, err = c1.InvokeBVMContract(constant.RuleManagerContractAddr.Address(), "RegisterRule", rpcx.String(f.Hex()), rpcx.String(addr.Hex()))
|
||||
suite.Assert().Nil(err)
|
||||
_, err = invokeBVMContract(suite.api, k1, constant.RuleManagerContractAddr.Address(), "RegisterRule", pb.String(f.Hex()), pb.String(addr.Hex()))
|
||||
suite.Require().Nil(err)
|
||||
|
||||
proof, err := ioutil.ReadFile("./test_data/proof")
|
||||
suite.Assert().Nil(err)
|
||||
suite.Require().Nil(err)
|
||||
ib := &pb.IBTP{From: f.Hex(), To: t.Hex(), Index: 1, Payload: []byte("111"), Timestamp: time.Now().UnixNano(), Proof: proof}
|
||||
data, err := ib.Marshal()
|
||||
suite.Assert().Nil(err)
|
||||
_, err = c1.InvokeBVMContract(rpcx.InterchainContractAddr, "HandleIBTP", rpcx.Bytes(data))
|
||||
suite.Assert().Nil(err)
|
||||
suite.Require().Nil(err)
|
||||
_, err = invokeBVMContract(suite.api, k1, constant.InterchainContractAddr.Address(), "HandleIBTP", pb.Bytes(data))
|
||||
suite.Require().Nil(err)
|
||||
|
||||
ib.Index = 2
|
||||
data, err = ib.Marshal()
|
||||
suite.Assert().Nil(err)
|
||||
receipt, err := c1.InvokeBVMContract(rpcx.InterchainContractAddr, "HandleIBTP", rpcx.Bytes(data))
|
||||
suite.Assert().Nil(err)
|
||||
suite.Assert().EqualValues(true, receipt.IsSuccess(), string(receipt.Ret))
|
||||
suite.Require().Nil(err)
|
||||
receipt, err := invokeBVMContract(suite.api, k1, constant.InterchainContractAddr.Address(), "HandleIBTP", pb.Bytes(data))
|
||||
suite.Require().Nil(err)
|
||||
suite.Require().EqualValues(true, receipt.IsSuccess(), string(receipt.Ret))
|
||||
|
||||
ib.Index = 3
|
||||
data, err = ib.Marshal()
|
||||
suite.Assert().Nil(err)
|
||||
_, err = c1.InvokeBVMContract(rpcx.InterchainContractAddr, "HandleIBTP", rpcx.Bytes(data))
|
||||
_, err = invokeBVMContract(suite.api, k1, constant.InterchainContractAddr.Address(), "HandleIBTP", pb.Bytes(data))
|
||||
suite.Assert().Nil(err)
|
||||
|
||||
ib.Index = 2
|
||||
ret, err := c1.InvokeBVMContract(rpcx.InterchainContractAddr, "GetIBTPByID", rpcx.String(ib.ID()))
|
||||
ret, err = invokeBVMContract(suite.api, k1, constant.InterchainContractAddr.Address(), "GetIBTPByID", pb.String(ib.ID()))
|
||||
suite.Assert().Nil(err)
|
||||
suite.Assert().Equal(true, ret.IsSuccess(), string(ret.Ret))
|
||||
}
|
||||
|
@ -180,21 +161,10 @@ func (suite *Interchain) TestAudit() {
|
|||
k, err := ecdsa.GenerateKey(ecdsa.Secp256r1)
|
||||
suite.Require().Nil(err)
|
||||
|
||||
c, err := rpcx.New(
|
||||
rpcx.WithPrivateKey(k),
|
||||
rpcx.WithAddrs([]string{
|
||||
"localhost:60011",
|
||||
"localhost:60012",
|
||||
"localhost:60013",
|
||||
"localhost:60014",
|
||||
}),
|
||||
)
|
||||
suite.Require().Nil(err)
|
||||
|
||||
ret, err := c.InvokeBVMContract(rpcx.InterchainContractAddr, "Audit",
|
||||
rpcx.String("0x123"),
|
||||
rpcx.Int32(1),
|
||||
rpcx.String("通过"),
|
||||
ret, err := invokeBVMContract(suite.api, k, constant.InterchainContractAddr.Address(), "Audit",
|
||||
pb.String("0x123"),
|
||||
pb.Int32(1),
|
||||
pb.String("通过"),
|
||||
)
|
||||
suite.Require().Nil(err)
|
||||
suite.Contains(string(ret.Ret), "caller is not an admin account")
|
||||
|
|
|
@ -3,20 +3,20 @@ package tester
|
|||
import (
|
||||
"strconv"
|
||||
|
||||
"github.com/meshplus/bitxhub/internal/constant"
|
||||
|
||||
"github.com/meshplus/bitxhub-kit/crypto"
|
||||
"github.com/meshplus/bitxhub-kit/crypto/asym/ecdsa"
|
||||
rpcx "github.com/meshplus/go-bitxhub-client"
|
||||
"github.com/meshplus/bitxhub-model/pb"
|
||||
"github.com/meshplus/bitxhub/internal/constant"
|
||||
"github.com/meshplus/bitxhub/internal/coreapi/api"
|
||||
"github.com/stretchr/testify/suite"
|
||||
"github.com/tidwall/gjson"
|
||||
)
|
||||
|
||||
type Role struct {
|
||||
suite.Suite
|
||||
api api.CoreAPI
|
||||
privKey crypto.PrivateKey
|
||||
pubKey crypto.PublicKey
|
||||
client rpcx.Client
|
||||
}
|
||||
|
||||
func (suite *Role) SetupSuite() {
|
||||
|
@ -25,42 +25,30 @@ func (suite *Role) SetupSuite() {
|
|||
suite.Assert().Nil(err)
|
||||
|
||||
suite.pubKey = suite.privKey.PublicKey()
|
||||
|
||||
suite.client, err = rpcx.New(
|
||||
rpcx.WithPrivateKey(suite.privKey),
|
||||
rpcx.WithAddrs([]string{
|
||||
"localhost:60011",
|
||||
"localhost:60012",
|
||||
"localhost:60013",
|
||||
"localhost:60014",
|
||||
}),
|
||||
)
|
||||
suite.Require().Nil(err)
|
||||
}
|
||||
|
||||
func (suite *Role) TestGetRole() {
|
||||
pubKey, err := suite.pubKey.Bytes()
|
||||
suite.Assert().Nil(err)
|
||||
_, err = suite.client.InvokeBVMContract(constant.InterchainContractAddr.Address(), "Register",
|
||||
rpcx.String(""),
|
||||
rpcx.Int32(0),
|
||||
rpcx.String("hyperchain"),
|
||||
rpcx.String("婚姻链"),
|
||||
rpcx.String("趣链婚姻链"),
|
||||
rpcx.String("1.8"),
|
||||
rpcx.String(string(pubKey)),
|
||||
_, err = invokeBVMContract(suite.api, suite.privKey, constant.InterchainContractAddr.Address(), "Register",
|
||||
pb.String(""),
|
||||
pb.Int32(0),
|
||||
pb.String("hyperchain"),
|
||||
pb.String("婚姻链"),
|
||||
pb.String("趣链婚姻链"),
|
||||
pb.String("1.8"),
|
||||
pb.String(string(pubKey)),
|
||||
)
|
||||
suite.Assert().Nil(err)
|
||||
|
||||
receipt, err := suite.client.InvokeBVMContract(constant.RoleContractAddr.Address(), "GetRole")
|
||||
receipt, err := invokeBVMContract(suite.api, suite.privKey, constant.RoleContractAddr.Address(), "GetRole")
|
||||
suite.Require().Nil(err)
|
||||
suite.Equal("appchain_admin", string(receipt.Ret))
|
||||
|
||||
k, err := ecdsa.GenerateKey(ecdsa.Secp256r1)
|
||||
suite.Require().Nil(err)
|
||||
|
||||
suite.client.SetPrivateKey(k)
|
||||
r, err := suite.client.InvokeBVMContract(constant.RoleContractAddr.Address(), "GetRole")
|
||||
r, err := invokeBVMContract(suite.api, k, constant.RoleContractAddr.Address(), "GetRole")
|
||||
suite.Assert().Nil(err)
|
||||
suite.Equal("none", string(r.Ret))
|
||||
}
|
||||
|
@ -69,8 +57,7 @@ func (suite *Role) TestGetAdminRoles() {
|
|||
k, err := ecdsa.GenerateKey(ecdsa.Secp256r1)
|
||||
suite.Require().Nil(err)
|
||||
|
||||
suite.client.SetPrivateKey(k)
|
||||
r, err := suite.client.InvokeBVMContract(constant.RoleContractAddr.Address(), "GetAdminRoles")
|
||||
r, err := invokeBVMContract(suite.api, k, constant.RoleContractAddr.Address(), "GetAdminRoles")
|
||||
suite.Assert().Nil(err)
|
||||
ret := gjson.ParseBytes(r.Ret)
|
||||
suite.EqualValues(4, len(ret.Array()))
|
||||
|
@ -82,8 +69,7 @@ func (suite *Role) TestIsAdmin() {
|
|||
from, err := k.PublicKey().Address()
|
||||
suite.Require().Nil(err)
|
||||
|
||||
suite.client.SetPrivateKey(k)
|
||||
r, err := suite.client.InvokeBVMContract(constant.RoleContractAddr.Address(), "IsAdmin", rpcx.String(from.Hex()))
|
||||
r, err := invokeBVMContract(suite.api, k, constant.RoleContractAddr.Address(), "IsAdmin", pb.String(from.Hex()))
|
||||
suite.Assert().Nil(err)
|
||||
ret, err := strconv.ParseBool(string(r.Ret))
|
||||
suite.Assert().Nil(err)
|
||||
|
|
|
@ -1,47 +0,0 @@
|
|||
package tester
|
||||
|
||||
import (
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/suite"
|
||||
"github.com/tidwall/gjson"
|
||||
)
|
||||
|
||||
const (
|
||||
host = "http://localhost:9091/v1/"
|
||||
)
|
||||
|
||||
type Gateway struct {
|
||||
suite.Suite
|
||||
}
|
||||
|
||||
func (suite *Gateway) TestGetBlock() {
|
||||
data := httpGet(suite.Suite, "block?type=0&value=1")
|
||||
height := gjson.Get(data, "block_header.number").Int()
|
||||
suite.Assert().EqualValues(1, height, data)
|
||||
}
|
||||
|
||||
func (suite *Gateway) TestGetBlockByHash() {
|
||||
data := httpGet(suite.Suite, "block?type=0&value=1")
|
||||
hash := gjson.Get(data, "block_hash").String()
|
||||
m := httpGet(suite.Suite, "block?type=1&value="+hash)
|
||||
suite.Assert().EqualValues(1, gjson.Get(m, "block_header.number").Int(), m)
|
||||
suite.Assert().Equal(hash, gjson.Get(m, "block_hash").String(), m)
|
||||
}
|
||||
|
||||
func TestGateway(t *testing.T) {
|
||||
suite.Run(t, &Gateway{})
|
||||
}
|
||||
|
||||
func httpGet(suite suite.Suite, path string) string {
|
||||
resp, err := http.Get(host + path)
|
||||
suite.Assert().Nil(err)
|
||||
c, err := ioutil.ReadAll(resp.Body)
|
||||
suite.Assert().Nil(err)
|
||||
err = resp.Body.Close()
|
||||
suite.Assert().Nil(err)
|
||||
|
||||
return string(c)
|
||||
}
|
|
@ -1,93 +0,0 @@
|
|||
package tester
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"testing"
|
||||
|
||||
"github.com/meshplus/bitxhub-kit/crypto"
|
||||
"github.com/meshplus/bitxhub-kit/crypto/asym/ecdsa"
|
||||
"github.com/meshplus/bitxhub-kit/key"
|
||||
"github.com/meshplus/bitxhub-kit/types"
|
||||
"github.com/meshplus/bitxhub-model/pb"
|
||||
rpcx "github.com/meshplus/go-bitxhub-client"
|
||||
"github.com/stretchr/testify/suite"
|
||||
)
|
||||
|
||||
type Pier struct {
|
||||
suite.Suite
|
||||
privKey crypto.PrivateKey
|
||||
pubKey crypto.PublicKey
|
||||
address types.Address
|
||||
client rpcx.Client // bitxhub admin
|
||||
}
|
||||
|
||||
func (suite *Pier) SetupSuite() {
|
||||
key, err := key.LoadKey("./test_data/key")
|
||||
suite.Require().Nil(err)
|
||||
|
||||
privKey, err := key.GetPrivateKey("bitxhub")
|
||||
suite.Require().Nil(err)
|
||||
|
||||
address, err := privKey.PublicKey().Address()
|
||||
suite.Require().Nil(err)
|
||||
|
||||
client, err := rpcx.New(
|
||||
rpcx.WithPrivateKey(privKey),
|
||||
rpcx.WithAddrs(grpcAddresses()),
|
||||
)
|
||||
suite.Require().Nil(err)
|
||||
|
||||
suite.privKey = privKey
|
||||
suite.pubKey = suite.privKey.PublicKey()
|
||||
suite.address = address
|
||||
suite.client = client
|
||||
}
|
||||
|
||||
func (suite *Pier) TestSyncMerkleWrapper() {
|
||||
privKey, err := ecdsa.GenerateKey(ecdsa.Secp256r1)
|
||||
suite.Assert().Nil(err)
|
||||
|
||||
address, err := privKey.PublicKey().Address()
|
||||
suite.Require().Nil(err)
|
||||
|
||||
client, err := rpcx.New(
|
||||
rpcx.WithPrivateKey(privKey),
|
||||
rpcx.WithAddrs(grpcAddresses()),
|
||||
)
|
||||
suite.Require().Nil(err)
|
||||
|
||||
pubKey, err := privKey.PublicKey().Bytes()
|
||||
suite.Require().Nil(err)
|
||||
args := []*pb.Arg{
|
||||
rpcx.String(""),
|
||||
rpcx.Int32(0),
|
||||
rpcx.String("hyperchain"),
|
||||
rpcx.String("税务链"),
|
||||
rpcx.String("趣链税务链"),
|
||||
rpcx.String("1.8"),
|
||||
rpcx.String(string(pubKey)),
|
||||
}
|
||||
|
||||
ret, err := client.InvokeBVMContract(rpcx.InterchainContractAddr, "Register", args...)
|
||||
suite.Require().Nil(err)
|
||||
suite.Require().EqualValues("SUCCESS", ret.Status.String())
|
||||
|
||||
go func() {
|
||||
w, err := client.Subscribe(context.Background(), pb.SubscriptionRequest_INTERCHAIN_TX_WRAPPER, address.Bytes())
|
||||
suite.Require().Nil(err)
|
||||
fmt.Println(<-w)
|
||||
}()
|
||||
|
||||
res, err := suite.client.InvokeBVMContract(rpcx.InterchainContractAddr, "Audit",
|
||||
rpcx.String(address.Hex()),
|
||||
rpcx.Int32(1),
|
||||
rpcx.String("pass"),
|
||||
)
|
||||
suite.Require().Nil(err)
|
||||
suite.Require().EqualValues("SUCCESS", res.Status.String())
|
||||
}
|
||||
|
||||
func TestPier(t *testing.T) {
|
||||
suite.Run(t, &Pier{})
|
||||
}
|
|
@ -0,0 +1,134 @@
|
|||
package tester
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"math/rand"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/meshplus/bitxhub/internal/coreapi/api"
|
||||
|
||||
"github.com/meshplus/bitxhub-kit/crypto"
|
||||
"github.com/meshplus/bitxhub-kit/types"
|
||||
"github.com/meshplus/bitxhub-model/pb"
|
||||
)
|
||||
|
||||
func genBVMContractTransaction(privateKey crypto.PrivateKey, address types.Address, method string, args ...*pb.Arg) (*pb.Transaction, error) {
|
||||
return genContractTransaction(pb.TransactionData_BVM, privateKey, address, method, args...)
|
||||
}
|
||||
|
||||
func genXVMContractTransaction(privateKey crypto.PrivateKey, address types.Address, method string, args ...*pb.Arg) (*pb.Transaction, error) {
|
||||
return genContractTransaction(pb.TransactionData_XVM, privateKey, address, method, args...)
|
||||
}
|
||||
|
||||
func invokeBVMContract(api api.CoreAPI, privateKey crypto.PrivateKey, address types.Address, method string, args ...*pb.Arg) (*pb.Receipt, error) {
|
||||
tx, err := genBVMContractTransaction(privateKey, address, method, args...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return sendTransactionWithReceipt(api, tx)
|
||||
}
|
||||
|
||||
func sendTransactionWithReceipt(api api.CoreAPI, tx *pb.Transaction) (*pb.Receipt, error) {
|
||||
err := api.Broker().HandleTransaction(tx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
|
||||
defer cancel()
|
||||
|
||||
for {
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
return nil, fmt.Errorf("get receipt timeout")
|
||||
default:
|
||||
time.Sleep(200 * time.Millisecond)
|
||||
receipt, err := api.Broker().GetReceipt(tx.TransactionHash)
|
||||
if err != nil {
|
||||
if strings.Contains(err.Error(), "not found") {
|
||||
continue
|
||||
}
|
||||
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return receipt, nil
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func genContractTransaction(vmType pb.TransactionData_VMType, privateKey crypto.PrivateKey, address types.Address, method string, args ...*pb.Arg) (*pb.Transaction, error) {
|
||||
from, err := privateKey.PublicKey().Address()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
pl := &pb.InvokePayload{
|
||||
Method: method,
|
||||
Args: args[:],
|
||||
}
|
||||
|
||||
data, err := pl.Marshal()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
td := &pb.TransactionData{
|
||||
Type: pb.TransactionData_INVOKE,
|
||||
VmType: vmType,
|
||||
Payload: data,
|
||||
}
|
||||
|
||||
tx := &pb.Transaction{
|
||||
From: from,
|
||||
To: address,
|
||||
Data: td,
|
||||
Timestamp: time.Now().UnixNano(),
|
||||
Nonce: rand.Int63(),
|
||||
}
|
||||
|
||||
if err := tx.Sign(privateKey); err != nil {
|
||||
return nil, fmt.Errorf("tx sign: %w", err)
|
||||
}
|
||||
|
||||
tx.TransactionHash = tx.Hash()
|
||||
|
||||
return tx, nil
|
||||
}
|
||||
|
||||
func deployContract(api api.CoreAPI, privateKey crypto.PrivateKey, contract []byte) (types.Address, error) {
|
||||
from, err := privateKey.PublicKey().Address()
|
||||
if err != nil {
|
||||
return types.Address{}, err
|
||||
}
|
||||
|
||||
td := &pb.TransactionData{
|
||||
Type: pb.TransactionData_INVOKE,
|
||||
VmType: pb.TransactionData_XVM,
|
||||
Payload: contract,
|
||||
}
|
||||
|
||||
tx := &pb.Transaction{
|
||||
From: from,
|
||||
Data: td,
|
||||
Timestamp: time.Now().UnixNano(),
|
||||
Nonce: rand.Int63(),
|
||||
}
|
||||
|
||||
if err := tx.Sign(privateKey); err != nil {
|
||||
return types.Address{}, fmt.Errorf("tx sign: %w", err)
|
||||
}
|
||||
|
||||
receipt, err := sendTransactionWithReceipt(api, tx)
|
||||
if err != nil {
|
||||
return types.Address{}, err
|
||||
}
|
||||
|
||||
ret := types.Bytes2Address(receipt.GetRet())
|
||||
|
||||
return ret, nil
|
||||
}
|
|
@ -0,0 +1 @@
|
|||
http://localhost:9091/v1/
|
|
@ -0,0 +1,41 @@
|
|||
title = "BitXHub configuration file"
|
||||
|
||||
solo = false
|
||||
|
||||
[port]
|
||||
grpc = 60011
|
||||
gateway = 9091
|
||||
pprof = 53121
|
||||
|
||||
[pprof]
|
||||
enable = true
|
||||
|
||||
[gateway]
|
||||
allowed_origins = ["*"]
|
||||
|
||||
[log]
|
||||
level = "info"
|
||||
dir = "logs"
|
||||
filename = "bitxhub.log"
|
||||
report_caller = false
|
||||
[log.module]
|
||||
p2p = "info"
|
||||
consensus = "info"
|
||||
executor = "info"
|
||||
router = "info"
|
||||
api = "info"
|
||||
coreapi = "info"
|
||||
|
||||
[cert]
|
||||
verify = true
|
||||
|
||||
[order]
|
||||
plugin = "plugins/raft.so"
|
||||
|
||||
[genesis]
|
||||
addresses = [
|
||||
"0xe6f8c9cf6e38bd506fae93b73ee5e80cc8f73667",
|
||||
"0x8374bb1e41d4a4bb4ac465e74caa37d242825efc",
|
||||
"0x759801eab44c9a9bbc3e09cb7f1f85ac57298708",
|
||||
"0xf2d66e2c27e93ff083ee3999acb678a36bb349bb"
|
||||
]
|
|
@ -0,0 +1,16 @@
|
|||
-----BEGIN CERTIFICATE-----
|
||||
MIICkTCCAjegAwIBAgIDCFlzMAoGCCqGSM49BAMCMIGhMQswCQYDVQQGEwJDTjER
|
||||
MA8GA1UECBMIWmhlSmlhbmcxETAPBgNVBAcTCEhhbmdaaG91MR8wDQYDVQQJEwZz
|
||||
dHJlZXQwDgYDVQQJEwdhZGRyZXNzMQ8wDQYDVQQREwYzMjQwMDAxEzARBgN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4GA1UEAxMHQml0WEh1YjAgFw0y
|
||||
MDAzMDQwODQ0MjRaGA8yMDcwMDIyMDA4NDQyNFowgZkxCzAJBgNVBAYTAkNOMREw
|
||||
DwYDVQQIEwhaaGVKaWFuZzERMA8GA1UEBxMISGFuZ1pob3UxHzANBgNVBAkTBnN0
|
||||
cmVldDAOBgNVBAkTB2FkZHJlc3MxDzANBgNVBBETBjMyNDAwMDEOMAwGA1UEChMF
|
||||
Tm9kZTExEDAOBgNVBAsTB0JpdFhIdWIxEDAOBgNVBAMTB0JpdFhIdWIwWTATBgcq
|
||||
hkjOPQIBBggqhkjOPQMBBwNCAAQi8bygCNVfLigWljvEOCr8gRlpTpfIEGoP+HL8
|
||||
4BwKcSX1n0hZC3oTfv7fMMGxE7lVjZ26C5q54vJAliceljbPozEwLzAOBgNVHQ8B
|
||||
Af8EBAMCAaYwDwYDVR0lBAgwBgYEVR0lADAMBgNVHRMBAf8EAjAAMAoGCCqGSM49
|
||||
BAMCA0kAMEYCIQDrq69L8mxZReND60P6tXDW5AnR4sSS/yPTsmh31D6+EgIhAKh/
|
||||
WpVWOgI8b/ltCWpufb3TUM3lEQrsXP4W28Uk7q1j
|
||||
-----END CERTIFICATE-----
|
|
@ -0,0 +1,5 @@
|
|||
-----BEGIN EC PRIVATE KEY-----
|
||||
MHcCAQEEIFYN9+xvnRzlNX6Cob3trD3HlcvuYZUYRPrhYU+Yh2ADoAoGCCqGSM49
|
||||
AwEHoUQDQgAEIvG8oAjVXy4oFpY7xDgq/IEZaU6XyBBqD/hy/OAcCnEl9Z9IWQt6
|
||||
E37+3zDBsRO5VY2duguaueLyQJYnHpY2zw==
|
||||
-----END EC PRIVATE KEY-----
|
|
@ -0,0 +1,5 @@
|
|||
{
|
||||
"address": "0xe6f8c9cf6e38bd506fae93b73ee5e80cc8f73667",
|
||||
"private_key": "b899679b51e2f81116c5489e6d873b4ea6a62817fc3c0db99cf7c6716b490df8997aa92937afb370d8537a36e4fd6116",
|
||||
"encrypted": true
|
||||
}
|
|
@ -0,0 +1,18 @@
|
|||
id = 1 # self id
|
||||
N = 4 # the number of cluster nodes
|
||||
|
||||
[[nodes]]
|
||||
addr = "/ip4/127.0.0.1/tcp/4001/p2p/QmZZFk1Tj6p25ecz98SpyHxb6joDPxR3wVPptDwuc8fue1"
|
||||
id = 1
|
||||
|
||||
[[nodes]]
|
||||
addr = "/ip4/127.0.0.1/tcp/4002/p2p/QmNRgD6djYJERNpDpHqRn3mxjJ9SYiiGWzExNSy4sEmSNL"
|
||||
id = 2
|
||||
|
||||
[[nodes]]
|
||||
addr = "/ip4/127.0.0.1/tcp/4003/p2p/QmXmyw2usKApP6UyK3cHEJ1XvxxSa8kM2M3Q1T6fhdifs5"
|
||||
id = 3
|
||||
|
||||
[[nodes]]
|
||||
addr = "/ip4/127.0.0.1/tcp/4004/p2p/QmY21wH1M694j1JFEvwegyJz8h2VpaSeeqcwt2vUpxsFPt"
|
||||
id = 4
|
|
@ -0,0 +1,12 @@
|
|||
[raft]
|
||||
election_tick = 10 # ElectionTick is the number of Node.Tick invocations that must pass between elections.
|
||||
heartbeat_tick = 1 # HeartbeatTick is the number of Node.Tick invocations that must pass between heartbeats.
|
||||
max_size_per_msg = 1048576 # 1024*1024, MaxSizePerMsg limits the max size of each append message.
|
||||
max_inflight_msgs = 500 # MaxInflightMsgs limits the max number of in-flight append messages during optimistic replication phase.
|
||||
check_quorum = true # Leader steps down when quorum is not active for an electionTimeout.
|
||||
pre_vote = true # PreVote prevents reconnected node from disturbing network.
|
||||
disable_proposal_forwarding = true # This prevents blocks from being accidentally proposed by followers.
|
||||
[raft.tx_pool]
|
||||
pack_size = 500 # How many transactions should the primary pack.
|
||||
pool_size = 50000 # How many transactions could the txPool stores in total.
|
||||
block_tick = "500ms" # Block packaging time period.
|
|
@ -0,0 +1 @@
|
|||
http://localhost:9092/v1/
|
|
@ -0,0 +1,41 @@
|
|||
title = "BitXHub configuration file"
|
||||
|
||||
solo = false
|
||||
|
||||
[port]
|
||||
grpc = 60012
|
||||
gateway = 9092
|
||||
pprof = 53122
|
||||
|
||||
[pprof]
|
||||
enable = true
|
||||
|
||||
[gateway]
|
||||
allowed_origins = ["*"]
|
||||
|
||||
[log]
|
||||
level = "info"
|
||||
dir = "logs"
|
||||
filename = "bitxhub.log"
|
||||
report_caller = false
|
||||
[log.module]
|
||||
p2p = "info"
|
||||
consensus = "info"
|
||||
executor = "info"
|
||||
router = "info"
|
||||
api = "info"
|
||||
coreapi = "info"
|
||||
|
||||
[cert]
|
||||
verify = true
|
||||
|
||||
[order]
|
||||
plugin = "plugins/raft.so"
|
||||
|
||||
[genesis]
|
||||
addresses = [
|
||||
"0xe6f8c9cf6e38bd506fae93b73ee5e80cc8f73667",
|
||||
"0x8374bb1e41d4a4bb4ac465e74caa37d242825efc",
|
||||
"0x759801eab44c9a9bbc3e09cb7f1f85ac57298708",
|
||||
"0xf2d66e2c27e93ff083ee3999acb678a36bb349bb"
|
||||
]
|
|
@ -0,0 +1,16 @@
|
|||
-----BEGIN CERTIFICATE-----
|
||||
MIICkTCCAjegAwIBAgIDCFlzMAoGCCqGSM49BAMCMIGhMQswCQYDVQQGEwJDTjER
|
||||
MA8GA1UECBMIWmhlSmlhbmcxETAPBgNVBAcTCEhhbmdaaG91MR8wDQYDVQQJEwZz
|
||||
dHJlZXQwDgYDVQQJEwdhZGRyZXNzMQ8wDQYDVQQREwYzMjQwMDAxEzARBgNVBAoT
|
||||
Ckh5cGVyY2hhaW4xEDAOBgNVBAsTB0JpdFhIdWIxEzARBgNVBAMTCmJpdHhodWIu
|
||||
Y24wIBcNMjAwMzA0MDg0NDIyWhgPMjA3MDAyMjAwODQ0MjJaMIGaMQswCQYDVQQG
|
||||
EwJDTjERMA8GA1UECBMIWmhlSmlhbmcxETAPBgNVBAcTCEhhbmdaaG91MR8wDQYD
|
||||
VQQJEwZzdHJlZXQwDgYDVQQJEwdhZGRyZXNzMQ8wDQYDVQQREwYzMjQwMDAxDzAN
|
||||
BgNVBAoTBk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q
|
||||
hkjOPQIBBggqhkjOPQMBBwNCAARNhmawbnCyMOZmKAsFOPIOGSJo0/l9RGCFUU+a
|
||||
Cd6/apiwrwWD4RGKWGHwjFAXSRHpYUzuwXwyQrB4FtJZ/1xoozEwLzAOBgNVHQ8B
|
||||
Af8EBAMCAaYwDwYDVR0lBAgwBgYEVR0lADAMBgNVHRMBAf8EAjAAMAoGCCqGSM49
|
||||
BAMCA0gAMEUCIQDSF6I7+I23UmoNxERZ7PHvW4dsIFTHaCLUNl2pG9uiHAIgB898
|
||||
yCHKASfneRgUxz5KZ1kvtcrnqC73muAxWz0TMEE=
|
||||
-----END CERTIFICATE-----
|
|
@ -0,0 +1,5 @@
|
|||
-----BEGIN EC PRIVATE KEY-----
|
||||
MHcCAQEEIEP1ckhwUxWqpJqnKitIC/u8eWAsR/4I+aLJDesKB9XOoAoGCCqGSM49
|
||||
AwEHoUQDQgAETYZmsG5wsjDmZigLBTjyDhkiaNP5fURghVFPmgnev2qYsK8Fg+ER
|
||||
ilhh8IxQF0kR6WFM7sF8MkKweBbSWf9caA==
|
||||
-----END EC PRIVATE KEY-----
|
|
@ -0,0 +1,5 @@
|
|||
{
|
||||
"address": "0x8374bb1e41d4a4bb4ac465e74caa37d242825efc",
|
||||
"private_key": "b9e3b4277cfc589a3dff7d0aba7cac297b84465afc76a74f1d738e8165f2043d3a36500c0f193b6be994683bc42f1096",
|
||||
"encrypted": true
|
||||
}
|
|
@ -0,0 +1,18 @@
|
|||
id = 2 # self id
|
||||
N = 4 # the number of cluster nodes
|
||||
|
||||
[[nodes]]
|
||||
addr = "/ip4/127.0.0.1/tcp/4001/p2p/QmZZFk1Tj6p25ecz98SpyHxb6joDPxR3wVPptDwuc8fue1"
|
||||
id = 1
|
||||
|
||||
[[nodes]]
|
||||
addr = "/ip4/127.0.0.1/tcp/4002/p2p/QmNRgD6djYJERNpDpHqRn3mxjJ9SYiiGWzExNSy4sEmSNL"
|
||||
id = 2
|
||||
|
||||
[[nodes]]
|
||||
addr = "/ip4/127.0.0.1/tcp/4003/p2p/QmXmyw2usKApP6UyK3cHEJ1XvxxSa8kM2M3Q1T6fhdifs5"
|
||||
id = 3
|
||||
|
||||
[[nodes]]
|
||||
addr = "/ip4/127.0.0.1/tcp/4004/p2p/QmY21wH1M694j1JFEvwegyJz8h2VpaSeeqcwt2vUpxsFPt"
|
||||
id = 4
|
|
@ -0,0 +1,12 @@
|
|||
[raft]
|
||||
election_tick = 10 # ElectionTick is the number of Node.Tick invocations that must pass between elections.
|
||||
heartbeat_tick = 1 # HeartbeatTick is the number of Node.Tick invocations that must pass between heartbeats.
|
||||
max_size_per_msg = 1048576 # 1024*1024, MaxSizePerMsg limits the max size of each append message.
|
||||
max_inflight_msgs = 500 # MaxInflightMsgs limits the max number of in-flight append messages during optimistic replication phase.
|
||||
check_quorum = true # Leader steps down when quorum is not active for an electionTimeout.
|
||||
pre_vote = true # PreVote prevents reconnected node from disturbing network.
|
||||
disable_proposal_forwarding = true # This prevents blocks from being accidentally proposed by followers.
|
||||
[raft.tx_pool]
|
||||
pack_size = 500 # How many transactions should the primary pack.
|
||||
pool_size = 50000 # How many transactions could the txPool stores in total.
|
||||
block_tick = "500ms" # Block packaging time period.
|
|
@ -0,0 +1 @@
|
|||
http://localhost:9093/v1/
|
|
@ -0,0 +1,41 @@
|
|||
title = "BitXHub configuration file"
|
||||
|
||||
solo = false
|
||||
|
||||
[port]
|
||||
grpc = 60013
|
||||
gateway = 9093
|
||||
pprof = 53123
|
||||
|
||||
[pprof]
|
||||
enable = true
|
||||
|
||||
[gateway]
|
||||
allowed_origins = ["*"]
|
||||
|
||||
[log]
|
||||
level = "info"
|
||||
dir = "logs"
|
||||
filename = "bitxhub.log"
|
||||
report_caller = false
|
||||
[log.module]
|
||||
p2p = "info"
|
||||
consensus = "info"
|
||||
executor = "info"
|
||||
router = "info"
|
||||
api = "info"
|
||||
coreapi = "info"
|
||||
|
||||
[cert]
|
||||
verify = true
|
||||
|
||||
[order]
|
||||
plugin = "plugins/raft3.so"
|
||||
|
||||
[genesis]
|
||||
addresses = [
|
||||
"0xe6f8c9cf6e38bd506fae93b73ee5e80cc8f73667",
|
||||
"0x8374bb1e41d4a4bb4ac465e74caa37d242825efc",
|
||||
"0x759801eab44c9a9bbc3e09cb7f1f85ac57298708",
|
||||
"0xf2d66e2c27e93ff083ee3999acb678a36bb349bb"
|
||||
]
|
|
@ -0,0 +1,16 @@
|
|||
-----BEGIN CERTIFICATE-----
|
||||
MIICkTCCAjegAwIBAgIDCFlzMAoGCCqGSM49BAMCMIGhMQswCQYDVQQGEwJDTjER
|
||||
MA8GA1UECBMIWmhlSmlhbmcxETAPBgNVBAcTCEhhbmdaaG91MR8wDQYDVQQJEwZz
|
||||
dHJlZXQwDgYDVQQJEwdhZGRyZXNzMQ8wDQYDVQQREwYzMjQwMDAxEzARBgNVBAoT
|
||||
Ckh5cGVyY2hhaW4xEDAOBgNVBAsTB0JpdFhIdWIxEzARBgNVBAMTCmJpdHhodWIu
|
||||
Y24wIBcNMjAwMzA0MDg0NDIyWhgPMjA3MDAyMjAwODQ0MjJaMIGaMQswCQYDVQQG
|
||||
EwJDTjERMA8GA1UECBMIWmhlSmlhbmcxETAPBgNVBAcTCEhhbmdaaG91MR8wDQYD
|
||||
VQQJEwZzdHJlZXQwDgYDVQQJEwdhZGRyZXNzMQ8wDQYDVQQREwYzMjQwMDAxDzAN
|
||||
BgNVBAoTBkFnZW5jeTEQMA4GA1UECxMHQml0WEh1YjEQMA4GA1UEAxMHQml0WEh1
|
||||
YjBZMBMGByqGSM49AgEGCCqGSM49AwEHA0IABDtMPr3mXU6kqFlAC9QDD+IofJJW
|
||||
phhBiNVqgKjVwuAnYdhONPtxHKK6wWBV5pwT2rLKQUOZjdIULNd+yjTGVy6jYTBf
|
||||
MA4GA1UdDwEB/wQEAwIBpjAPBgNVHSUECDAGBgRVHSUAMA8GA1UdEwEB/wQFMAMB
|
||||
Af8wKwYDVR0jBCQwIoAgkq80RhqcgxYaYUzvK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TK83MgW4gj0K0OFmtM2w==
|
||||
-----END CERTIFICATE-----
|
|
@ -0,0 +1,5 @@
|
|||
-----BEGIN EC PRIVATE KEY-----
|
||||
MHcCAQEEIPp2yQwm9q6goxwC+FtMjEMTqlmqPszl36E9HaFw/kIyoAoGCCqGSM49
|
||||
AwEHoUQDQgAEblZd6wRzRxOtteLJjwM2Ht81cMzOhQ7iMDXj3+Z/oXGnzr8tVbWm
|
||||
lmkM2BYGKhzd/mhkhvy3mHRdKJmOzcTrtw==
|
||||
-----END EC PRIVATE KEY-----
|
|
@ -0,0 +1,5 @@
|
|||
{
|
||||
"address": "0x759801eab44c9a9bbc3e09cb7f1f85ac57298708",
|
||||
"private_key": "ad69b589b7c218381b117382aea1003f4cdc6f32bcad41a4a5528bd48b486e0285e4a2fc0f64080c5d49082963fccb04",
|
||||
"encrypted": true
|
||||
}
|
|
@ -0,0 +1,18 @@
|
|||
id = 3 # self id
|
||||
N = 4 # the number of cluster nodes
|
||||
|
||||
[[nodes]]
|
||||
addr = "/ip4/127.0.0.1/tcp/4001/p2p/QmZZFk1Tj6p25ecz98SpyHxb6joDPxR3wVPptDwuc8fue1"
|
||||
id = 1
|
||||
|
||||
[[nodes]]
|
||||
addr = "/ip4/127.0.0.1/tcp/4002/p2p/QmNRgD6djYJERNpDpHqRn3mxjJ9SYiiGWzExNSy4sEmSNL"
|
||||
id = 2
|
||||
|
||||
[[nodes]]
|
||||
addr = "/ip4/127.0.0.1/tcp/4003/p2p/QmXmyw2usKApP6UyK3cHEJ1XvxxSa8kM2M3Q1T6fhdifs5"
|
||||
id = 3
|
||||
|
||||
[[nodes]]
|
||||
addr = "/ip4/127.0.0.1/tcp/4004/p2p/QmY21wH1M694j1JFEvwegyJz8h2VpaSeeqcwt2vUpxsFPt"
|
||||
id = 4
|
|
@ -0,0 +1,12 @@
|
|||
[raft]
|
||||
election_tick = 10 # ElectionTick is the number of Node.Tick invocations that must pass between elections.
|
||||
heartbeat_tick = 1 # HeartbeatTick is the number of Node.Tick invocations that must pass between heartbeats.
|
||||
max_size_per_msg = 1048576 # 1024*1024, MaxSizePerMsg limits the max size of each append message.
|
||||
max_inflight_msgs = 500 # MaxInflightMsgs limits the max number of in-flight append messages during optimistic replication phase.
|
||||
check_quorum = true # Leader steps down when quorum is not active for an electionTimeout.
|
||||
pre_vote = true # PreVote prevents reconnected node from disturbing network.
|
||||
disable_proposal_forwarding = true # This prevents blocks from being accidentally proposed by followers.
|
||||
[raft.tx_pool]
|
||||
pack_size = 500 # How many transactions should the primary pack.
|
||||
pool_size = 50000 # How many transactions could the txPool stores in total.
|
||||
block_tick = "500ms" # Block packaging time period.
|
|
@ -0,0 +1 @@
|
|||
http://localhost:9094/v1/
|
|
@ -0,0 +1,41 @@
|
|||
title = "BitXHub configuration file"
|
||||
|
||||
solo = false
|
||||
|
||||
[port]
|
||||
grpc = 60014
|
||||
gateway = 9094
|
||||
pprof = 53124
|
||||
|
||||
[pprof]
|
||||
enable = true
|
||||
|
||||
[gateway]
|
||||
allowed_origins = ["*"]
|
||||
|
||||
[log]
|
||||
level = "info"
|
||||
dir = "logs"
|
||||
filename = "bitxhub.log"
|
||||
report_caller = false
|
||||
[log.module]
|
||||
p2p = "info"
|
||||
consensus = "info"
|
||||
executor = "info"
|
||||
router = "info"
|
||||
api = "info"
|
||||
coreapi = "info"
|
||||
|
||||
[cert]
|
||||
verify = true
|
||||
|
||||
[order]
|
||||
plugin = "plugins/raft4.so"
|
||||
|
||||
[genesis]
|
||||
addresses = [
|
||||
"0xe6f8c9cf6e38bd506fae93b73ee5e80cc8f73667",
|
||||
"0x8374bb1e41d4a4bb4ac465e74caa37d242825efc",
|
||||
"0x759801eab44c9a9bbc3e09cb7f1f85ac57298708",
|
||||
"0xf2d66e2c27e93ff083ee3999acb678a36bb349bb"
|
||||
]
|
|
@ -0,0 +1,16 @@
|
|||
-----BEGIN CERTIFICATE-----
|
||||
MIICkTCCAjegAwIBAgIDCFlzMAoGCCqGSM49BAMCMIGhMQswCQY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NVBAcTCEhhbmdaaG91MR8wDQYDVQQJEwZz
|
||||
dHJlZXQwDgYDVQQJEwdhZGRyZXNzMQ8wDQYDVQQREwYzMjQwMDAxDzANBgNVBAoT
|
||||
BkFnZW5jeTEQMA4GA1UECxMHQml0WEh1YjEQMA4GA1UEAxMHQml0WEh1YjAgFw0y
|
||||
MDAzMDQwODQ0MjRaGA8yMDcwMDIyMDA4NDQyNFowgZkxCzAJBgNVBAYTAkNOMREw
|
||||
DwYDVQQIEwhaaGVKaWFuZzERMA8GA1UEBxMISGFuZ1pob3UxHzANBgNVBAkTBnN0
|
||||
cmVldDAOBgNVBAkTB2FkZHJlc3MxDzANBgNVBBETBjMyNDAwMDEOMAwGA1UEChMF
|
||||
Tm9kZTQxEDAOBgNVBAsTB0JpdFhIdWIxEDAOBgNVBAMTB0JpdFhIdWIwWTATBgcq
|
||||
hkjOPQIBBggqhkjOPQMBBwNCAARuDsfGfnzbqIZLSENOGJ72BfZW1NeKN8TsD/RD
|
||||
j4Trb3kbyBmY7qntTvNR7HuDmFkCVcRFR16IBPV+E7VtulxZozEwLzAOBgNVHQ8B
|
||||
Af8EBAMCAaYwDwYDVR0lBAgwBgYEVR0lADAMBgNVHRMBAf8EAjAAMAoGCCqGSM49
|
||||
BAMCA0cAMEQCIG96uffPzrEeYm688/GhV9d1gqaUTmQ1b4YYJo9GiNtiAiAVwBMc
|
||||
oz12grMgErh3sHb1DsbwWcz1aL1PDynk40HrvQ==
|
||||
-----END CERTIFICATE-----
|
|
@ -0,0 +1,5 @@
|
|||
-----BEGIN EC PRIVATE KEY-----
|
||||
MHcCAQEEIDDlbCWaYt24ANXbRep+t7Keq0Zu5GckeDECSfEASTq2oAoGCCqGSM49
|
||||
AwEHoUQDQgAEbg7Hxn5826iGS0hDThie9gX2VtTXijfE7A/0Q4+E6295G8gZmO6p
|
||||
7U7zUex7g5hZAlXERUdeiAT1fhO1bbpcWQ==
|
||||
-----END EC PRIVATE KEY-----
|
|
@ -0,0 +1,5 @@
|
|||
{
|
||||
"address": "0xf2d66e2c27e93ff083ee3999acb678a36bb349bb",
|
||||
"private_key": "b78b346732112129c1a8e82e0526523d29a0eeb92e8d5236e5433dcd203a19c2949a564e2075b2b873939967f1e2e0d2",
|
||||
"encrypted": true
|
||||
}
|
|
@ -0,0 +1,18 @@
|
|||
id = 4 # self id
|
||||
N = 4 # the number of cluster nodes
|
||||
|
||||
[[nodes]]
|
||||
addr = "/ip4/127.0.0.1/tcp/4001/p2p/QmZZFk1Tj6p25ecz98SpyHxb6joDPxR3wVPptDwuc8fue1"
|
||||
id = 1
|
||||
|
||||
[[nodes]]
|
||||
addr = "/ip4/127.0.0.1/tcp/4002/p2p/QmNRgD6djYJERNpDpHqRn3mxjJ9SYiiGWzExNSy4sEmSNL"
|
||||
id = 2
|
||||
|
||||
[[nodes]]
|
||||
addr = "/ip4/127.0.0.1/tcp/4003/p2p/QmXmyw2usKApP6UyK3cHEJ1XvxxSa8kM2M3Q1T6fhdifs5"
|
||||
id = 3
|
||||
|
||||
[[nodes]]
|
||||
addr = "/ip4/127.0.0.1/tcp/4004/p2p/QmY21wH1M694j1JFEvwegyJz8h2VpaSeeqcwt2vUpxsFPt"
|
||||
id = 4
|
|
@ -0,0 +1,12 @@
|
|||
[raft]
|
||||
election_tick = 10 # ElectionTick is the number of Node.Tick invocations that must pass between elections.
|
||||
heartbeat_tick = 1 # HeartbeatTick is the number of Node.Tick invocations that must pass between heartbeats.
|
||||
max_size_per_msg = 1048576 # 1024*1024, MaxSizePerMsg limits the max size of each append message.
|
||||
max_inflight_msgs = 500 # MaxInflightMsgs limits the max number of in-flight append messages during optimistic replication phase.
|
||||
check_quorum = true # Leader steps down when quorum is not active for an electionTimeout.
|
||||
pre_vote = true # PreVote prevents reconnected node from disturbing network.
|
||||
disable_proposal_forwarding = true # This prevents blocks from being accidentally proposed by followers.
|
||||
[raft.tx_pool]
|
||||
pack_size = 500 # How many transactions should the primary pack.
|
||||
pool_size = 50000 # How many transactions could the txPool stores in total.
|
||||
block_tick = "500ms" # Block packaging time period.
|
Binary file not shown.
|
@ -1,70 +1,60 @@
|
|||
package tester
|
||||
|
||||
import (
|
||||
"encoding/base64"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"net/http"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/Rican7/retry"
|
||||
"github.com/Rican7/retry/strategy"
|
||||
"github.com/meshplus/bitxhub/internal/app"
|
||||
"github.com/meshplus/bitxhub/internal/coreapi"
|
||||
"github.com/meshplus/bitxhub/internal/coreapi/api"
|
||||
"github.com/meshplus/bitxhub/internal/loggers"
|
||||
"github.com/meshplus/bitxhub/internal/repo"
|
||||
"github.com/stretchr/testify/require"
|
||||
"github.com/stretchr/testify/suite"
|
||||
"github.com/tidwall/gjson"
|
||||
)
|
||||
|
||||
func TestTester(t *testing.T) {
|
||||
err := retry.Retry(func(attempt uint) error {
|
||||
resp, err := http.Get(host + "info?type=0")
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return err
|
||||
node1 := setupNode(t, "./test_data/config/node1")
|
||||
node2 := setupNode(t, "./test_data/config/node2")
|
||||
node3 := setupNode(t, "./test_data/config/node3")
|
||||
node4 := setupNode(t, "./test_data/config/node4")
|
||||
|
||||
for {
|
||||
if node1.Broker().OrderReady() &&
|
||||
node2.Broker().OrderReady() &&
|
||||
node3.Broker().OrderReady() &&
|
||||
node4.Broker().OrderReady() {
|
||||
break
|
||||
}
|
||||
|
||||
c, err := ioutil.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return err
|
||||
}
|
||||
|
||||
if err := resp.Body.Close(); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
res := gjson.Get(string(c), "data")
|
||||
|
||||
ret, err := base64.StdEncoding.DecodeString(res.String())
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return err
|
||||
}
|
||||
|
||||
if string(ret) != "normal" {
|
||||
fmt.Println("abnormal")
|
||||
return fmt.Errorf("abnormal")
|
||||
}
|
||||
|
||||
return nil
|
||||
}, strategy.Wait(1*time.Second), strategy.Limit(60))
|
||||
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
time.Sleep(500 * time.Millisecond)
|
||||
}
|
||||
|
||||
suite.Run(t, &API{})
|
||||
suite.Run(t, &RegisterAppchain{})
|
||||
suite.Run(t, &Interchain{})
|
||||
suite.Run(t, &Role{})
|
||||
suite.Run(t, &Gateway{})
|
||||
suite.Run(t, &API{api: node1})
|
||||
suite.Run(t, &RegisterAppchain{api: node2})
|
||||
suite.Run(t, &Interchain{api: node3})
|
||||
suite.Run(t, &Role{api: node4})
|
||||
}
|
||||
|
||||
func grpcAddresses() []string {
|
||||
return []string{
|
||||
"localhost:60011",
|
||||
"localhost:60012",
|
||||
"localhost:60013",
|
||||
"localhost:60014",
|
||||
}
|
||||
func setupNode(t *testing.T, path string) api.CoreAPI {
|
||||
repoRoot, err := repo.PathRootWithDefault(path)
|
||||
require.Nil(t, err)
|
||||
|
||||
repo, err := repo.Load(repoRoot)
|
||||
require.Nil(t, err)
|
||||
|
||||
loggers.Initialize(repo.Config)
|
||||
|
||||
bxh, err := app.NewTesterBitXHub(repo)
|
||||
require.Nil(t, err)
|
||||
|
||||
api, err := coreapi.New(bxh)
|
||||
require.Nil(t, err)
|
||||
|
||||
go func() {
|
||||
err = bxh.Start()
|
||||
require.Nil(t, err)
|
||||
}()
|
||||
|
||||
return api
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue