Skip to content

Commit

Permalink
test: a failing case for structs parsing (#507)
Browse files Browse the repository at this point in the history
  • Loading branch information
Gusarich committed Jul 3, 2024
1 parent 6ed57e7 commit e7400c0
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 1 deletion.
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

0 comments on commit e7400c0

Please sign in to comment.