From 637b9b92df780d2648a35935763d9ee2f852da4b Mon Sep 17 00:00:00 2001 From: skywardboundd Date: Wed, 25 Jun 2025 17:53:05 +0300 Subject: [PATCH 1/3] refactor(test/utils): simplify storage prices configuration in gasUtils --- package.json | 2 +- src/test/e2e-emulated/debug/dump.spec.ts | 14 +--- .../e2e-emulated/maps/map-literals.spec.ts | 14 +--- .../traits/base-trait/empty.spec.ts | 14 +--- .../traits/base-trait/emptychange.spec.ts | 14 +--- .../traits/base-trait/negative.spec.ts | 14 +--- .../traits/base-trait/reserved.spec.ts | 14 +--- src/test/utils/gasUtils.ts | 81 +++++-------------- yarn.lock | 8 ++ 9 files changed, 43 insertions(+), 132 deletions(-) diff --git a/package.json b/package.json index dd6573c1c4..cd917e08a6 100644 --- a/package.json +++ b/package.json @@ -112,7 +112,7 @@ "@tact-lang/coverage": "^0.0.8", "@tact-lang/ton-abi": "^0.0.3", "@tact-lang/ton-jest": "^0.0.4", - "@ton/sandbox": "^0.32.2", + "@ton/sandbox": "^0.33.0", "@ton/test-utils": "^0.7.0", "@tonstudio/pgen": "^0.0.1", "@types/diff": "^7.0.0", diff --git a/src/test/e2e-emulated/debug/dump.spec.ts b/src/test/e2e-emulated/debug/dump.spec.ts index 9ca6220250..1191e3bbb7 100644 --- a/src/test/e2e-emulated/debug/dump.spec.ts +++ b/src/test/e2e-emulated/debug/dump.spec.ts @@ -3,7 +3,7 @@ import { Blockchain } from "@ton/sandbox"; import { Tester } from "./output/dump_Tester"; import "@ton/test-utils"; import { cached } from "@/test/utils/cache-state"; -import { setStoragePrices } from "@/test/utils/gasUtils"; +import { zeroStoragePrices } from "@/test/utils/gasUtils"; const deployValue = toNano("1"); // `dump` is expensive @@ -11,17 +11,7 @@ const setup = async () => { const blockchain = await Blockchain.create(); blockchain.verbosity.print = false; - const config = blockchain.config; - - blockchain.setConfig( - setStoragePrices(config, { - unixTimeSince: 0, - bitPricePerSecond: 0n, - cellPricePerSecond: 0n, - masterChainBitPricePerSecond: 0n, - masterChainCellPricePerSecond: 0n, - }), - ); + blockchain.setConfig(zeroStoragePrices(blockchain.config)); const treasury = await blockchain.treasury("treasury"); diff --git a/src/test/e2e-emulated/maps/map-literals.spec.ts b/src/test/e2e-emulated/maps/map-literals.spec.ts index 5e39a9e339..3e4fac04bf 100644 --- a/src/test/e2e-emulated/maps/map-literals.spec.ts +++ b/src/test/e2e-emulated/maps/map-literals.spec.ts @@ -4,7 +4,7 @@ import { toNano } from "@ton/core"; import { Blockchain } from "@ton/sandbox"; import { Flat } from "./output/map-literals_Flat"; -import { setStoragePrices } from "@/test/utils/gasUtils"; +import { zeroStoragePrices } from "@/test/utils/gasUtils"; const deployValue = toNano("1"); // `dump` is expensive @@ -12,17 +12,7 @@ const setup = async () => { const blockchain = await Blockchain.create(); blockchain.verbosity.print = false; - const config = blockchain.config; - - blockchain.setConfig( - setStoragePrices(config, { - unixTimeSince: 0, - bitPricePerSecond: 0n, - cellPricePerSecond: 0n, - masterChainBitPricePerSecond: 0n, - masterChainCellPricePerSecond: 0n, - }), - ); + blockchain.setConfig(zeroStoragePrices(blockchain.config)); const treasury = await blockchain.treasury("treasury"); diff --git a/src/test/e2e-emulated/traits/base-trait/empty.spec.ts b/src/test/e2e-emulated/traits/base-trait/empty.spec.ts index 40e5f3d4de..865f99dd76 100644 --- a/src/test/e2e-emulated/traits/base-trait/empty.spec.ts +++ b/src/test/e2e-emulated/traits/base-trait/empty.spec.ts @@ -14,7 +14,7 @@ import { Empty } from "./output/empty_Empty"; import "@ton/test-utils"; -import { setStoragePrices } from "@/test/utils/gasUtils"; +import { zeroStoragePrices } from "@/test/utils/gasUtils"; const setup = async () => { const deployValue = toNano("0.05"); @@ -46,17 +46,7 @@ const setup = async () => { const blockchain: Blockchain = await Blockchain.create(); - const config = blockchain.config; - - blockchain.setConfig( - setStoragePrices(config, { - unixTimeSince: 0, - bitPricePerSecond: 0n, - cellPricePerSecond: 0n, - masterChainBitPricePerSecond: 0n, - masterChainCellPricePerSecond: 0n, - }), - ); + blockchain.setConfig(zeroStoragePrices(blockchain.config)); const treasury: SandboxContract = await blockchain.treasury("treasury"); diff --git a/src/test/e2e-emulated/traits/base-trait/emptychange.spec.ts b/src/test/e2e-emulated/traits/base-trait/emptychange.spec.ts index c39fd42d16..69f52ab157 100644 --- a/src/test/e2e-emulated/traits/base-trait/emptychange.spec.ts +++ b/src/test/e2e-emulated/traits/base-trait/emptychange.spec.ts @@ -14,7 +14,7 @@ import { EmptyChange } from "./output/empty-change_EmptyChange"; import "@ton/test-utils"; -import { setStoragePrices } from "@/test/utils/gasUtils"; +import { zeroStoragePrices } from "@/test/utils/gasUtils"; const setup = async () => { const deployValue = toNano("0.05"); @@ -46,17 +46,7 @@ const setup = async () => { const blockchain: Blockchain = await Blockchain.create(); - const config = blockchain.config; - - blockchain.setConfig( - setStoragePrices(config, { - unixTimeSince: 0, - bitPricePerSecond: 0n, - cellPricePerSecond: 0n, - masterChainBitPricePerSecond: 0n, - masterChainCellPricePerSecond: 0n, - }), - ); + blockchain.setConfig(zeroStoragePrices(blockchain.config)); const treasury: SandboxContract = await blockchain.treasury("treasury"); diff --git a/src/test/e2e-emulated/traits/base-trait/negative.spec.ts b/src/test/e2e-emulated/traits/base-trait/negative.spec.ts index 75a9531d79..766c3b3f5a 100644 --- a/src/test/e2e-emulated/traits/base-trait/negative.spec.ts +++ b/src/test/e2e-emulated/traits/base-trait/negative.spec.ts @@ -14,7 +14,7 @@ import { Negative } from "./output/negative_Negative"; import "@ton/test-utils"; -import { setStoragePrices } from "@/test/utils/gasUtils"; +import { zeroStoragePrices } from "@/test/utils/gasUtils"; const setup = async () => { const deployValue = toNano("0.05"); @@ -46,17 +46,7 @@ const setup = async () => { const blockchain: Blockchain = await Blockchain.create(); - const config = blockchain.config; - - blockchain.setConfig( - setStoragePrices(config, { - unixTimeSince: 0, - bitPricePerSecond: 0n, - cellPricePerSecond: 0n, - masterChainBitPricePerSecond: 0n, - masterChainCellPricePerSecond: 0n, - }), - ); + blockchain.setConfig(zeroStoragePrices(blockchain.config)); const treasury: SandboxContract = await blockchain.treasury("treasury"); diff --git a/src/test/e2e-emulated/traits/base-trait/reserved.spec.ts b/src/test/e2e-emulated/traits/base-trait/reserved.spec.ts index 02967c7a2b..8337e23840 100644 --- a/src/test/e2e-emulated/traits/base-trait/reserved.spec.ts +++ b/src/test/e2e-emulated/traits/base-trait/reserved.spec.ts @@ -14,7 +14,7 @@ import { Reserved } from "./output/reserved_Reserved"; import "@ton/test-utils"; -import { setStoragePrices } from "@/test/utils/gasUtils"; +import { zeroStoragePrices } from "@/test/utils/gasUtils"; const setup = async () => { const deployValue = toNano("0.05"); @@ -46,17 +46,7 @@ const setup = async () => { const blockchain: Blockchain = await Blockchain.create(); - const config = blockchain.config; - - blockchain.setConfig( - setStoragePrices(config, { - unixTimeSince: 0, - bitPricePerSecond: 0n, - cellPricePerSecond: 0n, - masterChainBitPricePerSecond: 0n, - masterChainCellPricePerSecond: 0n, - }), - ); + blockchain.setConfig(zeroStoragePrices(blockchain.config)); const treasury: SandboxContract = await blockchain.treasury("treasury"); diff --git a/src/test/utils/gasUtils.ts b/src/test/utils/gasUtils.ts index 2e22bf1c26..ec4cbbccc8 100644 --- a/src/test/utils/gasUtils.ts +++ b/src/test/utils/gasUtils.ts @@ -1,64 +1,27 @@ -// https://github.com/ton-blockchain/stablecoin-contract/blob/main/gasUtils.ts -import { - beginCell, - Dictionary, - type Cell, - type DictionaryValue, -} from "@ton/core"; -import type { BlockchainConfig } from "@ton/sandbox"; +import { Dictionary, type Cell } from "@ton/core"; +import { updateConfig } from "@ton/sandbox"; +import type { StoragePrices } from "@ton/sandbox/dist/config/config.tlb-gen"; -// https://github.com/ton-blockchain/ton/blob/ed4682066978f69ffa38dd98912ca77d4f660f66/crypto/block/block.tlb#L705 -const ConfigStoragePriceIndex = 18; -const ConfigKeyLength = 32; +export function zeroStoragePrices(configRaw: Cell): Cell { + return setStoragePrices(configRaw, { + kind: "StoragePrices", + utime_since: 0, + bit_price_ps: 0n, + _cell_price_ps: 0n, + mc_bit_price_ps: 0n, + mc_cell_price_ps: 0n, + }); +} + +export function setStoragePrices(configRaw: Cell, prices: StoragePrices): Cell { + const storagePricesDict = Dictionary.empty(); -type StorageValue = { - unixTimeSince: number; - bitPricePerSecond: bigint; - cellPricePerSecond: bigint; - masterChainBitPricePerSecond: bigint; - masterChainCellPricePerSecond: bigint; -}; + storagePricesDict.set(0, prices); -const storageValue: DictionaryValue = { - serialize: (src, builder) => { - builder - .storeUint(0xcc, 8) - .storeUint(src.unixTimeSince, 32) - .storeUint(src.bitPricePerSecond, 64) - .storeUint(src.cellPricePerSecond, 64) - .storeUint(src.masterChainBitPricePerSecond, 64) - .storeUint(src.masterChainCellPricePerSecond, 64); - }, - parse: (src) => { - return { - unixTimeSince: src.skip(8).loadUint(32), - bitPricePerSecond: src.loadUintBig(64), - cellPricePerSecond: src.loadUintBig(64), - masterChainBitPricePerSecond: src.loadUintBig(64), - masterChainCellPricePerSecond: src.loadUintBig(64), - }; - }, -}; + const updatedConfig = updateConfig(configRaw, { + kind: "ConfigParam__18", + anon0: storagePricesDict, + }); -export function setStoragePrices( - configRaw: Cell, - prices: StorageValue, -): BlockchainConfig { - const config = configRaw - .beginParse() - .loadDictDirect( - Dictionary.Keys.Int(ConfigKeyLength), - Dictionary.Values.Cell(), - ); - const storageData = Dictionary.loadDirect( - Dictionary.Keys.Uint(ConfigKeyLength), - storageValue, - config.get(ConfigStoragePriceIndex)!, - ); - storageData.set(storageData.values().length - 1, prices); - config.set( - ConfigStoragePriceIndex, - beginCell().storeDictDirect(storageData).endCell(), - ); - return beginCell().storeDictDirect(config).endCell(); + return updatedConfig; } diff --git a/yarn.lock b/yarn.lock index 4a08562821..ddda9b0d1f 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1426,6 +1426,14 @@ chalk "^4.1.2" table "^6.9.0" +"@ton/sandbox@^0.33.0": + version "0.33.0" + resolved "https://npm.dev-internal.org/@ton/sandbox/-/sandbox-0.33.0.tgz#62efc1e8e0c5d7dcb8101a2709387e7c320839ea" + integrity sha512-hhPXaan9PNSGUY3NtG8g5e7lgzy81gh+pnp4dagvwFVp1F4iqfGXjIAYc0sTIT/UVIb1U64fTS+STbTgpXni1A== + dependencies: + chalk "^4.1.2" + table "^6.9.0" + "@ton/test-utils@^0.7.0": version "0.7.0" resolved "https://npm.dev-internal.org/@ton/test-utils/-/test-utils-0.7.0.tgz#c70dd68f5155edfc68482ea1050fda73511f0c92" From 91e04b65a867980b852066c6a5c1acbea9b1ba93 Mon Sep 17 00:00:00 2001 From: skywardboundd Date: Wed, 25 Jun 2025 17:58:41 +0300 Subject: [PATCH 2/3] fix --- spell/cspell-list.txt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/spell/cspell-list.txt b/spell/cspell-list.txt index e5797ec973..9562f364ff 100644 --- a/spell/cspell-list.txt +++ b/spell/cspell-list.txt @@ -154,10 +154,10 @@ prando quadtree quadtrees RANDU -Reentrancy rangle rawslice reentrancy +Reentrancy renamer replaceget respecifying @@ -219,6 +219,7 @@ uninit Uninit unixfs untypable +utime varint varuint verytactical From 5f63727bf147bed71724dd697a307614ad5629e0 Mon Sep 17 00:00:00 2001 From: skywardboundd Date: Wed, 25 Jun 2025 18:03:01 +0300 Subject: [PATCH 3/3] fix --- src/test/utils/gasUtils.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/utils/gasUtils.ts b/src/test/utils/gasUtils.ts index ec4cbbccc8..f3ee212935 100644 --- a/src/test/utils/gasUtils.ts +++ b/src/test/utils/gasUtils.ts @@ -13,7 +13,7 @@ export function zeroStoragePrices(configRaw: Cell): Cell { }); } -export function setStoragePrices(configRaw: Cell, prices: StoragePrices): Cell { +function setStoragePrices(configRaw: Cell, prices: StoragePrices): Cell { const storagePricesDict = Dictionary.empty(); storagePricesDict.set(0, prices);