-
Notifications
You must be signed in to change notification settings - Fork 0
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
[DRAFT] Select contracts implementing the correct trait from the Clarinet project for argument generation #88
base: master
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.
Interesting work on the draft implementation so far! Left some comments.
The next steps I see are:
- Create (perhaps parameterized?) test(s) based on the draft/example in
property.ts
. - Add as many more test cases as possible to expand coverage.
- Tweak the draft implementation to ensure all tests pass.
- (Once tests provide decent coverage, we'll consider refactoring with a
parsec-style library.)
fbbb156
to
74a086b
Compare
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.
Left questions and comments at the abstraction level. Let's make sure we get those right before proceeding.
74a086b
to
e92b62a
Compare
e92b62a
to
ae0d20c
Compare
...functionToArbitrary( | ||
r.selectedFunction, | ||
simnetAddresses, | ||
simnet |
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.
Do we need multiple stuff from the simnet object? Or just one?
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.
Currently we need to get any project contract's AST.
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.
Couldn't we pass just that function then from the simnet? E.g. pass simnet.getContractAST
as a delegate.
...functionToArbitrary( | ||
r.selectedInvariant, | ||
simnetAddresses, | ||
simnet |
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.
Do we need multiple stuff from the simnet object? Or just one?
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.
Currently, matching traits are selected during argument generation. This approach is WIP and inefficient, but it works for now. Ideally, once all trait reference nesting types are handled, we’ll pre-populate a map that links stringified trait data to the contracts implementing it. This will eliminate the need to pass simnet, but the pre-populated map.
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.
Couldn't we pass just that function then from the simnet? E.g. pass simnet.getContractAST
as a delegate.
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.
Passing a data structure (than a bag of functions) would be the most efficient way, agreed.
This commit moves the trait test inputs from the fixtures floder directly to `traits.tests.ts` in a `testInputs` object. This is done to make it easier to navigate the test inputs and to make it easier to add new test inputs in the future.
c65fc8a
to
c189840
Compare
85dce3b
to
1d76720
Compare
2b837d9
to
bef6767
Compare
...functionToArbitrary( | ||
r.selectedFunction, | ||
simnetAddresses, | ||
simnet |
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.
Couldn't we pass just that function then from the simnet? E.g. pass simnet.getContractAST
as a delegate.
...functionToArbitrary( | ||
r.selectedInvariant, | ||
simnetAddresses, | ||
simnet |
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.
Couldn't we pass just that function then from the simnet? E.g. pass simnet.getContractAST
as a delegate.
...functionToArbitrary( | ||
r.selectedTestFunction, | ||
simnetAddresses, | ||
simnet |
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.
Same comment about passing something more specific from the simnet here instead of the whole instance.
@@ -1,12 +1,14 @@ | |||
import fc from "fast-check"; | |||
import { | |||
BaseType, | |||
BaseTypeAfterEnrich, |
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.
Could be at least EnrichedType? or EnrichedBaseType? In case we go with "enriched".
@@ -54,20 +58,25 @@ export const getFunctionsFromContractInterfaces = ( | |||
); | |||
|
|||
export const getFunctionsListForContract = ( | |||
functionsMap: Map<string, ContractInterfaceFunction[]>, | |||
functionsMap: Map<string, any[]>, |
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.
Shouldn't any
be EnrichedXyz
?
ast: IContractAST, | ||
functionName: string, | ||
paramPath: string[] | ||
): [string, any] | [undefined, undefined] => { |
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.
Is it documented?
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.
This is massive 🥇 After refactoring simnet
and coming up with candidate alternatives for "enrich" this should be ready for review.
@@ -0,0 +1,3 @@ | |||
(define-public (function) |
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.
This contract is named trait but has just a function in it?
@@ -3,6 +3,9 @@ name = "example" | |||
telemetry = false | |||
cache_dir = "./.cache" | |||
|
|||
[[project.requirements]] | |||
contract_id = 'SP4SZE494VC2YC5JYG7AYFQ44F5Q4PYV7DVMDPBG.ststx-token' |
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 take it that adding this as requirement adds also dao
and sip-010-trait-ft-standard
, right?
@@ -0,0 +1,9 @@ | |||
(use-trait ft-trait 'SP4SZE494VC2YC5JYG7AYFQ44F5Q4PYV7DVMDPBG.sip-010-trait-ft-standard.sip-010-trait) |
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.
If we use this trait in the examples, why do we require ststx-token
after all?
...functionToArbitrary( | ||
r.selectedInvariant, | ||
simnetAddresses, | ||
simnet |
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.
Passing a data structure (than a bag of functions) would be the most efficient way, agreed.
|
||
it("correctly enriches interface with trait reference data for a direct trait that is the first parameter", () => { | ||
// Arrange | ||
const targetContractId = "ST1PQHQKV0RJXZFY1DGX8MNSNYVE3VGZJSRTPGZGM.trait"; |
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.
Same here. This could be moved just before the expected
.
|
||
it("correctly enriches interface with trait reference data for a direct trait that is the second parameter", () => { | ||
// Arrange | ||
const targetContractId = "ST1PQHQKV0RJXZFY1DGX8MNSNYVE3VGZJSRTPGZGM.trait"; |
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.
Same here.
|
||
it("correctly enriches interface with trait reference data for a direct trait that is the fifth parameter", () => { | ||
// Arrange | ||
const targetContractId = "ST1PQHQKV0RJXZFY1DGX8MNSNYVE3VGZJSRTPGZGM.trait"; |
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.
Same here and for the rest of the occurrences.
"ft-trait", | ||
{ | ||
Imported: { | ||
n |
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.
Made it to the end 🏁 As discussed, I think this is still way better than searching through pesky text files (and also relying on filesystem to do its thing during CI). Happy to see this 🎉
functionInterfaceList: ContractInterfaceFunction[], | ||
targetContractId: string | ||
): Map<string, EnrichedContractInterfaceFunction[]> => { | ||
const enriched = new Map<string, EnrichedContractInterfaceFunction[]>(); |
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.
At this point I feel so enriched. 🌟
This PR is still a draft. Related issue: #65.