From dbbe1ec4edb4c9a709a781e6dfe25ff6aee7978b Mon Sep 17 00:00:00 2001 From: Xiaying Peng Date: Wed, 10 Apr 2024 12:40:35 -0700 Subject: [PATCH] Update asserter.go --- asserter/asserter.go | 45 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/asserter/asserter.go b/asserter/asserter.go index ad1e5315..895162a5 100644 --- a/asserter/asserter.go +++ b/asserter/asserter.go @@ -122,6 +122,51 @@ 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, +) (*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, + ) + } + + asserter := &Asserter{ + operationTypes: supportedOperationTypes, + historicalBalanceLookup: historicalBalanceLookup, + supportedNetworks: supportedNetworks, + validations: &Validations{ + Enabled: false, + }, + 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.