Skip to content

Commit

Permalink
chore: update nearcore crates from 0.17 -> 0.19
Browse files Browse the repository at this point in the history
  • Loading branch information
dj8yf0μl committed Jan 11, 2024
1 parent 1343059 commit 707c445
Show file tree
Hide file tree
Showing 16 changed files with 311 additions and 136 deletions.
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]
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", 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

0 comments on commit 707c445

Please sign in to comment.