Skip to content

Commit

Permalink
go test
Browse files Browse the repository at this point in the history
  • Loading branch information
zhouop0 committed Jan 29, 2024
1 parent e508a8b commit afd0e3d
Show file tree
Hide file tree
Showing 8 changed files with 30 additions and 35 deletions.
2 changes: 1 addition & 1 deletion docs/sql/listener.sql
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ CREATE TABLE `sync_tasks` (

SET FOREIGN_KEY_CHECKS = 1;


DROP TABLE IF EXISTS `proposal`;
CREATE TABLE `proposal` (
`id` bigint NOT NULL AUTO_INCREMENT,
`created_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
Expand Down
1 change: 1 addition & 0 deletions internal/handler/checkstatus.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ func CheckStatus(ctx *svc.ServiceContext) {
if proposal.Status != schema.VotingStatus && proposal.Winner != "" {
dbProposal.Winner = proposal.Winner
dbProposal.Status = proposal.Status
dbProposal.BlockHeight = proposal.BlockHight
ctx.DB.Save(dbProposal)
}
time.Sleep(2 * time.Second)
Expand Down
11 changes: 8 additions & 3 deletions internal/handler/committer.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,15 @@ type VerifyRangBatchInfo struct {
func Committer(ctx *svc.ServiceContext) {
for {
var proposals []schema.Proposal
lastFinalBatchNum := schema.GetLastFinalBatchNum()
err := ctx.DB.Where("end_batch_num >", lastFinalBatchNum).Find(&proposals).Error
lastFinalBatchNum, _, err := ctx.NodeClient.QueryLastProposalID()
if err != nil {
log.Errorf("[Handler.inscribe] error info:", errors.WithStack(err))
log.Errorf("[Handler.inscribe][QueryLastProposalID] error info:", errors.WithStack(err))
time.Sleep(10 * time.Second)
continue
}
err = ctx.DB.Where("end_batch_num > ?", lastFinalBatchNum).Find(&proposals).Error
if err != nil {
log.Errorf("[Handler.inscribe][DB] error info:", errors.WithStack(err))
time.Sleep(10 * time.Second)
continue
}
Expand Down
14 changes: 7 additions & 7 deletions internal/handler/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ func Run(ctx *svc.ServiceContext) {
//// 同步事件
go SyncEvent(ctx)
// 执行committer
go Committer(ctx)
// 检查vote状态
go CheckStatus(ctx)
// 检查并铭刻
go Inscribe(ctx)
// check time out
go CheckStatusTimeOut(ctx)
//go Committer(ctx)
//// 检查vote状态
//go CheckStatus(ctx)
//// 检查并铭刻
//go Inscribe(ctx)
//// check time out
//go CheckStatusTimeOut(ctx)

//// 检查
// go CheckBlock(ctx)
Expand Down
11 changes: 0 additions & 11 deletions internal/schema/proposal.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,3 @@ type Proposal struct {
func (Proposal) TableName() string {
return "`proposal`"
}

// GetLastProposalID get last proposal id from b2node
func GetLastProposalID() uint64 {
return 0
}

// GetLastFinalBatchNum get final batch num from b2node. This num is endBatchNum of proposal which status is SUCCESS.
func GetLastFinalBatchNum() uint64 {
// 查询b2node 还pending中最大的finalBatchNum
return 3
}
2 changes: 1 addition & 1 deletion internal/svc/svc.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func NewServiceContext(cfg *types.Config, bitcoinCfg *types.BitcoinRPCConfig, b2
privateKeHex := b2nodeConfig.PrivateKeyHex
chainID := b2nodeConfig.ChainID
address := b2nodeConfig.Address
grpcConn, err := types.GetClientConnection(b2nodeConfig.GRPCHost, b2nodeConfig.GRPCPort)
grpcConn, err := types.GetClientConnection(b2nodeConfig.GRPCHost, types.WithClientPortOption(b2nodeConfig.GRPCPort))
if err != nil {
log.Panicf("[svc] init b2node grpc panic: %s\n", err)
}
Expand Down
2 changes: 1 addition & 1 deletion internal/types/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ type Config struct {
MySQLMaxIdleConns int `env:"MYSQL_MAX_IDLE_CONNS" envDefault:"10"`
MySQLMaxOpenConns int `env:"MYSQL_MAX_OPEN_CONNS" envDefault:"20"`
MySQLConnMaxLifetime int `env:"MYSQL_CONN_MAX_LIFETIME" envDefault:"3600"`
RPCUrl string `env:"RPC_URL" envDefault:"https://b2-nodes.bsquared.network"`
RPCUrl string `env:"RPC_URL" envDefault:"http://haven-b2-nodes.bsquared.network"`
Blockchain string `env:"BLOCKCHAIN" envDefault:"b2-node"`
InitBlockNumber int64 `env:"INIT_BLOCK_NUMBER" envDefault:"10"`
InitBlockHash string `env:"INIT_BLOCK_HASH" envDefault:"0x8d8577c6a00608173c9eb1de053aec98be5f10d8918f11c0fb9d7124b5b3b8ec"`
Expand Down
22 changes: 11 additions & 11 deletions pkg/b2node/b2node_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ import (
)

func TestGetAccountInfo(t *testing.T) {
privateKeHex := "ccfda99f572bd491c085e19986b6db234f7e1f8c6db3fc7a2eabb96615340ec5"
privateKeHex := "53da55319c649af5dec2d9ff11c0476698b27cf3bf8dfbce55fd29ab78caadf0"
chainID := "ethermint_9000-1"
address := "ethm10ky5utnz5ddlmus5t2mm5ftxal3u0u6rsnx5nl"
address := "ethm17ezey9h6zw0yzaxq00w3gmt0rdet063v3vfmee"
grpcConn, err := types.GetClientConnection("127.0.0.1", types.WithClientPortOption(9090))
if err != nil {
panic(err)
Expand All @@ -28,15 +28,15 @@ func TestGetAccountInfo(t *testing.T) {
}

func TestSubmitProof(t *testing.T) {
privateKeHex := "ccfda99f572bd491c085e19986b6db234f7e1f8c6db3fc7a2eabb96615340ec5"
privateKeHex := "53da55319c649af5dec2d9ff11c0476698b27cf3bf8dfbce55fd29ab78caadf0"
chainID := "ethermint_9000-1"
address := "ethm10ky5utnz5ddlmus5t2mm5ftxal3u0u6rsnx5nl"
address := "ethm17ezey9h6zw0yzaxq00w3gmt0rdet063v3vfmee"
grpcConn, err := types.GetClientConnection("127.0.0.1", types.WithClientPortOption(9090))
if err != nil {
panic(err)
}
nodeClient := NewNodeClient(privateKeHex, chainID, address, grpcConn)
proposalID, err := nodeClient.SubmitProof(0, "ethm10ky5utnz5ddlmus5t2mm5ftxal3u0u6rsnx5nl", "proof7", "stateRoot", 61, 70)
proposalID, err := nodeClient.SubmitProof(0, address, "proof7", "stateRoot", 61, 70)
if err != nil {
fmt.Errorf("submitProof err: %s", err)
}
Expand All @@ -55,9 +55,9 @@ func TestDecodeTxResponseData(t *testing.T) {
}

func TestQueryLastProposalID(t *testing.T) {
privateKeHex := "ccfda99f572bd491c085e19986b6db234f7e1f8c6db3fc7a2eabb96615340ec5"
privateKeHex := "53da55319c649af5dec2d9ff11c0476698b27cf3bf8dfbce55fd29ab78caadf0"
chainID := "ethermint_9000-1"
address := "ethm10ky5utnz5ddlmus5t2mm5ftxal3u0u6rsnx5nl"
address := "ethm17ezey9h6zw0yzaxq00w3gmt0rdet063v3vfmee"
grpcConn, err := types.GetClientConnection("127.0.0.1", types.WithClientPortOption(9090))
if err != nil {
panic(err)
Expand All @@ -72,9 +72,9 @@ func TestQueryLastProposalID(t *testing.T) {
}

func TestQueryProposalByID(t *testing.T) {
privateKeHex := "ccfda99f572bd491c085e19986b6db234f7e1f8c6db3fc7a2eabb96615340ec5"
privateKeHex := "53da55319c649af5dec2d9ff11c0476698b27cf3bf8dfbce55fd29ab78caadf0"
chainID := "ethermint_9000-1"
address := "ethm10ky5utnz5ddlmus5t2mm5ftxal3u0u6rsnx5nl"
address := "ethm17ezey9h6zw0yzaxq00w3gmt0rdet063v3vfmee"
grpcConn, err := types.GetClientConnection("127.0.0.1", types.WithClientPortOption(9090))
if err != nil {
panic(err)
Expand All @@ -93,9 +93,9 @@ func TestQueryProposalByID(t *testing.T) {
}

func TestCommitterBitcoinTx(t *testing.T) {
privateKeHex := "ccfda99f572bd491c085e19986b6db234f7e1f8c6db3fc7a2eabb96615340ec5"
privateKeHex := "53da55319c649af5dec2d9ff11c0476698b27cf3bf8dfbce55fd29ab78caadf0"
chainID := "ethermint_9000-1"
address := "ethm10ky5utnz5ddlmus5t2mm5ftxal3u0u6rsnx5nl"
address := "ethm17ezey9h6zw0yzaxq00w3gmt0rdet063v3vfmee"
grpcConn, err := types.GetClientConnection("127.0.0.1", types.WithClientPortOption(9090))
if err != nil {
panic(err)
Expand Down

0 comments on commit afd0e3d

Please sign in to comment.