forked from hyperledger-solang/solang
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcli.rs
More file actions
131 lines (106 loc) · 3.16 KB
/
cli.rs
File metadata and controls
131 lines (106 loc) · 3.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
// SPDX-License-Identifier: Apache-2.0
use assert_cmd::cargo_bin_cmd;
use std::fs::File;
use tempfile::TempDir;
#[test]
fn create_output_dir() {
let mut cmd = cargo_bin_cmd!("solang");
let tmp = TempDir::new_in("tests").unwrap();
let test1 = tmp.path().join("test1");
cmd.args([
"compile",
"examples/solana/flipper.sol",
"--target",
"solana",
"--output",
])
.arg(test1.clone())
.assert()
.success();
File::open(test1.join("flipper.json")).expect("should exist");
File::open(test1.join("flipper.so")).expect("should exist");
let mut cmd = cargo_bin_cmd!("solang");
let test2 = tmp.path().join("test2");
let test2_meta = tmp.path().join("test2_meta");
let assert = cmd
.args([
"compile",
"examples/solana/flipper.sol",
"--target",
"solana",
"--contract",
"flipper",
"--contract-authors",
"itchy and cratchy",
"--output",
])
.arg(test2.clone())
.arg("--output-meta")
.arg(test2_meta.clone())
.assert()
.success();
File::open(test2.join("flipper.so")).expect("should exist");
File::open(test2_meta.join("flipper.json")).expect("should exist");
let output = assert.get_output();
assert_eq!(
String::from_utf8_lossy(&output.stderr),
"warning: the `authors` flag will be ignored for Solana target\n"
);
let mut cmd = cargo_bin_cmd!("solang");
cmd.args([
"compile",
"examples/solana/flipper.sol",
"--target",
"solana",
"--output",
"examples/solana/flipper.sol",
])
.assert()
.failure();
let mut cmd = cargo_bin_cmd!("solang");
let test3 = tmp.path().join("test3");
cmd.args([
"compile",
"examples/solana/flipper.sol",
"--target",
"solana",
"--contract",
"flapper,flipper", // not just flipper
"--output",
])
.arg(test3.clone())
.assert()
.failure();
// nothing should have been created because flapper does not exist
assert!(!test3.exists());
}
#[test]
fn basic_compilation_from_toml() {
let mut new_cmd = cargo_bin_cmd!("solang");
let tmp = TempDir::new_in("tests").unwrap();
let solana_test = tmp.path().join("solana_test");
//solang new --target solana
new_cmd
.arg("new")
.arg(solana_test.clone())
.args(["--target", "solana"])
.assert()
.success();
File::open(solana_test.join("flipper.sol")).expect("should exist");
File::open(solana_test.join("solang.toml")).expect("should exist");
// compile flipper using config file
let mut compile_cmd = cargo_bin_cmd!("solang");
compile_cmd
.args(["compile"])
.current_dir(solana_test)
.assert()
.success();
let polkadot_test = tmp.path().join("polkadot_test");
let _new_cmd = cargo_bin_cmd!("solang")
.arg("new")
.arg(polkadot_test.clone())
.args(["--target", "solana"])
.assert()
.success();
compile_cmd.current_dir(polkadot_test).assert().success();
}