@@ -18,7 +18,6 @@ package rest
18
18
19
19
import (
20
20
"bytes"
21
- "encoding/base64"
22
21
"encoding/json"
23
22
"fmt"
24
23
"io/ioutil"
@@ -34,10 +33,10 @@ import (
34
33
"github.com/hyperledger/fabric/protos"
35
34
)
36
35
37
- var failb64 string = base64 . StdEncoding . EncodeToString ([] byte ( "fail" ))
38
- var initb64 string = base64 . StdEncoding . EncodeToString ([] byte ( "Init" ))
39
- var change_ownerb64 string = base64 . StdEncoding . EncodeToString ([] byte ( "change_owner" ))
40
- var get_ownerb64 string = base64 . StdEncoding . EncodeToString ([] byte ( "get_owner" ))
36
+ var fail_func string = "fail"
37
+ var init_func string = "Init"
38
+ var change_owner_func string = "change_owner"
39
+ var get_owner_func string = "get_owner"
41
40
42
41
func performHTTPGet (t * testing.T , url string ) []byte {
43
42
response , err := http .Get (url )
@@ -594,7 +593,7 @@ func TestServerOpenchainREST_API_Chaincode_Deploy(t *testing.T) {
594
593
},
595
594
"ctorMsg": {
596
595
"args": ["` +
597
- initb64 +
596
+ init_func +
598
597
`"]
599
598
},
600
599
"secureContext": "myuser"
@@ -621,7 +620,7 @@ func TestServerOpenchainREST_API_Chaincode_Deploy(t *testing.T) {
621
620
},
622
621
"ctorMsg": {
623
622
"args": ["` +
624
- initb64 +
623
+ init_func +
625
624
`"]
626
625
}
627
626
}
@@ -644,7 +643,7 @@ func TestServerOpenchainREST_API_Chaincode_Deploy(t *testing.T) {
644
643
},
645
644
"ctorMsg": {
646
645
"args": ["` +
647
- initb64 +
646
+ init_func +
648
647
`"]
649
648
},
650
649
"secureContext": "myuser"
@@ -691,7 +690,7 @@ func TestServerOpenchainREST_API_Chaincode_Invoke(t *testing.T) {
691
690
performHTTPPost (t , httpServer .URL + "/registrar" , []byte (`{"enrollId":"myuser","enrollSecret":"password"}` ))
692
691
693
692
// Test invoke with "fail" function
694
- httpResponse , body = performHTTPPost (t , httpServer .URL + "/chaincode" , []byte (`{"jsonrpc":"2.0","ID":123,"method":"invoke","params":{"type":1,"chaincodeID":{"name":"dummy"},"ctorMsg":{"args":[ "` + failb64 + `"]},"secureContext":"myuser"}}` ))
693
+ httpResponse , body = performHTTPPost (t , httpServer .URL + "/chaincode" , []byte (`{"jsonrpc":"2.0","ID":123,"method":"invoke","params":{"type":1,"chaincodeID":{"name":"dummy"},"ctorMsg":{"Function": "` + fail_func + `","args":[ ]},"secureContext":"myuser"}}` ))
695
694
if httpResponse .StatusCode != http .StatusOK {
696
695
t .Errorf ("Expected an HTTP status code %#v but got %#v" , http .StatusOK , httpResponse .StatusCode )
697
696
}
@@ -701,7 +700,7 @@ func TestServerOpenchainREST_API_Chaincode_Invoke(t *testing.T) {
701
700
}
702
701
703
702
// Test invoke with "change_owner" function
704
- httpResponse , body = performHTTPPost (t , httpServer .URL + "/chaincode" , []byte (`{"jsonrpc":"2.0","ID":123,"method":"invoke","params":{"type":1,"chaincodeID":{"name":"dummy"},"ctorMsg":{"args":[ "` + change_ownerb64 + `"]},"secureContext":"myuser"}}` ))
703
+ httpResponse , body = performHTTPPost (t , httpServer .URL + "/chaincode" , []byte (`{"jsonrpc":"2.0","ID":123,"method":"invoke","params":{"type":1,"chaincodeID":{"name":"dummy"},"ctorMsg":{"Function": "` + change_owner_func + `","args":[ ]},"secureContext":"myuser"}}` ))
705
704
if httpResponse .StatusCode != http .StatusOK {
706
705
t .Errorf ("Expected an HTTP status code %#v but got %#v" , http .StatusOK , httpResponse .StatusCode )
707
706
}
@@ -742,7 +741,7 @@ func TestServerOpenchainREST_API_Chaincode_Query(t *testing.T) {
742
741
performHTTPPost (t , httpServer .URL + "/registrar" , []byte (`{"enrollId":"myuser","enrollSecret":"password"}` ))
743
742
744
743
// Test query with non-existing chaincode name
745
- httpResponse , body = performHTTPPost (t , httpServer .URL + "/chaincode" , []byte (`{"jsonrpc":"2.0","ID":123,"method":"query","params":{"type":1,"chaincodeID":{"name":"non-existing"},"ctorMsg":{"args":[ "` + initb64 + `"]},"secureContext":"myuser"}}` ))
744
+ httpResponse , body = performHTTPPost (t , httpServer .URL + "/chaincode" , []byte (`{"jsonrpc":"2.0","ID":123,"method":"query","params":{"type":1,"chaincodeID":{"name":"non-existing"},"ctorMsg":{"Function": "` + init_func + `","args":[ ]},"secureContext":"myuser"}}` ))
746
745
if httpResponse .StatusCode != http .StatusOK {
747
746
t .Errorf ("Expected an HTTP status code %#v but got %#v" , http .StatusOK , httpResponse .StatusCode )
748
747
}
@@ -752,7 +751,7 @@ func TestServerOpenchainREST_API_Chaincode_Query(t *testing.T) {
752
751
}
753
752
754
753
// Test query with fail function
755
- httpResponse , body = performHTTPPost (t , httpServer .URL + "/chaincode" , []byte (`{"jsonrpc":"2.0","ID":123,"method":"query","params":{"type":1,"chaincodeID":{"name":"dummy"},"ctorMsg":{"args":[ "` + failb64 + `"]},"secureContext":"myuser"}}` ))
754
+ httpResponse , body = performHTTPPost (t , httpServer .URL + "/chaincode" , []byte (`{"jsonrpc":"2.0","ID":123,"method":"query","params":{"type":1,"chaincodeID":{"name":"dummy"},"ctorMsg":{"Function": "` + fail_func + `","args":[ ]},"secureContext":"myuser"}}` ))
756
755
if httpResponse .StatusCode != http .StatusOK {
757
756
t .Errorf ("Expected an HTTP status code %#v but got %#v" , http .StatusOK , httpResponse .StatusCode )
758
757
}
@@ -765,7 +764,7 @@ func TestServerOpenchainREST_API_Chaincode_Query(t *testing.T) {
765
764
}
766
765
767
766
// Test query with get_owner function
768
- httpResponse , body = performHTTPPost (t , httpServer .URL + "/chaincode" , []byte (`{"jsonrpc":"2.0","ID":123,"method":"query","params":{"type":1,"chaincodeID":{"name":"dummy"},"ctorMsg":{"args":[ "` + get_ownerb64 + `"]},"secureContext":"myuser"}}` ))
767
+ httpResponse , body = performHTTPPost (t , httpServer .URL + "/chaincode" , []byte (`{"jsonrpc":"2.0","ID":123,"method":"query","params":{"type":1,"chaincodeID":{"name":"dummy"},"ctorMsg":{"Function": "` + get_owner_func + `","args":[ ]},"secureContext":"myuser"}}` ))
769
768
if httpResponse .StatusCode != http .StatusOK {
770
769
t .Errorf ("Expected an HTTP status code %#v but got %#v" , http .StatusOK , httpResponse .StatusCode )
771
770
}
0 commit comments