Skip to content

Commit

Permalink
chore: upgrade to [email protected]
Browse files Browse the repository at this point in the history
  • Loading branch information
Jacob Lindahl committed Oct 12, 2023
1 parent 1415b6e commit 677a18d
Show file tree
Hide file tree
Showing 14 changed files with 40 additions and 48 deletions.
2 changes: 1 addition & 1 deletion rust-toolchain.toml
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
[toolchain]
channel = "1.69" # https://github.com/near/nearcore/issues/9143
channel = "1.72"
2 changes: 1 addition & 1 deletion workspaces-tests-utils/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ publish = false

[target.'cfg(not(windows))'.dependencies]
near-sdk.workspace = true
workspaces = "0.7"
near-workspaces = "0.8"
4 changes: 2 additions & 2 deletions workspaces-tests-utils/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#![cfg(not(windows))]

use near_sdk::{serde::de::DeserializeOwned, serde_json::json};
use workspaces::{result::ExecutionFinalResult, Account, Contract};
use near_workspaces::{result::ExecutionFinalResult, Account, Contract};

pub async fn nft_token<T: DeserializeOwned>(contract: &Contract, token_id: &str) -> Option<T> {
contract
Expand All @@ -21,7 +21,7 @@ pub struct Setup {

/// Setup for individual tests
pub async fn setup(wasm: &[u8], num_accounts: usize) -> Setup {
let worker = workspaces::sandbox().await.unwrap();
let worker = near_workspaces::sandbox().await.unwrap();

// Initialize contract
let contract = worker.dev_deploy(wasm).await.unwrap();
Expand Down
2 changes: 1 addition & 1 deletion workspaces-tests/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -71,5 +71,5 @@ near-crypto = "0.15.0"
tokio = "1.21.1"

[target.'cfg(not(windows))'.dev-dependencies]
workspaces = "0.7"
near-workspaces = "0.8"
workspaces-tests-utils = { path = "../workspaces-tests-utils" }
4 changes: 2 additions & 2 deletions workspaces-tests/tests/counter_multisig.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#![cfg(not(windows))]

use near_sdk::serde_json::json;
use workspaces::{Account, Contract};
use near_workspaces::{Account, Contract};

const WASM: &[u8] =
include_bytes!("../../target/wasm32-unknown-unknown/release/counter_multisig.wasm");
Expand All @@ -13,7 +13,7 @@ struct Setup {

/// Setup for individual tests
async fn setup(num_accounts: usize) -> Setup {
let worker = workspaces::sandbox().await.unwrap();
let worker = near_workspaces::sandbox().await.unwrap();

// Initialize contract
let contract = worker.dev_deploy(WASM).await.unwrap();
Expand Down
4 changes: 2 additions & 2 deletions workspaces-tests/tests/escrow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ use near_sdk::{
serde::{Deserialize, Serialize},
serde_json::{self, json},
};
use near_workspaces::{Account, AccountId, Contract};
use tokio::join;
use workspaces::{Account, AccountId, Contract};

const WASM: &[u8] = include_bytes!("../../target/wasm32-unknown-unknown/release/escrow.wasm");

Expand Down Expand Up @@ -36,7 +36,7 @@ struct Setup {

/// Setup for individual tests
async fn setup(num_accounts: usize, wasm: &[u8]) -> Setup {
let worker = workspaces::sandbox().await.unwrap();
let worker = near_workspaces::sandbox().await.unwrap();

// Initialize user accounts
let mut accounts = vec![];
Expand Down
4 changes: 2 additions & 2 deletions workspaces-tests/tests/fungible_token.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#![cfg(not(windows))]

use near_sdk::{json_types::U128, serde_json::json};
use workspaces::{Account, AccountId, Contract};
use near_workspaces::{Account, AccountId, Contract};

const WASM: &[u8] =
include_bytes!("../../target/wasm32-unknown-unknown/release/fungible_token.wasm");
Expand All @@ -24,7 +24,7 @@ struct Setup {

/// Setup for individual tests
async fn setup(num_accounts: usize) -> Setup {
let worker = workspaces::sandbox().await.unwrap();
let worker = near_workspaces::sandbox().await.unwrap();

// Initialize contract
let contract = worker.dev_deploy(WASM).await.unwrap();
Expand Down
33 changes: 11 additions & 22 deletions workspaces-tests/tests/native_multisig.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ use std::{future::IntoFuture, time::Duration};
use near_crypto::{KeyType, SecretKey};
use near_sdk::{serde_json::json, Gas, ONE_NEAR};
use near_sdk_contract_tools::approval::native_transaction_action::PromiseAction;
use tokio::{join, task::JoinSet, time::sleep};
use workspaces::{
use near_workspaces::{
result::{ExecutionResult, Value},
sandbox,
types::{AccessKeyPermission, Finality},
Account, Contract, DevNetwork, Worker,
Account, AccountDetailsPatch, Contract, DevNetwork, Worker,
};
use tokio::{join, time::sleep};

const WASM: &[u8] =
include_bytes!("../../target/wasm32-unknown-unknown/release/native_multisig.wasm");
Expand Down Expand Up @@ -106,23 +106,12 @@ async fn stake() {

const MINIMUM_STAKE: u128 = 800_000_000_000_000_000_000_000_000;

let mut set = JoinSet::new();

// Fund contract account to meet minumum stake requirement.
// At the time of writing, it looks like workspaces network configuration is not yet released:
// https://github.com/near/workspaces-rs/commit/8df17e5d6ebbfe9ced52beb133f3e5b07a86dffb
// Otherwise we could just decrease the staking requirement.
for _ in 0..10 {
let w = worker.clone();
let contract_id = contract.id().clone();
set.spawn(async move {
let a = w.dev_create_account().await.unwrap();
a.delete_account(&contract_id).await.unwrap().unwrap();
});
}

// Await all
while set.join_next().await.is_some() {}
worker
.patch(contract.id())
.account(AccountDetailsPatch::default().balance(MINIMUM_STAKE * 4))
.transact()
.await
.unwrap();

let alice = &accounts[0];
let bob = &accounts[1];
Expand All @@ -136,7 +125,7 @@ async fn stake() {
"Account should start with no staked tokens"
);

let stake_amount = MINIMUM_STAKE;
let stake_amount = MINIMUM_STAKE * 2;

let request_id = alice
.call(contract.id(), "request")
Expand Down Expand Up @@ -235,7 +224,7 @@ async fn create_account_transfer_deploy_contract_function_call() {
let bob = &accounts[1];

let new_account_id_str = format!("new.{}", contract.id());
let new_account_id: workspaces::AccountId = new_account_id_str.parse().unwrap();
let new_account_id: near_workspaces::AccountId = new_account_id_str.parse().unwrap();

// Account does not exist yet
assert!(worker.view_account(&new_account_id).await.is_err());
Expand Down
12 changes: 7 additions & 5 deletions workspaces-tests/tests/non_fungible_token.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ use near_sdk_contract_tools::standard::{
nep178,
nep297::Event,
};
use near_workspaces::{operations::Function, types::Gas};
use tokio::task::JoinSet;
use workspaces::operations::Function;
use workspaces_tests_utils::{expect_execution_error, nft_token, setup, Setup};

const WASM_171_ONLY: &[u8] =
Expand All @@ -22,6 +22,8 @@ const WASM_FULL: &[u8] =
const RECEIVER_WASM: &[u8] =
include_bytes!("../../target/wasm32-unknown-unknown/release/non_fungible_token_receiver.wasm");

const THIRTY_TERAGAS: Gas = Gas::from_gas(30_000_000_000_000);

fn token_meta(id: String) -> near_sdk::serde_json::Value {
near_sdk::serde_json::to_value(TokenMetadata {
title: Some(id),
Expand Down Expand Up @@ -508,7 +510,7 @@ async fn transfer_call_success() {
"receiver_id": bob.id(),
"msg": "",
}))
.gas(30_000_000_000_000)
.gas(THIRTY_TERAGAS)
.deposit(1)
.transact()
.await
Expand Down Expand Up @@ -567,7 +569,7 @@ async fn transfer_call_return_success() {
"receiver_id": bob.id(),
"msg": "return",
}))
.gas(30_000_000_000_000)
.gas(THIRTY_TERAGAS)
.deposit(1)
.transact()
.await
Expand Down Expand Up @@ -636,7 +638,7 @@ async fn transfer_call_receiver_panic() {
"receiver_id": bob.id(),
"msg": "panic",
}))
.gas(30_000_000_000_000)
.gas(THIRTY_TERAGAS)
.deposit(1)
.transact()
.await
Expand Down Expand Up @@ -706,7 +708,7 @@ async fn transfer_call_receiver_send_return() {
"receiver_id": bob.id(),
"msg": format!("transfer:{}", charlie.id()),
}))
.gas(300_000_000_000_000) // xtra gas
.gas(THIRTY_TERAGAS) // xtra gas
.deposit(1)
.transact()
.await
Expand Down
4 changes: 2 additions & 2 deletions workspaces-tests/tests/rbac.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ use near_sdk::{
serde::Deserialize,
serde_json::{self, json},
};
use near_workspaces::{Account, AccountId, Contract};
use tokio::join;
use workspaces::{Account, AccountId, Contract};

const WASM: &[u8] = include_bytes!("../../target/wasm32-unknown-unknown/release/rbac.wasm");

Expand All @@ -27,7 +27,7 @@ struct Setup {

/// Setup for individual tests
async fn setup(num_accounts: usize, wasm: &[u8]) -> Setup {
let worker = workspaces::sandbox().await.unwrap();
let worker = near_workspaces::sandbox().await.unwrap();

// Initialize user accounts
let mut accounts = vec![];
Expand Down
4 changes: 2 additions & 2 deletions workspaces-tests/tests/simple_multisig.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#![cfg(not(windows))]

use near_sdk::serde_json::json;
use workspaces::{Account, Contract};
use near_workspaces::{Account, Contract};

const WASM: &[u8] =
include_bytes!("../../target/wasm32-unknown-unknown/release/simple_multisig.wasm");
Expand All @@ -13,7 +13,7 @@ struct Setup {

/// Setup for individual tests
async fn setup(num_accounts: usize) -> Setup {
let worker = workspaces::sandbox().await.unwrap();
let worker = near_workspaces::sandbox().await.unwrap();

// Initialize contract
let contract = worker.dev_deploy(WASM).await.unwrap();
Expand Down
5 changes: 3 additions & 2 deletions workspaces-tests/tests/storage_fee.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

use near_sdk::{json_types::U128, serde_json::json, ONE_NEAR};

use workspaces::{sandbox, Account, Contract, DevNetwork, Worker};
use near_workspaces::{sandbox, Account, Contract, DevNetwork, Worker};

const WASM: &[u8] = include_bytes!("../../target/wasm32-unknown-unknown/release/storage_fee.wasm");

Expand Down Expand Up @@ -73,7 +73,8 @@ async fn storage_fee() {

// How much was actually charged to the account?
// Note that there will be *some* overhead, e.g. collection indexing
let net_fee = balance_before - balance_after - (r.total_gas_burnt as u128 * gas_price);
let net_fee =
balance_before - balance_after - (r.total_gas_burnt.as_gas() as u128 * gas_price);

assert!(net_fee >= minimum_storage_fee);
assert!(net_fee - minimum_storage_fee < byte_cost * 100); // Sanity/validity check / allow up to 100 bytes worth of additional storage to be charged
Expand Down
4 changes: 2 additions & 2 deletions workspaces-tests/tests/upgrade.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use near_sdk::{
borsh::{self, BorshSerialize},
serde::Serialize,
};
use workspaces::{Account, Contract};
use near_workspaces::{Account, Contract};

const WASM_BORSH: &[u8] =
include_bytes!("../../target/wasm32-unknown-unknown/release/upgrade_old_borsh.wasm");
Expand Down Expand Up @@ -42,7 +42,7 @@ struct Setup {

/// Setup for individual tests
async fn setup(num_accounts: usize, wasm: &[u8]) -> Setup {
let worker = workspaces::sandbox().await.unwrap();
let worker = near_workspaces::sandbox().await.unwrap();

// Initialize user accounts
let mut accounts = vec![];
Expand Down
4 changes: 2 additions & 2 deletions workspaces-tests/tests/upgrade_multisig.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#![cfg(not(windows))]

use near_sdk::{json_types::Base64VecU8, serde_json::json};
use workspaces::{Account, Contract};
use near_workspaces::{Account, Contract};

const WASM: &[u8] =
include_bytes!("../../target/wasm32-unknown-unknown/release/upgrade_old_multisig.wasm");
Expand All @@ -16,7 +16,7 @@ struct Setup {

/// Setup for individual tests
async fn setup(num_accounts: usize, wasm: &[u8]) -> Setup {
let worker = workspaces::testnet().await.unwrap();
let worker = near_workspaces::sandbox().await.unwrap();

// Initialize user accounts
let mut accounts = vec![];
Expand Down

0 comments on commit 677a18d

Please sign in to comment.