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

chore: cleanup TODOs and deprecate bad functions #671

Merged
merged 4 commits into from
Dec 16, 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: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
- `near_sdk::ONE_NEAR`, `near_sdk::ONE_YOCTO`, `near_sdk::Gas::ONE_TERA`
- Update SDK dependencies for `nearcore` crates used for mocking (`0.10`) and `borsh` (`0.9`)
- store: Implement caching `LookupSet` type. This is the new iteration of the previous version of `near_sdk::collections::LookupSet` that has an updated API, and is located at `near_sdk::store::LookupSet`. [PR 654](https://github.com/near/near-sdk-rs/pull/654).
- Deprecate `testing_env_with_promise_results`, `setup_with_config`, and `setup` due to these functions being unneeded anymore or have unintended side effects [PR 671](https://github.com/near/near-sdk-rs/pull/671)
- Added missing pattern for only including context and vm config to `testing_env!` to remove friction
- Added `_array` suffix versions of `sha256`, `keccak256`, and `keccak512` hash functions in `env` [PR 646](https://github.com/near/near-sdk-rs/pull/646)
- These return a fixed length array instead of heap allocating with `Vec<u8>`

Expand Down
Binary file not shown.
Binary file not shown.
Binary file modified examples/fungible-token/res/defi.wasm
Binary file not shown.
Binary file modified examples/fungible-token/res/fungible_token.wasm
Binary file not shown.
Binary file not shown.
Binary file modified examples/mission-control/res/mission_control.wasm
Binary file not shown.
Binary file modified examples/non-fungible-token/res/approval_receiver.wasm
Binary file not shown.
Binary file modified examples/non-fungible-token/res/non_fungible_token.wasm
Binary file not shown.
Binary file modified examples/non-fungible-token/res/token_receiver.wasm
Binary file not shown.
1 change: 0 additions & 1 deletion examples/non-fungible-token/tests/sim/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ const NFT_ID: &str = "nft";
const TOKEN_RECEIVER_ID: &str = "token-receiver";
const APPROVAL_RECEIVER_ID: &str = "approval-receiver";

// TODO: how to export String instead of &str? Way too much `into`/`to_string` with &str.
pub const TOKEN_ID: &str = "0";

/// Initialize simulator and return:
Expand Down
Binary file not shown.
Binary file modified examples/status-message/res/status_message.wasm
Binary file not shown.
Binary file modified examples/test-contract/res/test_contract.wasm
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,8 @@ impl NonFungibleToken {
// TODO: does this seem reasonable?
fn measure_min_token_storage_cost(&mut self) {
let initial_storage_usage = env::storage_usage();
let tmp_token_id = "a".repeat(64); // TODO: what's a reasonable max TokenId length?
// 64 Length because this is the max account id length
let tmp_token_id = "a".repeat(64);
let tmp_owner_id = AccountId::new_unchecked("a".repeat(64));

// 1. set some dummy data
Expand Down
5 changes: 2 additions & 3 deletions near-sdk/compilation_tests/all.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,8 @@ fn compilation_tests() {
t.pass("compilation_tests/private.rs");
t.pass("compilation_tests/trait_impl.rs");
t.pass("compilation_tests/metadata.rs");
// TODO uncomment following compile failures when/if compiler version errors are equivalent
// t.compile_fail("compilation_tests/metadata_invalid_rust.rs");
// t.compile_fail("compilation_tests/bad_argument.rs");
t.compile_fail("compilation_tests/metadata_invalid_rust.rs");
t.compile_fail("compilation_tests/bad_argument.rs");
t.pass("compilation_tests/complex.rs");
t.compile_fail("compilation_tests/impl_generic.rs");
t.pass("compilation_tests/references.rs");
Expand Down
2 changes: 2 additions & 0 deletions near-sdk/src/environment/env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -536,6 +536,8 @@ pub fn panic_str(message: &str) -> ! {
pub fn abort() -> ! {
// Use wasm32 unreachable call to avoid including the `panic` external function in Wasm.
#[cfg(target_arch = "wasm32")]
//* This was stabilized recently (~ >1.51), so ignore warnings but don't enforce higher msrv
#[allow(unused_unsafe)]
unsafe {
core::arch::wasm32::unreachable()
}
Expand Down
1 change: 0 additions & 1 deletion near-sdk/src/store/vec/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ fn expect_consistent_state<T>(val: Option<T>) -> T {
/// ```
/// use near_sdk::store::Vector;
///
///# near_sdk::test_utils::test_env::setup();
/// let mut vec = Vector::new(b"a");
/// assert!(vec.is_empty());
///
Expand Down
2 changes: 1 addition & 1 deletion near-sdk/src/test_utils/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,8 @@ impl VMContextBuilder {
}
}

// TODO: This probably shouldn't be necessary with the `testing_env` macro.
/// Initializes the [`MockedBlockchain`] with a single promise result during execution.
#[deprecated(since = "4.0.0", note = "Use `testing_env!` macro to initialize with promise results")]
pub fn testing_env_with_promise_results(context: VMContext, promise_result: PromiseResult) {
let storage = crate::mock::with_mocked_blockchain(|b| b.take_storage());

Expand Down
12 changes: 8 additions & 4 deletions near-sdk/src/test_utils/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ pub mod test_env;

mod context;
use crate::mock::Receipt;
#[allow(deprecated)]
pub use context::{accounts, testing_env_with_promise_results, VMContextBuilder};

/// Initializes a testing environment to mock interactions which would otherwise go through a
Expand Down Expand Up @@ -69,17 +70,20 @@ macro_rules! testing_env {
$crate::mock::with_mocked_blockchain(|b| b.take_storage()),
$validators,
None,
));
))
};
($context:expr, $config:expr, $fee_config:expr, $validators:expr $(,)?) => {
$crate::testing_env!($context, $config, $fee_config, $validators, Default::default());
$crate::testing_env!($context, $config, $fee_config, $validators, Default::default())
};

($context:expr, $config:expr, $fee_config:expr $(,)?) => {
$crate::testing_env!($context, $config, $fee_config, Default::default());
$crate::testing_env!($context, $config, $fee_config, Default::default())
};
($context:expr, $config:expr $(,)?) => {
$crate::testing_env!($context, $config, $crate::RuntimeFeesConfig::test())
};
($context:expr) => {
$crate::testing_env!($context, $crate::VMConfig::test(), $crate::RuntimeFeesConfig::test());
$crate::testing_env!($context, $crate::VMConfig::test())
};
}

Expand Down
30 changes: 13 additions & 17 deletions near-sdk/src/test_utils/test_env.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use crate::test_utils::VMContextBuilder;
use crate::{env, mock::MockedBlockchain, AccountId, VMConfig};
use near_primitives_core::runtime::fees::RuntimeFeesConfig;
use crate::{testing_env, AccountId, VMConfig};

pub fn alice() -> AccountId {
AccountId::new_unchecked("alice.near".to_string())
Expand All @@ -15,28 +14,25 @@ pub fn carol() -> AccountId {
}

/// Updates the blockchain interface with the config passed in.
// TODO(austinabell): This seems like a footgun, not clear it's replacing the context with default
#[deprecated(
since = "4.0.0",
note = "Use `testing_env!` macro to initialize with specific VMConfig"
)]
pub fn setup_with_config(vm_config: VMConfig) {
let context = VMContextBuilder::new().build();
let storage = crate::mock::with_mocked_blockchain(|b| b.take_storage());
env::set_blockchain_interface(MockedBlockchain::new(
context,
vm_config,
RuntimeFeesConfig::test(),
vec![],
storage,
Default::default(),
None,
));
testing_env!(VMContextBuilder::new().build(), vm_config)
}

/// Setup the blockchain interface with a default configuration.
#[deprecated(
since = "4.0.0",
note = "Mocked blockchain is now setup by default, use `testing_env!`"
)]
pub fn setup() {
setup_with_config(VMConfig::test());
testing_env!(VMContextBuilder::new().build());
}

// free == effectively unlimited gas
/// free == effectively unlimited gas
/// Sets up the blockchain interface with a [`VMConfig`] which sets the gas costs to zero.
pub fn setup_free() {
setup_with_config(VMConfig::free());
crate::testing_env!(VMContextBuilder::new().build(), VMConfig::free())
}