Skip to content

Commit

Permalink
asset transfer
Browse files Browse the repository at this point in the history
Signed-off-by: Angelo De Caro <[email protected]>
  • Loading branch information
adecaro committed May 27, 2024
1 parent a4be7c0 commit 13f5dd3
Show file tree
Hide file tree
Showing 87 changed files with 5,994 additions and 223 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -107,12 +107,14 @@ jobs:
interop-fabtoken-t4,
interop-fabtoken-t5,
interop-fabtoken-t6,
interop-fabtoken-t7,
interop-dlog-t1,
interop-dlog-t2,
interop-dlog-t3,
interop-dlog-t4,
interop-dlog-t5,
interop-dlog-t6,
interop-dlog-t7,
]

steps:
Expand Down
9 changes: 8 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ FABRIC_VERSION ?= 2.5.0
FABRIC_CA_VERSION ?= 1.5.7
FABRIC_TWO_DIGIT_VERSION = $(shell echo $(FABRIC_VERSION) | cut -d '.' -f 1,2)
ORION_VERSION=v0.2.5
WEAVER_VERSION=1.2.1

# need to install fabric binaries outside of fts tree for now (due to chaincode packaging issues)
FABRIC_BINARY_BASE=$(PWD)/../fabric
Expand Down Expand Up @@ -49,7 +50,7 @@ install-softhsm:
./ci/scripts/install_softhsm.sh

.PHONY: docker-images
docker-images: fabric-docker-images orion-server-images monitoring-docker-images
docker-images: fabric-docker-images orion-server-images monitoring-docker-images weaver-docker-images

.PHONY: fabric-docker-images
fabric-docker-images:
Expand All @@ -70,6 +71,12 @@ orion-server-images:
docker pull orionbcdb/orion-server:$(ORION_VERSION)
docker image tag orionbcdb/orion-server:$(ORION_VERSION) orionbcdb/orion-server:latest

.PHONY: weaver-docker-images
weaver-docker-images:
docker pull ghcr.io/hyperledger-labs/weaver-fabric-driver:$(WEAVER_VERSION)
docker image tag ghcr.io/hyperledger-labs/weaver-fabric-driver:$(WEAVER_VERSION) hyperledger-labs/weaver-fabric-driver:latest
docker pull ghcr.io/hyperledger-labs/weaver-relay-server:$(WEAVER_VERSION)
docker image tag ghcr.io/hyperledger-labs/weaver-relay-server:$(WEAVER_VERSION) hyperledger-labs/weaver-relay-server:latest

.PHONY: integration-tests-nft-dlog
integration-tests-nft-dlog:
Expand Down
8 changes: 0 additions & 8 deletions integration/nwo/token/topology.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@ SPDX-License-Identifier: Apache-2.0
package token

import (
"github.com/hyperledger-labs/fabric-smart-client/integration/nwo/fsc"
"github.com/hyperledger-labs/fabric-smart-client/integration/nwo/fsc/node"
"github.com/hyperledger-labs/fabric-smart-client/pkg/api"
"github.com/hyperledger-labs/fabric-token-sdk/integration/nwo/token/topology"
"github.com/hyperledger-labs/fabric-token-sdk/token/services/ttx"
. "github.com/onsi/gomega"
Expand Down Expand Up @@ -83,12 +81,6 @@ func (t *Topology) AddTMS(fscNodes []*node.Node, backend BackedTopology, channel
return tms
}

func (t *Topology) SetSDK(fscTopology *fsc.Topology, sdk api.SDK) {
for _, node := range fscTopology.Nodes {
node.AddSDK(sdk)
}
}

func (t *Topology) GetTMSs() []*topology.TMS {
return t.TMSs
}
2 changes: 2 additions & 0 deletions integration/ports.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ const (
ZKATDLogInteropHTLCSwapNoCrossTwoFabricNetworks
ZKATDLogInteropHTLCOrion
ZKATDLogInteropHTLCSwapNoCrossWithOrionAndFabricNetworks
FabTokenInteropAssetTransfer
ZKATDLogInteropAssetTransfer
)

// StartPortForNode On linux, the default ephemeral port range is 32768-60999 and can be
Expand Down
18 changes: 18 additions & 0 deletions integration/token/interop/dlog/dlog_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,4 +145,22 @@ var _ = Describe("DLog end to end", func() {
})
})

Describe("Asset Transfer With Two Fabric Networks", func() {
BeforeEach(func() {
var err error
ii, err = integration.New(
integration2.ZKATDLogInteropAssetTransfer.StartPortForNode(),
"",
interop.AssetTransferTopology("dlog", &fabric3.SDK{}, &sdk.SDK{})...,
)
Expect(err).NotTo(HaveOccurred())
ii.RegisterPlatformFactory(token.NewPlatformFactory())
ii.Generate()
ii.Start()
})

It("Performed a cross network asset transfer", func() {
interop.TestAssetTransferWithTwoNetworks(ii)
})
})
})
19 changes: 19 additions & 0 deletions integration/token/interop/fabtoken/fabtoken_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,4 +145,23 @@ var _ = Describe("FabToken end to end", func() {
})
})

Describe("Asset Transfer With Two Fabric Networks", func() {
BeforeEach(func() {
var err error
ii, err = integration.New(
integration2.FabTokenInteropAssetTransfer.StartPortForNode(),
"",
interop.AssetTransferTopology("fabtoken", &fabric3.SDK{}, &sdk.SDK{})...,
)
Expect(err).NotTo(HaveOccurred())
ii.RegisterPlatformFactory(token.NewPlatformFactory())
ii.Generate()
ii.Start()
})

It("Performed a cross network asset transfer", func() {
interop.TestAssetTransferWithTwoNetworks(ii)
})
})

})
161 changes: 161 additions & 0 deletions integration/token/interop/support.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,12 @@ import (

"github.com/hyperledger-labs/fabric-smart-client/integration"
"github.com/hyperledger-labs/fabric-smart-client/integration/nwo/common"
"github.com/hyperledger-labs/fabric-smart-client/pkg/api"
common2 "github.com/hyperledger-labs/fabric-token-sdk/integration/token/common"
"github.com/hyperledger-labs/fabric-token-sdk/integration/token/fungible/views"
views2 "github.com/hyperledger-labs/fabric-token-sdk/integration/token/interop/views"
"github.com/hyperledger-labs/fabric-token-sdk/integration/token/interop/views/htlc"
"github.com/hyperledger-labs/fabric-token-sdk/integration/token/interop/views/pledge"
"github.com/hyperledger-labs/fabric-token-sdk/token"
token2 "github.com/hyperledger-labs/fabric-token-sdk/token/token"
. "github.com/onsi/gomega"
Expand Down Expand Up @@ -422,3 +424,162 @@ func scanWithError(network *integration.Infrastructure, id string, hash []byte,
Expect(err.Error()).To(ContainSubstring(msg))
}
}

func Pledge(network *integration.Infrastructure, sender, wallet, typ string, amount uint64, receiver, issuer, destNetwork string, deadline time.Duration, opts ...token.ServiceOption) (string, string) {
options, err := token.CompileServiceOptions(opts...)
Expect(err).NotTo(HaveOccurred())
raw, err := network.Client(sender).CallView("transfer.pledge", common.JSONMarshall(&pledge.Pledge{
OriginTMSID: options.TMSID(),
Amount: amount,
ReclamationDeadline: deadline,
Type: typ,
DestinationNetworkURL: destNetwork,
Issuer: network.Identity(issuer),
Recipient: network.Identity(receiver),
OriginWallet: wallet,
}))
Expect(err).NotTo(HaveOccurred())
info := &pledge.Result{}
common.JSONUnmarshal(raw.([]byte), info)
Expect(network.Client(sender).IsTxFinal(
info.TxID,
api.WithNetwork(options.TMSID().Network),
api.WithChannel(options.TMSID().Channel),
)).NotTo(HaveOccurred())

return info.TxID, info.PledgeID
}

func PledgeIDExists(network *integration.Infrastructure, id, pledgeid string, startingTransactionID string, opts ...token.ServiceOption) {
options, err := token.CompileServiceOptions(opts...)
Expect(err).NotTo(HaveOccurred())
raw, err := network.Client(id).CallView("transfer.scan", common.JSONMarshall(&pledge.Scan{
TMSID: options.TMSID(),
Timeout: 120 * time.Second,
PledgeID: pledgeid,
StartingTransactionID: startingTransactionID,
}))
Expect(err).NotTo(HaveOccurred())
var res bool
common.JSONUnmarshal(raw.([]byte), &res)
Expect(res).Should(BeTrue())
}

func ScanPledgeIDWithError(network *integration.Infrastructure, id, pledgeid string, startingTransactionID string, errorMsgs []string, opts ...token.ServiceOption) {
options, err := token.CompileServiceOptions(opts...)
Expect(err).NotTo(HaveOccurred())
_, err = network.Client(id).CallView("transfer.scan", common.JSONMarshall(&pledge.Scan{
TMSID: options.TMSID(),
Timeout: 120 * time.Second,
PledgeID: pledgeid,
StartingTransactionID: startingTransactionID,
}))
Expect(err).To(HaveOccurred())
for _, msg := range errorMsgs {
Expect(err.Error()).To(ContainSubstring(msg))
}
}

func Reclaim(network *integration.Infrastructure, sender string, wallet string, txid string, opts ...token.ServiceOption) string {
options, err := token.CompileServiceOptions(opts...)
Expect(err).NotTo(HaveOccurred())
txID, err := network.Client(sender).CallView("transfer.reclaim", common.JSONMarshall(&pledge.Reclaim{ // TokenID contains the identifier of the token to be reclaimed.
TokenID: &token2.ID{TxId: txid, Index: 0},
WalletID: wallet,
TMSID: options.TMSID(),
}))
Expect(err).NotTo(HaveOccurred())
Expect(network.Client("alice").IsTxFinal(common.JSONUnmarshalString(txID))).NotTo(HaveOccurred())

return common.JSONUnmarshalString(txID)
}

func ReclaimWithError(network *integration.Infrastructure, sender string, wallet string, txid string, opts ...token.ServiceOption) {
options, err := token.CompileServiceOptions(opts...)
Expect(err).NotTo(HaveOccurred())
_, err = network.Client(sender).CallView("transfer.reclaim", common.JSONMarshall(&pledge.Reclaim{ // TokenID contains the identifier of the token to be reclaimed.
TokenID: &token2.ID{TxId: txid, Index: 0},
WalletID: wallet,
TMSID: options.TMSID(),
}))
Expect(err).To(HaveOccurred())
}

func Claim(network *integration.Infrastructure, recipient string, issuer string, originTokenID *token2.ID) string {
txid, err := network.Client(recipient).CallView("transfer.claim", common.JSONMarshall(&pledge.Claim{
OriginTokenID: originTokenID,
Issuer: issuer,
}))
Expect(err).NotTo(HaveOccurred())
Expect(network.Client(recipient).IsTxFinal(common.JSONUnmarshalString(txid))).NotTo(HaveOccurred())

return common.JSONUnmarshalString(txid)
}

func ClaimWithError(network *integration.Infrastructure, recipient string, issuer string, originTokenID *token2.ID) {
_, err := network.Client(recipient).CallView("transfer.claim", common.JSONMarshall(&pledge.Claim{
OriginTokenID: originTokenID,
Issuer: issuer,
}))
Expect(err).To(HaveOccurred())
}

func RedeemWithTMS(network *integration.Infrastructure, issuer string, tokenID *token2.ID, opts ...token.ServiceOption) string {
options, err := token.CompileServiceOptions(opts...)
Expect(err).NotTo(HaveOccurred())
txID, err := network.Client(issuer).CallView("transfer.redeem", common.JSONMarshall(&pledge.Redeem{
TokenID: tokenID,
TMSID: options.TMSID(),
}))
Expect(err).NotTo(HaveOccurred())
Expect(network.Client(issuer).IsTxFinal(common.JSONUnmarshalString(txID))).NotTo(HaveOccurred())

return common.JSONUnmarshalString(txID)
}

func RedeemWithTMSAndError(network *integration.Infrastructure, issuer string, tokenID *token2.ID, opt token.ServiceOption, errorMsgs ...string) {
options, err := token.CompileServiceOptions(opt)
Expect(err).NotTo(HaveOccurred())
_, err = network.Client(issuer).CallView("transfer.redeem", common.JSONMarshall(&pledge.Redeem{
TokenID: tokenID,
TMSID: options.TMSID(),
}))
Expect(err).To(HaveOccurred())
for _, msg := range errorMsgs {
Expect(err.Error()).To(ContainSubstring(msg))
}
}

func FastTransferPledgeClaim(network *integration.Infrastructure, sender, wallet, typ string, amount uint64, receiver, issuer, destNetwork string, deadline time.Duration, opts ...token.ServiceOption) {
options, err := token.CompileServiceOptions(opts...)
Expect(err).NotTo(HaveOccurred())

_, err = network.Client(sender).CallView("transfer.fastTransfer", common.JSONMarshall(&pledge.FastPledgeClaim{
OriginTMSID: options.TMSID(),
Amount: amount,
ReclamationDeadline: deadline,
Type: typ,
DestinationNetworkURL: destNetwork,
Issuer: network.Identity(issuer),
Recipient: network.Identity(receiver),
OriginWallet: wallet,
}))
Expect(err).NotTo(HaveOccurred())
}

func FastTransferPledgeReclaim(network *integration.Infrastructure, sender, wallet, typ string, amount uint64, receiver, issuer, destNetwork string, deadline time.Duration, opts ...token.ServiceOption) {
options, err := token.CompileServiceOptions(opts...)
Expect(err).NotTo(HaveOccurred())

_, err = network.Client(sender).CallView("transfer.fastPledgeReclaim", common.JSONMarshall(&pledge.FastPledgeReClaim{
OriginTMSID: options.TMSID(),
Amount: amount,
ReclamationDeadline: deadline,
Type: typ,
DestinationNetworkURL: destNetwork,
Issuer: network.Identity(issuer),
Recipient: network.Identity(receiver),
OriginWallet: wallet,
}))
Expect(err).NotTo(HaveOccurred())
}
Loading

0 comments on commit 13f5dd3

Please sign in to comment.