Skip to content

Conversation

@phanpak
Copy link

@phanpak phanpak commented Dec 22, 2023

No description provided.

Copy link
Contributor

@MatiasOS MatiasOS left a comment

Choose a reason for hiding this comment

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

Please, change .string() values to hex validation

});

const SegmentStructSchema = joi.object({
data: joi.string().required(),
Copy link
Contributor

Choose a reason for hiding this comment

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

data isn't required

value: joi.string().required()
});

const SegmentParamValueSchema = joi.alternatives().try(
Copy link
Contributor

Choose a reason for hiding this comment

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

Please, add some test with wrong parameters that fails at this level

Copy link
Contributor

Choose a reason for hiding this comment

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

agree on this - and especially we should check that the error messages are meaningful. We had this issue with DSL schema where all Joi errors were from the top level and did not say which parameter the error happened at

Copy link
Contributor

@mikec mikec left a comment

Choose a reason for hiding this comment

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

would like to see tests for specific errors and their messages before merging

@@ -0,0 +1,117 @@
import { segmentFunctionNames, signatureTypes, tokenStandards } from "./constants";
Copy link
Contributor

Choose a reason for hiding this comment

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

we have been calling it "low level" definition, but we should come up with a better name for this.

Maybe we call it "functional"? so we would have DSL Definition level, and functional level

value: joi.string().required()
});

const SegmentParamValueSchema = joi.alternatives().try(
Copy link
Contributor

Choose a reason for hiding this comment

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

agree on this - and especially we should check that the error messages are meaningful. We had this issue with DSL schema where all Joi errors were from the top level and did not say which parameter the error happened at

describe('DeclarationArgsSchema', () => {
it('should validate a valid declaration', () => {
const { error } = DeclarationArgsSchema.validate(declarationArgs);
console.log("@@@@@@@@@@@@@@@@@@@", error);
Copy link
Contributor

Choose a reason for hiding this comment

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

debugging? might want to remove

@phanpak phanpak force-pushed the BRI-1784-validation-args branch 2 times, most recently from 3ab41ea to 7adde84 Compare December 28, 2023 17:29
@phanpak phanpak force-pushed the BRI-1784-validation-args branch from 7adde84 to 2c1c9a6 Compare December 28, 2023 17:30
signer: owner,
tokenIn: tokenIn as SegmentParamValue,
tokenOut: tokenOut as SegmentParamValue,
tokenIn: { address: tokenIn.address } as SegmentParamValue,
Copy link
Author

Choose a reason for hiding this comment

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

@mikec can you tell me whether it's correct? The thing is tokenIn and tokenOut contain values that are irrelevant for segments.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think this will work because we are not supporting other values for token struct to be set with DSL. The additional struct values were for ERC721 (NFT's) which we're not currently dealing with. If tests for DSL are passing, this should be ok.

signer: owner,
tokenIn: tokenIn as SegmentParamValue,
tokenOut: tokenOut as SegmentParamValue,
tokenIn: { address: tokenIn.address } as SegmentParamValue,
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this will work because we are not supporting other values for token struct to be set with DSL. The additional struct values were for ERC721 (NFT's) which we're not currently dealing with. If tests for DSL are passing, this should be ok.



const declarationArgs = {
'data': '0x4f899fb2000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000007c000000000000000000000000079f147176824196789f07dfc2d21e100ee1ae13800000000000000000000000000000000000000000000000000000000000000800000000000000000000000000000000000000000000000000000000000000740000000000000000000000000000000000000000000000000000000000000076000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000080000000000000000000000000000000000000000000000000000000000000014000000000000000000000000000000000000000000000000000000000000001e00000000000000000000000000000000000000000000000000000000000000320000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000044a9aa5f7e0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000024502929ff00000000000000000000000000000000000000000000000000009a761dfdf100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000c42b2fc43a0000000000000000000000003b28d6ee052b65ed4d5230c1b2a9abaef031c648000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000003e8000000000000000000000000000000000000000000000000000000000000000000000000000000000000004000000000000000000000000088e6a0c2ddd26feeb64f039a2c41296fcb3f564000000000000000000000000000000000000000000000000000000000000003e8000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000002a449d9a2180000000000000000000000003b28d6ee052b65ed4d5230c1b2a9abaef031c64800000000000000000000000000000000000000000000000000000000000002200000000000000000000000006399ae010188f36e469fb6e62c859ddfc558328a0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000dac17f958d2ee523a2206206994597c13d831ec70000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb4800000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000566d3e80000000000000000000000000000000000000000000000000000000000000271000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000280000000000000000000000000000000000000000000000000000000000000004000000000000000000000000088e6a0c2ddd26feeb64f039a2c41296fcb3f564000000000000000000000000000000000000000000000000000000000000003e800000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000',
Copy link
Contributor

Choose a reason for hiding this comment

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

data should not be needed. if you remove data from the object, will it still work?

Copy link
Author

Choose a reason for hiding this comment

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

yep still working

// @ts-ignore
value.intents[0].segments[0].params = { index: '0' }; // missing value
const { error } = FunctionalSchema.validate(value);
expect(error.message).to.match(/params.value.*is required/);
Copy link
Contributor

Choose a reason for hiding this comment

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

does this error tell me which missing intent/segment/param is required?

Copy link
Author

Choose a reason for hiding this comment

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

True. I made the assertion more specific.

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