-
Notifications
You must be signed in to change notification settings - Fork 64
/
Copy pathdlog_test.go
176 lines (155 loc) · 6.85 KB
/
dlog_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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
/*
Copyright IBM Corp All Rights Reserved.
SPDX-License-Identifier: Apache-2.0
*/
package dlog
import (
"os"
"github.com/hyperledger-labs/fabric-smart-client/integration"
"github.com/hyperledger-labs/fabric-smart-client/integration/nwo/fsc"
"github.com/hyperledger-labs/fabric-smart-client/pkg/api"
integration2 "github.com/hyperledger-labs/fabric-token-sdk/integration"
"github.com/hyperledger-labs/fabric-token-sdk/integration/nwo/token"
token2 "github.com/hyperledger-labs/fabric-token-sdk/integration/token"
"github.com/hyperledger-labs/fabric-token-sdk/integration/token/common"
"github.com/hyperledger-labs/fabric-token-sdk/integration/token/common/sdk/fdlog"
"github.com/hyperledger-labs/fabric-token-sdk/integration/token/fungible"
"github.com/hyperledger-labs/fabric-token-sdk/integration/token/fungible/topology"
dlognoghv1 "github.com/hyperledger-labs/fabric-token-sdk/token/core/zkatdlog/nogh/v1/setup"
"github.com/hyperledger-labs/fabric-token-sdk/token/driver"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
)
const None = 0
const (
Aries = 1 << iota
AuditorAsIssuer
NoAuditor
HSM
WebEnabled
WithEndorsers
)
var _ = Describe("EndToEnd", func() {
for _, t := range integration2.AllTestTypes {
Describe("T1 Fungible with Auditor ne Issuer", t.Label, func() {
ts, selector := newTestSuite(t.CommType, Aries, t.ReplicationFactor, "", "alice", "bob", "charlie")
BeforeEach(ts.Setup)
AfterEach(ts.TearDown)
It("succeeded", Label("T1"), func() { fungible.TestAll(ts.II, "auditor", nil, true, selector) })
})
Describe("Extras with websockets and replicas", t.Label, func() {
ts, selector := newTestSuite(t.CommType, Aries|WebEnabled, t.ReplicationFactor, "", "alice", "bob", "charlie")
BeforeEach(ts.Setup)
AfterEach(ts.TearDown)
It("Update public params", Label("T2"), func() {
fungible.TestPublicParamsUpdate(
ts.II,
"newAuditor",
PrepareUpdatedPublicParams(ts.II, "newAuditor", "default"),
"default",
false,
selector,
)
})
It("Test Identity Revocation", Label("T3"), func() { fungible.TestRevokeIdentity(ts.II, "auditor", selector) })
It("Test Remote Wallet (GRPC)", Label("T4"), func() { fungible.TestRemoteOwnerWallet(ts.II, "auditor", selector, false) })
It("Test Remote Wallet (WebSocket)", Label("T5"), func() { fungible.TestRemoteOwnerWallet(ts.II, "auditor", selector, true) })
})
Describe("Fungible with Auditor = Issuer", t.Label, func() {
ts, selector := newTestSuite(t.CommType, Aries|AuditorAsIssuer, t.ReplicationFactor, "", "alice", "bob", "charlie")
BeforeEach(ts.Setup)
AfterEach(ts.TearDown)
It("succeeded", Label("T6"), func() { fungible.TestAll(ts.II, "issuer", nil, true, selector) })
It("Update public params", Label("T7"), func() {
fungible.TestPublicParamsUpdate(
ts.II,
"newIssuer",
PrepareUpdatedPublicParams(ts.II, "newIssuer", "default"),
"default",
true,
selector,
)
})
})
Describe("Fungible with Auditor ne Issuer + Fabric CA", t.Label, func() {
ts, selector := newTestSuite(t.CommType, None, t.ReplicationFactor, "", "alice", "bob", "charlie")
BeforeEach(ts.Setup)
AfterEach(ts.TearDown)
It("succeeded", Label("T8"), func() { fungible.TestAll(ts.II, "auditor", nil, false, selector) })
})
Describe("Malicious Transactions", t.Label, func() {
ts, selector := newTestSuite(t.CommType, Aries|NoAuditor, t.ReplicationFactor, "", "alice", "bob", "charlie")
BeforeEach(ts.Setup)
AfterEach(ts.TearDown)
It("Malicious Transactions", Label("T9"), func() { fungible.TestMaliciousTransactions(ts.II, selector) })
})
Describe("Fungible with Auditor ne Issuer and Endorsers", t.Label, func() {
ts, selector := newTestSuite(t.CommType, Aries|WithEndorsers, t.ReplicationFactor, "", "alice", "bob", "charlie")
BeforeEach(ts.Setup)
AfterEach(ts.TearDown)
It("succeeded", Label("T10"), func() { fungible.TestAll(ts.II, "auditor", nil, true, selector) })
})
Describe("Multisig", t.Label, func() {
ts, selector := newTestSuite(t.CommType, Aries, t.ReplicationFactor, "", "alice", "bob", "charlie")
BeforeEach(ts.Setup)
AfterEach(ts.TearDown)
It("succeeded", Label("T12"), func() { fungible.TestMultiSig(ts.II, selector) })
})
Describe("Redeem flow", t.Label, func() {
ts, selector := newTestSuite(t.CommType, Aries, t.ReplicationFactor, "", "alice", "bob", "charlie")
BeforeEach(ts.Setup)
AfterEach(ts.TearDown)
It("succeeded", Label("T13"), func() { fungible.TestRedeem(ts.II, selector, "default") })
})
}
for _, tokenSelector := range integration2.TokenSelectors {
Describe("TokenSelector Test", integration2.WebSocketNoReplication.Label, Label(tokenSelector), func() {
ts, replicaSelector := newTestSuite(integration2.WebSocketNoReplication.CommType, Aries, integration2.WebSocketNoReplication.ReplicationFactor, tokenSelector, "alice", "bob", "charlie")
BeforeEach(ts.Setup)
AfterEach(ts.TearDown)
It("succeeded", Label("T11"), func() { fungible.TestSelector(ts.II, "auditor", replicaSelector) })
})
}
})
func PrepareUpdatedPublicParams(network *integration.Infrastructure, auditor string, networkName string) []byte {
tms := fungible.GetTMSByNetworkName(network, networkName)
auditorId := fungible.GetAuditorIdentity(tms, auditor)
issuerId := fungible.GetIssuerIdentity(tms, "newIssuer.id1")
tokenPlatform, ok := network.Ctx.PlatformsByName["token"].(*token.Platform)
Expect(ok).To(BeTrue(), "failed to get token platform from context")
// Deserialize current params
ppBytes, err := os.ReadFile(tokenPlatform.PublicParametersFile(tms))
Expect(err).NotTo(HaveOccurred())
pp, err := dlognoghv1.NewPublicParamsFromBytes(ppBytes, dlognoghv1.DLogPublicParameters)
Expect(err).NotTo(HaveOccurred())
Expect(pp.Validate()).NotTo(HaveOccurred())
// Update publicParameters
pp.Auditor = auditorId
pp.IssuerIDs = []driver.Identity{issuerId}
// Serialize
ppBytes, err = pp.Serialize()
Expect(err).NotTo(HaveOccurred())
return ppBytes
}
func newTestSuite(commType fsc.P2PCommunicationType, mask int, factor int, tokenSelector string, names ...string) (*token2.TestSuite, *token2.ReplicaSelector) {
opts, selector := token2.NewReplicationOptions(factor, names...)
ts := token2.NewTestSuite(StartPortDlog, topology.Topology(
common.Opts{
Backend: "fabric",
CommType: commType,
DefaultTMSOpts: common.TMSOpts{TokenSDKDriver: "dlog", Aries: mask&Aries > 0},
NoAuditor: mask&NoAuditor > 0,
AuditorAsIssuer: mask&AuditorAsIssuer > 0,
HSM: mask&HSM > 0,
WebEnabled: mask&WebEnabled > 0,
SDKs: []api.SDK{&fdlog.SDK{}},
Monitoring: false,
ReplicationOpts: opts,
FSCBasedEndorsement: mask&WithEndorsers > 0,
// FSCLogSpec: "token-sdk=debug:fabric-sdk=debug:info",
OnlyUnity: true,
TokenSelector: tokenSelector,
},
))
return ts, selector
}