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

Add one more failing test case for structs parsing #507

Merged
merged 2 commits into from
Jul 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 47 additions & 0 deletions src/test/e2e-emulated/__snapshots__/structs.spec.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -281,3 +281,50 @@ exports[`structs should implement structs correctly 12`] = `
},
}
`;

exports[`structs should implement structs correctly 13`] = `
[
{
"$seq": 1,
"events": [
{
"$type": "storage-charged",
"amount": "0.000000014",
},
{
"$type": "received",
"message": {
"body": {
"text": "example",
"type": "text",
},
"bounce": true,
"from": "@treasure(treasure)",
"to": "kQCrlBLOnYwuUVhoEd9stnroUM3J7rKXhQIS3FIYvrDLvXrj",
"type": "internal",
"value": "10",
},
},
{
"$type": "failed",
"errorCode": 9,
"errorMessage": "Cell underflow",
},
{
"$type": "sent-bounced",
"message": {
"body": {
"cell": "x{FFFFFFFF000000006578616D706C65}",
"type": "cell",
},
"bounce": false,
"from": "kQCrlBLOnYwuUVhoEd9stnroUM3J7rKXhQIS3FIYvrDLvXrj",
"to": "@treasure(treasure)",
"type": "internal",
"value": "9.993898",
},
},
],
},
]
`;
20 changes: 20 additions & 0 deletions src/test/e2e-emulated/contracts/structs.tact
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,15 @@ message MyMessage1 {
s: MyStruct2;
}

struct Coin {
first: Int as coins;
second: Int as uint32;
}

fun directParse(payload: Cell): Coin {
return Coin.fromCell(payload);
}

contract StructsTester {
s1: S = S {a: false, b: 21 + 21};
s2: S;
Expand Down Expand Up @@ -134,4 +143,15 @@ contract StructsTester {
let s = globalConstStruct.s;
return s;
}

receive("example") {
let coin = directParse(
beginCell()
.storeCoins(42)
.storeUint(35, 31)
.endCell()
);
dump(coin.first);
dump(coin.second);
}
}
7 changes: 7 additions & 0 deletions src/test/e2e-emulated/structs.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ describe("structs", () => {
const contract = system.open(await StructsTester.fromInit());
await contract.send(treasure, { value: toNano("10") }, null);
await system.run();
const tracker = system.track(contract.address);

expect(await contract.getStructInitializerTest()).toEqual(true);

Expand Down Expand Up @@ -224,5 +225,11 @@ describe("structs", () => {
expect(
await contract.getGlobalConstStructConstantFieldViaVar(),
).toEqual(s6.s);

// https://github.com/tact-lang/tact/issues/472

await contract.send(treasure, { value: toNano("10") }, "example");
await system.run();
expect(tracker.collect()).toMatchSnapshot();
});
});
5 changes: 4 additions & 1 deletion tact.config.json
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,10 @@
{
"name": "structs",
"path": "./src/test/e2e-emulated/contracts/structs.tact",
"output": "./src/test/e2e-emulated/contracts/output"
"output": "./src/test/e2e-emulated/contracts/output",
"options": {
"debug": true
}
},
{
"name": "initof",
Expand Down
Loading