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

Rebuild config, consensus and crud #233

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 5 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
14 changes: 2 additions & 12 deletions cmd/commandline/kvTable.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,12 +81,7 @@ For more information please refer:
fmt.Printf("set failed, crud.NewCRUDService err: %v\n", err)
return
}
_, err = crudService.OpenTable(tableName)
if err != nil {
fmt.Printf("set failed,crudService.OpenTable err: %v\n", err)
return
}
result, err := crudService.Insert(&entry)
result, err := crudService.Insert(tableName, entry)
if err != nil {
fmt.Printf("set failed, crudService.Insert err: %v\n", err)
return
Expand Down Expand Up @@ -123,12 +118,7 @@ For more information please refer:
fmt.Printf("get failed, consensus.NewConsensusService err: %v\n", err)
return
}
_, err = crudService.OpenTable(tableName)
if err != nil {
fmt.Printf("get failed,crudService.OpenTable err: %v\n", err)
return
}
result, err := crudService.Select(key)
result, err := crudService.Select0(tableName, key)
if err != nil {
fmt.Printf("get failed, consensusService.AddObserver err: %v\n", err)
return
Expand Down
101 changes: 89 additions & 12 deletions precompiled/config/system_config.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 17 additions & 4 deletions precompiled/config/system_config_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,14 @@ import (
"github.com/FISCO-BCOS/go-sdk/core/types"
"github.com/FISCO-BCOS/go-sdk/precompiled"
"github.com/ethereum/go-ethereum/common"
"github.com/FISCO-BCOS/go-sdk/abi/bind"
)

// SystemConfigService is a precompile contract service.
type SystemConfigService struct {
systemConfig *Config
client *client.Client
systemConfig *Config
systemConfigAuth *bind.TransactOpts
client *client.Client
}

// systemConfig precompiled contract error code
Expand Down Expand Up @@ -55,12 +57,13 @@ func NewSystemConfigService(client *client.Client) (*SystemConfigService, error)
if err != nil {
return nil, fmt.Errorf("construct SystemConfigService failed: %+v", err)
}
return &SystemConfigService{systemConfig: instance, client: client}, nil
auth := client.GetTransactOpts()
return &SystemConfigService{systemConfig: instance, systemConfigAuth:auth, client: client}, nil
}

// SetValueByKey returns nil if there is no error occurred.
func (s *SystemConfigService) SetValueByKey(key string, value string) (int64, error) {
_, receipt, err := s.systemConfig.SetValueByKey(s.client.GetTransactOpts(), key, value)
_, _, receipt, err := s.systemConfig.SetValueByKey(s.client.GetTransactOpts(), key, value)
if err != nil {
return types.PrecompiledError, fmt.Errorf("client.WaitMined failed, err: %v", err)
}
Expand All @@ -78,3 +81,13 @@ func (s *SystemConfigService) SetValueByKey(key string, value string) (int64, er
}
return errorCode, errorCodeToError(errorCode)
}

func (s *SystemConfigService) GetValueByKey(key string) (string, int64, error) {
opts := &bind.CallOpts{From: s.systemConfigAuth.From}
fmt.Println("opts",opts)
ret0, ret1, err := s.systemConfig.GetValueByKey(opts, key)
if err != nil {
return "", precompiled.DefaultErrorCode, fmt.Errorf("systemConfigService getValueByKey failed: %+v", err)
}
return ret0, ret1.Int64(), nil
}
73 changes: 43 additions & 30 deletions precompiled/config/system_config_service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,52 +4,65 @@ import (
"context"
"encoding/hex"
"testing"
"os"

"github.com/FISCO-BCOS/go-sdk/client"
)

func testSetValueByKey(t *testing.T, key string, value string) {
privateKey, _ := hex.DecodeString("b89d42f12290070f235fb8fb61dcf96e3b11516c5d4f6333f26e49bb955f8b62")
const (
standardOutput = 0
key = "tx_count_limit"
value = "30000000"
)

func getClient(t *testing.T) *client.Client {
privateKey, _ := hex.DecodeString("145e247e170ba3afd6ae97e88f00dbc976c2345d511b0f6713355d19d8b80b58")
config := &client.Config{IsSMCrypto: false, GroupID: "group0",
PrivateKey: privateKey, Host: "127.0.0.1", Port: 20200, TLSCaFile: "./ca.crt", TLSKeyFile: "./sdk.key", TLSCertFile: "./sdk.crt"}
c, err := client.DialContext(context.Background(), config)
if err != nil {
t.Fatalf("init client failed: %+v", err)
t.Fatalf("Dial to %s:%d failed of %v", config.Host, config.Port, err)
}
service, err := NewSystemConfigService(c)
return c
}

func getService(t *testing.T) {
c := getClient(t)
newService, err := NewSystemConfigService(c)
if err != nil {
t.Fatalf("init SystemConfigService failed: %+v", err)
t.Fatalf("init CnsService failed: %+v", err)
}
service = newService
}

var (
service *SystemConfigService
)

func TestMain(m *testing.M) {
getService(&testing.T{})
exitCode := m.Run()
os.Exit(exitCode)
}

num, err := service.SetValueByKey(key, value)
func TestSetValueByKey(t *testing.T) {
result, err := service.SetValueByKey(key, value)
if err != nil {
t.Fatalf("SystemConfigService SetValueByKey failed: %+v", err)
t.Fatalf("Service RegisterCns failed: %+v\n", err)
}
if num != 0 {
t.Fatalf("testSetValueByKey failed, the result %v is inconsistent with \"1\"", num)
if result != standardOutput {
t.Fatalf("TestRegisterCns failed, the result %v is inconsistent with \"%v\"", result, standardOutput)
}
t.Logf("TestRegisterCns result: %v", result)
}

result, err := c.GetSystemConfigByKey(context.Background(), key)
func TestGetValueByKey(t *testing.T) {
ret0, _, err := service.GetValueByKey(key)
if err != nil {
t.Fatalf("GetSystemConfigByKey failed: %v", err)
t.Fatalf("Service GetValueByKey failed: %+v\n", err)
}
t.Logf("set %s value: %s, GetSystemConfigByKey: %s", key, value, result.GetValue())
//t.Logf("set %s value: %s, GetSystemConfigByKey: %s", key, value, result[1:len(result)-1])
if value != result.GetValue() {
t.Fatalf("SetValueByKey failed!")
if ret0 != value {
t.Fatalf("TestGetValueByKey failed, the ret0 %v is inconsistent with \"%v\"", ret0, value)
}
}

func TestSetValueByKey(t *testing.T) {
// test tx_count_limit
testSetValueByKey(t, "tx_count_limit", "30000000")

// test tx_gas_limit
testSetValueByKey(t, "tx_gas_limit", "3000000000")

// test rpbft_epoch_sealer_num
//testSetValueByKey(t, "rpbft_epoch_sealer_num", "20")

// test rpbft_epoch_block_num
//testSetValueByKey(t, "rpbft_epoch_block_num", "100")
}
t.Logf("TestGetValueByKey ret0: %v", ret0)
}
2 changes: 1 addition & 1 deletion precompiled/consensus/Consensus.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: Apache-2.0
pragma solidity ^0.6.0;
pragma solidity >=0.6.10 <0.8.20;

contract ConsensusPrecompiled {
function addSealer(string memory,uint256) public returns (int32){}
Expand Down
Loading
Loading