feat: add test stub generation#3342
Conversation
|
Example |
Kaladin13
left a comment
There was a problem hiding this comment.
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
Kaladin13
left a comment
There was a problem hiding this comment.
Great work here! PR approved, please fix small nitpicks ![]()
novusnota
left a comment
There was a problem hiding this comment.
Nice work! Left a couple of nitpicks to resolve altogether
novusnota
left a comment
There was a problem hiding this comment.
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>
Closes #3287