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

fix: 🐛 transformArrayToMap fieldsArray may undefined #129

Merged
Show file tree
Hide file tree
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
3 changes: 2 additions & 1 deletion dist/aelf.cjs.js
Original file line number Diff line number Diff line change
Expand Up @@ -34798,7 +34798,8 @@ function transformArrayToMap(inputType, origin) {
resolvedType = _fields$field.resolvedType;
if (resolvedType && origin !== null && origin !== undefined) {
if (origin[name] && Array.isArray(origin[name])) {
var fieldsArray = resolvedType.fieldsArray,
var _resolvedType$fieldsA = resolvedType.fieldsArray,
fieldsArray = _resolvedType$fieldsA === void 0 ? [] : _resolvedType$fieldsA,
resolvedFields = resolvedType.fields,
_resolvedType$options = resolvedType.options,
resolvedOptions = _resolvedType$options === void 0 ? {} : _resolvedType$options; // eslint-disable-next-line max-len
Expand Down
2 changes: 1 addition & 1 deletion dist/aelf.cjs.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/aelf.umd.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/aelf.umd.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/util/transform.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ export function transformArrayToMap(inputType, origin) {
if (resolvedType && origin !== null && origin !== undefined) {
if (origin[name] && Array.isArray(origin[name])) {
const {
fieldsArray,
fieldsArray = [],
fields: resolvedFields,
options: resolvedOptions = {},
} = resolvedType;
Expand Down
15 changes: 15 additions & 0 deletions test/unit/util/token.proto.json
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,21 @@
"id": 2
}
}
},
"TestEnum": {
"values": {
"EMAIL": 0,
"PHONE": 1
}
},
"TestEnumArray": {
"fields": {
"type": {
"rule": "repeated",
"type": "TestEnum",
"id": 1
}
}
}
}
}
40 changes: 29 additions & 11 deletions test/unit/util/transform.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ describe('test httpProvider', () => {
expect(result.merklePathNodes[0].hash.value.toString('hex')).toEqual(
'967f2a2c7f3d22f9278175c1e6aa39cf9171db91dceacd5ee0f37c2e507b5abe'
);
const result1 = transform(transferInput,{},INPUT_TRANSFORMERS);
const result1 = transform(transferInput, {}, INPUT_TRANSFORMERS);
expect(result1).toEqual({ merklePathNodes: undefined });
});
test('test transform with empty fieldsArray', async () => {
Expand Down Expand Up @@ -266,6 +266,18 @@ describe('test httpProvider', () => {
},
});
});
test('test transformArrayToMap with Enum Array', async () => {
const dataType = AElf.pbjs.Root.fromJSON(tokenProto);
dataType.resolveAll();
const enumArray = dataType.lookupType('TestEnumArray');
const params = {
type: ['EMAIL', 'PHONE'],
};
const result = transformArrayToMap(enumArray, params);
expect(result).toEqual({
type: ['EMAIL', 'PHONE'],
});
});
test('test encode address', async () => {
const address =
'0x967f2a2c7f3d22f9278175c1e6aa39cf9171db91dceacd5ee0f37c2e507b5abe';
Expand Down Expand Up @@ -332,11 +344,15 @@ describe('test httpProvider', () => {
);
});
test('test output address transformer with array object origin', () => {
const address = [{
value: 'FXD7R7PHkfRn4fmEDvHCN+7hb2XD0NgAcxXjYkMccuY=',
}];
const address = [
{
value: 'FXD7R7PHkfRn4fmEDvHCN+7hb2XD0NgAcxXjYkMccuY=',
},
];
const result = OUTPUT_TRANSFORMERS[0].transformer(address);
expect(result).toEqual(['ASh2Wt7nSEmYqnGxPPzp4pnVDU4uhj1XW9Se5VeZcX2UDdyjx']);
expect(result).toEqual([
'ASh2Wt7nSEmYqnGxPPzp4pnVDU4uhj1XW9Se5VeZcX2UDdyjx',
]);
});
test('test output hash transformer with string origin', () => {
const address =
Expand All @@ -347,13 +363,15 @@ describe('test httpProvider', () => {
);
});
test('test output hash transformer with array object origin', () => {
const address = [{
value: 'FXD7R7PHkfRn4fmEDvHCN+7hb2XD0NgAcxXjYkMccuY=',
}];
const address = [
{
value: 'FXD7R7PHkfRn4fmEDvHCN+7hb2XD0NgAcxXjYkMccuY=',
},
];
const result = OUTPUT_TRANSFORMERS[1].transformer(address);
expect(result).toEqual(
['1570fb47b3c791f467e1f9840ef1c237eee16f65c3d0d8007315e362431c72e6']
);
expect(result).toEqual([
'1570fb47b3c791f467e1f9840ef1c237eee16f65c3d0d8007315e362431c72e6',
]);
});
test('test output address transformer with object origin', () => {
const address = {
Expand Down
Loading