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

Add convert to bool if string or number receive for boolean value #467

Merged

Conversation

danielailie
Copy link
Contributor

Add convert to bool before creating the boolean value to cover the scenarios where boolean value is passed as string or number.
This is a follow up at this issue #258

}).getEndpoint("foo");

let typedValues = NativeSerializer.nativeToTypedValues(
[true, "true", "TRUE", 1, false, "false", "falseString", 0, 5],
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚀

}).getEndpoint("foo");

let typedValues = NativeSerializer.nativeToTypedValues(
[true, "true", "TRUE", 1, false, "false", "falseString", 0, 5],
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"falseString" can be "foobar" - test is thus more explicit about arbitrary strings.

@@ -610,4 +610,59 @@ describe("test native serializer", () => {
variadic: false,
});
});

it.only("should accept a mixed of values for boolen type", async () => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Slipped "only".

@@ -296,7 +296,8 @@ export namespace NativeSerializer {
return new AddressValue(convertNativeToAddress(native, errorContext));
}
if (type instanceof BooleanType) {
return new BooleanValue(native);
const boolValue = native.toString().toLowerCase() === "true" || native.toString() === "1";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚀

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't this be more appropriate in the "isTrue" evaluation?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the value from BooleanValue is expected to be bool, here we accept any type that's why we thought it's better to be here

package.json Outdated
@@ -1,6 +1,6 @@
{
"name": "@multiversx/sdk-core",
"version": "13.2.2",
"version": "13.2.3",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's bump the minor version, so that developers take this update intentionally (not as a hotfix) - v13.3.0.

@danielailie danielailie merged commit 9f0c630 into main Aug 6, 2024
1 check passed
@danielailie danielailie deleted the TOOL-220-add-check-for-boolean-value-to-increase-clarity branch August 6, 2024 11:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants