From a954dc43fe1a032dd986598fada145693aa3098a Mon Sep 17 00:00:00 2001 From: Patrick O'Grady Date: Tue, 1 Dec 2020 17:30:06 -0600 Subject: [PATCH 1/2] Handle populated, empty Operation.Status --- asserter/block.go | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/asserter/block.go b/asserter/block.go index be15d58b..a8a49db9 100644 --- a/asserter/block.go +++ b/asserter/block.go @@ -143,7 +143,12 @@ func (a *Asserter) OperationStatus(status *string, construction bool) error { return ErrAsserterNotInitialized } - if status == nil { + // As of rosetta-specifications@v1.4.7, populating + // the Operation.Status field is deprecated for construction, + // however, many implementations may still do this. Therefore, + // we need to handle a populated but empty Operation.Status + // field gracefully. + if status == nil || len(*status) == 0 { if construction { return nil } @@ -155,10 +160,6 @@ func (a *Asserter) OperationStatus(status *string, construction bool) error { return ErrOperationStatusNotEmptyForConstruction } - if len(*status) == 0 { - return ErrOperationStatusMissing - } - if _, ok := a.operationStatusMap[*status]; !ok { return fmt.Errorf("%w: %s", ErrOperationStatusInvalid, *status) } From 7f7df2bb06e5b2493c3570ad3ca38f31c5b73150 Mon Sep 17 00:00:00 2001 From: Patrick O'Grady Date: Tue, 1 Dec 2020 17:31:53 -0600 Subject: [PATCH 2/2] add test for empty string --- asserter/block_test.go | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/asserter/block_test.go b/asserter/block_test.go index 738a9259..7f3248a9 100644 --- a/asserter/block_test.go +++ b/asserter/block_test.go @@ -405,6 +405,21 @@ func TestOperation(t *testing.T) { construction: true, err: nil, }, + "valid construction operation (empty status)": { + operation: &types.Operation{ + OperationIdentifier: &types.OperationIdentifier{ + Index: int64(1), + }, + Type: "PAYMENT", + Status: types.String(""), + Account: validAccount, + Amount: validAmount, + }, + index: int64(1), + successful: false, + construction: true, + err: nil, + }, "invalid construction operation": { operation: &types.Operation{ OperationIdentifier: &types.OperationIdentifier{