diff --git a/spell/cspell-list.txt b/spell/cspell-list.txt index a1004ef481..61029f26ee 100644 --- a/spell/cspell-list.txt +++ b/spell/cspell-list.txt @@ -171,6 +171,7 @@ rangle rawslice Reentrancy reentrancy +Reentrancy renamer replaceget respecifying @@ -234,6 +235,7 @@ uninit Uninit unixfs untypable +utime varint varuint verificationkey 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..f3ee212935 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, + }); +} + +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; }