Skip to content

Commit

Permalink
Add funcitionality to create a new generic asserter (#503)
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaying-peng committed Apr 10, 2024
1 parent fa62d03 commit 14fc343
Showing 1 changed file with 49 additions and 0 deletions.
49 changes: 49 additions & 0 deletions asserter/asserter.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,55 @@ func NewServer(
}, nil
}

// NewGenericAsserter constructs a new Asserter for generic usage
func NewGenericAsserter(
supportedOperationTypes []string,
historicalBalanceLookup bool,
supportedNetworks []*types.NetworkIdentifier,
operationStatuses []*types.OperationStatus,
errors []*types.Error,
genesisBlockIdentifier *types.BlockIdentifier,
timestampStartIndex int64,
validationFilePath string,
) (*Asserter, error) {
if err := OperationTypes(supportedOperationTypes); err != nil {
return nil, fmt.Errorf("operation types %v are invalid: %w", supportedOperationTypes, err)
}

if err := SupportedNetworks(supportedNetworks); err != nil {
return nil, fmt.Errorf(
"network identifiers %s are invalid: %w",
types.PrintStruct(supportedNetworks),
err,
)
}

validationConfig, err := getValidationConfig(validationFilePath)
if err != nil {
return nil, fmt.Errorf("config %s is invalid: %w", validationFilePath, err)
}

asserter := &Asserter{
operationTypes: supportedOperationTypes,
historicalBalanceLookup: historicalBalanceLookup,
supportedNetworks: supportedNetworks,
validations: validationConfig,
genesisBlock: genesisBlockIdentifier,
timestampStartIndex: timestampStartIndex,
}

asserter.errorTypeMap = map[int32]*types.Error{}
for _, err := range errors {
asserter.errorTypeMap[err.Code] = err
}
asserter.operationStatusMap = map[string]bool{}
for _, status := range operationStatuses {
asserter.operationStatusMap[status.Status] = status.Successful
}

return asserter, nil
}

// NewClientWithResponses constructs a new Asserter
// from a NetworkStatusResponse and
// NetworkOptionsResponse.
Expand Down

0 comments on commit 14fc343

Please sign in to comment.