Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
Gusarich committed Aug 27, 2024
1 parent 33505eb commit a0d6292
Show file tree
Hide file tree
Showing 5 changed files with 155 additions and 113 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)`);
ctx.signature(`int __tact_dict_eq(cell a, cell b, int kl)`);
ctx.flag("inline");
ctx.context("stdlib");
ctx.body(() => {
ctx.write(`
(slice key, slice value, int flag) = ${ctx.used("__tact_dict_min")}(a, 1023);
(slice key, slice value, int flag) = ${ctx.used("__tact_dict_min")}(a, kl);
while (flag) {
(slice value_b, int flag_b) = b~${ctx.used("__tact_dict_delete_get")}(1023, key);
(slice value_b, int flag_b) = b~${ctx.used("__tact_dict_delete_get")}(kl, key);
ifnot (flag_b) {
return 0;
}
ifnot (value.slice_hash() == value_b.slice_hash()) {
return 0;
}
(key, value, flag) = ${ctx.used("__tact_dict_next")}(a, 1023, key);
(key, value, flag) = ${ctx.used("__tact_dict_next")}(a, kl, key);
}
return null?(b);
`);
Expand Down
53 changes: 0 additions & 53 deletions src/test/e2e-emulated/__snapshots__/map-comparison.spec.ts.snap

This file was deleted.

58 changes: 15 additions & 43 deletions src/test/e2e-emulated/contracts/map-comparison.tact
Original file line number Diff line number Diff line change
@@ -1,55 +1,27 @@
message CompareIntInt {
m1: map<Int, Int>;
m2: map<Int, Int>;
}

message CompareIntCell {
m1: map<Int, Cell>;
m2: map<Int, Cell>;
}

message CompareIntAddress {
m1: map<Int, Address>;
m2: map<Int, Address>;
}

message CompareAddressInt {
m1: map<Address, Int>;
m2: map<Address, Int>;
}

message CompareAddressCell {
m1: map<Address, Cell>;
m2: map<Address, Cell>;
}

message CompareAddressAddress {
m1: map<Address, Address>;
m2: map<Address, Address>;
}

contract MapComparisonTestContract {
receive(msg: CompareIntInt) {
require(msg.m1.deepEquals(msg.m2), "Maps are not equal");
receive() {}

get fun compareIntInt(m1: map<Int, Int>, m2: map<Int, Int>): Bool {
return m1.deepEquals(m2);
}

receive(msg: CompareIntCell) {
require(msg.m1.deepEquals(msg.m2), "Maps are not equal");
get fun compareIntCell(m1: map<Int, Cell>, m2: map<Int, Cell>): Bool {
return m1.deepEquals(m2);
}

receive(msg: CompareIntAddress) {
require(msg.m1.deepEquals(msg.m2), "Maps are not equal");
get fun compareIntAddress(m1: map<Int, Address>, m2: map<Int, Address>): Bool {
return m1.deepEquals(m2);
}

receive(msg: CompareAddressInt) {
require(msg.m1.deepEquals(msg.m2), "Maps are not equal");
get fun compareAddressInt(m1: map<Address, Int>, m2: map<Address, Int>): Bool {
return m1.deepEquals(m2);
}

receive(msg: CompareAddressCell) {
require(msg.m1.deepEquals(msg.m2), "Maps are not equal");
get fun compareAddressCell(m1: map<Address, Cell>, m2: map<Address, Cell>): Bool {
return m1.deepEquals(m2);
}

receive(msg: CompareAddressAddress) {
require(msg.m1.deepEquals(msg.m2), "Maps are not equal");
get fun compareAddressAddress(m1: map<Address, Address>, m2: map<Address, Address>): Bool {
return m1.deepEquals(m2);
}
}
144 changes: 131 additions & 13 deletions src/test/e2e-emulated/map-comparison.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Dictionary, toNano } from "@ton/core";
import { Address, beginCell, Cell, 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";
Expand All @@ -14,10 +14,13 @@ describe("map-comparison", () => {
const contract = system.open(
await MapComparisonTestContract.fromInit(),
);
const tracker = system.track(contract.address);
await contract.send(treasure, { value: toNano("10") }, null);
await system.run();

// Test

{
// Int Int - Equal
const m1: Dictionary<bigint, bigint> = Dictionary.empty(
Dictionary.Keys.BigInt(256),
Dictionary.Values.BigInt(256),
Expand All @@ -30,17 +33,132 @@ describe("map-comparison", () => {
);
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();
expect(await contract.getCompareIntInt(m1, m2)).toBe(true);
}

{
// Int Int - Not Equal
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, 5n);
expect(await contract.getCompareIntInt(m1, m2)).toBe(false);
}

{
// Int Cell - Equal
const m1: Dictionary<bigint, Cell> = Dictionary.empty(
Dictionary.Keys.BigInt(256),
Dictionary.Values.Cell(),
);
m1.set(1n, beginCell().storeUint(123, 64).endCell());
m1.set(3n, beginCell().storeUint(456, 64).endCell());
const m2: Dictionary<bigint, Cell> = Dictionary.empty(
Dictionary.Keys.BigInt(256),
Dictionary.Values.Cell(),
);
m2.set(1n, beginCell().storeUint(123, 64).endCell());
m2.set(3n, beginCell().storeUint(456, 64).endCell());
expect(await contract.getCompareIntCell(m1, m2)).toBe(true);
}

{
// Int Cell - Not Equal
const m1: Dictionary<bigint, Cell> = Dictionary.empty(
Dictionary.Keys.BigInt(256),
Dictionary.Values.Cell(),
);
m1.set(1n, beginCell().storeUint(123, 64).endCell());
m1.set(3n, beginCell().storeUint(456, 64).endCell());
const m2: Dictionary<bigint, Cell> = Dictionary.empty(
Dictionary.Keys.BigInt(256),
Dictionary.Values.Cell(),
);
m2.set(1n, beginCell().storeUint(123, 64).endCell());
m2.set(3n, beginCell().storeUint(457, 64).endCell());
expect(await contract.getCompareIntCell(m1, m2)).toBe(false);
}

{
// Int Address - Equal
const m1: Dictionary<bigint, Address> = Dictionary.empty(
Dictionary.Keys.BigInt(256),
Dictionary.Values.Address(),
);
m1.set(
1n,
Address.parseRaw(
"0:0000000000000000000000000000000000000000000000000000000000000002",
),
);
m1.set(
3n,
Address.parseRaw(
"0:0000000000000000000000000000000000000000000000000000000000000004",
),
);
const m2: Dictionary<bigint, Address> = Dictionary.empty(
Dictionary.Keys.BigInt(256),
Dictionary.Values.Address(),
);
m2.set(
1n,
Address.parseRaw(
"0:0000000000000000000000000000000000000000000000000000000000000002",
),
);
m2.set(
3n,
Address.parseRaw(
"0:0000000000000000000000000000000000000000000000000000000000000004",
),
);
expect(await contract.getCompareIntAddress(m1, m2)).toBe(true);
}

{
// Int Address - Not Equal
const m1: Dictionary<bigint, Address> = Dictionary.empty(
Dictionary.Keys.BigInt(256),
Dictionary.Values.Address(),
);
m1.set(
1n,
Address.parseRaw(
"0:0000000000000000000000000000000000000000000000000000000000000002",
),
);
m1.set(
3n,
Address.parseRaw(
"0:0000000000000000000000000000000000000000000000000000000000000004",
),
);
const m2: Dictionary<bigint, Address> = Dictionary.empty(
Dictionary.Keys.BigInt(256),
Dictionary.Values.Address(),
);
m2.set(
1n,
Address.parseRaw(
"0:0000000000000000000000000000000000000000000000000000000000000002",
),
);
m2.set(
3n,
Address.parseRaw(
"0:0000000000000000000000000000000000000000000000000000000000000005",
),
);
expect(await contract.getCompareIntAddress(m1, m2)).toBe(false);
}
});
});
5 changes: 5 additions & 0 deletions tact.config.json
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,11 @@
"path": "./src/test/e2e-emulated/contracts/map-traverse.tact",
"output": "./src/test/e2e-emulated/contracts/output"
},
{
"name": "map-comparison",
"path": "./src/test/e2e-emulated/contracts/map-comparison.tact",
"output": "./src/test/e2e-emulated/contracts/output"
},
{
"name": "mutating-method-chaining",
"path": "./src/test/e2e-emulated/contracts/mutating-method-chaining.tact",
Expand Down

0 comments on commit a0d6292

Please sign in to comment.