mirror of
https://gitee.com/BTAJL/repchain.git
synced 2024-11-30 02:38:24 +08:00
保留无权限的账户管理合约以及转账测试例,修改ContractCert以及测试用的ContractAssetsTPL,使之能够在新版下使用,并且修改与之对应的测试用例、genesis.json构建工具类
This commit is contained in:
parent
8f28345455
commit
b08031455e
@ -29,75 +29,79 @@ import rep.sc.scalax.ContractException
|
||||
import rep.protos.peer.ActionResult
|
||||
|
||||
/**
|
||||
* 资产管理合约
|
||||
*/
|
||||
* 资产管理合约
|
||||
*/
|
||||
|
||||
final case class Transfer(from:String, to:String, amount:Int)
|
||||
final case class Transfer(from: String, to: String, amount: Int)
|
||||
|
||||
class ContractAssetsTPL extends IContract{
|
||||
class ContractAssetsTPL extends IContract {
|
||||
|
||||
// 需要跨合约读账户
|
||||
val chaincodeName = SystemProfile.getAccountChaincodeName
|
||||
val chaincodeVersion = SystemProfile.getAccountChaincodeVersion
|
||||
val chaincodeVersion = SystemProfile.getAccountChaincodeVersion
|
||||
//val prefix = IdTool.getCid(ChaincodeId(chaincodeName, chaincodeVersion))
|
||||
|
||||
implicit val formats = DefaultFormats
|
||||
|
||||
def init(ctx: ContractContext){
|
||||
println(s"tid: $ctx.t.id")
|
||||
}
|
||||
|
||||
def set(ctx: ContractContext, data:Map[String,Int]) :ActionResult={
|
||||
println(s"set data:$data")
|
||||
for((k,v)<-data){
|
||||
ctx.api.setVal(k, v)
|
||||
}
|
||||
null
|
||||
}
|
||||
|
||||
def transfer(ctx: ContractContext, data:Transfer) :ActionResult={
|
||||
if(!data.from.equals(ctx.t.getSignature.getCertId.creditCode))
|
||||
throw ContractException("只允许从本人账户转出")
|
||||
val signerKey = data.to
|
||||
// 跨合约读账户,该处并未反序列化
|
||||
if(ctx.api.getStateEx(chaincodeName,data.to)==null)
|
||||
throw ContractException("目标账户不存在")
|
||||
val sfrom:Any = ctx.api.getVal(data.from)
|
||||
var dfrom =sfrom.asInstanceOf[Int]
|
||||
if(dfrom < data.amount)
|
||||
throw ContractException("余额不足")
|
||||
ctx.api.setVal(data.from,dfrom - data.amount)
|
||||
var dto = ctx.api.getVal(data.to).toString.toInt
|
||||
ctx.api.setVal(data.to,dto + data.amount)
|
||||
null
|
||||
}
|
||||
|
||||
def put_proof(ctx: ContractContext, data:Map[String,Any]): ActionResult={
|
||||
//先检查该hash是否已经存在,如果已存在,抛异常
|
||||
for((k,v)<-data){
|
||||
var pv0:Any = ctx.api.getVal(k)
|
||||
if(pv0 != null)
|
||||
// throw new Exception("["+k+"]已存在,当前值["+pv0+"]");
|
||||
throw ContractException(s"$k 已存在,当前值为 $pv0")
|
||||
ctx.api.setVal(k,v)
|
||||
print("putProof:"+k+":"+v)
|
||||
def init(ctx: ContractContext) {
|
||||
println(s"tid: $ctx.t.id")
|
||||
}
|
||||
|
||||
def set(ctx: ContractContext, data: Map[String, Int]): ActionResult = {
|
||||
println(s"set data:$data")
|
||||
for ((k, v) <- data) {
|
||||
ctx.api.setVal(k, v)
|
||||
}
|
||||
null
|
||||
null
|
||||
}
|
||||
|
||||
def transfer(ctx: ContractContext, data: Transfer): ActionResult = {
|
||||
if (!data.from.equals(ctx.t.getSignature.getCertId.creditCode))
|
||||
throw ContractException("只允许从本人账户转出")
|
||||
val signerKey = data.to
|
||||
// 跨合约读账户,该处并未反序列化
|
||||
if (IdTool.isDidContract) {
|
||||
if (ctx.api.getStateEx(chaincodeName, "signer_" + data.to) == null)
|
||||
throw ContractException("目标账户不存在")
|
||||
} else {
|
||||
if (ctx.api.getStateEx(chaincodeName, data.to) == null)
|
||||
throw ContractException("目标账户不存在")
|
||||
}
|
||||
val sfrom: Any = ctx.api.getVal(data.from)
|
||||
val dfrom = sfrom.asInstanceOf[Int]
|
||||
if (dfrom < data.amount)
|
||||
throw ContractException("余额不足")
|
||||
ctx.api.setVal(data.from, dfrom - data.amount)
|
||||
val dto = ctx.api.getVal(data.to).toString.toInt
|
||||
ctx.api.setVal(data.to, dto + data.amount)
|
||||
null
|
||||
}
|
||||
|
||||
def put_proof(ctx: ContractContext, data: Map[String, Any]): ActionResult = {
|
||||
//先检查该hash是否已经存在,如果已存在,抛异常
|
||||
for ((k, v) <- data) {
|
||||
val pv0: Any = ctx.api.getVal(k)
|
||||
if (pv0 != null)
|
||||
throw ContractException(s"[$k] 已存在,当前值为 [$pv0]")
|
||||
ctx.api.setVal(k, v)
|
||||
print("putProof:" + k + ":" + v)
|
||||
}
|
||||
null
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据action,找到对应的method,并将传入的json字符串parse为method需要的传入参数
|
||||
*/
|
||||
def onAction(ctx: ContractContext,action:String, sdata:String ):ActionResult={
|
||||
val json = parse(sdata)
|
||||
action match {
|
||||
case "transfer" =>
|
||||
transfer(ctx,json.extract[Transfer])
|
||||
case "set" =>
|
||||
set(ctx, json.extract[Map[String,Int]])
|
||||
case "putProof" =>
|
||||
put_proof(ctx, json.extract[Map[String,Any]])
|
||||
}
|
||||
* 根据action,找到对应的method,并将传入的json字符串parse为method需要的传入参数
|
||||
*/
|
||||
def onAction(ctx: ContractContext, action: String, sdata: String): ActionResult = {
|
||||
val json = parse(sdata)
|
||||
action match {
|
||||
case "transfer" =>
|
||||
transfer(ctx, json.extract[Transfer])
|
||||
case "set" =>
|
||||
set(ctx, json.extract[Map[String, Int]])
|
||||
case "putProof" =>
|
||||
put_proof(ctx, json.extract[Map[String, Any]])
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,95 +0,0 @@
|
||||
/*
|
||||
* Copyright 2019 Blockchain Technology and Application Joint Lab, Linkel Technology Co., Ltd, Beijing, Fintech Research Center of ISCAS.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BA SIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
*/
|
||||
|
||||
package rep.sc.tpl
|
||||
|
||||
import org.json4s._
|
||||
import org.json4s.jackson.JsonMethods._
|
||||
import rep.app.conf.SystemProfile
|
||||
import rep.protos.peer.ChaincodeId
|
||||
import rep.utils.IdTool
|
||||
import java.text.SimpleDateFormat
|
||||
|
||||
import rep.sc.scalax.{ContractContext, ContractException, IContract}
|
||||
import rep.protos.peer.ActionResult
|
||||
|
||||
/**
|
||||
* 资产管理合约
|
||||
*/
|
||||
|
||||
|
||||
class ContractAssetsTPL2 extends IContract{
|
||||
case class Transfer(from:String, to:String, amount:Int)
|
||||
|
||||
// 需要跨合约读账户
|
||||
val chaincodeName = SystemProfile.getAccountChaincodeName
|
||||
val chaincodeVersion = SystemProfile.getAccountChaincodeVersion
|
||||
//val prefix = IdTool.getCid(ChaincodeId(chaincodeName, chaincodeVersion))
|
||||
|
||||
implicit val formats = DefaultFormats
|
||||
|
||||
def init(ctx: ContractContext){
|
||||
println(s"tid: $ctx.t.id")
|
||||
}
|
||||
|
||||
def set(ctx: ContractContext, data:Map[String,Int]) :ActionResult={
|
||||
println(s"set data:$data")
|
||||
for((k,v)<-data){
|
||||
ctx.api.setVal(k, v)
|
||||
}
|
||||
null
|
||||
}
|
||||
|
||||
def transfer(ctx: ContractContext, data:Transfer) :ActionResult={
|
||||
if(!data.from.equals(ctx.t.getSignature.getCertId.creditCode))
|
||||
throw ContractException("只允许从本人账户转出")
|
||||
val signerKey = data.to
|
||||
// 跨合约读账户,该处并未反序列化
|
||||
if(ctx.api.getStateEx(chaincodeName,data.to)==null)
|
||||
throw ContractException("目标账户不存在")
|
||||
val sfrom:Any = ctx.api.getVal(data.from)
|
||||
var dfrom =sfrom.asInstanceOf[Int]
|
||||
if(dfrom < data.amount)
|
||||
throw ContractException("余额不足")
|
||||
var dto = ctx.api.getVal(data.to).toString.toInt
|
||||
|
||||
val df:SimpleDateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ")
|
||||
val t1 = System.currentTimeMillis()
|
||||
val s1 = s"setval begin:${ctx.t.id} " + df.format(t1)
|
||||
|
||||
ctx.api.setVal(data.from,dfrom - data.amount)
|
||||
//for test 同合约交易串行测试
|
||||
Thread.sleep(5000)
|
||||
ctx.api.setVal(data.to,dto + data.amount)
|
||||
val t2 = System.currentTimeMillis()
|
||||
val s2 = s"setval end:${ctx.t.id} " + df.format(t2)
|
||||
print("\n"+s1+"\n"+s2)
|
||||
null
|
||||
}
|
||||
/**
|
||||
* 根据action,找到对应的method,并将传入的json字符串parse为method需要的传入参数
|
||||
*/
|
||||
def onAction(ctx: ContractContext,action:String, sdata:String ):ActionResult={
|
||||
val json = parse(sdata)
|
||||
action match {
|
||||
case "transfer" =>
|
||||
transfer(ctx,json.extract[ Transfer])
|
||||
case "set" =>
|
||||
set(ctx, json.extract[Map[String,Int]])
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -23,79 +23,84 @@ import rep.app.conf.SystemProfile
|
||||
import rep.protos.peer.ChaincodeId
|
||||
import rep.utils.IdTool
|
||||
import java.text.SimpleDateFormat
|
||||
import rep.sc.scalax.IContract
|
||||
|
||||
import rep.sc.scalax.{ContractContext, ContractException, IContract}
|
||||
import rep.protos.peer.ActionResult
|
||||
import rep.sc.scalax.ContractContext
|
||||
|
||||
|
||||
/**
|
||||
* 资产管理合约
|
||||
*/
|
||||
* 资产管理合约
|
||||
*/
|
||||
|
||||
final case class TransferForLegal(from:String, to:String, amount:Int, remind:String)
|
||||
class ContractAssetsTPL_Legal extends IContract{
|
||||
final case class TransferForLegal(from: String, to: String, amount: Int, remind: String)
|
||||
|
||||
class ContractAssetsTPL_Legal extends IContract {
|
||||
|
||||
// 需要跨合约读账户
|
||||
val chaincodeName = SystemProfile.getAccountChaincodeName
|
||||
val chaincodeVersion = SystemProfile.getAccountChaincodeVersion
|
||||
val chaincodeVersion = SystemProfile.getAccountChaincodeVersion
|
||||
//val prefix = IdTool.getCid(ChaincodeId(chaincodeName, chaincodeVersion))
|
||||
|
||||
implicit val formats = DefaultFormats
|
||||
|
||||
def init(ctx: ContractContext){
|
||||
println(s"tid: $ctx.t.id")
|
||||
|
||||
def init(ctx: ContractContext) {
|
||||
println(s"tid: $ctx.t.id")
|
||||
}
|
||||
|
||||
def set(ctx: ContractContext, data: Map[String, Int]): ActionResult = {
|
||||
println(s"set data:$data")
|
||||
for ((k, v) <- data) {
|
||||
ctx.api.setVal(k, v)
|
||||
}
|
||||
|
||||
def set(ctx: ContractContext, data:Map[String,Int]) :ActionResult={
|
||||
println(s"set data:$data")
|
||||
for((k,v)<-data){
|
||||
ctx.api.setVal(k, v)
|
||||
}
|
||||
new ActionResult(1)
|
||||
new ActionResult(1)
|
||||
}
|
||||
|
||||
def transfer(ctx: ContractContext, data: TransferForLegal): ActionResult = {
|
||||
if (!data.from.equals(ctx.t.getSignature.getCertId.creditCode))
|
||||
return new ActionResult(-1, "只允许从本人账户转出")
|
||||
// 跨合约读账户,该处并未反序列化
|
||||
if (IdTool.isDidContract) {
|
||||
if (ctx.api.getStateEx(chaincodeName, "signer_" + data.to) == null)
|
||||
return new ActionResult(-2, "目标账户不存在")
|
||||
} else {
|
||||
if (ctx.api.getStateEx(chaincodeName, data.to) == null)
|
||||
return new ActionResult(-2, "目标账户不存在")
|
||||
}
|
||||
|
||||
def transfer(ctx: ContractContext, data:TransferForLegal) :ActionResult={
|
||||
if(!data.from.equals(ctx.t.getSignature.getCertId.creditCode))
|
||||
return new ActionResult(-1, "只允许从本人账户转出")
|
||||
val signerKey = data.to
|
||||
// 跨合约读账户,该处并未反序列化
|
||||
if(ctx.api.getStateEx(chaincodeName,data.to)==null)
|
||||
return new ActionResult(-2, "目标账户不存在")
|
||||
|
||||
val sfrom:Any = ctx.api.getVal(data.from)
|
||||
var dfrom =sfrom.asInstanceOf[Int]
|
||||
if(dfrom < data.amount)
|
||||
return new ActionResult(-3, "余额不足")
|
||||
|
||||
val rstr = s"""确定签名从本人所持有的账户【${data.from}】
|
||||
val sfrom: Any = ctx.api.getVal(data.from)
|
||||
val dfrom = sfrom.asInstanceOf[Int]
|
||||
if (dfrom < data.amount)
|
||||
return new ActionResult(-3, "余额不足")
|
||||
|
||||
val rstr =
|
||||
s"""确定签名从本人所持有的账户【${data.from}】
|
||||
向账户【${data.to}】
|
||||
转账【${data.amount}】元"""
|
||||
//预执行获得结果提醒
|
||||
if(data.remind==null){
|
||||
new ActionResult(2,rstr)
|
||||
}else{
|
||||
if(!data.remind.equals(rstr))
|
||||
new ActionResult(-4,"提醒内容不符")
|
||||
else{
|
||||
var dto = ctx.api.getVal(data.to).toString.toInt
|
||||
ctx.api.setVal(data.from,dfrom - data.amount)
|
||||
ctx.api.setVal(data.to,dto + data.amount)
|
||||
new ActionResult(1)
|
||||
}
|
||||
//预执行获得结果提醒
|
||||
if (data.remind == null) {
|
||||
new ActionResult(2, rstr)
|
||||
} else {
|
||||
if (!data.remind.equals(rstr))
|
||||
new ActionResult(-4, "提醒内容不符")
|
||||
else {
|
||||
val dto = ctx.api.getVal(data.to).toString.toInt
|
||||
ctx.api.setVal(data.from, dfrom - data.amount)
|
||||
ctx.api.setVal(data.to, dto + data.amount)
|
||||
new ActionResult(1)
|
||||
}
|
||||
}
|
||||
/**
|
||||
* 根据action,找到对应的method,并将传入的json字符串parse为method需要的传入参数
|
||||
*/
|
||||
def onAction(ctx: ContractContext,action:String, sdata:String ):ActionResult={
|
||||
val json = parse(sdata)
|
||||
action match {
|
||||
case "transfer" =>
|
||||
transfer(ctx,json.extract[TransferForLegal])
|
||||
case "set" =>
|
||||
set(ctx, json.extract[Map[String,Int]])
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据action,找到对应的method,并将传入的json字符串parse为method需要的传入参数
|
||||
*/
|
||||
def onAction(ctx: ContractContext, action: String, sdata: String): ActionResult = {
|
||||
val json = parse(sdata)
|
||||
action match {
|
||||
case "transfer" =>
|
||||
transfer(ctx, json.extract[TransferForLegal])
|
||||
case "set" =>
|
||||
set(ctx, json.extract[Map[String, Int]])
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -22,15 +22,15 @@ import org.json4s.jackson.JsonMethods._
|
||||
import scala.collection.mutable.Map
|
||||
import org.json4s.DefaultFormats
|
||||
import rep.app.conf.SystemProfile
|
||||
import rep.utils.{ IdTool, SerializeUtils }
|
||||
import rep.sc.scalax.{ ContractContext, ContractException, IContract }
|
||||
import rep.utils.{IdTool, SerializeUtils}
|
||||
import rep.sc.scalax.{ContractContext, ContractException, IContract}
|
||||
import rep.protos.peer.ActionResult
|
||||
import scalapb.json4s.JsonFormat
|
||||
|
||||
/**
|
||||
* @author zyf
|
||||
*/
|
||||
final case class CertStatus(credit_code: String, name: String, status: Boolean)
|
||||
final case class CertInfo(credit_code: String, name: String, cert: Certificate)
|
||||
class ContractCert extends IContract {
|
||||
//case class CertStatus(credit_code: String, name: String, status: Boolean)
|
||||
//case class CertInfo(credit_code: String, name: String, cert: Certificate)
|
||||
@ -43,8 +43,6 @@ class ContractCert extends IContract {
|
||||
val certExists = "证书已存在"
|
||||
val certNotExists = "证书不存在"
|
||||
val unknownError = "未知错误"
|
||||
val chaincodeName = SystemProfile.getAccountChaincodeName
|
||||
val chaincodeVersion = SystemProfile.getAccountChaincodeVersion
|
||||
//val prefix = IdTool.getCid(ChaincodeId(chaincodeName, chaincodeVersion))
|
||||
val underline = "_"
|
||||
val dot = "."
|
||||
@ -84,27 +82,27 @@ class ContractCert extends IContract {
|
||||
/**
|
||||
* 注册用户证书:1、将name加到账户中;2、将Certificate保存
|
||||
* @param ctx
|
||||
* @param data
|
||||
* @param cert
|
||||
* @return
|
||||
*/
|
||||
def signUpCert(ctx: ContractContext, data: CertInfo): ActionResult = {
|
||||
def signUpCert(ctx: ContractContext, cert: Certificate): ActionResult = {
|
||||
val isNodeCert = ctx.api.bNodeCreditCode(ctx.t.getSignature.getCertId.creditCode)
|
||||
if (!isNodeCert) {
|
||||
throw ContractException(notNodeCert)
|
||||
}
|
||||
val certKey = data.credit_code + dot + data.name
|
||||
val certKey = cert.getId.creditCode + dot + cert.getId.certName
|
||||
val certInfo = ctx.api.getState(certKey)
|
||||
val signerKey = data.credit_code
|
||||
val signerKey = cert.getId.creditCode
|
||||
val signerContent = ctx.api.getState(signerKey)
|
||||
// 先判断证书,若证书不存在,则向账户添加name
|
||||
if (certInfo == null) {
|
||||
if (signerContent == null) {
|
||||
throw ContractException(signerNotExists)
|
||||
} else {
|
||||
ctx.api.setVal(certKey, data.cert)
|
||||
ctx.api.setVal(certKey, cert)
|
||||
val signer = SerializeUtils.deserialise(signerContent).asInstanceOf[Signer]
|
||||
if (!signer.certNames.contains(data.name)) {
|
||||
val signerNew = signer.addCertNames(data.name)
|
||||
if (!signer.certNames.contains(cert.getId.certName)) {
|
||||
val signerNew = signer.addCertNames(cert.getId.certName)
|
||||
ctx.api.setVal(signerKey, signerNew)
|
||||
}
|
||||
}
|
||||
@ -172,10 +170,10 @@ class ContractCert extends IContract {
|
||||
action match {
|
||||
case ACTION.SignUpSigner =>
|
||||
println("SignUpSigner")
|
||||
signUpSigner(ctx, json.extract[Signer])
|
||||
signUpSigner(ctx, JsonFormat.fromJson[Signer](json))
|
||||
case ACTION.SignUpCert =>
|
||||
println("SignUpCert")
|
||||
signUpCert(ctx, json.extract[CertInfo])
|
||||
signUpCert(ctx, JsonFormat.fromJson[Certificate](json))
|
||||
case ACTION.UpdateCertStatus =>
|
||||
println("UpdateCertStatus")
|
||||
updateCertStatus(ctx, json.extract[CertStatus])
|
||||
|
@ -84,7 +84,7 @@ object GenesisBuilder {
|
||||
|
||||
for(i<-0 to 5){
|
||||
translist(i+1) = PeerHelper.createTransaction4Invoke("951002007l78123233.super_admin", cid,
|
||||
"SignUpSigner", Seq(SerializeUtils.compactJson(signers(i))))
|
||||
"SignUpSigner", Seq(JsonFormat.toJsonString(signers(i))))
|
||||
}
|
||||
|
||||
|
||||
@ -94,11 +94,10 @@ object GenesisBuilder {
|
||||
// val cert = SignTool.getCertByFile("jks/"+signers(i).creditCode+"."+signers(i).name+".cer")
|
||||
val millis = System.currentTimeMillis()
|
||||
|
||||
val tmp = rep.protos.peer.Certificate(certstr,"SHA1withECDSA",true,Option(Timestamp(millis/1000 , ((millis % 1000) * 1000000).toInt)))
|
||||
val tmp = Certificate(certstr,"SHA1withECDSA",true,Option(Timestamp(millis/1000 , ((millis % 1000) * 1000000).toInt)), id = Option(CertId(signers(i).creditCode, signers(i).name)))
|
||||
//val aa = new ContractCert
|
||||
val a : CertInfo = CertInfo(signers(i).creditCode,signers(i).name,tmp)
|
||||
translist(i+7) = PeerHelper.createTransaction4Invoke("951002007l78123233.super_admin", cid,
|
||||
"SignUpCert", Seq(SerializeUtils.compactJson(a)))
|
||||
"SignUpCert", Seq(JsonFormat.toJsonString(tmp)))
|
||||
}
|
||||
|
||||
|
||||
|
@ -24,8 +24,7 @@ import org.json4s.jackson.JsonMethods.{pretty, render}
|
||||
import org.json4s.{DefaultFormats, jackson}
|
||||
import rep.crypto.cert.SignTool
|
||||
import rep.network.autotransaction.PeerHelper
|
||||
import rep.protos.peer.{Block, ChaincodeId, Signer, Transaction}
|
||||
import rep.sc.tpl.CertInfo
|
||||
import rep.protos.peer._
|
||||
import scalapb.json4s.JsonFormat
|
||||
|
||||
import scala.collection.mutable
|
||||
@ -52,7 +51,7 @@ object GenesisBuilderMulti {
|
||||
|
||||
//交易发起人是超级管理员
|
||||
//增加scala的资产管理合约
|
||||
val s1 = scala.io.Source.fromFile("src/main/scala/rep/sc/tpl/ContractCert.scala","UTF-8")
|
||||
val s1 = scala.io.Source.fromFile("src/main/scala/rep/sc/tpl/ContractCert.scala", "UTF-8")
|
||||
val l1 = try s1.mkString finally s1.close()
|
||||
val cid1 = new ChaincodeId("ContractCert", 1)
|
||||
val dep_trans = PeerHelper.createTransaction4Deploy("951002007l78123233.super_admin", cid1, l1, "", 5000, rep.protos.peer.ChaincodeDeploy.CodeType.CODE_SCALA)
|
||||
@ -63,16 +62,16 @@ object GenesisBuilderMulti {
|
||||
signers(0) = Signer("super_admin", "951002007l78123233", "18912345678", List("super_admin"))
|
||||
|
||||
for (i <- signers.indices) {
|
||||
transList.add(PeerHelper.createTransaction4Invoke("951002007l78123233.super_admin", cid1, "SignUpSigner", Seq(SerializeUtils.compactJson(signers(i)))))
|
||||
transList.add(PeerHelper.createTransaction4Invoke("951002007l78123233.super_admin", cid1, "SignUpSigner", Seq(JsonFormat.toJsonString(signers(i)))))
|
||||
}
|
||||
|
||||
val certs = fillCerts(signers)
|
||||
for (i <- certs.indices) {
|
||||
transList.add(PeerHelper.createTransaction4Invoke("951002007l78123233.super_admin", cid1, "SignUpCert", Seq(SerializeUtils.compactJson(certs(i)))))
|
||||
transList.add(PeerHelper.createTransaction4Invoke("951002007l78123233.super_admin", cid1, "SignUpCert", Seq(JsonFormat.toJsonString(certs(i)))))
|
||||
}
|
||||
|
||||
val sysName = "121000005l35120456.node1"
|
||||
val s2 = scala.io.Source.fromFile("src/main/scala/rep/sc/tpl/ContractAssetsTPL.scala","UTF-8")
|
||||
val s2 = scala.io.Source.fromFile("src/main/scala/rep/sc/tpl/ContractAssetsTPL.scala", "UTF-8")
|
||||
val l2 = try s2.mkString finally s2.close()
|
||||
val cid2 = new ChaincodeId("ContractAssetsTPL", 1)
|
||||
val dep_asserts_trans = PeerHelper.createTransaction4Deploy(sysName, cid2, l2, "", 5000, rep.protos.peer.ChaincodeDeploy.CodeType.CODE_SCALA)
|
||||
@ -88,12 +87,12 @@ object GenesisBuilderMulti {
|
||||
transList.add(dep_set_trans)
|
||||
|
||||
// 可选的业务合约,如果没有,这里需要注释
|
||||
// val s4 = scala.io.Source.fromFile("src/main/scala/rep/sc/tpl/CustomTPL.scala","UTF-8")
|
||||
// val l4 = try s4.mkString finally s4.close()
|
||||
// val cid4 = new ChaincodeId("CustomTPL", 1)
|
||||
// val dep_process_proof = PeerHelper.createTransaction4Deploy(sysName, cid4, l4, "", 5000, rep.protos.peer.ChaincodeDeploy.CodeType.CODE_SCALA)
|
||||
// // 如果没有上述的业务合约,这里需要注释
|
||||
// transList.add(dep_process_proof)
|
||||
// val s4 = scala.io.Source.fromFile("src/main/scala/rep/sc/tpl/CustomTPL.scala","UTF-8")
|
||||
// val l4 = try s4.mkString finally s4.close()
|
||||
// val cid4 = new ChaincodeId("CustomTPL", 1)
|
||||
// val dep_process_proof = PeerHelper.createTransaction4Deploy(sysName, cid4, l4, "", 5000, rep.protos.peer.ChaincodeDeploy.CodeType.CODE_SCALA)
|
||||
// // 如果没有上述的业务合约,这里需要注释
|
||||
// transList.add(dep_process_proof)
|
||||
|
||||
var blk = new Block(1, 1, transList.toArray(new Array[Transaction](transList.size())), Seq(), _root_.com.google.protobuf.ByteString.EMPTY,
|
||||
_root_.com.google.protobuf.ByteString.EMPTY)
|
||||
@ -104,7 +103,7 @@ object GenesisBuilderMulti {
|
||||
val rStr = pretty(render(r))
|
||||
println(rStr)
|
||||
|
||||
val pw = new PrintWriter("json/genesis.json","UTF-8")
|
||||
val pw = new PrintWriter("json/genesis.json", "UTF-8")
|
||||
pw.write(rStr)
|
||||
pw.flush()
|
||||
pw.close()
|
||||
@ -135,14 +134,14 @@ object GenesisBuilderMulti {
|
||||
signers
|
||||
}
|
||||
|
||||
def fillCerts(signers: Array[Signer]): Array[CertInfo] = {
|
||||
val certInfos: Array[CertInfo] = new Array[CertInfo](signers.length)
|
||||
def fillCerts(signers: Array[Signer]): Array[Certificate] = {
|
||||
val certInfos: Array[Certificate] = new Array[Certificate](signers.length)
|
||||
for (i <- 0 until certInfos.length) {
|
||||
val certfile = scala.io.Source.fromFile("jks/" + signers(i).creditCode + "." + signers(i).name + ".cer", "UTF-8")
|
||||
val certstr = try certfile.mkString finally certfile.close()
|
||||
val millis = System.currentTimeMillis()
|
||||
val cert = rep.protos.peer.Certificate(certstr, "SHA1withECDSA", true, Option(Timestamp(millis / 1000, ((millis % 1000) * 1000000).toInt)))
|
||||
certInfos(i) = CertInfo(signers(i).creditCode, signers(i).name, cert)
|
||||
val cert = Certificate(certstr, "SHA1withECDSA", true, Option(Timestamp(millis / 1000, ((millis % 1000) * 1000000).toInt)), id = Option(CertId(signers(i).creditCode, signers(i).name)))
|
||||
certInfos(i) = cert
|
||||
}
|
||||
certInfos
|
||||
}
|
||||
|
@ -26,8 +26,7 @@ import org.json4s.jackson.JsonMethods.{pretty, render}
|
||||
import org.json4s.{DefaultFormats, jackson}
|
||||
import rep.crypto.cert.SignTool
|
||||
import rep.network.autotransaction.PeerHelper
|
||||
import rep.protos.peer.{Block, ChaincodeId, Signer, Transaction}
|
||||
import rep.sc.tpl.CertInfo
|
||||
import rep.protos.peer._
|
||||
import scalapb.json4s.JsonFormat
|
||||
|
||||
import scala.collection.mutable
|
||||
@ -92,7 +91,7 @@ object GenesisBuilderTool {
|
||||
}
|
||||
// 注册节点与管理员的证书
|
||||
for (i <- certs.indices) {
|
||||
transList.add(PeerHelper.createTransaction4Invoke(adminJksName.substring(0, adminJksName.length - 4), cid1, "SignUpCert", Seq(SerializeUtils.compactJson(certs(i)))))
|
||||
transList.add(PeerHelper.createTransaction4Invoke(adminJksName.substring(0, adminJksName.length - 4), cid1, "SignUpCert", Seq(JsonFormat.toJsonString(certs(i)))))
|
||||
}
|
||||
|
||||
// 可选的部署业务合约
|
||||
@ -163,8 +162,8 @@ object GenesisBuilderTool {
|
||||
signers
|
||||
}
|
||||
|
||||
def fillCerts(signers: Array[Signer]): Array[CertInfo] = {
|
||||
val certInfos: Array[CertInfo] = new Array[CertInfo](signers.length)
|
||||
def fillCerts(signers: Array[Signer]): Array[Certificate] = {
|
||||
val certInfos: Array[Certificate] = new Array[Certificate](signers.length)
|
||||
// 过滤掉非节点node的cer
|
||||
val files = certsFile.listFiles((pathname: File) => {
|
||||
def foo(pathname: File) = {
|
||||
@ -178,8 +177,8 @@ object GenesisBuilderTool {
|
||||
val certfile = scala.io.Source.fromFile(Path.of(certsFile.getPath, signers(i).creditCode + "." + signers(i).name + ".cer").toFile, "UTF-8")
|
||||
val certstr = try certfile.mkString finally certfile.close()
|
||||
val millis = System.currentTimeMillis()
|
||||
val cert = rep.protos.peer.Certificate(certstr, "SHA1withECDSA", true, Option(Timestamp(millis / 1000, ((millis % 1000) * 1000000).toInt)))
|
||||
certInfos(i) = CertInfo(signers(i).creditCode, signers(i).name, cert)
|
||||
val cert = Certificate(certstr, "SHA1withECDSA", true, Option(Timestamp(millis / 1000, ((millis % 1000) * 1000000).toInt)), id = Option(CertId(signers(i).creditCode, signers(i).name)))
|
||||
certInfos(i) = cert
|
||||
}
|
||||
certInfos
|
||||
}
|
||||
|
@ -18,6 +18,7 @@ package rep.sc
|
||||
|
||||
import akka.actor.{ActorRef, ActorSystem}
|
||||
import akka.testkit.{TestKit, TestProbe}
|
||||
import com.typesafe.config.ConfigFactory
|
||||
import org.json4s.jackson.Serialization
|
||||
import org.json4s.native.Serialization.{write, writePretty}
|
||||
import org.json4s.{DefaultFormats, jackson}
|
||||
@ -25,12 +26,15 @@ import org.scalatest._
|
||||
import rep.app.conf.SystemProfile
|
||||
import rep.app.system.ClusterSystem
|
||||
import rep.app.system.ClusterSystem.InitType
|
||||
import rep.crypto.Sha256
|
||||
import rep.crypto.cert.SignTool
|
||||
import rep.network.autotransaction.PeerHelper
|
||||
import rep.network.module.cfrd.ModuleManagerOfCFRD
|
||||
import rep.protos.peer.{Certificate, ChaincodeId, Signer, Transaction}
|
||||
import rep.protos.peer._
|
||||
import rep.sc.TransferSpec.ACTION
|
||||
import rep.sc.tpl._
|
||||
import rep.sc.tpl.ContractCert
|
||||
import scalapb.json4s.JsonFormat
|
||||
//.{CertStatus,CertInfo}
|
||||
|
||||
import scala.collection.mutable
|
||||
@ -51,15 +55,31 @@ class ContractCertSpec(_system: ActorSystem) extends TestKit(_system) with Match
|
||||
shutdown(system)
|
||||
}
|
||||
|
||||
implicit val serialization: Serialization.type = jackson.Serialization
|
||||
object ACTION {
|
||||
val transfer = "transfer"
|
||||
val set = "set"
|
||||
val SignUpSigner = "SignUpSigner"
|
||||
val SignUpCert = "SignUpCert"
|
||||
val UpdateCertStatus = "UpdateCertStatus"
|
||||
val UpdateSigner = "UpdateSigner"
|
||||
}
|
||||
|
||||
// or native.Serialization
|
||||
implicit val serialization: Serialization.type = jackson.Serialization
|
||||
implicit val formats: DefaultFormats.type = DefaultFormats
|
||||
|
||||
val sysName = "121000005l35120456.node1"
|
||||
val dbTag = "121000005l35120456.node1"
|
||||
val cid = ChaincodeId(SystemProfile.getAccountChaincodeName, 1)
|
||||
//建立PeerManager实例是为了调用transactionCreator(需要用到密钥签名),无他
|
||||
val pm: ActorRef = system.actorOf(ModuleManagerOfCFRD.props("modulemanager", sysName, false, false, false), "modulemanager")
|
||||
val superAdmin = "951002007l78123233.super_admin"
|
||||
// 初始化配置项,主要是为了初始化存储路径
|
||||
SystemProfile.initConfigSystem(ConfigFactory.parseString("system.account.chaincodename = ContractCert").withFallback(system.settings.config), sysName)
|
||||
// 加载node1的私钥
|
||||
SignTool.loadPrivateKey(sysName, "123", "jks/" + sysName + ".jks")
|
||||
// 加载super_admin的私钥
|
||||
SignTool.loadPrivateKey(superAdmin, "super_admin", "jks/" + superAdmin + ".jks")
|
||||
// 加载信任列表
|
||||
SignTool.loadNodeCertList("changeme", "jks/mytruststore.jks")
|
||||
|
||||
val cid = ChaincodeId("ContractCert", 1)
|
||||
|
||||
val signers: Array[Signer] = Array(
|
||||
Signer("node1", "121000005l35120456", "18912345678", List("node1")),
|
||||
@ -93,63 +113,62 @@ class ContractCertSpec(_system: ActorSystem) extends TestKit(_system) with Match
|
||||
// 部署账户管理合约
|
||||
val contractCert = scala.io.Source.fromFile("src/main/scala/rep/sc/tpl/ContractCert.scala")
|
||||
val contractCertStr = try contractCert.mkString finally contractCert.close()
|
||||
val t = PeerHelper.createTransaction4Deploy(sysName, cid,
|
||||
contractCertStr, "", 5000, rep.protos.peer.ChaincodeDeploy.CodeType.CODE_SCALA)
|
||||
val t = PeerHelper.createTransaction4Deploy(sysName, cid, contractCertStr, "", 5000, rep.protos.peer.ChaincodeDeploy.CodeType.CODE_SCALA)
|
||||
val msg_send = DoTransaction(Seq[Transaction](t), "dbnumber", TypeOfSender.FromAPI)
|
||||
probe.send(sandbox, msg_send)
|
||||
val msg_recv = probe.expectMsgType[Seq[Sandbox.DoTransactionResult]](1000.seconds)
|
||||
assert(msg_recv(0).err.isEmpty)
|
||||
val msg_recv = probe.expectMsgType[Seq[TransactionResult]](1000.seconds)
|
||||
assert(msg_recv(0).getResult.reason.isEmpty)
|
||||
}
|
||||
|
||||
// 注册node1 账户
|
||||
test("ContractCert should can signUp the signerNode1") {
|
||||
val signerNode1 = signers(0)
|
||||
// 注册账户
|
||||
val t = PeerHelper.createTransaction4Invoke(sysName, cid, ACTION.SignUpSigner, Seq(write(signerNode1)))
|
||||
val t = PeerHelper.createTransaction4Invoke(sysName, cid, ACTION.SignUpSigner, Seq(JsonFormat.toJsonString(signerNode1)))
|
||||
val msg_send = DoTransaction(Seq[Transaction](t), "dbnumber", TypeOfSender.FromAPI)
|
||||
probe.send(sandbox, msg_send)
|
||||
val msg_recv = probe.expectMsgType[Seq[Sandbox.DoTransactionResult]](1000.seconds)
|
||||
msg_recv(0).err.isEmpty should be(true)
|
||||
}
|
||||
//val aa = new ContractCert
|
||||
// 注册node1 证书
|
||||
test("ContractCert should can signUp the node1.cer") {
|
||||
val certInfo = CertInfo("121000005l35120456", "node1", Certificate(certs.getOrElse("node1", "default"), "SHA256withECDSA", certValid = true, None, None))
|
||||
val t = PeerHelper.createTransaction4Invoke(sysName, cid, ACTION.SignUpCert, Seq(writePretty(certInfo)))
|
||||
val msg_send = DoTransaction(Seq[Transaction](t), "dbnumber", TypeOfSender.FromAPI)
|
||||
probe.send(sandbox, msg_send)
|
||||
val msg_recv = probe.expectMsgType[Seq[Sandbox.DoTransactionResult]](1000.seconds)
|
||||
msg_recv(0).err should be(None)
|
||||
val msg_recv = probe.expectMsgType[Seq[TransactionResult]](1000.seconds)
|
||||
msg_recv(0).getResult.reason.isEmpty should be(true)
|
||||
}
|
||||
|
||||
// 重复注册一个证书会提示错误
|
||||
test("ContractCert should can't signUp the same Certificate") {
|
||||
val certInfo = CertInfo("121000005l35120456", "node1", Certificate(certs.getOrElse("node1", "default"), "SHA256withECDSA", certValid = true, None, None))
|
||||
val t = PeerHelper.createTransaction4Invoke(sysName, cid, ACTION.SignUpCert, Seq(writePretty(certInfo)))
|
||||
// 注册node1 证书
|
||||
test("ContractCert should can signUp the node1.cer") {
|
||||
val certInfo = Certificate(certs.getOrElse("node1", "default"), "SHA256withECDSA", certValid = true, None, None, id = Option(CertId("121000005l35120456", "node1")))
|
||||
val t = PeerHelper.createTransaction4Invoke(sysName, cid, ACTION.SignUpCert, Seq(JsonFormat.toJsonString(certInfo)))
|
||||
val msg_send = DoTransaction(Seq[Transaction](t), "dbnumber", TypeOfSender.FromAPI)
|
||||
probe.send(sandbox, msg_send)
|
||||
val msg_recv = probe.expectMsgType[Seq[Sandbox.DoTransactionResult]](1000.seconds)
|
||||
msg_recv(0).err.get.cause.getMessage should be(new ContractCert().certExists)
|
||||
val msg_recv = probe.expectMsgType[Seq[TransactionResult]](1000.seconds)
|
||||
msg_recv(0).getResult.reason.isEmpty should be(true)
|
||||
}
|
||||
|
||||
//重复注册一个证书会提示错误
|
||||
test("ContractCert should can't signUp the same Certificate") {
|
||||
val certInfo = Certificate(certs.getOrElse("node1", "default"), "SHA256withECDSA", certValid = true, None, None, id = Option(CertId("121000005l35120456", "node1")))
|
||||
val t = PeerHelper.createTransaction4Invoke(sysName, cid, ACTION.SignUpCert, Seq(JsonFormat.toJsonString(certInfo)))
|
||||
val msg_send = DoTransaction(Seq[Transaction](t), "dbnumber", TypeOfSender.FromAPI)
|
||||
probe.send(sandbox, msg_send)
|
||||
val msg_recv = probe.expectMsgType[Seq[TransactionResult]](1000.seconds)
|
||||
msg_recv(0).getResult.reason should be(new ContractCert().certExists)
|
||||
}
|
||||
|
||||
// 不能将证书注册到一个不存在的账户
|
||||
test("ContractCert should can't signUp the node1.cer to signerNode2 which not exists") {
|
||||
val certInfo = CertInfo("12110107bi45jh675g", "node2", Certificate(certs.getOrElse("node1", "default"), "SHA256withECDSA", certValid = true, None, None))
|
||||
val t = PeerHelper.createTransaction4Invoke(sysName, cid, ACTION.SignUpCert, Seq(writePretty(certInfo)))
|
||||
val certInfo = Certificate(certs.getOrElse("node1", "default"), "SHA256withECDSA", certValid = true, None, None, id = Option(CertId("12110107bi45jh675g", "node2")))
|
||||
val t = PeerHelper.createTransaction4Invoke(sysName, cid, ACTION.SignUpCert, Seq(JsonFormat.toJsonString(certInfo)))
|
||||
val msg_send = DoTransaction(Seq[Transaction](t), "dbnumber", TypeOfSender.FromAPI)
|
||||
probe.send(sandbox, msg_send)
|
||||
val msg_recv = probe.expectMsgType[Seq[Sandbox.DoTransactionResult]](1000.seconds)
|
||||
msg_recv(0).err.get.cause.getMessage should be(new ContractCert().signerNotExists)
|
||||
val msg_recv = probe.expectMsgType[Seq[TransactionResult]](1000.seconds)
|
||||
msg_recv(0).getResult.reason should be(new ContractCert().signerNotExists)
|
||||
}
|
||||
|
||||
// 将证书2追加到 node1的账户中,使用node2作为certName
|
||||
test("ContractCert can signUp the node2.cer to signerNode1") {
|
||||
val certInfo = CertInfo("121000005l35120456", "node2", Certificate(certs.getOrElse("node2", "default"), "SHA256withECDSA", certValid = true, None, None))
|
||||
val t = PeerHelper.createTransaction4Invoke(sysName, cid, ACTION.SignUpCert, Seq(writePretty(certInfo)))
|
||||
val certInfo = Certificate(certs.getOrElse("node2", "default"), "SHA256withECDSA", certValid = true, None, None, id = Option(CertId("121000005l35120456", "node2")))
|
||||
val t = PeerHelper.createTransaction4Invoke(sysName, cid, ACTION.SignUpCert, Seq(JsonFormat.toJsonString(certInfo)))
|
||||
val msg_send = DoTransaction(Seq[Transaction](t), "dbnumber", TypeOfSender.FromAPI)
|
||||
probe.send(sandbox, msg_send)
|
||||
val msg_recv = probe.expectMsgType[Seq[Sandbox.DoTransactionResult]](1000.seconds)
|
||||
msg_recv(0).err.isEmpty should be(true)
|
||||
val msg_recv = probe.expectMsgType[Seq[TransactionResult]](1000.seconds)
|
||||
msg_recv(0).getResult.reason.isEmpty should be(true)
|
||||
}
|
||||
|
||||
// 更新证书状态,将刚刚追加的node2的证书状态修改为false
|
||||
@ -158,8 +177,8 @@ class ContractCertSpec(_system: ActorSystem) extends TestKit(_system) with Match
|
||||
val t = PeerHelper.createTransaction4Invoke(sysName, cid, ACTION.UpdateCertStatus, Seq(writePretty(certStatus)))
|
||||
val msg_send = DoTransaction(Seq[Transaction](t), "dbnumber", TypeOfSender.FromAPI)
|
||||
probe.send(sandbox, msg_send)
|
||||
val msg_recv = probe.expectMsgType[Seq[Sandbox.DoTransactionResult]](1000.seconds)
|
||||
msg_recv(0).err.isEmpty should be(true)
|
||||
val msg_recv = probe.expectMsgType[Seq[TransactionResult]](1000.seconds)
|
||||
msg_recv(0).getResult.reason.isEmpty should be(true)
|
||||
}
|
||||
|
||||
// 更新证书状态,对应的证书不存在
|
||||
@ -168,18 +187,18 @@ class ContractCertSpec(_system: ActorSystem) extends TestKit(_system) with Match
|
||||
val t = PeerHelper.createTransaction4Invoke(sysName, cid, ACTION.UpdateCertStatus, Seq(writePretty(certStatus)))
|
||||
val msg_send = DoTransaction(Seq[Transaction](t), "dbnumber", TypeOfSender.FromAPI)
|
||||
probe.send(sandbox, msg_send)
|
||||
val msg_recv = probe.expectMsgType[Seq[Sandbox.DoTransactionResult]](1000.seconds)
|
||||
msg_recv(0).err.get.cause.getMessage should be(new ContractCert().certNotExists)
|
||||
val msg_recv = probe.expectMsgType[Seq[TransactionResult]](1000.seconds)
|
||||
msg_recv(0).getResult.reason should be(new ContractCert().certNotExists)
|
||||
}
|
||||
|
||||
// 更新账户信息,将账户node1中的name改为node2,并且修改手机号
|
||||
test("modify the signer's information") {
|
||||
val signerNode1 = Signer("node2", "121000005l35120456", "13112345678", List("node1"))
|
||||
// 修改账户
|
||||
val t = PeerHelper.createTransaction4Invoke(sysName, cid, ACTION.UpdateSigner, Seq(write(signerNode1)))
|
||||
val t = PeerHelper.createTransaction4Invoke(sysName, cid, ACTION.UpdateSigner, Seq(JsonFormat.toJsonString(signerNode1)))
|
||||
val msg_send = DoTransaction(Seq[Transaction](t), "dbnumber", TypeOfSender.FromAPI)
|
||||
probe.send(sandbox, msg_send)
|
||||
val msg_recv = probe.expectMsgType[Seq[Sandbox.DoTransactionResult]](1000.seconds)
|
||||
msg_recv(0).err.isEmpty should be(true)
|
||||
val msg_recv = probe.expectMsgType[Seq[TransactionResult]](1000.seconds)
|
||||
msg_recv(0).getResult.reason.isEmpty should be(true)
|
||||
}
|
||||
}
|
||||
|
@ -2,25 +2,28 @@ package rep.sc
|
||||
|
||||
import akka.actor.{ActorRef, ActorSystem}
|
||||
import akka.testkit.{TestKit, TestProbe}
|
||||
import com.typesafe.config.ConfigFactory
|
||||
import org.json4s.{DefaultFormats, jackson}
|
||||
import org.json4s.native.Serialization.{write, writePretty}
|
||||
import org.scalatest.{BeforeAndAfterAll, FlatSpecLike, Matchers}
|
||||
import rep.app.system.ClusterSystem
|
||||
import rep.app.system.ClusterSystem.InitType
|
||||
import rep.network.module.cfrd.ModuleManagerOfCFRD
|
||||
import rep.protos.peer.{Certificate, ChaincodeId, Signer}
|
||||
import rep.sc.TransferSpec.{ACTION, SetMap}
|
||||
import rep.protos.peer._
|
||||
import rep.sc.TransferSpec.SetMap
|
||||
import rep.storage.ImpDataAccess
|
||||
import rep.utils.SerializeUtils.toJson
|
||||
import rep.app.conf.SystemProfile
|
||||
import rep.network.autotransaction.PeerHelper
|
||||
import rep.network.tools.PeerExtension
|
||||
|
||||
import scala.concurrent.duration._
|
||||
import scala.collection.mutable.Map
|
||||
import rep.sc.SandboxDispatcher.DoTransaction
|
||||
import rep.protos.peer.Transaction
|
||||
import rep.sc.BlockStubActor.WriteBlockStub
|
||||
import rep.sc.ContractTest.ACTION
|
||||
import rep.sc.tpl._
|
||||
import scalapb.json4s.JsonFormat
|
||||
//.{CertStatus,CertInfo}
|
||||
//import rep.utils.CaseClassToString
|
||||
|
||||
@ -39,8 +42,7 @@ object ContractTest {
|
||||
|
||||
}
|
||||
|
||||
class ContractTest(_system: ActorSystem)
|
||||
extends TestKit(_system) with Matchers with FlatSpecLike with BeforeAndAfterAll {
|
||||
class ContractTest(_system: ActorSystem) extends TestKit(_system) with Matchers with FlatSpecLike with BeforeAndAfterAll {
|
||||
|
||||
def this() = this(ActorSystem("TransferSpec", new ClusterSystem("121000005l35120456.node1", InitType.MULTI_INIT, false).getConf))
|
||||
|
||||
@ -88,10 +90,10 @@ class ContractTest(_system: ActorSystem)
|
||||
}
|
||||
|
||||
// 构建Deploy交易,用来部署合约parallelPutProofTPL
|
||||
private def get_parallelPutProofTPL_Deploy_Trans(sysName: String, version: Int): Transaction = {
|
||||
val s3 = scala.io.Source.fromFile("src/main/scala/rep/sc/tpl/parallelPutProofTPL.scala")
|
||||
private def get_ParallelPutProofTPL_Deploy_Trans(sysName: String, version: Int): Transaction = {
|
||||
val s3 = scala.io.Source.fromFile("src/main/scala/rep/sc/tpl/ParallelPutProofTPL.scala")
|
||||
val l3 = try s3.mkString finally s3.close()
|
||||
val cid3 = ChaincodeId("parallelPutProofTPL", version)
|
||||
val cid3 = ChaincodeId("ParallelPutProofTPL", version)
|
||||
val t3 = PeerHelper.createTransaction4Deploy(sysName, cid3,
|
||||
l3, "", 5000, rep.protos.peer.ChaincodeDeploy.CodeType.CODE_SCALA_PARALLEL)
|
||||
t3
|
||||
@ -99,7 +101,7 @@ class ContractTest(_system: ActorSystem)
|
||||
|
||||
// 构建Invoke交易,用来调用合约parallelPutProofTPL
|
||||
private def createParallelTransInvoke(sysName: String, version: Int, action: String, param: String): Transaction = {
|
||||
val cid2 = ChaincodeId("parallelPutProofTPL", version)
|
||||
val cid2 = ChaincodeId("ParallelPutProofTPL", version)
|
||||
PeerHelper.createTransaction4Invoke(sysName, cid2, action, Seq(param))
|
||||
}
|
||||
|
||||
@ -107,12 +109,12 @@ class ContractTest(_system: ActorSystem)
|
||||
private def ExecuteTrans(probe: TestProbe, sandbox: ActorRef, t: Transaction, snapshotName: String, sendertype: TypeOfSender.Value, serial: Int, eresult: Boolean) = {
|
||||
val msg_send1 = DoTransaction(Seq[Transaction](t), snapshotName, sendertype)
|
||||
probe.send(sandbox, msg_send1)
|
||||
val msg_recv1 = probe.expectMsgType[Seq[Sandbox.DoTransactionResult]](1000.seconds)
|
||||
if (msg_recv1(0).err.isEmpty) {
|
||||
val msg_recv1 = probe.expectMsgType[Seq[TransactionResult]](1000.seconds)
|
||||
if (msg_recv1(0).getResult.reason.isEmpty) {
|
||||
println(s"serial:${serial},expect result:${eresult},exeresult:true")
|
||||
msg_recv1(0).err.isEmpty should be(true)
|
||||
msg_recv1(0).getResult.reason.isEmpty should be(true)
|
||||
} else {
|
||||
println(msg_recv1(0).err.get.toString())
|
||||
println(msg_recv1(0).getResult.reason)
|
||||
println(s"serial:${serial},expect result:${eresult},exeresult:false")
|
||||
}
|
||||
}
|
||||
@ -121,9 +123,11 @@ class ContractTest(_system: ActorSystem)
|
||||
"ContractAssetsTPL" should "can set assets and transfer from a to b" in {
|
||||
|
||||
val sysName = "121000005l35120456.node1"
|
||||
val dbTag = "121000005l35120456.node1"
|
||||
// 初始化配置项,主要是为了初始化存储路径
|
||||
SystemProfile.initConfigSystem(ConfigFactory.parseString("system.account.chaincodename = ContractCert").withFallback(system.settings.config), sysName)
|
||||
PeerExtension(system).setSysTag(sysName)
|
||||
//建立PeerManager实例是为了调用transactionCreator(需要用到密钥签名),无他
|
||||
val pm = system.actorOf(ModuleManagerOfCFRD.props("modulemanager", sysName, false, false, false), "modulemanager")
|
||||
val pm = system.actorOf(ModuleManagerOfCFRD.props("modulemanager", sysName, false, false, true), "modulemanager")
|
||||
|
||||
val sm: SetMap = Map("121000005l35120456" -> 50, "12110107bi45jh675g" -> 50, "122000002n00123567" -> 50)
|
||||
val sms = write(sm)
|
||||
@ -145,7 +149,7 @@ class ContractTest(_system: ActorSystem)
|
||||
aa.AddElement("name", "node2")
|
||||
aa.AddElement("cert", Certificate(certStr, "SHA1withECDSA", true, None, None))*/
|
||||
|
||||
val certinfo = CertInfo("12110107bi45jh675g", "node2", Certificate(certStr, "SHA1withECDSA", true, None, None))
|
||||
val certinfo = Certificate(certStr, "SHA1withECDSA", true, None, None, id = Option(CertId("12110107bi45jh675g", "node2")))
|
||||
|
||||
val certstatus = CertStatus("12110107bi45jh675g", "node2", false)
|
||||
//val certinfo = aa.toJsonString
|
||||
@ -157,42 +161,42 @@ class ContractTest(_system: ActorSystem)
|
||||
|
||||
//内存中没有合约,建立合约,此时合约在快照中
|
||||
val t1 = this.get_ContractCert_Deploy_Trans(sysName, 1)
|
||||
ExecuteTrans(probe, sandbox, t1, "dbnumber1", TypeOfSender.FromAPI, 1, true)
|
||||
ExecuteTrans(probe, sandbox, t1, "dbnumber1", TypeOfSender.FromPreloader, 1, true)
|
||||
|
||||
//内存中有合约,可以调用
|
||||
val t2 = this.createCertTransInvoke(sysName, 1, ACTION.SignUpSigner, write(signer))
|
||||
ExecuteTrans(probe, sandbox, t2, "dbnumber1", TypeOfSender.FromAPI, 2, true)
|
||||
val t2 = this.createCertTransInvoke(sysName, 1, ACTION.SignUpSigner, JsonFormat.toJsonString(signer))
|
||||
ExecuteTrans(probe, sandbox, t2, "dbnumber1", TypeOfSender.FromPreloader, 2, true)
|
||||
|
||||
//这个应该错误,应该是找不到合约
|
||||
val t3 = this.createCertTransInvoke(sysName, 1, ACTION.SignUpSigner, write(signer))
|
||||
ExecuteTrans(probe, sandbox, t3, "dbnumber2", TypeOfSender.FromAPI, 3, false)
|
||||
val t3 = this.createCertTransInvoke(sysName, 1, ACTION.SignUpSigner, JsonFormat.toJsonString(signer))
|
||||
ExecuteTrans(probe, sandbox, t3, "dbnumber2", TypeOfSender.FromPreloader, 3, false)
|
||||
|
||||
//修改合约状态
|
||||
val t4 = PeerHelper.createTransaction4State(sysName, ChaincodeId(SystemProfile.getAccountChaincodeName, 1), false)
|
||||
ExecuteTrans(probe, sandbox, t4, "dbnumber1", TypeOfSender.FromAPI, 4, true)
|
||||
ExecuteTrans(probe, sandbox, t4, "dbnumber1", TypeOfSender.FromPreloader, 4, true)
|
||||
|
||||
//val t5 = this.createCertTransInvoke(sysName,1, ACTION.SignUpCert, writePretty(certinfo))
|
||||
// t4未持久化,可以继续invoke该合约
|
||||
val t5 = this.createCertTransInvoke(sysName, 1, ACTION.SignUpCert, writePretty(certinfo))
|
||||
ExecuteTrans(probe, sandbox, t5, "dbnumber1", TypeOfSender.FromAPI, 5, true)
|
||||
val t5 = this.createCertTransInvoke(sysName, 1, ACTION.SignUpCert, JsonFormat.toJsonString(certinfo))
|
||||
ExecuteTrans(probe, sandbox, t5, "dbnumber1", TypeOfSender.FromPreloader, 5, true)
|
||||
|
||||
val t51 = this.createCertTransInvoke(sysName, 1, ACTION.UpdateCertStatus, writePretty(certstatus))
|
||||
ExecuteTrans(probe, sandbox, t51, "dbnumber1", TypeOfSender.FromAPI, 51, true)
|
||||
ExecuteTrans(probe, sandbox, t51, "dbnumber1", TypeOfSender.FromPreloader, 51, true)
|
||||
|
||||
//同一快照中,再次部署同一版本合约(ContractCert),会失败,对比 t1
|
||||
val t6 = this.get_ContractCert_Deploy_Trans(sysName, 1)
|
||||
ExecuteTrans(probe, sandbox, t6, "dbnumber1", TypeOfSender.FromAPI, 6, false)
|
||||
ExecuteTrans(probe, sandbox, t6, "dbnumber1", TypeOfSender.FromPreloader, 6, false)
|
||||
|
||||
//不同快照中,再次部署同一版本合约(ContractCert),会成功
|
||||
val t7 = this.get_ContractCert_Deploy_Trans(sysName, 1)
|
||||
ExecuteTrans(probe, sandbox, t7, "dbnumber2", TypeOfSender.FromAPI, 7, true)
|
||||
ExecuteTrans(probe, sandbox, t7, "dbnumber2", TypeOfSender.FromPreloader, 7, true)
|
||||
|
||||
// 通一快照中,部署升级版本的合约(ContractCertV2),会成功
|
||||
val t8 = this.get_ContractCert_Deploy_Trans(sysName, 2)
|
||||
ExecuteTrans(probe, sandbox, t8, "dbnumber1", TypeOfSender.FromAPI, 8, true)
|
||||
ExecuteTrans(probe, sandbox, t8, "dbnumber1", TypeOfSender.FromPreloader, 8, true)
|
||||
|
||||
val t81 = this.get_parallelPutProofTPL_Deploy_Trans(sysName, 1)
|
||||
ExecuteTrans(probe, sandbox, t81, "dbnumber1", TypeOfSender.FromAPI, 81, true)
|
||||
val t81 = this.get_ParallelPutProofTPL_Deploy_Trans(sysName, 1)
|
||||
ExecuteTrans(probe, sandbox, t81, "dbnumber1", TypeOfSender.FromPreloader, 81, true)
|
||||
|
||||
//持久化这些交易
|
||||
val tsls = Array(t1, t2, t3, t4, t5,t51, t81)
|
||||
@ -204,7 +208,7 @@ class ContractTest(_system: ActorSystem)
|
||||
|
||||
//已经持久化合约,应该要失败
|
||||
val t9 = this.get_ContractCert_Deploy_Trans(sysName, 1)
|
||||
ExecuteTrans(probe, sandbox: ActorRef, t9, "dbnumber1", TypeOfSender.FromAPI, 9, false)
|
||||
ExecuteTrans(probe, sandbox: ActorRef, t9, "dbnumber1", TypeOfSender.FromPreloader, 9, false)
|
||||
|
||||
val signer3 = Signer("node3", "122000002n00123567", "13856789274", Seq("node3"))
|
||||
val cert3 = scala.io.Source.fromFile("jks/certs/122000002n00123567.node3.cer")
|
||||
@ -215,20 +219,20 @@ class ContractTest(_system: ActorSystem)
|
||||
aa1.AddElement("name", "node3")
|
||||
aa1.AddElement("cert", Certificate(certStr3, "SHA1withECDSA", true, None, None))*/
|
||||
|
||||
val certinfo3 = CertInfo("122000002n00123567", "node3", Certificate(certStr3, "SHA1withECDSA", true, None, None))
|
||||
val certinfo3 = Certificate(certStr3, "SHA1withECDSA", true, None, None, id = Option(CertId("122000002n00123567", "node3")))
|
||||
//val certinfo3 = aa1.toJsonString
|
||||
|
||||
//合约状态为disable,会失败
|
||||
val t10 = this.createCertTransInvoke(sysName, 1, ACTION.SignUpSigner, write(signer3))
|
||||
ExecuteTrans(probe, sandbox: ActorRef, t10, "dbnumber1", TypeOfSender.FromAPI, 10, false)
|
||||
val t10 = this.createCertTransInvoke(sysName, 1, ACTION.SignUpSigner, JsonFormat.toJsonString(signer3))
|
||||
ExecuteTrans(probe, sandbox: ActorRef, t10, "dbnumber1", TypeOfSender.FromPreloader, 10, false)
|
||||
|
||||
//合约状态为disable,会失败
|
||||
val t11 = this.createCertTransInvoke(sysName, 1, ACTION.SignUpCert, writePretty(certinfo))
|
||||
ExecuteTrans(probe, sandbox: ActorRef, t11, "dbnumber1", TypeOfSender.FromAPI, 11, false)
|
||||
val t11 = this.createCertTransInvoke(sysName, 1, ACTION.SignUpCert, JsonFormat.toJsonString(certinfo))
|
||||
ExecuteTrans(probe, sandbox: ActorRef, t11, "dbnumber1", TypeOfSender.FromPreloader, 11, false)
|
||||
|
||||
//重新设置合约状态为enable
|
||||
var t12 = PeerHelper.createTransaction4State(sysName, ChaincodeId(SystemProfile.getAccountChaincodeName, 1), true)
|
||||
ExecuteTrans(probe, sandbox: ActorRef, t12, "dbnumber1", TypeOfSender.FromAPI, 12, true)
|
||||
val t12 = PeerHelper.createTransaction4State(sysName, ChaincodeId(SystemProfile.getAccountChaincodeName, 1), true)
|
||||
ExecuteTrans(probe, sandbox: ActorRef, t12, "dbnumber1", TypeOfSender.FromPreloader, 12, true)
|
||||
|
||||
//持久化这些交易
|
||||
probe.send(blocker, WriteBlockStub(Array(t10, t11, t12).toSeq))
|
||||
@ -237,21 +241,21 @@ class ContractTest(_system: ActorSystem)
|
||||
println("store finish 2= " + msg_recv2.toString())
|
||||
|
||||
//合约状态持久化为enable,会成功
|
||||
val t13 = this.createCertTransInvoke(sysName, 1, ACTION.SignUpSigner, write(signer3))
|
||||
ExecuteTrans(probe, sandbox: ActorRef, t13, "dbnumber1", TypeOfSender.FromAPI, 13, true)
|
||||
val t13 = this.createCertTransInvoke(sysName, 1, ACTION.SignUpSigner, JsonFormat.toJsonString(signer3))
|
||||
ExecuteTrans(probe, sandbox: ActorRef, t13, "dbnumber1", TypeOfSender.FromPreloader, 13, true)
|
||||
|
||||
//证书已经存在,会失败
|
||||
val t14 = this.createCertTransInvoke(sysName, 1, ACTION.SignUpCert, writePretty(certinfo))
|
||||
ExecuteTrans(probe, sandbox: ActorRef, t14, "dbnumber1", TypeOfSender.FromAPI, 14, false)
|
||||
val t14 = this.createCertTransInvoke(sysName, 1, ACTION.SignUpCert, JsonFormat.toJsonString(certinfo))
|
||||
ExecuteTrans(probe, sandbox: ActorRef, t14, "dbnumber1", TypeOfSender.FromPreloader, 14, false)
|
||||
|
||||
var probes = new Array[TestProbe](10)
|
||||
var doparams = new Array[DoTransaction](10)
|
||||
|
||||
// 并行执行parallelPutProofTPL
|
||||
for (i <- 0 to 9) {
|
||||
val p = proofDataSingle("paeallel_key_" + i, "value_" + i)
|
||||
val p = ProofDataSingle("parallel_key_" + i, "value_" + i)
|
||||
val t = this.createParallelTransInvoke(sysName, 1, "putProofSingle", writePretty(p))
|
||||
doparams(i) = DoTransaction(Seq[Transaction](t), "dbnumber1", TypeOfSender.FromAPI)
|
||||
doparams(i) = DoTransaction(Seq[Transaction](t), "dbnumber1", TypeOfSender.FromPreloader)
|
||||
probes(i) = TestProbe()
|
||||
}
|
||||
|
||||
@ -260,19 +264,19 @@ class ContractTest(_system: ActorSystem)
|
||||
}
|
||||
|
||||
for (i <- 0 to 9) {
|
||||
val msg_recv1 = probes(i).expectMsgType[Sandbox.DoTransactionResult](1000.seconds)
|
||||
if (msg_recv1.err.isEmpty) {
|
||||
val msg_recv1 = probes(i).expectMsgType[Seq[TransactionResult]](1000.seconds)
|
||||
if (msg_recv1.head.getResult.reason.isEmpty) {
|
||||
println(s"serial:${15 + i},expect result:${true},exeresult:true")
|
||||
msg_recv1.err.isEmpty should be(true)
|
||||
msg_recv1.head.getResult.reason.isEmpty should be(true)
|
||||
} else {
|
||||
println(msg_recv1.err.get.toString())
|
||||
println(msg_recv1.head.getResult.reason)
|
||||
println(s"serial:${15 + i},expect result:${true},exeresult:false")
|
||||
}
|
||||
}
|
||||
|
||||
/*val p = proofDataSingle("paeallel_key_1","value_1")
|
||||
val t15 = this.createParallelTransInvoke(sysName,1, "createParallelTransInvoke", writePretty(p))
|
||||
ExecuteTrans(probe,sandbox:ActorRef,t15,"dbnumber1",TypeOfSender.FromAPI,15,true)*/
|
||||
ExecuteTrans(probe,sandbox:ActorRef,t15,"dbnumber1",TypeOfSender.FromPreloader,15,true)*/
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -18,17 +18,25 @@ package rep.sc
|
||||
|
||||
import akka.actor.ActorSystem
|
||||
import akka.testkit.{TestKit, TestProbe}
|
||||
import org.json4s.{DefaultFormats, jackson}
|
||||
import com.google.protobuf.timestamp.Timestamp
|
||||
import org.json4s.{DefaultFormats, jackson, native}
|
||||
import org.json4s.native.Serialization.{write, writePretty}
|
||||
import org.scalatest.{BeforeAndAfterAll, FlatSpecLike, Matchers}
|
||||
import rep.app.system.ClusterSystem
|
||||
import rep.app.system.ClusterSystem.InitType
|
||||
import rep.crypto.Sha256
|
||||
import rep.crypto.cert.SignTool
|
||||
import rep.network.autotransaction.PeerHelper
|
||||
import rep.network.module.cfrd.ModuleManagerOfCFRD
|
||||
import rep.protos.peer.{Certificate, ChaincodeId, Signer, Transaction}
|
||||
import rep.protos.peer.Authorize.TransferType
|
||||
import rep.protos.peer.Certificate.CertType
|
||||
import rep.protos.peer.ChaincodeDeploy.ContractClassification
|
||||
import rep.protos.peer.Operate.OperateType
|
||||
import rep.protos.peer._
|
||||
import rep.sc.TransferSpec.{ACTION, SetMap}
|
||||
import rep.sc.tpl._
|
||||
//.{CertStatus,CertInfo}
|
||||
|
||||
import scalapb.json4s.JsonFormat
|
||||
|
||||
import rep.sc.tpl.Transfer
|
||||
import rep.storage.ImpDataAccess
|
||||
import rep.utils.SerializeUtils.toJson
|
||||
@ -45,7 +53,7 @@ object TransferSpec {
|
||||
object ACTION {
|
||||
val transfer = "transfer"
|
||||
val set = "set"
|
||||
val SignUpSigner = "SignUpSigner"
|
||||
val SignUpSigner = "signUpSigner"
|
||||
val SignUpCert = "SignUpCert"
|
||||
val UpdateCertStatus = "UpdateCertStatus"
|
||||
val UpdateSigner = "UpdateSigner"
|
||||
@ -58,8 +66,7 @@ object TransferSpec {
|
||||
*
|
||||
* @param _system
|
||||
*/
|
||||
class TransferSpec(_system: ActorSystem)
|
||||
extends TestKit(_system) with Matchers with FlatSpecLike with BeforeAndAfterAll {
|
||||
class TransferSpec(_system: ActorSystem) extends TestKit(_system) with Matchers with FlatSpecLike with BeforeAndAfterAll {
|
||||
|
||||
def this() = this(ActorSystem("TransferSpec", new ClusterSystem("121000005l35120456.node1", InitType.MULTI_INIT, false).getConf))
|
||||
|
||||
@ -67,96 +74,146 @@ class TransferSpec(_system: ActorSystem)
|
||||
shutdown(system)
|
||||
}
|
||||
|
||||
implicit val serialization = jackson.Serialization
|
||||
// or native.Serialization
|
||||
implicit val serialization = jackson.Serialization
|
||||
implicit val formats = DefaultFormats
|
||||
|
||||
"ContractAssetsTPL" should "can set assets and transfer from a to b" in {
|
||||
"ContractAssetsTPL" can "manage user's assets" in {
|
||||
|
||||
val sysName = "121000005l35120456.node1"
|
||||
val dbTag = "121000005l35120456.node1"
|
||||
//建立PeerManager实例是为了调用transactionCreator(需要用到密钥签名),无他
|
||||
val pm = system.actorOf(ModuleManagerOfCFRD.props("modulemanager", sysName, false, false, false), "modulemanager")
|
||||
val superAdmin = "951002007l78123233.super_admin"
|
||||
// 初始化配置项,主要是为了初始化存储路径
|
||||
SystemProfile.initConfigSystem(system.settings.config, sysName)
|
||||
// 加载node1的私钥
|
||||
SignTool.loadPrivateKey(sysName, "123", "jks/" + sysName + ".jks")
|
||||
// 加载super_admin的私钥
|
||||
SignTool.loadPrivateKey(superAdmin, "super_admin", "jks/" + superAdmin + ".jks")
|
||||
|
||||
// 部署资产管理
|
||||
val cid1 = ChaincodeId("ContractAssetsTPL", 1)
|
||||
val s1 = scala.io.Source.fromFile("src/main/scala/rep/sc/tpl/ContractAssetsTPL.scala")
|
||||
val l1 = try s1.mkString finally s1.close()
|
||||
|
||||
// 账户管理合约
|
||||
val s2 = scala.io.Source.fromFile("src/main/scala/rep/sc/tpl/ContractCert.scala")
|
||||
val cid2 = ChaincodeId("RdidOperateAuthorizeTPL", 1)
|
||||
val s2 = scala.io.Source.fromFile("src/main/scala/rep/sc/tpl/did/RdidOperateAuthorizeTPL.scala")
|
||||
val l2 = try s2.mkString finally s2.close()
|
||||
|
||||
//准备探针以验证调用返回结果
|
||||
val probe = TestProbe()
|
||||
val sandbox = system.actorOf(TransactionDispatcher.props("transactiondispatcher"), "transactiondispatcher")
|
||||
|
||||
//生成deploy交易,部署ContractAssetsTPL
|
||||
val t1 = PeerHelper.createTransaction4Deploy(superAdmin, cid1, l1, "", 5000, rep.protos.peer.ChaincodeDeploy.CodeType.CODE_SCALA, ContractClassification.CONTRACT_CUSTOM)
|
||||
val msg_send1 = DoTransaction(Seq[Transaction](t1), "test-db", TypeOfSender.FromPreloader)
|
||||
probe.send(sandbox, msg_send1)
|
||||
val msg_recv1 = probe.expectMsgType[Seq[TransactionResult]](1000.seconds)
|
||||
msg_recv1(0).getResult.reason.isEmpty should be(true)
|
||||
|
||||
// 生成deploy交易,部署RdidOperateAuthorizeTPL
|
||||
val t2 = PeerHelper.createTransaction4Deploy(superAdmin, cid2, l2, "", 5000, rep.protos.peer.ChaincodeDeploy.CodeType.CODE_SCALA, ContractClassification.CONTRACT_SYSTEM)
|
||||
val msg_send2 = DoTransaction(Seq[Transaction](t2), "test-db", TypeOfSender.FromPreloader)
|
||||
probe.send(sandbox, msg_send2)
|
||||
val msg_recv2 = probe.expectMsgType[Seq[TransactionResult]](1000.seconds)
|
||||
msg_recv2(0).getResult.reason.isEmpty should be(true)
|
||||
|
||||
// 生成invoke交易
|
||||
// 注册账户
|
||||
val superCert = scala.io.Source.fromFile("jks/certs/951002007l78123233.super_admin.cer", "UTF-8")
|
||||
val superCertPem = try superCert.mkString finally superCert.close()
|
||||
val superCertHash = Sha256.hashstr(superCertPem)
|
||||
val superCertId = CertId("951002007l78123233", "super_admin")
|
||||
var millis = System.currentTimeMillis()
|
||||
//生成Did的身份证书
|
||||
val superAuthCert = rep.protos.peer.Certificate(superCertPem, "SHA1withECDSA", true, Option(Timestamp(millis / 1000, ((millis % 1000) * 1000000).toInt)), None, CertType.CERT_AUTHENTICATION, Option(superCertId), superCertHash, "1.0")
|
||||
// 账户
|
||||
val superSigner = Signer("super_admin", "951002007l78123233", "13856789234", Seq.empty, Seq.empty, Seq.empty, Seq.empty, List(superAuthCert), "", Option(Timestamp(millis / 1000, ((millis % 1000) * 1000000).toInt)), None, true, "1.0")
|
||||
val t3 = PeerHelper.createTransaction4Invoke(superAdmin, cid2, ACTION.SignUpSigner, Seq(JsonFormat.toJsonString(superSigner)))
|
||||
val msg_send3 = DoTransaction(Seq[Transaction](t3), "test-db", TypeOfSender.FromPreloader)
|
||||
probe.send(sandbox, msg_send3)
|
||||
val msg_recv3 = probe.expectMsgType[Seq[TransactionResult]](1000.seconds)
|
||||
msg_recv3(0).getResult.reason.isEmpty should be(true)
|
||||
|
||||
// 注册账户
|
||||
val node1CertFile = scala.io.Source.fromFile("jks/certs/121000005l35120456.node1.cer", "UTF-8")
|
||||
val node1CertPem = try node1CertFile.mkString finally node1CertFile.close()
|
||||
val node1CertHash = Sha256.hashstr(node1CertPem)
|
||||
val node1CertId = CertId("121000005l35120456", "node1")
|
||||
millis = System.currentTimeMillis()
|
||||
//生成Did的身份证书
|
||||
val node1AuthCert = rep.protos.peer.Certificate(node1CertPem, "SHA1withECDSA", true, Option(Timestamp(millis / 1000, ((millis % 1000) * 1000000).toInt)), None, CertType.CERT_AUTHENTICATION, Option(node1CertId), node1CertHash, "1.0")
|
||||
// 账户
|
||||
val node1Signer = Signer("node1", "121000005l35120456", "13856789234", Seq.empty, Seq.empty, Seq.empty, Seq.empty, List(node1AuthCert), "", Option(Timestamp(millis / 1000, ((millis % 1000) * 1000000).toInt)), None, true, "1.0")
|
||||
val t9 = PeerHelper.createTransaction4Invoke(superAdmin, cid2, ACTION.SignUpSigner, Seq(JsonFormat.toJsonString(node1Signer)))
|
||||
val msg_send9 = DoTransaction(Seq[Transaction](t9), "test-db", TypeOfSender.FromPreloader)
|
||||
probe.send(sandbox, msg_send9)
|
||||
val msg_recv9 = probe.expectMsgType[Seq[TransactionResult]](1000.seconds)
|
||||
msg_recv9.head.getResult.reason.isEmpty should be(true)
|
||||
|
||||
// 注册账户
|
||||
val node2CertFile = scala.io.Source.fromFile("jks/certs/12110107bi45jh675g.node2.cer", "UTF-8")
|
||||
val node2CertPem = try node2CertFile.mkString finally node2CertFile.close()
|
||||
val node2CertHash = Sha256.hashstr(node2CertPem)
|
||||
val node2CertId = CertId("12110107bi45jh675g", "node2")
|
||||
millis = System.currentTimeMillis()
|
||||
//生成Did的身份证书
|
||||
val node2AuthCert = rep.protos.peer.Certificate(node2CertPem, "SHA1withECDSA", true, Option(Timestamp(millis / 1000, ((millis % 1000) * 1000000).toInt)), None, CertType.CERT_AUTHENTICATION, Option(node2CertId), node2CertHash, "1.0")
|
||||
// 账户
|
||||
val node2Signer = Signer("node2", "12110107bi45jh675g", "13856789234", Seq.empty, Seq.empty, Seq.empty, Seq.empty, List(node2AuthCert), "", Option(Timestamp(millis / 1000, ((millis % 1000) * 1000000).toInt)), None, true, "1.0")
|
||||
val t4 = PeerHelper.createTransaction4Invoke(superAdmin, cid2, ACTION.SignUpSigner, Seq(JsonFormat.toJsonString(node2Signer)))
|
||||
val msg_send4 = DoTransaction(Seq[Transaction](t4), "test-db", TypeOfSender.FromPreloader)
|
||||
probe.send(sandbox, msg_send4)
|
||||
val msg_recv4 = probe.expectMsgType[Seq[TransactionResult]](1000.seconds)
|
||||
msg_recv4.head.getResult.reason.isEmpty should be(true)
|
||||
|
||||
//生成invoke交易,给账户赋初值
|
||||
val sm: SetMap = Map("121000005l35120456" -> 50, "12110107bi45jh675g" -> 50, "122000002n00123567" -> 50)
|
||||
val sms = write(sm)
|
||||
val t5 = PeerHelper.createTransaction4Invoke(superAdmin, cid1, ACTION.set, Seq(sms))
|
||||
val msg_send5 = DoTransaction(Seq[Transaction](t5), "test-db", TypeOfSender.FromPreloader)
|
||||
probe.send(sandbox, msg_send5)
|
||||
val msg_recv5 = probe.expectMsgType[Seq[TransactionResult]](1000.seconds)
|
||||
msg_recv5(0).getResult.reason.isEmpty should be(true)
|
||||
|
||||
//val aa = new ContractCert
|
||||
// superAdmin 为自己注册操作(superAdmin不注册操作也能通过授权 ),目的是为了给其他用户授权
|
||||
val snls = List("transaction.stream", "transaction.postTranByString", "transaction.postTranStream", "transaction.postTran")
|
||||
// 公开操作,无需授权
|
||||
val transferOpt = rep.protos.peer.Operate(Sha256.hashstr("ContractAssetsTPL.transfer"), "转账交易", superAdmin.split("\\.")(0), true, OperateType.OPERATE_CONTRACT,
|
||||
snls, "*", "ContractAssetsTPL.transfer", Option(Timestamp(millis / 1000, ((millis % 1000) * 1000000).toInt)), None, true, "1.0")
|
||||
val t7 = PeerHelper.createTransaction4Invoke(superAdmin, cid2, "signUpOperate", Seq(JsonFormat.toJsonString(transferOpt)))
|
||||
probe.send(sandbox, DoTransaction(Seq[Transaction](t7), "test-db", TypeOfSender.FromPreloader))
|
||||
val msg_recv7 = probe.expectMsgType[Seq[TransactionResult]](1000.seconds)
|
||||
msg_recv7.head.getResult.reason.isEmpty should be(true)
|
||||
|
||||
// superAdmin 为用户授权
|
||||
// val granteds = new ArrayBuffer[String]
|
||||
// granteds.+=("121000005l35120456")
|
||||
// millis = System.currentTimeMillis()
|
||||
// val at = rep.protos.peer.Authorize(IdTool.getRandomUUID, superAdmin.split("\\.")(0), granteds, Seq(Sha256.hashstr("ContractAssetsTPL.transfer")),
|
||||
// TransferType.TRANSFER_REPEATEDLY, Option(Timestamp(millis / 1000, ((millis % 1000) * 1000000).toInt)), None, true, "1.0")
|
||||
// var als: List[String] = List(JsonFormat.toJsonString(at))
|
||||
// val t8 = PeerHelper.createTransaction4Invoke(superAdmin, cid2, "grantOperate", Seq(SerializeUtils.compactJson(als)))
|
||||
// probe.send(sandbox, DoTransaction(Seq[Transaction](t8), "test-db", TypeOfSender.FromPreloader))
|
||||
// val msg_recv8 = probe.expectMsgType[Seq[TransactionResult]](1000.seconds)
|
||||
// msg_recv8.head.getResult.reason.isEmpty should be(true)
|
||||
|
||||
// 转账测试
|
||||
// 转账测试集
|
||||
val tcs = Array(
|
||||
Transfer("121000005l35120456", "12110107bi45jh675g", 5),
|
||||
Transfer("121000005l35120456", "12110107bi45jh675g0", 5),
|
||||
Transfer("121000005l35120456", "12110107bi45jh675g", 500))
|
||||
val rcs = Array(None, "目标账户不存在", "余额不足")
|
||||
val rcs = Array(true, "目标账户不存在", "余额不足")
|
||||
|
||||
// 账户与证书
|
||||
val signer = Signer("node2", "12110107bi45jh675g", "13856789234", Seq("node2"))
|
||||
val cert = scala.io.Source.fromFile("jks/certs/12110107bi45jh675g.node2.cer")
|
||||
val certStr = try cert.mkString finally cert.close()
|
||||
val certinfo = CertInfo("12110107bi45jh675g", "node2", Certificate(certStr, "SHA1withECDSA", true, None, None))
|
||||
|
||||
//准备探针以验证调用返回结果
|
||||
val probe = TestProbe()
|
||||
val db = ImpDataAccess.GetDataAccess(sysName)
|
||||
val sandbox = system.actorOf(TransactionDispatcher.props("transactiondispatcher"), "transactiondispatcher")
|
||||
|
||||
val cid1 = ChaincodeId("ContractAssetsTPL", 1)
|
||||
val cid2 = ChaincodeId(SystemProfile.getAccountChaincodeName, 1)
|
||||
|
||||
//生成deploy交易,部署ContractAssetsTPL
|
||||
val t1 = PeerHelper.createTransaction4Deploy(sysName, cid1, l1, "", 5000, rep.protos.peer.ChaincodeDeploy.CodeType.CODE_SCALA)
|
||||
val msg_send1 = DoTransaction(Seq[Transaction](t1), "dbnumber", TypeOfSender.FromAPI)
|
||||
probe.send(sandbox, msg_send1)
|
||||
val msg_recv1 = probe.expectMsgType[Seq[Sandbox.DoTransactionResult]](1000.seconds)
|
||||
msg_recv1(0).err.isEmpty should be(true)
|
||||
|
||||
// 生成deploy交易,部署ContractCert
|
||||
val t2 = PeerHelper.createTransaction4Deploy(sysName, cid2, l2, "", 5000, rep.protos.peer.ChaincodeDeploy.CodeType.CODE_SCALA)
|
||||
val msg_send2 = DoTransaction(Seq[Transaction](t2), "dbnumber", TypeOfSender.FromAPI)
|
||||
probe.send(sandbox, msg_send2)
|
||||
val msg_recv2 = probe.expectMsgType[Seq[Sandbox.DoTransactionResult]](1000.seconds)
|
||||
msg_recv2(0).err.isEmpty should be(true)
|
||||
|
||||
// 生成invoke交易
|
||||
// 注册账户
|
||||
val t3 = PeerHelper.createTransaction4Invoke(sysName, cid2, ACTION.SignUpSigner, Seq(write(signer)))
|
||||
val msg_send3 = DoTransaction(Seq[Transaction](t3), "dbnumber", TypeOfSender.FromAPI)
|
||||
probe.send(sandbox, msg_send3)
|
||||
val msg_recv3 = probe.expectMsgType[Seq[Sandbox.DoTransactionResult]](1000.seconds)
|
||||
msg_recv3(0).err.isEmpty should be(true)
|
||||
|
||||
// 注册证书
|
||||
val t4 = PeerHelper.createTransaction4Invoke(sysName, cid2, ACTION.SignUpCert, Seq(writePretty(certinfo)))
|
||||
val msg_send4 = DoTransaction(Seq[Transaction](t4), "dbnumber", TypeOfSender.FromAPI)
|
||||
probe.send(sandbox, msg_send4)
|
||||
val msg_recv4 = probe.expectMsgType[Seq[Sandbox.DoTransactionResult]](1000.seconds)
|
||||
msg_recv4(0).err.isEmpty should be(true)
|
||||
|
||||
//生成invoke交易,给账户赋初值
|
||||
val t5 = PeerHelper.createTransaction4Invoke(sysName, cid1, ACTION.set, Seq(sms))
|
||||
val msg_send5 = DoTransaction(Seq[Transaction](t5), "dbnumber", TypeOfSender.FromAPI)
|
||||
probe.send(sandbox, msg_send5)
|
||||
val msg_recv5 = probe.expectMsgType[Seq[Sandbox.DoTransactionResult]](1000.seconds)
|
||||
msg_recv5(0).err.isEmpty should be(true)
|
||||
|
||||
// 转账测试
|
||||
for (i <- 0 until tcs.length) {
|
||||
val t6 = PeerHelper.createTransaction4Invoke(sysName, cid1, ACTION.transfer, Seq(write(tcs(i))))
|
||||
val msg_send6 = DoTransaction(Seq[Transaction](t6), "dbnumber", TypeOfSender.FromAPI)
|
||||
val msg_send6 = DoTransaction(Seq[Transaction](t6), "test-db", TypeOfSender.FromPreloader)
|
||||
probe.send(sandbox, msg_send6)
|
||||
val msg_recv6 = probe.expectMsgType[Seq[Sandbox.DoTransactionResult]](1000.seconds)
|
||||
if (msg_recv6(0).err.isEmpty && i == 0)
|
||||
msg_recv6(0).err should be(rcs(0))
|
||||
val msg_recv6 = probe.expectMsgType[Seq[TransactionResult]](1000.seconds)
|
||||
if (msg_recv6(0).getResult.reason.isEmpty && i == 0)
|
||||
msg_recv6(0).getResult.reason.isEmpty should be(rcs(0))
|
||||
else
|
||||
msg_recv6(0).err.get.cause.getMessage should be(rcs(i))
|
||||
msg_recv6(0).getResult.reason should be(rcs(i))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,152 +0,0 @@
|
||||
/*
|
||||
* Copyright 2019 Blockchain Technology and Application Joint Lab, Linkel Technology Co., Ltd, Beijing, Fintech Research Center of ISCAS.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BA SIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
*/
|
||||
|
||||
package rep.sc
|
||||
|
||||
import akka.actor.ActorSystem
|
||||
import akka.testkit.{TestKit, TestProbe}
|
||||
import org.json4s.{DefaultFormats, jackson}
|
||||
import org.json4s.native.Serialization.{write, writePretty}
|
||||
import org.scalatest.{BeforeAndAfterAll, FlatSpecLike, Matchers}
|
||||
import rep.app.system.ClusterSystem
|
||||
import rep.app.system.ClusterSystem.InitType
|
||||
import rep.network.autotransaction.PeerHelper
|
||||
import rep.network.module.cfrd.ModuleManagerOfCFRD
|
||||
import rep.protos.peer.{Certificate, ChaincodeId, Signer, Transaction}
|
||||
import rep.sc.TransferSpec.{ACTION, SetMap}
|
||||
import rep.sc.tpl._
|
||||
//.{CertStatus,CertInfo}
|
||||
import rep.sc.tpl.Transfer
|
||||
import rep.storage.ImpDataAccess
|
||||
import rep.utils.SerializeUtils.toJson
|
||||
import rep.app.conf.SystemProfile
|
||||
|
||||
import scala.concurrent.duration._
|
||||
import scala.collection.mutable.Map
|
||||
import rep.sc.SandboxDispatcher.DoTransaction
|
||||
|
||||
|
||||
/**
|
||||
* author zyf
|
||||
*
|
||||
* @param _system
|
||||
*/
|
||||
class TransferSpec2(_system: ActorSystem) extends TestKit(_system) with Matchers with FlatSpecLike with BeforeAndAfterAll {
|
||||
|
||||
def this() = this(ActorSystem("TransferSpec", new ClusterSystem("121000005l35120456.node1", InitType.MULTI_INIT, false).getConf))
|
||||
|
||||
override def afterAll: Unit = {
|
||||
shutdown(system)
|
||||
}
|
||||
|
||||
implicit val serialization = jackson.Serialization
|
||||
// or native.Serialization
|
||||
implicit val formats = DefaultFormats
|
||||
|
||||
"Contract deployed as CODE_SCALA " should "executes serially" in {
|
||||
|
||||
val sysName = "121000005l35120456.node1"
|
||||
val dbTag = "121000005l35120456.node1"
|
||||
//建立PeerManager实例是为了调用transactionCreator(需要用到密钥签名),无他
|
||||
val pm = system.actorOf(ModuleManagerOfCFRD.props("modulemanager", sysName, false, false, false), "modulemanager")
|
||||
|
||||
// 部署资产管理
|
||||
val s1 = scala.io.Source.fromFile("src/main/scala/rep/sc/tpl/ContractAssetsTPL2.scala")
|
||||
val l1 = try s1.mkString finally s1.close()
|
||||
|
||||
// 部署账户管理合约
|
||||
val s2 = scala.io.Source.fromFile("src/main/scala/rep/sc/tpl/ContractCert.scala")
|
||||
val l2 = try s2.mkString finally s2.close()
|
||||
|
||||
// 账户初始化赋值
|
||||
val sm: SetMap = Map("121000005l35120456" -> 50, "12110107bi45jh675g" -> 50, "122000002n00123567" -> 50)
|
||||
val sms = write(sm)
|
||||
|
||||
// 测试集
|
||||
val tcs = Array(
|
||||
Transfer("121000005l35120456", "12110107bi45jh675g", 5),
|
||||
Transfer("121000005l35120456", "12110107bi45jh675g", 3),
|
||||
Transfer("121000005l35120456", "12110107bi45jh675g", 2)
|
||||
)
|
||||
|
||||
// 结果集
|
||||
val rcs = Array(None, None, None)
|
||||
|
||||
//val aa = new ContractCert
|
||||
// 账户与证书
|
||||
val signer = Signer("node2", "12110107bi45jh675g", "13856789234", Seq("node2"))
|
||||
val cert = scala.io.Source.fromFile("jks/certs/12110107bi45jh675g.node2.cer")
|
||||
val certStr = try cert.mkString finally cert.close()
|
||||
val certinfo = CertInfo("12110107bi45jh675g", "node2", Certificate(certStr, "SHA1withECDSA", true, None, None))
|
||||
|
||||
//准备探针以验证调用返回结果
|
||||
val probe = TestProbe()
|
||||
val db = ImpDataAccess.GetDataAccess(sysName)
|
||||
val sandbox = system.actorOf(TransactionDispatcher.props("transactiondispatcher"), "transactiondispatcher")
|
||||
|
||||
val cid1 = ChaincodeId("ContractAssetsTPL2", 1)
|
||||
val cid2 = ChaincodeId(SystemProfile.getAccountChaincodeName, 1)
|
||||
|
||||
// 生成deploy交易,部署ContractAssetsTPL2
|
||||
val t1 = PeerHelper.createTransaction4Deploy(sysName, cid1, l1, "", 5000, rep.protos.peer.ChaincodeDeploy.CodeType.CODE_SCALA)
|
||||
val msg_send1 = DoTransaction(Seq[Transaction](t1), "dbnumber", TypeOfSender.FromAPI)
|
||||
probe.send(sandbox, msg_send1)
|
||||
val msg_recv1 = probe.expectMsgType[Seq[Sandbox.DoTransactionResult]](1000.seconds)
|
||||
msg_recv1(0).err.isEmpty should be(true)
|
||||
|
||||
// 生成deploy交易,部署ContractCert
|
||||
val t2 = PeerHelper.createTransaction4Deploy(sysName, cid2, l2, "", 5000, rep.protos.peer.ChaincodeDeploy.CodeType.CODE_SCALA)
|
||||
val msg_send2 = DoTransaction(Seq[Transaction](t2), "dbnumber", TypeOfSender.FromAPI)
|
||||
probe.send(sandbox, msg_send2)
|
||||
val msg_recv2 = probe.expectMsgType[Seq[Sandbox.DoTransactionResult]](1000.seconds)
|
||||
msg_recv2(0).err.isEmpty should be(true)
|
||||
|
||||
// 生成invoke交易
|
||||
// 注册账户
|
||||
val t3 = PeerHelper.createTransaction4Invoke(sysName, cid2, ACTION.SignUpSigner, Seq(write(signer)))
|
||||
val msg_send3 = DoTransaction(Seq[Transaction](t3), "dbnumber", TypeOfSender.FromAPI)
|
||||
probe.send(sandbox, msg_send3)
|
||||
val msg_recv3 = probe.expectMsgType[Seq[Sandbox.DoTransactionResult]](1000.seconds)
|
||||
msg_recv3(0).err.isEmpty should be(true)
|
||||
|
||||
// 注册证书
|
||||
val t4 = PeerHelper.createTransaction4Invoke(sysName, cid2, ACTION.SignUpCert, Seq(writePretty(certinfo)))
|
||||
val msg_send4 = DoTransaction(Seq[Transaction](t4), "dbnumber", TypeOfSender.FromAPI)
|
||||
probe.send(sandbox, msg_send4)
|
||||
val msg_recv4 = probe.expectMsgType[Seq[Sandbox.DoTransactionResult]](1000.seconds)
|
||||
msg_recv4(0).err.isEmpty should be(true)
|
||||
|
||||
//生成invoke交易
|
||||
val t5 = PeerHelper.createTransaction4Invoke(sysName, cid1, ACTION.set, Seq(sms))
|
||||
val msg_send5 = DoTransaction(Seq[Transaction](t5), "dbnumber", TypeOfSender.FromAPI)
|
||||
probe.send(sandbox, msg_send5)
|
||||
val msg_recv5 = probe.expectMsgType[Seq[Sandbox.DoTransactionResult]](1000.seconds)
|
||||
msg_recv5(0).err.isEmpty should be(true)
|
||||
|
||||
for (i <- 0 until tcs.length) {
|
||||
val t6 = PeerHelper.createTransaction4Invoke(sysName, cid1, ACTION.transfer, Seq(write(tcs(i))))
|
||||
val msg_send6 = DoTransaction(Seq[Transaction](t6), "dbnumber", TypeOfSender.FromAPI)
|
||||
probe.send(sandbox, msg_send6)
|
||||
}
|
||||
|
||||
for (i <- 0 until tcs.length) {
|
||||
val msg_recv6 = probe.expectMsgType[Seq[Sandbox.DoTransactionResult]](1000.seconds)
|
||||
msg_recv6(0).err.isEmpty should be(true)
|
||||
// println(msg_recv6.r.reason)
|
||||
msg_recv6(0).r shouldBe (null)
|
||||
}
|
||||
}
|
||||
}
|
@ -1,170 +0,0 @@
|
||||
/*
|
||||
* Copyright 2019 Blockchain Technology and Application Joint Lab, Linkel Technology Co., Ltd, Beijing, Fintech Research Center of ISCAS.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BA SIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
*/
|
||||
|
||||
package rep.sc
|
||||
|
||||
import akka.util.Timeout
|
||||
|
||||
import scala.concurrent.duration._
|
||||
import akka.pattern.ask
|
||||
import akka.pattern.AskTimeoutException
|
||||
|
||||
import scala.concurrent._
|
||||
import akka.actor.{ActorRef, ActorSelection, ActorSystem}
|
||||
import akka.testkit.{TestKit, TestProbe}
|
||||
import org.json4s.{DefaultFormats, jackson}
|
||||
import org.json4s.native.Serialization.{write, writePretty}
|
||||
import org.scalatest.{BeforeAndAfterAll, FlatSpecLike, Matchers}
|
||||
import rep.app.system.ClusterSystem
|
||||
import rep.app.system.ClusterSystem.InitType
|
||||
import rep.network.autotransaction.PeerHelper
|
||||
import rep.network.module.cfrd.ModuleManagerOfCFRD
|
||||
import rep.protos.peer.{Certificate, ChaincodeId, Signer}
|
||||
import rep.sc.tpl._
|
||||
//.{CertStatus,CertInfo}
|
||||
import rep.sc.tpl.{Transfer}
|
||||
import rep.sc.TransferSpec.{SetMap, ACTION}
|
||||
import rep.storage.ImpDataAccess
|
||||
import rep.utils.SerializeUtils.toJson
|
||||
import rep.app.conf.SystemProfile
|
||||
|
||||
import scala.concurrent.duration._
|
||||
import scala.collection.mutable.Map
|
||||
import rep.network.module.cfrd.CFRDActorType
|
||||
import rep.protos.peer.Transaction
|
||||
|
||||
import scala.concurrent.ExecutionContext.Implicits._
|
||||
import rep.sc.SandboxDispatcher.DoTransaction
|
||||
|
||||
|
||||
/**
|
||||
* author zyf
|
||||
*
|
||||
* @param _system
|
||||
*/
|
||||
class TransferSpec3(_system: ActorSystem) extends TestKit(_system) with Matchers with FlatSpecLike with BeforeAndAfterAll {
|
||||
|
||||
import scala.concurrent.duration._
|
||||
|
||||
implicit val timeout = Timeout(3.seconds)
|
||||
|
||||
def this() = this(ActorSystem("TransferSpec", new ClusterSystem("121000005l35120456.node1", InitType.MULTI_INIT, false).getConf))
|
||||
|
||||
override def afterAll: Unit = {
|
||||
shutdown(system)
|
||||
}
|
||||
|
||||
implicit val serialization = jackson.Serialization
|
||||
// or native.Serialization
|
||||
implicit val formats = DefaultFormats
|
||||
|
||||
"Contract deployed as CODE_SCALA_PARALLEL " should "executes in parallel" in {
|
||||
|
||||
val sysName = "121000005l35120456.node1"
|
||||
val dbTag = "121000005l35120456.node1"
|
||||
//建立PeerManager实例是为了调用transactionCreator(需要用到密钥签名),无他
|
||||
val pm = system.actorOf(ModuleManagerOfCFRD.props("modulemanager", sysName, false, false, false), "modulemanager")
|
||||
|
||||
//val path = pm.path.address.toString + "/user/modulemanager/preloadtransrouter"
|
||||
//val sandbox2 = system.actorOf(TransactionDispatcher.props("transactiondispatcher"),"transactiondispatcher")
|
||||
|
||||
// 部署资产管理
|
||||
val s1 = scala.io.Source.fromFile("src/main/scala/rep/sc/tpl/ContractAssetsTPL2.scala")
|
||||
val l1 = try s1.mkString finally s1.close()
|
||||
|
||||
// 部署账户管理合约
|
||||
val s2 = scala.io.Source.fromFile("src/main/scala/rep/sc/tpl/ContractCert.scala")
|
||||
val l2 = try s2.mkString finally s2.close()
|
||||
|
||||
// 账户初始化赋值
|
||||
val sm: SetMap = Map("121000005l35120456" -> 50, "12110107bi45jh675g" -> 50, "122000002n00123567" -> 50)
|
||||
val sms = write(sm)
|
||||
|
||||
//val aa = new ContractCert
|
||||
// 测试集
|
||||
val tcs = Array(
|
||||
Transfer("121000005l35120456", "12110107bi45jh675g", 5),
|
||||
Transfer("121000005l35120456", "12110107bi45jh675g", 3),
|
||||
Transfer("121000005l35120456", "12110107bi45jh675g", 2))
|
||||
// 结果集
|
||||
val rcs = Array(None, None, None)
|
||||
|
||||
// 账户与证书
|
||||
val signer = Signer("node2", "12110107bi45jh675g", "13856789234", Seq("node2"))
|
||||
val cert = scala.io.Source.fromFile("jks/certs/12110107bi45jh675g.node2.cer")
|
||||
val certStr = try cert.mkString finally cert.close()
|
||||
val certinfo = CertInfo("12110107bi45jh675g", "node2", Certificate(certStr, "SHA1withECDSA", true, None, None))
|
||||
|
||||
//准备探针以验证调用返回结果
|
||||
val probe = TestProbe()
|
||||
val db = ImpDataAccess.GetDataAccess(sysName)
|
||||
val sandbox = system.actorOf(TransactionDispatcher.props("transactiondispatcher"), "transactiondispatcher")
|
||||
|
||||
// name + version
|
||||
val cid1 = ChaincodeId("ContractAssetsTPL3", 1)
|
||||
val cid2 = ChaincodeId(SystemProfile.getAccountChaincodeName, 1)
|
||||
|
||||
//生成deploy交易,deploy ContractAssetsTPL3
|
||||
val t1 = PeerHelper.createTransaction4Deploy(sysName, cid1, l1, "", 5000, rep.protos.peer.ChaincodeDeploy.CodeType.CODE_SCALA_PARALLEL)
|
||||
val msg_send1 = DoTransaction(Seq[Transaction](t1), "dbnumber", TypeOfSender.FromAPI)
|
||||
probe.send(sandbox, msg_send1)
|
||||
val msg_recv1 = probe.expectMsgType[Seq[Sandbox.DoTransactionResult]](1000.seconds)
|
||||
msg_recv1(0).err.isEmpty should be(true)
|
||||
|
||||
// 生成deploy交易,deploy ContractCert
|
||||
val t2 = PeerHelper.createTransaction4Deploy(sysName, cid2, l2, "", 5000, rep.protos.peer.ChaincodeDeploy.CodeType.CODE_SCALA)
|
||||
val msg_send2 = DoTransaction(Seq[Transaction](t2), "dbnumber", TypeOfSender.FromAPI)
|
||||
probe.send(sandbox, msg_send2)
|
||||
val msg_recv2 = probe.expectMsgType[Seq[Sandbox.DoTransactionResult]](1000.seconds)
|
||||
msg_recv2(0).err.isEmpty should be(true)
|
||||
|
||||
// 生成invoke交易
|
||||
// 注册账户
|
||||
val t3 = PeerHelper.createTransaction4Invoke(sysName, cid2, ACTION.SignUpSigner, Seq(write(signer)))
|
||||
val msg_send3 = DoTransaction(Seq[Transaction](t3), "dbnumber", TypeOfSender.FromAPI)
|
||||
probe.send(sandbox, msg_send3)
|
||||
val msg_recv3 = probe.expectMsgType[Seq[Sandbox.DoTransactionResult]](1000.seconds)
|
||||
msg_recv3(0).err.isEmpty should be(true)
|
||||
|
||||
// 注册证书
|
||||
val t4 = PeerHelper.createTransaction4Invoke(sysName, cid2, ACTION.SignUpCert, Seq(writePretty(certinfo)))
|
||||
val msg_send4 = DoTransaction(Seq[Transaction](t4), "dbnumber", TypeOfSender.FromAPI)
|
||||
probe.send(sandbox, msg_send4)
|
||||
val msg_recv4 = probe.expectMsgType[Seq[Sandbox.DoTransactionResult]](1000.seconds)
|
||||
msg_recv4(0).err.isEmpty should be(true)
|
||||
|
||||
//生成invoke交易,给账户初始化赋值
|
||||
val t5 = PeerHelper.createTransaction4Invoke(sysName, cid1, ACTION.set, Seq(sms))
|
||||
val msg_send5 = DoTransaction(Seq[Transaction](t5), "dbnumber", TypeOfSender.FromAPI)
|
||||
probe.send(sandbox, msg_send5)
|
||||
val msg_recv5 = probe.expectMsgType[Seq[Sandbox.DoTransactionResult]](1000.seconds)
|
||||
msg_recv5(0).err.isEmpty should be(true)
|
||||
|
||||
Thread.sleep(5000)
|
||||
|
||||
for (i <- 0 until tcs.length) {
|
||||
val t6 = PeerHelper.createTransaction4Invoke(sysName, cid1, ACTION.transfer, Seq(write(tcs(i))))
|
||||
val msg_send6 = DoTransaction(Seq[Transaction](t6), "dbnumber", TypeOfSender.FromAPI)
|
||||
probe.send(sandbox, msg_send6)
|
||||
}
|
||||
|
||||
for (i <- 0 until tcs.length) {
|
||||
val msg_recv6 = probe.expectMsgType[Seq[Sandbox.DoTransactionResult]](1000.seconds)
|
||||
msg_recv6(0).err.isEmpty should be(true)
|
||||
msg_recv6(0).r shouldBe (null)
|
||||
}
|
||||
}
|
||||
}
|
@ -18,23 +18,26 @@ package rep.sc
|
||||
|
||||
import akka.actor.ActorSystem
|
||||
import akka.testkit.{TestKit, TestProbe}
|
||||
import com.google.protobuf.timestamp.Timestamp
|
||||
import org.scalatest.{BeforeAndAfterAll, FlatSpecLike, Matchers}
|
||||
import rep.app.conf.SystemProfile
|
||||
import rep.app.system.ClusterSystem
|
||||
import rep.app.system.ClusterSystem.InitType
|
||||
import rep.crypto.Sha256
|
||||
import rep.crypto.cert.SignTool
|
||||
import rep.network.autotransaction.PeerHelper
|
||||
import rep.network.module.cfrd.ModuleManagerOfCFRD
|
||||
import rep.protos.peer.{Certificate, ChaincodeId, Signer, Transaction}
|
||||
import rep.protos.peer.Certificate.CertType
|
||||
import rep.protos.peer.ChaincodeDeploy.ContractClassification
|
||||
import rep.protos.peer.Operate.OperateType
|
||||
import rep.protos.peer._
|
||||
import rep.sc.SandboxDispatcher.DoTransaction
|
||||
import rep.sc.TransferSpec.{ACTION, SetMap}
|
||||
import rep.sc.tpl._
|
||||
//.{CertStatus,CertInfo}
|
||||
import rep.sc.tpl.Transfer
|
||||
import rep.storage.ImpDataAccess
|
||||
import rep.utils.SerializeUtils.toJson
|
||||
import rep.app.conf.SystemProfile
|
||||
import scalapb.json4s.JsonFormat
|
||||
|
||||
import scala.concurrent.duration._
|
||||
import scala.collection.mutable.Map
|
||||
import rep.sc.SandboxDispatcher.DoTransaction
|
||||
import scala.concurrent.duration._
|
||||
|
||||
|
||||
/**
|
||||
@ -46,95 +49,138 @@ class TransferSpec_Legal(_system: ActorSystem) extends TestKit(_system) with Mat
|
||||
|
||||
case class Transfer(from: String, to: String, amount: Int, remind: String)
|
||||
|
||||
def this() = this(ActorSystem("TransferSpec", new ClusterSystem("121000005l35120456.node1", InitType.MULTI_INIT, false).getConf))
|
||||
def this() = this(ActorSystem("TransferSpec_Legal", new ClusterSystem("121000005l35120456.node1", InitType.MULTI_INIT, false).getConf))
|
||||
|
||||
override def afterAll: Unit = {
|
||||
shutdown(system)
|
||||
}
|
||||
|
||||
|
||||
"ContractAssetsTPL" should "can set assets and transfer from a to b" in {
|
||||
"ContractAssetsTPL" can "manage user's assets" in {
|
||||
|
||||
val sysName = "121000005l35120456.node1"
|
||||
val dbTag = "121000005l35120456.node1"
|
||||
//建立PeerManager实例是为了调用transactionCreator(需要用到密钥签名),无他
|
||||
val pm = system.actorOf(ModuleManagerOfCFRD.props("modulemanager", sysName, false, false, false), "modulemanager")
|
||||
val superAdmin = "951002007l78123233.super_admin"
|
||||
// 初始化配置项,主要是为了初始化存储路径
|
||||
SystemProfile.initConfigSystem(system.settings.config, sysName)
|
||||
// 加载node1的私钥
|
||||
SignTool.loadPrivateKey(sysName, "123", "jks/" + sysName + ".jks")
|
||||
// 加载super_admin的私钥
|
||||
SignTool.loadPrivateKey(superAdmin, "super_admin", "jks/" + superAdmin + ".jks")
|
||||
|
||||
// 部署资产管理
|
||||
val cid1 = ChaincodeId("ContractAssetsTPL_Legal", 1)
|
||||
val s1 = scala.io.Source.fromFile("src/main/scala/rep/sc/tpl/ContractAssets_Legal.scala")
|
||||
val l1 = try s1.mkString finally s1.close()
|
||||
// 部署账户管理合约
|
||||
val s2 = scala.io.Source.fromFile("src/main/scala/rep/sc/tpl/ContractCert.scala")
|
||||
val l2 = try s2.mkString finally s2.close()
|
||||
val sm: SetMap = Map("121000005l35120456" -> 50, "12110107bi45jh675g" -> 50, "122000002n00123567" -> 50)
|
||||
val sms = toJson(sm)
|
||||
|
||||
//val aa = new ContractCert
|
||||
val signer = Signer("node2", "12110107bi45jh675g", "13856789234", Seq("node2"))
|
||||
val cert = scala.io.Source.fromFile("jks/certs/12110107bi45jh675g.node2.cer")
|
||||
val certStr = try cert.mkString finally cert.close()
|
||||
val certinfo = CertInfo("12110107bi45jh675g", "node2", Certificate(certStr, "SHA1withECDSA", true, None, None))
|
||||
// 部署账户管理合约
|
||||
val cid2 = ChaincodeId(SystemProfile.getAccountChaincodeName, 1)
|
||||
val s2 = scala.io.Source.fromFile("src/main/scala/rep/sc/tpl/did/RdidOperateAuthorizeTPL.scala")
|
||||
val l2 = try s2.mkString finally s2.close()
|
||||
|
||||
//准备探针以验证调用返回结果
|
||||
val probe = TestProbe()
|
||||
val db = ImpDataAccess.GetDataAccess(sysName)
|
||||
// val db = ImpDataAccess.GetDataAccess(sysName)
|
||||
val sandbox = system.actorOf(TransactionDispatcher.props("transactiondispatcher"), "transactiondispatcher")
|
||||
|
||||
val cid2 = ChaincodeId(SystemProfile.getAccountChaincodeName, 1)
|
||||
val cid1 = ChaincodeId("ContractAssetsTPL_Legal", 1)
|
||||
|
||||
//生成deploy交易
|
||||
val t1 = PeerHelper.createTransaction4Deploy(sysName, cid1, l1, "", 5000, rep.protos.peer.ChaincodeDeploy.CodeType.CODE_SCALA)
|
||||
val msg_send1 = DoTransaction(Seq[Transaction](t1), "dbnumber", TypeOfSender.FromAPI)
|
||||
//生成deploy交易,部署ContractAssetsTPL
|
||||
val t1 = PeerHelper.createTransaction4Deploy(superAdmin, cid1, l1, "", 5000, rep.protos.peer.ChaincodeDeploy.CodeType.CODE_SCALA, ContractClassification.CONTRACT_CUSTOM)
|
||||
val msg_send1 = DoTransaction(Seq[Transaction](t1), "test-db", TypeOfSender.FromPreloader)
|
||||
probe.send(sandbox, msg_send1)
|
||||
val msg_recv1 = probe.expectMsgType[Seq[Sandbox.DoTransactionResult]](1000.seconds)
|
||||
msg_recv1(0).err should be(None)
|
||||
val msg_recv1 = probe.expectMsgType[Seq[TransactionResult]](1000.seconds)
|
||||
msg_recv1(0).getResult.reason.isEmpty should be(true)
|
||||
|
||||
val t2 = PeerHelper.createTransaction4Deploy(sysName, cid2, l2, "", 5000, rep.protos.peer.ChaincodeDeploy.CodeType.CODE_SCALA)
|
||||
val msg_send2 = DoTransaction(Seq[Transaction](t2), "dbnumber", TypeOfSender.FromAPI)
|
||||
// 生成deploy交易,部署RdidOperateAuthorizeTPL
|
||||
val t2 = PeerHelper.createTransaction4Deploy(superAdmin, cid2, l2, "", 5000, rep.protos.peer.ChaincodeDeploy.CodeType.CODE_SCALA, ContractClassification.CONTRACT_SYSTEM)
|
||||
val msg_send2 = DoTransaction(Seq[Transaction](t2), "test-db", TypeOfSender.FromPreloader)
|
||||
probe.send(sandbox, msg_send2)
|
||||
val msg_recv2 = probe.expectMsgType[Seq[Sandbox.DoTransactionResult]](1000.seconds)
|
||||
msg_recv2(0).err.isEmpty should be(true)
|
||||
val msg_recv2 = probe.expectMsgType[Seq[TransactionResult]](1000.seconds)
|
||||
msg_recv2(0).getResult.reason.isEmpty should be(true)
|
||||
|
||||
// 生成invoke交易
|
||||
// 注册账户
|
||||
val t3 = PeerHelper.createTransaction4Invoke(sysName, cid2, ACTION.SignUpSigner, Seq(toJson(signer)))
|
||||
val msg_send3 = DoTransaction(Seq[Transaction](t3), "dbnumber", TypeOfSender.FromAPI)
|
||||
val superCert = scala.io.Source.fromFile("jks/certs/951002007l78123233.super_admin.cer", "UTF-8")
|
||||
val superCertPem = try superCert.mkString finally superCert.close()
|
||||
val superCertHash = Sha256.hashstr(superCertPem)
|
||||
val superCertId = CertId("951002007l78123233", "super_admin")
|
||||
var millis = System.currentTimeMillis()
|
||||
//生成Did的身份证书
|
||||
val superAuthCert = rep.protos.peer.Certificate(superCertPem, "SHA1withECDSA", true, Option(Timestamp(millis / 1000, ((millis % 1000) * 1000000).toInt)), None, CertType.CERT_AUTHENTICATION, Option(superCertId), superCertHash, "1.0")
|
||||
// 账户
|
||||
val superSigner = Signer("super_admin", "951002007l78123233", "13856789234", Seq.empty, Seq.empty, Seq.empty, Seq.empty, List(superAuthCert), "", Option(Timestamp(millis / 1000, ((millis % 1000) * 1000000).toInt)), None, true, "1.0")
|
||||
val t3 = PeerHelper.createTransaction4Invoke(superAdmin, cid2, ACTION.SignUpSigner, Seq(JsonFormat.toJsonString(superSigner)))
|
||||
val msg_send3 = DoTransaction(Seq[Transaction](t3), "test-db", TypeOfSender.FromPreloader)
|
||||
probe.send(sandbox, msg_send3)
|
||||
val msg_recv3 = probe.expectMsgType[Seq[Sandbox.DoTransactionResult]](1000.seconds)
|
||||
msg_recv3(0).err.isEmpty should be(true)
|
||||
val msg_recv3 = probe.expectMsgType[Seq[TransactionResult]](1000.seconds)
|
||||
msg_recv3(0).getResult.reason.isEmpty should be(true)
|
||||
|
||||
// 注册证书
|
||||
val t4 = PeerHelper.createTransaction4Invoke(sysName, cid2, ACTION.SignUpCert, Seq(toJson(certinfo)))
|
||||
val msg_send4 = DoTransaction(Seq[Transaction](t4), "dbnumber", TypeOfSender.FromAPI)
|
||||
// 注册账户
|
||||
val node1CertFile = scala.io.Source.fromFile("jks/certs/121000005l35120456.node1.cer", "UTF-8")
|
||||
val node1CertPem = try node1CertFile.mkString finally node1CertFile.close()
|
||||
val node1CertHash = Sha256.hashstr(node1CertPem)
|
||||
val node1CertId = CertId("121000005l35120456", "node1")
|
||||
millis = System.currentTimeMillis()
|
||||
//生成Did的身份证书
|
||||
val node1AuthCert = rep.protos.peer.Certificate(node1CertPem, "SHA1withECDSA", true, Option(Timestamp(millis / 1000, ((millis % 1000) * 1000000).toInt)), None, CertType.CERT_AUTHENTICATION, Option(node1CertId), node1CertHash, "1.0")
|
||||
// 账户
|
||||
val node1Signer = Signer("node1", "121000005l35120456", "13856789234", Seq.empty, Seq.empty, Seq.empty, Seq.empty, List(node1AuthCert), "", Option(Timestamp(millis / 1000, ((millis % 1000) * 1000000).toInt)), None, true, "1.0")
|
||||
val t9 = PeerHelper.createTransaction4Invoke(superAdmin, cid2, ACTION.SignUpSigner, Seq(JsonFormat.toJsonString(node1Signer)))
|
||||
val msg_send9 = DoTransaction(Seq[Transaction](t9), "test-db", TypeOfSender.FromPreloader)
|
||||
probe.send(sandbox, msg_send9)
|
||||
val msg_recv9 = probe.expectMsgType[Seq[TransactionResult]](1000.seconds)
|
||||
msg_recv9.head.getResult.reason.isEmpty should be(true)
|
||||
|
||||
// 注册账户
|
||||
val node2CertFile = scala.io.Source.fromFile("jks/certs/12110107bi45jh675g.node2.cer", "UTF-8")
|
||||
val node2CertPem = try node2CertFile.mkString finally node2CertFile.close()
|
||||
val node2CertHash = Sha256.hashstr(node2CertPem)
|
||||
val node2CertId = CertId("12110107bi45jh675g", "node2")
|
||||
millis = System.currentTimeMillis()
|
||||
//生成Did的身份证书
|
||||
val node2AuthCert = rep.protos.peer.Certificate(node2CertPem, "SHA1withECDSA", true, Option(Timestamp(millis / 1000, ((millis % 1000) * 1000000).toInt)), None, CertType.CERT_AUTHENTICATION, Option(node2CertId), node2CertHash, "1.0")
|
||||
// 账户
|
||||
val node2Signer = Signer("node2", "12110107bi45jh675g", "13856789234", Seq.empty, Seq.empty, Seq.empty, Seq.empty, List(node2AuthCert), "", Option(Timestamp(millis / 1000, ((millis % 1000) * 1000000).toInt)), None, true, "1.0")
|
||||
val t4 = PeerHelper.createTransaction4Invoke(superAdmin, cid2, ACTION.SignUpSigner, Seq(JsonFormat.toJsonString(node2Signer)))
|
||||
val msg_send4 = DoTransaction(Seq[Transaction](t4), "test-db", TypeOfSender.FromPreloader)
|
||||
probe.send(sandbox, msg_send4)
|
||||
val msg_recv4 = probe.expectMsgType[Seq[Sandbox.DoTransactionResult]](1000.seconds)
|
||||
msg_recv4(0).err.isEmpty should be(true)
|
||||
val msg_recv4 = probe.expectMsgType[Seq[TransactionResult]](1000.seconds)
|
||||
msg_recv4.head.getResult.reason.isEmpty should be(true)
|
||||
|
||||
|
||||
//生成invoke交易
|
||||
val t5 = PeerHelper.createTransaction4Invoke(sysName, cid1, ACTION.set, Seq(sms))
|
||||
val msg_send5 = DoTransaction(Seq[Transaction](t5), "dbnumber", TypeOfSender.FromAPI)
|
||||
//生成invoke交易,给账户赋初值
|
||||
val sm: SetMap = Map("121000005l35120456" -> 50, "12110107bi45jh675g" -> 50, "122000002n00123567" -> 50)
|
||||
val sms = toJson(sm)
|
||||
val t5 = PeerHelper.createTransaction4Invoke(superAdmin, cid1, ACTION.set, Seq(sms))
|
||||
val msg_send5 = DoTransaction(Seq[Transaction](t5), "test-db", TypeOfSender.FromPreloader)
|
||||
probe.send(sandbox, msg_send5)
|
||||
val msg_recv5 = probe.expectMsgType[Seq[Sandbox.DoTransactionResult]](1000.seconds)
|
||||
msg_recv5(0).r.code should be(1)
|
||||
val msg_recv5 = probe.expectMsgType[Seq[TransactionResult]](1000.seconds)
|
||||
msg_recv5(0).getResult.code should be(1)
|
||||
|
||||
// superAdmin 为自己注册操作(superAdmin不注册操作也能通过授权 ),目的是为了给其他用户授权
|
||||
val snls = List("transaction.stream", "transaction.postTranByString", "transaction.postTranStream", "transaction.postTran")
|
||||
// 公开操作,无需授权
|
||||
val transferOpt = rep.protos.peer.Operate(Sha256.hashstr("ContractAssetsTPL_Legal.transfer"), "转账交易", superAdmin.split("\\.")(0), true, OperateType.OPERATE_CONTRACT,
|
||||
snls, "*", "ContractAssetsTPL_Legal.transfer", Option(Timestamp(millis / 1000, ((millis % 1000) * 1000000).toInt)), None, true, "1.0")
|
||||
val t7 = PeerHelper.createTransaction4Invoke(superAdmin, cid2, "signUpOperate", Seq(JsonFormat.toJsonString(transferOpt)))
|
||||
probe.send(sandbox, DoTransaction(Seq[Transaction](t7), "test-db", TypeOfSender.FromPreloader))
|
||||
val msg_recv7 = probe.expectMsgType[Seq[TransactionResult]](1000.seconds)
|
||||
msg_recv7.head.getResult.reason.isEmpty should be(true)
|
||||
|
||||
//获得提醒文本
|
||||
var p = Transfer("121000005l35120456", "12110107bi45jh675g", 5, null)
|
||||
var t = PeerHelper.createTransaction4Invoke(sysName, cid1, ACTION.transfer, Seq(toJson(p)))
|
||||
var msg_send = DoTransaction(Seq[Transaction](t), "dbnumber", TypeOfSender.FromAPI)
|
||||
var msg_send = DoTransaction(Seq[Transaction](t), "test-db", TypeOfSender.FromPreloader)
|
||||
probe.send(sandbox, msg_send)
|
||||
var msg_recv = probe.expectMsgType[Seq[Sandbox.DoTransactionResult]](1000.seconds)
|
||||
msg_recv(0).r.code should be(2)
|
||||
var msg_recv = probe.expectMsgType[Seq[TransactionResult]](1000.seconds)
|
||||
msg_recv(0).getResult.code should be(2)
|
||||
|
||||
//对提醒文本签名
|
||||
val remind = msg_recv(0).r.reason
|
||||
val remind = msg_recv(0).getResult.reason
|
||||
println(remind)
|
||||
p = Transfer("121000005l35120456", "12110107bi45jh675g", 5, remind)
|
||||
t = PeerHelper.createTransaction4Invoke(sysName, cid1, ACTION.transfer, Seq(toJson(p)))
|
||||
msg_send = DoTransaction(Seq[Transaction](t), "dbnumber", TypeOfSender.FromAPI)
|
||||
msg_send = DoTransaction(Seq[Transaction](t), "test-db", TypeOfSender.FromPreloader)
|
||||
probe.send(sandbox, msg_send)
|
||||
msg_recv = probe.expectMsgType[Seq[Sandbox.DoTransactionResult]](1000.seconds)
|
||||
msg_recv(0).r.code should be(1)
|
||||
msg_recv = probe.expectMsgType[Seq[TransactionResult]](1000.seconds)
|
||||
msg_recv(0).getResult.code should be(1)
|
||||
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user