remove base type, keep primitive type and make hints as unknown optional
This commit is contained in:
+18
-24
@@ -10,7 +10,7 @@ import {
|
||||
secp256k1,
|
||||
utf8ToBin,
|
||||
} from '@bitauth/libauth';
|
||||
import { XOTemplateBaseTypes, XOTemplatePrimitiveTypes } from '@xo-cash/types';
|
||||
import { XOTemplatePrimitiveTypes } from '@xo-cash/types';
|
||||
import {
|
||||
isCashAssemblyExpression,
|
||||
extractCashAssemblyEvaluations,
|
||||
@@ -383,10 +383,10 @@ const testCompileCashAssemblyStringLeavesMethodEvaluationForCashAssemblyWithoutT
|
||||
};
|
||||
|
||||
/**
|
||||
* Tests that an unsupported or missing hint leaves the evaluation for CashAssembly instead of throwing.
|
||||
* Tests that a type without a mapped primitive class leaves the evaluation for CashAssembly instead of throwing.
|
||||
*/
|
||||
const testCompileCashAssemblyStringSkipsWhenHintIsNotASupportedPrimitive = (): void => {
|
||||
const compileWithNonPrimitiveHint = (): string =>
|
||||
const testCompileCashAssemblyStringSkipsWhenTypeIsNotAResolvablePrimitive = (): void => {
|
||||
const compileWithNonPrimitiveType = (): string =>
|
||||
compileCashAssemblyString({
|
||||
cashAssemblyText: '$(<label.toIso8601>)',
|
||||
variables: { label: 'hello' },
|
||||
@@ -394,19 +394,19 @@ const testCompileCashAssemblyStringSkipsWhenHintIsNotASupportedPrimitive = (): v
|
||||
label: {
|
||||
name: 'Label',
|
||||
description: 'A text label',
|
||||
type: XOTemplateBaseTypes.STRING,
|
||||
type: XOTemplatePrimitiveTypes.STRING,
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
expect(compileWithNonPrimitiveHint).toThrow(CashAssemblyRequiredVariableMissingError);
|
||||
expect(compileWithNonPrimitiveHint).toThrow('Missing required variable: variableNames [label.toIso8601]');
|
||||
expect(compileWithNonPrimitiveType).toThrow(CashAssemblyRequiredVariableMissingError);
|
||||
expect(compileWithNonPrimitiveType).toThrow('Missing required variable: variableNames [label.toIso8601]');
|
||||
};
|
||||
|
||||
/**
|
||||
* Tests that a supported hint with an unknown method throws CashAssemblyPrimitiveMethodMissingError.
|
||||
* Tests that a method resolvable type with an unknown method throws CashAssemblyPrimitiveMethodMissingError.
|
||||
*
|
||||
* Once the hint maps to a supported primitive class, a missing method is a primitive resolution
|
||||
* Once the type maps to a primitive class for method resolution, a missing method is a primitive resolution
|
||||
* failure rather than a CashAssembly missing variable.
|
||||
*/
|
||||
const testCompileCashAssemblyStringThrowsWhenMethodDoesNotExistOnPrimitive = (): void => {
|
||||
@@ -418,14 +418,13 @@ const testCompileCashAssemblyStringThrowsWhenMethodDoesNotExistOnPrimitive = ():
|
||||
expiry: {
|
||||
name: 'Expiry',
|
||||
description: 'Invitation expiry time',
|
||||
type: XOTemplateBaseTypes.INTEGER,
|
||||
hint: XOTemplatePrimitiveTypes.TIMESTAMP,
|
||||
type: XOTemplatePrimitiveTypes.TIMESTAMP,
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
expect(compileWithUnknownMethod).toThrow(CashAssemblyPrimitiveMethodMissingError);
|
||||
expect(compileWithUnknownMethod).toThrow('CashAssembly primitive method does not exist: identifier "expiry.notARealMethod", methodName "notARealMethod", hint "timestamp"');
|
||||
expect(compileWithUnknownMethod).toThrow('CashAssembly primitive method does not exist: identifier "expiry.notARealMethod", methodName "notARealMethod", type "timestamp"');
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -440,8 +439,7 @@ const testCompileCashAssemblyStringThrowsWhenSupportedTransformIsMissingRuntimeV
|
||||
expiry: {
|
||||
name: 'Expiry',
|
||||
description: 'Invitation expiry time',
|
||||
type: XOTemplateBaseTypes.INTEGER,
|
||||
hint: XOTemplatePrimitiveTypes.TIMESTAMP,
|
||||
type: XOTemplatePrimitiveTypes.TIMESTAMP,
|
||||
},
|
||||
},
|
||||
});
|
||||
@@ -464,14 +462,12 @@ const testCompileCashAssemblyStringResolvesMultiplePrimitiveMethodPushesInOneEva
|
||||
amount: {
|
||||
name: 'Amount',
|
||||
description: 'Payment in satoshis',
|
||||
type: XOTemplateBaseTypes.BIGINT,
|
||||
hint: XOTemplatePrimitiveTypes.SATOSHIS,
|
||||
type: XOTemplatePrimitiveTypes.SATOSHIS,
|
||||
},
|
||||
fee: {
|
||||
name: 'Fee',
|
||||
description: 'Network fee in satoshis',
|
||||
type: XOTemplateBaseTypes.BIGINT,
|
||||
hint: XOTemplatePrimitiveTypes.SATOSHIS,
|
||||
type: XOTemplatePrimitiveTypes.SATOSHIS,
|
||||
},
|
||||
},
|
||||
evaluationDecodeMode: 'bigint',
|
||||
@@ -542,14 +538,12 @@ const testP2sh32RedeemWithPrimitiveAddAndSchnorrSignatureSpendsSuccessfully = ()
|
||||
price: {
|
||||
name: 'Price',
|
||||
description: 'Base payment in satoshis',
|
||||
type: XOTemplateBaseTypes.BIGINT,
|
||||
hint: XOTemplatePrimitiveTypes.SATOSHIS,
|
||||
type: XOTemplatePrimitiveTypes.SATOSHIS,
|
||||
},
|
||||
fee: {
|
||||
name: 'Fee',
|
||||
description: 'Network fee in satoshis',
|
||||
type: XOTemplateBaseTypes.BIGINT,
|
||||
hint: XOTemplatePrimitiveTypes.SATOSHIS,
|
||||
type: XOTemplatePrimitiveTypes.SATOSHIS,
|
||||
},
|
||||
},
|
||||
});
|
||||
@@ -781,8 +775,8 @@ const runTests = async (): Promise<void> => {
|
||||
testCompileCashAssemblyStringLeavesMethodEvaluationForCashAssemblyWithoutTemplateVariables,
|
||||
);
|
||||
test(
|
||||
'compileCashAssemblyString: skips when hint is not a supported primitive',
|
||||
testCompileCashAssemblyStringSkipsWhenHintIsNotASupportedPrimitive,
|
||||
'compileCashAssemblyString: skips when type is not a resolvable primitive',
|
||||
testCompileCashAssemblyStringSkipsWhenTypeIsNotAResolvablePrimitive,
|
||||
);
|
||||
test(
|
||||
'compileCashAssemblyString: throws when method does not exist on the primitive',
|
||||
|
||||
Reference in New Issue
Block a user