-
Notifications
You must be signed in to change notification settings - Fork 0
/
message_test.go
57 lines (47 loc) · 1.54 KB
/
message_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
package main
import (
"encoding/json"
"fmt"
"testing"
"github.com/abbeydabiri/hdlchaincode/models"
"github.com/abbeydabiri/hdlchaincode/utils"
"github.com/google/uuid"
"github.com/hyperledger/fabric-chaincode-go/shim"
"github.com/hyperledger/fabric-chaincode-go/shimtest"
"github.com/stretchr/testify/assert"
)
func TestMessageWR(t *testing.T) {
fmt.Println("Entering TestMessageLogic")
assert := assert.New(t)
// Instantiate mockStub using HDLChaincode as the target chaincode to unit test
stub := shimtest.NewMockStub("TestStub", new(HDLChaincode))
//Verify stub is available
assert.NotNil(stub, "Stub is nil, Test stub creation failed")
uid := uuid.New().String()
writeResp := stub.MockInvoke(uid,
[][]byte{[]byte(utils.MessageW),
[]byte("1"),
[]byte("Test From"),
[]byte("Test To"),
[]byte("Test Subject"),
[]byte("Test Message"),
[]byte("Test MessageDate"),
})
assert.EqualValues(shim.OK, writeResp.GetStatus(), writeResp.GetMessage())
testID := "1"
readResp := stub.MockInvoke(uid,
[][]byte{[]byte(utils.MessageR),
[]byte(testID),
})
assert.EqualValues(shim.OK, readResp.GetStatus(), readResp.GetMessage())
var ccResp struct {
Code string `json:"code"`
Message string `json:"message"`
Payload models.Message `json:"payload"`
}
if err := json.Unmarshal(readResp.GetPayload(), &ccResp); err != nil {
panic(err)
}
assert.Equal(testID, ccResp.Payload.MessageID, "Retrieved Message ID mismatch")
assert.Equal(utils.MESSAG, ccResp.Payload.ObjectType, "Retrieved Object Type mismatch")
}