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

[DRAFT] Select contracts implementing the correct trait from the Clarinet project for argument generation #88

Draft
wants to merge 10 commits into
base: master
Choose a base branch
from

Conversation

BowTiedRadone
Copy link
Collaborator

This PR is still a draft. Related issue: #65.

Copy link
Member

@moodmosaic moodmosaic left a 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.)

citizen.tests.ts Outdated Show resolved Hide resolved
property.ts Outdated Show resolved Hide resolved
property.ts Outdated Show resolved Hide resolved
shared.types.ts Show resolved Hide resolved
shared.types.ts Outdated Show resolved Hide resolved
@BowTiedRadone BowTiedRadone force-pushed the feat/project-trait-selection branch from fbbb156 to 74a086b Compare January 17, 2025 21:47
Copy link
Member

@moodmosaic moodmosaic left a 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.

ast1737030528990.json Outdated Show resolved Hide resolved
example/contracts/trait.clar Outdated Show resolved Hide resolved
property.ts Show resolved Hide resolved
property.ts Outdated Show resolved Hide resolved
@BowTiedRadone BowTiedRadone force-pushed the feat/project-trait-selection branch from 74a086b to e92b62a Compare January 20, 2025 18:16
@BowTiedRadone BowTiedRadone force-pushed the feat/project-trait-selection branch from e92b62a to ae0d20c Compare January 20, 2025 21:25
...functionToArbitrary(
r.selectedFunction,
simnetAddresses,
simnet
Copy link
Member

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?

Copy link
Collaborator Author

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.

Copy link
Member

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
Copy link
Member

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?

Copy link
Collaborator Author

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.

Copy link
Member

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.

Copy link
Member

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.

property.ts Outdated Show resolved Hide resolved
property.ts Outdated Show resolved Hide resolved
property.ts Outdated Show resolved Hide resolved
traits.tests.ts Outdated Show resolved Hide resolved
traits.tests.ts Outdated Show resolved Hide resolved
traits.tests.ts Outdated Show resolved Hide resolved
traits.tests.ts Outdated Show resolved Hide resolved
traits.tests.ts Show resolved Hide resolved
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.
@BowTiedRadone BowTiedRadone force-pushed the feat/project-trait-selection branch from c65fc8a to c189840 Compare January 21, 2025 14:13
@BowTiedRadone BowTiedRadone force-pushed the feat/project-trait-selection branch from 85dce3b to 1d76720 Compare January 21, 2025 14:26
@BowTiedRadone BowTiedRadone force-pushed the feat/project-trait-selection branch from 2b837d9 to bef6767 Compare January 21, 2025 14:35
...functionToArbitrary(
r.selectedFunction,
simnetAddresses,
simnet
Copy link
Member

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
Copy link
Member

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.

property.ts Outdated Show resolved Hide resolved
...functionToArbitrary(
r.selectedTestFunction,
simnetAddresses,
simnet
Copy link
Member

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,
Copy link
Member

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[]>,
Copy link
Member

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?

traits.ts Outdated Show resolved Hide resolved
ast: IContractAST,
functionName: string,
paramPath: string[]
): [string, any] | [undefined, undefined] => {
Copy link
Member

Choose a reason for hiding this comment

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

Is it documented?

Copy link
Member

@moodmosaic moodmosaic left a 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)
Copy link
Member

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?

ast1737030528990.json Outdated Show resolved Hide resolved
@@ -3,6 +3,9 @@ name = "example"
telemetry = false
cache_dir = "./.cache"

[[project.requirements]]
contract_id = 'SP4SZE494VC2YC5JYG7AYFQ44F5Q4PYV7DVMDPBG.ststx-token'
Copy link
Member

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)
Copy link
Member

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
Copy link
Member

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";
Copy link
Member

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";
Copy link
Member

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";
Copy link
Member

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
Copy link
Member

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[]>();
Copy link
Member

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. 🌟

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.

2 participants