Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions spell/cspell-list.txt
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ rangle
rawslice
Reentrancy
reentrancy
Reentrancy
renamer
replaceget
respecifying
Expand Down Expand Up @@ -234,6 +235,7 @@ uninit
Uninit
unixfs
untypable
utime
varint
varuint
verificationkey
Expand Down
14 changes: 2 additions & 12 deletions src/test/e2e-emulated/debug/dump.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,15 @@ 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";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd name this function using the verb as the first word.
What about removeStorageFee or something like that?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

turnOffStorageFee or skipStorageFee would be some other alternatives


const deployValue = toNano("1"); // `dump` is expensive

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");

Expand Down
14 changes: 2 additions & 12 deletions src/test/e2e-emulated/maps/map-literals.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,15 @@ 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

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");

Expand Down
14 changes: 2 additions & 12 deletions src/test/e2e-emulated/traits/base-trait/empty.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -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<TreasuryContract> =
await blockchain.treasury("treasury");
Expand Down
14 changes: 2 additions & 12 deletions src/test/e2e-emulated/traits/base-trait/emptychange.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -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<TreasuryContract> =
await blockchain.treasury("treasury");
Expand Down
14 changes: 2 additions & 12 deletions src/test/e2e-emulated/traits/base-trait/negative.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -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<TreasuryContract> =
await blockchain.treasury("treasury");
Expand Down
14 changes: 2 additions & 12 deletions src/test/e2e-emulated/traits/base-trait/reserved.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -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<TreasuryContract> =
await blockchain.treasury("treasury");
Expand Down
81 changes: 22 additions & 59 deletions src/test/utils/gasUtils.ts
Original file line number Diff line number Diff line change
@@ -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,
Comment on lines +5 to +12

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P0 Badge Incorrect StoragePrices field name breaks TypeScript compile

The new zeroStoragePrices helper constructs a StoragePrices object with _cell_price_ps. The generated type in @ton/sandbox/dist/config/config.tlb-gen exposes this property as cell_price_ps (no leading underscore). Because the required field is missing, TypeScript will reject the call to setStoragePrices, so any test importing this helper fails to compile. Use the correct field name when building the StoragePrices object.

Useful? React with 👍 / 👎.

});
}

function setStoragePrices(configRaw: Cell, prices: StoragePrices): Cell {
const storagePricesDict = Dictionary.empty<number, StoragePrices>();

type StorageValue = {
unixTimeSince: number;
bitPricePerSecond: bigint;
cellPricePerSecond: bigint;
masterChainBitPricePerSecond: bigint;
masterChainCellPricePerSecond: bigint;
};
storagePricesDict.set(0, prices);

const storageValue: DictionaryValue<StorageValue> = {
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;
}