Skip to content

Commit ba04046

Browse files
committed
integration test
Signed-off-by: Angelo De Caro <angelo.decaro@gmail.com>
1 parent 38e0d49 commit ba04046

File tree

14 files changed

+144
-67
lines changed

14 files changed

+144
-67
lines changed

.github/workflows/tests.yml

Lines changed: 1 addition & 0 deletions
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,

cmd/tokengen/cobra/pp/dlog/update.go

Lines changed: 2 additions & 3 deletions
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

cmd/tokengen/main_test.go

Lines changed: 1 addition & 1 deletion
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))

fungible.mk

Lines changed: 4 additions & 0 deletions
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"

integration/token/fungible/dlog/dlog_test.go

Lines changed: 16 additions & 3 deletions
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
})

integration/token/fungible/fabtoken/fabtoken_test.go

Lines changed: 1 addition & 1 deletion
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) {

integration/token/fungible/support.go

Lines changed: 43 additions & 18 deletions
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()

integration/token/fungible/tests.go

Lines changed: 13 additions & 3 deletions
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
}

integration/token/fungible/views/issue.go

Lines changed: 7 additions & 1 deletion
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:

token/core/zkatdlog/nogh/v1/validator/validator_issue.go

Lines changed: 1 addition & 1 deletion
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

0 commit comments

Comments
 (0)