Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package main
- import (
- "encoding/json"
- "strings"
- "testing"
- "github.com/hyperledger/fabric/core/chaincode/shim"
- "github.com/stretchr/testify/assert"
- )
- func Test_GetAssetInvalidID(t *testing.T) {
- // Arrange
- scc := new(SmartContract)
- stub := shim.NewMockStub("", scc)
- // Act
- res := stub.MockInvoke(
- "1",
- [][]byte{
- []byte("getAsset"),
- []byte("1")},
- )
- // Assert
- assert.Equal(t, shim.ERROR, int(res.Status))
- }
- func Test_GetAssetValidID(t *testing.T) {
- // Arrange
- scc := new(SmartContract)
- stub := shim.NewMockStub("", scc)
- asset := Asset{}
- asset.Name = "john"
- assetAsBytes, _ := json.Marshal(asset)
- stub.MockTransactionStart("CREATEASSET")
- stub.PutState("A1", assetAsBytes)
- // Act
- res := stub.MockInvoke(
- "1",
- [][]byte{
- []byte("getAsset"),
- []byte("A1")},
- )
- // Assert
- assert.Equal(
- t,
- strings.Contains(string(res.Payload), "\"name\":\"John\""),
- true,
- )
- assert.Equal(t, shim.OK, int(res.Status))
- }
Add Comment
Please, Sign In to add comment