Skip to content

Commit

Permalink
Merge pull request #372 from tonlabs/1.11.1-rc
Browse files Browse the repository at this point in the history
Version 1.11.1
  • Loading branch information
d3p authored Mar 17, 2021
2 parents b6449a8 + b47d1f4 commit f042a14
Show file tree
Hide file tree
Showing 17 changed files with 141 additions and 81 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@

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

## [1.11.1] – 2021-03-15

### New
- Giver address in tests is calculated from secret key. Default values are provided for TON OS SE giver

## [1.11.0] – 2021-03-05

### New
Expand Down
41 changes: 36 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,25 @@

[![Channel on Telegram](https://img.shields.io/badge/chat-on%20telegram-9cf.svg)](https://t.me/ton_sdk)

# Documentation
[Full API/SDK documentation](https://docs.ton.dev/86757ecb2/p/39fc5e-products)

[Javascript SDK](https://github.com/tonlabs/ton-client-js)
# Content Table
- [Content Table](#content-table)
- [Useful links](#useful-links)
- [What is Core Free TON Client Library](#what-is-core-free-ton-client-library)
- [SDKs in other languages (bindings over TON-SDK)](#sdks-in-other-languages-bindings-over-ton-sdk)
- [Official Javascript(Typescript) SDK](#official-javascripttypescript-sdk)
- [Community bindings](#community-bindings)
- [How to use library](#how-to-use-library)
- [How to avoid Soft Breaking Problems](#how-to-avoid-soft-breaking-problems)
- [Build client library](#build-client-library)
- [Build artifacts](#build-artifacts)
- [Run tests](#run-tests)
- [Download precompiled binaries](#download-precompiled-binaries)

# Useful links

[Quick Start](https://docs.ton.dev/86757ecb2/p/33b76d-quick-start)

[Example Hello World](https://github.com/tonlabs/sdk-samples/tree/master/v1/node-js/core-api/hello)
[Full API/SDK documentation](https://docs.ton.dev/86757ecb2/p/39fc5e-products)

# What is Core Free TON Client Library

Expand Down Expand Up @@ -181,6 +194,24 @@ tsc
node index binding -l ts -o ../../ton-client-js/packages/core/src
```

# Run tests
To run test suite use standard Rust test command
```
cargo test
```
SDK tests need [TON OS API](https://docs.ton.dev/86757ecb2/p/793337-ton-os-api) endpoint to run on.
Such an API is exposed by a [DApp Server](https://github.com/tonlabs/TON-OS-DApp-Server) which runs in real networks and by local blockchain [TON OS SE](https://github.com/tonlabs/tonos-se).

TON OS SE is used by default with address `http://localhost` and port 80. If you launch it on another port you need to specify it explicitly like this: `http://localhost:port`.
If you have TON OS SE running on another address or you need to run tests on a real TON network use the following
environment variables to override the default parameters
```
TON_USE_SE: true/false - flag defining if tests run against TON OS SE or a real network (DApp Server)
TON_NETWORK_ADDRESS - Dapp server or TON OS SE address
TON_GIVER_SECRET - Giver secret key. If not defined, default TON OS SE giver keys are used
TON_GIVER_ADDRESS - Address of the giver to use for prepaying accounts before deploying test contracts. If not defined, the address is calculated using `GiverV2.tvc` and configured public key
```

# Download precompiled binaries

Instead of building library yourself, you can download the __latest__ precompiled binaries from
Expand Down
2 changes: 1 addition & 1 deletion api/derive/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "api_derive"
version = "1.11.0"
version = "1.11.1"
authors = ["TON DEV SOLUTIONS LTD <[email protected]>"]
edition = "2018"

Expand Down
2 changes: 1 addition & 1 deletion api/info/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "api_info"
version = "1.11.0"
version = "1.11.1"
authors = ["TON DEV SOLUTIONS LTD <[email protected]>"]
edition = "2018"

Expand Down
2 changes: 1 addition & 1 deletion api/test/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "api_test"
version = "1.11.0"
version = "1.11.1"
authors = ["TON DEV SOLUTIONS LTD <[email protected]>"]
edition = "2018"

Expand Down
2 changes: 1 addition & 1 deletion ton_client/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "ton_client"
version = "1.11.0"
version = "1.11.1"
authors = ["TON DEV SOLUTIONS LTD <[email protected]>"]
edition = "2018"
license = "Apache-2.0"
Expand Down
2 changes: 2 additions & 0 deletions ton_client/src/debot/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1109,6 +1109,8 @@ async fn test_debot_invoke_msgs() {
).await;
}

// TODO: make test runnable not only once
#[ignore]
#[tokio::test(core_threads = 2)]
async fn test_debot_sdk_get_accounts_by_hash() {
let client = std::sync::Arc::new(TestClient::new());
Expand Down
8 changes: 4 additions & 4 deletions ton_client/src/net/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ async fn wait_for() {
let client = TestClient::new();

client
.get_tokens_from_giver_async(&TestClient::giver_address(), None)
.get_tokens_from_giver_async(&client.giver_address().await, None)
.await;

request.await.unwrap();
Expand Down Expand Up @@ -431,7 +431,7 @@ async fn subscribe_for_messages() {
.unwrap();

client
.get_tokens_from_giver_async(&TestClient::giver_address(), None)
.get_tokens_from_giver_async(&client.giver_address().await, None)
.await;

assert_eq!(messages.lock().await.len(), 0);
Expand All @@ -450,7 +450,7 @@ async fn find_last_shard_block() {
.request_async(
"net.find_last_shard_block",
ParamsOfFindLastShardBlock {
address: TestClient::giver_address(),
address: client.giver_address().await,
},
)
.await
Expand Down Expand Up @@ -489,7 +489,7 @@ async fn test_wait_resume() {

let duration = tokio::spawn(async move {
client_copy
.fetch_account(&TestClient::giver_address())
.fetch_account(&client_copy.giver_address().await)
.await;

start.elapsed().as_millis()
Expand Down
6 changes: 3 additions & 3 deletions ton_client/src/processing/blocks_walking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ pub async fn find_last_shard_block(
// if account is from other chains, then starting point is last account's shard block
// To obtain it we take masterchain block to get shards configuration and select matching shard
if blocks[0].is_null() {
// Node SE case - no masterchain, no sharding. Check that only one shard
// TON OS SE case - no masterchain, no sharding. Check that only one shard
let blocks = client
.query_collection(ParamsOfQueryCollection {
collection: BLOCKS_TABLE_NAME.to_string(),
Expand All @@ -93,7 +93,7 @@ pub async fn find_last_shard_block(
workchain
)));
}
// if workchain is sharded, then it is not Node SE and masterchain blocks missing is error
// if workchain is sharded, then it is not TON OS SE and masterchain blocks missing is error
if blocks[0]["after_merge"] == true || blocks[0]["shard"] != "8000000000000000" {
return Err(Error::block_not_found(
"No masterchain block found".to_owned(),
Expand All @@ -120,7 +120,7 @@ pub async fn find_last_shard_block(
.as_str()
.map(|val| val.to_owned().into())
.ok_or(Error::block_not_found(
"No starting Node SE block found".to_owned(),
"No starting TON OS SE block found".to_owned(),
))
} else {
let shards =
Expand Down
4 changes: 2 additions & 2 deletions ton_client/src/processing/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ async fn test_process_message() {

#[tokio::test(core_threads = 2)]
async fn test_error_resolving() {
// skip on Node SE since it behaves different to real node
// skip on TON OS SE since it behaves different to real node
if TestClient::node_se() {
return;
}
Expand Down Expand Up @@ -338,7 +338,7 @@ async fn test_error_resolving() {
call_set: Some(CallSet {
function_name: "sendAllMoney".to_owned(),
header: None,
input: Some(json!({ "dest_addr": TestClient::giver_address() })),
input: Some(json!({ "dest_addr": client.giver_address().await })),
}),
};

Expand Down
2 changes: 1 addition & 1 deletion ton_client/src/tests/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ async fn test_clock_sync() {
let msg = client
.encode_message(ParamsOfEncodeMessage {
abi: TestClient::abi(HELLO, None),
address: Some(TestClient::giver_address()),
address: Some(client.giver_address().await),
call_set: CallSet::some_with_function("touch"),
deploy_set: None,
processing_try_index: None,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,40 +1,40 @@
{"ABI version": 2,
"header": ["time", "expire"],
"functions": [
{
"name": "upgrade",
"inputs": [
{"name":"newcode","type":"cell"}
],
"outputs": [
]
},
{
"name": "sendTransaction",
"inputs": [
{"name":"dest","type":"address"},
{"name":"value","type":"uint128"},
{"name":"bounce","type":"bool"}
],
"outputs": [
]
},
{
"name": "getMessages",
"inputs": [
],
"outputs": [
{"components":[{"name":"hash","type":"uint256"},{"name":"expireAt","type":"uint64"}],"name":"messages","type":"tuple[]"}
]
},
{
"name": "constructor",
"inputs": [
],
"outputs": [
]
}
],
"events": [
]
{"ABI version": 2,
"header": ["time", "expire"],
"functions": [
{
"name": "upgrade",
"inputs": [
{"name":"newcode","type":"cell"}
],
"outputs": [
]
},
{
"name": "sendTransaction",
"inputs": [
{"name":"dest","type":"address"},
{"name":"value","type":"uint128"},
{"name":"bounce","type":"bool"}
],
"outputs": [
]
},
{
"name": "getMessages",
"inputs": [
],
"outputs": [
{"components":[{"name":"hash","type":"uint256"},{"name":"expireAt","type":"uint64"}],"name":"messages","type":"tuple[]"}
]
},
{
"name": "constructor",
"inputs": [
],
"outputs": [
]
}
],
"events": [
]
}
Binary file added ton_client/src/tests/contracts/abi_v2/GiverV2.tvc
Binary file not shown.
62 changes: 42 additions & 20 deletions ton_client/src/tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@
*/

use super::{tc_destroy_string, tc_read_string, tc_request, tc_request_sync};
use crate::abi::{
encode_message, Abi, CallSet, ParamsOfEncodeMessage, ResultOfEncodeMessage, Signer,
};
use crate::abi::{Abi, CallSet, DeploySet, ParamsOfEncodeMessage, ResultOfEncodeMessage, Signer, encode_message};
use crate::boc::{ParamsOfParse, ResultOfParse};
use crate::client::*;
use crate::crypto::{
Expand Down Expand Up @@ -45,13 +43,17 @@ use tokio::sync::{

mod common;

const DEFAULT_TON_USE_SE: &str = "true";
const DEFAULT_NETWORK_ADDRESS: &str = "http://localhost";
//const DEFAULT_NETWORK_ADDRESS: &str = "cinet.tonlabs.io";
//const DEFAULT_NETWORK_ADDRESS: &str = "net.ton.dev";

const ROOT_CONTRACTS_PATH: &str = "src/tests/contracts/";
const LOG_CGF_PATH: &str = "src/tests/log_cfg.yaml";

const GIVER_ADDRESS_VAR: &str = "TON_GIVER_ADDRESS";
const GIVER_SECRET_VAR: &str = "TON_GIVER_SECRET";

struct SimpleLogger;

const MAX_LEVEL: log::LevelFilter = log::LevelFilter::Warn;
Expand All @@ -72,7 +74,7 @@ pub const SUBSCRIBE: &str = "Subscription";
// pub const PIGGY_BANK: &str = "Piggy";
// pub const WALLET: &str = "LimitWallet";
// pub const SIMPLE_WALLET: &str = "Wallet";
pub const GIVER_WALLET: &str = "GiverWallet";
pub const GIVER_V2: &str = "GiverV2";
pub const HELLO: &str = "Hello";
pub const EVENTS: &str = "Events";
pub const TEST_DEBOT: &str = "testDebot";
Expand Down Expand Up @@ -240,33 +242,53 @@ impl TestClient {
}

pub fn giver_abi() -> Abi {
Self::abi(GIVER_WALLET, Some(2))
Self::abi(GIVER_V2, Some(2))
}

pub fn giver_address() -> String {
const GIVER_ADDRESS_VAR: &str = "TON_GIVER_ADDRESS";
std::env::var(GIVER_ADDRESS_VAR)
.expect(&format!("Please set giver's address in {} environment variable", GIVER_ADDRESS_VAR))
async fn calc_giver_address(&self, keys: KeyPair) -> String {
self.encode_message(
ParamsOfEncodeMessage {
abi: Self::giver_abi(),
deploy_set: DeploySet::some_with_tvc(Self::tvc(GIVER_V2, None)),
signer: Signer::Keys { keys },
..Default::default()
}
)
.await
.unwrap()
.address
}

pub fn giver_keys() -> KeyPair {
const GIVER_KEYS_FILENAME: &str = "giverKeys.json";
let keys_file = dirs::home_dir()
.expect("Error obtaining user's home dir")
.join(GIVER_KEYS_FILENAME);
let keys = std::fs::read_to_string(&keys_file)
.expect(&format!("Error reading file: {:?}", &keys_file));
pub async fn giver_address(&self) -> String {
if let Ok(address) = std::env::var(GIVER_ADDRESS_VAR) {
address
} else {
self.calc_giver_address(Self::giver_keys()).await
}
}

serde_json::from_str(&keys)
.expect(&format!("Error parsing {:?} as JSON", &keys_file))
pub fn giver_keys() -> KeyPair {
if let Ok(secret) = std::env::var(GIVER_SECRET_VAR) {
let secret_key = ed25519_dalek::SecretKey::from_bytes(&hex::decode(&secret).unwrap()).unwrap();
let public_key = ed25519_dalek::PublicKey::from(&secret_key);
KeyPair {
public: hex::encode(public_key.to_bytes()),
secret,
}
} else {
KeyPair {
public: "2ada2e65ab8eeab09490e3521415f45b6e42df9c760a639bcf53957550b25a16".to_owned(),
secret: "172af540e43a524763dd53b26a066d472a97c4de37d5498170564510608250c3".to_owned(),
}
}
}

pub fn network_address() -> String {
std::env::var("TON_NETWORK_ADDRESS").unwrap_or(DEFAULT_NETWORK_ADDRESS.into())
}

pub fn node_se() -> bool {
std::env::var("USE_NODE_SE").unwrap_or("true".to_owned()) == "true".to_owned()
std::env::var("TON_USE_SE").unwrap_or(DEFAULT_TON_USE_SE.to_owned()) == "true".to_owned()
}

pub fn abi_version() -> u8 {
Expand Down Expand Up @@ -578,7 +600,7 @@ impl TestClient {

pub(crate) async fn get_tokens_from_giver_async(&self, account: &str, value: Option<u64>) {
let run_result = self.net_process_function(
Self::giver_address(),
self.giver_address().await,
Self::giver_abi(),
"sendTransaction",
json!({
Expand Down
Loading

0 comments on commit f042a14

Please sign in to comment.