Skip to content

Commit

Permalink
rebase fix
Browse files Browse the repository at this point in the history
Signed-off-by: Angelo De Caro <[email protected]>
  • Loading branch information
adecaro committed Nov 12, 2024
1 parent c6e4eb7 commit f9d2870
Show file tree
Hide file tree
Showing 22 changed files with 222 additions and 146 deletions.
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,8 @@ require (
github.com/hashicorp/golang-lru/v2 v2.0.7 // indirect
github.com/hashicorp/hcl v1.0.0 // indirect
github.com/huin/goupnp v1.3.0 // indirect
github.com/hyperledger-labs/weaver-dlt-interoperability/common/protos-go v1.2.3-alpha.1 // indirect
github.com/hyperledger-labs/weaver-dlt-interoperability/sdks/fabric/go-sdk v1.2.3-alpha.1.0.20210812140206-37f430515b8c // indirect
github.com/hyperledger/fabric-amcl v0.0.0-20230602173724-9e02669dceb2 // indirect
github.com/hyperledger/fabric-private-chaincode v1.0.0-rc3.0.20231026135044-67a19b0fcda0 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
Expand Down
85 changes: 85 additions & 0 deletions go.sum

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion integration/ports.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,6 @@ const (
ZKATDLogInteropHTLCSwapNoCrossWithOrionAndFabricNetworks
FabTokenInteropAssetTransfer
ZKATDLogInteropAssetTransfer
)

Mixed
)
40 changes: 20 additions & 20 deletions integration/token/interop/dlog/dlog_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,13 @@ var _ = Describe("DLog end to end", func() {
BeforeEach(ts.Setup)
It("Performed an htlc based atomic swap", Label("T6"), func() { interop.TestHTLCNoCrossClaimTwoNetworks(ts.II, selector) })
})

Describe("Asset Transfer With Two Fabric Networks", func() {
ts, selector := newTestSuiteInteropAssetTransfer(t.CommType, t.ReplicationFactor, "alice", "bob")
AfterEach(ts.TearDown)
BeforeEach(ts.Setup)
It("Performed a cross network asset transfer", Label("T7"), func() { interop.TestAssetTransferWithTwoNetworks(ts.II, selector) })
})
}
})

Expand Down Expand Up @@ -106,33 +113,26 @@ func newTestSuiteNoCrossClaimFabric(commType fsc.P2PCommunicationType, factor in
return ts, selector
}

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{}, &fdlog.SDK{})...,
)
Expect(err).NotTo(HaveOccurred())
ii.RegisterPlatformFactory(token.NewPlatformFactory())
ii.Generate()
ii.Start()
})

It("Performed a cross network asset transfer", func() {
interop.TestAssetTransferWithTwoNetworks(ii)
})
})
})
func newTestSuiteNoCrossClaimOrion(commType fsc.P2PCommunicationType, factor int, names ...string) (*token2.TestSuite, *token2.ReplicaSelector) {
opts, selector := token2.NewReplicationOptions(factor, names...)
ts := token2.NewTestSuite(opts.SQLConfigs, integration2.ZKATDLogInteropHTLCSwapNoCrossWithOrionAndFabricNetworks.StartPortForNode, interop.HTLCNoCrossClaimWithOrionTopology(common.Opts{
CommType: commType,
ReplicationOpts: opts,
TokenSDKDriver: "dlog",
SDKs: []api2.SDK{&fodlog.SDK{}},
FSCLogSpec: "token-sdk=debug:fabric-sdk=debug:view-sdk=debug:info",
// FSCLogSpec: "token-sdk=debug:fabric-sdk=debug:view-sdk=debug:info",
}))
return ts, selector
}

func newTestSuiteInteropAssetTransfer(commType fsc.P2PCommunicationType, factor int, names ...string) (*token2.TestSuite, *token2.ReplicaSelector) {
opts, selector := token2.NewReplicationOptions(factor, names...)
ts := token2.NewTestSuite(opts.SQLConfigs, integration2.ZKATDLogInteropAssetTransfer.StartPortForNode, interop.AssetTransferTopology(common.Opts{
CommType: commType,
ReplicationOpts: opts,
TokenSDKDriver: "dlog",
SDKs: []api2.SDK{&fdlog.SDK{}},
// FSCLogSpec: "token-sdk=debug:fabric-sdk=debug:view-sdk=debug:info",
}))
return ts, selector
}
39 changes: 19 additions & 20 deletions integration/token/interop/fabtoken/fabtoken_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,13 @@ var _ = Describe("FabToken end to end", func() {
BeforeEach(ts.Setup)
It("Performed an htlc based atomic swap", Label("T6"), func() { interop.TestHTLCNoCrossClaimTwoNetworks(ts.II, selector) })
})

Describe("Asset Transfer With Two Fabric Networks", func() {
ts, selector := newTestSuiteInteropAssetTransfer(t.CommType, t.ReplicationFactor, "alice", "bob")
AfterEach(ts.TearDown)
BeforeEach(ts.Setup)
It("Performed a cross network asset transfer", Label("T7"), func() { interop.TestAssetTransferWithTwoNetworks(ts.II, selector) })
})
}
})

Expand Down Expand Up @@ -106,26 +113,6 @@ func newTestSuiteNoCrossClaimFabric(commType fsc.P2PCommunicationType, factor in
return ts, selector
}

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{}, &ffabtoken.SDK{})...,
)
Expect(err).NotTo(HaveOccurred())
ii.RegisterPlatformFactory(token.NewPlatformFactory())
ii.Generate()
ii.Start()
})

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

})
func newTestSuiteNoCrossClaimOrion(commType fsc.P2PCommunicationType, factor int, names ...string) (*token2.TestSuite, *token2.ReplicaSelector) {
opts, selector := token2.NewReplicationOptions(factor, names...)
ts := token2.NewTestSuite(opts.SQLConfigs, integration2.FabTokenInteropHTLCSwapNoCrossWithOrionAndFabricNetworks.StartPortForNode, interop.HTLCNoCrossClaimWithOrionTopology(common.Opts{
Expand All @@ -136,3 +123,15 @@ func newTestSuiteNoCrossClaimOrion(commType fsc.P2PCommunicationType, factor int
}))
return ts, selector
}

func newTestSuiteInteropAssetTransfer(commType fsc.P2PCommunicationType, factor int, names ...string) (*token2.TestSuite, *token2.ReplicaSelector) {
opts, selector := token2.NewReplicationOptions(factor, names...)
ts := token2.NewTestSuite(opts.SQLConfigs, integration2.ZKATDLogInteropAssetTransfer.StartPortForNode, interop.AssetTransferTopology(common.Opts{
CommType: commType,
ReplicationOpts: opts,
TokenSDKDriver: "fabtoken",
SDKs: []api2.SDK{&ffabtoken.SDK{}},
// FSCLogSpec: "token-sdk=debug:fabric-sdk=debug:view-sdk=debug:info",
}))
return ts, selector
}
2 changes: 1 addition & 1 deletion integration/token/interop/support.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ import (

"github.com/hyperledger-labs/fabric-smart-client/integration"
"github.com/hyperledger-labs/fabric-smart-client/integration/nwo/common"
token3 "github.com/hyperledger-labs/fabric-token-sdk/integration/token"
"github.com/hyperledger-labs/fabric-smart-client/pkg/api"
token3 "github.com/hyperledger-labs/fabric-token-sdk/integration/token"
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"
Expand Down
83 changes: 44 additions & 39 deletions integration/token/interop/tests.go
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,12 @@ func TestFastExchange(network *integration.Infrastructure, sel *token2.ReplicaSe
Eventually(CheckBalanceReturnError).WithArguments(network, sel.Get("bob"), "", "USD", uint64(20), token.WithTMSID(beta)).WithTimeout(1 * time.Minute).WithPolling(15 * time.Second).Should(Succeed())
}

func TestAssetTransferWithTwoNetworks(network *integration.Infrastructure) {
func TestAssetTransferWithTwoNetworks(network *integration.Infrastructure, sel *token2.ReplicaSelector) {
issuer := sel.Get("issuer")
alice := sel.Get("alice")
bob := sel.Get("bob")
auditor := sel.Get("auditor")

// give some time to the nodes to get the public parameters
time.Sleep(10 * time.Second)

Expand All @@ -369,113 +374,113 @@ func TestAssetTransferWithTwoNetworks(network *integration.Infrastructure) {

IssueCashWithTMS(network, alpha, "issuerAlpha", "", "USD", 50, "alice")
IssueCashWithTMS(network, alpha, "issuerAlpha", "", "EUR", 10, "alice")
CheckBalance(network, "alice", "", "USD", 50)
CheckBalance(network, "alice", "", "EUR", 10)
CheckBalance(network, alice, "", "USD", 50)
CheckBalance(network, alice, "", "EUR", 10)

// Pledge + Claim
txid, pledgeid := Pledge(network, "alice", "", "USD", 50, "bob", "issuerAlpha", betaURL, time.Minute*1, token.WithTMSID(alpha))
CheckBalance(network, "alice", "", "USD", 0)
txid, pledgeid := Pledge(network, alice, "", "USD", 50, "bob", "issuerAlpha", betaURL, time.Minute*1, token.WithTMSID(alpha))
CheckBalance(network, alice, "", "USD", 0)
CheckBalance(network, "bob", "", "USD", 0)

PledgeIDExists(network, "alice", pledgeid, txid, token.WithTMSID(alpha))
PledgeIDExists(network, alice, pledgeid, txid, token.WithTMSID(alpha))

Claim(network, "bob", "issuerBeta", &token2.ID{TxId: txid, Index: 0})
CheckBalance(network, "alice", "", "USD", 0)
CheckBalance(network, alice, "", "USD", 0)
CheckBalance(network, "bob", "", "USD", 50)

time.Sleep(time.Minute * 1)
RedeemWithTMS(network, "issuerAlpha", &token2.ID{TxId: txid, Index: 0}, token.WithTMSID(alpha))
CheckBalance(network, "alice", "", "USD", 0)
CheckBalance(network, alice, "", "USD", 0)
CheckBalance(network, "bob", "", "USD", 50)

// Pledge + Reclaim

IssueCashWithTMS(network, alpha, "issuerAlpha", "", "USD", 50, "alice")
CheckBalance(network, "alice", "", "USD", 50, token.WithTMSID(alpha))
txid, _ = Pledge(network, "alice", "", "USD", 50, "bob", "issuerAlpha", betaURL, time.Second*10, token.WithTMSID(alpha))
IssueCashWithTMS(network, alpha, "issuerAlpha", "", "USD", 50, alice)
CheckBalance(network, alice, "", "USD", 50, token.WithTMSID(alpha))
txid, _ = Pledge(network, alice, "", "USD", 50, "bob", "issuerAlpha", betaURL, time.Second*10, token.WithTMSID(alpha))

time.Sleep(time.Second * 15)
Reclaim(network, "alice", "", txid, token.WithTMSID(alpha))
CheckBalance(network, "alice", "", "USD", 50, token.WithTMSID(alpha))
Reclaim(network, alice, "", txid, token.WithTMSID(alpha))
CheckBalance(network, alice, "", "USD", 50, token.WithTMSID(alpha))
CheckBalance(network, "bob", "", "USD", 50)

RedeemWithTMSAndError(network, "issuerAlpha", &token2.ID{TxId: txid, Index: 0}, token.WithTMSID(alpha))
CheckBalance(network, "alice", "", "USD", 50, token.WithTMSID(alpha))
CheckBalance(network, alice, "", "USD", 50, token.WithTMSID(alpha))
CheckBalance(network, "bob", "", "USD", 50)

ScanPledgeIDWithError(network, "alice", pledgeid, txid, []string{"timeout reached"}, token.WithTMSID(alpha))
ScanPledgeIDWithError(network, alice, pledgeid, txid, []string{"timeout reached"}, token.WithTMSID(alpha))

// Try to reclaim again

ReclaimWithError(network, "alice", "", txid, token.WithTMSID(alpha))
CheckBalance(network, "alice", "", "USD", 50, token.WithTMSID(alpha))
ReclaimWithError(network, alice, "", txid, token.WithTMSID(alpha))
CheckBalance(network, alice, "", "USD", 50, token.WithTMSID(alpha))
CheckBalance(network, "bob", "", "USD", 50)

// Try to claim after reclaim

ClaimWithError(network, "bob", "issuerBeta", &token2.ID{TxId: txid, Index: 0})
CheckBalance(network, "alice", "", "USD", 50, token.WithTMSID(alpha))
CheckBalance(network, alice, "", "USD", 50, token.WithTMSID(alpha))
CheckBalance(network, "bob", "", "USD", 50)

// Try to reclaim after claim

txid, _ = Pledge(network, "alice", "", "USD", 10, "bob", "issuerAlpha", betaURL, time.Minute*1, token.WithTMSID(alpha))
CheckBalance(network, "alice", "", "USD", 40)
txid, _ = Pledge(network, alice, "", "USD", 10, "bob", "issuerAlpha", betaURL, time.Minute*1, token.WithTMSID(alpha))
CheckBalance(network, alice, "", "USD", 40)
CheckBalance(network, "bob", "", "USD", 50)

Claim(network, "bob", "issuerBeta", &token2.ID{TxId: txid, Index: 0})
CheckBalance(network, "alice", "", "USD", 40)
CheckBalance(network, alice, "", "USD", 40)
CheckBalance(network, "bob", "", "USD", 60)

time.Sleep(time.Minute * 1)

ReclaimWithError(network, "alice", "", txid, token.WithTMSID(alpha))
CheckBalance(network, "alice", "", "USD", 40)
ReclaimWithError(network, alice, "", txid, token.WithTMSID(alpha))
CheckBalance(network, alice, "", "USD", 40)
CheckBalance(network, "bob", "", "USD", 60)

// Try to claim after claim

txid, pledgeid = Pledge(network, "bob", "", "USD", 5, "alice", "issuerBeta", alphaURL, time.Minute*1, token.WithTMSID(beta))
CheckBalance(network, "alice", "", "USD", 40)
txid, pledgeid = Pledge(network, "bob", "", "USD", 5, alice, "issuerBeta", alphaURL, time.Minute*1, token.WithTMSID(beta))
CheckBalance(network, alice, "", "USD", 40)
CheckBalance(network, "bob", "", "USD", 55)

PledgeIDExists(network, "bob", pledgeid, txid, token.WithTMSID(beta))

Claim(network, "alice", "issuerAlpha", &token2.ID{TxId: txid, Index: 0})
CheckBalance(network, "alice", "", "USD", 45)
Claim(network, alice, "issuerAlpha", &token2.ID{TxId: txid, Index: 0})
CheckBalance(network, alice, "", "USD", 45)
CheckBalance(network, "bob", "", "USD", 55)

ClaimWithError(network, "alice", "issuerAlpha", &token2.ID{TxId: txid, Index: 0})
CheckBalance(network, "alice", "", "USD", 45)
ClaimWithError(network, alice, "issuerAlpha", &token2.ID{TxId: txid, Index: 0})
CheckBalance(network, alice, "", "USD", 45)
CheckBalance(network, "bob", "", "USD", 55)

time.Sleep(1 * time.Minute)
RedeemWithTMS(network, "issuerBeta", &token2.ID{TxId: txid, Index: 0}, token.WithTMSID(beta))
CheckBalance(network, "alice", "", "USD", 45)
CheckBalance(network, alice, "", "USD", 45)
CheckBalance(network, "bob", "", "USD", 55)

// Try to redeem again
RedeemWithTMSAndError(network, "issuerBeta", &token2.ID{TxId: txid, Index: 0}, token.WithTMSID(beta), "failed to retrieve pledged token during redeem")
CheckBalance(network, "alice", "", "USD", 45)
CheckBalance(network, alice, "", "USD", 45)
CheckBalance(network, "bob", "", "USD", 55)

// Try to claim or reclaim without pledging

ClaimWithError(network, "alice", "issuerAlpha", &token2.ID{TxId: "", Index: 0})
CheckBalance(network, "alice", "", "USD", 45)
ClaimWithError(network, alice, "issuerAlpha", &token2.ID{TxId: "", Index: 0})
CheckBalance(network, alice, "", "USD", 45)
CheckBalance(network, "bob", "", "USD", 55)

ReclaimWithError(network, "alice", "", "", token.WithTMSID(alpha))
CheckBalance(network, "alice", "", "USD", 45)
ReclaimWithError(network, alice, "", "", token.WithTMSID(alpha))
CheckBalance(network, alice, "", "USD", 45)
CheckBalance(network, "bob", "", "USD", 55)

// Fast Pledge + Claim
FastTransferPledgeClaim(network, "alice", "", "USD", 10, "bob", "issuerAlpha", betaURL, time.Minute*1, token.WithTMSID(alpha))
CheckBalance(network, "alice", "", "USD", 35)
FastTransferPledgeClaim(network, alice, "", "USD", 10, "bob", "issuerAlpha", betaURL, time.Minute*1, token.WithTMSID(alpha))
CheckBalance(network, alice, "", "USD", 35)
CheckBalance(network, "bob", "", "USD", 65)

// Fast Pledge + Reclaim
FastTransferPledgeReclaim(network, "alice", "", "USD", 10, "bob", "issuerAlpha", betaURL, time.Second*5, token.WithTMSID(alpha))
CheckBalance(network, "alice", "", "USD", 35)
FastTransferPledgeReclaim(network, alice, "", "USD", 10, "bob", "issuerAlpha", betaURL, time.Second*5, token.WithTMSID(alpha))
CheckBalance(network, alice, "", "USD", 35)
CheckBalance(network, "bob", "", "USD", 65)
}
15 changes: 7 additions & 8 deletions integration/token/interop/topology.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import (
"github.com/hyperledger-labs/fabric-smart-client/integration/nwo/fsc/node"
"github.com/hyperledger-labs/fabric-smart-client/integration/nwo/orion"
"github.com/hyperledger-labs/fabric-smart-client/integration/nwo/weaver"
api2 "github.com/hyperledger-labs/fabric-smart-client/pkg/api"
"github.com/hyperledger-labs/fabric-token-sdk/integration/nwo/token"
fabric2 "github.com/hyperledger-labs/fabric-token-sdk/integration/nwo/token/fabric"
orion2 "github.com/hyperledger-labs/fabric-token-sdk/integration/nwo/token/orion"
Expand All @@ -34,7 +33,7 @@ func HTLCSingleFabricNetworkTopology(opts common.Opts) []api.Topology {

// FSC
fscTopology := fsc.NewTopology()
//fscTopology.SetLogging("token-sdk=debug:fabric-sdk=debug:info", "")
// fscTopology.SetLogging("token-sdk=debug:fabric-sdk=debug:info", "")
fscTopology.P2PCommunicationType = opts.CommType

addIssuer(fscTopology).
Expand Down Expand Up @@ -71,7 +70,7 @@ func HTLCSingleOrionNetworkTopology(opts common.Opts) []api.Topology {

// FSC
fscTopology := fsc.NewTopology()
//fscTopology.SetLogging("debug", "")
// fscTopology.SetLogging("debug", "")
fscTopology.P2PCommunicationType = opts.CommType

addIssuer(fscTopology).
Expand Down Expand Up @@ -119,7 +118,7 @@ func HTLCTwoFabricNetworksTopology(opts common.Opts) []api.Topology {

// FSC
fscTopology := fsc.NewTopology()
//fscTopology.SetLogging("debug", "")
// fscTopology.SetLogging("debug", "")
fscTopology.P2PCommunicationType = opts.CommType

addIssuer(fscTopology).
Expand Down Expand Up @@ -181,7 +180,7 @@ func HTLCNoCrossClaimTopology(opts common.Opts) []api.Topology {

// FSC
fscTopology := fsc.NewTopology()
//fscTopology.SetLogging("db.driver.badger=info:debug", "")
// fscTopology.SetLogging("db.driver.badger=info:debug", "")
fscTopology.P2PCommunicationType = opts.CommType

addIssuer(fscTopology).
Expand Down Expand Up @@ -248,7 +247,7 @@ func HTLCNoCrossClaimWithOrionTopology(opts common.Opts) []api.Topology {

// FSC
fscTopology := fsc.NewTopology()
//fscTopology.SetLogging("db.driver.badger=info:debug", "")
// fscTopology.SetLogging("db.driver.badger=info:debug", "")
fscTopology.P2PCommunicationType = opts.CommType

addIssuer(fscTopology).
Expand All @@ -274,7 +273,7 @@ func HTLCNoCrossClaimWithOrionTopology(opts common.Opts) []api.Topology {
RegisterViewFactory("htlc.claim", &htlc.ClaimViewFactory{}).
RegisterViewFactory("htlc.scan", &htlc.ScanViewFactory{}).
RegisterResponder(&htlc.LockAcceptView{}, &htlc.LockView{})
//TODO Anonymous identity
// TODO Anonymous identity
addBob(fscTopology).
AddOptions(
orion.WithRole("bob"),
Expand Down Expand Up @@ -309,7 +308,7 @@ func HTLCNoCrossClaimWithOrionTopology(opts common.Opts) []api.Topology {
return []api.Topology{f1Topology, orionTopology, tokenTopology, fscTopology}
}

func AssetTransferTopology(tokenSDKDriver string, sdks ...api2.SDK) []api.Topology {
func AssetTransferTopology(opts common.Opts) []api.Topology {
// Define two Fabric topologies
f1Topology := fabric.NewTopologyWithName("alpha").SetDefault()
f1Topology.EnableIdemix()
Expand Down
2 changes: 1 addition & 1 deletion token/core/common/logging/logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const loggerNameSeparator = "."
type Logger = logging.Logger

func MustGetLogger(name string) Logger {
return flogging.MustGetLogger(name)
return logging.MustGetLogger(name)
}

func DriverLogger(prefix string, networkID string, channel string, namespace string) Logger {
Expand Down
Loading

0 comments on commit f9d2870

Please sign in to comment.