Skip to content

Commit

Permalink
Merge pull request #260 from coinbase/patrick/backwards-compatible-st…
Browse files Browse the repository at this point in the history
…atus

[asserter] Backwards Compatibility for Operation.Status
  • Loading branch information
patrick-ogrady committed Dec 1, 2020
2 parents 3507943 + 7f7df2b commit 906f251
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 5 deletions.
11 changes: 6 additions & 5 deletions asserter/block.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -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)
}
Expand Down
15 changes: 15 additions & 0 deletions asserter/block_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down

0 comments on commit 906f251

Please sign in to comment.