-
Notifications
You must be signed in to change notification settings - Fork 4
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
[BRI-1784] Validate low level declaration args #142
base: v5
Are you sure you want to change the base?
Conversation
There was a problem hiding this 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
src/intents/schemas/lowLevel.ts
Outdated
}); | ||
|
||
const SegmentStructSchema = joi.object({ | ||
data: joi.string().required(), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
data isn't required
src/intents/schemas/lowLevel.ts
Outdated
value: joi.string().required() | ||
}); | ||
|
||
const SegmentParamValueSchema = joi.alternatives().try( |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
There was a problem hiding this 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
src/intents/schemas/lowLevel.ts
Outdated
@@ -0,0 +1,117 @@ | |||
import { segmentFunctionNames, signatureTypes, tokenStandards } from "./constants"; |
There was a problem hiding this comment.
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
src/intents/schemas/lowLevel.ts
Outdated
value: joi.string().required() | ||
}); | ||
|
||
const SegmentParamValueSchema = joi.alternatives().try( |
There was a problem hiding this comment.
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
test/local/fullSchema.test.ts
Outdated
describe('DeclarationArgsSchema', () => { | ||
it('should validate a valid declaration', () => { | ||
const { error } = DeclarationArgsSchema.validate(declarationArgs); | ||
console.log("@@@@@@@@@@@@@@@@@@@", error); |
There was a problem hiding this comment.
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
3ab41ea
to
7adde84
Compare
7adde84
to
2c1c9a6
Compare
@@ -65,8 +65,8 @@ function blockIntervalDutchAuctionSwap ({ | |||
functionName: 'swap01', | |||
params: { | |||
signer: owner, | |||
tokenIn: tokenIn as SegmentParamValue, | |||
tokenOut: tokenOut as SegmentParamValue, | |||
tokenIn: { address: tokenIn.address } as SegmentParamValue, |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
@@ -65,8 +65,8 @@ function blockIntervalDutchAuctionSwap ({ | |||
functionName: 'swap01', | |||
params: { | |||
signer: owner, | |||
tokenIn: tokenIn as SegmentParamValue, | |||
tokenOut: tokenOut as SegmentParamValue, | |||
tokenIn: { address: tokenIn.address } as SegmentParamValue, |
There was a problem hiding this comment.
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', |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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/); |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
No description provided.