Skip to content

Commit

Permalink
feat: add test
Browse files Browse the repository at this point in the history
  • Loading branch information
Gusarich committed Aug 19, 2024
1 parent d1715fb commit baeb420
Show file tree
Hide file tree
Showing 4 changed files with 104 additions and 5 deletions.
8 changes: 4 additions & 4 deletions src/generator/writers/writeStdlib.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1421,21 +1421,21 @@ export function writeStdlib(ctx: WriterContext) {
//

ctx.fun(`__tact_dict_eq`, () => {
ctx.signature(`int __tact_dict_eq(cell a, cell b, int kl)`);
ctx.signature(`int __tact_dict_eq(cell a, cell b)`);
ctx.flag("inline");
ctx.context("stdlib");
ctx.body(() => {
ctx.write(`
(slice key, slice value, int flag) = ${ctx.used("__tact_dict_min")}(a, kl);
(slice key, slice value, int flag) = ${ctx.used("__tact_dict_min")}(a, 1023);
while (flag) {
(slice value_b, int flag_b) = b~${ctx.used("__tact_dict_delete_get")}(kl, key);
(slice value_b, int flag_b) = b~${ctx.used("__tact_dict_delete_get")}(1023, key);
ifnot (flag_b) {
return 0;
}
ifnot (value.slice_hash() == value_b.slice_hash()) {
return 0;
}
(key, val, flag) = ${ctx.used("__tact_dict_next")}(a, kl, key);
(key, value, flag) = ${ctx.used("__tact_dict_next")}(a, 1023, key);
}
return null?(b);
`);
Expand Down
53 changes: 53 additions & 0 deletions src/test/e2e-emulated/__snapshots__/map-comparison.spec.ts.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`map-comparison should implement map comparison correctly 1`] = `
[
{
"$seq": 0,
"events": [
{
"$type": "deploy",
},
{
"$type": "received",
"message": {
"body": {
"cell": "x{602DB8CDE_}
x{CFF}
x{500000000000000000000000000000000000000000000000000000000000000014_}
x{500000000000000000000000000000000000000000000000000000000000000024_}
x{CFF}
x{500000000000000000000000000000000000000000000000000000000000000014_}
x{500000000000000000000000000000000000000000000000000000000000000024_}",
"type": "cell",
},
"bounce": true,
"from": "@treasure(treasure)",
"to": "kQB_fk7kQdo5QXLBsDT5CiTCeaSICOBKsOIkviCSYGKxbfgw",
"type": "internal",
"value": "10",
},
},
{
"$type": "failed",
"errorCode": 9,
"errorMessage": "Cell underflow",
},
{
"$type": "sent-bounced",
"message": {
"body": {
"cell": "x{FFFFFFFF602DB8CDE_}",
"type": "cell",
},
"bounce": false,
"from": "kQB_fk7kQdo5QXLBsDT5CiTCeaSICOBKsOIkviCSYGKxbfgw",
"to": "@treasure(treasure)",
"type": "internal",
"value": "9.996081",
},
},
],
},
]
`;
2 changes: 1 addition & 1 deletion src/test/e2e-emulated/contracts/map-comparison.tact
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ message CompareAddressAddress {
m2: map<Address, Address>;
}

contract MapTraverseTestContract {
contract MapComparisonTestContract {
receive(msg: CompareIntInt) {
require(msg.m1.deepEquals(msg.m2), "Maps are not equal");
}
Expand Down
46 changes: 46 additions & 0 deletions src/test/e2e-emulated/map-comparison.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import { Dictionary, toNano } from "@ton/core";
import { ContractSystem } from "@tact-lang/emulator";
import { __DANGER_resetNodeId } from "../../grammar/ast";
import { MapComparisonTestContract } from "./contracts/output/map-comparison_MapComparisonTestContract";

describe("map-comparison", () => {
beforeEach(() => {
__DANGER_resetNodeId();
});
it("should implement map comparison correctly", async () => {
// Init
const system = await ContractSystem.create();
const treasure = system.treasure("treasure");
const contract = system.open(
await MapComparisonTestContract.fromInit(),
);
const tracker = system.track(contract.address);

// Test
{
const m1: Dictionary<bigint, bigint> = Dictionary.empty(
Dictionary.Keys.BigInt(256),
Dictionary.Values.BigInt(256),
);
m1.set(1n, 2n);
m1.set(3n, 4n);
const m2: Dictionary<bigint, bigint> = Dictionary.empty(
Dictionary.Keys.BigInt(256),
Dictionary.Values.BigInt(256),
);
m2.set(1n, 2n);
m2.set(3n, 4n);
await contract.send(
treasure,
{ value: toNano("10") },
{
$$type: "CompareIntInt",
m1,
m2,
},
);
await system.run();
expect(tracker.collect()).toMatchSnapshot();
}
});
});

0 comments on commit baeb420

Please sign in to comment.