-
Notifications
You must be signed in to change notification settings - Fork 191
feat: add test stub generation #3342
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
base: main
Are you sure you want to change the base?
feat: add test stub generation #3342
Conversation
Example
|
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 like the idea behind the PR, it's very fresh and could be useful
However, I think we should discuss the end result more, because all Tact users would be affected by such test template generation, so it needs to be polished
One way is to move it to CLI instead of default build pipeline, or maybe add flag to the tact.config
I think maintaining a template file will be clearer and easier than generating it on-fly with many // !!THIS FILE IS GENERATED BY TACT. COPY IT TO YOUR PROJECT MANUALLY!!
// https://docs.tact-lang.org/book/debug/
{{#imports}}
import {{.}};
{{/imports}}
export type FromInit{{contractName}} = typeof {{contractName}}.fromInit;
export type TestCase = (fromInit: FromInit{{contractName}}) => void;
export const test{{contractName}} = (fromInit: FromInit{{contractName}}) => {
describe("{{contractName}} Contract", () => {
// Test receivers
{{#receivers}}
test{{.}}(fromInit);
{{/receivers}}
// Test getters
{{#getters}}
getterTest{{.}}(fromInit);
{{/getters}}
});
};
const globalSetup = async (fromInit: FromInit{{contractName}}) => {
const blockchain = await Blockchain.create();
// @ts-ignore
const contract = await blockchain.openContract(await fromInit(
// TODO: implement default values
));
// Universal deploy without message
await blockchain.setShardAccount(contract.address, createShardAccount({
address: contract.address,
code: contract.init!.code,
data: contract.init!.data,
balance: 0n,
workchain: 0,
}));
const owner = await blockchain.treasury("owner");
const notOwner = await blockchain.treasury("notOwner");
return { blockchain, contract, owner, notOwner };
};
{{#receiverBlocks}}
{{{.}}}
{{/receiverBlocks}}
{{#getterBlocks}}
{{{.}}}
{{/getterBlocks}}
// entry point
test{{contractName}}({{contractName}}.fromInit.bind({{contractName}})); |
…ttps://github.com/tact-lang/tact into 3287-we-should-generate-test-template-as-wrappers
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.
Great work here! PR approved, please fix small nitpicks
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.
Nice work! Left a couple of nitpicks to resolve altogether
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.
Whoops, chose the wrong radio button :)
Co-authored-by: Novus Nota <68142933+novusnota@users.noreply.github.com>
Co-authored-by: Novus Nota <68142933+novusnota@users.noreply.github.com>
Co-authored-by: Novus Nota <68142933+novusnota@users.noreply.github.com>
Co-authored-by: Novus Nota <68142933+novusnota@users.noreply.github.com>
Co-authored-by: Novus Nota <68142933+novusnota@users.noreply.github.com>
Co-authored-by: Novus Nota <68142933+novusnota@users.noreply.github.com>
Co-authored-by: Novus Nota <68142933+novusnota@users.noreply.github.com>
Co-authored-by: Novus Nota <68142933+novusnota@users.noreply.github.com>
Co-authored-by: Novus Nota <68142933+novusnota@users.noreply.github.com>
Co-authored-by: Novus Nota <68142933+novusnota@users.noreply.github.com>
Co-authored-by: Novus Nota <68142933+novusnota@users.noreply.github.com>
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.
yay!
Closes #3287