Repository: coinbase/rosetta-sdk-go
Pull request #85 (2020-07-27 04:29:08)

Miscellaneous Fixes Before Release
Related Issue: https://github.com/coinbase/rosetta-cli/issues/68

### Changes
- [x] Only parse status if confirming success in `parser`
- [x] Less verbose logging


Patch:
diff --git a/parser/intent.go b/parser/intent.go
index 88df89a..f07ca30 100644
--- a/parser/intent.go
+++ b/parser/intent.go
@@ -17,7 +17,6 @@ package parser
 import (
 	"errors"
 	"fmt"
-	"log"
 
 	"github.com/coinbase/rosetta-sdk-go/asserter"
 	"github.com/coinbase/rosetta-sdk-go/types"
@@ -68,7 +67,6 @@ func (p *Parser) ExpectedOperations(
 ) error {
 	matches := make(map[int]struct{})
 	failedMatches := []*types.Operation{}
-	unmatched := []*types.Operation{}
 
 	for _, obs := range observed {
 		foundMatch := false
@@ -86,14 +84,16 @@ func (p *Parser) ExpectedOperations(
 				continue
 			}
 
-			obsSuccess, err := p.Asserter.OperationSuccessful(obs)
-			if err != nil {
-				return fmt.Errorf("%w: unable to check operation success", err)
-			}
+			if confirmSuccess {
+				obsSuccess, err := p.Asserter.OperationSuccessful(obs)
+				if err != nil {
+					return fmt.Errorf("%w: unable to check operation success", err)
+				}
 
-			if confirmSuccess && !obsSuccess {
-				failedMatches = append(failedMatches, obs)
-				continue
+				if !obsSuccess {
+					failedMatches = append(failedMatches, obs)
+					continue
+				}
 			}
 
 			matches[i] = struct{}{}
@@ -101,14 +101,11 @@ func (p *Parser) ExpectedOperations(
 			break
 		}
 
-		if !foundMatch {
-			if errExtra {
-				return fmt.Errorf(
-					"found extra operation %s",
-					types.PrettyPrintStruct(obs),
-				)
-			}
-			unmatched = append(unmatched, obs)
+		if !foundMatch && errExtra {
+			return fmt.Errorf(
+				"found extra operation %s",
+				types.PrettyPrintStruct(obs),
+			)
 		}
 	}
 
@@ -136,10 +133,6 @@ func (p *Parser) ExpectedOperations(
 		return errors.New(errString)
 	}
 
-	if len(unmatched) > 0 {
-		log.Printf("found extra operations: %s\n", types.PrettyPrintStruct(unmatched))
-	}
-
 	return nil
 }
 


Test patch:
diff --git a/parser/intent_test.go b/parser/intent_test.go
index 11a3389..de6af34 100644
--- a/parser/intent_test.go
+++ b/parser/intent_test.go
@@ -243,6 +243,65 @@ func TestExpectedOperations(t *testing.T) {
 				},
 			},
 		},
+		"simple unbroadcast match": {
+			intent: []*types.Operation{
+				{
+					OperationIdentifier: &types.OperationIdentifier{
+						Index: 1,
+					},
+					Type: "transfer",
+					Account: &types.AccountIdentifier{
+						Address: "addr1",
+					},
+					Amount: &types.Amount{
+						Value: "100",
+					},
+				},
+				{
+					OperationIdentifier: &types.OperationIdentifier{
+						Index: 5,
+					},
+					Type: "fee",
+					Account: &types.AccountIdentifier{
+						Address: "addr2",
+					},
+					Amount: &types.Amount{
+						Value: "50",
+					},
+				},
+			},
+			observed: []*types.Operation{
+				{
+					OperationIdentifier: &types.OperationIdentifier{
+						Index: 2,
+					},
+					Type: "fee",
+					Account: &types.AccountIdentifier{
+						Address: "addr2",
+					},
+					Amount: &types.Amount{
+						Value: "50",
+					},
+				},
+				{
+					OperationIdentifier: &types.OperationIdentifier{
+						Index: 3,
+					},
+					RelatedOperations: []*types.OperationIdentifier{
+						{
+							Index: 2,
+						},
+					},
+					Type: "transfer",
+					Account: &types.AccountIdentifier{
+						Address: "addr1",
+					},
+					Amount: &types.Amount{
+						Value: "100",
+					},
+				},
+			},
+		},
 		"simple match (confirm success)": {
 			intent: []*types.Operation{
 				{