diff --git a/src/main/scala/rep/sc/tpl/ContractAssetsTPL2.scala b/src/main/scala/rep/sc/tpl/ContractAssetsTPL2.scala index 01f965b7..42cbea7e 100644 --- a/src/main/scala/rep/sc/tpl/ContractAssetsTPL2.scala +++ b/src/main/scala/rep/sc/tpl/ContractAssetsTPL2.scala @@ -23,9 +23,8 @@ 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 +import rep.sc.scalax.{ContractContext, ContractException, IContract} import rep.protos.peer.ActionResult /** @@ -52,20 +51,20 @@ case class Transfer(from:String, to:String, amount:Int) for((k,v)<-data){ ctx.api.setVal(k, v) } - new ActionResult(1) + null } def transfer(ctx: ContractContext, data:Transfer) :ActionResult={ if(!data.from.equals(ctx.t.getSignature.getCertId.creditCode)) - return new ActionResult(-1, "只允许从本人账户转出") + throw ContractException("只允许从本人账户转出") val signerKey = data.to // 跨合约读账户,该处并未反序列化 if(ctx.api.getStateEx(chaincodeName,data.to)==null) - return new ActionResult(-2, "目标账户不存在") + throw ContractException("目标账户不存在") val sfrom = ctx.api.getVal(data.from) var dfrom =sfrom.asInstanceOf[Int] if(dfrom < data.amount) - return new ActionResult(-3, "余额不足") + throw ContractException("余额不足") var dto = ctx.api.getVal(data.to).toString.toInt val df:SimpleDateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ") @@ -78,7 +77,8 @@ case class Transfer(from:String, to:String, amount:Int) ctx.api.setVal(data.to,dto + data.amount) val t2 = System.currentTimeMillis() val s2 = s"setval end:${ctx.t.id} " + df.format(t2) - new ActionResult(1, s1+"\n"+s2) + print(s1+"\n"+s2) + null } /** * 根据action,找到对应的method,并将传入的json字符串parse为method需要的传入参数 diff --git a/src/main/scala/rep/sc/tpl/SupplyTPL.scala b/src/main/scala/rep/sc/tpl/SupplyTPL.scala index fd9d5ee5..9d793152 100644 --- a/src/main/scala/rep/sc/tpl/SupplyTPL.scala +++ b/src/main/scala/rep/sc/tpl/SupplyTPL.scala @@ -49,13 +49,13 @@ class SupplyTPL extends IContract { * 追加确认签名 TODO 逻辑实现 */ def confirmSign(ctx: ContractContext, data:IPTConfirm ):ActionResult={ - ActionResult(1) + null } /** * 取消追加确认签名 TODO 逻辑实现 */ def cancelSign(ctx: ContractContext, data:IPTConfirm ):ActionResult={ - ActionResult(1) + null } /** @@ -65,7 +65,7 @@ class SupplyTPL extends IContract { * @return */ def SignUp(ctx: ContractContext, data:Map[String,String]):ActionResult = { - ActionResult(1) + null } /** @@ -77,7 +77,7 @@ class SupplyTPL extends IContract { //签约输入持久化,默认的类型转换无法胜任,以json字符串形式持久化 ctx.api.setVal(sid, write(data)) ctx.api.setVal(pid, TPL.Share) - ActionResult(1) + null } def signFixed(ctx: ContractContext, data:IPTSignFixed ):ActionResult={ @@ -86,7 +86,7 @@ class SupplyTPL extends IContract { //签约输入持久化 ctx.api.setVal(sid, write(data)) ctx.api.setVal(pid, TPL.Fixed) - ActionResult(1) + null } /** @@ -110,7 +110,7 @@ class SupplyTPL extends IContract { } //返回分账计算结果 addToAccount(ctx, mr) - ActionResult(1) + null } /** diff --git a/src/main/scala/rep/sc/tpl/SupplyTPL2.scala b/src/main/scala/rep/sc/tpl/SupplyTPL2.scala index e275cafa..d8edca1d 100644 --- a/src/main/scala/rep/sc/tpl/SupplyTPL2.scala +++ b/src/main/scala/rep/sc/tpl/SupplyTPL2.scala @@ -49,13 +49,13 @@ class SupplyTPL2 extends IContract { * 追加确认签名 TODO 逻辑实现 */ def confirmSign(ctx: ContractContext, data:IPTConfirm ):ActionResult={ - ActionResult(1) + null } /** * 取消追加确认签名 TODO 逻辑实现 */ def cancelSign(ctx: ContractContext, data:IPTConfirm ):ActionResult={ - ActionResult(1) + null } /** @@ -65,7 +65,7 @@ class SupplyTPL2 extends IContract { * @return */ def SignUp(ctx: ContractContext, data:Map[String,String]):ActionResult = { - ActionResult(1) + null } /** @@ -77,7 +77,7 @@ class SupplyTPL2 extends IContract { //签约输入持久化,默认的类型转换无法胜任,以json字符串形式持久化 ctx.api.setVal(sid, write(data)) ctx.api.setVal(pid, TPL.Share) - ActionResult(1) + null } def signFixed(ctx: ContractContext, data:IPTSignFixed ):ActionResult={ @@ -86,7 +86,7 @@ class SupplyTPL2 extends IContract { //签约输入持久化 ctx.api.setVal(sid, write(data)) ctx.api.setVal(pid, TPL.Fixed) - ActionResult(1) + null } /** @@ -110,7 +110,7 @@ class SupplyTPL2 extends IContract { } //返回分账计算结果 addToAccount(ctx, mr) - ActionResult(1) + null } /** diff --git a/src/main/scala/rep/sc/tpl/SupplyTPL3.scala b/src/main/scala/rep/sc/tpl/SupplyTPL3.scala index 9747f4f3..ce6ac70d 100644 --- a/src/main/scala/rep/sc/tpl/SupplyTPL3.scala +++ b/src/main/scala/rep/sc/tpl/SupplyTPL3.scala @@ -49,13 +49,13 @@ class SupplyTPL3 extends IContract { * 追加确认签名 TODO 逻辑实现 */ def confirmSign(ctx: ContractContext, data:IPTConfirm ):ActionResult={ - ActionResult(1) + null } /** * 取消追加确认签名 TODO 逻辑实现 */ def cancelSign(ctx: ContractContext, data:IPTConfirm ):ActionResult={ - ActionResult(1) + null } /** @@ -65,7 +65,7 @@ class SupplyTPL3 extends IContract { * @return */ def SignUp(ctx: ContractContext, data:Map[String,String]):ActionResult = { - ActionResult(1) + null } /** @@ -77,7 +77,7 @@ class SupplyTPL3 extends IContract { //签约输入持久化,默认的类型转换无法胜任,以json字符串形式持久化 ctx.api.setVal(sid, write(data)) ctx.api.setVal(pid, TPL.Share) - ActionResult(1) + null } def signFixed(ctx: ContractContext, data:IPTSignFixed ):ActionResult={ @@ -86,7 +86,7 @@ class SupplyTPL3 extends IContract { //签约输入持久化 ctx.api.setVal(sid, write(data)) ctx.api.setVal(pid, TPL.Fixed) - ActionResult(1) + null } /** @@ -110,7 +110,7 @@ class SupplyTPL3 extends IContract { } //返回分账计算结果 addToAccount(ctx, mr) - ActionResult(1) + null } /** diff --git a/src/test/scala/rep/sc/SandboxSpec.scala b/src/test/scala/rep/sc/SandboxSpec.scala index 0848dfdb..95ae56f1 100644 --- a/src/test/scala/rep/sc/SandboxSpec.scala +++ b/src/test/scala/rep/sc/SandboxSpec.scala @@ -83,7 +83,7 @@ class SandboxSpec(_system: ActorSystem) Transfer("121000005l35120456", "12110107bi45jh675g", 5), Transfer("121000005l35120456", "12110107bi45jh675g0", 5), Transfer("121000005l35120456", "12110107bi45jh675g", 500)) - val rcs = Array(1, -2 , -3) + val rcs = Array(None, "目标账户不存在", "余额不足") val signer = Signer("node2", "12110107bi45jh675g", "13856789234", Seq("node2")) val cert = scala.io.Source.fromFile("jks/certs/12110107bi45jh675g.node2.cer") @@ -94,55 +94,62 @@ class SandboxSpec(_system: ActorSystem) val db = ImpDataAccess.GetDataAccess(sysName) val sandbox = system.actorOf(TransProcessor.props("sandbox", probe.ref)) - val cid2 = ChaincodeId(SystemProfile.getAccountChaincodeName,1) - val cid1 = ChaincodeId("ContractAssetsTPL",1) - //生成deploy交易 - val t1 = PeerHelper.createTransaction4Deploy(sysName,cid1 , - l1, "",5000, rep.protos.peer.ChaincodeDeploy.CodeType.CODE_SCALA) + // 该处由于ContractAssetsTPL中判断用的ChainCodeIdName是用的系统设置,因此现在暂定为系统设置的 + val cid1 = ChaincodeId(SystemProfile.getAccountChaincodeName,1) + val cid2 = ChaincodeId("ContractCert",1) - val msg_send1 = DoTransaction(t1, "api_"+t1.id) + //生成deploy交易 + // 资产管理合约 + val t1 = PeerHelper.createTransaction4Deploy(sysName,cid1 , l1, + "",5000, rep.protos.peer.ChaincodeDeploy.CodeType.CODE_SCALA) + + val msg_send1 = DoTransaction(t1, "dbnumber") probe.send(sandbox, msg_send1) val msg_recv1 = probe.expectMsgType[Sandbox.DoTransactionResult](1000.seconds) - msg_recv1.r.code should be (1) + msg_recv1.err.isEmpty should be (true) - val t2 = PeerHelper.createTransaction4Deploy(sysName,cid2, - l2, "",5000, rep.protos.peer.ChaincodeDeploy.CodeType.CODE_SCALA) - - val msg_send2 = DoTransaction(t2, "api_"+t2.id) + // 账户管理合约 + val t2 = PeerHelper.createTransaction4Deploy(sysName,cid2, l2, + "",5000, rep.protos.peer.ChaincodeDeploy.CodeType.CODE_SCALA) + val msg_send2 = DoTransaction(t2, "dbnumber") probe.send(sandbox, msg_send2) // 生成invoke交易 // 注册账户 val t3 = PeerHelper.createTransaction4Invoke(sysName,cid2, ACTION.SignUpSigner, Seq(write(signer))) - val msg_send3 = DoTransaction(t3, "api_"+t3.id) + val msg_send3 = DoTransaction(t3, "dbnumber") probe.send(sandbox, msg_send3) + //deploy紧接invoke测试 val msg_recv2 = probe.expectMsgType[Sandbox.DoTransactionResult](1000.seconds) - msg_recv2.r.code should be (1) + msg_recv2.err.isEmpty should be (true) val msg_recv3 = probe.expectMsgType[Sandbox.DoTransactionResult](1000.seconds) - msg_recv3.r.code should be (1) + msg_recv3.err should be (None) // 注册证书 val t4 = PeerHelper.createTransaction4Invoke(sysName,cid2, ACTION.SignUpCert, Seq(writePretty(certinfo))) - val msg_send4 = DoTransaction(t4, "api_"+t4.id) + val msg_send4 = DoTransaction(t4, "dbnumber") probe.send(sandbox, msg_send4) val msg_recv4 = probe.expectMsgType[Sandbox.DoTransactionResult](1000.seconds) - msg_recv4.r.code should be (1) + msg_recv4.err should be (None) //生成invoke交易 val t5 = PeerHelper.createTransaction4Invoke(sysName,cid1, ACTION.set, Seq(sms)) - val msg_send5 = DoTransaction(t5, "api_"+t5.id) + val msg_send5 = DoTransaction(t5, "dbnumber") probe.send(sandbox, msg_send5) val msg_recv5 = probe.expectMsgType[Sandbox.DoTransactionResult](1000.seconds) - msg_recv5.r.code should be (1) + msg_recv5.err should be (None) for (i <- 0 until tcs.length){ val t6 = PeerHelper.createTransaction4Invoke(sysName, cid1, ACTION.transfer, Seq(write(tcs(i)))) - val msg_send6 = DoTransaction(t6, "api_"+t6.id) + val msg_send6 = DoTransaction(t6, "dbnumber") probe.send(sandbox, msg_send6) val msg_recv6 = probe.expectMsgType[Sandbox.DoTransactionResult](1000.seconds) - msg_recv6.r.code should be (rcs(i)) + if (msg_recv6.err.isEmpty && i == 0) + msg_recv6.err should be (rcs(0)) + else + msg_recv6.err.get.cause.getMessage should be (rcs(i)) } } } diff --git a/src/test/scala/rep/sc/StateSpec.scala b/src/test/scala/rep/sc/StateSpec.scala index 618ab00d..63176f39 100644 --- a/src/test/scala/rep/sc/StateSpec.scala +++ b/src/test/scala/rep/sc/StateSpec.scala @@ -82,7 +82,7 @@ class StateSpec(_system: ActorSystem) Transfer("121000005l35120456", "12110107bi45jh675g", 5), Transfer("121000005l35120456", "12110107bi45jh675g0", 5), Transfer("121000005l35120456", "12110107bi45jh675g", 500)) - val rcs = Array(1, -2 , -3) + val rcs = Array(None, "目标账户不存在", "余额不足") val signer = Signer("node2", "12110107bi45jh675g", "13856789234", Seq("node2")) val cert = scala.io.Source.fromFile("jks/certs/12110107bi45jh675g.node2.cer") @@ -99,92 +99,98 @@ class StateSpec(_system: ActorSystem) val t1 = PeerHelper.createTransaction4Deploy(sysName,cid1 , l1, "",5000, rep.protos.peer.ChaincodeDeploy.CodeType.CODE_SCALA) - val msg_send1 = DoTransaction(t1, "api_"+t1.id) + val msg_send1 = DoTransaction(t1, "dbnumber") probe.send(sandbox, msg_send1) val msg_recv1 = probe.expectMsgType[Sandbox.DoTransactionResult](1000.seconds) - msg_recv1.r.code should be (1) + msg_recv1.err.isEmpty should be (true) val t2 = PeerHelper.createTransaction4Deploy(sysName,cid2, l2, "",5000, rep.protos.peer.ChaincodeDeploy.CodeType.CODE_SCALA) - val msg_send2 = DoTransaction(t2, "api_"+t2.id) + val msg_send2 = DoTransaction(t2, "dbnumber") probe.send(sandbox, msg_send2) val msg_recv2 = probe.expectMsgType[Sandbox.DoTransactionResult](1000.seconds) - msg_recv2.r.code should be (1) + msg_recv2.err.isEmpty should be (true) // 生成invoke交易 // 注册账户 val t3 = PeerHelper.createTransaction4Invoke(sysName,cid2, ACTION.SignUpSigner, Seq(write(signer))) - val msg_send3 = DoTransaction(t3, "api_"+t3.id) + val msg_send3 = DoTransaction(t3, "dbnumber") probe.send(sandbox, msg_send3) val msg_recv3 = probe.expectMsgType[Sandbox.DoTransactionResult](1000.seconds) - msg_recv3.r.code should be (1) + msg_recv3.err.isEmpty should be (true) // 注册证书 val t4 = PeerHelper.createTransaction4Invoke(sysName,cid2, ACTION.SignUpCert, Seq(writePretty(certinfo))) - val msg_send4 = DoTransaction(t4, "api_"+t4.id) + val msg_send4 = DoTransaction(t4, "dbnumber") probe.send(sandbox, msg_send4) val msg_recv4 = probe.expectMsgType[Sandbox.DoTransactionResult](1000.seconds) - msg_recv4.r.code should be (1) + msg_recv4.err.isEmpty should be (true) //生成invoke交易 val t5 = PeerHelper.createTransaction4Invoke(sysName,cid1, ACTION.set, Seq(sms)) - val msg_send5 = DoTransaction(t5, "api_"+t5.id) + val msg_send5 = DoTransaction(t5, "dbnumber") probe.send(sandbox, msg_send5) val msg_recv5 = probe.expectMsgType[Sandbox.DoTransactionResult](1000.seconds) - msg_recv5.r.code should be (1) + msg_recv5.err.isEmpty should be (true) //正常调用 for (i <- 0 until 1){ val t6 = PeerHelper.createTransaction4Invoke(sysName, cid1, ACTION.transfer, Seq(write(tcs(i)))) - val msg_send6 = DoTransaction(t6, "api_"+t6.id) + val msg_send6 = DoTransaction(t6, "dbnumber") probe.send(sandbox, msg_send6) val msg_recv6 = probe.expectMsgType[Sandbox.DoTransactionResult](1000.seconds) - msg_recv6.r.code should be (rcs(i)) + if (msg_recv6.err.isEmpty && i == 0) + msg_recv6.err should be (rcs(0)) + else + msg_recv6.err.get.cause.getMessage should be (rcs(i)) } //非部署者无法禁用合约 val sysName2 = "12110107bi45jh675g.node2" SignTool.loadPrivateKey("12110107bi45jh675g.node2", "123", "jks/12110107bi45jh675g.node2.jks") var t = PeerHelper.createTransaction4State(sysName2, cid1,false) - var msg_send = DoTransaction(t, "api_"+t.id) + var msg_send = DoTransaction(t, "dbnumber") probe.send(sandbox, msg_send) var msg_recv = probe.expectMsgType[Sandbox.DoTransactionResult](1000.seconds) msg_recv.err.get.cause.getMessage should be (TransProcessor.ERR_CODER) //部署者可以禁用合约 t = PeerHelper.createTransaction4State(sysName, cid1,false) - msg_send = DoTransaction(t, "api_"+t.id) + msg_send = DoTransaction(t, "dbnumber") probe.send(sandbox, msg_send) msg_recv = probe.expectMsgType[Sandbox.DoTransactionResult](1000.seconds) - msg_recv4.r.code should be (1) + msg_recv4.err.isEmpty should be (true) //禁用合约之后,无法Invoke合约 for (i <- 0 until 1){ val t6 = PeerHelper.createTransaction4Invoke(sysName, cid1, ACTION.transfer, Seq(write(tcs(i)))) - val msg_send6 = DoTransaction(t6, "api_"+t6.id) + val msg_send6 = DoTransaction(t6, "dbnumber") probe.send(sandbox, msg_send6) val msg_recv6 = probe.expectMsgType[Sandbox.DoTransactionResult](1000.seconds) msg_recv6.err.get.cause.getMessage should be (TransProcessor.ERR_DISABLE_CID) } //非部署者无法启用合约 t = PeerHelper.createTransaction4State(sysName2, cid1,true) - msg_send = DoTransaction(t, "api_"+t.id) + msg_send = DoTransaction(t, "dbnumber") probe.send(sandbox, msg_send) msg_recv = probe.expectMsgType[Sandbox.DoTransactionResult](1000.seconds) msg_recv.err.get.cause.getMessage should be (TransProcessor.ERR_CODER) //部署者可以启用合约 t = PeerHelper.createTransaction4State(sysName, cid1,true) - msg_send = DoTransaction(t, "api_"+t.id) + msg_send = DoTransaction(t, "dbnumber") probe.send(sandbox, msg_send) msg_recv = probe.expectMsgType[Sandbox.DoTransactionResult](1000.seconds) - msg_recv4.r.code should be (1) + msg_recv4.err.isEmpty should be (true) //启用合约之后,可以Invoke合约 for (i <- 0 until 1){ val t6 = PeerHelper.createTransaction4Invoke(sysName, cid1, ACTION.transfer, Seq(write(tcs(i)))) - val msg_send6 = DoTransaction(t6, "api_"+t6.id) + val msg_send6 = DoTransaction(t6, "dbnumber") probe.send(sandbox, msg_send6) val msg_recv6 = probe.expectMsgType[Sandbox.DoTransactionResult](1000.seconds) - msg_recv6.r.code should be (rcs(i)) + if (msg_recv6.err.isEmpty && i == 0) + msg_recv6.err should be (rcs(0)) + else + msg_recv6.err.get.cause.getMessage should be (rcs(i)) } } } diff --git a/src/test/scala/rep/sc/SupplySpec.scala b/src/test/scala/rep/sc/SupplySpec.scala index a617fe98..febb3e9a 100644 --- a/src/test/scala/rep/sc/SupplySpec.scala +++ b/src/test/scala/rep/sc/SupplySpec.scala @@ -113,7 +113,7 @@ class SupplySpec(_system: ActorSystem) val t1 = PeerHelper.createTransaction4Deploy(sysName, cid, l1, "",5000, rep.protos.peer.ChaincodeDeploy.CodeType.CODE_SCALA) - val msg_send1 = new DoTransaction(t1, "api_"+t1.id) + val msg_send1 = new DoTransaction(t1, "dbnumber") probe.send(sandbox, msg_send1) val msg_recv1 = probe.expectMsgType[Sandbox.DoTransactionResult](1000.seconds) val ol1 = msg_recv1.ol @@ -123,12 +123,12 @@ class SupplySpec(_system: ActorSystem) //初始化资产 val t2 = PeerHelper.createTransaction4Invoke(sysName,cid, ACTION.SignFixed, Seq(l2)) - val msg_send2 = new DoTransaction(t2, "api_"+t2.id) + val msg_send2 = new DoTransaction(t2, "dbnumber") probe.send(sandbox, msg_send2) val msg_recv2 = probe.expectMsgType[Sandbox.DoTransactionResult](1000.seconds) val t3 = PeerHelper.createTransaction4Invoke(sysName, cid, ACTION.SignShare, Seq(l3)) - val msg_send3 = new DoTransaction(t3, "api_"+t3.id) + val msg_send3 = new DoTransaction(t3, "dbnumber") probe.send(sandbox, msg_send3) val msg_recv3 = probe.expectMsgType[Sandbox.DoTransactionResult](1000.seconds) @@ -139,7 +139,7 @@ class SupplySpec(_system: ActorSystem) val ipt4 = new IPTSplit(account_sales1,product_id,el) val l4 = write(ipt4) val t4 = PeerHelper.createTransaction4Invoke(sysName, cid, ACTION.Split, Seq(l4)) - val msg_send4 = new DoTransaction(t4, "api_"+t4.id) + val msg_send4 = new DoTransaction(t4, "dbnumber") probe.send(sandbox, msg_send4) val msg_recv4 = probe.expectMsgType[Sandbox.DoTransactionResult](1000.seconds) @@ -162,7 +162,7 @@ class SupplySpec(_system: ActorSystem) val ipt4 = new IPTSplit(account_sales2,product_id,el) val l4 = write(ipt4) val t4 = PeerHelper.createTransaction4Invoke(sysName, cid, ACTION.Split, Seq(l4)) - val msg_send4 = new DoTransaction(t4, "api_"+t4.id) + val msg_send4 = new DoTransaction(t4, "dbnumber") probe.send(sandbox, msg_send4) val msg_recv4 = probe.expectMsgType[Sandbox.DoTransactionResult](1000.seconds) diff --git a/src/test/scala/rep/sc/SupplySpec2.scala b/src/test/scala/rep/sc/SupplySpec2.scala index 9cfdf4bb..6576172b 100644 --- a/src/test/scala/rep/sc/SupplySpec2.scala +++ b/src/test/scala/rep/sc/SupplySpec2.scala @@ -116,7 +116,7 @@ class SupplySpec2(_system: ActorSystem) val t1 = PeerHelper.createTransaction4Deploy(sysName, cid, l1, "",5000, rep.protos.peer.ChaincodeDeploy.CodeType.CODE_SCALA) - val msg_send1 = new DoTransaction(t1, "api_"+t1.id) + val msg_send1 = new DoTransaction(t1, "dbnumber") probe.send(sandbox, msg_send1) val msg_recv1 = probe.expectMsgType[Sandbox.DoTransactionResult](1000.seconds) val ol1 = msg_recv1.ol @@ -126,14 +126,14 @@ class SupplySpec2(_system: ActorSystem) //初始化资产 val t2 = PeerHelper.createTransaction4Invoke(sysName,cid, ACTION.SignFixed, Seq(l2)) - val msg_send2 = new DoTransaction(t2, "api_"+t2.id) + val msg_send2 = new DoTransaction(t2, "dbnumber") probe.send(sandbox, msg_send2) val msg_recv2 = probe.expectMsgType[Sandbox.DoTransactionResult](1000.seconds) //由于版本1支持SignFixed 分账方法,因此能够正确处理 - msg_recv2.r.code should be (1) + msg_recv2.err should be (None) var t = PeerHelper.createTransaction4Invoke(sysName, cid, ACTION.SignShare, Seq(l3)) - var msg_send = new DoTransaction(t, "api_"+t.id) + var msg_send = new DoTransaction(t, "dbnumber") probe.send(sandbox, msg_send) var msg_recv = probe.expectMsgType[Sandbox.DoTransactionResult](1000.seconds) //由于版本1不支持SignShare 分账方法,因此无法正确处理 @@ -144,17 +144,17 @@ class SupplySpec2(_system: ActorSystem) val cid2 = new ChaincodeId("Supply",2) t = PeerHelper.createTransaction4Deploy(sysName, cid2, l7, "",5000, rep.protos.peer.ChaincodeDeploy.CodeType.CODE_SCALA) - msg_send = new DoTransaction(t, "api_"+t.id) + msg_send = new DoTransaction(t, "dbnumber") probe.send(sandbox, msg_send) msg_recv = probe.expectMsgType[Sandbox.DoTransactionResult](1000.seconds) - msg_recv.r.code should be (1) + msg_recv.err should be (None) t = PeerHelper.createTransaction4Invoke(sysName, cid2, ACTION.SignShare, Seq(l3)) - msg_send = new DoTransaction(t, "api_"+t.id) + msg_send = new DoTransaction(t, "dbnumber") probe.send(sandbox, msg_send) msg_recv = probe.expectMsgType[Sandbox.DoTransactionResult](1000.seconds) //由于版本2支持SignShare 分账方法,因此正确处理 - msg_recv.r.code should be (1) + msg_recv.err.isEmpty should be (true) //测试各种金额下的分账结果 @@ -164,7 +164,7 @@ class SupplySpec2(_system: ActorSystem) val ipt4 = new IPTSplit(account_sales1,product_id,el) val l4 = write(ipt4) val t4 = PeerHelper.createTransaction4Invoke(sysName, cid, ACTION.Split, Seq(l4)) - val msg_send4 = new DoTransaction(t4, "api_"+t4.id) + val msg_send4 = new DoTransaction(t4, "dbnumber") probe.send(sandbox, msg_send4) val msg_recv4 = probe.expectMsgType[Sandbox.DoTransactionResult](1000.seconds) @@ -187,7 +187,7 @@ class SupplySpec2(_system: ActorSystem) val ipt4 = new IPTSplit(account_sales2,product_id,el) val l4 = write(ipt4) val t4 = PeerHelper.createTransaction4Invoke(sysName, cid2, ACTION.Split, Seq(l4)) - val msg_send4 = new DoTransaction(t4, "api_"+t4.id) + val msg_send4 = new DoTransaction(t4, "dbnumber") probe.send(sandbox, msg_send4) val msg_recv4 = probe.expectMsgType[Sandbox.DoTransactionResult](1000.seconds) diff --git a/src/test/scala/rep/sc/TransferSpec.scala b/src/test/scala/rep/sc/TransferSpec.scala index a4ab9046..11faf078 100644 --- a/src/test/scala/rep/sc/TransferSpec.scala +++ b/src/test/scala/rep/sc/TransferSpec.scala @@ -83,7 +83,7 @@ class TransferSpec(_system: ActorSystem) Transfer("121000005l35120456", "12110107bi45jh675g", 5), Transfer("121000005l35120456", "12110107bi45jh675g0", 5), Transfer("121000005l35120456", "12110107bi45jh675g", 500)) - val rcs = Array(1, -2 , -3) + val rcs = Array(None, "目标账户不存在", "余额不足") val signer = Signer("node2", "12110107bi45jh675g", "13856789234", Seq("node2")) val cert = scala.io.Source.fromFile("jks/certs/12110107bi45jh675g.node2.cer") @@ -100,48 +100,51 @@ class TransferSpec(_system: ActorSystem) val t1 = PeerHelper.createTransaction4Deploy(sysName,cid1 , l1, "",5000, rep.protos.peer.ChaincodeDeploy.CodeType.CODE_SCALA) - val msg_send1 = DoTransaction(t1, "api_"+t1.id) + val msg_send1 = DoTransaction(t1, "dbnumber") probe.send(sandbox, msg_send1) val msg_recv1 = probe.expectMsgType[Sandbox.DoTransactionResult](1000.seconds) - msg_recv1.r.code should be (1) + msg_recv1.err.isEmpty should be (true) val t2 = PeerHelper.createTransaction4Deploy(sysName,cid2, l2, "",5000, rep.protos.peer.ChaincodeDeploy.CodeType.CODE_SCALA) - val msg_send2 = DoTransaction(t2, "api_"+t2.id) + val msg_send2 = DoTransaction(t2, "dbnumber") probe.send(sandbox, msg_send2) val msg_recv2 = probe.expectMsgType[Sandbox.DoTransactionResult](1000.seconds) - msg_recv2.r.code should be (1) + msg_recv2.err.isEmpty should be (true) // 生成invoke交易 // 注册账户 val t3 = PeerHelper.createTransaction4Invoke(sysName,cid2, ACTION.SignUpSigner, Seq(write(signer))) - val msg_send3 = DoTransaction(t3, "api_"+t3.id) + val msg_send3 = DoTransaction(t3, "dbnumber") probe.send(sandbox, msg_send3) val msg_recv3 = probe.expectMsgType[Sandbox.DoTransactionResult](1000.seconds) - msg_recv3.r.code should be (1) + msg_recv3.err.isEmpty should be (true) // 注册证书 val t4 = PeerHelper.createTransaction4Invoke(sysName,cid2, ACTION.SignUpCert, Seq(writePretty(certinfo))) - val msg_send4 = DoTransaction(t4, "api_"+t4.id) + val msg_send4 = DoTransaction(t4, "dbnumber") probe.send(sandbox, msg_send4) val msg_recv4 = probe.expectMsgType[Sandbox.DoTransactionResult](1000.seconds) - msg_recv4.r.code should be (1) + msg_recv4.err.isEmpty should be (true) //生成invoke交易 val t5 = PeerHelper.createTransaction4Invoke(sysName,cid1, ACTION.set, Seq(sms)) - val msg_send5 = DoTransaction(t5, "api_"+t5.id) + val msg_send5 = DoTransaction(t5, "dbnumber") probe.send(sandbox, msg_send5) val msg_recv5 = probe.expectMsgType[Sandbox.DoTransactionResult](1000.seconds) - msg_recv5.r.code should be (1) + msg_recv5.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(t6, "api_"+t6.id) + val msg_send6 = DoTransaction(t6, "dbnumber") probe.send(sandbox, msg_send6) val msg_recv6 = probe.expectMsgType[Sandbox.DoTransactionResult](1000.seconds) - msg_recv6.r.code should be (rcs(i)) + if (msg_recv6.err.isEmpty && i == 0) + msg_recv6.err should be (rcs(0)) + else + msg_recv6.err.get.cause.getMessage should be (rcs(i)) } } } diff --git a/src/test/scala/rep/sc/TransferSpec2.scala b/src/test/scala/rep/sc/TransferSpec2.scala index a8fd54e7..47967ed0 100644 --- a/src/test/scala/rep/sc/TransferSpec2.scala +++ b/src/test/scala/rep/sc/TransferSpec2.scala @@ -70,7 +70,7 @@ class TransferSpec2(_system: ActorSystem) Transfer("121000005l35120456", "12110107bi45jh675g", 5), Transfer("121000005l35120456", "12110107bi45jh675g", 3), Transfer("121000005l35120456", "12110107bi45jh675g", 2)) - val rcs = Array(1, 1 , 1) + 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") @@ -87,51 +87,52 @@ class TransferSpec2(_system: ActorSystem) val t1 = PeerHelper.createTransaction4Deploy(sysName,cid1 , l1, "",5000, rep.protos.peer.ChaincodeDeploy.CodeType.CODE_SCALA) - val msg_send1 = DoTransaction(t1, "api_"+t1.id) + val msg_send1 = DoTransaction(t1, "dbnumber") probe.send(sandbox, msg_send1) val msg_recv1 = probe.expectMsgType[Sandbox.DoTransactionResult](1000.seconds) - msg_recv1.r.code should be (1) + msg_recv1.err.isEmpty should be (true) val t2 = PeerHelper.createTransaction4Deploy(sysName,cid2, l2, "",5000, rep.protos.peer.ChaincodeDeploy.CodeType.CODE_SCALA) - val msg_send2 = DoTransaction(t2, "api_"+t2.id) + val msg_send2 = DoTransaction(t2, "dbnumber") probe.send(sandbox, msg_send2) val msg_recv2 = probe.expectMsgType[Sandbox.DoTransactionResult](1000.seconds) - msg_recv2.r.code should be (1) + msg_recv2.err.isEmpty should be (true) // 生成invoke交易 // 注册账户 val t3 = PeerHelper.createTransaction4Invoke(sysName,cid2, ACTION.SignUpSigner, Seq(write(signer))) - val msg_send3 = DoTransaction(t3, "api_"+t3.id) + val msg_send3 = DoTransaction(t3, "dbnumber") probe.send(sandbox, msg_send3) val msg_recv3 = probe.expectMsgType[Sandbox.DoTransactionResult](1000.seconds) - msg_recv3.r.code should be (1) + msg_recv3.err.isEmpty should be (true) // 注册证书 val t4 = PeerHelper.createTransaction4Invoke(sysName,cid2, ACTION.SignUpCert, Seq(writePretty(certinfo))) - val msg_send4 = DoTransaction(t4, "api_"+t4.id) + val msg_send4 = DoTransaction(t4, "dbnumber") probe.send(sandbox, msg_send4) val msg_recv4 = probe.expectMsgType[Sandbox.DoTransactionResult](1000.seconds) - msg_recv4.r.code should be (1) + msg_recv4.err.isEmpty should be (true) //生成invoke交易 val t5 = PeerHelper.createTransaction4Invoke(sysName,cid1, ACTION.set, Seq(sms)) - val msg_send5 = DoTransaction(t5, "api_"+t5.id) + val msg_send5 = DoTransaction(t5, "dbnumber") probe.send(sandbox, msg_send5) val msg_recv5 = probe.expectMsgType[Sandbox.DoTransactionResult](1000.seconds) - msg_recv5.r.code should be (1) + msg_recv5.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(t6, "api_"+t6.id) + val msg_send6 = DoTransaction(t6, "dbnumber") probe.send(sandbox, msg_send6) } for (i <- 0 until tcs.length){ val msg_recv6 = probe.expectMsgType[Sandbox.DoTransactionResult](1000.seconds) - msg_recv6.r.code should be (rcs(i)) - println(msg_recv6.r.reason) + msg_recv6.err.isEmpty should be (true) +// println(msg_recv6.r.reason) + msg_recv6.r shouldBe(null) } } } diff --git a/src/test/scala/rep/sc/TransferSpec_Legal.scala b/src/test/scala/rep/sc/TransferSpec_Legal.scala index 32e07976..5a64f3a8 100644 --- a/src/test/scala/rep/sc/TransferSpec_Legal.scala +++ b/src/test/scala/rep/sc/TransferSpec_Legal.scala @@ -75,43 +75,43 @@ class TransferSpec_Legal(_system: ActorSystem) val sandbox = system.actorOf(TransProcessor.props("sandbox", probe.ref)) val cid2 = ChaincodeId(SystemProfile.getAccountChaincodeName,1) - val cid1 = ChaincodeId("ContractAssetsTPL",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(t1, "api_"+t1.id) + val msg_send1 = DoTransaction(t1, "dbnumber") probe.send(sandbox, msg_send1) val msg_recv1 = probe.expectMsgType[Sandbox.DoTransactionResult](1000.seconds) - msg_recv1.r.code should be (1) + msg_recv1.err should be (None) val t2 = PeerHelper.createTransaction4Deploy(sysName,cid2, l2, "",5000, rep.protos.peer.ChaincodeDeploy.CodeType.CODE_SCALA) - val msg_send2 = DoTransaction(t2, "api_"+t2.id) + val msg_send2 = DoTransaction(t2, "dbnumber") probe.send(sandbox, msg_send2) val msg_recv2 = probe.expectMsgType[Sandbox.DoTransactionResult](1000.seconds) - msg_recv2.r.code should be (1) + msg_recv2.err.isEmpty should be (true) // 生成invoke交易 // 注册账户 val t3 = PeerHelper.createTransaction4Invoke(sysName,cid2, ACTION.SignUpSigner, Seq(toJson(signer))) - val msg_send3 = DoTransaction(t3, "api_"+t3.id) + val msg_send3 = DoTransaction(t3, "dbnumber") probe.send(sandbox, msg_send3) val msg_recv3 = probe.expectMsgType[Sandbox.DoTransactionResult](1000.seconds) - msg_recv3.r.code should be (1) + msg_recv3.err.isEmpty should be (true) // 注册证书 val t4 = PeerHelper.createTransaction4Invoke(sysName,cid2, ACTION.SignUpCert, Seq(toJson(certinfo))) - val msg_send4 = DoTransaction(t4, "api_"+t4.id) + val msg_send4 = DoTransaction(t4, "dbnumber") probe.send(sandbox, msg_send4) val msg_recv4 = probe.expectMsgType[Sandbox.DoTransactionResult](1000.seconds) - msg_recv4.r.code should be (1) + msg_recv4.err.isEmpty should be (true) //生成invoke交易 val t5 = PeerHelper.createTransaction4Invoke(sysName,cid1, ACTION.set, Seq(sms)) - val msg_send5 = DoTransaction(t5, "api_"+t5.id) + val msg_send5 = DoTransaction(t5, "dbnumber") probe.send(sandbox, msg_send5) val msg_recv5 = probe.expectMsgType[Sandbox.DoTransactionResult](1000.seconds) msg_recv5.r.code should be (1) @@ -119,7 +119,7 @@ class TransferSpec_Legal(_system: ActorSystem) //获得提醒文本 var p = Transfer("121000005l35120456", "12110107bi45jh675g", 5,null) var t = PeerHelper.createTransaction4Invoke(sysName, cid1, ACTION.transfer, Seq(toJson(p))) - var msg_send = DoTransaction(t, "api_"+t.id) + var msg_send = DoTransaction(t, "dbnumber") probe.send(sandbox, msg_send) var msg_recv = probe.expectMsgType[Sandbox.DoTransactionResult](1000.seconds) msg_recv.r.code should be (2) @@ -129,7 +129,7 @@ class TransferSpec_Legal(_system: ActorSystem) println(remind) p = Transfer("121000005l35120456", "12110107bi45jh675g", 5,remind ) t = PeerHelper.createTransaction4Invoke(sysName, cid1, ACTION.transfer, Seq(toJson(p))) - msg_send = DoTransaction(t, "api_"+t.id) + msg_send = DoTransaction(t, "dbnumber") probe.send(sandbox, msg_send) msg_recv = probe.expectMsgType[Sandbox.DoTransactionResult](1000.seconds) msg_recv.r.code should be (1)