github.com/s7techlab/cckit@v0.10.5/extensions/encryption/testing/invoke.go (about) 1 package testing 2 3 import ( 4 "github.com/hyperledger/fabric-protos-go/peer" 5 6 "github.com/s7techlab/cckit/extensions/encryption" 7 "github.com/s7techlab/cckit/response" 8 testcc "github.com/s7techlab/cckit/testing" 9 ) 10 11 // MockInvoke helper for invoking MockStub with transient key and encrypted args 12 func MockInvoke(cc *testcc.MockStub, encKey []byte, args ...interface{}) peer.Response { 13 encArgs, err := encryption.EncryptArgs(encKey, args...) 14 if err != nil { 15 return response.Error(`unable to encrypt input args`) 16 } 17 return cc.AddTransient(encryption.TransientMapWithKey(encKey)).InvokeBytes(encArgs...) 18 } 19 20 // MockQuery helper for querying MockStub with transient key and encrypted args 21 func MockQuery(cc *testcc.MockStub, encKey []byte, args ...interface{}) peer.Response { 22 encArgs, err := encryption.EncryptArgs(encKey, args...) 23 if err != nil { 24 return response.Error(`unable to encrypt input args`) 25 } 26 return cc.AddTransient(encryption.TransientMapWithKey(encKey)).QueryBytes(encArgs...) 27 }