Skip to content

Commit c7ec9db

Browse files
committed
integration test
Signed-off-by: Angelo De Caro <[email protected]>
1 parent 8253e77 commit c7ec9db

File tree

14 files changed

+144
-67
lines changed

14 files changed

+144
-67
lines changed

Diff for: .github/workflows/tests.yml

+1
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ jobs:
8181
tests: [
8282
dlog-fabric-t1,
8383
dlog-fabric-t2,
84+
dlog-fabric-t2.1,
8485
dlog-fabric-t3,
8586
dlog-fabric-t4,
8687
dlog-fabric-t5,

Diff for: cmd/tokengen/cobra/pp/dlog/update.go

+2-3
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ import (
1313

1414
"github.com/hyperledger-labs/fabric-token-sdk/cmd/tokengen/cobra/pp/common"
1515
v1 "github.com/hyperledger-labs/fabric-token-sdk/token/core/zkatdlog/nogh/v1/setup"
16-
"github.com/hyperledger-labs/fabric-token-sdk/token/driver"
1716
"github.com/pkg/errors"
1817
"github.com/spf13/cobra"
1918
)
@@ -90,10 +89,10 @@ func Update(args *UpdateArgs) error {
9089
// Clear auditor and issuers if provided, and add them again.
9190
// If not provided, do not change them.
9291
if len(args.Auditors) > 0 {
93-
pp.AuditorIDs = []driver.Identity{}
92+
pp.SetAuditors(nil)
9493
}
9594
if len(args.Issuers) > 0 {
96-
pp.IssuerIDs = []driver.Identity{}
95+
pp.SetIssuers(nil)
9796
}
9897
if err := common.SetupIssuersAndAuditors(pp, args.Auditors, args.Issuers); err != nil {
9998
return err

Diff for: cmd/tokengen/main_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ func validateOutputEquivalent(gt *WithT, tempOutput, auditorsMSPdir, issuersMSPd
227227
gt.Expect(err).NotTo(HaveOccurred())
228228
gt.Expect(auditors[0]).To(Equal(auditor))
229229

230-
issuers := pp.IssuerIDs
230+
issuers := pp.Issuers()
231231
issuer, err := common.GetX509Identity(issuersMSPdir)
232232
gt.Expect(err).NotTo(HaveOccurred())
233233
gt.Expect(issuers[0]).To(BeEquivalentTo(issuer))

Diff for: fungible.mk

+4
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ integration-tests-dlog-fabric-t1:
66
integration-tests-dlog-fabric-t2:
77
make integration-tests-dlog-fabric TEST_FILTER="T2"
88

9+
.PHONY: integration-tests-dlog-fabric-t2.1
10+
integration-tests-dlog-fabric-t2.1:
11+
make integration-tests-dlog-fabric TEST_FILTER="T2.1"
12+
913
.PHONY: integration-tests-dlog-fabric-t3
1014
integration-tests-dlog-fabric-t3:
1115
make integration-tests-dlog-fabric TEST_FILTER="T3"

Diff for: integration/token/fungible/dlog/dlog_test.go

+16-3
Original file line numberDiff line numberDiff line change
@@ -41,14 +41,26 @@ var _ = Describe("EndToEnd", func() {
4141
ts, selector := newTestSuite(t.CommType, Aries|WebEnabled, t.ReplicationFactor, "", "alice", "bob", "charlie")
4242
BeforeEach(ts.Setup)
4343
AfterEach(ts.TearDown)
44-
It("Update public params", Label("T2"), func() {
44+
It("Update public params (new auditor and issuer)", Label("T2"), func() {
4545
fungible.TestPublicParamsUpdate(
4646
ts.II,
4747
"newAuditor",
48-
fungible.PrepareUpdatedPublicParams(ts.II, "newAuditor", "default"),
48+
fungible.PrepareUpdatedPublicParams(ts.II, "newAuditor", "newIssuer", "default", false),
4949
"default",
5050
false,
5151
selector,
52+
false,
53+
)
54+
})
55+
It("Update public params (append new auditor and issuer)", Label("T2.1"), func() {
56+
fungible.TestPublicParamsUpdate(
57+
ts.II,
58+
"newAuditor",
59+
fungible.PrepareUpdatedPublicParams(ts.II, "newAuditor", "newIssuer", "default", true),
60+
"default",
61+
false,
62+
selector,
63+
true,
5264
)
5365
})
5466
It("Test Identity Revocation", Label("T3"), func() { fungible.TestRevokeIdentity(ts.II, "auditor", selector) })
@@ -65,10 +77,11 @@ var _ = Describe("EndToEnd", func() {
6577
fungible.TestPublicParamsUpdate(
6678
ts.II,
6779
"newIssuer",
68-
fungible.PrepareUpdatedPublicParams(ts.II, "newIssuer", "default"),
80+
fungible.PrepareUpdatedPublicParams(ts.II, "newIssuer", "newIssuer", "default", false),
6981
"default",
7082
true,
7183
selector,
84+
false,
7285
)
7386
})
7487
})

Diff for: integration/token/fungible/fabtoken/fabtoken_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ func UpdatePublicParams(network *integration.Infrastructure, selector *token2.Re
5353
ppBytes, err := publicParam.Serialize()
5454
Expect(err).NotTo(HaveOccurred())
5555

56-
fungible.TestPublicParamsUpdate(network, "newAuditor", ppBytes, "default", false, selector)
56+
fungible.TestPublicParamsUpdate(network, "newAuditor", ppBytes, "default", false, selector, false)
5757
}
5858

5959
func newTestSuite(commType fsc.P2PCommunicationType, factor int, names ...string) (*token2.TestSuite, *token2.ReplicaSelector) {

Diff for: integration/token/fungible/support.go

+43-18
Original file line numberDiff line numberDiff line change
@@ -93,23 +93,41 @@ func IssueCash(network *integration.Infrastructure, wallet string, typ token.Typ
9393
}
9494

9595
func IssueSuccessfulCash(network *integration.Infrastructure, wallet string, typ token.Type, amount uint64, receiver *token3.NodeReference, auditor *token3.NodeReference, anonymous bool, issuer *token3.NodeReference, finalities ...*token3.NodeReference) string {
96-
return issueCashForTMSID(network, wallet, typ, amount, receiver, auditor, anonymous, issuer, nil, finalities, []string{})
96+
return issueCashForTMSID(network, wallet, typ, amount, receiver, auditor, anonymous, issuer, nil, finalities, false, []string{})
9797
}
9898

9999
func IssueCashForTMSID(network *integration.Infrastructure, wallet string, typ token.Type, amount uint64, receiver *token3.NodeReference, auditor *token3.NodeReference, anonymous bool, issuer *token3.NodeReference, tmsId *token2.TMSID, expectedErrorMsgs ...string) string {
100-
return issueCashForTMSID(network, wallet, typ, amount, receiver, auditor, anonymous, issuer, tmsId, []*token3.NodeReference{}, expectedErrorMsgs)
101-
}
102-
103-
func issueCashForTMSID(network *integration.Infrastructure, wallet string, typ token.Type, amount uint64, receiver *token3.NodeReference, auditor *token3.NodeReference, anonymous bool, issuer *token3.NodeReference, tmsId *token2.TMSID, endorsers []*token3.NodeReference, expectedErrorMsgs []string) string {
100+
return issueCashForTMSID(network, wallet, typ, amount, receiver, auditor, anonymous, issuer, tmsId, []*token3.NodeReference{}, false, expectedErrorMsgs)
101+
}
102+
103+
func IssueCashWithNoAuditorSigVerification(network *integration.Infrastructure, wallet string, typ token.Type, amount uint64, receiver *token3.NodeReference, auditor *token3.NodeReference, anonymous bool, issuer *token3.NodeReference, expectedErrorMsgs ...string) string {
104+
return issueCashForTMSID(network, wallet, typ, amount, receiver, auditor, anonymous, issuer, nil, []*token3.NodeReference{}, true, expectedErrorMsgs)
105+
}
106+
107+
func issueCashForTMSID(
108+
network *integration.Infrastructure,
109+
wallet string,
110+
typ token.Type,
111+
amount uint64,
112+
receiver *token3.NodeReference,
113+
auditor *token3.NodeReference,
114+
anonymous bool,
115+
issuer *token3.NodeReference,
116+
tmsId *token2.TMSID,
117+
endorsers []*token3.NodeReference,
118+
skipAuditorSignatureVerification bool,
119+
expectedErrorMsgs []string,
120+
) string {
104121
txIDBoxed, err := network.Client(issuer.ReplicaName()).CallView("issue", common.JSONMarshall(&views.IssueCash{
105-
Anonymous: anonymous,
106-
Auditor: auditor.Id(),
107-
IssuerWallet: wallet,
108-
TokenType: typ,
109-
Quantity: amount,
110-
Recipient: network.Identity(receiver.Id()),
111-
RecipientEID: receiver.Id(),
112-
TMSID: tmsId,
122+
Anonymous: anonymous,
123+
Auditor: auditor.Id(),
124+
IssuerWallet: wallet,
125+
TokenType: typ,
126+
Quantity: amount,
127+
Recipient: network.Identity(receiver.Id()),
128+
RecipientEID: receiver.Id(),
129+
TMSID: tmsId,
130+
SkipAuditorSignatureVerification: skipAuditorSignatureVerification,
113131
}))
114132

115133
topology.ToOptions(network.FscPlatform.Peers[0].Options).Endorser()
@@ -1369,10 +1387,10 @@ func MultiSigSpendCashForTMSID(network *integration.Infrastructure, sender *toke
13691387

13701388
}
13711389

1372-
func PrepareUpdatedPublicParams(network *integration.Infrastructure, auditor string, networkName string) []byte {
1390+
func PrepareUpdatedPublicParams(network *integration.Infrastructure, auditor string, issuer string, networkName string, appendIdentities bool) []byte {
13731391
tms := GetTMSByNetworkName(network, networkName)
13741392
auditorId := GetAuditorIdentity(tms, auditor)
1375-
issuerId := GetIssuerIdentity(tms, "newIssuer")
1393+
issuerId := GetIssuerIdentity(tms, issuer)
13761394

13771395
tokenPlatform, ok := network.Ctx.PlatformsByName["token"].(*tplatform.Platform)
13781396
Expect(ok).To(BeTrue(), "failed to get token platform from context")
@@ -1389,6 +1407,8 @@ func PrepareUpdatedPublicParams(network *integration.Infrastructure, auditor str
13891407
Serialize() ([]byte, error)
13901408
SetIssuers(identities []driver.Identity)
13911409
SetAuditors(identities []driver.Identity)
1410+
AddAuditor(identity2 driver.Identity)
1411+
AddIssuer(identity2 driver.Identity)
13921412
}
13931413
var pp PP
13941414
switch genericPP.Identifier {
@@ -1399,12 +1419,17 @@ func PrepareUpdatedPublicParams(network *integration.Infrastructure, auditor str
13991419
pp, err = fabtokenv1.NewPublicParamsFromBytes(ppBytes, fabtokenv1.PublicParameters)
14001420
Expect(err).NotTo(HaveOccurred())
14011421
default:
1402-
Expect(false).To(BeTrue(), "unknown pp identitfier [%s]", genericPP.Identifier)
1422+
Expect(false).To(BeTrue(), "unknown pp identifier [%s]", genericPP.Identifier)
14031423
}
14041424

14051425
Expect(pp.Validate()).NotTo(HaveOccurred())
1406-
pp.SetAuditors([]driver.Identity{auditorId})
1407-
pp.SetIssuers([]driver.Identity{issuerId})
1426+
if appendIdentities {
1427+
pp.AddAuditor(auditorId)
1428+
pp.AddIssuer(issuerId)
1429+
} else {
1430+
pp.SetAuditors([]driver.Identity{auditorId})
1431+
pp.SetIssuers([]driver.Identity{issuerId})
1432+
}
14081433

14091434
// Serialize
14101435
ppBytes, err = pp.Serialize()

Diff for: integration/token/fungible/tests.go

+13-3
Original file line numberDiff line numberDiff line change
@@ -847,15 +847,14 @@ func TestSelector(network *integration.Infrastructure, auditorId string, sel *to
847847
TransferCash(network, alice, "", "USD", 160, bob, auditor, "insufficient funds, only [150] tokens of type [USD] are available")
848848
}
849849

850-
func TestPublicParamsUpdate(network *integration.Infrastructure, newAuditorID string, ppBytes []byte, networkName string, issuerAsAuditor bool, sel *token3.ReplicaSelector) {
850+
func TestPublicParamsUpdate(network *integration.Infrastructure, newAuditorID string, ppBytes []byte, networkName string, issuerAsAuditor bool, sel *token3.ReplicaSelector, updateWithAppend bool) {
851851
newAuditor := sel.Get(newAuditorID)
852852
tms := GetTMSByNetworkName(network, networkName)
853853
newIssuer := sel.Get("newIssuer")
854854
issuer := sel.Get("issuer")
855855
alice := sel.Get("alice")
856856
manager := sel.Get("manager")
857857
auditor := sel.Get("auditor")
858-
errorMessage := "is not in issuers"
859858
if issuerAsAuditor {
860859
auditor = issuer
861860
}
@@ -886,7 +885,18 @@ func TestPublicParamsUpdate(network *integration.Infrastructure, newAuditorID st
886885
Expect(txId).NotTo(BeEmpty())
887886
CheckBalance(network, alice, "", "USD", 220)
888887
CheckHolding(network, alice, "", "USD", 110, newAuditor)
889-
IssueCash(network, "", "USD", 110, alice, newAuditor, true, issuer, errorMessage)
888+
if updateWithAppend {
889+
IssueCash(network, "", "USD", 110, alice, newAuditor, true, issuer)
890+
} else {
891+
IssueCash(network, "", "USD", 110, alice, newAuditor, true, issuer, "is not in issuers")
892+
}
893+
if newAuditorID != "auditor" {
894+
if updateWithAppend {
895+
IssueCash(network, "", "USD", 110, alice, auditor, true, newIssuer)
896+
} else {
897+
IssueCashWithNoAuditorSigVerification(network, "", "USD", 110, alice, auditor, true, newIssuer, "is not in auditors")
898+
}
899+
}
890900

891901
CheckOwnerWalletIDs(network, manager, "manager.id1", "manager.id2", "manager.id3")
892902
}

Diff for: integration/token/fungible/views/issue.go

+7-1
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ type IssueCash struct {
3838
RecipientWalletID string
3939
// RecipientEID is the expected enrolment id of the recipient
4040
RecipientEID string
41+
// SkipAuditorSignatureVerification set to true to skip the verification of the auditor signature during endorsement collection
42+
SkipAuditorSignatureVerification bool
4143
}
4244

4345
type IssueCashView struct {
@@ -116,7 +118,11 @@ func (p *IssueCashView) Call(context view.Context) (interface{}, error) {
116118
// Before completing, all recipients receive the approved transaction.
117119
// Depending on the token driver implementation, the recipient's signature might or might not be needed to make
118120
// the token transaction valid.
119-
_, err = context.RunView(ttx.NewCollectEndorsementsView(tx))
121+
var eOpts []ttx.EndorsementsOpt
122+
if p.SkipAuditorSignatureVerification {
123+
eOpts = append(eOpts, ttx.WithSkipAuditorSignatureVerification())
124+
}
125+
_, err = context.RunView(ttx.NewCollectEndorsementsView(tx, eOpts...))
120126
assert.NoError(err, "failed to sign issue transaction for "+tx.ID())
121127

122128
// Sanity checks:

Diff for: token/core/zkatdlog/nogh/v1/validator/validator_issue.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ func IssueValidate(ctx *Context) error {
3131
return err
3232
}
3333

34-
issuers := ctx.PP.IssuerIDs
34+
issuers := ctx.PP.Issuers()
3535
if len(issuers) != 0 {
3636
// Check the issuer is among those known
3737
found := false

Diff for: token/core/zkatdlog/nogh/v1/validator/validator_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ var _ = Describe("validator", func() {
9292
auditor = audit.NewAuditor(logging.MustGetLogger("auditor"), &noop.Tracer{}, des, pp.PedersenGenerators, asigner, c)
9393
araw, err := asigner.Serialize()
9494
Expect(err).NotTo(HaveOccurred())
95-
pp.AuditorIDs = []driver.Identity{araw}
95+
pp.SetAuditors([]driver.Identity{araw})
9696

9797
// initialize enginw with pp
9898
deserializer, err := zkatdlog.NewDeserializer(pp)

Diff for: token/services/ttx/auditor.go

+43-34
Original file line numberDiff line numberDiff line change
@@ -121,12 +121,13 @@ func (r *RegisterAuditorView) Call(context view.Context) (interface{}, error) {
121121
}
122122

123123
type AuditingViewInitiator struct {
124-
tx *Transaction
125-
local bool
124+
tx *Transaction
125+
local bool
126+
skipAuditorSignatureVerification bool
126127
}
127128

128-
func newAuditingViewInitiator(tx *Transaction, local bool) *AuditingViewInitiator {
129-
return &AuditingViewInitiator{tx: tx, local: local}
129+
func newAuditingViewInitiator(tx *Transaction, local, skipAuditorSignatureVerification bool) *AuditingViewInitiator {
130+
return &AuditingViewInitiator{tx: tx, local: local, skipAuditorSignatureVerification: skipAuditorSignatureVerification}
130131
}
131132

132133
func (a *AuditingViewInitiator) Call(context view.Context) (interface{}, error) {
@@ -154,39 +155,11 @@ func (a *AuditingViewInitiator) Call(context view.Context) (interface{}, error)
154155
span.AddEvent("received_message")
155156
logger.Debugf("reply received from %s", a.tx.Opts.Auditor)
156157

157-
// Check signature
158-
signed, err := a.tx.MarshallToAudit()
158+
auditorIdentity, err := a.verifyAuditorSignature(context, signature)
159159
if err != nil {
160-
return nil, errors.Wrapf(err, "failed marshalling message to sign")
161-
}
162-
if logger.IsEnabledFor(zapcore.DebugLevel) {
163-
logger.Debugf("Verifying auditor signature on [%s][%s][%s]", a.tx.Opts.Auditor.UniqueID(), hash.Hashable(signed).String(), a.tx.ID())
160+
return nil, errors.Wrapf(err, "failed verifying auditor signature")
164161
}
165162

166-
validAuditing := false
167-
var auditorIdentity token.Identity
168-
span.AddEvent("validate_auditing")
169-
for _, auditorID := range a.tx.TokenService().PublicParametersManager().PublicParameters().Auditors() {
170-
v, err := a.tx.TokenService().SigService().AuditorVerifier(auditorID)
171-
if err != nil {
172-
logger.Debugf("failed to get auditor verifier for [%s]", auditorID)
173-
continue
174-
}
175-
span.AddEvent("verify_auditor_signature")
176-
if err := v.Verify(signed, signature); err != nil {
177-
logger.Errorf("failed verifying auditor signature [%s][%s][%s]", auditorID, hash.Hashable(signed).String(), a.tx.TokenRequest.Anchor)
178-
} else {
179-
if logger.IsEnabledFor(zapcore.DebugLevel) {
180-
logger.Debugf("auditor signature verified [%s][%s][%s]", auditorID, base64.StdEncoding.EncodeToString(signature), hash.Hashable(signed))
181-
}
182-
auditorIdentity = auditorID
183-
validAuditing = true
184-
break
185-
}
186-
}
187-
if !validAuditing {
188-
return nil, errors.Errorf("failed verifying auditor signature [%s][%s]", hash.Hashable(signed).String(), a.tx.TokenRequest.Anchor)
189-
}
190163
span.AddEvent("append_auditor_signature")
191164
a.tx.TokenRequest.AddAuditorSignature(auditorIdentity, signature)
192165

@@ -259,6 +232,42 @@ func (a *AuditingViewInitiator) startLocal(context view.Context) (view.Session,
259232
return left, nil
260233
}
261234

235+
func (a *AuditingViewInitiator) verifyAuditorSignature(context view.Context, signature []byte) (token.Identity, error) {
236+
span := trace.SpanFromContext(context.Context())
237+
span.AddEvent("validate_auditing")
238+
239+
if a.skipAuditorSignatureVerification {
240+
return a.tx.Opts.Auditor, nil
241+
}
242+
243+
// check the signature
244+
signed, err := a.tx.MarshallToAudit()
245+
if err != nil {
246+
return nil, errors.Wrapf(err, "failed marshalling message to sign")
247+
}
248+
if logger.IsEnabledFor(zapcore.DebugLevel) {
249+
logger.Debugf("Verifying auditor signature on [%s][%s][%s]", a.tx.Opts.Auditor.UniqueID(), hash.Hashable(signed).String(), a.tx.ID())
250+
}
251+
252+
for _, auditorID := range a.tx.TokenService().PublicParametersManager().PublicParameters().Auditors() {
253+
v, err := a.tx.TokenService().SigService().AuditorVerifier(auditorID)
254+
if err != nil {
255+
logger.Debugf("failed to get auditor verifier for [%s]", auditorID)
256+
continue
257+
}
258+
span.AddEvent("verify_auditor_signature")
259+
if err := v.Verify(signed, signature); err != nil {
260+
logger.Errorf("failed verifying auditor signature [%s][%s][%s]", auditorID, hash.Hashable(signed).String(), a.tx.TokenRequest.Anchor)
261+
} else {
262+
if logger.IsEnabledFor(zapcore.DebugLevel) {
263+
logger.Debugf("auditor signature verified [%s][%s][%s]", auditorID, base64.StdEncoding.EncodeToString(signature), hash.Hashable(signed))
264+
}
265+
return auditorID, nil
266+
}
267+
}
268+
return nil, errors.Errorf("failed verifying auditor signature [%s][%s]", hash.Hashable(signed).String(), a.tx.TokenRequest.Anchor)
269+
}
270+
262271
type AuditApproveView struct {
263272
w *token.AuditorWallet
264273
tx *Transaction

Diff for: token/services/ttx/endorse.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -419,7 +419,7 @@ func (c *CollectEndorsementsView) requestAudit(context view.Context) ([]view.Ide
419419
logger.Debugf("ask auditing to [%s]", c.tx.Opts.Auditor)
420420
}
421421
local := view2.GetSigService(context).IsMe(c.tx.Opts.Auditor)
422-
sessionBoxed, err := context.RunView(newAuditingViewInitiator(c.tx, local))
422+
sessionBoxed, err := context.RunView(newAuditingViewInitiator(c.tx, local, c.Opts.SkipAuditorSignatureVerification))
423423
if err != nil {
424424
return nil, errors.WithMessagef(err, "failed requesting auditing from [%s]", c.tx.Opts.Auditor.String())
425425
}

0 commit comments

Comments
 (0)