Skip to content

Commit 524b030

Browse files
authored
fix(wrappers): generated code for contract with init(init: Init) (#1709)
1 parent 7f3bb27 commit 524b030

File tree

4 files changed

+59
-3
lines changed

4 files changed

+59
-3
lines changed

dev-docs/CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7777
- Allow constant/trait constants depend on each other: PR [#1622](https://github.com/tact-lang/tact/pull/1622)
7878
- Combine all generated FunC code into a single file: PR [#1698](https://github.com/tact-lang/tact/pull/1698)
7979
- Runtime `sha256` now work for arbitrary strings with length >= 128: PR [#1626](https://github.com/tact-lang/tact/pull/1626)
80+
- Generated code in TypeScript wrappers for contract with `init(init: Init)`: PR [#1709](https://github.com/tact-lang/tact/pull/1709)
8081
- Error message for comment (text) receivers with 124 bytes or more: PR [#1711](https://github.com/tact-lang/tact/pull/1711)
8182

8283
### Docs

src/bindings/writeTypescript.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -290,10 +290,10 @@ export function writeTypescript(
290290
);
291291
w.inIndent(() => {
292292
w.append(
293-
`const init = await ${abi.name}_init(${init!.args.map((v) => v.name).join(", ")});`,
293+
`const __gen_init = await ${abi.name}_init(${init!.args.map((v) => v.name).join(", ")});`,
294294
);
295-
w.append(`const address = contractAddress(0, init);`);
296-
w.append(`return new ${abi.name}(address, init);`);
295+
w.append(`const address = contractAddress(0, __gen_init);`);
296+
w.append(`return new ${abi.name}(address, __gen_init);`);
297297
});
298298
w.append(`}`);
299299
w.append();
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import { toNano } from "@ton/core";
2+
import { Blockchain, SandboxContract, TreasuryContract } from "@ton/sandbox";
3+
import { Test } from "./contracts/output/contract-with-init-init-parameter_Test";
4+
import "@ton/test-utils";
5+
6+
describe("contract-with-init-init-parameter", () => {
7+
let blockchain: Blockchain;
8+
let treasure: SandboxContract<TreasuryContract>;
9+
let contract: SandboxContract<Test>;
10+
11+
beforeEach(async () => {
12+
blockchain = await Blockchain.create();
13+
blockchain.verbosity.print = false;
14+
treasure = await blockchain.treasury("treasure");
15+
16+
contract = blockchain.openContract(
17+
await Test.fromInit({
18+
$$type: "Init",
19+
foo: 99n,
20+
}),
21+
);
22+
23+
const deployResult = await contract.send(
24+
treasure.getSender(),
25+
{ value: toNano("0.5") },
26+
null,
27+
);
28+
29+
expect(deployResult.transactions).toHaveTransaction({
30+
from: treasure.address,
31+
to: contract.address,
32+
success: true,
33+
deploy: true,
34+
});
35+
});
36+
37+
it("should return correct result", async () => {
38+
expect(await contract.getData()).toBe(99n);
39+
});
40+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
struct Init { foo: Int as uint8 }
2+
3+
contract Test {
4+
foo: Int;
5+
6+
init(init: Init) {
7+
self.foo = init.foo;
8+
}
9+
10+
receive() {}
11+
12+
get fun data(): Int {
13+
return self.foo;
14+
}
15+
}

0 commit comments

Comments
 (0)