Skip to content

Commit c6f454f

Browse files
author
PiVortex
committed
update sdk ot 5.3.0, fix errors and tests
1 parent b70459c commit c6f454f

File tree

3 files changed

+27
-17
lines changed

3 files changed

+27
-17
lines changed

Cargo.toml

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@ crate-type = ["cdylib", "rlib"]
1313

1414
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
1515
[dependencies]
16-
near-sdk = { version = "5.1.0", features = ["unstable"] }
16+
near-sdk = { version = "5.3.0", features = ["unstable"] }
1717

1818
[dev-dependencies]
19-
near-sdk = { version = "5.1.0", features = ["unit-testing"] }
19+
near-sdk = { version = "5.3.0", features = ["unit-testing"] }
2020
near-workspaces = { version = "0.10.0", features = ["unstable"] }
2121
tokio = { version = "1.12.0", features = ["full"] }
2222
serde_json = "1"

src/deploy.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -74,13 +74,11 @@ impl Contract {
7474
#[callback_result] create_deploy_result: Result<(), PromiseError>,
7575
) -> bool {
7676
if let Ok(_result) = create_deploy_result {
77-
log!(format!("Correctly created and deployed to {account}"));
77+
log!("Correctly created and deployed to {account}");
7878
return true;
7979
};
8080

81-
log!(format!(
82-
"Error creating {account}, returning {attached}yⓃ to {user}"
83-
));
81+
log!("Error creating {account}, returning {attached}yⓃ to {user}");
8482
Promise::new(user).transfer(attached);
8583
false
8684
}

tests/sandbox.rs

+23-11
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,19 @@
1-
use near_workspaces::types::{AccountId, KeyType, NearToken, SecretKey};
1+
use near_workspaces::types::{AccountId, NearToken};
22
use serde_json::json;
33

4+
const TEN_NEAR: NearToken = NearToken::from_near(10);
5+
46
#[tokio::test]
57
async fn main() -> Result<(), Box<dyn std::error::Error>> {
68
let sandbox = near_workspaces::sandbox().await?;
7-
let contract_wasm = near_workspaces::compile_project("./").await?;
8-
let contract = sandbox.dev_deploy(&contract_wasm).await?;
9+
let root = sandbox.root_account()?;
910

10-
let alice = sandbox
11-
.create_tla(
12-
"alice.test.near".parse().unwrap(),
13-
SecretKey::from_random(KeyType::ED25519),
14-
)
15-
.await?
16-
.unwrap();
11+
// Create accounts
12+
let alice = create_subaccount(&root, "alice").await?;
13+
let bob = create_subaccount(&root, "bob").await?;
1714

18-
let bob = sandbox.dev_create_account().await?;
15+
let contract_wasm = near_workspaces::compile_project("./").await?;
16+
let contract = sandbox.dev_deploy(&contract_wasm).await?;
1917

2018
let res = contract
2119
.call("create_factory_subaccount_and_deploy")
@@ -50,3 +48,17 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
5048

5149
Ok(())
5250
}
51+
52+
async fn create_subaccount(
53+
root: &near_workspaces::Account,
54+
name: &str,
55+
) -> Result<near_workspaces::Account, Box<dyn std::error::Error>> {
56+
let subaccount = root
57+
.create_subaccount(name)
58+
.initial_balance(TEN_NEAR)
59+
.transact()
60+
.await?
61+
.unwrap();
62+
63+
Ok(subaccount)
64+
}

0 commit comments

Comments
 (0)