Skip to content

Commit 17ff030

Browse files
authored
Integration Tests: Register Owner Wallet (#427)
Signed-off-by: Angelo De Caro <adc@zurich.ibm.com>
1 parent 3a9b328 commit 17ff030

File tree

11 files changed

+124
-17
lines changed

11 files changed

+124
-17
lines changed

integration/nwo/token/fabric/fabric.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,21 @@ func (p *NetworkHandler) GenIssuerCryptoMaterial(tms *topology2.TMS, nodeID stri
186186
return ""
187187
}
188188

189+
func (p *NetworkHandler) GenOwnerCryptoMaterial(tms *topology2.TMS, nodeID string, walletID string) string {
190+
cmGenerator := p.CryptoMaterialGenerators[tms.Driver]
191+
Expect(cmGenerator).NotTo(BeNil(), "Crypto material generator for driver %s not found", tms.Driver)
192+
193+
fscTopology := p.TokenPlatform.GetContext().TopologyByName(fsc.TopologyName).(*fsc.Topology)
194+
for _, node := range fscTopology.Nodes {
195+
if node.ID() == nodeID {
196+
ids := cmGenerator.GenerateOwnerIdentities(tms, node, walletID)
197+
return ids[0].Path
198+
}
199+
}
200+
Expect(false).To(BeTrue(), "cannot find FSC node [%s:%s]", tms.Network, nodeID)
201+
return ""
202+
}
203+
189204
func (p *NetworkHandler) SetCryptoMaterialGenerator(driver string, generator generators.CryptoMaterialGenerator) {
190205
p.CryptoMaterialGenerators[driver] = generator
191206
}

integration/nwo/token/orion/orion.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,21 @@ func (p *NetworkHandler) GenIssuerCryptoMaterial(tms *topology2.TMS, nodeID stri
184184
return ""
185185
}
186186

187+
func (p *NetworkHandler) GenOwnerCryptoMaterial(tms *topology2.TMS, nodeID string, walletID string) string {
188+
cmGenerator := p.CryptoMaterialGenerators[tms.Driver]
189+
Expect(cmGenerator).NotTo(BeNil(), "Crypto material generator for driver %s not found", tms.Driver)
190+
191+
fscTopology := p.TokenPlatform.GetContext().TopologyByName(fsc.TopologyName).(*fsc.Topology)
192+
for _, node := range fscTopology.Nodes {
193+
if node.ID() == nodeID {
194+
ids := cmGenerator.GenerateOwnerIdentities(tms, node, walletID)
195+
return ids[0].Path
196+
}
197+
}
198+
Expect(false).To(BeTrue(), "cannot find FSC node [%s:%s]", tms.Network, nodeID)
199+
return ""
200+
}
201+
187202
func (p *NetworkHandler) SetCryptoMaterialGenerator(driver string, generator generators.CryptoMaterialGenerator) {
188203
p.CryptoMaterialGenerators[driver] = generator
189204
}

integration/nwo/token/platform.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ type NetworkHandler interface {
4040
GenerateExtension(tms *topology2.TMS, node *sfcnode.Node) string
4141
PostRun(load bool, tms *topology2.TMS)
4242
GenIssuerCryptoMaterial(tms *topology2.TMS, nodeID string, walletID string) string
43+
GenOwnerCryptoMaterial(tms *topology2.TMS, nodeID string, walletID string) string
4344
}
4445

4546
type Platform struct {
@@ -202,6 +203,19 @@ func (p *Platform) GenIssuerCryptoMaterial(tmsNetwork string, fscNode string, wa
202203
return nh.GenIssuerCryptoMaterial(targetTMS, fscNode, walletID)
203204
}
204205

206+
func (p *Platform) GenOwnerCryptoMaterial(tmsNetwork string, fscNode string, walletID string) string {
207+
var targetTMS *topology2.TMS
208+
for _, tms := range p.Topology.TMSs {
209+
if tms.Network == tmsNetwork {
210+
targetTMS = tms
211+
}
212+
}
213+
Expect(targetTMS).ToNot(BeNil(), "failed to find TMS for network [%s]", tmsNetwork)
214+
215+
nh := p.NetworkHandlers[p.Context.TopologyByName(targetTMS.Network).Type()]
216+
return nh.GenOwnerCryptoMaterial(targetTMS, fscNode, walletID)
217+
}
218+
205219
func (p *Platform) AddNetworkHandler(label string, nh NetworkHandler) {
206220
p.NetworkHandlers[label] = nh
207221
}

integration/token/fungible/dloghsm/topology.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,7 @@ func Topology(backend string, tokenSDKDriver string, auditorAsIssuer bool) []api
187187
charlie.RegisterViewFactory("PruneInvalidUnspentTokens", &views.PruneInvalidUnspentTokensViewFactory{})
188188
charlie.RegisterViewFactory("WhoDeletedToken", &views.WhoDeletedTokenViewFactory{})
189189
charlie.RegisterViewFactory("ListVaultUnspentTokens", &views.ListVaultUnspentTokensViewFactory{})
190+
charlie.RegisterViewFactory("RegisterOwnerWallet", &views.RegisterOwnerWalletViewFactory{})
190191

191192
manager := fscTopology.AddNodeByName("manager").AddOptions(
192193
fabric.WithOrganization("Org2"),

integration/token/fungible/support.go

Lines changed: 27 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import (
2121
"github.com/hyperledger-labs/fabric-token-sdk/token/services/ttx"
2222
"github.com/hyperledger-labs/fabric-token-sdk/token/services/ttxdb"
2323
"github.com/hyperledger-labs/fabric-token-sdk/token/services/ttxdb/driver"
24-
token2 "github.com/hyperledger-labs/fabric-token-sdk/token/token"
24+
"github.com/hyperledger-labs/fabric-token-sdk/token/token"
2525
. "github.com/onsi/gomega"
2626
)
2727

@@ -131,9 +131,9 @@ func CheckBalance(network *integration.Infrastructure, id string, wallet string,
131131
b := &views.Balance{}
132132
common.JSONUnmarshal(res.([]byte), b)
133133
Expect(b.Type).To(BeEquivalentTo(typ))
134-
q, err := token2.ToQuantity(b.Quantity, 64)
134+
q, err := token.ToQuantity(b.Quantity, 64)
135135
Expect(err).NotTo(HaveOccurred())
136-
expectedQ := token2.NewQuantityFromUInt64(expected)
136+
expectedQ := token.NewQuantityFromUInt64(expected)
137137
Expect(expectedQ.Cmp(q)).To(BeEquivalentTo(0), "[%s]!=[%s]", expected, q)
138138
}
139139

@@ -171,26 +171,26 @@ func CheckSpending(network *integration.Infrastructure, id string, wallet string
171171
Expect(spending).To(Equal(expected))
172172
}
173173

174-
func ListIssuerHistory(network *integration.Infrastructure, wallet string, typ string) *token2.IssuedTokens {
174+
func ListIssuerHistory(network *integration.Infrastructure, wallet string, typ string) *token.IssuedTokens {
175175
res, err := network.Client("issuer").CallView("historyIssuedToken", common.JSONMarshall(&views.ListIssuedTokens{
176176
Wallet: wallet,
177177
TokenType: typ,
178178
}))
179179
Expect(err).NotTo(HaveOccurred())
180180

181-
issuedTokens := &token2.IssuedTokens{}
181+
issuedTokens := &token.IssuedTokens{}
182182
common.JSONUnmarshal(res.([]byte), issuedTokens)
183183
return issuedTokens
184184
}
185185

186-
func ListUnspentTokens(network *integration.Infrastructure, id string, wallet string, typ string) *token2.UnspentTokens {
186+
func ListUnspentTokens(network *integration.Infrastructure, id string, wallet string, typ string) *token.UnspentTokens {
187187
res, err := network.Client(id).CallView("history", common.JSONMarshall(&views.ListUnspentTokens{
188188
Wallet: wallet,
189189
TokenType: typ,
190190
}))
191191
Expect(err).NotTo(HaveOccurred())
192192

193-
unspentTokens := &token2.UnspentTokens{}
193+
unspentTokens := &token.UnspentTokens{}
194194
common.JSONUnmarshal(res.([]byte), unspentTokens)
195195
return unspentTokens
196196
}
@@ -231,7 +231,7 @@ func TransferCash(network *integration.Infrastructure, id string, wallet string,
231231
return ""
232232
}
233233

234-
func PrepareTransferCash(network *integration.Infrastructure, id string, wallet string, typ string, amount uint64, receiver string, auditor string, tokenID *token2.ID, expectedErrorMsgs ...string) (string, []byte) {
234+
func PrepareTransferCash(network *integration.Infrastructure, id string, wallet string, typ string, amount uint64, receiver string, auditor string, tokenID *token.ID, expectedErrorMsgs ...string) (string, []byte) {
235235
transferInput := &views.Transfer{
236236
Auditor: auditor,
237237
Wallet: wallet,
@@ -240,7 +240,7 @@ func PrepareTransferCash(network *integration.Infrastructure, id string, wallet
240240
Recipient: network.Identity(receiver),
241241
}
242242
if tokenID != nil {
243-
transferInput.TokenIDs = []*token2.ID{tokenID}
243+
transferInput.TokenIDs = []*token.ID{tokenID}
244244
}
245245
txBoxed, err := network.Client(id).CallView("prepareTransfer", common.JSONMarshall(transferInput))
246246
if len(expectedErrorMsgs) == 0 {
@@ -322,7 +322,7 @@ func GetTransactionInfo(network *integration.Infrastructure, id string, txnId st
322322
return info
323323
}
324324

325-
func TransferCashByIDs(network *integration.Infrastructure, id string, wallet string, ids []*token2.ID, amount uint64, receiver string, auditor string, failToRelease bool, expectedErrorMsgs ...string) string {
325+
func TransferCashByIDs(network *integration.Infrastructure, id string, wallet string, ids []*token.ID, amount uint64, receiver string, auditor string, failToRelease bool, expectedErrorMsgs ...string) string {
326326
txIDBoxed, err := network.Client(id).CallView("transfer", common.JSONMarshall(&views.Transfer{
327327
Auditor: auditor,
328328
Wallet: wallet,
@@ -379,7 +379,7 @@ func RedeemCash(network *integration.Infrastructure, id string, wallet string, t
379379
Expect(network.Client("auditor").IsTxFinal(common.JSONUnmarshalString(txid))).NotTo(HaveOccurred())
380380
}
381381

382-
func RedeemCashByIDs(network *integration.Infrastructure, id string, wallet string, ids []*token2.ID, amount uint64, auditor string) {
382+
func RedeemCashByIDs(network *integration.Infrastructure, id string, wallet string, ids []*token.ID, amount uint64, auditor string) {
383383
txid, err := network.Client(id).CallView("redeem", common.JSONMarshall(&views.Redeem{
384384
Auditor: auditor,
385385
Wallet: wallet,
@@ -450,33 +450,33 @@ func PruneInvalidUnspentTokens(network *integration.Infrastructure, ids ...strin
450450
eIDBoxed, err := network.Client(id).CallView("PruneInvalidUnspentTokens", common.JSONMarshall(&views.PruneInvalidUnspentTokens{}))
451451
Expect(err).NotTo(HaveOccurred())
452452

453-
var deleted []*token2.ID
453+
var deleted []*token.ID
454454
common.JSONUnmarshal(eIDBoxed.([]byte), &deleted)
455455
Expect(len(deleted)).To(BeZero())
456456
}
457457
}
458458

459-
func ListVaultUnspentTokens(network *integration.Infrastructure, id string) []*token2.ID {
459+
func ListVaultUnspentTokens(network *integration.Infrastructure, id string) []*token.ID {
460460
res, err := network.Client(id).CallView("ListVaultUnspentTokens", common.JSONMarshall(&views.ListVaultUnspentTokens{}))
461461
Expect(err).NotTo(HaveOccurred())
462462

463-
unspentTokens := &token2.UnspentTokens{}
463+
unspentTokens := &token.UnspentTokens{}
464464
common.JSONUnmarshal(res.([]byte), unspentTokens)
465465
count := unspentTokens.Count()
466-
var IDs []*token2.ID
466+
var IDs []*token.ID
467467
for i := 0; i < count; i++ {
468468
tok := unspentTokens.At(i)
469469
IDs = append(IDs, tok.Id)
470470
}
471471
return IDs
472472
}
473473

474-
func CheckIfExistsInVault(network *integration.Infrastructure, id string, tokenIDs []*token2.ID) {
474+
func CheckIfExistsInVault(network *integration.Infrastructure, id string, tokenIDs []*token.ID) {
475475
_, err := network.Client(id).CallView("CheckIfExistsInVault", common.JSONMarshall(&views.CheckIfExistsInVault{IDs: tokenIDs}))
476476
Expect(err).NotTo(HaveOccurred())
477477
}
478478

479-
func WhoDeletedToken(network *integration.Infrastructure, id string, tokenIDs []*token2.ID, txIDs ...string) *views.WhoDeletedTokenResult {
479+
func WhoDeletedToken(network *integration.Infrastructure, id string, tokenIDs []*token.ID, txIDs ...string) *views.WhoDeletedTokenResult {
480480
boxed, err := network.Client(id).CallView("WhoDeletedToken", common.JSONMarshall(&views.WhoDeletedToken{
481481
TokenIDs: tokenIDs,
482482
}))
@@ -544,4 +544,14 @@ func RegisterIssuerWallet(network *integration.Infrastructure, id string, wallet
544544
Path: walletPath,
545545
}))
546546
Expect(err).NotTo(HaveOccurred())
547+
network.Ctx.SetViewClient(walletPath, network.Client(id))
548+
}
549+
550+
func RegisterOwnerWallet(network *integration.Infrastructure, id string, walletID, walletPath string) {
551+
_, err := network.Client(id).CallView("RegisterOwnerWallet", common.JSONMarshall(&views.RegisterOwnerWallet{
552+
ID: walletID,
553+
Path: walletPath,
554+
}))
555+
Expect(err).NotTo(HaveOccurred())
556+
network.Ctx.SetViewClient(walletID, network.Client(id))
547557
}

integration/token/fungible/tests.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -328,6 +328,8 @@ func TestAll(network *integration.Infrastructure, auditor string) {
328328

329329
IssueCash(network, "", "USD", 1, "alice", auditor, true)
330330

331+
testTwoGeneratedOwnerWalletsSameNode(network, auditor)
332+
331333
CheckBalanceAndHolding(network, "alice", "", "USD", 10)
332334
CheckBalanceAndHolding(network, "alice", "", "EUR", 0)
333335
CheckBalanceAndHolding(network, "bob", "", "EUR", 30)
@@ -644,3 +646,19 @@ func TestAll(network *integration.Infrastructure, auditor string) {
644646
CheckIfExistsInVault(network, auditor, IDs)
645647
}
646648
}
649+
650+
func testTwoGeneratedOwnerWalletsSameNode(network *integration.Infrastructure, auditor string) {
651+
tokenPlatform := token.GetPlatform(network.Ctx, "token")
652+
newOwnerWalletPath1 := tokenPlatform.GenOwnerCryptoMaterial(tokenPlatform.Topology.TMSs[0].BackendTopology.Name(), "charlie", "charlie.ExtraId1")
653+
RegisterOwnerWallet(network, "charlie", "charlie.ExtraId1", newOwnerWalletPath1)
654+
newOwnerWalletPath2 := tokenPlatform.GenOwnerCryptoMaterial(tokenPlatform.Topology.TMSs[0].BackendTopology.Name(), "charlie", "charlie.ExtraId2")
655+
RegisterOwnerWallet(network, "charlie", "charlie.ExtraId2", newOwnerWalletPath2)
656+
657+
IssueCash(network, "", "SPE", 100, "charlie", auditor, true)
658+
TransferCash(network, "charlie", "", "SPE", 25, "charlie.ExtraId1", auditor)
659+
TransferCash(network, "charlie", "charlie.ExtraId1", "SPE", 15, "charlie.ExtraId2", auditor)
660+
661+
CheckBalanceAndHolding(network, "charlie", "", "SPE", 75)
662+
CheckBalanceAndHolding(network, "charlie", "charlie.ExtraId1", "SPE", 10)
663+
CheckBalanceAndHolding(network, "charlie", "charlie.ExtraId2", "SPE", 15)
664+
}

integration/token/fungible/topology.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,7 @@ func Topology(backend string, tokenSDKDriver string, auditorAsIssuer bool) []api
187187
charlie.RegisterViewFactory("PruneInvalidUnspentTokens", &views.PruneInvalidUnspentTokensViewFactory{})
188188
charlie.RegisterViewFactory("WhoDeletedToken", &views.WhoDeletedTokenViewFactory{})
189189
charlie.RegisterViewFactory("ListVaultUnspentTokens", &views.ListVaultUnspentTokensViewFactory{})
190+
charlie.RegisterViewFactory("RegisterOwnerWallet", &views.RegisterOwnerWalletViewFactory{})
190191

191192
manager := fscTopology.AddNodeByName("manager").AddOptions(
192193
fabric.WithOrganization("Org2"),

integration/token/fungible/views/wallets.go

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,3 +42,32 @@ func (p *RegisterIssuerWalletViewFactory) NewView(in []byte) (view.View, error)
4242

4343
return f, nil
4444
}
45+
46+
type RegisterOwnerWallet struct {
47+
TMSID token.TMSID
48+
ID string
49+
Path string
50+
}
51+
52+
// RegisterOwnerWalletView is a view that registers an owner wallet
53+
type RegisterOwnerWalletView struct {
54+
*RegisterOwnerWallet
55+
}
56+
57+
func (r *RegisterOwnerWalletView) Call(context view.Context) (interface{}, error) {
58+
tms := token.GetManagementService(context, token.WithTMSID(r.TMSID))
59+
assert.NotNil(tms, "tms not found [%s]", r.TMSID)
60+
err := tms.WalletManager().RegisterOwnerWallet(r.ID, r.Path)
61+
assert.NoError(err, "failed to register owner wallet [%s:%s]", r.ID, r.TMSID)
62+
return nil, nil
63+
}
64+
65+
type RegisterOwnerWalletViewFactory struct{}
66+
67+
func (p *RegisterOwnerWalletViewFactory) NewView(in []byte) (view.View, error) {
68+
f := &RegisterOwnerWalletView{RegisterOwnerWallet: &RegisterOwnerWallet{}}
69+
err := json.Unmarshal(in, f.RegisterOwnerWallet)
70+
assert.NoError(err, "failed unmarshalling input")
71+
72+
return f, nil
73+
}

token/core/identity/msp/idemix/wallet.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,5 +148,6 @@ func (w *wallet) MapToID(v interface{}) (view.Identity, string) {
148148

149149
// RegisterIdentity registers the given identity
150150
func (w *wallet) RegisterIdentity(id string, path string) error {
151+
logger.Debugf("register idemix identity [%s:%s]", id, path)
151152
return w.localMembership.RegisterIdentity(id, path)
152153
}

token/core/identity/msp/x509/wallet.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,5 +165,6 @@ func (w *wallet) MapToID(v interface{}) (view.Identity, string) {
165165

166166
// RegisterIdentity registers the given identity
167167
func (w *wallet) RegisterIdentity(id string, path string) error {
168+
logger.Debugf("register x509 identity [%s:%s]", id, path)
168169
return w.localMembership.RegisterIdentity(id, path)
169170
}

0 commit comments

Comments
 (0)