Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add funcitionality to create a new generic asserter #503

Merged
merged 3 commits into from
Apr 10, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading