Skip to content

Commit

Permalink
formated names after review
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexKushnir1 authored and AlexKushnir1 committed Dec 20, 2024
1 parent 981d65e commit 2fc538d
Show file tree
Hide file tree
Showing 8 changed files with 27 additions and 24 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ jobs:
needs: cargo-fmt
strategy:
matrix:
platform: [macos-latest, ubuntu-latest]
platform: [ubuntu-latest, macos-latest]
toolchain: [stable]
runs-on: ${{ matrix.platform }}

Expand Down
2 changes: 1 addition & 1 deletion examples/src/croncat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ async fn main() -> anyhow::Result<()> {
.into_result()?;

// Create a root croncat account with agent subaccounts to schedule tasks.
let croncat = worker.dev_create().await?;
let croncat = worker.dev_create_account().await?;

// This will setup a task to call into the counter contract, with a cadence of 1 hour.
println!("Creating task for `counter.increment`");
Expand Down
2 changes: 1 addition & 1 deletion examples/src/various_queries.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ async fn main() -> anyhow::Result<()> {
.await?;
println!("Latest Chunk: {chunk:#?}");

let bob = worker.dev_create().await?;
let bob = worker.dev_create_account().await?;
println!("\nCreated bob's account with id {:?}", bob.id());

// Show all the access keys relating to bob:
Expand Down
8 changes: 4 additions & 4 deletions workspaces/src/network/variants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -172,22 +172,22 @@ where
Ok(res)
}

pub async fn dev_generate(&self) -> (AccountId, SecretKey) {
pub async fn generate_sponsored_credentials(&self) -> (AccountId, SecretKey) {
let id = crate::rpc::tool::random_account_id();
let sk = SecretKey::from_seed(KeyType::ED25519, DEV_ACCOUNT_SEED);
(id, sk)
}

/// Creates a sub-account of the network root account with
/// random account ID and secret key. By default, balance is around 10 Near.
pub async fn dev_create(&self) -> Result<Account> {
let (id, sk) = self.dev_generate().await;
pub async fn dev_create_account(&self) -> Result<Account> {
let (id, sk) = self.generate_sponsored_credentials().await;
let account = self.create_sponsored_account(id.clone(), sk).await?;
Ok(account.into_result()?)
}

pub async fn dev_deploy(&self, wasm: &[u8]) -> Result<Contract> {
let (id, sk) = self.dev_generate().await;
let (id, sk) = self.generate_sponsored_credentials().await;
let contract = self
.create_sponsored_account_and_deploy(id.clone(), sk, wasm)
.await?;
Expand Down
7 changes: 5 additions & 2 deletions workspaces/tests/account.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use std::path::Path;
#[test(tokio::test)]
async fn test_subaccount_creation() -> anyhow::Result<()> {
let worker = near_workspaces::sandbox().await?;
let account = worker.dev_create().await?;
let account = worker.dev_create_account().await?;

let sub = account
.create_subaccount("subaccount")
Expand Down Expand Up @@ -71,7 +71,10 @@ async fn test_transfer_near() -> anyhow::Result<()> {
async fn test_delete_account() -> anyhow::Result<()> {
let worker = near_workspaces::sandbox().await?;

let (alice, bob) = (worker.dev_create().await?, worker.dev_create().await?);
let (alice, bob) = (
worker.dev_create_account().await?,
worker.dev_create_account().await?,
);

_ = alice.clone().delete_account(bob.id()).await?;

Expand Down
22 changes: 11 additions & 11 deletions workspaces/tests/gas_meter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ async fn test_gas_meter_with_single_transaction() -> anyhow::Result<()> {

// analogous to: worker.dev_deploy(include_bytes!("*.wasm")).await?;
let status_msg = {
let (id, sk) = worker.dev_generate().await;
let (id, sk) = worker.generate_sponsored_credentials().await;
let contract = worker
.create_sponsored_account_and_deploy(
id.clone(),
Expand All @@ -28,7 +28,7 @@ async fn test_gas_meter_with_single_transaction() -> anyhow::Result<()> {

// analogous to: worker.dev_create_account().await?;
let account = {
let (id, sk) = worker.dev_generate().await;
let (id, sk) = worker.generate_sponsored_credentials().await;
let account = worker.create_sponsored_account(id.clone(), sk).await?;
total_gas += account.details.total_gas_burnt.as_gas();

Expand Down Expand Up @@ -57,7 +57,7 @@ async fn test_gas_meter_with_multiple_transactions() -> anyhow::Result<()> {

// analogous to: worker.dev_deploy(include_bytes!("*.wasm")).await?;
let status_msg = {
let (id, sk) = worker.dev_generate().await;
let (id, sk) = worker.generate_sponsored_credentials().await;
let contract = worker
.create_sponsored_account_and_deploy(
id.clone(),
Expand All @@ -72,7 +72,7 @@ async fn test_gas_meter_with_multiple_transactions() -> anyhow::Result<()> {

// analogous to: worker.dev_create_account().await?;
let account = {
let (id, sk) = worker.dev_generate().await;
let (id, sk) = worker.generate_sponsored_credentials().await;
let account = worker.create_sponsored_account(id.clone(), sk).await?;
total_gas += account.details.total_gas_burnt.as_gas();

Expand Down Expand Up @@ -110,7 +110,7 @@ async fn test_gas_meter_with_parallel_transactions() -> anyhow::Result<()> {

// analogous to: worker.dev_deploy(include_bytes!("*.wasm")).await?;
let status_msg = {
let (id, sk) = worker.dev_generate().await;
let (id, sk) = worker.generate_sponsored_credentials().await;
let contract = worker
.create_sponsored_account_and_deploy(
id.clone(),
Expand All @@ -125,7 +125,7 @@ async fn test_gas_meter_with_parallel_transactions() -> anyhow::Result<()> {

// analogous to: worker.dev_create_account().await?;
let account = {
let (id, sk) = worker.dev_generate().await;
let (id, sk) = worker.generate_sponsored_credentials().await;
let account = worker.create_sponsored_account(id.clone(), sk).await?;
total_gas += account.details.total_gas_burnt.as_gas();

Expand Down Expand Up @@ -168,7 +168,7 @@ async fn test_gas_meter_with_multiple_transactions_and_view() -> anyhow::Result<

// analogous to: worker.dev_deploy(include_bytes!("*.wasm")).await?;
let status_msg = {
let (id, sk) = worker.dev_generate().await;
let (id, sk) = worker.generate_sponsored_credentials().await;
let contract = worker
.create_sponsored_account_and_deploy(
id.clone(),
Expand All @@ -183,7 +183,7 @@ async fn test_gas_meter_with_multiple_transactions_and_view() -> anyhow::Result<

// analogous to: worker.dev_create_account().await?;
let account = {
let (id, sk) = worker.dev_generate().await;
let (id, sk) = worker.generate_sponsored_credentials().await;
let account = worker.create_sponsored_account(id.clone(), sk).await?;
total_gas += account.details.total_gas_burnt.as_gas();

Expand Down Expand Up @@ -231,7 +231,7 @@ async fn test_gas_meter_batch_tx() -> anyhow::Result<()> {

// analogous to: worker.dev_deploy(include_bytes!("*.wasm")).await?;
let contract = {
let (id, sk) = worker.dev_generate().await;
let (id, sk) = worker.generate_sponsored_credentials().await;
let contract = worker
.create_sponsored_account_and_deploy(
id.clone(),
Expand Down Expand Up @@ -290,7 +290,7 @@ async fn test_gas_meter_create_account_transaction() -> anyhow::Result<()> {

// analogous to: worker.dev_create_account().await?;
let account = {
let (id, sk) = worker.dev_generate().await;
let (id, sk) = worker.generate_sponsored_credentials().await;
let account = worker.create_sponsored_account(id.clone(), sk).await?;
total_gas += account.details.total_gas_burnt.as_gas();

Expand All @@ -311,7 +311,7 @@ async fn test_dropped_gas_meter() -> anyhow::Result<()> {
let gas_meter = GasMeter::now(&mut worker);
drop(gas_meter);

worker.dev_create().await?;
worker.dev_create_account().await?;

Ok(())
}
4 changes: 2 additions & 2 deletions workspaces/tests/parallel_transactions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const STATUS_MSG_CONTRACT: &[u8] = include_bytes!("../../examples/res/status_mes
async fn test_parallel() -> anyhow::Result<()> {
let worker = near_workspaces::sandbox().await?;
let contract = worker.dev_deploy(STATUS_MSG_CONTRACT).await?;
let account = worker.dev_create().await?;
let account = worker.dev_create_account().await?;

let parallel_tasks = ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j"]
.iter()
Expand Down Expand Up @@ -46,7 +46,7 @@ async fn test_parallel() -> anyhow::Result<()> {
async fn test_parallel_async() -> anyhow::Result<()> {
let worker = near_workspaces::sandbox().await?;
let contract = worker.dev_deploy(STATUS_MSG_CONTRACT).await?;
let account = worker.dev_create().await?;
let account = worker.dev_create_account().await?;

// nonce of access key before any transactions occurred.
let nonce_start = worker
Expand Down
4 changes: 2 additions & 2 deletions workspaces/tests/patch_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ async fn test_patch_code_hash() -> anyhow::Result<()> {
let status_msg_acc = worker.view_account(&contract_id).await?;
let status_msg_code = worker.view_code(&contract_id).await?;

let bob = worker.dev_create().await?;
let bob = worker.dev_create_account().await?;

// Patching code bytes should also set the code hash, otherwise the node will crash
// when we try to do anything with the contract.
Expand All @@ -190,7 +190,7 @@ async fn test_patch_code_hash() -> anyhow::Result<()> {
async fn test_patch_account_from_current() -> anyhow::Result<()> {
let worker = near_workspaces::sandbox().await?;

let bob = worker.dev_create().await?;
let bob = worker.dev_create_account().await?;

const NEW_BALANCE: NearToken = NearToken::from_yoctonear(10_u128.pow(16));

Expand Down

0 comments on commit 2fc538d

Please sign in to comment.