s7techlab / cckit Goto Github PK
View Code? Open in Web Editor NEWSource code moved to https://github.com/hyperledger-labs/cckit
Home Page: https://github.com/hyperledger-labs/cckit
License: Apache License 2.0
Source code moved to https://github.com/hyperledger-labs/cckit
Home Page: https://github.com/hyperledger-labs/cckit
License: Apache License 2.0
Hi! First of all, congratiulations on this kit, it's really helping me out to understand Fabric contracts and its quirks.
However, I couldn't find any documentation on how to perform tests with state mock data. Do the contracts need to be deployed to a HLF network to verify that the written business logic is actually working rather than just relying on test results?
I am getting the follwing warning message while trying to deploy chaincode in dev mode:
WARNING: Package "github.com/golang/protobuf/protoc-gen-go/generator" is deprecated.
A future release of golang/protobuf will delete this package,
which has long been excluded from the compatibility promise.
If it's not fatal, Is there a way to remove this warning?
Dear CCKit
Thanks so much for this great repo; it clearly is a more complex and nuanced tool than the HL commercial paper tutorial. I can see considerable potential for my own work and students at UCLA. However: there's an assumption of considerable expertise in your ReadMe.
Could you possibly:
Thanks so much
David
UCLA
https://www.davidmacfadyen.com/
Hi,
The tool is nice, when to upgrade to v2?
if err = setAllowance(c, fromMspId, fromCertId, invoker.GetID(), invoker.GetID(), allowance-amount); err != nil {
return nil, err
}
should be
if err = setAllowance(c, fromMspId, fromCertId, invoker.GetMSPID(), invoker.GetID(), allowance-amount); err != nil {
return nil, err
}
How it works in Fabric
Execution flow
backend -> init tx -> cc1 (initial call) -> cc2 (cc2cc invokation) -> cc1 (processes result of cc2 execution) -> tx ends, rwset contains data from cc1 and cc2 -> peer commits block with data from cc1 and cc2 (state updated)
How it works in cckit's testing package
init tx -> cc1 (initial call) -> cc2 (cc2cc, and it saves data HERE to mockstub's putState), cc1 (processes result of cc2 execution with the updated state)
Hi, I ran the erc20 example and it seems to be a problem with invokeTransferFrom().
allowance, err := getAllowance(c, fromMspId, fromCertId, invoker.GetMSPID(), invoker.GetID())
In the above code, the argument value corresponding to 'from' and the argument value position of 'invoker' seem to be reversed.
Please confirm.
Thanks
Hi Victor,
Simply marvelous work on this kit. Had few questions on Private Data and Unit testing around same. Are these supported?
Any examples around these?
Best Regards,
Govinda
The shim package used by cckit is the only and deprecated github.com/hyperledger/fabric/core/chaincode/shim
which has since been archived. Is there any plans to update the service to utilise the new and supported fabric-go-chaincode/shim
packages?
Hi,
I noticed that when using the Key()
interface for user-defined structs, the objects get stored in the CouchDB state with some Unicode NULL characters.
Example:
"id": "\u0000ASSET\u00001c730708-70b2-4f99-b4c1-cf6689006e32\u0000",
"key": "\u0000ASSET\u00001c730708-70b2-4f99-b4c1-cf6689006e32\u0000",
This does not happen when the composite key is passed directly as an []string
.
Thanks for the wonderful work !
Q1. Where is main function in this program ?https://gist.github.com/vitiko/ca8ec2631e3978fcdaa3a237b4c4b43d#file-cars_chaincode_example-go
Q-2 : Is Owner really important ?
Q-3. I tried to use this , but received on following : return t.router.Handle(stub) on Invoke
2018–09–04 06:09:15.443 UTC [grpc] Printf -> DEBU 006 pickfirstBalancer: HandleSubConnStateChange: 0xc4203c5270, CONNECTING
2018–09–04 06:09:15.444 UTC [grpc] Printf -> DEBU 007 pickfirstBalancer: HandleSubConnStateChange: 0xc4203c5270, READY
panic: runtime error: invalid memory address or nil pointer dereference
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x30 pc=0x8cac06]
Q-4: On init can we remove it : return owner.SetFromCreator(cc.router.Context(init
, stub)) and keep return shim.Success(nil) ?
Q-5 : How to Debug it with breakpoint , it without creating HLF network and deploying there ?
Q-6 : Can you send running full program without owner ? and with main included too.
I try to run examples but they fail with an error C:\Users\User1\go\pkg\mod\github.com\docker\[email protected]\pkg\system\filesys_windows.go:113:24: cannot use uintptr(unsafe.Pointer(&sd[0])) (type uintptr) as type *"golang.org/x/sys/windows".SECURITY_DESCRIPTOR in assignment
The ERC20 instructions file still mentions dep for installation, however it seems that a different command is used now (go mod).
https://github.com/s7techlab/cckit/blob/master/examples/erc20/README.md
I want to read data as a sorted list. I added CouchDB query:
func list(c router.Context) (interface{}, error) {
queryString := `{
"selector": {},
"sort": [
{"id": "asc"}
]
}`
iter, err1 := c.Stub().GetQueryResult(queryString)
if err1 != nil {
return nil, errors.Wrap(err1, "failed to GetQueryResult")
}
defer iter.Close()
items := []interface{}{}
for iter.HasNext() {
kvResult, err := iter.Next()
if err != nil {
return nil, errors.Wrap(err1, "fetch error")
}
item := QueueItem{}
err2 := json.Unmarshal(kvResult.Value, &item)
if err2 != nil {
return nil, errors.Wrap(err1, "value unmarshal error")
}
items = append(items, item)
}
return items, nil
}
But the test by mock tells me `failed to GetQueryResult: not implemented.
Is it so because I run the test with mock?
https://github.com/s7techlab/cckit/blob/master/go.mod#L18
and ginkgo should only be used on a test build
today ginkgo deps is always compiled into the main binary assembly
Due to ongoing Fabric maintainers efforts to eliminate dependence on bsccp shim/ext/entities was deleted https://gerrit.hyperledger.org/r/c/fabric/+/32727
We need to use another package that implements cryptographic primitives and possibly an abstraction layer for using it in CC.
there is a bug,I use protoc command generate struct like this:
type Commodity struct {
.... // other fileds skip
XXX_NoUnkeyedLiteral struct{} `json:"-"`
XXX_unrecognized []byte `json:"-"`
XXX_sizecache int32 `json:"-"`
}
and I store the instance of Commodity,but get an error: *router handler error: write: key from field message.Commodity.XXX_NoUnkeyedLiteral: field type not supported for key extraction
I find that cckit would also handle the struct fileds like "XXX_NoUnkeyedLiteral" ,"XXX_unrecognized". I think they should be skipped.
I changed the source code file "state/mapping/state_mapping_opt.go" like this:
func attrsPKeyer(attrs []string) InstanceKeyer {
return func(instance interface{}) (key state.Key, err error) {
inst := reflect.Indirect(reflect.ValueOf(instance))
var pkey state.Key
for _, attr := range attrs {
v := inst.FieldByName(attr)
if !v.IsValid() {
return nil, fmt.Errorf(`%s: %s`, ErrFieldNotExists, attr)
}
// **********************************************************************
// skip the fields who start with "XXX_"
if state,_ := regexp.Match("XXX_.*",[]byte(attr)); state {
continue
}
// **************************************************************************
if key, err = keyFromValue(v); err != nil {
return nil, fmt.Errorf(`key from field %s.%s: %s`, mapKey(instance), attr, err)
}
pkey = pkey.Append(key)
}
return pkey, nil
}
}
if allowance <= amount {
return nil, ErrSpenderNotHaveAllowance
}
should be
if allowance < amount {
return nil, ErrSpenderNotHaveAllowance
}
I am trying to test 'RecordCreate' function which calls a query function context.Stub().GetQueryResult()
. This function is returning an error with message "not implemented". The function calls context.State().Get()
is working fine.
Text execution logs:
Running Suite: Chaincode
========================
Random Seed: 1603439528
Will run 1 of 1 specs
***** BEFORE SUITE *****
Init() called
2020-10-23 13:22:08.188 IST [TEST] Debugf -> DEBU 001 state KEY: OWNER
2020-10-23 13:22:08.188 IST [TEST] Debugf -> DEBU 002 state check EXISTENCE OWNER
2020-10-23 13:22:08.188 IST [TEST] Debugf -> DEBU 003 state KEY: OWNER
2020-10-23 13:22:08.188 IST [TEST] Debugf -> DEBU 004 state check EXISTENCE OWNER
2020-10-23 13:22:08.188 IST [TEST] Debugf -> DEBU 005 state KEY: OWNER
2020-10-23 13:22:08.188 IST [TEST] Debugf -> DEBU 006 state PUT with string key: OWNER
2020-10-23 13:22:08.188 IST [TEST] Debug -> DEBU 007 router handler: RecordCreate
********** CreateRecord Called **********
2020-10-23 13:22:08.188 IST [TEST] Errorf -> ERRO 008 router handler error: RecordCreate: {"code":500,"msg":"not implemented"}
• Failure [0.001 seconds]
TEST
/home/akshay/chaincode/chaincode_test.go:37
/home/akshay/TEST/chaincode/chaincode_test.go:48
Should be able to create record [It]
/home/akshay/TEST/chaincode/chaincode_test.go:49
{"code":500,"msg":"not implemented"}
Expected
<int>: 500
to equal
<int>: 200
/home/akshay/pkg/mod/github.com/s7techlab/[email protected]/testing/expect/response.go:16
------------------------------
Summarizing 1 Failure:
[Fail] TEST Record Flow [It] Should be able to create record
/home/akshay/pkg/mod/github.com/s7techlab/[email protected]/testing/expect/response.go:16
Ran 1 of 1 Specs in 0.001 seconds
FAIL! -- 0 Passed | 1 Failed | 0 Pending | 0 Skipped
--- FAIL: TestChaincode (0.00s)
FAIL
exit status 1
FAIL chaincode 0.061s
When trying to run tests based on NewMockStub + chaincode permissioning, I receive the following error:
s7techlab/cckit/testing/tx.go:79:19: cannot use p.MockStub.MockStub.TxTimestamp (type *"github.com/hyperledger/fabric/vendor/github.com/golang/protobuf/ptypes/timestamp".Timestamp) as type *"github.com/golang/protobuf/ptypes/timestamp".Timestamp in return argument
Hello!
I was playing around with your useful lib and it's indeed pretty supportive in the chaincode development process. It speeds up things rapidly :)
However, I struggled with the deployment of the chaincode including the lib on an example docker environment like https://hyperledger-fabric.readthedocs.io/en/release-1.3/build_network.html#install-instantiate-chaincode. How would you deploy your example s7techlab/cckit/examples/cars to it?
Cheers & Thanks!
Where is the main and init implementation?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.