Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

near-sdk-sim 3.2.0: Expose cur block and fix storage costs #390

Merged
merged 9 commits into from
May 3, 2021
Merged
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 Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion examples/fungible-token/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion examples/fungible-token/tests/sim/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ pub fn register_user(user: &near_sdk_sim::UserAccount) {
pub fn init_no_macros(initial_balance: u128) -> (UserAccount, UserAccount, UserAccount) {
let root = init_simulator(None);

let ft = root.deploy(&FT_WASM_BYTES, FT_ID.into(), STORAGE_AMOUNT);
let ft = root.deploy(&FT_WASM_BYTES, FT_ID.into(), to_yocto("5"));

ft.call(
FT_ID.into(),
Expand Down
2 changes: 1 addition & 1 deletion near-sdk-sim/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "near-sdk-sim"
version = "3.1.1"
version = "3.2.0"
authors = ["Near Inc <hello@near.org>"]
edition = "2018"
license = "GPL-3.0"
Expand Down
15 changes: 9 additions & 6 deletions near-sdk-sim/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,12 @@ To view this documentation locally, clone this repo and from this folder run `ca

## Changelog

### `3.1.1`
### `3.2.0`

* Fixed stack overflow for deep chain [PR #385](https://github.com/near/near-sdk-rs/pull/385).
* Introduce `block_prod_time` duration in nanoseconds to `GenesisConfig` that defines the duration between produced blocks.
* Expose `cur_block` and `genesis_config` from `RuntimeStandalone`. This allows to manipulate block time.
* Use `RuntimeConfig::from_protocol_version` that fixes storage costs issue.
* Set root account balance to one billion tokens.

# Getting started

Expand All @@ -28,15 +31,15 @@ Currently this crate depends on a the GitHub repo of [nearcore](https://github.c

```toml
[dev-dependencies]
near-sdk-sim = "3.1.1"
near-sdk-sim = "3.2.0"

```

And update `near-sdk` too:

```toml
[dependencies]
near-sdk = "3.1.1"
near-sdk = "3.1.0"

```

Expand All @@ -61,8 +64,8 @@ Now in the root of the project (`contract-wrap`), create a new `Cargo.toml`. You

```toml
[dev-dependencies]
near-sdk = "3.1.1"
near-sdk-sim = "3.1.1"
near-sdk = "3.1.0"
near-sdk-sim = "3.2.0"
contract = { path = "./contract" }

[workspace]
Expand Down
15 changes: 10 additions & 5 deletions near-sdk-sim/src/runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,12 @@ pub struct GenesisConfig {

impl Default for GenesisConfig {
fn default() -> Self {
let runtime_config = RuntimeConfig::default();
let runtime_config = RuntimeConfig::from_protocol_version(
&Arc::new(RuntimeConfig::default()),
PROTOCOL_VERSION,
)
.as_ref()
.clone();
Self {
genesis_time: 0,
gas_price: 100_000_000,
Expand All @@ -74,7 +79,7 @@ impl Default for GenesisConfig {
impl GenesisConfig {
pub fn init_root_signer(&mut self, account_id: &str) -> InMemorySigner {
let signer = InMemorySigner::from_seed(account_id, KeyType::ED25519, "test");
let root_account = account_new(std::u128::MAX, CryptoHash::default());
let root_account = account_new(10u128.pow(33), CryptoHash::default());

self.state_records.push(StateRecord::Account {
account_id: account_id.to_string(),
Expand Down Expand Up @@ -146,12 +151,12 @@ impl Block {
}

pub struct RuntimeStandalone {
genesis: GenesisConfig,
pub genesis: GenesisConfig,
tx_pool: TransactionPool,
transactions: HashMap<CryptoHash, SignedTransaction>,
outcomes: HashMap<CryptoHash, ExecutionOutcome>,
profile: HashMap<CryptoHash, ProfileData>,
cur_block: Block,
pub cur_block: Block,
runtime: Runtime,
tries: ShardTries,
pending_receipts: Vec<Receipt>,
Expand Down Expand Up @@ -268,7 +273,7 @@ impl RuntimeStandalone {
random_seed: Default::default(),
epoch_id: EpochId::default(),
current_protocol_version: PROTOCOL_VERSION,
config: Arc::from(self.genesis.runtime_config.clone()),
config: Arc::new(self.genesis.runtime_config.clone()),
#[cfg(feature = "no_contract_cache")]
cache: None,
#[cfg(not(feature = "no_contract_cache"))]
Expand Down