test(contracts): revise contracts tests
This commit is contained in:
parent
06ced08775
commit
6d97564b5c
20
go.mod
20
go.mod
|
@ -11,13 +11,11 @@ require (
|
|||
github.com/cpuguy83/go-md2man/v2 v2.0.0 // indirect
|
||||
github.com/ethereum/go-ethereum v1.9.18
|
||||
github.com/fatih/color v1.7.0
|
||||
github.com/fsnotify/fsnotify v1.4.9 // indirect
|
||||
github.com/gobuffalo/envy v1.9.0 // indirect
|
||||
github.com/gobuffalo/packd v1.0.0
|
||||
github.com/gobuffalo/packr v1.30.1
|
||||
github.com/gogo/protobuf v1.3.2
|
||||
github.com/golang/mock v1.5.0
|
||||
github.com/golang/protobuf v1.4.3 // indirect
|
||||
github.com/google/btree v1.0.0
|
||||
github.com/grpc-ecosystem/go-grpc-middleware v1.2.2
|
||||
github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0
|
||||
|
@ -29,15 +27,12 @@ require (
|
|||
github.com/magiconair/properties v1.8.4
|
||||
github.com/meshplus/bitxhub-core v0.1.0-rc1.0.20210408091239-7e5f1c49f9cb
|
||||
github.com/meshplus/bitxhub-kit v1.1.2-0.20210112075018-319e668d6359
|
||||
github.com/meshplus/bitxhub-model v1.1.2-0.20210309053945-afaea82e9fe1
|
||||
github.com/meshplus/bitxid v0.0.0-20210331074321-62187b1145f5
|
||||
github.com/meshplus/did-registry v0.0.0-20210407092831-8da970934f93
|
||||
github.com/meshplus/bitxhub-model v1.1.2-0.20210409090411-de23bd385c5f
|
||||
github.com/meshplus/did-registry v0.0.0-20210412063954-3a6aab1c683e
|
||||
github.com/meshplus/bitxid v0.0.0-20210412025850-e0eaf0f9063a
|
||||
github.com/meshplus/did-registry v0.0.0-20210413035015-509c6c3a0bae
|
||||
github.com/meshplus/go-libp2p-cert v0.0.0-20210125063330-7c25fd5b7a49
|
||||
github.com/meshplus/go-lightp2p v0.0.0-20210120082108-df5a536a6192
|
||||
github.com/mitchellh/go-homedir v1.1.0
|
||||
github.com/mitchellh/mapstructure v1.4.1 // indirect
|
||||
github.com/multiformats/go-multiaddr v0.3.0
|
||||
github.com/orcaman/concurrent-map v0.0.0-20190826125027-8c72a8bb44f6
|
||||
github.com/pelletier/go-toml v1.8.1
|
||||
|
@ -45,13 +40,10 @@ require (
|
|||
github.com/prometheus/client_golang v1.5.0
|
||||
github.com/rogpeppe/go-internal v1.8.0 // indirect
|
||||
github.com/rs/cors v1.7.0
|
||||
github.com/spf13/afero v1.5.1 // indirect
|
||||
github.com/sirupsen/logrus v1.8.1
|
||||
github.com/spf13/cast v1.3.1
|
||||
github.com/spf13/jwalterweatherman v1.1.0 // indirect
|
||||
github.com/spf13/viper v1.7.1
|
||||
github.com/stretchr/testify v1.6.1
|
||||
github.com/sykesm/zap-logfmt v0.0.4 // indirect
|
||||
github.com/syndtr/goleveldb v1.0.1-0.20190923125748-758128399b1d
|
||||
github.com/tidwall/gjson v1.6.8
|
||||
github.com/tmc/grpc-websocket-proxy v0.0.0-20190109142713-0ad062ec5ee5
|
||||
|
@ -60,15 +52,7 @@ require (
|
|||
github.com/willf/bitset v1.1.11 // indirect
|
||||
github.com/willf/bloom v2.0.3+incompatible
|
||||
go.uber.org/atomic v1.7.0
|
||||
go.uber.org/multierr v1.6.0 // indirect
|
||||
go.uber.org/zap v1.16.0 // indirect
|
||||
golang.org/x/net v0.0.0-20201110031124-69a78807bb2b // indirect
|
||||
golang.org/x/sys v0.0.0-20210119212857-b64e53b001e4 // indirect
|
||||
golang.org/x/text v0.3.5 // indirect
|
||||
google.golang.org/genproto v0.0.0-20201119123407-9b1e624d6bc4 // indirect
|
||||
google.golang.org/grpc v1.33.2
|
||||
gopkg.in/ini.v1 v1.62.0 // indirect
|
||||
gopkg.in/yaml.v2 v2.4.0 // indirect
|
||||
)
|
||||
|
||||
replace github.com/golang/protobuf => github.com/golang/protobuf v1.3.2
|
||||
|
|
8
go.sum
8
go.sum
|
@ -682,8 +682,8 @@ github.com/mattn/goveralls v0.0.2/go.mod h1:8d1ZMHsd7fW6IRPKQh46F2WRpyib5/X4FOpe
|
|||
github.com/matttproud/golang_protobuf_extensions v1.0.1 h1:4hp9jkHxhMHkqkrB3Ix0jegS5sx/RkqARlsWZ6pIwiU=
|
||||
github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0=
|
||||
github.com/meshplus/bitxhub-core v0.1.0-rc1.0.20210318102029-494ee3060b0c/go.mod h1:G19Wrz1u66UmwaES/iLM19jmlv3APAZ5qfYOlNnIIZw=
|
||||
github.com/meshplus/bitxhub-core v0.1.0-rc1.0.20210330035001-b327cf056572 h1:kKcS6taPdH8fOi8kU35ciUlk5cbYCyKa4QbA+04OQ4s=
|
||||
github.com/meshplus/bitxhub-core v0.1.0-rc1.0.20210330035001-b327cf056572/go.mod h1:G19Wrz1u66UmwaES/iLM19jmlv3APAZ5qfYOlNnIIZw=
|
||||
github.com/meshplus/bitxhub-core v0.1.0-rc1.0.20210408091239-7e5f1c49f9cb h1:2wL8uQHsyRGnubKYLub3AhKuFF0M5RSblUKIOR/5mHE=
|
||||
github.com/meshplus/bitxhub-core v0.1.0-rc1.0.20210408091239-7e5f1c49f9cb/go.mod h1:G19Wrz1u66UmwaES/iLM19jmlv3APAZ5qfYOlNnIIZw=
|
||||
github.com/meshplus/bitxhub-kit v1.1.1 h1:vkPO88oA3+Kpc0N8lIgfj/U52KBuI+633hPbMYt1xm8=
|
||||
github.com/meshplus/bitxhub-kit v1.1.1/go.mod h1:r4l4iqn0RPJreb/OmoYKfjCjQJrXpZX++6Qc31VG/1k=
|
||||
github.com/meshplus/bitxhub-kit v1.1.2-0.20201021105954-468d0a9d7957/go.mod h1:r4l4iqn0RPJreb/OmoYKfjCjQJrXpZX++6Qc31VG/1k=
|
||||
|
@ -698,8 +698,8 @@ github.com/meshplus/bitxhub-model v1.1.2-0.20210409090411-de23bd385c5f h1:fGDz6C
|
|||
github.com/meshplus/bitxhub-model v1.1.2-0.20210409090411-de23bd385c5f/go.mod h1:x3H+TL24wcByzHegenLfs+5PQkQGNsk8eCm31QJMa+Q=
|
||||
github.com/meshplus/bitxid v0.0.0-20210412025850-e0eaf0f9063a h1:c4ESPDa60Jd4zfzZIGGTyzhfaVM3vKN+xV2G9BwIDGQ=
|
||||
github.com/meshplus/bitxid v0.0.0-20210412025850-e0eaf0f9063a/go.mod h1:vAldSRfDe2Qo7exsSTbchVmZWXPY7fhWQrRw18QJHho=
|
||||
github.com/meshplus/did-registry v0.0.0-20210412063954-3a6aab1c683e h1:1g5GC8rtS0IBJDlXnbWizHFpjfc44WgoUu7+fRs53wI=
|
||||
github.com/meshplus/did-registry v0.0.0-20210412063954-3a6aab1c683e/go.mod h1:tNbFVcS1TX5hnn+2o42byYK/W1cMnYuLdaCPFr+9Umk=
|
||||
github.com/meshplus/did-registry v0.0.0-20210413035015-509c6c3a0bae h1:E4iaFwHAg1ScyiU9Bz3RY0wjfXNZzPH3O43DBTl9iWg=
|
||||
github.com/meshplus/did-registry v0.0.0-20210413035015-509c6c3a0bae/go.mod h1:tNbFVcS1TX5hnn+2o42byYK/W1cMnYuLdaCPFr+9Umk=
|
||||
github.com/meshplus/go-libp2p-cert v0.0.0-20210120021632-1578cf63e06a h1:eg1BDjSOsz3cdH49kPE8c2XnIFlLTPEMJLqpofV/OEY=
|
||||
github.com/meshplus/go-libp2p-cert v0.0.0-20210120021632-1578cf63e06a/go.mod h1:rS4AYMqKypLn2IPEnHICP//V2v16SZo4CWUbwMdihl0=
|
||||
github.com/meshplus/go-libp2p-cert v0.0.0-20210125063330-7c25fd5b7a49 h1:F8dpLJZW6FxqinAQcZKTkoymZgxnqlNvTebNqWVMEYI=
|
||||
|
|
|
@ -69,7 +69,7 @@ func (am *AppchainManager) Manager(des string, proposalResult string, extra []by
|
|||
}
|
||||
|
||||
return am.CrossInvoke(constant.MethodRegistryContractAddr.String(), "Register",
|
||||
pb.String(chain.OwnerDID), pb.String(chain.ID),
|
||||
pb.String(relaychainAdmin), pb.String(chain.ID),
|
||||
pb.String(chain.DidDocAddr), pb.Bytes([]byte(chain.DidDocHash)), pb.Bytes(nil))
|
||||
case appchainMgr.EventUpdate:
|
||||
return responseWrapper(am.AppchainManager.UpdateAppchain(chain.ID, chain.OwnerDID,
|
||||
|
@ -123,8 +123,8 @@ func (am *AppchainManager) Register(appchainAdminDID, appchainMethod string, doc
|
|||
}
|
||||
|
||||
// UpdateAppchain updates available appchain
|
||||
func (am *AppchainManager) UpdateAppchain(appchainMethod, validators string, consensusType, chainType,
|
||||
name, desc, version, pubkey, docAddr, docHash string) *boltvm.Response {
|
||||
func (am *AppchainManager) UpdateAppchain(appchainMethod, docAddr, docHash, validators string, consensusType, chainType,
|
||||
name, desc, version, pubkey string) *boltvm.Response {
|
||||
am.AppchainManager.Persister = am.Stub
|
||||
if ok, data := am.AppchainManager.ChangeStatus(appchainMethod, appchainMgr.EventUpdate); !ok {
|
||||
return boltvm.Error(string(data))
|
||||
|
|
|
@ -5,8 +5,8 @@ import (
|
|||
"encoding/base64"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"strings"
|
||||
"strconv"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
|
@ -41,11 +41,8 @@ func TestAppchainManager_Appchain(t *testing.T) {
|
|||
mockCtl := gomock.NewController(t)
|
||||
mockStub := mock_stub.NewMockStub(mockCtl)
|
||||
|
||||
addr0 := types.NewAddress([]byte{0}).String()
|
||||
addr1 := types.NewAddress([]byte{1}).String()
|
||||
|
||||
chain := &appchainMgr.Appchain{
|
||||
ID: addr0,
|
||||
ID: appchainMethod,
|
||||
Name: "appchain A",
|
||||
Validators: "",
|
||||
ConsensusType: "",
|
||||
|
@ -58,9 +55,6 @@ func TestAppchainManager_Appchain(t *testing.T) {
|
|||
data, err := json.Marshal(chain)
|
||||
assert.Nil(t, err)
|
||||
|
||||
o1 := mockStub.EXPECT().Caller().Return(addr0)
|
||||
o2 := mockStub.EXPECT().Caller().Return(addr1)
|
||||
gomock.InOrder(o1, o2)
|
||||
mockStub.EXPECT().Get("appchain-"+appchainMethod).Return(true, data)
|
||||
mockStub.EXPECT().Get("appchain-"+appchainMethod2).Return(false, nil)
|
||||
|
||||
|
@ -87,7 +81,7 @@ func TestAppchainManager_Appchains(t *testing.T) {
|
|||
|
||||
chain := &appchainMgr.Appchain{
|
||||
Status: appchainMgr.AppchainAvailable,
|
||||
ID: addr,
|
||||
ID: appchainMethod,
|
||||
Name: "appchain" + addr,
|
||||
Validators: "",
|
||||
ConsensusType: "",
|
||||
|
@ -113,17 +107,23 @@ func TestAppchainManager_Appchains(t *testing.T) {
|
|||
mockStub.EXPECT().SetObject(gomock.Any(), gomock.Any()).Return().AnyTimes()
|
||||
mockStub.EXPECT().Logger().Return(logger).AnyTimes()
|
||||
|
||||
applyResponse := &boltvm.Response{
|
||||
Ok: true,
|
||||
Result: []byte("OK"),
|
||||
}
|
||||
// test for register
|
||||
mockStub.EXPECT().Caller().Return(caller).AnyTimes()
|
||||
mockStub.EXPECT().SetObject(gomock.Any(), gomock.Any()).Return().AnyTimes()
|
||||
mockStub.EXPECT().Logger().Return(logger).AnyTimes()
|
||||
|
||||
// test for register
|
||||
mockStub.EXPECT().CrossInvoke(constant.InterchainContractAddr.String(), "Register", pb.String(appchainMethod)).Return(registerResponse)
|
||||
mockStub.EXPECT().CrossInvoke(constant.MethodRegistryContractAddr.String(), "Register",
|
||||
gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(registerResponse)
|
||||
mockStub.EXPECT().Has(AppchainKey(appchainMethod)).Return(false).MaxTimes(3)
|
||||
am.Register(appchainAdminDID, appchainMethod, fakeSig, docAddr, docHash,
|
||||
chains[0].Validators, chains[0].ConsensusType, chains[0].ChainType,
|
||||
mockStub.EXPECT().Get(gomock.Any()).Return(true, chainsData[0]).AnyTimes()
|
||||
mockStub.EXPECT().CrossInvoke(constant.GovernanceContractAddr.String(), "SubmitProposal", gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(boltvm.Success(nil))
|
||||
mockStub.EXPECT().Has(AppchainKey(caller)).Return(false).MaxTimes(3)
|
||||
am.Register(chains[0].Validators, chains[0].ConsensusType, chains[0].ChainType,
|
||||
mockStub.EXPECT().CrossInvoke(constant.MethodRegistryContractAddr.String(), "Apply",
|
||||
gomock.Any(), gomock.Any(), gomock.Any()).Return(applyResponse)
|
||||
mockStub.EXPECT().Has(AppchainKey(appchainMethod)).Return(false).MaxTimes(3)
|
||||
am.Register(appchainAdminDID, appchainMethod, docAddr, docHash,
|
||||
chains[0].Validators, chains[0].ConsensusType, chains[0].ChainType,
|
||||
chains[0].Name, chains[0].Desc, chains[0].Version, chains[0].PublicKey)
|
||||
|
||||
appchainsReq1 := mockStub.EXPECT().Query(appchainMgr.PREFIX).Return(true, chainsData)
|
||||
|
@ -158,42 +158,6 @@ func TestAppchainManager_Appchains(t *testing.T) {
|
|||
func TestAppchainManager_Register(t *testing.T) {
|
||||
am, mockStub, chains, chainsData := prepare(t)
|
||||
|
||||
func TestApply(t *testing.T) {
|
||||
am, mockStub, _, _ := prepare(t)
|
||||
// test for Apply
|
||||
mockStub.EXPECT().Caller().Return(caller).AnyTimes()
|
||||
|
||||
approveRes := &boltvm.Response{
|
||||
Ok: true,
|
||||
Result: []byte("true"),
|
||||
}
|
||||
mockStub.EXPECT().CrossInvoke(constant.MethodRegistryContractAddr.String(), "Apply",
|
||||
pb.String(appchainAdminDID), pb.String(appchainMethod), pb.Bytes(fakeSig)).Return(approveRes)
|
||||
//mockStub.EXPECT().GetObject(gomock.Any(), gomock.Any()).Return(true).AnyTimes()
|
||||
|
||||
res := am.Apply(appchainAdminDID, appchainMethod, fakeSig)
|
||||
assert.Equal(t, true, res.Ok)
|
||||
}
|
||||
|
||||
func TestAuditApply(t *testing.T) {
|
||||
am, mockStub, _, _ := prepare(t)
|
||||
// test for Apply
|
||||
mockStub.EXPECT().Caller().Return(caller).AnyTimes()
|
||||
|
||||
approveRes := &boltvm.Response{
|
||||
Ok: true,
|
||||
Result: []byte("true"),
|
||||
}
|
||||
mockStub.EXPECT().CrossInvoke(constant.MethodRegistryContractAddr.String(), "AuditApply",
|
||||
pb.String(relayAdminDID), pb.String(appchainMethod), pb.Int32(1), pb.Bytes(fakeSig)).Return(approveRes)
|
||||
mockStub.EXPECT().CrossInvoke(constant.RoleContractAddr.String(), "IsAdmin", gomock.Any()).Return(approveRes)
|
||||
|
||||
res := am.AuditApply(relayAdminDID, appchainMethod, 1, fakeSig)
|
||||
assert.Equal(t, true, res.Ok)
|
||||
}
|
||||
|
||||
func TestAudit(t *testing.T) {
|
||||
am, mockStub, _, _ := prepare(t)
|
||||
logger := log.NewWithModule("contracts")
|
||||
|
||||
mockStub.EXPECT().Caller().Return(caller).AnyTimes()
|
||||
|
@ -207,18 +171,51 @@ func TestAudit(t *testing.T) {
|
|||
mockStub.EXPECT().SetObject(gomock.Any(), gomock.Any()).Return().AnyTimes()
|
||||
mockStub.EXPECT().Logger().Return(logger).AnyTimes()
|
||||
mockStub.EXPECT().CrossInvoke(constant.GovernanceContractAddr.String(), "SubmitProposal", gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(boltvm.Success(nil))
|
||||
mockStub.EXPECT().Has(AppchainKey(caller)).Return(false).Times(1)
|
||||
mockStub.EXPECT().Has(AppchainKey(caller)).Return(true).AnyTimes()
|
||||
res := am.Register(chains[0].Validators, chains[0].ConsensusType, chains[0].ChainType,
|
||||
mockStub.EXPECT().CrossInvoke(constant.MethodRegistryContractAddr.String(), "Apply",
|
||||
gomock.Any(), gomock.Any(), gomock.Any()).Return(boltvm.Success(nil))
|
||||
mockStub.EXPECT().Has(AppchainKey(appchainMethod)).Return(false).Times(1)
|
||||
mockStub.EXPECT().Has(AppchainKey(appchainMethod)).Return(true).AnyTimes()
|
||||
res := am.Register(appchainAdminDID, appchainMethod, docAddr, docHash,
|
||||
chains[0].Validators, chains[0].ConsensusType, chains[0].ChainType,
|
||||
chains[0].Name, chains[0].Desc, chains[0].Version, chains[0].PublicKey)
|
||||
assert.True(t, res.Ok)
|
||||
|
||||
// test for repeated register
|
||||
am.Register(chains[0].Validators, chains[0].ConsensusType, chains[0].ChainType,
|
||||
am.Register(appchainAdminDID, appchainMethod, docAddr, docHash,
|
||||
chains[0].Validators, chains[0].ConsensusType, chains[0].ChainType,
|
||||
chains[0].Name, chains[0].Desc, chains[0].Version, chains[0].PublicKey)
|
||||
assert.True(t, res.Ok)
|
||||
}
|
||||
|
||||
//func TestAudit(t *testing.T) {
|
||||
// am, mockStub, _, _ := prepare(t)
|
||||
// logger := log.NewWithModule("contracts")
|
||||
//
|
||||
// mockStub.EXPECT().Caller().Return(caller).AnyTimes()
|
||||
// mockStub.EXPECT().Get(gomock.Any()).Return(true, chainsData[0]).AnyTimes()
|
||||
// mockStub.EXPECT().GetObject(gomock.Any(), gomock.Any()).Do(
|
||||
// func(key string, ret interface{}) bool {
|
||||
// chain := ret.(*appchainMgr.Appchain)
|
||||
// chain.ID = chains[0].ID
|
||||
// return true
|
||||
// }).Return(true).AnyTimes()
|
||||
// mockStub.EXPECT().SetObject(gomock.Any(), gomock.Any()).Return().AnyTimes()
|
||||
// mockStub.EXPECT().Logger().Return(logger).AnyTimes()
|
||||
// mockStub.EXPECT().CrossInvoke(constant.GovernanceContractAddr.String(), "SubmitProposal", gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(boltvm.Success(nil))
|
||||
// mockStub.EXPECT().Has(AppchainKey(caller)).Return(false).Times(1)
|
||||
// mockStub.EXPECT().Has(AppchainKey(caller)).Return(true).AnyTimes()
|
||||
// res := am.Register(appchainAdminDID, appchainMethod, docAddr, docHash,
|
||||
// chains[0].Validators, chains[0].ConsensusType, chains[0].ChainType,
|
||||
// chains[0].Name, chains[0].Desc, chains[0].Version, chains[0].PublicKey)
|
||||
// assert.True(t, res.Ok)
|
||||
//
|
||||
// // test for repeated register
|
||||
// am.Register(appchainAdminDID, appchainMethod, docAddr, docHash,
|
||||
// chains[0].Validators, chains[0].ConsensusType, chains[0].ChainType,
|
||||
// chains[0].Name, chains[0].Desc, chains[0].Version, chains[0].PublicKey)
|
||||
// assert.True(t, res.Ok)
|
||||
//}
|
||||
|
||||
func TestAppchainManager_Manager(t *testing.T) {
|
||||
mockCtl := gomock.NewController(t)
|
||||
mockStub := mock_stub.NewMockStub(mockCtl)
|
||||
|
@ -228,7 +225,7 @@ func TestAppchainManager_Manager(t *testing.T) {
|
|||
|
||||
chain := &appchainMgr.Appchain{
|
||||
Status: appchainMgr.AppchainUpdating,
|
||||
ID: "addr",
|
||||
ID: appchainMethod,
|
||||
Name: "appchain A",
|
||||
Validators: "",
|
||||
ConsensusType: "",
|
||||
|
@ -242,7 +239,7 @@ func TestAppchainManager_Manager(t *testing.T) {
|
|||
|
||||
chain1 := &appchainMgr.Appchain{
|
||||
Status: appchainMgr.AppchainUpdating,
|
||||
ID: "addr1",
|
||||
ID: appchainMethod2,
|
||||
Name: "appchain A",
|
||||
Validators: "",
|
||||
ConsensusType: "",
|
||||
|
@ -254,15 +251,20 @@ func TestAppchainManager_Manager(t *testing.T) {
|
|||
data1, err := json.Marshal(chain1)
|
||||
assert.Nil(t, err)
|
||||
|
||||
mockStub.EXPECT().Get(AppchainKey("addr")).Return(true, data).AnyTimes()
|
||||
mockStub.EXPECT().Get(AppchainKey("addr1")).Return(false, nil).AnyTimes()
|
||||
mockStub.EXPECT().Has(AppchainKey("addr")).Return(true).AnyTimes()
|
||||
mockStub.EXPECT().Has(AppchainKey("addr1")).Return(false).AnyTimes()
|
||||
mockStub.EXPECT().Caller().Return(caller).AnyTimes()
|
||||
mockStub.EXPECT().Get(AppchainKey(appchainMethod)).Return(true, data).AnyTimes()
|
||||
mockStub.EXPECT().Get(AppchainKey(appchainMethod2)).Return(false, nil).AnyTimes()
|
||||
mockStub.EXPECT().Has(AppchainKey(appchainMethod)).Return(true).AnyTimes()
|
||||
mockStub.EXPECT().Has(AppchainKey(appchainMethod2)).Return(false).AnyTimes()
|
||||
mockStub.EXPECT().SetObject(gomock.Any(), gomock.Any()).Return().AnyTimes()
|
||||
mockStub.EXPECT().CurrentCaller().Return("addrNotAdmin").Times(1)
|
||||
mockStub.EXPECT().CurrentCaller().Return(constant.GovernanceContractAddr.String()).AnyTimes()
|
||||
mockStub.EXPECT().CrossInvoke(constant.RoleContractAddr.String(), "CheckPermission", gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(boltvm.Error("")).Times(1)
|
||||
mockStub.EXPECT().CrossInvoke(constant.RoleContractAddr.String(), "CheckPermission", gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(boltvm.Success(nil)).AnyTimes()
|
||||
mockStub.EXPECT().CrossInvoke(constant.MethodRegistryContractAddr.String(), "AuditApply",
|
||||
gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(boltvm.Success(nil))
|
||||
mockStub.EXPECT().CrossInvoke(constant.MethodRegistryContractAddr.String(), "Register",
|
||||
gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(boltvm.Success(nil))
|
||||
|
||||
// test without permission
|
||||
res := am.Manager(appchainMgr.EventUpdate, string(APPOVED), data)
|
||||
|
@ -308,29 +310,29 @@ func TestManageChain(t *testing.T) {
|
|||
mockStub.EXPECT().Caller().Return(caller).AnyTimes()
|
||||
mockStub.EXPECT().CurrentCaller().Return(caller).AnyTimes()
|
||||
mockStub.EXPECT().Has(gomock.Any()).Return(true).AnyTimes()
|
||||
mockStub.EXPECT().Has(AppchainKey(appchainMethod)).Return(true)
|
||||
mockStub.EXPECT().SetObject(gomock.Any(), gomock.Any()).Return().AnyTimes()
|
||||
mockStub.EXPECT().Logger().Return(logger).AnyTimes()
|
||||
mockStub.EXPECT().Get(AppchainKey(caller)).Return(true, chainsData[0]).AnyTimes()
|
||||
mockStub.EXPECT().Get(AppchainKey("freezingChain")).Return(true, chainsData[1]).AnyTimes()
|
||||
mockStub.EXPECT().Get(AppchainKey(appchainMethod)).Return(true, chainsData[0]).AnyTimes()
|
||||
mockStub.EXPECT().Get(AppchainKey(appchainMethod2)).Return(true, chainsData[1]).AnyTimes()
|
||||
mockStub.EXPECT().CrossInvoke(constant.GovernanceContractAddr.String(), "SubmitProposal", gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(boltvm.Success(nil)).AnyTimes()
|
||||
mockStub.EXPECT().CrossInvoke(constant.RoleContractAddr.String(), "CheckPermission", gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(boltvm.Success(nil)).AnyTimes()
|
||||
|
||||
// test UpdateAppchain
|
||||
res := am.UpdateAppchain(chains[0].Validators, chains[0].ConsensusType, chains[0].ChainType,
|
||||
// test UpdateAppchain without register
|
||||
mockStub.EXPECT().GetObject(AppchainKey(appchainMethod), gomock.Any()).Return(true)
|
||||
res := am.UpdateAppchain(appchainMethod, chains[0].Validators, chains[0].ConsensusType, chains[0].ChainType,
|
||||
res := am.UpdateAppchain(appchainMethod, docAddr, docHash,
|
||||
chains[0].Validators, chains[0].ConsensusType, chains[0].ChainType,
|
||||
chains[0].Name, chains[0].Desc, chains[0].Version, chains[0].PublicKey)
|
||||
res = am.UpdateAppchain(appchainMethod, docAddr, docHash,
|
||||
chains[0].Validators, chains[0].ConsensusType, chains[0].ChainType,
|
||||
chains[0].Name, chains[0].Desc, chains[0].Version, chains[0].PublicKey)
|
||||
assert.Equal(t, true, res.Ok, string(res.Result))
|
||||
// test FreezeAppchain
|
||||
res = am.FreezeAppchain(caller)
|
||||
res = am.FreezeAppchain(appchainMethod)
|
||||
assert.Equal(t, true, res.Ok, string(res.Result))
|
||||
// test ActivateAppchain
|
||||
res = am.ActivateAppchain("freezingChain")
|
||||
res = am.ActivateAppchain(appchainMethod2)
|
||||
assert.Equal(t, true, res.Ok, string(res.Result))
|
||||
// test LogoutAppchain
|
||||
res = am.LogoutAppchain()
|
||||
res = am.LogoutAppchain(appchainMethod)
|
||||
assert.Equal(t, true, res.Ok, string(res.Result))
|
||||
}
|
||||
|
||||
|
@ -341,18 +343,6 @@ func TestManageChain_WithoutPermission(t *testing.T) {
|
|||
mockStub.EXPECT().CrossInvoke(constant.GovernanceContractAddr.String(), "SubmitProposal", gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(boltvm.Success(nil)).AnyTimes()
|
||||
mockStub.EXPECT().CrossInvoke(constant.RoleContractAddr.String(), "CheckPermission", gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(boltvm.Error("")).AnyTimes()
|
||||
|
||||
assert.Equal(t, false, res.Ok)
|
||||
// test UpdateAppchain with register
|
||||
mockStub.EXPECT().Has(AppchainKey(appchainMethod)).Return(true)
|
||||
mockStub.EXPECT().GetObject(gomock.Any(), gomock.Any()).Do(
|
||||
func(key string, ret interface{}) bool {
|
||||
chain := ret.(*appchainMgr.Appchain)
|
||||
chain.Status = appchainMgr.APPROVED
|
||||
chain.PublicKey = chains[0].PublicKey
|
||||
assert.Equal(t, key, AppchainKey(appchainMethod))
|
||||
return true
|
||||
})
|
||||
res = am.UpdateAppchain(appchainMethod, chains[0].Validators, chains[0].ConsensusType, chains[0].ChainType,
|
||||
// test FreezeAppchain
|
||||
res := am.FreezeAppchain("addr")
|
||||
assert.Equal(t, false, res.Ok, string(res.Result))
|
||||
|
@ -363,6 +353,37 @@ func TestManageChain_WithoutPermission(t *testing.T) {
|
|||
assert.Equal(t, false, res.Ok, string(res.Result))
|
||||
}
|
||||
|
||||
//func TestManageChain_WithoutPermission(t *testing.T) {
|
||||
// am, mockStub, _, _ := prepare(t)
|
||||
// mockStub.EXPECT().Caller().Return(caller).AnyTimes()
|
||||
// mockStub.EXPECT().CurrentCaller().Return(caller).AnyTimes()
|
||||
// mockStub.EXPECT().CrossInvoke(constant.GovernanceContractAddr.String(), "SubmitProposal", gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(boltvm.Success(nil)).AnyTimes()
|
||||
// mockStub.EXPECT().CrossInvoke(constant.RoleContractAddr.String(), "CheckPermission", gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(boltvm.Error("")).AnyTimes()
|
||||
//
|
||||
// assert.Equal(t, false, res.Ok)
|
||||
// // test UpdateAppchain with register
|
||||
// mockStub.EXPECT().Has(AppchainKey(appchainMethod)).Return(true)
|
||||
// mockStub.EXPECT().GetObject(gomock.Any(), gomock.Any()).Do(
|
||||
// func(key string, ret interface{}) bool {
|
||||
// chain := ret.(*appchainMgr.Appchain)
|
||||
// chain.Status = appchainMgr.APPROVED
|
||||
// chain.PublicKey = chains[0].PublicKey
|
||||
// assert.Equal(t, key, AppchainKey(appchainMethod))
|
||||
// return true
|
||||
// })
|
||||
// res = am.UpdateAppchain(appchainMethod, docAddr, docHash,
|
||||
// chains[0].Validators, chains[0].ConsensusType, chains[0].ChainType,
|
||||
// chains[0].Name, chains[0].Desc, chains[0].Version, chains[0].PublicKey)
|
||||
// // test FreezeAppchain
|
||||
// res := am.FreezeAppchain("addr")
|
||||
// assert.Equal(t, false, res.Ok, string(res.Result))
|
||||
// res = am.FreezeAppchain("addr")
|
||||
// assert.Equal(t, false, res.Ok, string(res.Result))
|
||||
// // test ActivateAppchain
|
||||
// res = am.ActivateAppchain("addr")
|
||||
// assert.Equal(t, false, res.Ok, string(res.Result))
|
||||
//}
|
||||
|
||||
func TestManageChain_Error(t *testing.T) {
|
||||
am, mockStub, chains, _ := prepare(t)
|
||||
logger := log.NewWithModule("contracts")
|
||||
|
@ -375,7 +396,8 @@ func TestManageChain_Error(t *testing.T) {
|
|||
mockStub.EXPECT().CrossInvoke(constant.RoleContractAddr.String(), "CheckPermission", gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(boltvm.Success(nil)).AnyTimes()
|
||||
|
||||
// test UpdateAppchain
|
||||
res := am.UpdateAppchain(chains[0].Validators, chains[0].ConsensusType, chains[0].ChainType,
|
||||
res := am.UpdateAppchain(appchainMethod, docAddr, docHash,
|
||||
chains[0].Validators, chains[0].ConsensusType, chains[0].ChainType,
|
||||
chains[0].Name, chains[0].Desc, chains[0].Version, chains[0].PublicKey)
|
||||
assert.Equal(t, false, res.Ok, string(res.Result))
|
||||
// test FreezeAppchain
|
||||
|
@ -385,7 +407,7 @@ func TestManageChain_Error(t *testing.T) {
|
|||
res = am.ActivateAppchain(caller)
|
||||
assert.Equal(t, false, res.Ok, string(res.Result))
|
||||
// test LogoutAppchain
|
||||
res = am.LogoutAppchain()
|
||||
res = am.LogoutAppchain(caller)
|
||||
assert.Equal(t, false, res.Ok, string(res.Result))
|
||||
}
|
||||
|
||||
|
@ -423,11 +445,8 @@ func TestDeleteAppchain(t *testing.T) {
|
|||
mockStub.EXPECT().CrossInvoke(constant.InterchainContractAddr.String(), "DeleteInterchain",
|
||||
gomock.Any()).Return(approveRes).AnyTimes()
|
||||
mockStub.EXPECT().Delete(AppchainKey(caller)).Return()
|
||||
gomock.Any()).Return(approveRes)
|
||||
mockStub.EXPECT().CrossInvoke(constant.MethodRegistryContractAddr.String(), "Delete",
|
||||
gomock.Any(), gomock.Any(), gomock.Any()).Return(approveRes)
|
||||
mockStub.EXPECT().GetObject(AppchainKey(appchainMethod), gomock.Any()).Return(true)
|
||||
mockStub.EXPECT().Delete(AppchainKey(appchainMethod)).Return()
|
||||
gomock.Any(), gomock.Any(), gomock.Any()).Return(boltvm.Success(nil))
|
||||
|
||||
// judge caller type error
|
||||
res := am.DeleteAppchain(caller)
|
||||
|
@ -440,10 +459,50 @@ func TestDeleteAppchain(t *testing.T) {
|
|||
assert.Equal(t, false, res.Ok)
|
||||
|
||||
res = am.DeleteAppchain(caller)
|
||||
res := am.DeleteAppchain(relayAdminDID, appchainMethod, fakeSig)
|
||||
assert.Equal(t, true, res.Ok)
|
||||
}
|
||||
|
||||
//func TestDeleteAppchain(t *testing.T) {
|
||||
// am, mockStub, _, _ := prepare(t)
|
||||
//
|
||||
// approveRes := &boltvm.Response{
|
||||
// Ok: true,
|
||||
// Result: []byte("true"),
|
||||
// }
|
||||
// logger := log.NewWithModule("contracts")
|
||||
// // test for DeleteAppchain
|
||||
// mockStub.EXPECT().Caller().Return(caller).AnyTimes()
|
||||
// mockStub.EXPECT().SetObject(gomock.Any(), gomock.Any()).Return().AnyTimes()
|
||||
// mockStub.EXPECT().Logger().Return(logger).AnyTimes()
|
||||
// mockStub.EXPECT().CrossInvoke(constant.RoleContractAddr.String(), "IsAdmin", gomock.Any()).Return(boltvm.Success(nil)).Times(1)
|
||||
// mockStub.EXPECT().CrossInvoke(constant.RoleContractAddr.String(), "IsAdmin", gomock.Any()).Return(boltvm.Success([]byte(strconv.FormatBool(false)))).Times(1)
|
||||
// mockStub.EXPECT().CrossInvoke(constant.RoleContractAddr.String(), "IsAdmin", gomock.Any()).Return(approveRes).AnyTimes()
|
||||
// mockStub.EXPECT().CrossInvoke(constant.InterchainContractAddr.String(), "DeleteInterchain",
|
||||
// gomock.Any()).Return(boltvm.Error("")).Times(1)
|
||||
// mockStub.EXPECT().CrossInvoke(constant.InterchainContractAddr.String(), "DeleteInterchain",
|
||||
// gomock.Any()).Return(approveRes).AnyTimes()
|
||||
// mockStub.EXPECT().Delete(AppchainKey(caller)).Return()
|
||||
// gomock.Any()).Return(approveRes)
|
||||
// mockStub.EXPECT().CrossInvoke(constant.MethodRegistryContractAddr.String(), "Delete",
|
||||
// gomock.Any(), gomock.Any(), gomock.Any()).Return(approveRes)
|
||||
// mockStub.EXPECT().GetObject(AppchainKey(appchainMethod), gomock.Any()).Return(true)
|
||||
// mockStub.EXPECT().Delete(AppchainKey(appchainMethod)).Return()
|
||||
//
|
||||
// // judge caller type error
|
||||
// res := am.DeleteAppchain(caller)
|
||||
// assert.Equal(t, false, res.Ok)
|
||||
// // caller is not an admin account
|
||||
// res = am.DeleteAppchain(caller)
|
||||
// assert.Equal(t, false, res.Ok)
|
||||
// // CrossInvoke DeleteInterchain error
|
||||
// res = am.DeleteAppchain(caller)
|
||||
// assert.Equal(t, false, res.Ok)
|
||||
//
|
||||
// res = am.DeleteAppchain(caller)
|
||||
// res := am.DeleteAppchain(relayAdminDID, appchainMethod, fakeSig)
|
||||
// assert.Equal(t, true, res.Ok)
|
||||
//}
|
||||
|
||||
func TestGetPubKeyByChainID(t *testing.T) {
|
||||
am, mockStub, chains, _ := prepare(t)
|
||||
// test for GetPubKeyByChainID
|
||||
|
@ -473,7 +532,7 @@ func prepare(t *testing.T) (*AppchainManager, *mock_stub.MockStub, []*appchainMg
|
|||
var chainsData [][]byte
|
||||
chainType := []string{string(appchainMgr.AppchainAvailable), string(appchainMgr.AppchainFrozen)}
|
||||
for i := 0; i < 2; i++ {
|
||||
addr := types.NewAddress([]byte{byte(i)}).String()
|
||||
addr := appchainMethod + types.NewAddress([]byte{byte(i)}).String()
|
||||
|
||||
chain := &appchainMgr.Appchain{
|
||||
Status: appchainMgr.AppchainStatus(chainType[i]),
|
||||
|
@ -501,7 +560,6 @@ func TestInterchainManager_Register(t *testing.T) {
|
|||
mockCtl := gomock.NewController(t)
|
||||
mockStub := mock_stub.NewMockStub(mockCtl)
|
||||
|
||||
addr := types.NewAddress([]byte{0}).String()
|
||||
//mockStub.EXPECT().Caller().Return(addr).AnyTimes()
|
||||
mockStub.EXPECT().Set(gomock.Any(), gomock.Any()).AnyTimes()
|
||||
o1 := mockStub.EXPECT().Get(appchainMgr.PREFIX+appchainMethod).Return(false, nil)
|
||||
|
@ -533,7 +591,6 @@ func TestInterchainManager_Register(t *testing.T) {
|
|||
im := &InterchainManager{mockStub}
|
||||
|
||||
res := im.Register(appchainMethod)
|
||||
res := im.Register(addr)
|
||||
assert.Equal(t, true, res.Ok)
|
||||
|
||||
ic := &pb.Interchain{}
|
||||
|
@ -675,8 +732,9 @@ func TestInterchainManager_HandleIBTP(t *testing.T) {
|
|||
dstAppchain := &appchainMgr.Appchain{
|
||||
ID: appchainMethod2,
|
||||
Name: "Relay2",
|
||||
Status: appchainMgr.AppchainAvailable,
|
||||
Validators: "",
|
||||
ConsensusType: 0,
|
||||
ConsensusType: "raft",
|
||||
ChainType: "appchain",
|
||||
Desc: "Relay2",
|
||||
Version: "1",
|
||||
|
@ -686,8 +744,8 @@ func TestInterchainManager_HandleIBTP(t *testing.T) {
|
|||
assert.Nil(t, err)
|
||||
|
||||
// mockStub.EXPECT().IsRelayIBTP(gomock.Any()).Return(true).AnyTimes()
|
||||
mockStub.EXPECT().CrossInvoke(gomock.Any(), gomock.Eq("GetAppchain"), pb.String(appchainMethod)).Return(boltvm.Success(appchainData)).AnyTimes()
|
||||
mockStub.EXPECT().CrossInvoke(gomock.Any(), gomock.Eq("GetAppchain"), pb.String(appchainMethod2)).Return(boltvm.Success(dstAppchainData)).AnyTimes()
|
||||
mockStub.EXPECT().CrossInvoke(constant.AppchainMgrContractAddr.String(), gomock.Eq("GetAppchain"), pb.String(appchainMethod)).Return(boltvm.Success(appchainData)).AnyTimes()
|
||||
mockStub.EXPECT().CrossInvoke(constant.AppchainMgrContractAddr.String(), gomock.Eq("GetAppchain"), pb.String(appchainMethod2)).Return(boltvm.Success(dstAppchainData)).AnyTimes()
|
||||
mockStub.EXPECT().CrossInvoke(gomock.Any(), gomock.Not("GetAppchain"), gomock.Any()).Return(boltvm.Success(nil)).AnyTimes()
|
||||
mockStub.EXPECT().AddObject(gomock.Any(), gomock.Any()).AnyTimes()
|
||||
mockStub.EXPECT().GetTxIndex().Return(uint64(1)).AnyTimes()
|
||||
|
@ -717,7 +775,6 @@ func TestInterchainManager_HandleIBTP(t *testing.T) {
|
|||
Timestamp: 0,
|
||||
Proof: nil,
|
||||
Payload: nil,
|
||||
Version: "",
|
||||
}
|
||||
|
||||
mockStub.EXPECT().Caller().Return(from.String()).MaxTimes(7)
|
||||
|
@ -800,28 +857,6 @@ func TestInterchainManager_HandleIBTPs(t *testing.T) {
|
|||
mockCtl := gomock.NewController(t)
|
||||
mockStub := mock_stub.NewMockStub(mockCtl)
|
||||
|
||||
interchain := pb.Interchain{
|
||||
ID: appchainMethod,
|
||||
InterchainCounter: make(map[string]uint64),
|
||||
ReceiptCounter: make(map[string]uint64),
|
||||
SourceReceiptCounter: make(map[string]uint64),
|
||||
}
|
||||
interchain.InterchainCounter[appchainMethod2] = 1
|
||||
interchain.ReceiptCounter[appchainMethod2] = 1
|
||||
interchain.SourceReceiptCounter[appchainMethod2] = 1
|
||||
|
||||
mockStub.EXPECT().Has(gomock.Any()).Return(true).AnyTimes()
|
||||
mockStub.EXPECT().GetObject(gomock.Any(), gomock.Any()).Do(
|
||||
func(key string, ret interface{}) bool {
|
||||
assert.Equal(t, key, AppchainKey(appchainMethod))
|
||||
meta := ret.(*pb.Interchain)
|
||||
meta.ID = appchainMethod
|
||||
meta.SourceReceiptCounter = interchain.SourceReceiptCounter
|
||||
meta.ReceiptCounter = interchain.InterchainCounter
|
||||
meta.InterchainCounter = interchain.InterchainCounter
|
||||
return true
|
||||
}).AnyTimes()
|
||||
|
||||
fromPrivKey, err := asym.GenerateKeyPair(crypto.Secp256k1)
|
||||
assert.Nil(t, err)
|
||||
fromPubKey := fromPrivKey.PublicKey()
|
||||
|
@ -831,33 +866,38 @@ func TestInterchainManager_HandleIBTPs(t *testing.T) {
|
|||
assert.Nil(t, err)
|
||||
fromPubKeyBytes := base64.StdEncoding.EncodeToString(rawFromPubKeyBytes)
|
||||
|
||||
appchain := &appchainMgr.Appchain{
|
||||
ID: appchainMethod,
|
||||
Name: "Relay1",
|
||||
Validators: "",
|
||||
ConsensusType: 0,
|
||||
ChainType: "appchain",
|
||||
Desc: "Relay1",
|
||||
Version: "1",
|
||||
PublicKey: fromPubKeyBytes,
|
||||
to := types.NewAddress([]byte{1}).String()
|
||||
interchain := pb.Interchain{
|
||||
ID: appchainMethod,
|
||||
InterchainCounter: make(map[string]uint64),
|
||||
ReceiptCounter: make(map[string]uint64),
|
||||
SourceReceiptCounter: make(map[string]uint64),
|
||||
}
|
||||
appchainData, err := json.Marshal(appchain)
|
||||
require.Nil(t, err)
|
||||
interchain.InterchainCounter[to] = 1
|
||||
interchain.ReceiptCounter[to] = 1
|
||||
interchain.SourceReceiptCounter[to] = 1
|
||||
|
||||
mockStub.EXPECT().Caller().Return(from.String()).AnyTimes()
|
||||
mockStub.EXPECT().Has(gomock.Any()).Return(true).AnyTimes()
|
||||
mockStub.EXPECT().GetObject(gomock.Any(), gomock.Any()).Do(
|
||||
func(key string, ret interface{}) bool {
|
||||
assert.Equal(t, key, AppchainKey(caller))
|
||||
meta := ret.(*pb.Interchain)
|
||||
meta.ID = caller
|
||||
meta.SourceReceiptCounter = interchain.SourceReceiptCounter
|
||||
meta.ReceiptCounter = interchain.InterchainCounter
|
||||
meta.InterchainCounter = interchain.InterchainCounter
|
||||
return true
|
||||
}).AnyTimes()
|
||||
|
||||
mockStub.EXPECT().Set(gomock.Any(), gomock.Any()).AnyTimes()
|
||||
mockStub.EXPECT().SetObject(gomock.Any(), gomock.Any()).AnyTimes()
|
||||
f1 := mockStub.EXPECT().Get(appchainMgr.PREFIX+appchainMethod).Return(false, nil)
|
||||
|
||||
data0, err := interchain.Marshal()
|
||||
assert.Nil(t, err)
|
||||
|
||||
f2 := mockStub.EXPECT().Get(appchainMgr.PREFIX+appchainMethod).Return(true, data0).AnyTimes()
|
||||
mockStub.EXPECT().Get(appchainMgr.PREFIX+appchainMethod2).Return(true, data0).AnyTimes()
|
||||
mockStub.EXPECT().CrossInvoke(constant.AppchainMgrContractAddr.String(), "GetAppchain", pb.String(appchainMethod)).Return(boltvm.Success(appchainData)).AnyTimes()
|
||||
mockStub.EXPECT().CrossInvoke(gomock.Any(), gomock.Any(), gomock.Any()).Return(boltvm.Success(nil)).AnyTimes()
|
||||
appchain := &appchainMgr.Appchain{
|
||||
ID: "",
|
||||
ID: appchainMethod,
|
||||
Name: "Relay1",
|
||||
Validators: "",
|
||||
ConsensusType: "",
|
||||
|
@ -865,15 +905,15 @@ func TestInterchainManager_HandleIBTPs(t *testing.T) {
|
|||
ChainType: "appchain",
|
||||
Desc: "Relay1",
|
||||
Version: "1",
|
||||
PublicKey: "",
|
||||
PublicKey: fromPubKeyBytes,
|
||||
}
|
||||
appchainData, err := json.Marshal(appchain)
|
||||
assert.Nil(t, err)
|
||||
|
||||
mockStub.EXPECT().Get(appchainMgr.PREFIX+caller).Return(true, data0).AnyTimes()
|
||||
mockStub.EXPECT().Get(appchainMgr.PREFIX+to).Return(true, data0).AnyTimes()
|
||||
mockStub.EXPECT().Get(appchainMgr.PREFIX+appchainMethod).Return(true, data0).AnyTimes()
|
||||
mockStub.EXPECT().Get(appchainMgr.PREFIX+appchainMethod2).Return(true, data0).AnyTimes()
|
||||
mockStub.EXPECT().CrossInvoke(constant.TransactionMgrContractAddr.String(), gomock.Any(), gomock.Any()).Return(boltvm.Success(nil)).AnyTimes()
|
||||
mockStub.EXPECT().CrossInvoke(constant.AppchainMgrContractAddr.String(), "GetAppchain", pb.String(caller)).Return(boltvm.Success(appchainData)).AnyTimes()
|
||||
mockStub.EXPECT().CrossInvoke(constant.AppchainMgrContractAddr.String(), "GetAppchain", pb.String(appchainMethod)).Return(boltvm.Success(appchainData)).AnyTimes()
|
||||
mockStub.EXPECT().AddObject(gomock.Any(), gomock.Any()).AnyTimes()
|
||||
mockStub.EXPECT().GetTxIndex().Return(uint64(1)).AnyTimes()
|
||||
mockStub.EXPECT().PostInterchainEvent(gomock.Any()).AnyTimes()
|
||||
|
@ -884,7 +924,7 @@ func TestInterchainManager_HandleIBTPs(t *testing.T) {
|
|||
ibtp := &pb.IBTP{
|
||||
From: appchainMethod,
|
||||
To: appchainMethod2,
|
||||
Index: 2,
|
||||
Index: 1,
|
||||
Type: pb.IBTP_INTERCHAIN,
|
||||
Timestamp: time.Now().UnixNano(),
|
||||
Proof: nil,
|
||||
|
@ -902,12 +942,121 @@ func TestInterchainManager_HandleIBTPs(t *testing.T) {
|
|||
data, err := ibtps.Marshal()
|
||||
assert.Nil(t, err)
|
||||
res := im.HandleIBTPs(data)
|
||||
//fmt.Printf("result is %v", string(res.Result))
|
||||
assert.Equal(t, true, res.Ok)
|
||||
fmt.Printf("result is %v", string(res.Result))
|
||||
assert.Equal(t, true, res.Ok, string(res.Result))
|
||||
}
|
||||
|
||||
//func TestInterchainManager_HandleIBTPs(t *testing.T) {
|
||||
// mockCtl := gomock.NewController(t)
|
||||
// mockStub := mock_stub.NewMockStub(mockCtl)
|
||||
//
|
||||
// interchain := pb.Interchain{
|
||||
// ID: appchainMethod,
|
||||
// InterchainCounter: make(map[string]uint64),
|
||||
// ReceiptCounter: make(map[string]uint64),
|
||||
// SourceReceiptCounter: make(map[string]uint64),
|
||||
// }
|
||||
// interchain.InterchainCounter[appchainMethod2] = 1
|
||||
// interchain.ReceiptCounter[appchainMethod2] = 1
|
||||
// interchain.SourceReceiptCounter[appchainMethod2] = 1
|
||||
//
|
||||
// mockStub.EXPECT().Has(gomock.Any()).Return(true).AnyTimes()
|
||||
// mockStub.EXPECT().GetObject(gomock.Any(), gomock.Any()).Do(
|
||||
// func(key string, ret interface{}) bool {
|
||||
// assert.Equal(t, key, AppchainKey(appchainMethod))
|
||||
// meta := ret.(*pb.Interchain)
|
||||
// meta.ID = appchainMethod
|
||||
// meta.SourceReceiptCounter = interchain.SourceReceiptCounter
|
||||
// meta.ReceiptCounter = interchain.InterchainCounter
|
||||
// meta.InterchainCounter = interchain.InterchainCounter
|
||||
// return true
|
||||
// }).AnyTimes()
|
||||
//
|
||||
// fromPrivKey, err := asym.GenerateKeyPair(crypto.Secp256k1)
|
||||
// assert.Nil(t, err)
|
||||
// fromPubKey := fromPrivKey.PublicKey()
|
||||
// from, err := fromPubKey.Address()
|
||||
// assert.Nil(t, err)
|
||||
// rawFromPubKeyBytes, err := fromPubKey.Bytes()
|
||||
// assert.Nil(t, err)
|
||||
// fromPubKeyBytes := base64.StdEncoding.EncodeToString(rawFromPubKeyBytes)
|
||||
//
|
||||
// appchain := &appchainMgr.Appchain{
|
||||
// ID: appchainMethod,
|
||||
// Name: "Relay1",
|
||||
// Validators: "",
|
||||
// ConsensusType: "raft",
|
||||
// ChainType: "appchain",
|
||||
// Desc: "Relay1",
|
||||
// Version: "1",
|
||||
// PublicKey: fromPubKeyBytes,
|
||||
// }
|
||||
// appchainData, err := json.Marshal(appchain)
|
||||
// require.Nil(t, err)
|
||||
//
|
||||
// mockStub.EXPECT().Caller().Return(from.String()).AnyTimes()
|
||||
// mockStub.EXPECT().Set(gomock.Any(), gomock.Any()).AnyTimes()
|
||||
// mockStub.EXPECT().SetObject(gomock.Any(), gomock.Any()).AnyTimes()
|
||||
// f1 := mockStub.EXPECT().Get(appchainMgr.PREFIX+appchainMethod).Return(false, nil)
|
||||
//
|
||||
// data0, err := interchain.Marshal()
|
||||
// assert.Nil(t, err)
|
||||
//
|
||||
// f2 := mockStub.EXPECT().Get(appchainMgr.PREFIX+appchainMethod).Return(true, data0).AnyTimes()
|
||||
// mockStub.EXPECT().Get(appchainMgr.PREFIX+appchainMethod2).Return(true, data0).AnyTimes()
|
||||
// mockStub.EXPECT().CrossInvoke(constant.AppchainMgrContractAddr.String(), "GetAppchain", pb.String(appchainMethod)).Return(boltvm.Success(appchainData)).AnyTimes()
|
||||
// mockStub.EXPECT().CrossInvoke(gomock.Any(), gomock.Any(), gomock.Any()).Return(boltvm.Success(nil)).AnyTimes()
|
||||
// appchain := &appchainMgr.Appchain{
|
||||
// ID: "",
|
||||
// Name: "Relay1",
|
||||
// Validators: "",
|
||||
// ConsensusType: "",
|
||||
// Status: appchainMgr.AppchainAvailable,
|
||||
// ChainType: "appchain",
|
||||
// Desc: "Relay1",
|
||||
// Version: "1",
|
||||
// PublicKey: "",
|
||||
// }
|
||||
// appchainData, err := json.Marshal(appchain)
|
||||
// assert.Nil(t, err)
|
||||
//
|
||||
// mockStub.EXPECT().Get(appchainMgr.PREFIX+caller).Return(true, data0).AnyTimes()
|
||||
// mockStub.EXPECT().Get(appchainMgr.PREFIX+to).Return(true, data0).AnyTimes()
|
||||
// mockStub.EXPECT().CrossInvoke(constant.TransactionMgrContractAddr.String(), gomock.Any(), gomock.Any()).Return(boltvm.Success(nil)).AnyTimes()
|
||||
// mockStub.EXPECT().CrossInvoke(constant.AppchainMgrContractAddr.String(), "GetAppchain", pb.String(caller)).Return(boltvm.Success(appchainData)).AnyTimes()
|
||||
// mockStub.EXPECT().AddObject(gomock.Any(), gomock.Any()).AnyTimes()
|
||||
// mockStub.EXPECT().GetTxIndex().Return(uint64(1)).AnyTimes()
|
||||
// mockStub.EXPECT().PostInterchainEvent(gomock.Any()).AnyTimes()
|
||||
// mockStub.EXPECT().GetTxHash().Return(&types.Hash{}).AnyTimes()
|
||||
//
|
||||
// im := &InterchainManager{mockStub}
|
||||
//
|
||||
// ibtp := &pb.IBTP{
|
||||
// From: appchainMethod,
|
||||
// To: appchainMethod2,
|
||||
// Index: 2,
|
||||
// Type: pb.IBTP_INTERCHAIN,
|
||||
// Timestamp: time.Now().UnixNano(),
|
||||
// Proof: nil,
|
||||
// Payload: nil,
|
||||
// Version: "",
|
||||
// }
|
||||
//
|
||||
// ibs := make([]*pb.IBTP, 0, 3)
|
||||
// for i := 0; i < 3; i++ {
|
||||
// ibs = append(ibs, ibtp)
|
||||
// }
|
||||
// ibtps := &pb.IBTPs{
|
||||
// Ibtps: ibs,
|
||||
// }
|
||||
// data, err := ibtps.Marshal()
|
||||
// assert.Nil(t, err)
|
||||
// res := im.HandleIBTPs(data)
|
||||
// //fmt.Printf("result is %v", string(res.Result))
|
||||
// assert.Equal(t, true, res.Ok)
|
||||
// fmt.Printf("result is %v", string(res.Result))
|
||||
// assert.Equal(t, true, res.Ok, string(res.Result))
|
||||
//}
|
||||
|
||||
func TestInterchainManager_HandleUnionIBTP(t *testing.T) {
|
||||
mockCtl := gomock.NewController(t)
|
||||
mockStub := mock_stub.NewMockStub(mockCtl)
|
||||
|
@ -930,12 +1079,9 @@ func TestInterchainManager_HandleUnionIBTP(t *testing.T) {
|
|||
assert.Nil(t, err)
|
||||
|
||||
relayChain := &appchainMgr.Appchain{
|
||||
Status: appchainMgr.APPROVED,
|
||||
Status: appchainMgr.AppchainAvailable,
|
||||
ID: appchainMethod,
|
||||
Name: "appchain" + appchainMethod,
|
||||
Status: appchainMgr.AppchainAvailable,
|
||||
ID: from,
|
||||
Name: "appchain" + from,
|
||||
Validators: "",
|
||||
ConsensusType: "",
|
||||
ChainType: "fabric",
|
||||
|
@ -964,9 +1110,8 @@ func TestInterchainManager_HandleUnionIBTP(t *testing.T) {
|
|||
data, err := json.Marshal(relayChain)
|
||||
assert.Nil(t, err)
|
||||
|
||||
mockStub.EXPECT().Get(appchainMgr.PREFIX+appchainMethod).Return(true, data0).AnyTimes()
|
||||
mockStub.EXPECT().Get(appchainMgr.PREFIX+appchainMethod+"-"+appchainMethod).Return(true, data0).AnyTimes()
|
||||
mockStub.EXPECT().Get(appchainMgr.PREFIX+from).Return(true, data0).AnyTimes()
|
||||
mockStub.EXPECT().Get(appchainMgr.PREFIX+from+"-"+from).Return(true, data0).AnyTimes()
|
||||
mockStub.EXPECT().CrossInvoke(gomock.Any(), gomock.Any(), gomock.Any()).Return(boltvm.Success(data)).AnyTimes()
|
||||
mockStub.EXPECT().AddObject(gomock.Any(), gomock.Any()).AnyTimes()
|
||||
mockStub.EXPECT().GetTxIndex().Return(uint64(1)).AnyTimes()
|
||||
|
|
|
@ -80,7 +80,6 @@ func (router *InterchainRouter) AddPier(key bitxid.DID, pierID string, isUnion b
|
|||
// return nil, fmt.Errorf("did %s for subscription is not exist", key)
|
||||
//}
|
||||
subBus := raw.(*event.Feed)
|
||||
router.logger.Errorf("feed addr is %v", subBus)
|
||||
sub := subBus.Subscribe(c)
|
||||
router.subscriptions.Store(pierID, sub)
|
||||
}
|
||||
|
|
|
@ -5,8 +5,6 @@
|
|||
package mock_peermgr
|
||||
|
||||
import (
|
||||
reflect "reflect"
|
||||
|
||||
event "github.com/ethereum/go-ethereum/event"
|
||||
gomock "github.com/golang/mock/gomock"
|
||||
peer "github.com/libp2p/go-libp2p-core/peer"
|
||||
|
@ -14,44 +12,61 @@ import (
|
|||
events "github.com/meshplus/bitxhub/internal/model/events"
|
||||
peermgr "github.com/meshplus/bitxhub/pkg/peermgr"
|
||||
network "github.com/meshplus/go-lightp2p"
|
||||
reflect "reflect"
|
||||
)
|
||||
|
||||
// MockPeerManager is a mock of PeerManager interface.
|
||||
// MockPeerManager is a mock of PeerManager interface
|
||||
type MockPeerManager struct {
|
||||
ctrl *gomock.Controller
|
||||
recorder *MockPeerManagerMockRecorder
|
||||
}
|
||||
|
||||
// MockPeerManagerMockRecorder is the mock recorder for MockPeerManager.
|
||||
// MockPeerManagerMockRecorder is the mock recorder for MockPeerManager
|
||||
type MockPeerManagerMockRecorder struct {
|
||||
mock *MockPeerManager
|
||||
}
|
||||
|
||||
// NewMockPeerManager creates a new mock instance.
|
||||
// NewMockPeerManager creates a new mock instance
|
||||
func NewMockPeerManager(ctrl *gomock.Controller) *MockPeerManager {
|
||||
mock := &MockPeerManager{ctrl: ctrl}
|
||||
mock.recorder = &MockPeerManagerMockRecorder{mock}
|
||||
return mock
|
||||
}
|
||||
|
||||
// EXPECT returns an object that allows the caller to indicate expected use.
|
||||
// EXPECT returns an object that allows the caller to indicate expected use
|
||||
func (m *MockPeerManager) EXPECT() *MockPeerManagerMockRecorder {
|
||||
return m.recorder
|
||||
}
|
||||
|
||||
// AddNode mocks base method.
|
||||
func (m *MockPeerManager) AddNode(newNodeID uint64, vpInfo *pb.VpInfo) {
|
||||
// Start mocks base method
|
||||
func (m *MockPeerManager) Start() error {
|
||||
m.ctrl.T.Helper()
|
||||
m.ctrl.Call(m, "AddNode", newNodeID, vpInfo)
|
||||
ret := m.ctrl.Call(m, "Start")
|
||||
ret0, _ := ret[0].(error)
|
||||
return ret0
|
||||
}
|
||||
|
||||
// AddNode indicates an expected call of AddNode.
|
||||
func (mr *MockPeerManagerMockRecorder) AddNode(newNodeID, vpInfo interface{}) *gomock.Call {
|
||||
// Start indicates an expected call of Start
|
||||
func (mr *MockPeerManagerMockRecorder) Start() *gomock.Call {
|
||||
mr.mock.ctrl.T.Helper()
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "AddNode", reflect.TypeOf((*MockPeerManager)(nil).AddNode), newNodeID, vpInfo)
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Start", reflect.TypeOf((*MockPeerManager)(nil).Start))
|
||||
}
|
||||
|
||||
// AsyncSend mocks base method.
|
||||
// Stop mocks base method
|
||||
func (m *MockPeerManager) Stop() error {
|
||||
m.ctrl.T.Helper()
|
||||
ret := m.ctrl.Call(m, "Stop")
|
||||
ret0, _ := ret[0].(error)
|
||||
return ret0
|
||||
}
|
||||
|
||||
// Stop indicates an expected call of Stop
|
||||
func (mr *MockPeerManagerMockRecorder) Stop() *gomock.Call {
|
||||
mr.mock.ctrl.T.Helper()
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Stop", reflect.TypeOf((*MockPeerManager)(nil).Stop))
|
||||
}
|
||||
|
||||
// AsyncSend mocks base method
|
||||
func (m *MockPeerManager) AsyncSend(arg0 uint64, arg1 *pb.Message) error {
|
||||
m.ctrl.T.Helper()
|
||||
ret := m.ctrl.Call(m, "AsyncSend", arg0, arg1)
|
||||
|
@ -59,107 +74,27 @@ func (m *MockPeerManager) AsyncSend(arg0 uint64, arg1 *pb.Message) error {
|
|||
return ret0
|
||||
}
|
||||
|
||||
// AsyncSend indicates an expected call of AsyncSend.
|
||||
// AsyncSend indicates an expected call of AsyncSend
|
||||
func (mr *MockPeerManagerMockRecorder) AsyncSend(arg0, arg1 interface{}) *gomock.Call {
|
||||
mr.mock.ctrl.T.Helper()
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "AsyncSend", reflect.TypeOf((*MockPeerManager)(nil).AsyncSend), arg0, arg1)
|
||||
}
|
||||
|
||||
// Broadcast mocks base method.
|
||||
func (m *MockPeerManager) Broadcast(arg0 *pb.Message) error {
|
||||
// SendWithStream mocks base method
|
||||
func (m *MockPeerManager) SendWithStream(arg0 network.Stream, arg1 *pb.Message) error {
|
||||
m.ctrl.T.Helper()
|
||||
ret := m.ctrl.Call(m, "Broadcast", arg0)
|
||||
ret := m.ctrl.Call(m, "SendWithStream", arg0, arg1)
|
||||
ret0, _ := ret[0].(error)
|
||||
return ret0
|
||||
}
|
||||
|
||||
// Broadcast indicates an expected call of Broadcast.
|
||||
func (mr *MockPeerManagerMockRecorder) Broadcast(arg0 interface{}) *gomock.Call {
|
||||
// SendWithStream indicates an expected call of SendWithStream
|
||||
func (mr *MockPeerManagerMockRecorder) SendWithStream(arg0, arg1 interface{}) *gomock.Call {
|
||||
mr.mock.ctrl.T.Helper()
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Broadcast", reflect.TypeOf((*MockPeerManager)(nil).Broadcast), arg0)
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SendWithStream", reflect.TypeOf((*MockPeerManager)(nil).SendWithStream), arg0, arg1)
|
||||
}
|
||||
|
||||
// CountConnectedPeers mocks base method.
|
||||
func (m *MockPeerManager) CountConnectedPeers() uint64 {
|
||||
m.ctrl.T.Helper()
|
||||
ret := m.ctrl.Call(m, "CountConnectedPeers")
|
||||
ret0, _ := ret[0].(uint64)
|
||||
return ret0
|
||||
}
|
||||
|
||||
// CountConnectedPeers indicates an expected call of CountConnectedPeers.
|
||||
func (mr *MockPeerManagerMockRecorder) CountConnectedPeers() *gomock.Call {
|
||||
mr.mock.ctrl.T.Helper()
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "CountConnectedPeers", reflect.TypeOf((*MockPeerManager)(nil).CountConnectedPeers))
|
||||
}
|
||||
|
||||
// DelNode mocks base method.
|
||||
func (m *MockPeerManager) DelNode(delID uint64) {
|
||||
m.ctrl.T.Helper()
|
||||
m.ctrl.Call(m, "DelNode", delID)
|
||||
}
|
||||
|
||||
// DelNode indicates an expected call of DelNode.
|
||||
func (mr *MockPeerManagerMockRecorder) DelNode(delID interface{}) *gomock.Call {
|
||||
mr.mock.ctrl.T.Helper()
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "DelNode", reflect.TypeOf((*MockPeerManager)(nil).DelNode), delID)
|
||||
}
|
||||
|
||||
// Disconnect mocks base method.
|
||||
func (m *MockPeerManager) Disconnect(vpInfos map[uint64]*pb.VpInfo) {
|
||||
m.ctrl.T.Helper()
|
||||
m.ctrl.Call(m, "Disconnect", vpInfos)
|
||||
}
|
||||
|
||||
// Disconnect indicates an expected call of Disconnect.
|
||||
func (mr *MockPeerManagerMockRecorder) Disconnect(vpInfos interface{}) *gomock.Call {
|
||||
mr.mock.ctrl.T.Helper()
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Disconnect", reflect.TypeOf((*MockPeerManager)(nil).Disconnect), vpInfos)
|
||||
}
|
||||
|
||||
// OtherPeers mocks base method.
|
||||
func (m *MockPeerManager) OtherPeers() map[uint64]*peer.AddrInfo {
|
||||
m.ctrl.T.Helper()
|
||||
ret := m.ctrl.Call(m, "OtherPeers")
|
||||
ret0, _ := ret[0].(map[uint64]*peer.AddrInfo)
|
||||
return ret0
|
||||
}
|
||||
|
||||
// OtherPeers indicates an expected call of OtherPeers.
|
||||
func (mr *MockPeerManagerMockRecorder) OtherPeers() *gomock.Call {
|
||||
mr.mock.ctrl.T.Helper()
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "OtherPeers", reflect.TypeOf((*MockPeerManager)(nil).OtherPeers))
|
||||
}
|
||||
|
||||
// Peers mocks base method.
|
||||
func (m *MockPeerManager) Peers() map[uint64]*pb.VpInfo {
|
||||
m.ctrl.T.Helper()
|
||||
ret := m.ctrl.Call(m, "Peers")
|
||||
ret0, _ := ret[0].(map[uint64]*pb.VpInfo)
|
||||
return ret0
|
||||
}
|
||||
|
||||
// Peers indicates an expected call of Peers.
|
||||
func (mr *MockPeerManagerMockRecorder) Peers() *gomock.Call {
|
||||
mr.mock.ctrl.T.Helper()
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Peers", reflect.TypeOf((*MockPeerManager)(nil).Peers))
|
||||
}
|
||||
|
||||
// PierManager mocks base method.
|
||||
func (m *MockPeerManager) PierManager() peermgr.PierManager {
|
||||
m.ctrl.T.Helper()
|
||||
ret := m.ctrl.Call(m, "PierManager")
|
||||
ret0, _ := ret[0].(peermgr.PierManager)
|
||||
return ret0
|
||||
}
|
||||
|
||||
// PierManager indicates an expected call of PierManager.
|
||||
func (mr *MockPeerManagerMockRecorder) PierManager() *gomock.Call {
|
||||
mr.mock.ctrl.T.Helper()
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "PierManager", reflect.TypeOf((*MockPeerManager)(nil).PierManager))
|
||||
}
|
||||
|
||||
// Send mocks base method.
|
||||
// Send mocks base method
|
||||
func (m *MockPeerManager) Send(arg0 uint64, arg1 *pb.Message) (*pb.Message, error) {
|
||||
m.ctrl.T.Helper()
|
||||
ret := m.ctrl.Call(m, "Send", arg0, arg1)
|
||||
|
@ -168,55 +103,69 @@ func (m *MockPeerManager) Send(arg0 uint64, arg1 *pb.Message) (*pb.Message, erro
|
|||
return ret0, ret1
|
||||
}
|
||||
|
||||
// Send indicates an expected call of Send.
|
||||
// Send indicates an expected call of Send
|
||||
func (mr *MockPeerManagerMockRecorder) Send(arg0, arg1 interface{}) *gomock.Call {
|
||||
mr.mock.ctrl.T.Helper()
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Send", reflect.TypeOf((*MockPeerManager)(nil).Send), arg0, arg1)
|
||||
}
|
||||
|
||||
// SendWithStream mocks base method.
|
||||
func (m *MockPeerManager) SendWithStream(arg0 network.Stream, arg1 *pb.Message) error {
|
||||
// Broadcast mocks base method
|
||||
func (m *MockPeerManager) Broadcast(arg0 *pb.Message) error {
|
||||
m.ctrl.T.Helper()
|
||||
ret := m.ctrl.Call(m, "SendWithStream", arg0, arg1)
|
||||
ret := m.ctrl.Call(m, "Broadcast", arg0)
|
||||
ret0, _ := ret[0].(error)
|
||||
return ret0
|
||||
}
|
||||
|
||||
// SendWithStream indicates an expected call of SendWithStream.
|
||||
func (mr *MockPeerManagerMockRecorder) SendWithStream(arg0, arg1 interface{}) *gomock.Call {
|
||||
// Broadcast indicates an expected call of Broadcast
|
||||
func (mr *MockPeerManagerMockRecorder) Broadcast(arg0 interface{}) *gomock.Call {
|
||||
mr.mock.ctrl.T.Helper()
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SendWithStream", reflect.TypeOf((*MockPeerManager)(nil).SendWithStream), arg0, arg1)
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Broadcast", reflect.TypeOf((*MockPeerManager)(nil).Broadcast), arg0)
|
||||
}
|
||||
|
||||
// Start mocks base method.
|
||||
func (m *MockPeerManager) Start() error {
|
||||
// CountConnectedPeers mocks base method
|
||||
func (m *MockPeerManager) CountConnectedPeers() uint64 {
|
||||
m.ctrl.T.Helper()
|
||||
ret := m.ctrl.Call(m, "Start")
|
||||
ret0, _ := ret[0].(error)
|
||||
ret := m.ctrl.Call(m, "CountConnectedPeers")
|
||||
ret0, _ := ret[0].(uint64)
|
||||
return ret0
|
||||
}
|
||||
|
||||
// Start indicates an expected call of Start.
|
||||
func (mr *MockPeerManagerMockRecorder) Start() *gomock.Call {
|
||||
// CountConnectedPeers indicates an expected call of CountConnectedPeers
|
||||
func (mr *MockPeerManagerMockRecorder) CountConnectedPeers() *gomock.Call {
|
||||
mr.mock.ctrl.T.Helper()
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Start", reflect.TypeOf((*MockPeerManager)(nil).Start))
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "CountConnectedPeers", reflect.TypeOf((*MockPeerManager)(nil).CountConnectedPeers))
|
||||
}
|
||||
|
||||
// Stop mocks base method.
|
||||
func (m *MockPeerManager) Stop() error {
|
||||
// Peers mocks base method
|
||||
func (m *MockPeerManager) Peers() map[uint64]*pb.VpInfo {
|
||||
m.ctrl.T.Helper()
|
||||
ret := m.ctrl.Call(m, "Stop")
|
||||
ret0, _ := ret[0].(error)
|
||||
ret := m.ctrl.Call(m, "Peers")
|
||||
ret0, _ := ret[0].(map[uint64]*pb.VpInfo)
|
||||
return ret0
|
||||
}
|
||||
|
||||
// Stop indicates an expected call of Stop.
|
||||
func (mr *MockPeerManagerMockRecorder) Stop() *gomock.Call {
|
||||
// Peers indicates an expected call of Peers
|
||||
func (mr *MockPeerManagerMockRecorder) Peers() *gomock.Call {
|
||||
mr.mock.ctrl.T.Helper()
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Stop", reflect.TypeOf((*MockPeerManager)(nil).Stop))
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Peers", reflect.TypeOf((*MockPeerManager)(nil).Peers))
|
||||
}
|
||||
|
||||
// SubscribeOrderMessage mocks base method.
|
||||
// OtherPeers mocks base method
|
||||
func (m *MockPeerManager) OtherPeers() map[uint64]*peer.AddrInfo {
|
||||
m.ctrl.T.Helper()
|
||||
ret := m.ctrl.Call(m, "OtherPeers")
|
||||
ret0, _ := ret[0].(map[uint64]*peer.AddrInfo)
|
||||
return ret0
|
||||
}
|
||||
|
||||
// OtherPeers indicates an expected call of OtherPeers
|
||||
func (mr *MockPeerManagerMockRecorder) OtherPeers() *gomock.Call {
|
||||
mr.mock.ctrl.T.Helper()
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "OtherPeers", reflect.TypeOf((*MockPeerManager)(nil).OtherPeers))
|
||||
}
|
||||
|
||||
// SubscribeOrderMessage mocks base method
|
||||
func (m *MockPeerManager) SubscribeOrderMessage(ch chan<- events.OrderMessageEvent) event.Subscription {
|
||||
m.ctrl.T.Helper()
|
||||
ret := m.ctrl.Call(m, "SubscribeOrderMessage", ch)
|
||||
|
@ -224,13 +173,37 @@ func (m *MockPeerManager) SubscribeOrderMessage(ch chan<- events.OrderMessageEve
|
|||
return ret0
|
||||
}
|
||||
|
||||
// SubscribeOrderMessage indicates an expected call of SubscribeOrderMessage.
|
||||
// SubscribeOrderMessage indicates an expected call of SubscribeOrderMessage
|
||||
func (mr *MockPeerManagerMockRecorder) SubscribeOrderMessage(ch interface{}) *gomock.Call {
|
||||
mr.mock.ctrl.T.Helper()
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SubscribeOrderMessage", reflect.TypeOf((*MockPeerManager)(nil).SubscribeOrderMessage), ch)
|
||||
}
|
||||
|
||||
// UpdateRouter mocks base method.
|
||||
// AddNode mocks base method
|
||||
func (m *MockPeerManager) AddNode(newNodeID uint64, vpInfo *pb.VpInfo) {
|
||||
m.ctrl.T.Helper()
|
||||
m.ctrl.Call(m, "AddNode", newNodeID, vpInfo)
|
||||
}
|
||||
|
||||
// AddNode indicates an expected call of AddNode
|
||||
func (mr *MockPeerManagerMockRecorder) AddNode(newNodeID, vpInfo interface{}) *gomock.Call {
|
||||
mr.mock.ctrl.T.Helper()
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "AddNode", reflect.TypeOf((*MockPeerManager)(nil).AddNode), newNodeID, vpInfo)
|
||||
}
|
||||
|
||||
// DelNode mocks base method
|
||||
func (m *MockPeerManager) DelNode(delID uint64) {
|
||||
m.ctrl.T.Helper()
|
||||
m.ctrl.Call(m, "DelNode", delID)
|
||||
}
|
||||
|
||||
// DelNode indicates an expected call of DelNode
|
||||
func (mr *MockPeerManagerMockRecorder) DelNode(delID interface{}) *gomock.Call {
|
||||
mr.mock.ctrl.T.Helper()
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "DelNode", reflect.TypeOf((*MockPeerManager)(nil).DelNode), delID)
|
||||
}
|
||||
|
||||
// UpdateRouter mocks base method
|
||||
func (m *MockPeerManager) UpdateRouter(vpInfos map[uint64]*pb.VpInfo, isNew bool) bool {
|
||||
m.ctrl.T.Helper()
|
||||
ret := m.ctrl.Call(m, "UpdateRouter", vpInfos, isNew)
|
||||
|
@ -238,36 +211,76 @@ func (m *MockPeerManager) UpdateRouter(vpInfos map[uint64]*pb.VpInfo, isNew bool
|
|||
return ret0
|
||||
}
|
||||
|
||||
// UpdateRouter indicates an expected call of UpdateRouter.
|
||||
// UpdateRouter indicates an expected call of UpdateRouter
|
||||
func (mr *MockPeerManagerMockRecorder) UpdateRouter(vpInfos, isNew interface{}) *gomock.Call {
|
||||
mr.mock.ctrl.T.Helper()
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "UpdateRouter", reflect.TypeOf((*MockPeerManager)(nil).UpdateRouter), vpInfos, isNew)
|
||||
}
|
||||
|
||||
// MockPierManager is a mock of PierManager interface.
|
||||
// Disconnect mocks base method
|
||||
func (m *MockPeerManager) Disconnect(vpInfos map[uint64]*pb.VpInfo) {
|
||||
m.ctrl.T.Helper()
|
||||
m.ctrl.Call(m, "Disconnect", vpInfos)
|
||||
}
|
||||
|
||||
// Disconnect indicates an expected call of Disconnect
|
||||
func (mr *MockPeerManagerMockRecorder) Disconnect(vpInfos interface{}) *gomock.Call {
|
||||
mr.mock.ctrl.T.Helper()
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Disconnect", reflect.TypeOf((*MockPeerManager)(nil).Disconnect), vpInfos)
|
||||
}
|
||||
|
||||
// PierManager mocks base method
|
||||
func (m *MockPeerManager) PierManager() peermgr.PierManager {
|
||||
m.ctrl.T.Helper()
|
||||
ret := m.ctrl.Call(m, "PierManager")
|
||||
ret0, _ := ret[0].(peermgr.PierManager)
|
||||
return ret0
|
||||
}
|
||||
|
||||
// PierManager indicates an expected call of PierManager
|
||||
func (mr *MockPeerManagerMockRecorder) PierManager() *gomock.Call {
|
||||
mr.mock.ctrl.T.Helper()
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "PierManager", reflect.TypeOf((*MockPeerManager)(nil).PierManager))
|
||||
}
|
||||
|
||||
// MockPierManager is a mock of PierManager interface
|
||||
type MockPierManager struct {
|
||||
ctrl *gomock.Controller
|
||||
recorder *MockPierManagerMockRecorder
|
||||
}
|
||||
|
||||
// MockPierManagerMockRecorder is the mock recorder for MockPierManager.
|
||||
// MockPierManagerMockRecorder is the mock recorder for MockPierManager
|
||||
type MockPierManagerMockRecorder struct {
|
||||
mock *MockPierManager
|
||||
}
|
||||
|
||||
// NewMockPierManager creates a new mock instance.
|
||||
// NewMockPierManager creates a new mock instance
|
||||
func NewMockPierManager(ctrl *gomock.Controller) *MockPierManager {
|
||||
mock := &MockPierManager{ctrl: ctrl}
|
||||
mock.recorder = &MockPierManagerMockRecorder{mock}
|
||||
return mock
|
||||
}
|
||||
|
||||
// EXPECT returns an object that allows the caller to indicate expected use.
|
||||
// EXPECT returns an object that allows the caller to indicate expected use
|
||||
func (m *MockPierManager) EXPECT() *MockPierManagerMockRecorder {
|
||||
return m.recorder
|
||||
}
|
||||
|
||||
// AskPierMaster mocks base method.
|
||||
// Piers mocks base method
|
||||
func (m *MockPierManager) Piers() *peermgr.Piers {
|
||||
m.ctrl.T.Helper()
|
||||
ret := m.ctrl.Call(m, "Piers")
|
||||
ret0, _ := ret[0].(*peermgr.Piers)
|
||||
return ret0
|
||||
}
|
||||
|
||||
// Piers indicates an expected call of Piers
|
||||
func (mr *MockPierManagerMockRecorder) Piers() *gomock.Call {
|
||||
mr.mock.ctrl.T.Helper()
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Piers", reflect.TypeOf((*MockPierManager)(nil).Piers))
|
||||
}
|
||||
|
||||
// AskPierMaster mocks base method
|
||||
func (m *MockPierManager) AskPierMaster(arg0 string) (bool, error) {
|
||||
m.ctrl.T.Helper()
|
||||
ret := m.ctrl.Call(m, "AskPierMaster", arg0)
|
||||
|
@ -276,22 +289,8 @@ func (m *MockPierManager) AskPierMaster(arg0 string) (bool, error) {
|
|||
return ret0, ret1
|
||||
}
|
||||
|
||||
// AskPierMaster indicates an expected call of AskPierMaster.
|
||||
// AskPierMaster indicates an expected call of AskPierMaster
|
||||
func (mr *MockPierManagerMockRecorder) AskPierMaster(arg0 interface{}) *gomock.Call {
|
||||
mr.mock.ctrl.T.Helper()
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "AskPierMaster", reflect.TypeOf((*MockPierManager)(nil).AskPierMaster), arg0)
|
||||
}
|
||||
|
||||
// Piers mocks base method.
|
||||
func (m *MockPierManager) Piers() *peermgr.Piers {
|
||||
m.ctrl.T.Helper()
|
||||
ret := m.ctrl.Call(m, "Piers")
|
||||
ret0, _ := ret[0].(*peermgr.Piers)
|
||||
return ret0
|
||||
}
|
||||
|
||||
// Piers indicates an expected call of Piers.
|
||||
func (mr *MockPierManagerMockRecorder) Piers() *gomock.Call {
|
||||
mr.mock.ctrl.T.Helper()
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Piers", reflect.TypeOf((*MockPierManager)(nil).Piers))
|
||||
}
|
||||
|
|
|
@ -2,85 +2,36 @@ package boltvm
|
|||
|
||||
import (
|
||||
"encoding/json"
|
||||
"strconv"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/golang/mock/gomock"
|
||||
appchain_mgr "github.com/meshplus/bitxhub-core/appchain-mgr"
|
||||
"github.com/meshplus/bitxhub-core/agency"
|
||||
"github.com/meshplus/bitxhub-core/validator/mock_validator"
|
||||
"github.com/meshplus/bitxhub-kit/log"
|
||||
"github.com/meshplus/bitxhub/internal/ledger/mock_ledger"
|
||||
"github.com/meshplus/bitxhub/internal/repo"
|
||||
"github.com/meshplus/bitxhub/pkg/vm"
|
||||
|
||||
"github.com/meshplus/bitxhub-core/agency"
|
||||
"github.com/meshplus/bitxhub-kit/types"
|
||||
"github.com/meshplus/bitxhub-model/constant"
|
||||
"github.com/meshplus/bitxhub-model/pb"
|
||||
"github.com/meshplus/bitxhub/internal/executor/contracts"
|
||||
"github.com/meshplus/bitxhub/internal/ledger/mock_ledger"
|
||||
"github.com/meshplus/bitxhub/pkg/vm"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
const (
|
||||
from = "0x3f9d18f7C3a6E5E4C0B877FE3E688aB08840b997"
|
||||
to = "0x000018f7C3A6E5E4c0b877fe3E688ab08840b997"
|
||||
admin1 = "0xc7F999b83Af6DF9e67d0a37Ee7e900bF38b3D013"
|
||||
admin2 = "0x79a1215469FaB6f9c63c1816b45183AD3624bE34"
|
||||
admin3 = "0x97c8B516D19edBf575D72a172Af7F418BE498C37"
|
||||
from = "0x3f9d18f7C3a6E5E4C0B877FE3E688aB08840b997"
|
||||
to = "0x000018f7C3A6E5E4c0b877fe3E688ab08840b997"
|
||||
)
|
||||
|
||||
func GetBoltContracts() map[string]agency.Contract {
|
||||
boltContracts := []*BoltContract{
|
||||
{
|
||||
Enabled: true,
|
||||
Name: "interchain manager contract",
|
||||
Address: constant.InterchainContractAddr.Address().String(),
|
||||
Contract: &contracts.InterchainManager{},
|
||||
},
|
||||
{
|
||||
Enabled: true,
|
||||
Name: "store service",
|
||||
Address: constant.StoreContractAddr.Address().String(),
|
||||
Contract: &contracts.Store{},
|
||||
},
|
||||
{
|
||||
Enabled: true,
|
||||
Name: "rule manager service",
|
||||
Address: constant.RuleManagerContractAddr.Address().String(),
|
||||
Contract: &contracts.RuleManager{},
|
||||
},
|
||||
{
|
||||
Enabled: true,
|
||||
Name: "role manager service",
|
||||
Address: constant.RoleContractAddr.Address().String(),
|
||||
Contract: &contracts.Role{},
|
||||
},
|
||||
{
|
||||
Enabled: true,
|
||||
Name: "appchain manager service",
|
||||
Address: constant.AppchainMgrContractAddr.Address().String(),
|
||||
Contract: &contracts.AppchainManager{},
|
||||
},
|
||||
{
|
||||
Enabled: true,
|
||||
Name: "transaction manager service",
|
||||
Address: constant.TransactionMgrContractAddr.Address().String(),
|
||||
Contract: &contracts.TransactionManager{},
|
||||
},
|
||||
{
|
||||
Enabled: true,
|
||||
Name: "asset exchange service",
|
||||
Address: constant.AssetExchangeContractAddr.Address().String(),
|
||||
Contract: &contracts.AssetExchange{},
|
||||
},
|
||||
{
|
||||
Enabled: true,
|
||||
Name: "governance service",
|
||||
Address: constant.GovernanceContractAddr.Address().String(),
|
||||
Contract: &contracts.Governance{},
|
||||
},
|
||||
}
|
||||
|
||||
ContractsInfo := agency.GetRegisteredContractInfo()
|
||||
|
@ -97,7 +48,7 @@ func GetBoltContracts() map[string]agency.Contract {
|
|||
|
||||
func TestRegister(t *testing.T) {
|
||||
registers := GetBoltContracts()
|
||||
require.Equal(t, len(registers), 8)
|
||||
require.Equal(t, len(registers), 1)
|
||||
|
||||
contract, err := GetBoltContract(constant.StoreContractAddr.Address().String(), registers)
|
||||
require.Nil(t, err)
|
||||
|
@ -125,6 +76,7 @@ func TestBoltVM_Run(t *testing.T) {
|
|||
mockEngine := mock_validator.NewMockEngine(ctr)
|
||||
mockLedger := mock_ledger.NewMockLedger(ctr)
|
||||
|
||||
cons := GetBoltContracts()
|
||||
data := make([][]byte, 0)
|
||||
data = append(data, []byte("1"))
|
||||
proposalData, err := json.Marshal(&contracts.Proposal{
|
||||
|
@ -134,50 +86,6 @@ func TestBoltVM_Run(t *testing.T) {
|
|||
proposals := make([][]byte, 0)
|
||||
proposals = append(proposals, proposalData)
|
||||
|
||||
admins := make([]*repo.Admin, 0)
|
||||
admins = append(admins, &repo.Admin{
|
||||
Address: admin1,
|
||||
Weight: uint64(1),
|
||||
})
|
||||
admins = append(admins, &repo.Admin{
|
||||
Address: admin2,
|
||||
Weight: uint64(1),
|
||||
})
|
||||
admins = append(admins, &repo.Admin{
|
||||
Address: admin3,
|
||||
Weight: uint64(1),
|
||||
})
|
||||
adminsData, err := json.Marshal(admins)
|
||||
require.Nil(t, err)
|
||||
|
||||
chainRegisting := &appchain_mgr.Appchain{
|
||||
Status: appchain_mgr.AppchainRegisting,
|
||||
ID: from,
|
||||
Name: "appchain A",
|
||||
Validators: "",
|
||||
ConsensusType: "rbft",
|
||||
ChainType: "fabric",
|
||||
Desc: "",
|
||||
Version: "",
|
||||
PublicKey: "11111",
|
||||
}
|
||||
chainRegistingData, err := json.Marshal(chainRegisting)
|
||||
require.Nil(t, err)
|
||||
|
||||
chainAvailable := &appchain_mgr.Appchain{
|
||||
Status: appchain_mgr.AppchainAvailable,
|
||||
ID: from,
|
||||
Name: "appchain A",
|
||||
Validators: "",
|
||||
ConsensusType: "rbft",
|
||||
ChainType: "fabric",
|
||||
Desc: "",
|
||||
Version: "",
|
||||
PublicKey: "11111",
|
||||
}
|
||||
chainAvailableData, err := json.Marshal(chainAvailable)
|
||||
require.Nil(t, err)
|
||||
|
||||
interchain := &pb.Interchain{
|
||||
ID: from,
|
||||
InterchainCounter: make(map[string]uint64),
|
||||
|
@ -186,66 +94,7 @@ func TestBoltVM_Run(t *testing.T) {
|
|||
}
|
||||
interchainData, err := interchain.Marshal()
|
||||
require.Nil(t, err)
|
||||
|
||||
mockLedger.EXPECT().QueryByPrefix(gomock.Any(), contracts.PROPOSAL_PREFIX).Return(true, proposals).AnyTimes()
|
||||
mockLedger.EXPECT().QueryByPrefix(gomock.Any(), appchain_mgr.PREFIX).Return(true, data).AnyTimes()
|
||||
mockLedger.EXPECT().GetState(gomock.Any(), gomock.Any()).DoAndReturn(func(addr *types.Address, key []byte) (bool, []byte) {
|
||||
switch addr.String() {
|
||||
case constant.AppchainMgrContractAddr.Address().String():
|
||||
return false, nil
|
||||
case constant.InterchainContractAddr.Address().String():
|
||||
return false, nil
|
||||
case constant.RoleContractAddr.Address().String():
|
||||
return true, adminsData
|
||||
}
|
||||
return false, nil
|
||||
}).Times(1)
|
||||
mockLedger.EXPECT().GetState(gomock.Any(), gomock.Any()).DoAndReturn(func(addr *types.Address, key []byte) (bool, []byte) {
|
||||
switch addr.String() {
|
||||
case constant.AppchainMgrContractAddr.Address().String():
|
||||
return true, chainRegistingData
|
||||
case constant.InterchainContractAddr.Address().String():
|
||||
return false, nil
|
||||
case constant.RoleContractAddr.Address().String():
|
||||
return true, adminsData
|
||||
case constant.GovernanceContractAddr.Address().String():
|
||||
return true, nil
|
||||
}
|
||||
return true, nil
|
||||
}).Times(5)
|
||||
mockLedger.EXPECT().GetState(gomock.Any(), gomock.Any()).DoAndReturn(func(addr *types.Address, key []byte) (bool, []byte) {
|
||||
switch addr.String() {
|
||||
case constant.AppchainMgrContractAddr.Address().String():
|
||||
return true, chainAvailableData
|
||||
case constant.InterchainContractAddr.Address().String():
|
||||
return true, interchainData
|
||||
case constant.RoleContractAddr.Address().String():
|
||||
return true, adminsData
|
||||
case constant.GovernanceContractAddr.Address().String():
|
||||
return true, nil
|
||||
}
|
||||
return true, nil
|
||||
}).AnyTimes()
|
||||
mockLedger.EXPECT().AddState(gomock.Any(), gomock.Any(), gomock.Any()).AnyTimes()
|
||||
mockLedger.EXPECT().SetState(gomock.Any(), gomock.Any(), gomock.Any()).AnyTimes()
|
||||
mockLedger.EXPECT().AddEvent(gomock.Any()).AnyTimes()
|
||||
|
||||
tx := &pb.Transaction{
|
||||
From: types.NewAddressByStr(from),
|
||||
To: constant.AppchainMgrContractAddr.Address(),
|
||||
}
|
||||
tx.TransactionHash = tx.Hash()
|
||||
ctx := vm.NewContext(tx, 1, nil, mockLedger, log.NewWithModule("vm"))
|
||||
boltVM := New(ctx, mockEngine, GetBoltContracts())
|
||||
|
||||
// create Governance boltVM
|
||||
txGovernance := &pb.Transaction{
|
||||
From: types.NewAddressByStr(constant.GovernanceContractAddr.String()),
|
||||
To: constant.AppchainMgrContractAddr.Address(),
|
||||
}
|
||||
txGovernance.TransactionHash = txGovernance.Hash()
|
||||
ctxGovernance := vm.NewContext(txGovernance, 1, nil, mockLedger, log.NewWithModule("vm"))
|
||||
boltVMGovernance := New(ctxGovernance, mockEngine, GetBoltContracts())
|
||||
print(interchainData)
|
||||
|
||||
// create Interchain boltVM
|
||||
txInterchain := &pb.Transaction{
|
||||
|
@ -254,117 +103,11 @@ func TestBoltVM_Run(t *testing.T) {
|
|||
}
|
||||
txInterchain.TransactionHash = txInterchain.Hash()
|
||||
ctxInterchain := vm.NewContext(txInterchain, 1, nil, mockLedger, log.NewWithModule("vm"))
|
||||
boltVMInterchain := New(ctxInterchain, mockEngine, GetBoltContracts())
|
||||
|
||||
ip := &pb.InvokePayload{
|
||||
Method: "CountAppchains",
|
||||
}
|
||||
input, err := ip.Marshal()
|
||||
require.Nil(t, err)
|
||||
|
||||
ret, err := boltVM.Run(input)
|
||||
require.Nil(t, err)
|
||||
require.Equal(t, "1", string(ret))
|
||||
|
||||
ip = &pb.InvokePayload{
|
||||
Method: "GetAppchain",
|
||||
Args: []*pb.Arg{
|
||||
{
|
||||
Type: pb.Arg_U64,
|
||||
Value: []byte(strconv.Itoa(1)),
|
||||
},
|
||||
{
|
||||
Type: pb.Arg_Bytes,
|
||||
Value: []byte(strconv.Itoa(1)),
|
||||
},
|
||||
},
|
||||
}
|
||||
input, err = ip.Marshal()
|
||||
require.Nil(t, err)
|
||||
ret, err = boltVM.Run(input)
|
||||
require.NotNil(t, err)
|
||||
|
||||
//validators string, consensusType int32, chainType, name, desc, version, pubkey string
|
||||
ip = &pb.InvokePayload{
|
||||
Method: "Register",
|
||||
Args: []*pb.Arg{
|
||||
{
|
||||
Type: pb.Arg_String,
|
||||
Value: []byte(from),
|
||||
},
|
||||
{
|
||||
Type: pb.Arg_String,
|
||||
Value: []byte("rbft"),
|
||||
},
|
||||
{
|
||||
Type: pb.Arg_String,
|
||||
Value: []byte(from),
|
||||
},
|
||||
{
|
||||
Type: pb.Arg_String,
|
||||
Value: []byte(from),
|
||||
},
|
||||
{
|
||||
Type: pb.Arg_String,
|
||||
Value: []byte(from),
|
||||
},
|
||||
{
|
||||
Type: pb.Arg_String,
|
||||
Value: []byte(from),
|
||||
},
|
||||
{
|
||||
Type: pb.Arg_String,
|
||||
Value: []byte(from),
|
||||
},
|
||||
},
|
||||
}
|
||||
input, err = ip.Marshal()
|
||||
require.Nil(t, err)
|
||||
ret, err = boltVM.Run(input)
|
||||
require.Nil(t, err)
|
||||
|
||||
ip = &pb.InvokePayload{
|
||||
Method: "Manager",
|
||||
Args: []*pb.Arg{
|
||||
{
|
||||
Type: pb.Arg_String,
|
||||
Value: []byte(appchain_mgr.EventRegister),
|
||||
},
|
||||
{
|
||||
Type: pb.Arg_String,
|
||||
Value: []byte(contracts.APPOVED),
|
||||
},
|
||||
{
|
||||
Type: pb.Arg_Bytes,
|
||||
Value: chainRegistingData,
|
||||
},
|
||||
},
|
||||
}
|
||||
input, err = ip.Marshal()
|
||||
require.Nil(t, err)
|
||||
ret, err = boltVMGovernance.Run(input)
|
||||
require.Nil(t, err, string(ret))
|
||||
|
||||
ip = &pb.InvokePayload{
|
||||
Method: "DeleteAppchain",
|
||||
Args: []*pb.Arg{
|
||||
{
|
||||
Type: pb.Arg_String,
|
||||
IsArray: false,
|
||||
Value: []byte(from),
|
||||
},
|
||||
},
|
||||
}
|
||||
input, err = ip.Marshal()
|
||||
require.Nil(t, err)
|
||||
ret, err = boltVM.Run(input)
|
||||
require.NotNil(t, err)
|
||||
require.Contains(t, err.Error(), "caller is not an admin account")
|
||||
|
||||
boltVMInterchain := New(ctxInterchain, mockEngine, cons)
|
||||
ibtp := mockIBTP(t, 1, pb.IBTP_INTERCHAIN)
|
||||
mockLedger.EXPECT().GetState(txInterchain.To, []byte(contracts.AppchainKey(ibtp.From))).Return(false, nil).AnyTimes()
|
||||
_, err = boltVMInterchain.HandleIBTP(ibtp)
|
||||
require.Nil(t, err)
|
||||
|
||||
require.NotNil(t, err)
|
||||
}
|
||||
|
||||
func mockIBTP(t *testing.T, index uint64, typ pb.IBTP_Type) *pb.IBTP {
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package tester
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
|
@ -59,6 +60,7 @@ func testSendTransaction(suite *API) *types.Hash {
|
|||
constant.StoreContractAddr.Address(), "Set", pb.String("key"), pb.String(value))
|
||||
suite.Nil(err)
|
||||
|
||||
fmt.Printf("api is %v\n", suite.api)
|
||||
suite.Nil(suite.api.Broker().HandleTransaction(tx))
|
||||
return tx.TransactionHash
|
||||
}
|
||||
|
|
|
@ -2,6 +2,7 @@ package tester
|
|||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"path/filepath"
|
||||
"strconv"
|
||||
|
||||
|
@ -13,14 +14,25 @@ import (
|
|||
"github.com/meshplus/bitxhub-model/pb"
|
||||
"github.com/meshplus/bitxhub/internal/coreapi/api"
|
||||
"github.com/meshplus/bitxhub/internal/executor/contracts"
|
||||
"github.com/meshplus/bitxid"
|
||||
"github.com/stretchr/testify/suite"
|
||||
"github.com/tidwall/gjson"
|
||||
)
|
||||
|
||||
const (
|
||||
appchainMethod = "did:bitxhub:appchain1:."
|
||||
appchainAdminDIDPrefix = "did:bitxhub:appchain"
|
||||
relaychainAdminDIDPrefix = "did:bitxhub:relayroot"
|
||||
relayAdminDID = "did:bitxhub:relay:0xc7F999b83Af6DF9e67d0a37Ee7e900bF38b3D013"
|
||||
docAddr = "/ipfs/QmQVxzUqN2Yv2UHUQXYwH8dSNkM8ReJ9qPqwJsf8zzoNUi"
|
||||
docHash = "QmQVxzUqN2Yv2UHUQXYwH8dSNkM8ReJ9qPqwJsf8zzoNUi"
|
||||
)
|
||||
|
||||
type RegisterAppchain struct {
|
||||
suite.Suite
|
||||
api api.CoreAPI
|
||||
privKey crypto.PrivateKey
|
||||
adminKey crypto.PrivateKey
|
||||
from *types.Address
|
||||
normalNonce uint64
|
||||
}
|
||||
|
@ -39,9 +51,16 @@ func (suite *RegisterAppchain) SetupSuite() {
|
|||
func (suite *RegisterAppchain) TestRegisterAppchain() {
|
||||
pub, err := suite.privKey.PublicKey().Bytes()
|
||||
suite.Require().Nil(err)
|
||||
addr, err := suite.privKey.PublicKey().Address()
|
||||
suite.Require().Nil(err)
|
||||
|
||||
did := genUniqueAppchainDID(addr.String())
|
||||
args := []*pb.Arg{
|
||||
pb.String("validators"),
|
||||
pb.String(did),
|
||||
pb.String(string(bitxid.DID(did).GetChainDID())),
|
||||
pb.String(docAddr),
|
||||
pb.String(docHash),
|
||||
pb.String(""),
|
||||
pb.String(""),
|
||||
pb.String("hyperchain"),
|
||||
pb.String("税务链"),
|
||||
|
@ -49,7 +68,6 @@ func (suite *RegisterAppchain) TestRegisterAppchain() {
|
|||
pb.String("1.8"),
|
||||
pb.String(string(pub)),
|
||||
}
|
||||
|
||||
ret, err := invokeBVMContract(suite.api, suite.privKey, suite.normalNonce, constant.AppchainMgrContractAddr.Address(), "Register", args...)
|
||||
suite.Require().Nil(err)
|
||||
suite.Require().True(ret.IsSuccess(), string(ret.Ret))
|
||||
|
@ -78,8 +96,17 @@ func (suite *RegisterAppchain) TestFetchAppchains() {
|
|||
suite.Require().Nil(err)
|
||||
pub2, err := k2.PublicKey().Bytes()
|
||||
suite.Require().Nil(err)
|
||||
addr1, err := k1.PublicKey().Address()
|
||||
suite.Require().Nil(err)
|
||||
addr2, err := k2.PublicKey().Address()
|
||||
suite.Require().Nil(err)
|
||||
|
||||
did := genUniqueAppchainDID(addr1.String())
|
||||
args := []*pb.Arg{
|
||||
pb.String(did),
|
||||
pb.String(string(bitxid.DID(did).GetChainDID())),
|
||||
pb.String(docAddr),
|
||||
pb.String(docHash),
|
||||
pb.String(""),
|
||||
pb.String(""),
|
||||
pb.String("hyperchain"),
|
||||
|
@ -93,8 +120,12 @@ func (suite *RegisterAppchain) TestFetchAppchains() {
|
|||
suite.Require().True(ret.IsSuccess(), string(ret.Ret))
|
||||
k1Nonce++
|
||||
id1 := gjson.Get(string(ret.Ret), "chain_id").String()
|
||||
|
||||
did2 := genUniqueAppchainDID(addr2.String())
|
||||
args = []*pb.Arg{
|
||||
pb.String(did2),
|
||||
pb.String(string(bitxid.DID(did2).GetChainDID())),
|
||||
pb.String(docAddr),
|
||||
pb.String(docHash),
|
||||
pb.String(""),
|
||||
pb.String(""),
|
||||
pb.String("fabric"),
|
||||
|
@ -130,17 +161,14 @@ func (suite *RegisterAppchain) TestFetchAppchains() {
|
|||
suite.Require().EqualValues(0, num)
|
||||
k2Nonce++
|
||||
|
||||
//AppChain
|
||||
ret, err = invokeBVMContract(suite.api, k1, k1Nonce, constant.AppchainMgrContractAddr.Address(), "Appchain")
|
||||
suite.Require().Nil(err)
|
||||
suite.Require().True(ret.IsSuccess())
|
||||
k1Nonce++
|
||||
|
||||
//GetAppchain
|
||||
ret2, err := invokeBVMContract(suite.api, k2, k2Nonce, constant.AppchainMgrContractAddr.Address(), "GetAppchain", pb.String(string(id1)))
|
||||
ret2, err := invokeBVMContract(suite.api, k2, k2Nonce, constant.AppchainMgrContractAddr.Address(), "GetAppchain", pb.String(id1))
|
||||
suite.Require().Nil(err)
|
||||
suite.Require().True(ret2.IsSuccess())
|
||||
suite.Require().Equal(ret.Ret, ret2.Ret)
|
||||
suite.Require().True(ret2.IsSuccess(), string(ret2.Ret))
|
||||
appchain := &appchainMgr.Appchain{}
|
||||
err = json.Unmarshal(ret2.Ret, appchain)
|
||||
suite.Require().Nil(err)
|
||||
suite.Require().Equal("hyperchain", appchain.ChainType)
|
||||
k2Nonce++
|
||||
}
|
||||
|
||||
|
@ -156,8 +184,17 @@ func (suite *RegisterAppchain) TestGetPubKeyByChainID() {
|
|||
suite.Require().Nil(err)
|
||||
pub2, err := k2.PublicKey().Bytes()
|
||||
suite.Require().Nil(err)
|
||||
addr1, err := k1.PublicKey().Address()
|
||||
suite.Require().Nil(err)
|
||||
addr2, err := k2.PublicKey().Address()
|
||||
suite.Require().Nil(err)
|
||||
|
||||
did := genUniqueAppchainDID(addr1.String())
|
||||
args := []*pb.Arg{
|
||||
pb.String(did),
|
||||
pb.String(string(bitxid.DID(did).GetChainDID())),
|
||||
pb.String(docAddr),
|
||||
pb.String(docHash),
|
||||
pb.String(""),
|
||||
pb.String(""),
|
||||
pb.String("hyperchain"),
|
||||
|
@ -171,7 +208,12 @@ func (suite *RegisterAppchain) TestGetPubKeyByChainID() {
|
|||
suite.Require().True(ret.IsSuccess(), string(ret.Ret))
|
||||
k1Nonce++
|
||||
|
||||
did2 := genUniqueAppchainDID(addr2.String())
|
||||
args = []*pb.Arg{
|
||||
pb.String(did2),
|
||||
pb.String(string(bitxid.DID(did2).GetChainDID())),
|
||||
pb.String(docAddr),
|
||||
pb.String(docHash),
|
||||
pb.String(""),
|
||||
pb.String(""),
|
||||
pb.String("fabric"),
|
||||
|
@ -208,8 +250,15 @@ func (suite *RegisterAppchain) TestUpdateAppchains() {
|
|||
pub1, err := k1.PublicKey().Bytes()
|
||||
suite.Require().Nil(err)
|
||||
k1Nonce := uint64(1)
|
||||
addr1, err := k1.PublicKey().Address()
|
||||
suite.Require().Nil(err)
|
||||
|
||||
did := genUniqueAppchainDID(addr1.String())
|
||||
args := []*pb.Arg{
|
||||
pb.String(did),
|
||||
pb.String(string(bitxid.DID(did).GetChainDID())),
|
||||
pb.String(docAddr),
|
||||
pb.String(docHash),
|
||||
pb.String(""),
|
||||
pb.String(""),
|
||||
pb.String("hyperchain"),
|
||||
|
@ -230,9 +279,16 @@ func (suite *RegisterAppchain) TestUpdateAppchains() {
|
|||
suite.Require().Nil(err)
|
||||
pubAdmin, err := priAdmin.PublicKey().Bytes()
|
||||
suite.Require().Nil(err)
|
||||
adminAddr, err := priAdmin.PublicKey().Address()
|
||||
suite.Require().Nil(err)
|
||||
adminNonce := uint64(1)
|
||||
|
||||
adminDID := genUniqueAppchainDID(adminAddr.String())
|
||||
args = []*pb.Arg{
|
||||
pb.String(adminDID),
|
||||
pb.String(string(bitxid.DID(adminDID).GetChainDID())),
|
||||
pb.String(docAddr),
|
||||
pb.String(docHash),
|
||||
pb.String(""),
|
||||
pb.String(""),
|
||||
pb.String("hyperchain"),
|
||||
|
@ -248,6 +304,10 @@ func (suite *RegisterAppchain) TestUpdateAppchains() {
|
|||
|
||||
//UpdateAppchain
|
||||
args = []*pb.Arg{
|
||||
pb.String(did),
|
||||
pb.String(string(bitxid.DID(did).GetChainDID())),
|
||||
pb.String(docAddr),
|
||||
pb.String(docHash),
|
||||
pb.String(""),
|
||||
pb.String(""),
|
||||
pb.String("hyperchain"),
|
||||
|
@ -263,6 +323,10 @@ func (suite *RegisterAppchain) TestUpdateAppchains() {
|
|||
k1Nonce++
|
||||
}
|
||||
|
||||
//func TestRegisterAppchain(t *testing.T) {
|
||||
// suite.Run(t, &RegisterAppchain{})
|
||||
//}
|
||||
func genUniqueAppchainDID(addr string) string {
|
||||
return fmt.Sprintf("%s%s:%s", appchainAdminDIDPrefix, addr, addr)
|
||||
}
|
||||
|
||||
func genUniqueRelaychainDID(addr string) string {
|
||||
return fmt.Sprintf("%s:%s", relaychainAdminDIDPrefix, addr)
|
||||
}
|
||||
|
|
|
@ -2,10 +2,14 @@ package tester
|
|||
|
||||
import (
|
||||
"crypto/sha256"
|
||||
"encoding/base64"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"path/filepath"
|
||||
"time"
|
||||
|
||||
"github.com/meshplus/bitxid"
|
||||
|
||||
"github.com/meshplus/bitxhub-kit/crypto"
|
||||
"github.com/meshplus/bitxhub-kit/crypto/asym"
|
||||
"github.com/meshplus/bitxhub-model/constant"
|
||||
|
@ -51,20 +55,28 @@ func (suite *Interchain) TestHandleIBTP() {
|
|||
suite.Require().Nil(err)
|
||||
k2, err := asym.GenerateKeyPair(crypto.Secp256k1)
|
||||
suite.Require().Nil(err)
|
||||
f, err := k1.PublicKey().Address()
|
||||
suite.Require().Nil(err)
|
||||
t, err := k2.PublicKey().Address()
|
||||
addr1, err := k1.PublicKey().Address()
|
||||
suite.Require().Nil(err)
|
||||
addr2, err := k2.PublicKey().Address()
|
||||
suite.Require().Nil(err)
|
||||
k1Nonce := uint64(1)
|
||||
k2Nonce := uint64(1)
|
||||
ibtpNonce := uint64(1)
|
||||
|
||||
pub1, err := k1.PublicKey().Bytes()
|
||||
rawpub1, err := k1.PublicKey().Bytes()
|
||||
suite.Require().Nil(err)
|
||||
pub2, err := k2.PublicKey().Bytes()
|
||||
pub1 := base64.StdEncoding.EncodeToString(rawpub1)
|
||||
rawpub2, err := k2.PublicKey().Bytes()
|
||||
suite.Require().Nil(err)
|
||||
pub2 := base64.StdEncoding.EncodeToString(rawpub2)
|
||||
|
||||
did := genUniqueAppchainDID(addr1.String())
|
||||
ret, err := invokeBVMContract(suite.api, k1, k1Nonce, constant.AppchainMgrContractAddr.Address(), "Register",
|
||||
pb.String(did),
|
||||
pb.String(string(bitxid.DID(did).GetChainDID())),
|
||||
pb.String(docAddr),
|
||||
pb.String(docHash),
|
||||
pb.String(""),
|
||||
pb.String("rbft"),
|
||||
pb.String("hyperchain"),
|
||||
|
@ -111,7 +123,12 @@ func (suite *Interchain) TestHandleIBTP() {
|
|||
suite.Require().True(ret.IsSuccess(), string(ret.Ret))
|
||||
adminNonce3++
|
||||
|
||||
did2 := genUniqueAppchainDID(addr2.String())
|
||||
ret, err = invokeBVMContract(suite.api, k2, k2Nonce, constant.AppchainMgrContractAddr.Address(), "Register",
|
||||
pb.String(did2),
|
||||
pb.String(string(bitxid.DID(did2).GetChainDID())),
|
||||
pb.String(docAddr),
|
||||
pb.String(docHash),
|
||||
pb.String(""),
|
||||
pb.String("rbft"),
|
||||
pb.String("fabric"),
|
||||
|
@ -125,6 +142,8 @@ func (suite *Interchain) TestHandleIBTP() {
|
|||
k2Nonce++
|
||||
id2 := gjson.Get(string(ret.Ret), "chain_id").String()
|
||||
proposalId2 := gjson.Get(string(ret.Ret), "proposal_id").String()
|
||||
fmt.Printf("appchain id 2 is %s\n", id2)
|
||||
fmt.Printf("proposal id is %s\n", proposalId2)
|
||||
|
||||
ret, err = invokeBVMContract(suite.api, k2, k2Nonce, constant.AppchainMgrContractAddr.Address(), "GetAppchain", pb.String(id2))
|
||||
suite.Require().Nil(err)
|
||||
|
@ -166,14 +185,15 @@ func (suite *Interchain) TestHandleIBTP() {
|
|||
k1Nonce++
|
||||
|
||||
// register rule
|
||||
ret, err = invokeBVMContract(suite.api, k1, k1Nonce, constant.RuleManagerContractAddr.Address(), "RegisterRule", pb.String(f.String()), pb.String(addr.String()))
|
||||
ret, err = invokeBVMContract(suite.api, k1, k1Nonce, constant.RuleManagerContractAddr.Address(),
|
||||
"RegisterRule", pb.String(string(bitxid.DID(did).GetChainDID())), pb.String(addr.String()))
|
||||
suite.Require().Nil(err)
|
||||
suite.Require().True(ret.IsSuccess())
|
||||
k1Nonce++
|
||||
|
||||
proof := []byte("true")
|
||||
proofHash := sha256.Sum256(proof)
|
||||
ib := &pb.IBTP{From: f.String(), To: t.String(), Index: ibtpNonce, Timestamp: time.Now().UnixNano(), Proof: proofHash[:]}
|
||||
ib := &pb.IBTP{From: id1, To: id2, Index: ibtpNonce, Timestamp: time.Now().UnixNano(), Proof: proofHash[:]}
|
||||
tx, err := genIBTPTransaction(k1, ib, k1Nonce)
|
||||
suite.Require().Nil(err)
|
||||
k1Nonce++
|
||||
|
@ -212,23 +232,31 @@ func (suite *Interchain) TestGetIBTPByID() {
|
|||
suite.Require().Nil(err)
|
||||
k2, err := asym.GenerateKeyPair(crypto.Secp256k1)
|
||||
suite.Require().Nil(err)
|
||||
f, err := k1.PublicKey().Address()
|
||||
suite.Require().Nil(err)
|
||||
t, err := k2.PublicKey().Address()
|
||||
suite.Require().Nil(err)
|
||||
k1Nonce := uint64(1)
|
||||
k2Nonce := uint64(1)
|
||||
ibtpNonce := uint64(1)
|
||||
|
||||
pub1, err := k1.PublicKey().Bytes()
|
||||
rawpub1, err := k1.PublicKey().Bytes()
|
||||
suite.Require().Nil(err)
|
||||
pub2, err := k2.PublicKey().Bytes()
|
||||
pub1 := base64.StdEncoding.EncodeToString(rawpub1)
|
||||
rawpub2, err := k2.PublicKey().Bytes()
|
||||
suite.Require().Nil(err)
|
||||
pub2 := base64.StdEncoding.EncodeToString(rawpub2)
|
||||
addr1, err := k1.PublicKey().Address()
|
||||
suite.Require().Nil(err)
|
||||
addr2, err := k2.PublicKey().Address()
|
||||
suite.Require().Nil(err)
|
||||
|
||||
confByte, err := ioutil.ReadFile("./test_data/validator")
|
||||
suite.Require().Nil(err)
|
||||
|
||||
did := genUniqueAppchainDID(addr1.String())
|
||||
ret, err := invokeBVMContract(suite.api, k1, k1Nonce, constant.AppchainMgrContractAddr.Address(), "Register",
|
||||
pb.String(did),
|
||||
pb.String(string(bitxid.DID(did).GetChainDID())),
|
||||
pb.String(docAddr),
|
||||
pb.String(docHash),
|
||||
pb.String(string(confByte)),
|
||||
pb.String("rbft"),
|
||||
pb.String("hyperchain"),
|
||||
|
@ -275,7 +303,12 @@ func (suite *Interchain) TestGetIBTPByID() {
|
|||
suite.Require().True(ret.IsSuccess(), string(ret.Ret))
|
||||
adminNonce3++
|
||||
|
||||
did2 := genUniqueAppchainDID(addr2.String())
|
||||
ret, err = invokeBVMContract(suite.api, k2, k2Nonce, constant.AppchainMgrContractAddr.Address(), "Register",
|
||||
pb.String(did2),
|
||||
pb.String(string(bitxid.DID(did2).GetChainDID())),
|
||||
pb.String(docAddr),
|
||||
pb.String(docHash),
|
||||
pb.String(""),
|
||||
pb.String("rbft"),
|
||||
pb.String("fabric"),
|
||||
|
@ -329,7 +362,8 @@ func (suite *Interchain) TestGetIBTPByID() {
|
|||
k1Nonce++
|
||||
|
||||
// register rule
|
||||
_, err = invokeBVMContract(suite.api, k1, k1Nonce, constant.RuleManagerContractAddr.Address(), "RegisterRule", pb.String(f.String()), pb.String(addr.String()))
|
||||
_, err = invokeBVMContract(suite.api, k1, k1Nonce, constant.RuleManagerContractAddr.Address(),
|
||||
"RegisterRule", pb.String(id1), pb.String(addr.String()))
|
||||
suite.Require().Nil(err)
|
||||
k1Nonce++
|
||||
|
||||
|
@ -337,7 +371,7 @@ func (suite *Interchain) TestGetIBTPByID() {
|
|||
suite.Require().Nil(err)
|
||||
|
||||
proofHash := sha256.Sum256(proof)
|
||||
ib := &pb.IBTP{From: f.String(), To: t.String(), Index: ibtpNonce, Payload: []byte("111"), Timestamp: time.Now().UnixNano(), Proof: proofHash[:]}
|
||||
ib := &pb.IBTP{From: id1, To: id2, Index: ibtpNonce, Payload: []byte("111"), Timestamp: time.Now().UnixNano(), Proof: proofHash[:]}
|
||||
tx, err := genIBTPTransaction(k1, ib, k1Nonce)
|
||||
suite.Require().Nil(err)
|
||||
tx.Extra = proof
|
||||
|
@ -347,7 +381,7 @@ func (suite *Interchain) TestGetIBTPByID() {
|
|||
ibtpNonce++
|
||||
k1Nonce++
|
||||
|
||||
ib2 := &pb.IBTP{From: f.String(), To: t.String(), Index: ibtpNonce, Payload: []byte("111"), Timestamp: time.Now().UnixNano(), Proof: proofHash[:]}
|
||||
ib2 := &pb.IBTP{From: id1, To: id2, Index: ibtpNonce, Payload: []byte("111"), Timestamp: time.Now().UnixNano(), Proof: proofHash[:]}
|
||||
tx, err = genIBTPTransaction(k1, ib2, k1Nonce)
|
||||
suite.Require().Nil(err)
|
||||
tx.Extra = proof
|
||||
|
@ -357,7 +391,7 @@ func (suite *Interchain) TestGetIBTPByID() {
|
|||
ibtpNonce++
|
||||
k1Nonce++
|
||||
|
||||
ib3 := &pb.IBTP{From: f.String(), To: t.String(), Index: ibtpNonce, Payload: []byte("111"), Timestamp: time.Now().UnixNano(), Proof: proofHash[:]}
|
||||
ib3 := &pb.IBTP{From: id1, To: id2, Index: ibtpNonce, Payload: []byte("111"), Timestamp: time.Now().UnixNano(), Proof: proofHash[:]}
|
||||
tx, err = genIBTPTransaction(k1, ib3, k1Nonce)
|
||||
suite.Require().Nil(err)
|
||||
tx.Extra = proof
|
||||
|
@ -400,10 +434,18 @@ func (suite *Interchain) TestInterchain() {
|
|||
suite.Require().Nil(err)
|
||||
k1Nonce := uint64(1)
|
||||
|
||||
pub1, err := k1.PublicKey().Bytes()
|
||||
rawpub1, err := k1.PublicKey().Bytes()
|
||||
suite.Require().Nil(err)
|
||||
pub1 := base64.StdEncoding.EncodeToString(rawpub1)
|
||||
addr1, err := k1.PublicKey().Address()
|
||||
suite.Require().Nil(err)
|
||||
|
||||
did := genUniqueAppchainDID(addr1.String())
|
||||
ret, err := invokeBVMContract(suite.api, k1, k1Nonce, constant.AppchainMgrContractAddr.Address(), "Register",
|
||||
pb.String(did),
|
||||
pb.String(string(bitxid.DID(did).GetChainDID())),
|
||||
pb.String(docAddr),
|
||||
pb.String(docHash),
|
||||
pb.String(""),
|
||||
pb.String("rbft"),
|
||||
pb.String("hyperchain"),
|
||||
|
@ -450,9 +492,10 @@ func (suite *Interchain) TestInterchain() {
|
|||
suite.Require().True(ret.IsSuccess(), string(ret.Ret))
|
||||
adminNonce3++
|
||||
|
||||
ret, err = invokeBVMContract(suite.api, k1, k1Nonce, constant.InterchainContractAddr.Address(), "Interchain")
|
||||
ret, err = invokeBVMContract(suite.api, k1, k1Nonce, constant.InterchainContractAddr.Address(),
|
||||
"Interchain", pb.String(string(bitxid.DID(did).GetChainDID())))
|
||||
suite.Require().Nil(err)
|
||||
suite.Require().True(ret.IsSuccess())
|
||||
suite.Require().True(ret.IsSuccess(), string(ret.Ret))
|
||||
|
||||
ic := &pb.Interchain{}
|
||||
err = ic.Unmarshal(ret.Ret)
|
||||
|
@ -476,7 +519,3 @@ func (suite *Interchain) TestRegister() {
|
|||
suite.Require().True(ret.IsSuccess(), string(ret.Ret))
|
||||
k1Nonce++
|
||||
}
|
||||
|
||||
//func TestInterchain(t *testing.T) {
|
||||
// suite.Run(t, &Interchain{})
|
||||
//}
|
||||
|
|
|
@ -6,6 +6,8 @@ import (
|
|||
"path/filepath"
|
||||
"strconv"
|
||||
|
||||
"github.com/meshplus/bitxid"
|
||||
|
||||
"github.com/meshplus/bitxhub/internal/executor/contracts"
|
||||
|
||||
"github.com/meshplus/bitxhub-kit/crypto"
|
||||
|
@ -37,7 +39,15 @@ func (suite *Role) SetupSuite() {
|
|||
func (suite *Role) TestGetRole() {
|
||||
pubKey, err := suite.pubKey.Bytes()
|
||||
suite.Assert().Nil(err)
|
||||
addr, err := suite.privKey.PublicKey().Address()
|
||||
suite.Require().Nil(err)
|
||||
|
||||
did := genUniqueAppchainDID(addr.String())
|
||||
_, err = invokeBVMContract(suite.api, suite.privKey, suite.normalNonce, constant.AppchainMgrContractAddr.Address(), "Register",
|
||||
pb.String(did),
|
||||
pb.String(string(bitxid.DID(did).GetChainDID())),
|
||||
pb.String(docAddr),
|
||||
pb.String(docHash),
|
||||
pb.String(""),
|
||||
pb.String("rbft"),
|
||||
pb.String("hyperchain"),
|
||||
|
@ -49,10 +59,10 @@ func (suite *Role) TestGetRole() {
|
|||
suite.Assert().Nil(err)
|
||||
suite.normalNonce++
|
||||
|
||||
receipt, err := invokeBVMContract(suite.api, suite.privKey, suite.normalNonce, constant.RoleContractAddr.Address(), "GetRole")
|
||||
suite.Require().Nil(err)
|
||||
suite.Equal("appchain_admin", string(receipt.Ret))
|
||||
suite.normalNonce++
|
||||
//receipt, err := invokeBVMContract(suite.api, suite.privKey, suite.normalNonce, constant.RoleContractAddr.Address(), "GetRole")
|
||||
//suite.Require().Nil(err)
|
||||
//suite.Equal("appchain_admin", string(receipt.Ret))
|
||||
//suite.normalNonce++
|
||||
|
||||
k, err := asym.GenerateKeyPair(crypto.Secp256k1)
|
||||
suite.Require().Nil(err)
|
||||
|
@ -142,13 +152,18 @@ func (suite *Role) TestGetRuleAddress() {
|
|||
pub2, err := k2.PublicKey().Bytes()
|
||||
suite.Require().Nil(err)
|
||||
|
||||
f1, err := k1.PublicKey().Address()
|
||||
addr1, err := k1.PublicKey().Address()
|
||||
suite.Require().Nil(err)
|
||||
f2, err := k2.PublicKey().Address()
|
||||
addr2, err := k2.PublicKey().Address()
|
||||
suite.Require().Nil(err)
|
||||
|
||||
did := genUniqueAppchainDID(addr1.String())
|
||||
// Register
|
||||
ret, err := invokeBVMContract(suite.api, k1, k1Nonce, constant.AppchainMgrContractAddr.Address(), "Register",
|
||||
pb.String(did),
|
||||
pb.String(string(bitxid.DID(did).GetChainDID())),
|
||||
pb.String(docAddr),
|
||||
pb.String(docHash),
|
||||
pb.String(""),
|
||||
pb.String("rbft"),
|
||||
pb.String("hyperchain"),
|
||||
|
@ -190,7 +205,12 @@ func (suite *Role) TestGetRuleAddress() {
|
|||
suite.Require().True(ret.IsSuccess(), string(ret.Ret))
|
||||
adminNonce3++
|
||||
|
||||
did2 := genUniqueAppchainDID(addr2.String())
|
||||
ret, err = invokeBVMContract(suite.api, k2, k2Nonce, constant.AppchainMgrContractAddr.Address(), "Register",
|
||||
pb.String(did2),
|
||||
pb.String(string(bitxid.DID(did2).GetChainDID())),
|
||||
pb.String(docAddr),
|
||||
pb.String(docHash),
|
||||
pb.String(""),
|
||||
pb.String("rbft"),
|
||||
pb.String("fabric"),
|
||||
|
@ -235,25 +255,25 @@ func (suite *Role) TestGetRuleAddress() {
|
|||
// deploy rule
|
||||
bytes, err := ioutil.ReadFile("./test_data/hpc_rule.wasm")
|
||||
suite.Require().Nil(err)
|
||||
addr1, err := deployContract(suite.api, k1, k1Nonce, bytes)
|
||||
addr1, err = deployContract(suite.api, k1, k1Nonce, bytes)
|
||||
suite.Require().Nil(err)
|
||||
k1Nonce++
|
||||
|
||||
bytes, err = ioutil.ReadFile("./test_data/fabric_policy.wasm")
|
||||
suite.Require().Nil(err)
|
||||
addr2, err := deployContract(suite.api, k2, k2Nonce, bytes)
|
||||
addr2, err = deployContract(suite.api, k2, k2Nonce, bytes)
|
||||
suite.Require().Nil(err)
|
||||
k2Nonce++
|
||||
|
||||
suite.Require().NotEqual(addr1, addr2)
|
||||
|
||||
// register rule
|
||||
ret, err = invokeBVMContract(suite.api, k1, k1Nonce, constant.RuleManagerContractAddr.Address(), "RegisterRule", pb.String(f1.String()), pb.String(addr1.String()))
|
||||
ret, err = invokeBVMContract(suite.api, k1, k1Nonce, constant.RuleManagerContractAddr.Address(), "RegisterRule", pb.String(string(bitxid.DID(did).GetChainDID())), pb.String(addr1.String()))
|
||||
suite.Require().Nil(err)
|
||||
suite.Require().True(ret.IsSuccess())
|
||||
suite.Require().True(ret.IsSuccess(), string(ret.Ret))
|
||||
k1Nonce++
|
||||
|
||||
ret, err = invokeBVMContract(suite.api, k2, k2Nonce, constant.RuleManagerContractAddr.Address(), "RegisterRule", pb.String(f2.String()), pb.String(addr2.String()))
|
||||
ret, err = invokeBVMContract(suite.api, k2, k2Nonce, constant.RuleManagerContractAddr.Address(), "RegisterRule", pb.String(string(bitxid.DID(did2).GetChainDID())), pb.String(addr2.String()))
|
||||
suite.Require().Nil(err)
|
||||
suite.Require().True(ret.IsSuccess())
|
||||
k2Nonce++
|
||||
|
@ -285,7 +305,12 @@ func (suite *Role) TestSetAdminRoles() {
|
|||
adminNonce := suite.api.Broker().GetPendingNonceByAccount(fromAdmin.String())
|
||||
|
||||
// register
|
||||
did := genUniqueAppchainDID(fromAdmin.String())
|
||||
retReg, err := invokeBVMContract(suite.api, priAdmin, adminNonce, constant.AppchainMgrContractAddr.Address(), "Register",
|
||||
pb.String(did),
|
||||
pb.String(string(bitxid.DID(did).GetChainDID())),
|
||||
pb.String(docAddr),
|
||||
pb.String(docHash),
|
||||
pb.String(""),
|
||||
pb.String("rbft"),
|
||||
pb.String("hyperchain"),
|
||||
|
|
|
@ -5,6 +5,8 @@ import (
|
|||
"path/filepath"
|
||||
"strconv"
|
||||
|
||||
"github.com/meshplus/bitxid"
|
||||
|
||||
appchainMgr "github.com/meshplus/bitxhub-core/appchain-mgr"
|
||||
"github.com/meshplus/bitxhub-kit/crypto"
|
||||
"github.com/meshplus/bitxhub-kit/crypto/asym"
|
||||
|
@ -59,10 +61,17 @@ func (suite *Governance) TestGovernance() {
|
|||
suite.Require().Nil(err)
|
||||
appchainPub, err := appchainPri.PublicKey().Bytes()
|
||||
suite.Require().Nil(err)
|
||||
addr, err := appchainPri.PublicKey().Address()
|
||||
suite.Require().Nil(err)
|
||||
appchainNonce := uint64(1)
|
||||
|
||||
// 1. Register ==============================================
|
||||
did := genUniqueAppchainDID(addr.String())
|
||||
ret, err := invokeBVMContract(suite.api, appchainPri, appchainNonce, constant.AppchainMgrContractAddr.Address(), "Register",
|
||||
pb.String(did),
|
||||
pb.String(string(bitxid.DID(did).GetChainDID())),
|
||||
pb.String(docAddr),
|
||||
pb.String(docHash),
|
||||
pb.String("validators"),
|
||||
pb.String("rbft"),
|
||||
pb.String("hyperchain"),
|
||||
|
@ -79,6 +88,10 @@ func (suite *Governance) TestGovernance() {
|
|||
|
||||
// repeated registration
|
||||
ret, err = invokeBVMContract(suite.api, appchainPri, appchainNonce, constant.AppchainMgrContractAddr.Address(), "Register",
|
||||
pb.String(did),
|
||||
pb.String(string(bitxid.DID(did).GetChainDID())),
|
||||
pb.String(docAddr),
|
||||
pb.String(docHash),
|
||||
pb.String("validators"),
|
||||
pb.String("rbft"),
|
||||
pb.String("hyperchain"),
|
||||
|
|
|
@ -33,6 +33,7 @@ solo = false
|
|||
plugin = "plugins/raft.so"
|
||||
|
||||
[genesis]
|
||||
dider = "0xc7F999b83Af6DF9e67d0a37Ee7e900bF38b3D013"
|
||||
[[genesis.admins]]
|
||||
address = "0xc7F999b83Af6DF9e67d0a37Ee7e900bF38b3D013"
|
||||
weight = 1
|
||||
|
|
|
@ -33,6 +33,7 @@ solo = false
|
|||
plugin = "plugins/raft.so"
|
||||
|
||||
[genesis]
|
||||
dider = "0xc7F999b83Af6DF9e67d0a37Ee7e900bF38b3D013"
|
||||
[[genesis.admins]]
|
||||
address = "0xc7F999b83Af6DF9e67d0a37Ee7e900bF38b3D013"
|
||||
weight = 1
|
||||
|
|
|
@ -33,6 +33,7 @@ solo = false
|
|||
plugin = "plugins/raft3.so"
|
||||
|
||||
[genesis]
|
||||
dider = "0xc7F999b83Af6DF9e67d0a37Ee7e900bF38b3D013"
|
||||
[[genesis.admins]]
|
||||
address = "0xc7F999b83Af6DF9e67d0a37Ee7e900bF38b3D013"
|
||||
weight = 1
|
||||
|
|
|
@ -33,6 +33,7 @@ solo = false
|
|||
plugin = "plugins/raft4.so"
|
||||
|
||||
[genesis]
|
||||
dider = "0xc7F999b83Af6DF9e67d0a37Ee7e900bF38b3D013"
|
||||
[[genesis.admins]]
|
||||
address = "0xc7F999b83Af6DF9e67d0a37Ee7e900bF38b3D013"
|
||||
weight = 1
|
||||
|
|
|
@ -5,9 +5,16 @@ import (
|
|||
"fmt"
|
||||
"os"
|
||||
"path"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/stretchr/testify/suite"
|
||||
|
||||
"github.com/meshplus/bitxhub-kit/crypto/asym"
|
||||
"github.com/meshplus/bitxhub-model/constant"
|
||||
"github.com/meshplus/bitxhub-model/pb"
|
||||
|
||||
"github.com/meshplus/bitxhub/internal/app"
|
||||
"github.com/meshplus/bitxhub/internal/coreapi"
|
||||
"github.com/meshplus/bitxhub/internal/coreapi/api"
|
||||
|
@ -17,7 +24,6 @@ import (
|
|||
"github.com/meshplus/bitxhub/pkg/order"
|
||||
"github.com/meshplus/bitxhub/pkg/order/etcdraft"
|
||||
"github.com/stretchr/testify/require"
|
||||
"github.com/stretchr/testify/suite"
|
||||
)
|
||||
|
||||
func TestTester(t *testing.T) {
|
||||
|
@ -38,6 +44,65 @@ func TestTester(t *testing.T) {
|
|||
time.Sleep(500 * time.Millisecond)
|
||||
}
|
||||
|
||||
keyPath1 := filepath.Join("./test_data/config/node1/key.json")
|
||||
priAdmin1, err := asym.RestorePrivateKey(keyPath1, "bitxhub")
|
||||
require.Nil(t, err)
|
||||
fromAdmin1, err := priAdmin1.PublicKey().Address()
|
||||
require.Nil(t, err)
|
||||
adminNonce1 := node1.Broker().GetPendingNonceByAccount(fromAdmin1.String())
|
||||
require.Nil(t, err)
|
||||
keyPath2 := filepath.Join("./test_data/config/node2/key.json")
|
||||
priAdmin2, err := asym.RestorePrivateKey(keyPath2, "bitxhub")
|
||||
require.Nil(t, err)
|
||||
fromAdmin2, err := priAdmin2.PublicKey().Address()
|
||||
require.Nil(t, err)
|
||||
keyPath3 := filepath.Join("./test_data/config/node3/key.json")
|
||||
priAdmin3, err := asym.RestorePrivateKey(keyPath3, "bitxhub")
|
||||
require.Nil(t, err)
|
||||
fromAdmin3, err := priAdmin3.PublicKey().Address()
|
||||
require.Nil(t, err)
|
||||
keyPath4 := filepath.Join("./test_data/config/node4/key.json")
|
||||
priAdmin4, err := asym.RestorePrivateKey(keyPath4, "bitxhub")
|
||||
require.Nil(t, err)
|
||||
fromAdmin4, err := priAdmin4.PublicKey().Address()
|
||||
require.Nil(t, err)
|
||||
// init registry first
|
||||
adminDid := genUniqueRelaychainDID(fromAdmin1.String())
|
||||
args := []*pb.Arg{
|
||||
pb.String(adminDid),
|
||||
}
|
||||
ret, err := invokeBVMContract(node1, priAdmin1, adminNonce1, constant.MethodRegistryContractAddr.Address(), "Init", args...)
|
||||
require.Nil(t, err)
|
||||
require.True(t, ret.IsSuccess(), string(ret.Ret))
|
||||
adminNonce1++
|
||||
// set admin for method registry for other nodes
|
||||
args = []*pb.Arg{
|
||||
pb.String(adminDid),
|
||||
pb.String(genUniqueRelaychainDID(fromAdmin2.String())),
|
||||
}
|
||||
ret, err = invokeBVMContract(node1, priAdmin1, adminNonce1, constant.MethodRegistryContractAddr.Address(), "AddAdmin", args...)
|
||||
require.Nil(t, err)
|
||||
require.True(t, ret.IsSuccess(), string(ret.Ret))
|
||||
adminNonce1++
|
||||
|
||||
args = []*pb.Arg{
|
||||
pb.String(adminDid),
|
||||
pb.String(genUniqueRelaychainDID(fromAdmin3.String())),
|
||||
}
|
||||
ret, err = invokeBVMContract(node1, priAdmin1, adminNonce1, constant.MethodRegistryContractAddr.Address(), "AddAdmin", args...)
|
||||
require.Nil(t, err)
|
||||
require.True(t, ret.IsSuccess(), string(ret.Ret))
|
||||
adminNonce1++
|
||||
|
||||
args = []*pb.Arg{
|
||||
pb.String(adminDid),
|
||||
pb.String(genUniqueRelaychainDID(fromAdmin4.String())),
|
||||
}
|
||||
ret, err = invokeBVMContract(node1, priAdmin1, adminNonce1, constant.MethodRegistryContractAddr.Address(), "AddAdmin", args...)
|
||||
require.Nil(t, err)
|
||||
require.True(t, ret.IsSuccess(), string(ret.Ret))
|
||||
adminNonce1++
|
||||
|
||||
suite.Run(t, &API{api: node1})
|
||||
suite.Run(t, &RegisterAppchain{api: node2})
|
||||
suite.Run(t, &Interchain{api: node3})
|
||||
|
|
Loading…
Reference in New Issue