test:add repo and boltvm unit test

This commit is contained in:
jzhe 2021-02-22 15:10:54 +08:00
parent 02e651cbd5
commit b5cba02552
17 changed files with 517 additions and 63 deletions

View File

@ -3,10 +3,12 @@ package repo
import (
"testing"
"github.com/mitchellh/go-homedir"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func testReadConfig(t *testing.T) {
func TestReadNetworkConfig(t *testing.T) {
path := "../../config/network.toml"
cfg := &NetworkConfig{}
err := ReadConfig(path, "toml", cfg)
@ -19,4 +21,31 @@ func testReadConfig(t *testing.T) {
for i, node := range cfg.Nodes {
assert.True(t, uint64(i+1) == node.ID)
}
}
func TestReadConfig(t *testing.T) {
_, err := DefaultConfig()
require.Nil(t, err)
path := "../../config/bitxhub.toml"
cfg := &Config{}
err = ReadConfig(path, "toml", cfg)
assert.Nil(t, err)
_, err = cfg.Bytes()
require.Nil(t, err)
_, err = UnmarshalConfig("../../config")
require.Nil(t, err)
pathRoot, err := PathRoot()
require.Nil(t, err)
dir, err := homedir.Expand(defaultPathRoot)
require.Nil(t, err)
require.Equal(t, dir, pathRoot)
rootWithDefault, err := PathRootWithDefault("../../config")
require.Nil(t, err)
require.Equal(t, "../../config", rootWithDefault)
}

View File

@ -0,0 +1,23 @@
package repo
import (
"io/ioutil"
"os"
"testing"
"github.com/stretchr/testify/require"
)
func TestInitialize(t *testing.T) {
tempDir, err := ioutil.TempDir("", "TestInitialize")
require.Nil(t, err)
defer os.RemoveAll(tempDir)
initialized := Initialized(tempDir)
require.Equal(t, false, initialized)
err = Initialize(tempDir)
require.Nil(t, err)
require.Equal(t, true, Initialized(tempDir))
}

View File

@ -1 +1,16 @@
package repo
import (
"testing"
"github.com/stretchr/testify/require"
)
func TestLoadKey(t *testing.T) {
path := "testdata/key.json"
_, err := LoadKey(path)
require.Nil(t, err)
_, err = loadPrivKey("testdata")
require.Nil(t, err)
}

View File

@ -1,9 +1,10 @@
package repo
import (
"testing"
"github.com/meshplus/bitxhub-model/pb"
"github.com/stretchr/testify/require"
"testing"
)
func TestNetworkConfig(t *testing.T) {
@ -58,4 +59,7 @@ func TestRewriteNetworkConfig(t *testing.T) {
}
err := RewriteNetworkConfig("./testdata", infos, false)
require.Nil(t, err)
_, err = GetPidFromPrivFile("testdata/certs/node.priv")
require.Nil(t, err)
}

View File

@ -4,6 +4,7 @@ import (
"testing"
"github.com/magiconair/properties/assert"
"github.com/stretchr/testify/require"
)
func TestGetStoragePath(t *testing.T) {
@ -11,4 +12,13 @@ func TestGetStoragePath(t *testing.T) {
assert.Equal(t, p, "/data/storage/order")
p = GetStoragePath("/data")
assert.Equal(t, p, "/data/storage")
_, err := Load("testdata")
require.Nil(t, err)
_, err = GetAPI("testdata")
require.Nil(t, err)
path := GetKeyPath("testdata")
require.Contains(t, path, KeyName)
}

View File

@ -3,34 +3,62 @@ title = "BitXHub configuration file"
solo = false
[port]
grpc = 60011
gateway = 9091
pprof = 53121
grpc = 60011
gateway = 9091
pprof = 53121
monitor = 40011
[pprof]
enable = false
enable = true
ptype = "http" # including two types: runtime (recommended for use during the development phase) and http
mode = "memory" # only required for runtime ptype, including two modes: cpu、memory
duration = "30s" # only required for runtime ptype, every duration will generation a profile.
[monitor]
enable = true
[gateway]
allowed_origins = ["*"]
allowed_origins = ["*"]
[ping]
enable = true
duration = "15s"
[security]
enable_tls = false
pem_file_path = "certs/server.pem"
server_key_path = "certs/server.key"
[log]
level = "info"
dir = "logs"
filename = "bitxhub.log"
[log.module]
p2p = "info"
consensus = "info"
executor = "info"
router = "info"
api = "info"
level = "info"
dir = "logs"
filename = "bitxhub.log"
report_caller = false
[log.module]
p2p = "info"
consensus = "info"
executor = "info"
router = "info"
api = "info"
coreapi = "info"
storage = "info"
[cert]
verify = true
verify = true
node_cert_path = "certs/node.cert"
agency_cert_path = "certs/agency.cert"
ca_cert_path = "certs/ca.cert"
[order]
plugin = "plugins/raft.so"
plugin = "plugins/raft.so"
[executor]
type = "serial" # opensource version only supports serial type, commercial version supports serial and parallel types
[genesis]
addresses = [
"0x64734c73a4cd00d7b3d1768946447ae9ebf240af"
]
addresses = [
"0xc7F999b83Af6DF9e67d0a37Ee7e900bF38b3D013",
"0x79a1215469FaB6f9c63c1816b45183AD3624bE34",
"0x97c8B516D19edBf575D72a172Af7F418BE498C37",
"0xc0Ff2e0b3189132D815b8eb325bE17285AC898f8"
]

View File

@ -1,16 +1,16 @@
-----BEGIN CERTIFICATE-----
MIIClTCCAjygAwIBAgIDCpnMMAoGCCqGSM49BAMCMIGhMQswCQYDVQQGEwJDTjER
MIICkjCCAjegAwIBAgIDAoB1MAoGCCqGSM49BAMCMIGhMQswCQYDVQQGEwJDTjER
MA8GA1UECBMIWmhlSmlhbmcxETAPBgNVBAcTCEhhbmdaaG91MR8wDQYDVQQJEwZz
dHJlZXQwDgYDVQQJEwdhZGRyZXNzMQ8wDQYDVQQREwYzMjQwMDAxEzARBgNVBAoT
Ckh5cGVyY2hhaW4xEDAOBgNVBAsTB0JpdFhIdWIxEzARBgNVBAMTCmJpdHhodWIu
Y24wIBcNMjAwMjE3MDE1MjIxWhgPMjA3MDAyMDQwMTUyMjFaMIGhMQswCQYDVQQG
Y24wIBcNMjAwODExMDUwNzEzWhgPMjA3MDA3MzAwNTA3MTNaMIGaMQswCQYDVQQG
EwJDTjERMA8GA1UECBMIWmhlSmlhbmcxETAPBgNVBAcTCEhhbmdaaG91MR8wDQYD
VQQJEwZzdHJlZXQwDgYDVQQJEwdhZGRyZXNzMQ8wDQYDVQQREwYzMjQwMDAxEzAR
BgNVBAoTCkh5cGVyY2hhaW4xEDAOBgNVBAsTB0JpdFhIdWIxEzARBgNVBAMTCmJp
dHhodWIuY24wWTATBgcqhkjOPQIBBggqhkjOPQMBBwNCAAQWNGFeLaXUE7yX2Kd2
0wU1c+IBVvD3KZLvFwFWdCBFHw2bE7/duotcHjaVFpWhRVWrTDd3nMWlj914Am8X
Qhdho18wXTAOBgNVHQ8BAf8EBAMCAaYwDwYDVR0lBAgwBgYEVR0lADAPBgNVHRMB
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mlBFiEWZZRJTyiubI7NDqN5+JlVBAog=
-----END CERTIFICATE-----

3
internal/repo/testdata/certs/key.priv vendored Normal file
View File

@ -0,0 +1,3 @@
-----BEGIN EC PRIVATE KEY-----
tkdxQ+F/iJJjBE9s9GPcNxd6xFJsTDmno0QZhFcCSi8=
-----END EC PRIVATE KEY-----

View File

@ -1,17 +1,15 @@
-----BEGIN CERTIFICATE-----
MIICwjCCAmigAwIBAgIDCWorMAoGCCqGSM49BAMCMIGhMQswCQYDVQQGEwJDTjER
MIICWjCCAf+gAwIBAgIDDhFLMAoGCCqGSM49BAMCMIGaMQswCQYDVQQGEwJDTjER
MA8GA1UECBMIWmhlSmlhbmcxETAPBgNVBAcTCEhhbmdaaG91MR8wDQYDVQQJEwZz
dHJlZXQwDgYDVQQJEwdhZGRyZXNzMQ8wDQYDVQQREwYzMjQwMDAxEzARBgNVBAoT
Ckh5cGVyY2hhaW4xEDAOBgNVBAsTB0JpdFhIdWIxEzARBgNVBAMTCmJpdHhodWIu
Y24wIBcNMjAwMjE3MDE1MjIyWhgPMjA3MDAyMDQwMTUyMjJaMIGeMQswCQYDVQQG
EwJDTjERMA8GA1UECBMIWmhlSmlhbmcxETAPBgNVBAcTCEhhbmdaaG91MR8wDQYD
VQQJEwZzdHJlZXQwDgYDVQQJEwdhZGRyZXNzMQ8wDQYDVQQREwYzMjQwMDAxEDAO
BgNVBAoTB0FnZW5jeTExEDAOBgNVBAsTB0JpdFhIdWIxEzARBgNVBAMTCmJpdHho
dWIuY24wWTATBgcqhkjOPQIBBggqhkjOPQMBBwNCAARPkxN+n+u52WedWVOoVZpb
2ZJWRb8ljZJZNWS+AMgUmTg5aQAU1xapOG4MFUeRujT0OmXIMY3sw+roqcG8Doxm
o4GNMIGKMA4GA1UdDwEB/wQEAwIBpjAPBgNVHSUECDAGBgRVHSUAMA8GA1UdEwEB
/wQFMAMBAf8wKQYDVR0OBCIEIP7jTLDWDuuEwaiZOMxv/4lpNkYJEnI/yduG4lcJ
AG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Hkbo09DplyDGN7MPq6KnBvA6MZg==
MHcCAQEEIJjph6szT64kRmvzyZYWYaonaFVsvTZwRLqeV20wo2D3oAoGCCqGSM49
AwEHoUQDQgAE4I02BJ2r8XqxbhCifAt/UFGNdsYf0wthOVe54p5kHDoAw0b+R1uL
LJE0pv1l9g9ATM8G+1xOQE8qA3jPanLqww==
-----END EC PRIVATE KEY-----

27
internal/repo/testdata/certs/server.key vendored Normal file
View File

@ -0,0 +1,27 @@
-----BEGIN RSA PRIVATE KEY-----
MIIEpAIBAAKCAQEAvUURnJYTyByepyuLU2wdqsTfNtdty5LFjwhuW2JJquQt+qeV
Oq9y65nKnr/8x1dIE4Z5zmWh2bpTzddT6KItlhL1zJY/zF3pbVjUsSiPLfSFRvHQ
iltUZspKgGij/Tb9I/4hy7vvv95ff6v7C3kgqFmUzxoRUGil2PoJ88vyDit/coSB
IgqTR9QonutL1RIgurraTcGHLPpRqFuPouvU8aMN8dW2kjqW+YwsnxcpVXegDGDp
9k8i2iDcwpMF6C8n7il47O8LWmAMpcT7nsPbKBiseXMzhNspt8r+otE7T0wAfTKN
IVVuEkq/1HQZBUPtnhpTJREHI1kX3Znt4eIkgwIDAQABAoIBAQCI12IXW25r9T1D
0jjGlNmSOQrFpNYOJEzP0CGx0os+kgEoQ3eiWW12J9gWFOrW2SUUcNqqPlLZj1y9
61wQSwk4gvbR9yOjR5bYZyxH9fInIK4nj/fdwJByTPm2g3FlRxeYqUmX+oYpq8ZS
EW7NacMR1MrBPbCc+TxHdugxKxgT42FWcQaUAqTX4SfdHblSh3ae/3xyDgRyB7UC
34JCAWaHZq2d9fVZ6LSCir70VUrq1QvbYNXd2hO5K8c/8+HRy6GanzXn29yff9+j
+I+WkULOmxqQ/N/nhRwuAaRU0Fdgi6wa+8TdXSxIgVsAYdsDcMxwheAL50Cv6kgn
Cn3Wo+JRAoGBAPJv4Hk49SJJdN01OCL/vCc6iLA4dV5HIDp77nMCaaKWOlL4iJFD
eNIfuP5Pi+DvjRouQB52kKXbd61z1eyVJ7gW73iZS92zaO7CNwj7iFmNb8mSjShx
TgdxGxNYoTXb4WPrHbBh3GTrrfBvLEuAYoFIXesHdK60VE33+tadx7J5AoGBAMfb
voEh63kucjoxWHzW/uLoxCaKnGpWCjO6wRjsXZAeNe7tznhuHqgeF9TUVRHnrMa1
pvHVW1w95G9Q1vJymbhuXtGBffjgOgjr6Vf4tIxUUkX+bkUDf+NM+LmkI+g/2h8a
i65b43YuQmnYqyAauOntHWOSuETsXmo/8RFkem/bAoGAfribzMFI4LMksruurByg
bKDb8cCRGMZ0wh0ldlg8fw+nTNc8CzIJZUvPlp5dryWHy7eBLGstEIS2+aMinpcY
O9FBOvhl/2xX3PUHb1qK2sRjOimwPwN6lck5LdOV8GEOXvv2eMuuN9I5CQQTUyO4
WXtKHB+5jdgUeOy14Jh4WYECgYBpPW9NdF0YjLqdpgpggp3pQoS3ftnqrK/mmXrA
8wY5s47W5+aHSAVgpagK7Fx3dzVl1ZW5Vo4rPnQhocHuHSaRFZ1cWQHKodgthnxz
VIVON8CzFs1eDf+z43490w8NZ0ImisXu5HgcbTOPpQZHe4rPs4p8OnBJ6uW0sULx
06UdbQKBgQCMQ3iu/1e83zTnbFa6wecIMZHjitM4G1S+MeT6T/lMGvtf5jQClx2C
JGiqFvwmbfUpxe/8PaSj9nmPUhWk/RrpkjlGry9wedAoLtdzjKOBvOcSjNPNibyD
QGp5IKS37dPJRKl2gxiTSKyb7ba+O2twFm1sgC3zvmfB1qr3T9qPfw==
-----END RSA PRIVATE KEY-----

62
internal/repo/testdata/certs/server.pem vendored Normal file
View File

@ -0,0 +1,62 @@
CONNECTED(00000005)
---
Certificate chain
0 s:/C=CN/ST=ZJ/L=HZ/O=Hyperchain/OU=DM/CN=localhost/emailAddress=datamesh@hyperchain.cn
i:/C=CN/ST=ZJ/L=HZ/O=Hyperchain/OU=DM/CN=localhost/emailAddress=datamesh@hyperchain.cn
-----BEGIN CERTIFICATE-----
MIIDhjCCAm4CCQD0t1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qKX7O+iza4pD
b6r3Uz8HLl2oFmn/T1b5RhuuMS7diQ5y8HzNRYTBdzNmIGovGWg0GQBTZQrUZh6J
75fuj5+DANruj0/MTZqGI71LpqD7QmrKl5Ii+CBknYZPXLnXgw/rGhXE
-----END CERTIFICATE-----
---
Server certificate
subject=/C=CN/ST=ZJ/L=HZ/O=Hyperchain/OU=DM/CN=localhost/emailAddress=datamesh@hyperchain.cn
issuer=/C=CN/ST=ZJ/L=HZ/O=Hyperchain/OU=DM/CN=localhost/emailAddress=datamesh@hyperchain.cn
---
No client certificate CA names sent
Server Temp Key: ECDH, X25519, 253 bits
---
SSL handshake has read 1485 bytes and written 307 bytes
---
New, TLSv1/SSLv3, Cipher is ECDHE-RSA-AES128-GCM-SHA256
Server public key is 2048 bit
Secure Renegotiation IS supported
Compression: NONE
Expansion: NONE
No ALPN negotiated
SSL-Session:
Protocol : TLSv1.2
Cipher : ECDHE-RSA-AES128-GCM-SHA256
Session-ID: EF7931988E269C85760BEBBC0379299C1148C3AE8140EA1FD14745C3F0AA4527
Session-ID-ctx:
Master-Key: 08E910F7086C2848818F800ACDBE6D00FE55A896188CDDE281158B1C02D7A458269861E584A3FAECB610BC59C487F322
TLS session ticket:
0000 - 60 f7 27 df 8c 98 71 e3-48 70 29 6f 56 3b 6f 85 `.'...q.Hp)oV;o.
0010 - 16 1f 90 8b 5b 94 c3 c0-94 1c 9d dd e1 83 3f 3c ....[.........?<
0020 - ff cb 93 11 44 ff 57 9d-37 97 8d 8e 04 e2 19 bc ....D.W.7.......
0030 - 6f 75 df b5 fd 00 bb ee-ba 56 c6 fd b2 21 8d ae ou.......V...!..
0040 - f5 39 94 82 69 fa 7f 97-c5 3f 4f 50 20 0f dc d8 .9..i....?OP ...
0050 - 60 00 a0 37 f8 59 19 4d-5c 87 08 e6 37 82 b9 34 `..7.Y.M\...7..4
0060 - 3c 56 38 f1 db cf 4f e1-99 7a dd 50 b0 a8 7a 83 <V8...O..z.P..z.
0070 - 26 82 80 8d 2e ec 0b 67- &......g
Start Time: 1605496292
Timeout : 7200 (sec)
Verify return code: 18 (self signed certificate)
---

View File

@ -1,5 +0,0 @@
{
"pid": "QmUxPDgpWTVrFByfqhfbiULJKoRPBjgVVXhhdtByfZPi5C",
"address": "0x486e02ee11994af271a0df12111a654a47bce6dc",
"priv_key": "CAMSeTB3AgEBBCBNF9f5ktxONu1pqprIFLV6/7F27gyjvycYPq6zaqplvqAKBggqhkjOPQMBB6FEA0IABPY2wPn+T8+bDcIuyKRfcO4E7UujG2lT+UGuSXH1exdOjVdixno9J8PT7glJfpcTJ+ayomb6UqT4lkfCewZ70ZI="
}

7
internal/repo/testdata/key.json vendored Normal file
View File

@ -0,0 +1,7 @@
{
"type": 3,
"cipher": {
"data": "9a77705a7509546495684650a2bff74abd35567840b77a166961ed0b373eb963dba086cdac91c60ca8ab1c5876a5d4d8fe08cb6cefb1f1c63ebfa32e8e22bc69",
"cipher": "AES-256"
}
}

View File

@ -6,10 +6,10 @@ new = false
account = ""
hosts = ["/ip4/127.0.0.1/tcp/5002/p2p/"]
id = 2
pid = "QmWrwfrnqmiRhL64TBhSUNi3PpMDyWbyjkfPG24k2ddFae"
pid = "Qmc4hJ677WGmeak3FsyGiEctvgYW1gaiTBmoS59XxzD3gC"
[[nodes]]
account = ""
hosts = ["/ip4/127.0.0.1/tcp/5003/p2p/"]
id = 3
pid = "QmQm4dciK8X16c5weAKwu4gzKDNQHFpWPoK2pNCLKhV2a7"
pid = "QmaSJtJm8k15PqJMso8cJLvspXS4yf1NjQzD7mvQHc9rCf"

View File

@ -0,0 +1,253 @@
package boltvm
import (
"encoding/json"
"strconv"
"testing"
"time"
"github.com/golang/mock/gomock"
"github.com/meshplus/bitxhub-core/agency"
"github.com/meshplus/bitxhub-core/validator/mock_validator"
"github.com/meshplus/bitxhub-kit/log"
"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"
)
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{},
},
}
ContractsInfo := agency.GetRegisteredContractInfo()
for addr, info := range ContractsInfo {
boltContracts = append(boltContracts, &BoltContract{
Enabled: true,
Name: info.Name,
Address: addr,
Contract: info.Constructor(),
})
}
return Register(boltContracts)
}
func TestRegister(t *testing.T) {
registers := GetBoltContracts()
require.Equal(t, len(registers), 7)
contract, err := GetBoltContract(constant.StoreContractAddr.Address().String(), registers)
require.Nil(t, err)
require.NotNil(t, contract)
}
func TestNewContext(t *testing.T) {
tx := &pb.Transaction{
From: types.NewAddressByStr(from),
To: types.NewAddressByStr(to),
}
tx.TransactionHash = tx.Hash()
ctx := NewContext(tx, 1, nil, nil, nil)
require.Equal(t, from, ctx.Caller())
require.Equal(t, to, ctx.Callee())
require.Equal(t, uint64(1), ctx.TransactionIndex())
require.Equal(t, tx.TransactionHash.String(), ctx.TransactionHash().String())
require.Nil(t, ctx.Logger())
}
func TestBoltVM_Run(t *testing.T) {
ctr := gomock.NewController(t)
mockEngine := mock_validator.NewMockEngine(ctr)
mockLedger := mock_ledger.NewMockLedger(ctr)
data := make([][]byte, 0)
data = append(data, []byte("1"))
mockLedger.EXPECT().QueryByPrefix(gomock.Any(), gomock.Any()).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.String():
return true, nil
case constant.InterchainContractAddr.String():
return false, 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())
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_I32,
Value: []byte(strconv.Itoa(1)),
},
{
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: "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")
ibtp := mockIBTP(t, 1, pb.IBTP_INTERCHAIN)
_, err = boltVM.HandleIBTP(ibtp)
require.Nil(t, err)
}
func mockIBTP(t *testing.T, index uint64, typ pb.IBTP_Type) *pb.IBTP {
content := pb.Content{
SrcContractId: from,
DstContractId: from,
Func: "set",
}
bytes, err := content.Marshal()
assert.Nil(t, err)
ibtppd, err := json.Marshal(pb.Payload{
Encrypted: false,
Content: bytes,
})
assert.Nil(t, err)
return &pb.IBTP{
From: from,
To: from,
Payload: ibtppd,
Index: index,
Type: typ,
Timestamp: time.Now().UnixNano(),
}
}