Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

asset transfer #447 #437

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -106,12 +106,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
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
19 changes: 19 additions & 0 deletions integration/token/interop/dlog/dlog_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,4 +142,23 @@ 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")...,
)
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 @@ -142,4 +142,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")...,
)
Expect(err).NotTo(HaveOccurred())
ii.RegisterPlatformFactory(token.NewPlatformFactory())
ii.Generate()
ii.Start()
})

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

})
168 changes: 164 additions & 4 deletions integration/token/interop/support.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"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"
pledge2 "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 @@ -359,7 +360,7 @@ func HTLCCheckExistenceReceivedExpiredByHash(network *integration.Infrastructure
}
}

func htlcClaim(network *integration.Infrastructure, tmsID token.TMSID, id string, wallet string, preImage []byte, errorMsgs ...string) string {
func HTLCClaim(network *integration.Infrastructure, tmsID token.TMSID, id string, wallet string, preImage []byte, errorMsgs ...string) string {
txIDBoxed, err := network.Client(id).CallView("htlc.claim", common.JSONMarshall(&htlc.Claim{
TMSID: tmsID,
Wallet: wallet,
Expand Down Expand Up @@ -398,7 +399,7 @@ func htlcClaim(network *integration.Infrastructure, tmsID token.TMSID, id string
}
}

func fastExchange(network *integration.Infrastructure, id string, recipient string, tmsID1 token.TMSID, typ1 string, amount1 uint64, tmsID2 token.TMSID, typ2 string, amount2 uint64, deadline time.Duration) {
func FastExchange(network *integration.Infrastructure, id string, recipient string, tmsID1 token.TMSID, typ1 string, amount1 uint64, tmsID2 token.TMSID, typ2 string, amount2 uint64, deadline time.Duration) {
_, err := network.Client(id).CallView("htlc.fastExchange", common.JSONMarshall(&htlc.FastExchange{
Recipient: network.Identity(recipient),
TMSID1: tmsID1,
Expand All @@ -414,7 +415,7 @@ func fastExchange(network *integration.Infrastructure, id string, recipient stri
time.Sleep(10 * time.Second)
}

func scan(network *integration.Infrastructure, id string, hash []byte, hashFunc crypto.Hash, startingTransactionID string, opts ...token.ServiceOption) {
func Scan(network *integration.Infrastructure, id string, hash []byte, hashFunc crypto.Hash, startingTransactionID string, opts ...token.ServiceOption) {
options, err := token.CompileServiceOptions(opts...)
Expect(err).NotTo(HaveOccurred())

Expand All @@ -428,7 +429,7 @@ func scan(network *integration.Infrastructure, id string, hash []byte, hashFunc
Expect(err).NotTo(HaveOccurred())
}

func scanWithError(network *integration.Infrastructure, id string, hash []byte, hashFunc crypto.Hash, startingTransactionID string, errorMsgs []string, opts ...token.ServiceOption) {
func ScanWithError(network *integration.Infrastructure, id string, hash []byte, hashFunc crypto.Hash, startingTransactionID string, errorMsgs []string, opts ...token.ServiceOption) {
options, err := token.CompileServiceOptions(opts...)
Expect(err).NotTo(HaveOccurred())

Expand All @@ -444,3 +445,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(&pledge2.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 := &pledge2.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(&pledge2.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(&pledge2.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(&pledge2.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(&pledge2.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(&pledge2.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(&pledge2.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(&pledge2.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(&pledge2.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(&pledge2.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(&pledge2.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