diff --git a/smart_contracts/contracts_as/test/set-action-thresholds/assembly/index.ts b/smart_contracts/contracts_as/test/set-action-thresholds/assembly/index.ts index a5753d1122..0062c75e94 100644 --- a/smart_contracts/contracts_as/test/set-action-thresholds/assembly/index.ts +++ b/smart_contracts/contracts_as/test/set-action-thresholds/assembly/index.ts @@ -8,6 +8,25 @@ import { addAssociatedKey, AddKeyFailure, ActionType, setActionThreshold, SetThr const ARG_KEY_MANAGEMENT_THRESHOLD = "key_management_threshold"; const ARG_DEPLOY_THRESHOLD = "deploy_threshold"; +function handleError(error: SetThresholdFailure): void { + switch (error) { + case SetThresholdFailure.Ok: + break; + case SetThresholdFailure.KeyManagementThreshold: + Error.fromErrorCode(ErrorCode.KeyManagementThreshold).revert(); + break; + case SetThresholdFailure.DeploymentThreshold: + Error.fromErrorCode(ErrorCode.DeploymentThreshold).revert(); + break; + case SetThresholdFailure.PermissionDeniedError: + Error.fromErrorCode(ErrorCode.PermissionDenied).revert(); + break; + case SetThresholdFailure.InsufficientTotalWeight: + Error.fromErrorCode(ErrorCode.InsufficientTotalWeight).revert(); + break; + } +} + export function call(): void { let keyManagementThresholdBytes = CL.getNamedArg(ARG_KEY_MANAGEMENT_THRESHOLD); let keyManagementThreshold = keyManagementThresholdBytes[0]; @@ -17,31 +36,11 @@ export function call(): void { if (keyManagementThreshold != 0) { const result1 = setActionThreshold(ActionType.KeyManagement, keyManagementThreshold); - switch (result1) { - case SetThresholdFailure.Ok: - break; - case SetThresholdFailure.PermissionDeniedError: - Error.fromErrorCode(ErrorCode.PermissionDenied).revert(); - break; - default: - // TODO: Create standard Error from those enum values - Error.fromUserError(4464 + 1).revert(); - break; - } + handleError(result1); } if (deployThreshold != 0) { const result2 = setActionThreshold(ActionType.Deployment, deployThreshold); - switch (result2) { - case SetThresholdFailure.Ok: - break; - case SetThresholdFailure.PermissionDeniedError: - Error.fromErrorCode(ErrorCode.PermissionDenied).revert(); - break; - default: - // TODO: Create standard Error from those enum values - Error.fromUserError(4464).revert(); - break; - } + handleError(result2); } } diff --git a/smart_contracts/contracts_as/test/set-action-thresholds/package.json b/smart_contracts/contracts_as/test/set-action-thresholds/package.json index 2123be0925..1b01197e81 100644 --- a/smart_contracts/contracts_as/test/set-action-thresholds/package.json +++ b/smart_contracts/contracts_as/test/set-action-thresholds/package.json @@ -1,6 +1,6 @@ { "scripts": { - "asbuild:optimized": "asc --lib ../../.. assembly/index.ts -b ../../../../target_as/authorized_keys.wasm --optimize --use abort=", + "asbuild:optimized": "asc --lib ../../.. assembly/index.ts -b ../../../../target_as/set_action_thresholds.wasm --optimize --use abort=", "asbuild": "npm run asbuild:optimized" }, "devDependencies": {