forked from hyperledger/fabric-private-chaincode
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtlcc_test.go
100 lines (81 loc) · 2.7 KB
/
tlcc_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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
/*
Copyright IBM Corp. All Rights Reserved.
SPDX-License-Identifier: Apache-2.0
*/
package tlcc
import (
"encoding/base64"
"fmt"
"strconv"
"testing"
"github.com/hyperledger-labs/fabric-private-chaincode/tlcc/enclave"
. "github.com/hyperledger-labs/fabric-private-chaincode/utils"
"github.com/hyperledger/fabric-chaincode-go/shim"
"github.com/hyperledger/fabric-chaincode-go/shimtest"
"github.com/spf13/viper"
)
func setupTestLedger(chainid string) {
viper.Set("peer.fileSystemPath", "/tmp/hyperledger/test/")
// TODO
// MockInitialize and MockCreateChain have been removed with Fabric v2. To make golinter happy again this is
// simply commented out as this test is not invoked by make script anyway. Another PR will re-enable this test.
// peer.MockInitialize()
// peer.MockCreateChain(chainid)
}
func TestTrustedLedgerCC_Init(t *testing.T) {
tlcc := createTlcc()
stub := shimtest.NewMockStub("tlcc", tlcc)
stub.ChannelID = "mychannel"
setupTestLedger("mychannel")
CheckInit(t, stub, [][]byte{})
}
func TestTrustedLedgerCC_JoinChannel(t *testing.T) {
tlcc := createTlcc()
stub := shimtest.NewMockStub("tlcc", tlcc)
stub.ChannelID = "mychannel"
setupTestLedger("mychannel")
CheckInit(t, stub, [][]byte{})
CheckInvoke(t, stub, [][]byte{[]byte("JOIN_CHANNEL"), []byte("mychannel")})
}
func TestTrustedLedgerCC_GetReport(t *testing.T) {
tlcc := createTlcc()
stub := shimtest.NewMockStub("tlcc", tlcc)
stub.ChannelID = "mychannel"
setupTestLedger("mychannel")
CheckInit(t, stub, [][]byte{})
CheckInvoke(t, stub, [][]byte{[]byte("JOIN_CHANNEL"), []byte("mychannel")})
// note this is a debugging call :D
targetInfo, _ := tlcc.GetTargetInfo()
args := [][]byte{[]byte("GET_LOCAL_ATT_REPORT"), targetInfo}
res := stub.MockInvoke("1", args)
if res.Status != shim.OK {
fmt.Println("Invoke", args, "failed", string(res.Message))
t.FailNow()
}
}
func TestTrustedLedgerCC_GetStateCMAC(t *testing.T) {
tlcc := createTlcc()
stub := shimtest.NewMockStub("tlcc", tlcc)
stub.ChannelID = "mychannel"
setupTestLedger("mychannel")
CheckInit(t, stub, [][]byte{})
CheckInvoke(t, stub, [][]byte{[]byte("JOIN_CHANNEL"), []byte("mychannel")})
key := []byte("some.channel.someKey")
nonce := []byte(base64.StdEncoding.EncodeToString([]byte("moin")))
isRangeQuery := []byte(strconv.FormatBool(false))
args := [][]byte{[]byte("VERIFY_STATE"), key, nonce, isRangeQuery}
res := stub.MockInvoke("1", args)
if res.Status != shim.OK {
fmt.Println("Invoke", args, "failed", string(res.Message))
t.FailNow()
}
fmt.Println("CMAC: " + string(res.Payload))
}
func TestLoadPlugin(t *testing.T) {
CheckLoadPlugin(t, "tlcc.so")
}
func createTlcc() *TrustedLedgerCC {
return &TrustedLedgerCC{
enclave: &enclave.MockStub{},
}
}