Commit 0d5f2ac5 authored by 袁邓@五瓣科技's avatar 袁邓@五瓣科技

完善测试用例

parent cf385a85
...@@ -72,7 +72,7 @@ func getCouponsByAddressApi(args []string, stub shim.ChaincodeStubInterface) pb. ...@@ -72,7 +72,7 @@ func getCouponsByAddressApi(args []string, stub shim.ChaincodeStubInterface) pb.
if err != nil{ if err != nil{
return shim.Error(err.Error()) return shim.Error(err.Error())
} }
if strings.Compare(utxo.Status,"2") != 0{ if strings.Compare(utxo.Status,"3") != 0{
return shim.Error("Query for exceptions, UTXO status exceptions") return shim.Error("Query for exceptions, UTXO status exceptions")
} }
utxoByte,_ :=json.Marshal(utxo) utxoByte,_ :=json.Marshal(utxo)
......
...@@ -168,8 +168,8 @@ func TestParse(t *testing.T){ ...@@ -168,8 +168,8 @@ func TestParse(t *testing.T){
} }
} }
var userPubHex = `04e6496ec8db3af69f1efbe12dc6e6c28402d2ff928e69160040cd4e293402d224785cf12912635306a65dc08f2dc840daa71cc30049fb77d3a95480f09d011c7d` var userPubHex = `7b227075625f73657269616c697a65223a2242484f2f74413243544464614c46575054632b326e51577a504f6e663134466e79776b55694c6e44556f38466f4d446b453048724341355166736f76766b6a374e35474d5076644b64736d4273646c2f2f4b4643356b4d3d222c227075625f74797065223a32317d`
var usePrivHex = `7b22707269765f73657269616c697a65223a223453384363544476374a4862767867747076516969653961506a784e756c316b46324431496850765574553d222c22707269765f74797065223a32317d` var usePrivHex = `7b22707269765f73657269616c697a65223a2277526e35323350712f547064675673437a6349384956386e41446453637a3861514f4e2b4d51676a4b66413d222c22707269765f74797065223a32317d`
func TestCreateTx(t *testing.T){ func TestCreateTx(t *testing.T){
//coupons:= &Coupons{ //coupons:= &Coupons{
// CoupId:"c1", // CoupId:"c1",
...@@ -232,16 +232,28 @@ func TestCreateTx(t *testing.T){ ...@@ -232,16 +232,28 @@ func TestCreateTx(t *testing.T){
} }
var createCouponsSign =`e99c297f03c1f3b5bbf1602dc15ff61bb05fb2617abc1e29f28f9d59c8445e39d19d3897827a85567032a7e0e711e20c6092e6e733a3a886de87ab3bf6b9e671` var createCouponsSign =`e99c297f03c1f3b5bbf1602dc15ff61bb05fb2617abc1e29f28f9d59c8445e39d19d3897827a85567032a7e0e711e20c6092e6e733a3a886de87ab3bf6b9e671`
var createCouponsSign1 =`5af9620fdd58f5fc43833b180bbc912c29f8ea8c2a8f3a52f5ae807f098545d592ea4b2a003845edc9a6af8c6b58cf0d6d55bc8a705ec7a464056287f3c75c62`
var createCouponsDate1 =`{"value":"{\"coup_id\":\"c11\",\"issue_org_id\":\"1\",\"coup_type\":\"\",\"coup_valid\":\"\",\"coup_available_time\":\"\",\"coup_description\":\"\",\"coup_quantity\":100,\"coup_amount\":0,\"coup_discount\":0,\"coup_total_amount\":0,\"floor_amount\":0,\"use_merchats\":[\"111\"],\"use_merchants_type\":null,\"extensions\":null}","fromAddress":"","toAddress":"utxo1","toPublicKey":"1"}`
var createCouponsDate =`{"value":"{\"coup_id\":\"c1\",\"issue_org_id\":\"1\",\"coup_type\":\"\",\"coup_valid\":\"\",\"coup_available_time\":\"\",\"coup_description\":\"\",\"coup_quantity\":100,\"coup_amount\":0,\"coup_discount\":0,\"coup_total_amount\":0,\"floor_amount\":0,\"use_merchats\":[\"111\"],\"use_merchants_type\":null,\"extensions\":null}","fromAddress":"","toAddress":"utxo1","toPublicKey":"1"}` var createCouponsDate =`{"value":"{\"coup_id\":\"c1\",\"issue_org_id\":\"1\",\"coup_type\":\"\",\"coup_valid\":\"\",\"coup_available_time\":\"\",\"coup_description\":\"\",\"coup_quantity\":100,\"coup_amount\":0,\"coup_discount\":0,\"coup_total_amount\":0,\"floor_amount\":0,\"use_merchats\":[\"111\"],\"use_merchants_type\":null,\"extensions\":null}","fromAddress":"","toAddress":"utxo1","toPublicKey":"1"}`
var disCouponsSign = `54063e3edce3905d44312a7e4038d9a06f819eae0991d04a4b8e944c721d716eaaab47befba449c2bf4e4634847daad3f2c4ed49ae80e50b4f051a1a8675cb99` var disCouponsSign = `54063e3edce3905d44312a7e4038d9a06f819eae0991d04a4b8e944c721d716eaaab47befba449c2bf4e4634847daad3f2c4ed49ae80e50b4f051a1a8675cb99`
var disCouponsSign1 = `54063e3edce3905d44312a7e4038d9a06f819eae0991d04a4b8e944c721d716eaaab47befba449c2bf4e4634847daad3f2c4ed49ae80e50b4f051a1a8675cb99`
var disCouponsDate = `{"value":"{\"amount\":99,\"did\":\"11\"}","fromAddress":"utxo1","toAddress":"utxo2","toPublicKey":"11"}` var disCouponsDate = `{"value":"{\"amount\":99,\"did\":\"11\"}","fromAddress":"utxo1","toAddress":"utxo2","toPublicKey":"11"}`
var ApplyCouponsSign = `7092dde322c376f5d43541f219ffe3234b8cea365a7e5aa49983865a36516e2c0e7b875cc5750e61b6a1bf3d22e0f004ae42d73aaad655fe972047b70ff91246` var ApplyCouponsSign = `384680b931d61d74f92dce95407f917455845c0c8d26826b87830d5b2851b5abf54e145f18e7c7e0f1c0c4febcaf059c6ae24a48953ea9bf1d192080e8916693`
var ApplyCouponsDate = `{"value":"{\"uid\":\"\",\"name\":\"\",\"number\":\"\",\"phone\":\"\",\"create_time\":\"0001-01-01T00:00:00Z\"}","fromAddress":"utxo2","toAddress":"utxo3","toPublicKey":"04e6496ec8db3af69f1efbe12dc6e6c28402d2ff928e69160040cd4e293402d224785cf12912635306a65dc08f2dc840daa71cc30049fb77d3a95480f09d011c7d"}` var ApplyCouponsDate = `{"value":"{\"uid\":\"\",\"name\":\"\",\"number\":\"\",\"phone\":\"\",\"create_time\":\"0001-01-01T00:00:00Z\"}","fromAddress":"utxo2","toAddress":"utxo3","toPublicKey":"7b227075625f73657269616c697a65223a2242484f2f74413243544464614c46575054632b326e51577a504f6e663134466e79776b55694c6e44556f38466f4d446b453048724341355166736f76766b6a374e35474d5076644b64736d4273646c2f2f4b4643356b4d3d222c227075625f74797065223a32317d"}`
var useCouponsSign = `2eb8f81b19a2e4c14d15c1736f8c9ea764e707ddb14a16c8a373e38e3000de3b7e62c56eac42241bdc739ad4ca52fc7d13c97a597e5c7e5993a845cc75a9f22d` var useCouponsSign = `64676e919d52bf33f79a1854d8f4b432b18d438941b4bc6d261293bee8f64a53bcce6dcd7b639d3dfb6cb4198b4af7f028aabdbdd321fc6b4ad458dc6b48c852`
var useCouponsDate = `{"value":"{\"orderSign\":\"eb12fd1922cdb15b8be9c43a685f342c455c8a44f9972d0c83761a760554f3cdee6e127378d1d3953aeed678e04d55d059be5f6ca65cb864310891626daf1336\",\"order\":\"订单信息\",\"algorithm\":1}","fromAddress":"utxo3","toAddress":"utxo4"}` var useCouponsDate = `{"value":"{\"orderSign\":\"cb272bf42428ae99322c924b83fc24dada62b2bd063dbe570e56d8fddfa9d10a6437c3ef2e4b8c187234729bbe4af0371ec774e1c69d2002a73dae62310204af\",\"order\":\"订单信息\",\"algorithm\":1}","fromAddress":"utxo3","toAddress":"utxo4"}`
var getCouponsSign = `ae4ed3d14343109d8c427eb472a1ea6d8ceb30d5262a6fe9fdf53ffaedee36a908c20e1756d137c51ada112924dc69e2c344e3bedad21bfb2ba4bbf115617ab1`
var getCouponsDate = `{"value":"{\"coup_id\":\"c1\"}"}`
var getUtxoSign = `d384e0d41d3264210e10471ba9d83a1608ead270382863151e180be87740cabe03cf42d3ee484b2c29127ec817fb0c9471df3ac24471a0fc970dcbea27f1775e`
var getUtxoInfo = `{"fromAddress":"utxo3"}`
var getUtxoSign1 = `232d69a60be346f65b011e9dfb0e98a211eb9592f90beaaf3d8e3c25897cf1c4f3b15d36e67d10d5fc3cdf5a5c831266ef3ba703ee7a4b11c4b87711b20e9678`
var getUtxoInfo1 = `{"fromAddress":"utxo2"}`
func TestCouponsFlow(t *testing.T){ func TestCouponsFlow(t *testing.T){
cc := new(CPSChainCode) cc := new(CPSChainCode)
...@@ -271,6 +283,16 @@ func TestCouponsFlow(t *testing.T){ ...@@ -271,6 +283,16 @@ func TestCouponsFlow(t *testing.T){
fmt.Println() fmt.Println()
responseByPutschema = stub.MockInvoke("invoke1",[][]byte{[]byte("createTx/createCoupons"), []byte("1"),[]byte(createCouponsDate),[]byte(createCouponsSign)}) responseByPutschema = stub.MockInvoke("invoke1",[][]byte{[]byte("createTx/createCoupons"), []byte("1"),[]byte(createCouponsDate),[]byte(createCouponsSign)})
fmt.Printf("Invoke status %d,message %s and payload %s\n",responseByPutschema.Status,responseByPutschema.Message,string(responseByPutschema.Payload)) fmt.Printf("Invoke status %d,message %s and payload %s\n",responseByPutschema.Status,responseByPutschema.Message,string(responseByPutschema.Payload))
fmt.Println("========================================测试错误的私钥签名============================================")
fmt.Println()
fmt.Println()
responseByPutschema = stub.MockInvoke("invoke1",[][]byte{[]byte("createTx/createCoupons"), []byte("1"),[]byte(createCouponsDate1),[]byte(createCouponsSign1)})
fmt.Printf("Invoke status %d,message %s and payload %s\n",responseByPutschema.Status,responseByPutschema.Message,string(responseByPutschema.Payload))
fmt.Println("========================================测试原始数据被修改============================================")
fmt.Println()
fmt.Println()
responseByPutschema = stub.MockInvoke("invoke1",[][]byte{[]byte("createTx/createCoupons"), []byte("1"),[]byte(createCouponsDate1),[]byte(createCouponsSign)})
fmt.Printf("Invoke status %d,message %s and payload %s\n",responseByPutschema.Status,responseByPutschema.Message,string(responseByPutschema.Payload))
fmt.Println("========================================invoke createTx disCoupon============================================") fmt.Println("========================================invoke createTx disCoupon============================================")
fmt.Println() fmt.Println()
fmt.Println() fmt.Println()
...@@ -287,17 +309,21 @@ func TestCouponsFlow(t *testing.T){ ...@@ -287,17 +309,21 @@ func TestCouponsFlow(t *testing.T){
responseByPutschema = stub.MockInvoke("invoke1",[][]byte{[]byte("createTx/useCoupon"),[]byte("111"),[]byte(useCouponsDate),[]byte(useCouponsSign)}) responseByPutschema = stub.MockInvoke("invoke1",[][]byte{[]byte("createTx/useCoupon"),[]byte("111"),[]byte(useCouponsDate),[]byte(useCouponsSign)})
fmt.Printf("Invoke status %d,message %s and payload %s\n",responseByPutschema.Status,responseByPutschema.Message,string(responseByPutschema.Payload)) fmt.Printf("Invoke status %d,message %s and payload %s\n",responseByPutschema.Status,responseByPutschema.Message,string(responseByPutschema.Payload))
//fmt.Println("========================================query getCoupons============================================") fmt.Println("========================================query getCoupons============================================")
//fmt.Println() fmt.Println()
//fmt.Println() fmt.Println()
//responseByPutschema = stub.MockInvoke("invoke1",[][]byte{[]byte("getCoupons"),[]byte("111"),[]byte(useCouponsDate),[]byte(useCouponsSign)}) responseByPutschema = stub.MockInvoke("invoke1",[][]byte{[]byte("getCoupons"),[]byte("1"),[]byte(getCouponsDate),[]byte(getCouponsSign)})
//fmt.Printf("Invoke status %d,message %s and payload %s\n",responseByPutschema.Status,responseByPutschema.Message,string(responseByPutschema.Payload)) fmt.Printf("Invoke status %d,message %s and payload %s\n",responseByPutschema.Status,responseByPutschema.Message,string(responseByPutschema.Payload))
//
//fmt.Println("========================================query getCouponsByAddress============================================")
//fmt.Println()
//fmt.Println()
//responseByPutschema = stub.MockInvoke("invoke1",[][]byte{[]byte("getCouponsByAddress"),[]byte("111"),[]byte(useCouponsDate),[]byte(useCouponsSign)})
//fmt.Printf("Invoke status %d,message %s and payload %s\n",responseByPutschema.Status,responseByPutschema.Message,string(responseByPutschema.Payload))
fmt.Println("========================================query getCouponsByAddress============================================")
fmt.Println()
fmt.Println()
responseByPutschema = stub.MockInvoke("invoke1",[][]byte{[]byte("getCouponsByAddress"),[]byte("111"),[]byte(getUtxoInfo),[]byte(getUtxoSign)})
fmt.Printf("Invoke status %d,message %s and payload %s\n",responseByPutschema.Status,responseByPutschema.Message,string(responseByPutschema.Payload))
fmt.Println("========================================测试查询未使用的UTXO============================================")
fmt.Println()
fmt.Println()
responseByPutschema = stub.MockInvoke("invoke1",[][]byte{[]byte("getCouponsByAddress"),[]byte("111"),[]byte(getUtxoInfo1),[]byte(getUtxoSign1)})
fmt.Printf("Invoke status %d,message %s and payload %s\n",responseByPutschema.Status,responseByPutschema.Message,string(responseByPutschema.Payload))
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment