|
@@ -8,11 +8,7 @@ use rand::{RngCore, SeedableRng};
|
8
|
8
|
use rand_chacha::ChaChaRng;
|
9
|
9
|
use reqwest::Url;
|
10
|
10
|
use serde_json::json;
|
11
|
|
-use std::{
|
12
|
|
- fs::{create_dir, read, write},
|
13
|
|
- path::Path,
|
14
|
|
- str::FromStr,
|
15
|
|
-};
|
|
11
|
+use std::{fs::write, path::Path, str::FromStr};
|
16
|
12
|
use workspaces::{network::Sandbox, types::SecretKey, AccountId, Worker};
|
17
|
13
|
|
18
|
14
|
// auxiliary structs and methods
|
|
@@ -50,55 +46,41 @@ async fn create_signer(
|
50
|
46
|
|
51
|
47
|
async fn download_contract() -> Vec<u8> {
|
52
|
48
|
let target = "https://github.com/near-examples/FT/raw/master/res/fungible_token.wasm";
|
53
|
|
- let target_path = "../target/tmp-contracts";
|
|
49
|
+ let target_path = temp_dir().into_path();
|
54
|
50
|
let fname = "contract.wasm";
|
55
|
|
- let full_dest = format!("{}/{}", target_path, fname);
|
56
|
|
-
|
57
|
|
- if !Path::new(&full_dest).exists() {
|
58
|
|
- if !Path::new(&target_path).exists() {
|
59
|
|
- create_dir(target_path).unwrap();
|
60
|
|
- };
|
|
51
|
+ let full_dest = format!("{}/{}", target_path.to_string_lossy(), fname);
|
61
|
52
|
|
62
|
|
- let contract_bytes = reqwest::get(target).await.unwrap().bytes().await.unwrap();
|
63
|
|
- write(full_dest, &contract_bytes).unwrap();
|
64
|
|
- contract_bytes.to_vec()
|
65
|
|
- } else {
|
66
|
|
- read(&full_dest).unwrap()
|
67
|
|
- }
|
|
53
|
+ let contract_bytes = reqwest::get(target).await.unwrap().bytes().await.unwrap();
|
|
54
|
+ write(full_dest, &contract_bytes).unwrap();
|
|
55
|
+ contract_bytes.to_vec()
|
68
|
56
|
}
|
69
|
57
|
|
70
|
58
|
async fn clone_and_compile_wasm() -> Vec<u8> {
|
71
|
|
- let tmp_path = "../target/tmp-contracts";
|
72
|
|
- let repo_path = format!("{}/near-smartcontracts", tmp_path);
|
|
59
|
+ let tmp_path = temp_dir().into_path();
|
|
60
|
+ let repo_path = format!("{}/near-smartcontracts", tmp_path.to_string_lossy());
|
73
|
61
|
let target_path = format!("{}/test-contract", repo_path);
|
74
|
62
|
let repo_url = "git@github.com:Relayz-io/near-smartcontracts.git";
|
75
|
63
|
|
76
|
|
- if !Path::new(&target_path).exists() {
|
77
|
|
- if !Path::new(&tmp_path).exists() {
|
78
|
|
- create_dir(tmp_path).unwrap();
|
79
|
|
- }
|
|
64
|
+ // Prepare callbacks.
|
|
65
|
+ let mut callbacks = RemoteCallbacks::new();
|
|
66
|
+ callbacks.credentials(|_, username_from_url, _| {
|
|
67
|
+ let username = username_from_url
|
|
68
|
+ .ok_or_else(|| git2::Error::from_str("Parsing the given URL is failed"))
|
|
69
|
+ .unwrap();
|
|
70
|
+ Cred::ssh_key_from_agent(username)
|
|
71
|
+ });
|
80
|
72
|
|
81
|
|
- // Prepare callbacks.
|
82
|
|
- let mut callbacks = RemoteCallbacks::new();
|
83
|
|
- callbacks.credentials(|_, username_from_url, _| {
|
84
|
|
- let username = username_from_url
|
85
|
|
- .ok_or_else(|| git2::Error::from_str("Parsing the given URL is failed"))
|
86
|
|
- .unwrap();
|
87
|
|
- Cred::ssh_key_from_agent(username)
|
88
|
|
- });
|
89
|
|
-
|
90
|
|
- // Prepare fetch options.
|
91
|
|
- let mut fo = git2::FetchOptions::new();
|
92
|
|
- fo.remote_callbacks(callbacks);
|
93
|
|
-
|
94
|
|
- // Prepare builder.
|
95
|
|
- let mut builder = git2::build::RepoBuilder::new();
|
96
|
|
- builder.fetch_options(fo);
|
97
|
|
- builder.branch("main");
|
98
|
|
-
|
99
|
|
- // Clone the project.
|
100
|
|
- builder.clone(repo_url, Path::new(&repo_path)).unwrap();
|
101
|
|
- }
|
|
73
|
+ // Prepare fetch options.
|
|
74
|
+ let mut fo = git2::FetchOptions::new();
|
|
75
|
+ fo.remote_callbacks(callbacks);
|
|
76
|
+
|
|
77
|
+ // Prepare builder.
|
|
78
|
+ let mut builder = git2::build::RepoBuilder::new();
|
|
79
|
+ builder.fetch_options(fo);
|
|
80
|
+ builder.branch("main");
|
|
81
|
+
|
|
82
|
+ // Clone the project.
|
|
83
|
+ builder.clone(repo_url, Path::new(&repo_path)).unwrap();
|
102
|
84
|
|
103
|
85
|
workspaces::compile_project(&target_path).await.unwrap()
|
104
|
86
|
}
|
|
@@ -440,3 +422,10 @@ async fn delete_account() {
|
440
|
422
|
}
|
441
|
423
|
));
|
442
|
424
|
}
|
|
425
|
+
|
|
426
|
+fn temp_dir() -> tempfile::TempDir {
|
|
427
|
+ tempfile::Builder::new()
|
|
428
|
+ .prefix("near-client-test-")
|
|
429
|
+ .tempdir()
|
|
430
|
+ .unwrap()
|
|
431
|
+}
|