Skip to content

Commit

Permalink
chore: fix various small nits
Browse files Browse the repository at this point in the history
  • Loading branch information
dj8yf0μl committed Jan 15, 2024
1 parent 22aedbf commit 91d786e
Show file tree
Hide file tree
Showing 10 changed files with 129 additions and 268 deletions.
9 changes: 0 additions & 9 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,6 @@ jobs:
toolchain: ${{ matrix.toolchain }}
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.72.1'
run: |
cargo update -p anstyle --precise 1.0.2
cargo update -p anstyle-query --precise 1.0.0
cargo update -p anstyle-parse --precise 0.2.1
cargo update -p clap --precise 4.3.24
cargo update -p clap_lex --precise 0.5.0
cargo update -p home --precise 0.5.5
- uses: Swatinem/rust-cache@v1
- name: Test
run: cargo test --all --features unstable,legacy
Expand Down
4 changes: 2 additions & 2 deletions near-sdk/src/environment/env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,9 @@ 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.
///
/// ```ignore
/// ```
/// # let context = near_sdk::test_utils::VMContextBuilder::new().build();
/// # let vm_config = near_sdk::VMConfig::test();
/// # let vm_config = near_sdk::test_vm_config();
/// # let fees_config = near_sdk::RuntimeFeesConfig::test();
/// # let storage = Default::default();
/// # let validators = Default::default();
Expand Down
216 changes: 0 additions & 216 deletions near-sdk/src/environment/mock/external.rs

This file was deleted.

11 changes: 6 additions & 5 deletions near-sdk/src/environment/mock/mocked_blockchain.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use super::{Receipt, SdkExternal};
use super::Receipt;
use crate::mock::MockAction;
// TODO replace with near_vm_logic::mocks::mock_memory::MockedMemory after updating version from 0.17
use crate::mock::mocked_memory::MockedMemory;
Expand All @@ -7,6 +7,7 @@ use crate::types::{NearToken, PromiseResult};
use crate::VMContext;
use near_parameters::{RuntimeConfigStore, RuntimeFeesConfig};
use near_primitives_core::version::PROTOCOL_VERSION;
use near_vm_runner::logic::mocks::mock_external::MockedExternal;
use near_vm_runner::logic::types::{PromiseResult as VmPromiseResult, ReceiptIndex};
use near_vm_runner::logic::{External, MemoryLike, VMLogic};
use std::cell::RefCell;
Expand Down Expand Up @@ -48,7 +49,7 @@ impl Default for MockedBlockchain {
}

struct LogicFixture {
ext: Box<SdkExternal>,
ext: Box<MockedExternal>,
memory: Box<dyn MemoryLike>,
#[allow(clippy::box_collection)]
promise_results: Box<Vec<VmPromiseResult>>,
Expand All @@ -66,7 +67,7 @@ impl MockedBlockchain {
validators: HashMap<String, NearToken>,
memory_opt: Option<Box<dyn MemoryLike>>,
) -> Self {
let mut ext = Box::new(SdkExternal::new());
let mut ext = Box::new(MockedExternal::new());
let context = sdk_context_to_vm_context(context);
ext.fake_trie = storage;
ext.validators =
Expand Down Expand Up @@ -100,7 +101,8 @@ impl MockedBlockchain {
/// Returns metadata about the receipts created
pub fn created_receipts(&self) -> Vec<Receipt> {
let action_log = &self.logic_fixture.ext.action_log;
println!("{:#?}", action_log);
let action_log: Vec<MockAction> =
action_log.clone().into_iter().map(<MockAction as From<_>>::from).collect();
let create_receipts: Vec<(usize, MockAction)> = action_log
.clone()
.into_iter()
Expand Down Expand Up @@ -130,7 +132,6 @@ impl MockedBlockchain {
Receipt { receiver_id, actions, receipt_indices }
})
.collect();
println!("{:#?}", result);
result
}

Expand Down
2 changes: 0 additions & 2 deletions near-sdk/src/environment/mock/mod.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
mod external;
mod mocked_blockchain;
mod mocked_memory;
mod receipt;

pub use mocked_blockchain::test_vm_config;

pub(crate) use self::external::SdkExternal;
pub use self::mocked_blockchain::MockedBlockchain;
pub use self::receipt::{MockAction, Receipt};
use core::cell::RefCell;
Expand Down
76 changes: 75 additions & 1 deletion near-sdk/src/environment/mock/receipt.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use near_primitives_core::types::GasWeight;
use near_vm_runner::logic::mocks::mock_external::MockAction as LogicMockAction;
use near_vm_runner::logic::types::ReceiptIndex;

use crate::{AccountId, Gas, NearToken};
Expand Down Expand Up @@ -60,7 +61,7 @@ pub enum MockAction {
nonce: u64,
allowance: Option<NearToken>,
receiver_id: AccountId,
method_names: Vec<Vec<u8>>,
method_names: Vec<String>,
},
AddKeyWithFullAccess {
receipt_index: ReceiptIndex,
Expand All @@ -85,3 +86,76 @@ impl MockAction {
}
}
}

fn map_vec_str(vec_str: Vec<Vec<u8>>) -> Vec<String> {
vec_str
.into_iter()
.map(|element| {
let string: String = String::from_utf8(element).unwrap();
string
})
.collect()
}

impl From<LogicMockAction> for MockAction {
fn from(value: LogicMockAction) -> Self {
match value {
LogicMockAction::CreateReceipt { receipt_indices, receiver_id } => {
Self::CreateReceipt { receipt_indices, receiver_id }
}
LogicMockAction::CreateAccount { receipt_index } => {
Self::CreateAccount { receipt_index }
}
LogicMockAction::DeployContract { receipt_index, code } => {
Self::DeployContract { receipt_index, code }
}
LogicMockAction::FunctionCallWeight {
receipt_index,
method_name,
args,
attached_deposit,
prepaid_gas,
gas_weight,
} => Self::FunctionCallWeight {
receipt_index,
method_name,
args,
attached_deposit: NearToken::from_yoctonear(attached_deposit),
prepaid_gas: Gas::from_gas(prepaid_gas),
gas_weight,
},
LogicMockAction::Transfer { receipt_index, deposit } => {
MockAction::Transfer { receipt_index, deposit: NearToken::from_yoctonear(deposit) }
}
LogicMockAction::Stake { receipt_index, stake, public_key } => MockAction::Stake {
receipt_index,
stake: NearToken::from_yoctonear(stake),
public_key,
},
LogicMockAction::DeleteAccount { receipt_index, beneficiary_id } => {
Self::DeleteAccount { receipt_index, beneficiary_id }
}
LogicMockAction::DeleteKey { receipt_index, public_key } => {
Self::DeleteKey { receipt_index, public_key }
}
LogicMockAction::AddKeyWithFunctionCall {
receipt_index,
public_key,
nonce,
allowance,
receiver_id,
method_names,
} => Self::AddKeyWithFunctionCall {
receipt_index,
public_key,
nonce,
allowance: allowance.map(NearToken::from_yoctonear),
receiver_id,
method_names: map_vec_str(method_names),
},
LogicMockAction::AddKeyWithFullAccess { receipt_index, public_key, nonce } => {
Self::AddKeyWithFullAccess { receipt_index, public_key, nonce }
}
}
}
}
Loading

0 comments on commit 91d786e

Please sign in to comment.