包详细信息

ton-emulator

ton-core72MIT2.1.1

Emulation toolkit for TON Smart Contracts

自述文件

TON Emulator

Emulation toolkit for TON Smart Contracts

Installation

yarn add ton-emulator ton-core ton-crypto

Usage

import { ContractSystem } from 'ton-emulator';

// Contract System is a virtual environment that emulates the TON blockchain
const system = await ContractSystem.create();

// Treasure is a contract that has 1m of TONs and is a handy entry point for your smart contracts
let treasure = await system.treasure('my-treasure');

// Track contract transactions and events
let tracker = system.track(treasure.address);

// Logger to collect VM logs from a contract
let logger = system.log(treasure.address);

// Create a random unknown address that would be treated as unititialized contract
let unknownAddress = testAddress('some-unknown-seed'); // This seed is used to generate deterministic address

// Send an empty message to the unknown address
await treasure.send({
    to: unknownAddress,
    bounce: true,
});

// Run a block
let transactions = await system.run();
console.warn(inspect(transactions, false, 10000));

// Open a contract
let wallet = system.open(WalletContractV4.create({ workchain: 0, publicKey: <some-test-key> }));

// Show contract logs
console.warn(logger.collect());

// Test events and transactions
expect(tracker.collect()).toMatchSnapshot();

License

MIT

更新日志

Changelog

All notable changes to this project will be documented in this file.

The format is based on Keep a Changelog, and this project adheres to Semantic Versioning.

[Unreleased]

Changed

  • Fixed Logger.collect() types
  • Print out VM Logs in Logger.collect()

[2.1.0] - 2023-02-02

Changed

  • Upgraded emulator binary to latest version
  • Combine all available logs into a single variable

[2.0.0] - 2023-02-02

Added

  • Logger to collect VM Logs from transactions

Changed

  • Tracker now collects transactions instead of plain events for easier debugging
  • events() renamed to collect()
  • Changed type field in events to $type for better readability of jest snapshots

[1.6.1] - 2023-01-26

Changed

  • Repository name

[1.6.0] - 2023-01-11

Added

  • reset to Tracker for better readability in some tests

[1.5.0] - 2023-01-11

Added

  • update to ContractSystem to change config, current date or block lt.
  • overwrite to ContractSystem and ContractExecutor to replace contract state by address. Useful for mocking.

[1.4.0] - 2023-01-08

Added

  • Resolving error messages from error codes

[1.3.0] - 2023-01-04

Added

  • Expose vm logs in get method exceptions

[1.2.0] - 2023-01-03

Added

  • Tracker for tracking contract transactions

Fixed

  • Allow sending multiple treasure messages in a single block

[1.1.1] - 2023-01-03

Fixed

  • Treasure balance is now 1m instead of 1bn to avoid overflow
  • Double message delivery
  • Case where multiple messages were sent to non-existent contract

[1.1.0] - 2023-01-02

Changed

  • Better typings for Treasure to include address

[1.0.1]

🚀 Initial release