Skip to content

Commit

Permalink
- Migrated dependencies to @ton organization packages
Browse files Browse the repository at this point in the history
- Bumped @ton/test-utils version to 0.3.1
  • Loading branch information
KardanovIR authored and krigga committed Jul 28, 2023
1 parent 8e26476 commit 11d4adb
Show file tree
Hide file tree
Showing 30 changed files with 763 additions and 870 deletions.
8 changes: 7 additions & 1 deletion .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,13 @@ jobs:
run: yarn
- name: Build
run: yarn build
- name: Setup .yarnrc.yml
run: |
yarn config set npmAuthToken $NPM_AUTH_TOKEN
yarn config set npmAlwaysAuth true
env:
NPM_AUTH_TOKEN: ${{ secrets.NPM_AUTH_TOKEN }}
- name: Publish
env:
NPM_AUTH_TOKEN: ${{ secrets.NPM_AUTH_TOKEN }}
run: yarn publish --access public
run: yarn npm publish --access public
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [0.11.1] - 2023-07-26

### Changed

- Migrated dependencies to @ton organization packages
- Bumped @ton/test-utils version to 0.3.1

## [0.11.0] - 2023-05-11

### Added
Expand Down
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ The key difference of this package from [ton-contract-executor](https://github.c
Requires node 16 or higher.

```
yarn add @ton/sandbox ton @ton/core ton-crypto
yarn add @ton/sandbox @ton/ton @ton/core @ton/crypto
```
or
```
npm i @ton/sandbox ton @ton/core ton-crypto
npm i @ton/sandbox @ton/ton @ton/core @ton/crypto
```

## Usage
Expand All @@ -41,14 +41,14 @@ import { Blockchain } from "@ton/sandbox";
const blockchain = await Blockchain.create()
```

After that, you can use the low level methods on Blockchain (such as sendMessage) to emulate any messages that you want, but the recommended way to use it is to write wrappers for your contract using the `Contract` interface from `ton-core`. Then you can use `blockchain.openContract` on instances of such contracts, and they will be wrapped in a Proxy that will supply a `ContractProvider` as a first argument to all its methods starting with either `get` or `send`. Also all `send` methods will get Promisified and will return results of running the blockchain message queue along with the original method's result in the `result` field.
After that, you can use the low level methods on Blockchain (such as sendMessage) to emulate any messages that you want, but the recommended way to use it is to write wrappers for your contract using the `Contract` interface from `@ton/core`. Then you can use `blockchain.openContract` on instances of such contracts, and they will be wrapped in a Proxy that will supply a `ContractProvider` as a first argument to all its methods starting with either `get` or `send`. Also all `send` methods will get Promisified and will return results of running the blockchain message queue along with the original method's result in the `result` field.

A good example of this is the [treasury contract](/src/treasury/Treasury.ts) that is basically a built-in highload wallet meant to help you write tests for your systems of smart contracts. When `blockchain.treasury` is called, an instance of `TreasuryContract` is created and `blockchain.openContract` is called to "open" it. After that, when you call `treasury.send`, `Blockchain` automatically supplies the first `provider` argument.

For your own contracts, you can draw inspiration from the contracts in the [examples](/examples/) - all of them use the `provider.internal` method to send internal messages using the treasuries passed in from the unit test file.
Here is an excerpt of that from [NftItem.ts](/examples/contracts/NftItem.ts):
```typescript
import { Address, beginCell, Cell, Contract, ContractProvider, Sender, toNano, Builder } from "ton-core";
import { Address, beginCell, Cell, Contract, ContractProvider, Sender, toNano, Builder } from "@ton/core";

class NftItem implements Contract {
async sendTransfer(provider: ContractProvider, via: Sender, params: {
Expand Down Expand Up @@ -78,7 +78,7 @@ When you call `nftItem.sendTransfer(treasury.getSender(), { to: recipient })` (w

Here is another excerpt that shows the way to interact with get methods from wrappers:
```typescript
import { Contract, ContractProvider } from "ton-core";
import { Contract, ContractProvider } from "@ton/core";

export type NftItemData = {
inited: boolean
Expand Down
2 changes: 1 addition & 1 deletion examples/contracts/Elector.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Address, Cell, Contract, ContractProvider } from "ton-core";
import { Address, Cell, Contract, ContractProvider } from "@ton/core";

export class Elector implements Contract {
constructor(readonly address: Address, readonly init?: { code: Cell; data: Cell }) {}
Expand Down
2 changes: 1 addition & 1 deletion examples/contracts/NftCollection.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Address, beginCell, Cell, Contract, contractAddress, ContractProvider, Sender, toNano } from "ton-core";
import { Address, beginCell, Cell, Contract, contractAddress, ContractProvider, Sender, toNano } from "@ton/core";
import { NftItem } from "./NftItem";

export type NftCollectionData = {
Expand Down
2 changes: 1 addition & 1 deletion examples/contracts/NftItem.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Address, beginCell, Cell, Contract, ContractProvider, Sender, toNano, Builder } from "ton-core";
import { Address, beginCell, Cell, Contract, ContractProvider, Sender, toNano, Builder } from "@ton/core";

export type NftItemData = {
inited: boolean
Expand Down
2 changes: 1 addition & 1 deletion examples/contracts/NftMarketplace.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Address, beginCell, Cell, Contract, contractAddress, ContractProvider, Sender, storeStateInit, toNano } from "ton-core";
import { Address, beginCell, Cell, Contract, contractAddress, ContractProvider, Sender, storeStateInit, toNano } from "@ton/core";

export type NftMarketplaceConfig = {
owner: Address
Expand Down
2 changes: 1 addition & 1 deletion examples/contracts/NftSale.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Address, beginCell, Cell, Contract, contractAddress, ContractProvider } from "ton-core";
import { Address, beginCell, Cell, Contract, contractAddress, ContractProvider } from "@ton/core";

export type NftSaleConfig = {
marketplace: Address
Expand Down
2 changes: 1 addition & 1 deletion examples/contracts/NftSaleV3.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Address, Cell, Contract, ContractProvider } from "ton-core";
import { Address, Cell, Contract, ContractProvider } from "@ton/core";
import { NftSaleConfig } from "./NftSale";

export class NftSaleV3 implements Contract {
Expand Down
2 changes: 1 addition & 1 deletion examples/nft-sale/README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# NFT sale example

This is an example demonstrating how to write unit tests for smart contracts using `@ton-community/sandbox` and `@ton-community/test-utils` to test them in an emulated TON network.
This is an example demonstrating how to write unit tests for smart contracts using `@ton-community/sandbox` and `@ton/test-utils` to test them in an emulated TON network.
6 changes: 3 additions & 3 deletions examples/nft-sale/Sale.spec.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { beginCell, SendMode, toNano } from "ton-core"
import { Blockchain } from "@ton-community/sandbox"
import { beginCell, SendMode, toNano } from "@ton/core"
import { Blockchain } from "@ton/sandbox"
import { NftCollection } from "../contracts/NftCollection"
import { NftItem } from "../contracts/NftItem"
import { NftMarketplace } from "../contracts/NftMarketplace"
import { NftSale } from "../contracts/NftSale"
import "@ton-community/test-utils" // register matchers
import "@ton/test-utils" // register matchers

describe('Collection', () => {
it('should work', async () => {
Expand Down
8 changes: 4 additions & 4 deletions examples/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@
"license": "MIT",
"devDependencies": {
"@ton-community/sandbox": "^0.11.0",
"@ton-community/test-utils": "^0.2.0",
"@ton/test-utils": "^0.2.0",
"@types/jest": "^29.5.1",
"jest": "^29.5.0",
"ton": "^13.5.0",
"ton-core": "^0.49.1",
"ton-crypto": "^3.2.0",
"@ton/ton": "^13.5.1",
"@ton/core": "^0.49.1",
"@ton/crypto": "^3.2.0",
"ts-jest": "^29.1.0",
"typescript": "^4.9.5"
},
Expand Down
6 changes: 3 additions & 3 deletions examples/remote-storage/RemoteStorage.spec.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { TonClient4 } from "ton"
import { Address, toNano, SendMode } from "ton-core"
import { TonClient4 } from "@ton/ton"
import { Address, toNano, SendMode } from "@ton/core"
import { Blockchain, RemoteBlockchainStorage, wrapTonClient4ForRemote } from "@ton-community/sandbox"
import { NftSaleV3 } from "../contracts/NftSaleV3"
import { NftItem } from "../contracts/NftItem"
import "@ton-community/test-utils" // register matchers
import "@ton/test-utils" // register matchers
import { Elector } from "../contracts/Elector"

describe('RemoteStorage', () => {
Expand Down
14 changes: 7 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@ton/sandbox",
"version": "0.11.0",
"version": "0.11.1",
"description": "TON transaction emulator",
"main": "dist/index.js",
"license": "MIT",
Expand All @@ -13,20 +13,20 @@
"url": "git+https://github.com/ton-org/sandbox"
},
"devDependencies": {
"@ton-community/test-utils": "^0.2.0",
"@ton/core": "^0.49.2",
"@ton/crypto": "3.2.0",
"@ton/test-utils": "^0.3.1",
"@ton/ton": "^13.4.2",
"@types/jest": "^29.5.0",
"@types/node": "^18.15.11",
"jest": "^29.5.0",
"ton": "^13.4.1",
"ton-core": "^0.49.0",
"ton-crypto": "3.2.0",
"ts-jest": "^29.0.5",
"ts-node": "^10.9.1",
"typescript": "^4.9.5"
},
"peerDependencies": {
"ton-core": ">=0.48.0",
"ton-crypto": ">=3.2.0"
"@ton/core": ">=0.49.2",
"@ton/crypto": ">=3.2.0"
},
"scripts": {
"wasm:pack": "ts-node ./scripts/pack-wasm.ts",
Expand Down
2 changes: 1 addition & 1 deletion scripts/pack-config.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { beginCell, Cell, Dictionary, DictionaryValue, TonClient4 } from 'ton';
import { beginCell, Cell, Dictionary, DictionaryValue, TonClient4 } from '@ton/ton';
import fs from 'fs';

const CellRef: DictionaryValue<Cell> = {
Expand Down
6 changes: 3 additions & 3 deletions src/blockchain/Blockchain.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {Blockchain} from "./Blockchain";
import {Address, beginCell, Cell, Contract, contractAddress, ContractProvider, Message, Sender, storeTransaction, toNano} from "ton-core";
import {randomAddress} from "@ton-community/test-utils";
import {TonClient4} from "ton";
import {Address, beginCell, Cell, Contract, contractAddress, ContractProvider, Message, Sender, storeTransaction, toNano} from "@ton/core";
import {randomAddress} from "@ton/test-utils";
import {TonClient4} from "@ton/ton";
import {RemoteBlockchainStorage, wrapTonClient4ForRemote} from "./BlockchainStorage";
import {prettyLogTransactions} from "../utils/prettyLogTransaction";
import {printTransactionFees} from "../utils/printTransactionFees";
Expand Down
2 changes: 1 addition & 1 deletion src/blockchain/Blockchain.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { defaultConfig } from "../config/defaultConfig";
import {Address, Cell, Message, Transaction, ContractProvider, Contract, Sender, toNano, loadMessage, ShardAccount, TupleItem, ExternalAddress, StateInit} from "ton-core";
import {Address, Cell, Message, Transaction, ContractProvider, Contract, Sender, toNano, loadMessage, ShardAccount, TupleItem, ExternalAddress, StateInit} from "@ton/core";
import {Executor, TickOrTock} from "../executor/Executor";
import {BlockchainStorage, LocalBlockchainStorage} from "./BlockchainStorage";
import { extractEvents, Event } from "../event/Event";
Expand Down
2 changes: 1 addition & 1 deletion src/blockchain/BlockchainContractProvider.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { AccountState, Address, Cell, comment, ContractGetMethodResult, ContractProvider, ContractState, Message, Sender, SendMode, toNano, TupleItem } from "ton-core";
import { AccountState, Address, Cell, comment, ContractGetMethodResult, ContractProvider, ContractState, Message, Sender, SendMode, toNano, TupleItem } from "@ton/core";
import { TickOrTock } from "../executor/Executor";
import { GetMethodResult, SmartContract } from "./SmartContract";

Expand Down
2 changes: 1 addition & 1 deletion src/blockchain/BlockchainSender.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Address, Cell, Message, Sender, SenderArguments } from "ton-core";
import { Address, Cell, Message, Sender, SenderArguments } from "@ton/core";

export class BlockchainSender implements Sender {
constructor(
Expand Down
2 changes: 1 addition & 1 deletion src/blockchain/BlockchainStorage.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {AccountState, Address, Cell} from "ton-core";
import {AccountState, Address, Cell} from "@ton/core";
import {SmartContract} from "./SmartContract";
import {Blockchain} from "./Blockchain";

Expand Down
2 changes: 1 addition & 1 deletion src/blockchain/SmartContract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
storeMessage, storeShardAccount,
Transaction,
TupleItem, TupleReader
} from "ton-core";
} from "@ton/core";
import {getSelectorForMethod} from "../utils/selector";
import { EmulationResult, ExecutorVerbosity, RunCommonArgs, TickOrTock } from "../executor/Executor";

Expand Down
2 changes: 1 addition & 1 deletion src/event/Event.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { AccountStatus, Address, Cell, Transaction } from "ton-core";
import { AccountStatus, Address, Cell, Transaction } from "@ton/core";

export type EventAccountCreated = {
type: 'account_created',
Expand Down
2 changes: 1 addition & 1 deletion src/executor/Executor.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {Executor} from "./Executor";
import {Address, beginCell, Cell, contractAddress, storeMessage, storeShardAccount} from "ton-core";
import {Address, beginCell, Cell, contractAddress, storeMessage, storeShardAccount} from "@ton/core";
import {defaultConfig} from "../config/defaultConfig";

describe('Executor', () => {
Expand Down
2 changes: 1 addition & 1 deletion src/executor/Executor.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {Address, Cell, serializeTuple, TupleItem} from "ton-core";
import {Address, Cell, serializeTuple, TupleItem} from "@ton/core";
import {base64Decode} from "../utils/base64";
const EmulatorModule = require('./emulator-emscripten.js');

Expand Down
2 changes: 1 addition & 1 deletion src/treasury/Treasury.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Address, beginCell, Cell, Contract, contractAddress, ContractProvider, Dictionary, DictionaryValue, internal, loadMessageRelaxed, MessageRelaxed, Sender, SenderArguments, SendMode, storeMessageRelaxed } from "ton-core";
import { Address, beginCell, Cell, Contract, contractAddress, ContractProvider, Dictionary, DictionaryValue, internal, loadMessageRelaxed, MessageRelaxed, Sender, SenderArguments, SendMode, storeMessageRelaxed } from "@ton/core";

const DictionaryMessageValue: DictionaryValue<{ sendMode: SendMode, message: MessageRelaxed }> = {
serialize(src, builder) {
Expand Down
2 changes: 1 addition & 1 deletion src/utils/message.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Address, Cell, Message, StateInit } from "ton-core";
import { Address, Cell, Message, StateInit } from "@ton/core";

export function internal(params: {
from: Address
Expand Down
2 changes: 1 addition & 1 deletion src/utils/prettyLogTransaction.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {Transaction, fromNano} from "ton-core";
import {Transaction, fromNano} from "@ton/core";

export function prettyLogTransaction(tx: Transaction) {
let res = `${tx.inMessage?.info.src!} ➡️ ${tx.inMessage?.info.dest}\n`
Expand Down
2 changes: 1 addition & 1 deletion src/utils/printTransactionFees.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Transaction } from "ton-core";
import { Transaction } from "@ton/core";

const decimalCount = 9;
const decimal = pow10(decimalCount);
Expand Down
2 changes: 1 addition & 1 deletion src/utils/testTreasurySubwalletId.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { sha256_sync } from "ton-crypto";
import { sha256_sync } from "@ton/crypto";

const prefix = 'TESTSEED'

Expand Down
Loading

0 comments on commit 11d4adb

Please sign in to comment.