Skip to content

Commit 7ca0e34

Browse files
committed
test(e2e): FileUpdate
Signed-off-by: Skyler Ross <[email protected]>
1 parent 209196d commit 7ca0e34

File tree

2 files changed

+117
-0
lines changed

2 files changed

+117
-0
lines changed

tests/e2e/file/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@ mod contents;
33
mod create;
44
mod delete;
55
mod info;
6+
mod update;

tests/e2e/file/update.rs

Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
use assert_matches::assert_matches;
2+
use hedera::{
3+
FileCreateTransaction,
4+
FileDeleteTransaction,
5+
FileInfoQuery,
6+
FileUpdateTransaction,
7+
Key,
8+
KeyList,
9+
Status,
10+
};
11+
12+
use crate::common::{
13+
setup_nonfree,
14+
TestEnvironment,
15+
};
16+
17+
#[tokio::test]
18+
async fn basic() -> anyhow::Result<()> {
19+
let Some(TestEnvironment { config, client }) = setup_nonfree() else {
20+
return Ok(())
21+
};
22+
23+
let Some(op) = &config.operator else {
24+
log::debug!("skipping test due to missing operator");
25+
return Ok(())
26+
};
27+
28+
let file_id = FileCreateTransaction::new()
29+
.keys([op.private_key.public_key()])
30+
.contents("[rust::e2e::file_update::1]")
31+
.execute(&client)
32+
.await?
33+
.get_receipt(&client)
34+
.await?
35+
.file_id
36+
.unwrap();
37+
38+
FileUpdateTransaction::new()
39+
.file_id(file_id)
40+
.contents(b"updated file".to_vec())
41+
.execute(&client)
42+
.await?
43+
.get_receipt(&client)
44+
.await?;
45+
46+
let info = FileInfoQuery::new().file_id(file_id).execute(&client).await?;
47+
48+
assert_eq!(info.file_id, file_id);
49+
assert_eq!(info.size, 12);
50+
assert_eq!(info.is_deleted, false);
51+
assert_eq!(
52+
info.keys,
53+
KeyList { keys: Vec::from([Key::Single(op.private_key.public_key())]), threshold: None }
54+
);
55+
56+
FileDeleteTransaction::new()
57+
.file_id(file_id)
58+
.execute(&client)
59+
.await?
60+
.get_receipt(&client)
61+
.await?;
62+
63+
Ok(())
64+
}
65+
66+
#[tokio::test]
67+
async fn immutable_file_fails() -> anyhow::Result<()> {
68+
let Some(TestEnvironment { config: _, client }) = setup_nonfree() else {
69+
return Ok(())
70+
};
71+
72+
let file_id = FileCreateTransaction::new()
73+
.contents("[rust::e2e::file_update::2]")
74+
.execute(&client)
75+
.await?
76+
.get_receipt(&client)
77+
.await?
78+
.file_id
79+
.unwrap();
80+
81+
let res = FileUpdateTransaction::new()
82+
.file_id(file_id)
83+
.contents(Vec::from([0]))
84+
.execute(&client)
85+
.await?
86+
.get_receipt(&client)
87+
.await;
88+
89+
assert_matches!(
90+
res,
91+
Err(hedera::Error::ReceiptStatus { status: Status::Unauthorized, transaction_id: _ })
92+
);
93+
94+
Ok(())
95+
}
96+
97+
#[tokio::test]
98+
async fn missing_file_id_fails() -> anyhow::Result<()> {
99+
let Some(TestEnvironment { config: _, client }) = setup_nonfree() else {
100+
return Ok(())
101+
};
102+
103+
let res = FileUpdateTransaction::new()
104+
.contents(b"contents".to_vec())
105+
.execute(&client)
106+
.await?
107+
.get_receipt(&client)
108+
.await;
109+
110+
assert_matches!(
111+
res,
112+
Err(hedera::Error::ReceiptStatus { status: Status::InvalidFileId, transaction_id: _ })
113+
);
114+
115+
Ok(())
116+
}

0 commit comments

Comments
 (0)