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: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
3 changes: 2 additions & 1 deletion spell/cspell-list.txt
Original file line number Diff line number Diff line change
Expand Up @@ -154,10 +154,10 @@ prando
quadtree
quadtrees
RANDU
Reentrancy
rangle
rawslice
reentrancy
Reentrancy
renamer
replaceget
respecifying
Expand Down Expand Up @@ -219,6 +219,7 @@ uninit
Uninit
unixfs
untypable
utime
varint
varuint
verytactical
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?


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,
});
}

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;
}
8 changes: 8 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
Loading