Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/tact-lang/tact-emulator
@tact-lang/emulator testing library
https://github.com/tact-lang/tact-emulator
Last synced: about 2 months ago
JSON representation
@tact-lang/emulator testing library
- Host: GitHub
- URL: https://github.com/tact-lang/tact-emulator
- Owner: tact-lang
- License: mit
- Created: 2023-03-09T09:19:36.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2024-06-28T15:32:21.000Z (3 months ago)
- Last Synced: 2024-07-31T21:11:11.853Z (about 2 months ago)
- Language: TypeScript
- Size: 16.3 MB
- Stars: 25
- Watchers: 5
- Forks: 8
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
- awesome-tact - Tact Emulator
README
# TON Emulator
Emulation toolkit for TON Smart Contracts
## Installation
```bash
yarn add @tact-lang/emulator @ton/core @ton/crypto ton-abi
```## Usage
```typescript
import { ContractSystem, randomAddress } from '@tact-lang/emulator';
import { WalletContractV4 } from '@ton/ton';// 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');
system.name(treasure, 'my treasure'); // Set a name for the contract. Useful for snapshot testing.// Update verbosity
system.verbosity(treasure, Verbosity.ERROR); // Overwrite for a specific contract// Track contract transactions and events
let tracker = system.track(treasure);// Logger to collect VM logs from a contract
let logger = system.log(treasure);// Create a random unknown address that would be treated as uninitialized contract
let unknownAddress = randomAddress('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: }));// Show contract logs
console.warn(logger.collect());// Test events and transactions
expect(tracker.collect()).toMatchSnapshot();```
## License
MIT