Skip to content

Commit

Permalink
[FAB-14149] tx protos cleanup
Browse files Browse the repository at this point in the history
-- rename PlainOutput Token
-- remove Plain from the names
-- rename Import Issue
-- refactor code accordingly

Change-Id: I9cecdaead5154f5d4e3dc59f9c128574f2c94c4d
Signed-off-by: Kaoutar Elkhiyaoui <kao@zurich.ibm.com>
  • Loading branch information
KElkhiyaoui committed Feb 19, 2019
1 parent 946f86b commit 36ad9fd
Show file tree
Hide file tree
Showing 25 changed files with 832 additions and 804 deletions.
10 changes: 5 additions & 5 deletions core/committer/txvalidator/v14/validator_test.go
Expand Up @@ -204,11 +204,11 @@ func getEnvWithSigner(ccID string, event []byte, res []byte, sig msp.SigningIden

func getTokenTx(t *testing.T) *common.Envelope {
transactionData := &token.TokenTransaction{
Action: &token.TokenTransaction_PlainAction{
PlainAction: &token.PlainTokenAction{
Data: &token.PlainTokenAction_PlainImport{
PlainImport: &token.PlainImport{
Outputs: []*token.PlainOutput{
Action: &token.TokenTransaction_TokenAction{
TokenAction: &token.TokenAction{
Data: &token.TokenAction_Issue{
Issue: &token.Issue{
Outputs: []*token.Token{
{Owner: &token.TokenOwner{Raw: []byte("owner-1")}, Type: "TOK1", Quantity: 111},
{Owner: &token.TokenOwner{Raw: []byte("owner-2")}, Type: "TOK2", Quantity: 222},
},
Expand Down
10 changes: 5 additions & 5 deletions core/committer/txvalidator/v20/validator_test.go
Expand Up @@ -152,11 +152,11 @@ func getEnvWithSigner(ccID string, event []byte, res []byte, sig msp.SigningIden

func getTokenTx(t *testing.T) *common.Envelope {
transactionData := &token.TokenTransaction{
Action: &token.TokenTransaction_PlainAction{
PlainAction: &token.PlainTokenAction{
Data: &token.PlainTokenAction_PlainImport{
PlainImport: &token.PlainImport{
Outputs: []*token.PlainOutput{
Action: &token.TokenTransaction_TokenAction{
TokenAction: &token.TokenAction{
Data: &token.TokenAction_Issue{
Issue: &token.Issue{
Outputs: []*token.Token{
{Owner: &token.TokenOwner{Raw: []byte("owner-1")}, Type: "TOK1", Quantity: 111},
{Owner: &token.TokenOwner{Raw: []byte("owner-2")}, Type: "TOK2", Quantity: 222},
},
Expand Down
10 changes: 5 additions & 5 deletions core/common/validation/msgvalidation_test.go
Expand Up @@ -72,11 +72,11 @@ func protoMarshal(t *testing.T, m proto.Message) []byte {
// getTokenTransaction returns a valid token transaction
func getTokenTransaction() *token.TokenTransaction {
return &token.TokenTransaction{
Action: &token.TokenTransaction_PlainAction{
PlainAction: &token.PlainTokenAction{
Data: &token.PlainTokenAction_PlainImport{
PlainImport: &token.PlainImport{
Outputs: []*token.PlainOutput{{
Action: &token.TokenTransaction_TokenAction{
TokenAction: &token.TokenAction{
Data: &token.TokenAction_Issue{
Issue: &token.Issue{
Outputs: []*token.Token{{
Owner: &token.TokenOwner{Raw: []byte("token-owner")},
Type: "PDQ",
Quantity: 777,
Expand Down
62 changes: 31 additions & 31 deletions integration/token/token_test.go
Expand Up @@ -56,22 +56,22 @@ var _ = Describe("Token EndToEnd", func() {

// expected token transaction returned by prover peer
expectedTokenTransaction = &token.TokenTransaction{
Action: &token.TokenTransaction_PlainAction{
PlainAction: &token.PlainTokenAction{
Data: &token.PlainTokenAction_PlainImport{
PlainImport: &token.PlainImport{
Outputs: []*token.PlainOutput{{
Action: &token.TokenTransaction_TokenAction{
TokenAction: &token.TokenAction{
Data: &token.TokenAction_Issue{
Issue: &token.Issue{
Outputs: []*token.Token{{
Owner: &token.TokenOwner{Raw: []byte("test-owner")},
Type: "ABC123",
Quantity: 119,
}}}}}}}
expectedTransferTransaction = &token.TokenTransaction{
Action: &token.TokenTransaction_PlainAction{
PlainAction: &token.PlainTokenAction{
Data: &token.PlainTokenAction_PlainTransfer{
PlainTransfer: &token.PlainTransfer{
Action: &token.TokenTransaction_TokenAction{
TokenAction: &token.TokenAction{
Data: &token.TokenAction_Transfer{
Transfer: &token.Transfer{
Inputs: nil,
Outputs: []*token.PlainOutput{{
Outputs: []*token.Token{{
Owner: nil,
Type: "ABC123",
Quantity: 119,
Expand All @@ -82,12 +82,12 @@ var _ = Describe("Token EndToEnd", func() {
},
}
expectedRedeemTransaction = &token.TokenTransaction{
Action: &token.TokenTransaction_PlainAction{
PlainAction: &token.PlainTokenAction{
Data: &token.PlainTokenAction_PlainRedeem{
PlainRedeem: &token.PlainTransfer{
Action: &token.TokenTransaction_TokenAction{
TokenAction: &token.TokenAction{
Data: &token.TokenAction_Redeem{
Redeem: &token.Transfer{
Inputs: nil,
Outputs: []*token.PlainOutput{
Outputs: []*token.Token{
{
Owner: nil,
Type: "ABC123",
Expand Down Expand Up @@ -155,12 +155,12 @@ var _ = Describe("Token EndToEnd", func() {
Expect(err).NotTo(HaveOccurred())
recipientUser2 = &token.TokenOwner{Raw: recipientUser2Bytes}
tokensToIssue[0].Recipient = recipientUser2
expectedTokenTransaction.GetPlainAction().GetPlainImport().Outputs[0].Owner = recipientUser2
expectedTokenTransaction.GetTokenAction().GetIssue().Outputs[0].Owner = recipientUser2
recipientUser1Bytes, err := getIdentity(network, peer, "User1", "Org1MSP")
Expect(err).NotTo(HaveOccurred())
recipientUser1 = &token.TokenOwner{Raw: recipientUser1Bytes}
expectedTransferTransaction.GetPlainAction().GetPlainTransfer().Outputs[0].Owner = recipientUser1
expectedRedeemTransaction.GetPlainAction().GetPlainRedeem().Outputs[1].Owner = recipientUser1
expectedTransferTransaction.GetTokenAction().GetTransfer().Outputs[0].Owner = recipientUser1
expectedRedeemTransaction.GetTokenAction().GetRedeem().Outputs[1].Owner = recipientUser1

networkRunner := network.NetworkGroupRunner()
process = ifrit.Invoke(networkRunner)
Expand Down Expand Up @@ -199,7 +199,7 @@ var _ = Describe("Token EndToEnd", func() {

By("transferring tokens to user1")
tokenIDs := []*token.TokenId{{TxId: txID, Index: 0}}
expectedTransferTransaction.GetPlainAction().GetPlainTransfer().Inputs = tokenIDs
expectedTransferTransaction.GetTokenAction().GetTransfer().Inputs = tokenIDs
txID = RunTransferRequest(tClient, issuedTokens, recipientUser1, expectedTransferTransaction)

By("list tokens user 2")
Expand All @@ -218,7 +218,7 @@ var _ = Describe("Token EndToEnd", func() {

By("redeeming tokens user1")
tokenIDs = []*token.TokenId{{TxId: txID, Index: 0}}
expectedRedeemTransaction.GetPlainAction().GetPlainRedeem().Inputs = tokenIDs
expectedRedeemTransaction.GetTokenAction().GetRedeem().Inputs = tokenIDs
quantityToRedeem := 50 // redeem 50 out of 119
RunRedeemRequest(tClient, issuedTokens, uint64(quantityToRedeem), expectedRedeemTransaction)

Expand Down Expand Up @@ -264,11 +264,11 @@ var _ = Describe("Token EndToEnd", func() {
Expect(err).NotTo(HaveOccurred())
recipientUser2 = &token.TokenOwner{Raw: recipientUser2Bytes}
tokensToIssue[0].Recipient = &token.TokenOwner{Raw: recipientUser2Bytes}
expectedTokenTransaction.GetPlainAction().GetPlainImport().Outputs[0].Owner = recipientUser2
expectedTokenTransaction.GetTokenAction().GetIssue().Outputs[0].Owner = recipientUser2
recipientUser1Bytes, err := getIdentity(network, peer, "User1", "Org1MSP")
Expect(err).NotTo(HaveOccurred())
recipientUser1 = &token.TokenOwner{Raw: recipientUser1Bytes}
expectedTransferTransaction.GetPlainAction().GetPlainTransfer().Outputs[0].Owner = &token.TokenOwner{Raw: recipientUser1Bytes}
expectedTransferTransaction.GetTokenAction().GetTransfer().Outputs[0].Owner = &token.TokenOwner{Raw: recipientUser1Bytes}

networkRunner := network.NetworkGroupRunner()
process = ifrit.Invoke(networkRunner)
Expand All @@ -294,7 +294,7 @@ var _ = Describe("Token EndToEnd", func() {

By("User2 transfers his token to User1")
inputIDs := []*token.TokenId{{TxId: txID, Index: 0}}
expectedTransferTransaction.GetPlainAction().GetPlainTransfer().Inputs = inputIDs
expectedTransferTransaction.GetTokenAction().GetTransfer().Inputs = inputIDs
RunTransferRequest(tClient, issuedTokens, recipientUser1, expectedTransferTransaction)

By("User2 try to transfer again the same token already transferred before")
Expand Down Expand Up @@ -326,12 +326,12 @@ var _ = Describe("Token EndToEnd", func() {

By("User1 attempts to spend User2's tokens by submitting a token transaction directly")
expectedTokenTransaction = &token.TokenTransaction{
Action: &token.TokenTransaction_PlainAction{
PlainAction: &token.PlainTokenAction{
Data: &token.PlainTokenAction_PlainTransfer{
PlainTransfer: &token.PlainTransfer{
Action: &token.TokenTransaction_TokenAction{
TokenAction: &token.TokenAction{
Data: &token.TokenAction_Transfer{
Transfer: &token.Transfer{
Inputs: []*token.TokenId{{TxId: txID, Index: 0}},
Outputs: []*token.PlainOutput{{
Outputs: []*token.Token{{
Owner: &token.TokenOwner{Raw: []byte("test-owner")},
Type: "ABC123",
Quantity: 119,
Expand Down Expand Up @@ -421,9 +421,9 @@ func RunTransferRequest(c *tokenclient.Client, inputTokens []*token.TokenOutput,
Expect(tokenTxid).To(Equal(txid))

// Verify the result
Expect(tokenTx.GetPlainAction().GetPlainTransfer().GetInputs()).ToNot(BeNil())
Expect(len(tokenTx.GetPlainAction().GetPlainTransfer().GetInputs())).To(Equal(1))
Expect(tokenTx.GetPlainAction().GetPlainTransfer().GetOutputs()).ToNot(BeNil())
Expect(tokenTx.GetTokenAction().GetTransfer().GetInputs()).ToNot(BeNil())
Expect(len(tokenTx.GetTokenAction().GetTransfer().GetInputs())).To(Equal(1))
Expect(tokenTx.GetTokenAction().GetTransfer().GetOutputs()).ToNot(BeNil())

return txid
}
Expand Down
90 changes: 46 additions & 44 deletions protos/token/expectations.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions protos/token/expectations.proto
Expand Up @@ -11,7 +11,6 @@ option java_package = "org.hyperledger.fabric.protos.token";

package token;

import "google/protobuf/timestamp.proto";
import "token/transaction.proto";

// TokenExpectation represent the belief that someone should achieve in terms of a token action
Expand All @@ -36,5 +35,5 @@ message PlainExpectation {
// certain outputs will be matched
message PlainTokenExpectation {
// Outputs contains the expected outputs
repeated PlainOutput outputs = 1;
repeated Token outputs = 1;
}

0 comments on commit 36ad9fd

Please sign in to comment.