diff --git a/src/abi/map.ts b/src/abi/map.ts index 1d4932660..162dc4667 100644 --- a/src/abi/map.ts +++ b/src/abi/map.ts @@ -278,6 +278,66 @@ export const MapFunctions: { [key: string]: AbiFunction } = { throwError(`set expects a map with Int keys`, ref); } }, + del: { + name: 'del', + resolve(ctx, args, ref) { + + // Check arguments + if (args.length !== 2) { + throwError('del expects one argument', ref); // Ignore self argument + } + let self = args[0]; + if (!self || self.kind !== 'map') { + throwError('del expects a map as self argument', ref); // Should not happen + } + + // Check key type + if (args[1].kind !== 'ref' || args[1].optional) { + throwError('del expects a direct type as first argument', ref); + } + if (args[1].name !== self.key) { + throwError(`del expects a ${self.key} as first argument`, ref); + } + + // Returns nothing + return { kind: 'void' }; + }, + generate: (ctx, args, exprs, ref) => { + + if (args.length !== 2) { + throwError('del expects one argument', ref); // Ignore self argument + } + let self = args[0]; + if (!self || self.kind !== 'map') { + throwError('del expects a map as self argument', ref); // Should not happen + } + + // Render expressions + let resolved = exprs.map((v) => writeExpression(v, ctx)); + + // Handle Int key + if (self.key === 'Int') { + let bits = 257; + let kind = 'int'; + if (self.keyAs && self.keyAs.startsWith('int')) { + bits = parseInt(self.keyAs.slice(3), 10); + } else if (self.keyAs && self.keyAs.startsWith('uint')) { + bits = parseInt(self.keyAs.slice(4), 10); + kind = 'uint'; + } + ctx.used(`__tact_dict_delete_${kind}`); + return `${resolved[0]}~__tact_dict_delete_${kind}(${bits}, ${resolved[1]})`; + } + + // Handle Address key + if (self.key === 'Address') { + ctx.used(`__tact_dict_delete`); + return `${resolved[0]}~__tact_dict_delete(267, ${resolved[1]})`; + } + + throwError(`del expects a map with Int keys`, ref); + } + }, asCell: { name: 'asCell', resolve(ctx, args, ref) { diff --git a/src/generator/writers/writeStdlib.ts b/src/generator/writers/writeStdlib.ts index d3c5ce96c..7a20dd702 100644 --- a/src/generator/writers/writeStdlib.ts +++ b/src/generator/writers/writeStdlib.ts @@ -161,6 +161,18 @@ export function writeStdlib(ctx: WriterContext) { ctx.asm(`asm(index dict key_len) "DICTDEL"`); }); + ctx.fun('__tact_dict_delete_int', () => { + ctx.signature(`(cell, int) __tact_dict_delete_int(cell dict, int key_len, int index)`); + ctx.context('stdlib'); + ctx.asm(`asm(index dict key_len) "DICTIDEL"`); + }); + + ctx.fun('__tact_dict_delete_uint', () => { + ctx.signature(`(cell, int) __tact_dict_delete_uint(cell dict, int key_len, int index)`); + ctx.context('stdlib'); + ctx.asm(`asm(index dict key_len) "DICTUDEL"`); + }); + ctx.fun('__tact_dict_set_ref', () => { ctx.signature(`((cell), ()) __tact_dict_set_ref(cell dict, int key_len, slice index, cell value)`); ctx.context('stdlib'); diff --git a/src/imports/stdlib.ts b/src/imports/stdlib.ts index edb52481d..4988af201 100644 --- a/src/imports/stdlib.ts +++ b/src/imports/stdlib.ts @@ -170,8 +170,8 @@ files['std/contract.tact'] = files['std/crypto.tact'] = 'QG5hbWUoY2VsbF9oYXNoKQpleHRlbmRzIG5hdGl2ZSBoYXNoKHNlbGY6IENlbGwpOiBJbnQ7CgpAbmFtZShzbGljZV9oYXNoKQpleHRlbmRzIG5hdGl2ZSBoYXNoKHNl' + 'bGY6IFNsaWNlKTogSW50OwoKQG5hbWUoY2hlY2tfc2lnbmF0dXJlKQpuYXRpdmUgY2hlY2tTaWduYXR1cmUoaGFzaDogSW50LCBzaWduYXR1cmU6IFNsaWNlLCBwdWJs' + - 'aWNfa2V5OiBJbnQpOiBCb29sOwoKQG5hbWUoY2hlY2tfZGF0YV9zaWduYXR1cmUpCm5hdGl2ZSBjaGVja0RhdGFTaWduYXR1cmUoaGFzaDogU2xpY2UsIHNpZ25hdHVy' + - 'ZTogU2xpY2UsIHB1YmxpY19rZXk6IFNsaWNlKTogQm9vbDs='; + 'aWNfa2V5OiBJbnQpOiBCb29sOwoKQG5hbWUoY2hlY2tfZGF0YV9zaWduYXR1cmUpCm5hdGl2ZSBjaGVja0RhdGFTaWduYXR1cmUoZGF0YTogU2xpY2UsIHNpZ25hdHVy' + + 'ZTogU2xpY2UsIHB1YmxpY19rZXk6IEludCk6IEJvb2w7Cg=='; files['std/debug.tact'] = 'QG5hbWUodGhyb3cpCm5hdGl2ZSBuYXRpdmVUaHJvdyhjb2RlOiBJbnQpOwoKQG5hbWUodGhyb3dfd2hlbikKbmF0aXZlIG5hdGl2ZVRocm93V2hlbihjb2RlOiBJbnQs' + 'IGNvbmRpdGlvbjogQm9vbCk7CgpAbmFtZSh0aHJvdykKbmF0aXZlIHRocm93KGNvZGU6IEludCk7CgpAbmFtZSh0aHJvd191bmxlc3MpCm5hdGl2ZSBuYXRpdmVUaHJv' + diff --git a/src/test/feature-map.spec.ts b/src/test/feature-map.spec.ts index a98c62fa0..9570257ed 100644 --- a/src/test/feature-map.spec.ts +++ b/src/test/feature-map.spec.ts @@ -300,4 +300,281 @@ describe('feature-map', () => { throw e; } }); + + it('should implement key deletion correctly', async () => { + jest.setTimeout(2 * 60000); + try { + + // Init contract + let system = await ContractSystem.create(); + let treasure = system.treasure('treasure'); + let contract = system.open(await MapTestContract.fromInit()); + await contract.send(treasure, { value: toNano('10') }, null); + await system.run(); + + // Initial state + expect((await contract.getIntMap1()).size).toBe(0); + expect((await contract.getIntMap2()).size).toBe(0); + expect((await contract.getIntMap3()).size).toBe(0); + expect((await contract.getIntMap4()).size).toBe(0); + expect((await contract.getIntMap5()).size).toBe(0); + expect((await contract.getIntMap6_1()).size).toBe(0); + expect((await contract.getIntMap6_2()).size).toBe(0); + expect((await contract.getIntMap6_3()).size).toBe(0); + expect((await contract.getIntMap6_4()).size).toBe(0); + expect((await contract.getIntMap6_5()).size).toBe(0); + expect((await contract.getIntMap6_6()).size).toBe(0); + expect((await contract.getIntMap6_7()).size).toBe(0); + expect((await contract.getIntMap7_1()).size).toBe(0); + expect((await contract.getIntMap7_2()).size).toBe(0); + expect((await contract.getIntMap7_3()).size).toBe(0); + expect((await contract.getIntMap7_4()).size).toBe(0); + expect((await contract.getIntMap7_5()).size).toBe(0); + expect((await contract.getIntMap7_6()).size).toBe(0); + expect((await contract.getIntMap8_1()).size).toBe(0); + expect((await contract.getIntMap8_2()).size).toBe(0); + expect((await contract.getIntMap8_3()).size).toBe(0); + expect((await contract.getIntMap8_4()).size).toBe(0); + expect((await contract.getIntMap8_5()).size).toBe(0); + expect((await contract.getIntMap8_6()).size).toBe(0); + expect((await contract.getIntMap8_7()).size).toBe(0); + expect((await contract.getIntMap9_1()).size).toBe(0); + expect((await contract.getIntMap9_2()).size).toBe(0); + expect((await contract.getIntMap9_3()).size).toBe(0); + expect((await contract.getIntMap9_4()).size).toBe(0); + expect((await contract.getIntMap9_5()).size).toBe(0); + expect((await contract.getIntMap9_6()).size).toBe(0); + expect((await contract.getAddrMap1()).size).toBe(0); + expect((await contract.getAddrMap2()).size).toBe(0); + expect((await contract.getAddrMap3()).size).toBe(0); + expect((await contract.getAddrMap4()).size).toBe(0); + expect((await contract.getAddrMap6_1()).size).toBe(0); + expect((await contract.getAddrMap6_2()).size).toBe(0); + expect((await contract.getAddrMap6_3()).size).toBe(0); + expect((await contract.getAddrMap6_4()).size).toBe(0); + expect((await contract.getAddrMap6_5()).size).toBe(0); + expect((await contract.getAddrMap6_6()).size).toBe(0); + expect((await contract.getAddrMap6_7()).size).toBe(0); + expect((await contract.getAddrMap7_1()).size).toBe(0); + expect((await contract.getAddrMap7_2()).size).toBe(0); + expect((await contract.getAddrMap7_3()).size).toBe(0); + expect((await contract.getAddrMap7_4()).size).toBe(0); + expect((await contract.getAddrMap7_5()).size).toBe(0); + expect((await contract.getAddrMap7_6()).size).toBe(0); + + // Keys for test + let keys: bigint[] = []; + keys.push(1n); + keys.push(0n); + keys.push(-1n); + keys.push(10102312312312312312312n); + keys.push(-10102312312312312312312n); + for (let k of keys) { + + // Check keys to be empty + expect(await contract.getIntMap1Value(k)).toBeNull(); + expect(await contract.getIntMap2Value(k)).toBeNull(); + expect(await contract.getIntMap3Value(k)).toBeNull(); + expect(await contract.getIntMap4Value(k)).toBeNull(); + + // Set keys + let valueInt = k * 10n; + let valueBool = k < 0n; + let addr = randomAddress(0, 'addr-' + k.toString(10)); + let valueCell = beginCell().storeUint(123123, 128).endCell(); + let valueStruct: SomeStruct = { $$type: 'SomeStruct', value: 10012312n }; + let valueAddr = randomAddress(0, 'value-' + k.toString(10)); + let keySmall = k % 100n; + let keySmallAbs = (k > 0 ? k : -k) % 100n; + let valueSmall = k % 100n; + let valueSmallAbs = (k > 0 ? k : -k) % 100n; + await contract.send(treasure, { value: toNano(1) }, { $$type: 'SetIntMap1', key: k, value: valueInt }); + await contract.send(treasure, { value: toNano(1) }, { $$type: 'SetIntMap2', key: k, value: valueBool }); + await contract.send(treasure, { value: toNano(1) }, { $$type: 'SetIntMap3', key: k, value: valueCell }); + await contract.send(treasure, { value: toNano(1) }, { $$type: 'SetIntMap4', key: k, value: valueStruct }); + await contract.send(treasure, { value: toNano(1) }, { $$type: 'SetIntMap5', key: k, value: valueAddr }); + await contract.send(treasure, { value: toNano(1) }, { $$type: 'SetIntMap6', key: keySmall, value: valueInt }); + await contract.send(treasure, { value: toNano(1) }, { $$type: 'SetUIntMap7', key: keySmallAbs, value: valueInt }); + await contract.send(treasure, { value: toNano(1) }, { $$type: 'SetIntMap8', key: k, value: valueSmall }); + await contract.send(treasure, { value: toNano(1) }, { $$type: 'SetUIntMap9', key: k, value: valueSmallAbs }); + await contract.send(treasure, { value: toNano(1) }, { $$type: 'SetAddrMap1', key: addr, value: valueInt }); + await contract.send(treasure, { value: toNano(1) }, { $$type: 'SetAddrMap2', key: addr, value: valueBool }); + await contract.send(treasure, { value: toNano(1) }, { $$type: 'SetAddrMap3', key: addr, value: valueCell }); + await contract.send(treasure, { value: toNano(1) }, { $$type: 'SetAddrMap4', key: addr, value: valueStruct }); + await contract.send(treasure, { value: toNano(1) }, { $$type: 'SetAddrMap5', key: addr, value: valueAddr }); + await contract.send(treasure, { value: toNano(1) }, { $$type: 'SetAddrMap6', key: addr, value: valueSmall }); + await contract.send(treasure, { value: toNano(1) }, { $$type: 'SetAddrMap7', key: addr, value: valueSmallAbs }); + await system.run(); + + // Check value set + expect((await contract.getIntMap1Value(k))).toBe(valueInt); + expect((await contract.getIntMap2Value(k))!).toBe(valueBool); + expect((await contract.getIntMap3Value(k))!.equals(valueCell)).toBe(true); + expect(strEq((await contract.getIntMap4Value(k))!, valueStruct)).toBe(true); + expect((await contract.getIntMap5Value(k))!.equals(valueAddr)).toBe(true); + expect((await contract.getIntMap6_1Value(keySmall))).toBe(valueInt); + expect((await contract.getIntMap6_2Value(keySmall))).toBe(valueInt); + expect((await contract.getIntMap6_3Value(keySmall))).toBe(valueInt); + expect((await contract.getIntMap6_4Value(keySmall))).toBe(valueInt); + expect((await contract.getIntMap6_5Value(keySmall))).toBe(valueInt); + expect((await contract.getIntMap6_6Value(keySmall))).toBe(valueInt); + expect((await contract.getIntMap6_7Value(keySmall))).toBe(valueInt); + expect((await contract.getIntMap7_1Value(keySmallAbs))).toBe(valueInt); + expect((await contract.getIntMap7_2Value(keySmallAbs))).toBe(valueInt); + expect((await contract.getIntMap7_3Value(keySmallAbs))).toBe(valueInt); + expect((await contract.getIntMap7_4Value(keySmallAbs))).toBe(valueInt); + expect((await contract.getIntMap7_5Value(keySmallAbs))).toBe(valueInt); + expect((await contract.getIntMap7_6Value(keySmallAbs))).toBe(valueInt); + expect((await contract.getIntMap8_1Value(k))).toBe(valueSmall); + expect((await contract.getIntMap8_2Value(k))).toBe(valueSmall); + expect((await contract.getIntMap8_3Value(k))).toBe(valueSmall); + expect((await contract.getIntMap8_4Value(k))).toBe(valueSmall); + expect((await contract.getIntMap8_5Value(k))).toBe(valueSmall); + expect((await contract.getIntMap8_6Value(k))).toBe(valueSmall); + expect((await contract.getIntMap8_7Value(k))).toBe(valueSmall); + expect((await contract.getIntMap9_1Value(k))).toBe(valueSmallAbs); + expect((await contract.getIntMap9_2Value(k))).toBe(valueSmallAbs); + expect((await contract.getIntMap9_3Value(k))).toBe(valueSmallAbs); + expect((await contract.getIntMap9_4Value(k))).toBe(valueSmallAbs); + expect((await contract.getIntMap9_5Value(k))).toBe(valueSmallAbs); + expect((await contract.getIntMap9_6Value(k))).toBe(valueSmallAbs); + expect((await contract.getIntMap10Value(keySmall, valueInt))).toBe(valueInt * 7n); + expect((await contract.getIntMap11Value(keySmallAbs, valueInt))).toBe(valueInt * 6n); + expect((await contract.getIntMap12Value(k, valueSmall))).toBe(valueSmall * 7n); + expect((await contract.getIntMap13Value(k, valueSmallAbs))).toBe(valueSmallAbs * 7n); + expect((await contract.getAddrMap1Value(addr))).toBe(valueInt); + expect((await contract.getAddrMap2Value(addr))!).toBe(valueBool); + expect((await contract.getAddrMap3Value(addr))!.equals(valueCell)).toBe(true); + expect(strEq((await contract.getAddrMap4Value(addr))!, valueStruct)).toBe(true); + expect((await contract.getAddrMap5Value(addr))!.equals(valueAddr)).toBe(true); + expect((await contract.getAddrMap6_1Value(addr))).toBe(valueSmall); + expect((await contract.getAddrMap6_2Value(addr))).toBe(valueSmall); + expect((await contract.getAddrMap6_3Value(addr))).toBe(valueSmall); + expect((await contract.getAddrMap6_4Value(addr))).toBe(valueSmall); + expect((await contract.getAddrMap6_5Value(addr))).toBe(valueSmall); + expect((await contract.getAddrMap6_6Value(addr))).toBe(valueSmall); + expect((await contract.getAddrMap6_7Value(addr))).toBe(valueSmall); + expect((await contract.getAddrMap7_1Value(addr))).toBe(valueSmallAbs); + expect((await contract.getAddrMap7_2Value(addr))).toBe(valueSmallAbs); + expect((await contract.getAddrMap7_3Value(addr))).toBe(valueSmallAbs); + expect((await contract.getAddrMap7_4Value(addr))).toBe(valueSmallAbs); + expect((await contract.getAddrMap7_5Value(addr))).toBe(valueSmallAbs); + expect((await contract.getAddrMap7_6Value(addr))).toBe(valueSmallAbs); + + // Sizes + expect((await contract.getIntMap1()).size).toBe(1); + expect((await contract.getIntMap2()).size).toBe(1); + expect((await contract.getIntMap3()).size).toBe(1); + expect((await contract.getIntMap4()).size).toBe(1); + expect((await contract.getIntMap5()).size).toBe(1); + expect((await contract.getIntMap6_1()).size).toBe(1); + expect((await contract.getIntMap6_2()).size).toBe(1); + expect((await contract.getIntMap6_3()).size).toBe(1); + expect((await contract.getIntMap6_4()).size).toBe(1); + expect((await contract.getIntMap6_5()).size).toBe(1); + expect((await contract.getIntMap6_6()).size).toBe(1); + expect((await contract.getIntMap6_7()).size).toBe(1); + expect((await contract.getIntMap7_1()).size).toBe(1); + expect((await contract.getIntMap7_2()).size).toBe(1); + expect((await contract.getIntMap7_3()).size).toBe(1); + expect((await contract.getIntMap7_4()).size).toBe(1); + expect((await contract.getIntMap7_5()).size).toBe(1); + expect((await contract.getIntMap7_6()).size).toBe(1); + expect((await contract.getIntMap8_1()).size).toBe(1); + expect((await contract.getIntMap8_2()).size).toBe(1); + expect((await contract.getIntMap8_3()).size).toBe(1); + expect((await contract.getIntMap8_4()).size).toBe(1); + expect((await contract.getIntMap8_5()).size).toBe(1); + expect((await contract.getIntMap8_6()).size).toBe(1); + expect((await contract.getIntMap8_7()).size).toBe(1); + expect((await contract.getIntMap9_1()).size).toBe(1); + expect((await contract.getIntMap9_2()).size).toBe(1); + expect((await contract.getIntMap9_3()).size).toBe(1); + expect((await contract.getIntMap9_4()).size).toBe(1); + expect((await contract.getIntMap9_5()).size).toBe(1); + expect((await contract.getIntMap9_6()).size).toBe(1); + expect((await contract.getAddrMap1()).size).toBe(1); + expect((await contract.getAddrMap2()).size).toBe(1); + expect((await contract.getAddrMap3()).size).toBe(1); + expect((await contract.getAddrMap4()).size).toBe(1); + + // Clear keys + await contract.send(treasure, { value: toNano(1) }, { $$type: 'DelIntMap1', key: k }); + await contract.send(treasure, { value: toNano(1) }, { $$type: 'DelIntMap2', key: k }); + await contract.send(treasure, { value: toNano(1) }, { $$type: 'DelIntMap3', key: k }); + await contract.send(treasure, { value: toNano(1) }, { $$type: 'DelIntMap4', key: k }); + await contract.send(treasure, { value: toNano(1) }, { $$type: 'DelIntMap5', key: k }); + await contract.send(treasure, { value: toNano(1) }, { $$type: 'DelIntMap6', key: keySmall }); + await contract.send(treasure, { value: toNano(1) }, { $$type: 'DelUIntMap7', key: keySmallAbs }); + await contract.send(treasure, { value: toNano(1) }, { $$type: 'DelIntMap8', key: k }); + await contract.send(treasure, { value: toNano(1) }, { $$type: 'DelUIntMap9', key: k }); + await contract.send(treasure, { value: toNano(1) }, { $$type: 'DelAddrMap1', key: addr }); + await contract.send(treasure, { value: toNano(1) }, { $$type: 'DelAddrMap2', key: addr }); + await contract.send(treasure, { value: toNano(1) }, { $$type: 'DelAddrMap3', key: addr }); + await contract.send(treasure, { value: toNano(1) }, { $$type: 'DelAddrMap4', key: addr }); + await contract.send(treasure, { value: toNano(1) }, { $$type: 'DelAddrMap5', key: addr }); + await contract.send(treasure, { value: toNano(1) }, { $$type: 'DelAddrMap6', key: addr }); + await contract.send(treasure, { value: toNano(1) }, { $$type: 'DelAddrMap7', key: addr }); + await system.run(); + + // Check value cleared + expect((await contract.getIntMap1Value(k))).toBeNull(); + expect((await contract.getIntMap2Value(k))).toBeNull(); + expect((await contract.getIntMap3Value(k))).toBeNull(); + expect((await contract.getIntMap4Value(k))).toBeNull(); + expect((await contract.getIntMap5Value(k))).toBeNull(); + expect((await contract.getIntMap6_1Value(keySmall))).toBe(null); + expect((await contract.getIntMap6_2Value(keySmall))).toBe(null); + expect((await contract.getIntMap6_3Value(keySmall))).toBe(null); + expect((await contract.getIntMap6_4Value(keySmall))).toBe(null); + expect((await contract.getIntMap6_5Value(keySmall))).toBe(null); + expect((await contract.getIntMap6_6Value(keySmall))).toBe(null); + expect((await contract.getIntMap6_7Value(keySmall))).toBe(null); + expect((await contract.getIntMap7_1Value(keySmallAbs))).toBe(null); + expect((await contract.getIntMap7_2Value(keySmallAbs))).toBe(null); + expect((await contract.getIntMap7_3Value(keySmallAbs))).toBe(null); + expect((await contract.getIntMap7_4Value(keySmallAbs))).toBe(null); + expect((await contract.getIntMap7_5Value(keySmallAbs))).toBe(null); + expect((await contract.getIntMap7_6Value(keySmallAbs))).toBe(null); + expect((await contract.getIntMap8_1Value(k))).toBe(null); + expect((await contract.getIntMap8_2Value(k))).toBe(null); + expect((await contract.getIntMap8_3Value(k))).toBe(null); + expect((await contract.getIntMap8_4Value(k))).toBe(null); + expect((await contract.getIntMap8_5Value(k))).toBe(null); + expect((await contract.getIntMap8_6Value(k))).toBe(null); + expect((await contract.getIntMap8_7Value(k))).toBe(null); + expect((await contract.getIntMap9_1Value(k))).toBe(null); + expect((await contract.getIntMap9_2Value(k))).toBe(null); + expect((await contract.getIntMap9_3Value(k))).toBe(null); + expect((await contract.getIntMap9_4Value(k))).toBe(null); + expect((await contract.getIntMap9_5Value(k))).toBe(null); + expect((await contract.getIntMap9_6Value(k))).toBe(null); + expect((await contract.getAddrMap1Value(addr))).toBeNull(); + expect((await contract.getAddrMap2Value(addr))).toBeNull(); + expect((await contract.getAddrMap3Value(addr))).toBeNull(); + expect((await contract.getAddrMap4Value(addr))).toBeNull(); + expect((await contract.getAddrMap5Value(addr))).toBeNull(); + expect((await contract.getAddrMap6_1Value(addr))).toBe(null); + expect((await contract.getAddrMap6_2Value(addr))).toBe(null); + expect((await contract.getAddrMap6_3Value(addr))).toBe(null); + expect((await contract.getAddrMap6_4Value(addr))).toBe(null); + expect((await contract.getAddrMap6_5Value(addr))).toBe(null); + expect((await contract.getAddrMap6_6Value(addr))).toBe(null); + expect((await contract.getAddrMap6_7Value(addr))).toBe(null); + expect((await contract.getAddrMap7_1Value(addr))).toBe(null); + expect((await contract.getAddrMap7_2Value(addr))).toBe(null); + expect((await contract.getAddrMap7_3Value(addr))).toBe(null); + expect((await contract.getAddrMap7_4Value(addr))).toBe(null); + expect((await contract.getAddrMap7_5Value(addr))).toBe(null); + expect((await contract.getAddrMap7_6Value(addr))).toBe(null); + } + } catch (e) { + if (e instanceof ComputeError) { + if (e.logs) { + console.warn(e.logs); + } + } + throw e; + } + }); }); \ No newline at end of file diff --git a/src/test/features/maps.tact b/src/test/features/maps.tact index 522ac8aab..d7582556c 100644 --- a/src/test/features/maps.tact +++ b/src/test/features/maps.tact @@ -82,6 +82,70 @@ struct SomeStruct { value: Int; } +message DelIntMap1 { + key: Int; +} + +message DelIntMap2 { + key: Int; +} + +message DelIntMap3 { + key: Int; +} + +message DelIntMap4 { + key: Int; +} + +message DelIntMap5 { + key: Int; +} + +message DelIntMap6 { + key: Int; +} + +message DelUIntMap7 { + key: Int; +} + +message DelIntMap8 { + key: Int; +} + +message DelUIntMap9 { + key: Int; +} + +message DelAddrMap1 { + key: Address; +} + +message DelAddrMap2 { + key: Address; +} + +message DelAddrMap3 { + key: Address; +} + +message DelAddrMap4 { + key: Address; +} + +message DelAddrMap5 { + key: Address; +} + +message DelAddrMap6 { + key: Address; +} + +message DelAddrMap7 { + key: Address; +} + contract MapTestContract { init() { @@ -189,6 +253,64 @@ contract MapTestContract { self.intMap9_6.set(msg.key, msg.value); } + receive(msg: DelIntMap1) { + self.intMap1.del(msg.key); + } + + receive(msg: DelIntMap2) { + self.intMap2.del(msg.key); + } + + receive(msg: DelIntMap3) { + self.intMap3.del(msg.key); + } + + receive(msg: DelIntMap4) { + self.intMap4.del(msg.key); + } + + receive(msg: DelIntMap5) { + self.intMap5.del(msg.key); + } + + receive(msg: DelIntMap6) { + self.intMap6_1.del(msg.key); + self.intMap6_2.del(msg.key); + self.intMap6_3.del(msg.key); + self.intMap6_4.del(msg.key); + self.intMap6_5.del(msg.key); + self.intMap6_6.del(msg.key); + self.intMap6_6.del(msg.key); + } + + receive(msg: DelUIntMap7) { + self.intMap7_1.del(msg.key); + self.intMap7_2.del(msg.key); + self.intMap7_3.del(msg.key); + self.intMap7_4.del(msg.key); + self.intMap7_5.del(msg.key); + self.intMap7_6.del(msg.key); + } + + receive(msg: DelIntMap8) { + self.intMap8_1.del(msg.key); + self.intMap8_2.del(msg.key); + self.intMap8_3.del(msg.key); + self.intMap8_4.del(msg.key); + self.intMap8_5.del(msg.key); + self.intMap8_6.del(msg.key); + self.intMap8_7.del(msg.key); + } + + receive(msg: DelUIntMap9) { + self.intMap9_1.del(msg.key); + self.intMap9_2.del(msg.key); + self.intMap9_3.del(msg.key); + self.intMap9_4.del(msg.key); + self.intMap9_5.del(msg.key); + self.intMap9_6.del(msg.key); + } + get fun intMap1(): map { return self.intMap1; } @@ -614,6 +736,45 @@ contract MapTestContract { self.addrMap7_6.set(msg.key, msg.value); } + receive(msg: DelAddrMap1) { + self.addrMap1.del(msg.key); + } + + receive(msg: DelAddrMap2) { + self.addrMap2.del(msg.key); + } + + receive(msg: DelAddrMap3) { + self.addrMap3.del(msg.key); + } + + receive(msg: DelAddrMap4) { + self.addrMap4.del(msg.key); + } + + receive(msg: DelAddrMap5) { + self.addrMap5.del(msg.key); + } + + receive(msg: DelAddrMap6) { + self.addrMap6_1.del(msg.key); + self.addrMap6_2.del(msg.key); + self.addrMap6_3.del(msg.key); + self.addrMap6_4.del(msg.key); + self.addrMap6_5.del(msg.key); + self.addrMap6_6.del(msg.key); + self.addrMap6_7.del(msg.key); + } + + receive(msg: DelAddrMap7) { + self.addrMap7_1.del(msg.key); + self.addrMap7_2.del(msg.key); + self.addrMap7_3.del(msg.key); + self.addrMap7_4.del(msg.key); + self.addrMap7_5.del(msg.key); + self.addrMap7_6.del(msg.key); + } + receive("reset") { self.addrMap1 = emptyMap(); self.addrMap2 = emptyMap();