2020-03-29 21:32:01 +08:00
|
|
|
package tester
|
|
|
|
|
|
|
|
import (
|
2020-07-02 16:03:53 +08:00
|
|
|
"encoding/json"
|
|
|
|
"io/ioutil"
|
|
|
|
"path/filepath"
|
2020-03-29 21:32:01 +08:00
|
|
|
"strconv"
|
|
|
|
|
2021-03-25 11:46:01 +08:00
|
|
|
"github.com/meshplus/bitxhub/internal/executor/contracts"
|
|
|
|
|
2020-03-29 21:32:01 +08:00
|
|
|
"github.com/meshplus/bitxhub-kit/crypto"
|
2020-08-11 14:07:15 +08:00
|
|
|
"github.com/meshplus/bitxhub-kit/crypto/asym"
|
2020-10-21 18:41:53 +08:00
|
|
|
"github.com/meshplus/bitxhub-model/constant"
|
2020-04-28 17:08:21 +08:00
|
|
|
"github.com/meshplus/bitxhub-model/pb"
|
|
|
|
"github.com/meshplus/bitxhub/internal/coreapi/api"
|
2020-03-29 21:32:01 +08:00
|
|
|
"github.com/stretchr/testify/suite"
|
2020-10-21 18:41:53 +08:00
|
|
|
"github.com/tidwall/gjson"
|
2020-03-29 21:32:01 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
type Role struct {
|
|
|
|
suite.Suite
|
2020-09-29 15:01:30 +08:00
|
|
|
api api.CoreAPI
|
|
|
|
privKey crypto.PrivateKey
|
|
|
|
pubKey crypto.PublicKey
|
|
|
|
normalNonce uint64
|
2020-03-29 21:32:01 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func (suite *Role) SetupSuite() {
|
|
|
|
var err error
|
2020-08-11 14:07:15 +08:00
|
|
|
suite.privKey, err = asym.GenerateKeyPair(crypto.Secp256k1)
|
2020-03-29 21:32:01 +08:00
|
|
|
suite.Assert().Nil(err)
|
|
|
|
|
2020-04-28 15:02:55 +08:00
|
|
|
suite.pubKey = suite.privKey.PublicKey()
|
2020-09-29 15:01:30 +08:00
|
|
|
suite.normalNonce = 1
|
2020-03-29 21:32:01 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func (suite *Role) TestGetRole() {
|
2020-04-28 15:02:55 +08:00
|
|
|
pubKey, err := suite.pubKey.Bytes()
|
|
|
|
suite.Assert().Nil(err)
|
2020-09-29 15:01:30 +08:00
|
|
|
_, err = invokeBVMContract(suite.api, suite.privKey, suite.normalNonce, constant.AppchainMgrContractAddr.Address(), "Register",
|
2020-04-28 17:08:21 +08:00
|
|
|
pb.String(""),
|
2021-03-25 11:46:01 +08:00
|
|
|
pb.String("rbft"),
|
2020-04-28 17:08:21 +08:00
|
|
|
pb.String("hyperchain"),
|
|
|
|
pb.String("婚姻链"),
|
|
|
|
pb.String("趣链婚姻链"),
|
|
|
|
pb.String("1.8"),
|
|
|
|
pb.String(string(pubKey)),
|
2020-03-29 21:32:01 +08:00
|
|
|
)
|
|
|
|
suite.Assert().Nil(err)
|
2020-09-29 15:01:30 +08:00
|
|
|
suite.normalNonce++
|
2020-03-29 21:32:01 +08:00
|
|
|
|
2020-09-29 15:01:30 +08:00
|
|
|
receipt, err := invokeBVMContract(suite.api, suite.privKey, suite.normalNonce, constant.RoleContractAddr.Address(), "GetRole")
|
2020-03-29 21:32:01 +08:00
|
|
|
suite.Require().Nil(err)
|
|
|
|
suite.Equal("appchain_admin", string(receipt.Ret))
|
2020-09-29 15:01:30 +08:00
|
|
|
suite.normalNonce++
|
2020-03-29 21:32:01 +08:00
|
|
|
|
2020-08-11 14:07:15 +08:00
|
|
|
k, err := asym.GenerateKeyPair(crypto.Secp256k1)
|
2020-03-29 21:32:01 +08:00
|
|
|
suite.Require().Nil(err)
|
|
|
|
|
2020-09-29 15:01:30 +08:00
|
|
|
r, err := invokeBVMContract(suite.api, k, 1, constant.RoleContractAddr.Address(), "GetRole")
|
2020-03-29 21:32:01 +08:00
|
|
|
suite.Assert().Nil(err)
|
|
|
|
suite.Equal("none", string(r.Ret))
|
|
|
|
}
|
|
|
|
|
|
|
|
func (suite *Role) TestGetAdminRoles() {
|
2020-08-11 14:07:15 +08:00
|
|
|
k, err := asym.GenerateKeyPair(crypto.Secp256k1)
|
2020-03-29 21:32:01 +08:00
|
|
|
suite.Require().Nil(err)
|
2020-09-29 15:01:30 +08:00
|
|
|
kNonce := uint64(1)
|
2020-03-29 21:32:01 +08:00
|
|
|
|
2020-09-29 15:01:30 +08:00
|
|
|
r, err := invokeBVMContract(suite.api, k, kNonce, constant.RoleContractAddr.Address(), "GetAdminRoles")
|
2020-03-29 21:32:01 +08:00
|
|
|
suite.Assert().Nil(err)
|
|
|
|
ret := gjson.ParseBytes(r.Ret)
|
|
|
|
suite.EqualValues(4, len(ret.Array()))
|
2020-09-29 15:01:30 +08:00
|
|
|
kNonce++
|
2020-03-29 21:32:01 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func (suite *Role) TestIsAdmin() {
|
2020-07-02 16:03:53 +08:00
|
|
|
// Not Admin Chain
|
2020-08-11 14:07:15 +08:00
|
|
|
k, err := asym.GenerateKeyPair(crypto.Secp256k1)
|
2020-03-29 21:32:01 +08:00
|
|
|
suite.Require().Nil(err)
|
|
|
|
from, err := k.PublicKey().Address()
|
|
|
|
suite.Require().Nil(err)
|
2020-09-29 15:01:30 +08:00
|
|
|
kNonce := uint64(1)
|
2020-03-29 21:32:01 +08:00
|
|
|
|
2020-10-22 14:22:31 +08:00
|
|
|
r, err := invokeBVMContract(suite.api, k, kNonce, constant.RoleContractAddr.Address(), "IsAdmin", pb.String(from.String()))
|
2020-03-29 21:32:01 +08:00
|
|
|
suite.Assert().Nil(err)
|
|
|
|
ret, err := strconv.ParseBool(string(r.Ret))
|
|
|
|
suite.Assert().Nil(err)
|
|
|
|
suite.EqualValues(false, ret)
|
2020-09-29 15:01:30 +08:00
|
|
|
kNonce++
|
2020-07-02 16:03:53 +08:00
|
|
|
|
|
|
|
// Admin Chain
|
|
|
|
path := "./test_data/config/node1/key.json"
|
|
|
|
keyPath := filepath.Join(path)
|
2020-08-11 14:07:15 +08:00
|
|
|
priAdmin, err := asym.RestorePrivateKey(keyPath, "bitxhub")
|
2020-07-02 16:03:53 +08:00
|
|
|
suite.Require().Nil(err)
|
|
|
|
fromAdmin, err := priAdmin.PublicKey().Address()
|
|
|
|
suite.Require().Nil(err)
|
2020-10-22 14:22:31 +08:00
|
|
|
adminNonce := suite.api.Broker().GetPendingNonceByAccount(fromAdmin.String())
|
2020-07-02 16:03:53 +08:00
|
|
|
|
2020-10-22 14:22:31 +08:00
|
|
|
r, err = invokeBVMContract(suite.api, priAdmin, adminNonce, constant.RoleContractAddr.Address(), "IsAdmin", pb.String(fromAdmin.String()))
|
2020-07-02 16:03:53 +08:00
|
|
|
suite.Require().Nil(err)
|
|
|
|
suite.Require().True(r.IsSuccess())
|
|
|
|
ret, err = strconv.ParseBool(string(r.Ret))
|
|
|
|
suite.Assert().Nil(err)
|
|
|
|
suite.EqualValues(true, ret)
|
2020-09-29 15:01:30 +08:00
|
|
|
adminNonce++
|
2020-07-02 16:03:53 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func (suite *Role) TestGetRuleAddress() {
|
2021-03-25 11:46:01 +08:00
|
|
|
path1 := "./test_data/config/node1/key.json"
|
|
|
|
path2 := "./test_data/config/node2/key.json"
|
|
|
|
path3 := "./test_data/config/node3/key.json"
|
|
|
|
keyPath1 := filepath.Join(path1)
|
|
|
|
keyPath2 := filepath.Join(path2)
|
|
|
|
keyPath3 := filepath.Join(path3)
|
|
|
|
priAdmin1, err := asym.RestorePrivateKey(keyPath1, "bitxhub")
|
|
|
|
suite.Require().Nil(err)
|
|
|
|
priAdmin2, err := asym.RestorePrivateKey(keyPath2, "bitxhub")
|
|
|
|
suite.Require().Nil(err)
|
|
|
|
priAdmin3, err := asym.RestorePrivateKey(keyPath3, "bitxhub")
|
|
|
|
suite.Require().Nil(err)
|
|
|
|
fromAdmin1, err := priAdmin1.PublicKey().Address()
|
|
|
|
suite.Require().Nil(err)
|
|
|
|
fromAdmin2, err := priAdmin2.PublicKey().Address()
|
|
|
|
suite.Require().Nil(err)
|
|
|
|
fromAdmin3, err := priAdmin3.PublicKey().Address()
|
|
|
|
suite.Require().Nil(err)
|
|
|
|
adminNonce1 := suite.api.Broker().GetPendingNonceByAccount(fromAdmin1.String())
|
|
|
|
adminNonce2 := suite.api.Broker().GetPendingNonceByAccount(fromAdmin2.String())
|
|
|
|
adminNonce3 := suite.api.Broker().GetPendingNonceByAccount(fromAdmin3.String())
|
|
|
|
|
2020-08-11 14:07:15 +08:00
|
|
|
k1, err := asym.GenerateKeyPair(crypto.Secp256k1)
|
2020-07-02 16:03:53 +08:00
|
|
|
suite.Require().Nil(err)
|
2020-08-11 14:07:15 +08:00
|
|
|
k2, err := asym.GenerateKeyPair(crypto.Secp256k1)
|
2020-07-02 16:03:53 +08:00
|
|
|
suite.Require().Nil(err)
|
2020-09-29 15:01:30 +08:00
|
|
|
k1Nonce := uint64(1)
|
|
|
|
k2Nonce := uint64(1)
|
2020-07-02 16:03:53 +08:00
|
|
|
|
|
|
|
pub1, err := k1.PublicKey().Bytes()
|
|
|
|
suite.Require().Nil(err)
|
|
|
|
pub2, err := k2.PublicKey().Bytes()
|
|
|
|
suite.Require().Nil(err)
|
|
|
|
|
|
|
|
f1, err := k1.PublicKey().Address()
|
|
|
|
suite.Require().Nil(err)
|
|
|
|
f2, err := k2.PublicKey().Address()
|
|
|
|
suite.Require().Nil(err)
|
|
|
|
|
|
|
|
// Register
|
2020-09-29 15:01:30 +08:00
|
|
|
ret, err := invokeBVMContract(suite.api, k1, k1Nonce, constant.AppchainMgrContractAddr.Address(), "Register",
|
2020-07-02 16:03:53 +08:00
|
|
|
pb.String(""),
|
2021-03-25 11:46:01 +08:00
|
|
|
pb.String("rbft"),
|
2020-07-02 16:03:53 +08:00
|
|
|
pb.String("hyperchain"),
|
|
|
|
pb.String("婚姻链"),
|
|
|
|
pb.String("趣链婚姻链"),
|
|
|
|
pb.String("1.8"),
|
|
|
|
pb.String(string(pub1)),
|
|
|
|
)
|
|
|
|
suite.Require().Nil(err)
|
|
|
|
suite.Require().True(ret.IsSuccess(), string(ret.Ret))
|
2020-09-29 15:01:30 +08:00
|
|
|
k1Nonce++
|
2021-03-19 09:41:19 +08:00
|
|
|
id1 := gjson.Get(string(ret.Ret), "chain_id").String()
|
2021-03-25 11:46:01 +08:00
|
|
|
proposalId1 := gjson.Get(string(ret.Ret), "proposal_id").String()
|
|
|
|
|
|
|
|
ret, err = invokeBVMContract(suite.api, priAdmin1, adminNonce1, constant.GovernanceContractAddr.Address(), "Vote",
|
|
|
|
pb.String(proposalId1),
|
|
|
|
pb.String(string(contracts.APPOVED)),
|
|
|
|
pb.String("reason"),
|
|
|
|
)
|
|
|
|
suite.Require().Nil(err)
|
|
|
|
suite.Require().True(ret.IsSuccess(), string(ret.Ret))
|
|
|
|
adminNonce1++
|
|
|
|
|
|
|
|
ret, err = invokeBVMContract(suite.api, priAdmin2, adminNonce2, constant.GovernanceContractAddr.Address(), "Vote",
|
|
|
|
pb.String(proposalId1),
|
|
|
|
pb.String(string(contracts.APPOVED)),
|
|
|
|
pb.String("reason"),
|
|
|
|
)
|
|
|
|
suite.Require().Nil(err)
|
|
|
|
suite.Require().True(ret.IsSuccess(), string(ret.Ret))
|
|
|
|
adminNonce2++
|
|
|
|
|
|
|
|
ret, err = invokeBVMContract(suite.api, priAdmin3, adminNonce3, constant.GovernanceContractAddr.Address(), "Vote",
|
|
|
|
pb.String(proposalId1),
|
|
|
|
pb.String(string(contracts.APPOVED)),
|
|
|
|
pb.String("reason"),
|
|
|
|
)
|
|
|
|
suite.Require().Nil(err)
|
|
|
|
suite.Require().True(ret.IsSuccess(), string(ret.Ret))
|
|
|
|
adminNonce3++
|
2020-07-02 16:03:53 +08:00
|
|
|
|
2020-09-29 15:01:30 +08:00
|
|
|
ret, err = invokeBVMContract(suite.api, k2, k2Nonce, constant.AppchainMgrContractAddr.Address(), "Register",
|
2020-07-02 16:03:53 +08:00
|
|
|
pb.String(""),
|
2021-03-25 11:46:01 +08:00
|
|
|
pb.String("rbft"),
|
2020-07-02 16:03:53 +08:00
|
|
|
pb.String("fabric"),
|
|
|
|
pb.String("政务链"),
|
|
|
|
pb.String("fabric政务"),
|
|
|
|
pb.String("1.4"),
|
|
|
|
pb.String(string(pub2)),
|
|
|
|
)
|
|
|
|
suite.Require().Nil(err)
|
|
|
|
suite.Require().True(ret.IsSuccess(), string(ret.Ret))
|
2020-09-29 15:01:30 +08:00
|
|
|
k2Nonce++
|
2021-03-19 09:41:19 +08:00
|
|
|
id2 := gjson.Get(string(ret.Ret), "chain_id").String()
|
2021-03-25 11:46:01 +08:00
|
|
|
proposalId2 := gjson.Get(string(ret.Ret), "proposal_id").String()
|
|
|
|
|
|
|
|
ret, err = invokeBVMContract(suite.api, priAdmin1, adminNonce1, constant.GovernanceContractAddr.Address(), "Vote",
|
|
|
|
pb.String(proposalId2),
|
|
|
|
pb.String(string(contracts.APPOVED)),
|
|
|
|
pb.String("reason"),
|
|
|
|
)
|
|
|
|
suite.Require().Nil(err)
|
|
|
|
suite.Require().True(ret.IsSuccess(), string(ret.Ret))
|
|
|
|
adminNonce1++
|
|
|
|
|
|
|
|
ret, err = invokeBVMContract(suite.api, priAdmin2, adminNonce2, constant.GovernanceContractAddr.Address(), "Vote",
|
|
|
|
pb.String(proposalId2),
|
|
|
|
pb.String(string(contracts.APPOVED)),
|
|
|
|
pb.String("reason"),
|
|
|
|
)
|
|
|
|
suite.Require().Nil(err)
|
|
|
|
suite.Require().True(ret.IsSuccess(), string(ret.Ret))
|
|
|
|
adminNonce2++
|
|
|
|
|
|
|
|
ret, err = invokeBVMContract(suite.api, priAdmin3, adminNonce3, constant.GovernanceContractAddr.Address(), "Vote",
|
|
|
|
pb.String(proposalId2),
|
|
|
|
pb.String(string(contracts.APPOVED)),
|
|
|
|
pb.String("reason"),
|
|
|
|
)
|
|
|
|
suite.Require().Nil(err)
|
|
|
|
suite.Require().True(ret.IsSuccess(), string(ret.Ret))
|
|
|
|
adminNonce3++
|
2020-07-02 16:03:53 +08:00
|
|
|
|
|
|
|
// deploy rule
|
|
|
|
bytes, err := ioutil.ReadFile("./test_data/hpc_rule.wasm")
|
|
|
|
suite.Require().Nil(err)
|
2020-09-29 15:01:30 +08:00
|
|
|
addr1, err := deployContract(suite.api, k1, k1Nonce, bytes)
|
2020-07-02 16:03:53 +08:00
|
|
|
suite.Require().Nil(err)
|
2020-09-29 15:01:30 +08:00
|
|
|
k1Nonce++
|
2020-07-02 16:03:53 +08:00
|
|
|
|
|
|
|
bytes, err = ioutil.ReadFile("./test_data/fabric_policy.wasm")
|
|
|
|
suite.Require().Nil(err)
|
2020-09-29 15:01:30 +08:00
|
|
|
addr2, err := deployContract(suite.api, k2, k2Nonce, bytes)
|
2020-07-02 16:03:53 +08:00
|
|
|
suite.Require().Nil(err)
|
2020-09-29 15:01:30 +08:00
|
|
|
k2Nonce++
|
2020-07-02 16:03:53 +08:00
|
|
|
|
|
|
|
suite.Require().NotEqual(addr1, addr2)
|
|
|
|
|
|
|
|
// register rule
|
2020-10-22 14:22:31 +08:00
|
|
|
ret, err = invokeBVMContract(suite.api, k1, k1Nonce, constant.RuleManagerContractAddr.Address(), "RegisterRule", pb.String(f1.String()), pb.String(addr1.String()))
|
2020-07-02 16:03:53 +08:00
|
|
|
suite.Require().Nil(err)
|
|
|
|
suite.Require().True(ret.IsSuccess())
|
2020-09-29 15:01:30 +08:00
|
|
|
k1Nonce++
|
2020-07-02 16:03:53 +08:00
|
|
|
|
2020-10-22 14:22:31 +08:00
|
|
|
ret, err = invokeBVMContract(suite.api, k2, k2Nonce, constant.RuleManagerContractAddr.Address(), "RegisterRule", pb.String(f2.String()), pb.String(addr2.String()))
|
2020-07-02 16:03:53 +08:00
|
|
|
suite.Require().Nil(err)
|
|
|
|
suite.Require().True(ret.IsSuccess())
|
2020-09-29 15:01:30 +08:00
|
|
|
k2Nonce++
|
2020-07-02 16:03:53 +08:00
|
|
|
|
|
|
|
// get role address
|
2020-09-29 15:01:30 +08:00
|
|
|
ret, err = invokeBVMContract(suite.api, k1, k1Nonce, constant.RuleManagerContractAddr.Address(), "GetRuleAddress", pb.String(string(id1)), pb.String("hyperchain"))
|
2020-07-02 16:03:53 +08:00
|
|
|
suite.Assert().Nil(err)
|
|
|
|
suite.Require().True(ret.IsSuccess())
|
|
|
|
suite.Require().Equal(addr1.String(), string(ret.Ret))
|
2020-09-29 15:01:30 +08:00
|
|
|
k1Nonce++
|
2020-07-02 16:03:53 +08:00
|
|
|
|
2020-09-29 15:01:30 +08:00
|
|
|
ret, err = invokeBVMContract(suite.api, k2, k2Nonce, constant.RuleManagerContractAddr.Address(), "GetRuleAddress", pb.String(string(id2)), pb.String("fabric"))
|
2020-07-02 16:03:53 +08:00
|
|
|
suite.Assert().Nil(err)
|
|
|
|
suite.Require().True(ret.IsSuccess())
|
|
|
|
suite.Require().Equal(addr2.String(), string(ret.Ret))
|
2020-09-29 15:01:30 +08:00
|
|
|
k2Nonce++
|
2020-07-02 16:03:53 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func (suite *Role) TestSetAdminRoles() {
|
|
|
|
// admin chain
|
|
|
|
path1 := "./test_data/config/node1/key.json"
|
|
|
|
keyPath1 := filepath.Join(path1)
|
2020-08-11 14:07:15 +08:00
|
|
|
priAdmin, err := asym.RestorePrivateKey(keyPath1, "bitxhub")
|
2020-07-02 16:03:53 +08:00
|
|
|
suite.Require().Nil(err)
|
|
|
|
fromAdmin, err := priAdmin.PublicKey().Address()
|
|
|
|
suite.Require().Nil(err)
|
|
|
|
pubAdmin, err := priAdmin.PublicKey().Bytes()
|
|
|
|
suite.Require().Nil(err)
|
2020-10-22 14:22:31 +08:00
|
|
|
adminNonce := suite.api.Broker().GetPendingNonceByAccount(fromAdmin.String())
|
2020-07-02 16:03:53 +08:00
|
|
|
|
|
|
|
// register
|
2020-09-29 15:01:30 +08:00
|
|
|
retReg, err := invokeBVMContract(suite.api, priAdmin, adminNonce, constant.AppchainMgrContractAddr.Address(), "Register",
|
2020-07-02 16:03:53 +08:00
|
|
|
pb.String(""),
|
2021-03-25 11:46:01 +08:00
|
|
|
pb.String("rbft"),
|
2020-07-02 16:03:53 +08:00
|
|
|
pb.String("hyperchain"),
|
|
|
|
pb.String("管理链"),
|
|
|
|
pb.String("趣链管理链"),
|
|
|
|
pb.String("1.8"),
|
|
|
|
pb.String(string(pubAdmin)),
|
|
|
|
)
|
|
|
|
suite.Require().Nil(err)
|
|
|
|
suite.Require().True(retReg.IsSuccess(), string(retReg.Ret))
|
2020-09-29 15:01:30 +08:00
|
|
|
adminNonce++
|
2020-07-02 16:03:53 +08:00
|
|
|
|
|
|
|
// is admin
|
2020-10-22 14:22:31 +08:00
|
|
|
retIsAdmin, err := invokeBVMContract(suite.api, priAdmin, adminNonce, constant.RoleContractAddr.Address(), "IsAdmin", pb.String(fromAdmin.String()))
|
2020-07-02 16:03:53 +08:00
|
|
|
suite.Require().Nil(err)
|
|
|
|
suite.Require().True(retIsAdmin.IsSuccess())
|
2020-09-29 15:01:30 +08:00
|
|
|
adminNonce++
|
2020-07-02 16:03:53 +08:00
|
|
|
|
|
|
|
// get admin roles
|
2020-09-29 15:01:30 +08:00
|
|
|
r1, err := invokeBVMContract(suite.api, priAdmin, adminNonce, constant.RoleContractAddr.Address(), "GetAdminRoles")
|
2020-07-02 16:03:53 +08:00
|
|
|
suite.Assert().Nil(err)
|
|
|
|
ret1 := gjson.ParseBytes(r1.Ret)
|
|
|
|
suite.EqualValues(4, len(ret1.Array()))
|
2020-09-29 15:01:30 +08:00
|
|
|
adminNonce++
|
2020-07-02 16:03:53 +08:00
|
|
|
|
|
|
|
as := make([]string, 0)
|
2020-10-22 14:22:31 +08:00
|
|
|
as = append(as, fromAdmin.String())
|
2020-07-02 16:03:53 +08:00
|
|
|
data, err := json.Marshal(as)
|
|
|
|
suite.Nil(err)
|
|
|
|
|
|
|
|
// set admin roles
|
2020-09-29 15:01:30 +08:00
|
|
|
r, err := invokeBVMContract(suite.api, priAdmin, adminNonce, constant.RoleContractAddr.Address(), "SetAdminRoles", pb.String(string(data)))
|
2020-07-02 16:03:53 +08:00
|
|
|
suite.Require().Nil(err)
|
|
|
|
suite.Require().True(r.IsSuccess())
|
2020-09-29 15:01:30 +08:00
|
|
|
adminNonce++
|
2020-07-02 16:03:53 +08:00
|
|
|
|
|
|
|
// get admin roles
|
2020-09-29 15:01:30 +08:00
|
|
|
r2, err := invokeBVMContract(suite.api, priAdmin, adminNonce, constant.RoleContractAddr.Address(), "GetAdminRoles")
|
2020-07-02 16:03:53 +08:00
|
|
|
suite.Assert().Nil(err)
|
|
|
|
ret2 := gjson.ParseBytes(r2.Ret)
|
|
|
|
suite.EqualValues(1, len(ret2.Array()))
|
2020-09-29 15:01:30 +08:00
|
|
|
adminNonce++
|
2020-07-02 16:03:53 +08:00
|
|
|
|
|
|
|
// set more admin roles
|
|
|
|
path2 := "./test_data/config/node2/key.json"
|
|
|
|
path3 := "./test_data/config/node3/key.json"
|
|
|
|
path4 := "./test_data/config/node4/key.json"
|
|
|
|
|
|
|
|
keyPath2 := filepath.Join(path2)
|
|
|
|
keyPath3 := filepath.Join(path3)
|
|
|
|
keyPath4 := filepath.Join(path4)
|
|
|
|
|
2020-08-11 14:07:15 +08:00
|
|
|
priAdmin2, err := asym.RestorePrivateKey(keyPath2, "bitxhub")
|
2020-07-02 16:03:53 +08:00
|
|
|
suite.Require().Nil(err)
|
2020-08-11 14:07:15 +08:00
|
|
|
priAdmin3, err := asym.RestorePrivateKey(keyPath3, "bitxhub")
|
2020-07-02 16:03:53 +08:00
|
|
|
suite.Require().Nil(err)
|
2020-08-11 14:07:15 +08:00
|
|
|
priAdmin4, err := asym.RestorePrivateKey(keyPath4, "bitxhub")
|
2020-07-02 16:03:53 +08:00
|
|
|
suite.Require().Nil(err)
|
|
|
|
|
|
|
|
fromAdmin2, err := priAdmin2.PublicKey().Address()
|
|
|
|
suite.Require().Nil(err)
|
|
|
|
fromAdmin3, err := priAdmin3.PublicKey().Address()
|
|
|
|
suite.Require().Nil(err)
|
|
|
|
fromAdmin4, err := priAdmin4.PublicKey().Address()
|
|
|
|
suite.Require().Nil(err)
|
|
|
|
|
|
|
|
// set admin roles
|
|
|
|
as2 := make([]string, 0)
|
2020-10-22 14:22:31 +08:00
|
|
|
as2 = append(as2, fromAdmin.String(), fromAdmin2.String(), fromAdmin3.String(), fromAdmin4.String())
|
2020-07-02 16:03:53 +08:00
|
|
|
data2, err := json.Marshal(as2)
|
|
|
|
suite.Nil(err)
|
2020-09-29 15:01:30 +08:00
|
|
|
r, err = invokeBVMContract(suite.api, priAdmin, adminNonce, constant.RoleContractAddr.Address(), "SetAdminRoles", pb.String(string(data2)))
|
2020-07-02 16:03:53 +08:00
|
|
|
suite.Require().Nil(err)
|
|
|
|
suite.Require().True(r.IsSuccess())
|
2020-09-29 15:01:30 +08:00
|
|
|
adminNonce++
|
2020-07-02 16:03:53 +08:00
|
|
|
|
|
|
|
// get Admin Roles
|
2020-09-29 15:01:30 +08:00
|
|
|
r3, err := invokeBVMContract(suite.api, priAdmin, adminNonce, constant.RoleContractAddr.Address(), "GetAdminRoles")
|
2020-07-02 16:03:53 +08:00
|
|
|
suite.Assert().Nil(err)
|
|
|
|
ret3 := gjson.ParseBytes(r3.Ret)
|
|
|
|
suite.EqualValues(4, len(ret3.Array()))
|
2020-09-29 15:01:30 +08:00
|
|
|
adminNonce++
|
2020-03-29 21:32:01 +08:00
|
|
|
}
|