clone-akc-go-sdk

command module
v0.0.0-...-76989e6 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 10, 2020 License: GPL-2.0 Imports: 5 Imported by: 0

README

Akachain Golang Software Development Kit

Go Report Card

golang SDK that supports writing chaincodes on Akachain platform. In release v1.0, we introduce 3 different Software Development Kits (SDKs)

1. Unit testing framework

Hyperledger Fabric supports writing unit test for chaincode using GoMock. However, the default Mock file provided by Fabric does not support testing with CouchDB. Instead, key-value data is stored in an in-memory map. This does not allows developers to perform unit test on any function that relies on couchdb.

akc-go-sdk provides utilities that override the default mock stub class to allow writing chaincode unit test that uses a local (or remote) couchdb instance.

We first need to install Apache couchdb at http://couchdb.apache.org/

There is also a list of imports that are neccessary as follows.

import (
    ...
    "testing"
    "github.com/hongsongp97/clone-akc-go-sdk/util"
    "github.com/hyperledger/fabric/core/chaincode/shim"
    "github.com/stretchr/testify/assert"
)

We then create a MockStubExtend object that literally extend Fabric MockStub and

type Chaincode struct {
}

func setupMock() *util.MockStubExtend {
    // Initialize mockstubextend
    cc := new(Chaincode)
    stub := util.NewMockStubExtend(shim.NewMockStub("mockstubextend", cc), cc)

    // Create a new database, Drop old database
    db, _ := util.NewCouchDBHandler("dbtest", true)
    stub.SetCouchDBConfiguration(db)
    return stub
}

Then we can perform Unit test for each chaincode invoke function normally. Here is an example of testing an invoke function:

func TestSample(t *testing.T) {
	stub := setupMock()

	usr := models.UserWallet{
		UserId:      "id1",
		PublicKey:   "pubkey",
	}

	param, _ := json.Marshal(usr)

	// Create a new user
	rs := util.MockInvokeTransaction(t, stub, [][]byte{[]byte("createUser"), []byte(param), []byte("2")})

	// Make a composite key that is similar with the one in couchdb
	compositeKey, _ := stub.CreateCompositeKey(models.USERWALLET_TABLE, []string{rs})

	// Check if the created user exist
	state, _ := stub.GetState(compositeKey)
	var ad models.UserWallet
	json.Unmarshal([]byte(state), &ad)

	// Check if the created user information is correct
	assert.Equal(t, usr.UserId, ad.UserId)
	assert.Equal(t, usr.PublicKey, ad.PublicKey)
}

2. High Throughput Chaincode (HTC)

Please follow the instruction here

3. High Secure Transaction Chaincode (HSTX)

A high level description of HSTX is described here. It is still in R&D phase.

We have a live demo here

Documentation

The Go Gopher

There is no documentation for this package.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL