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: update nearcore crates from 0.17 -> 0.20 #1130

Merged
merged 7 commits into from
Jan 16, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
4 changes: 2 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
strategy:
matrix:
platform: [ubuntu-latest, macos-latest]
toolchain: [stable, 1.69.0]
toolchain: [stable, 1.72.1]
Copy link
Collaborator Author

@dj8yfo dj8yfo Jan 12, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

error[E0659]: `opentelemetry` is ambiguous
  --> /home/user/.cargo/registry/src/index.crates.io-6f17d22bba15001f/near-o11y-0.19.0/src/lib.rs:6:9
   |
6  | pub use opentelemetry::OpenTelemetryLevel;
   |         ^^^^^^^^^^^^^ ambiguous name
   |
   = note: ambiguous because of multiple potential import sources
   = note: `opentelemetry` could refer to a crate passed with `--extern`
   = help: use `::opentelemetry` to refer to this crate unambiguously
note: `opentelemetry` could also refer to the module defined here
  --> /home/user/.cargo/registry/src/index.crates.io-6f17d22bba15001f/near-o11y-0.19.0/src/lib.rs:22:1
   |
22 | mod opentelemetry;
   | ^^^^^^^^^^^^^^^^^^
   = help: use `crate::opentelemetry` to refer to this module unambiguously
                                                                                                                                                                                    
For more information about this error, try `rustc --explain E0659`.
error: could not compile `near-o11y` (lib) due to previous error

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

steps:
- uses: actions/checkout@v3
- name: "${{ matrix.toolchain }} with rustfmt, and wasm32"
Expand All @@ -24,7 +24,7 @@ jobs:
default: true
target: wasm32-unknown-unknown
- name: downgrade `anstyle`,`anstyle-parse`,`anstyle-query`,`clap`,`clap_lex`, `home` crates to support older Rust toolchain
if: matrix.toolchain == '1.69.0'
if: matrix.toolchain == '1.72.1'
run: |
cargo update -p anstyle --precise 1.0.2
cargo update -p anstyle-query --precise 1.0.0
Expand Down
14 changes: 8 additions & 6 deletions near-sdk/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,17 @@ wee_alloc = { version = "0.4.5", default-features = false, optional = true }
once_cell = { version = "1.17", default-features = false }

near-abi = { version = "0.4.0", features = ["__chunked-entries"], optional = true }
near-account-id = { version="1.0.0-alpha.4", features = ["serde", "borsh"] }
near-account-id = { version="1.0.0", features = ["serde", "borsh"] }
near-gas = { version = "0.2.3", features = ["serde", "borsh"] }
near-token = { version = "0.2.0", features = ["serde", "borsh"] }


[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
near-vm-logic = { version = "0.17", optional = true }
near-primitives-core = { version = "0.17", optional = true }
near-primitives = { version = "0.17", optional = true }
near-crypto = { version = "0.17", optional = true }
near-vm-runner = { version = "0.19", default_features = false, optional = true }
near-primitives-core = { version = "0.19", optional = true }
near-primitives = { version = "0.19", optional = true }
near-crypto = { version = "0.19", optional = true }
near-parameters = { version = "0.19", optional = true }

[dev-dependencies]
rand = "0.8.4"
Expand All @@ -63,7 +65,7 @@ expensive-debug = []
unstable = []
legacy = []
abi = ["borsh/unstable__schema", "near-abi", "schemars", "near-sdk-macros/abi", "near-account-id/abi", "near-gas/abi", "near-token/abi"]
unit-testing = ["near-vm-logic", "near-primitives-core", "near-primitives", "near-crypto"]
unit-testing = ["near-vm-runner", "near-primitives-core", "near-primitives", "near-crypto", "near-parameters"]

__abi-embed = ["near-sdk-macros/__abi-embed"]
__abi-generate = ["abi", "near-sdk-macros/__abi-generate"]
Expand Down
2 changes: 1 addition & 1 deletion near-sdk/src/environment/env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ pub(crate) unsafe fn read_register_fixed_64(register_id: u64) -> [u8; 64] {
/// low-level blockchain interfacr that implements `BlockchainInterface` trait. In most cases you
/// want to use `testing_env!` macro to set it.
///
/// ```no_run
/// ```ignore
/// # let context = near_sdk::test_utils::VMContextBuilder::new().build();
/// # let vm_config = near_sdk::VMConfig::test();
/// # let fees_config = near_sdk::RuntimeFeesConfig::test();
Expand Down
134 changes: 131 additions & 3 deletions near-sdk/src/environment/mock/external.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,23 @@
use near_gas::NearGas;
use near_primitives::types::TrieNodesCount;
use near_primitives_core::hash::{hash, CryptoHash};
use near_primitives_core::types::{AccountId, Balance};
use near_vm_logic::{External, StorageGetMode, ValuePtr};
use near_primitives_core::types::{AccountId, Balance, Gas, GasWeight};
use near_token::NearToken;
use near_vm_runner::logic::types::ReceiptIndex;
use near_vm_runner::logic::{External, StorageGetMode, ValuePtr};
use std::collections::HashMap;

type Result<T> = ::core::result::Result<T, near_vm_logic::VMLogicError>;
use super::receipt::MockAction;

type Result<T> = ::core::result::Result<T, near_vm_runner::logic::errors::VMLogicError>;

#[derive(Default, Clone)]
/// Emulates the trie and the mock handling code for the SDK. This is a modified version of
/// `MockedExternal` from `near_vm_logic`.
pub(crate) struct SdkExternal {
pub fake_trie: HashMap<Vec<u8>, Vec<u8>>,
pub validators: HashMap<AccountId, Balance>,
pub action_log: Vec<MockAction>,
data_count: u64,
}

Expand Down Expand Up @@ -85,4 +91,126 @@ impl External for SdkExternal {
fn validator_total_stake(&self) -> Result<Balance> {
Ok(self.validators.values().sum())
}

fn create_receipt(
&mut self,
receipt_indices: Vec<ReceiptIndex>,
receiver_id: AccountId,
) -> Result<ReceiptIndex> {
let index = self.action_log.len();
self.action_log.push(MockAction::CreateReceipt { receipt_indices, receiver_id });
Ok(index as u64)
}

fn append_action_create_account(&mut self, receipt_index: ReceiptIndex) -> Result<()> {
self.action_log.push(MockAction::CreateAccount { receipt_index });
Ok(())
}

fn append_action_deploy_contract(
&mut self,
receipt_index: ReceiptIndex,
code: Vec<u8>,
) -> Result<()> {
self.action_log.push(MockAction::DeployContract { receipt_index, code });
Ok(())
}

fn append_action_function_call_weight(
&mut self,
receipt_index: ReceiptIndex,
method_name: Vec<u8>,
args: Vec<u8>,
attached_deposit: Balance,
prepaid_gas: Gas,
gas_weight: GasWeight,
) -> Result<()> {
self.action_log.push(MockAction::FunctionCallWeight {
receipt_index,
method_name,
args,
attached_deposit: NearToken::from_yoctonear(attached_deposit),
prepaid_gas: NearGas::from_gas(prepaid_gas),
gas_weight,
});
Ok(())
}

fn append_action_transfer(
&mut self,
receipt_index: ReceiptIndex,
deposit: Balance,
) -> Result<()> {
self.action_log.push(MockAction::Transfer {
receipt_index,
deposit: NearToken::from_yoctonear(deposit),
});
Ok(())
}

fn append_action_stake(
&mut self,
receipt_index: ReceiptIndex,
stake: Balance,
public_key: near_crypto::PublicKey,
) {
self.action_log.push(MockAction::Stake {
receipt_index,
stake: NearToken::from_yoctonear(stake),
public_key,
});
}

fn append_action_add_key_with_full_access(
&mut self,
receipt_index: ReceiptIndex,
public_key: near_crypto::PublicKey,
nonce: near_primitives_core::types::Nonce,
) {
self.action_log.push(MockAction::AddKeyWithFullAccess { receipt_index, public_key, nonce });
}

fn append_action_add_key_with_function_call(
&mut self,
receipt_index: ReceiptIndex,
public_key: near_crypto::PublicKey,
nonce: near_primitives_core::types::Nonce,
allowance: Option<Balance>,
receiver_id: AccountId,
method_names: Vec<Vec<u8>>,
) -> Result<()> {
self.action_log.push(MockAction::AddKeyWithFunctionCall {
receipt_index,
public_key,
nonce,
allowance: allowance.map(NearToken::from_yoctonear),
receiver_id,
method_names,
});
Ok(())
}

fn append_action_delete_key(
&mut self,
receipt_index: ReceiptIndex,
public_key: near_crypto::PublicKey,
) {
self.action_log.push(MockAction::DeleteKey { receipt_index, public_key });
}

fn append_action_delete_account(
&mut self,
receipt_index: ReceiptIndex,
beneficiary_id: AccountId,
) -> Result<()> {
self.action_log.push(MockAction::DeleteAccount { receipt_index, beneficiary_id });
Ok(())
}

fn get_receipt_receiver(&self, receipt_index: ReceiptIndex) -> &AccountId {
match &self.action_log[receipt_index as usize] {
MockAction::CreateReceipt { receiver_id, .. } => receiver_id,
_ => panic!("not a valid receipt index!"),
}
}
}
Loading
Loading