Guest User

Untitled

a guest
Jan 18th, 2019
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.13 KB | None | 0 0
  1. package main
  2.  
  3. import (
  4. "encoding/json"
  5. "strings"
  6. "testing"
  7. "github.com/hyperledger/fabric/core/chaincode/shim"
  8.   "github.com/stretchr/testify/assert"
  9. )
  10.  
  11. func Test_GetAssetInvalidID(t *testing.T) {
  12. // Arrange
  13.   scc := new(SmartContract)
  14.   stub := shim.NewMockStub("", scc)
  15.  
  16. // Act
  17.   res := stub.MockInvoke(
  18.   "1",
  19.   [][]byte{
  20.   []byte("getAsset"),
  21. []byte("1")},
  22.   )
  23.  
  24. // Assert
  25.   assert.Equal(t, shim.ERROR, int(res.Status))
  26. }
  27.  
  28. func Test_GetAssetValidID(t *testing.T) {
  29.  // Arrange
  30. scc := new(SmartContract)
  31. stub := shim.NewMockStub("", scc)
  32.   asset := Asset{}
  33.   asset.Name = "john"
  34.   assetAsBytes, _ := json.Marshal(asset)
  35.   stub.MockTransactionStart("CREATEASSET")
  36.   stub.PutState("A1", assetAsBytes)
  37.  
  38. // Act
  39.   res := stub.MockInvoke(
  40.   "1",
  41.   [][]byte{
  42.   []byte("getAsset"),
  43.   []byte("A1")},
  44.   )
  45.  
  46. // Assert
  47.   assert.Equal(
  48.   t,
  49. strings.Contains(string(res.Payload), "\"name\":\"John\""),
  50.   true,
  51.   )
  52.   assert.Equal(t, shim.OK, int(res.Status))
  53. }
Add Comment
Please, Sign In to add comment