Merge pull request #1614 from blockscout/interpretation-validation-fix

fix tx interpretation validation
This commit is contained in:
Igor Stuev
2024-02-14 23:46:47 +01:00
committed by GitHub
2 changed files with 5 additions and 2 deletions
+2 -2
View File
@@ -13,13 +13,13 @@ it('split string without capturing variables', () => {
});
it('checks that summary is valid', () => {
const result = checkSummary('{foo} {bar}', { foo: { type: 'string', value: 'foo' }, bar: { type: 'string', value: 'bar' } });
const result = checkSummary('{foo} {native} {bar}', { foo: { type: 'string', value: 'foo' }, bar: { type: 'string', value: 'bar' } });
expect(result).toBe(true);
});
it('checks that summary is invalid', () => {
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore:
const result = checkSummary('{foo} {bar}', { foo: { type: 'string', value: null }, bar: { type: 'string', value: 'bar' } });
const result = checkSummary('{foo} {native} {bar}', { foo: { type: 'string', value: null }, bar: { type: 'string', value: 'bar' } });
expect(result).toBe(false);
});
+3
View File
@@ -24,6 +24,9 @@ export function checkSummary(template: string, variables: Record<string, TxInter
const variablesNames = extractVariables(template);
let result = true;
for (const name of variablesNames) {
if (name === NATIVE_COIN_SYMBOL_VAR_NAME) {
continue;
}
if (!variables[name] || variables[name].value === undefined || variables[name].value === null) {
result = false;
break;