@@ -2,10 +2,17 @@ use assert_matches::assert_matches;
2
2
use hedera:: {
3
3
Hbar ,
4
4
Key ,
5
+ PrivateKey ,
5
6
Status ,
7
+ TokenCreateTransaction ,
6
8
TokenInfoQuery ,
9
+ TokenType ,
7
10
TokenUpdateTransaction ,
8
11
} ;
12
+ use time:: {
13
+ Duration ,
14
+ OffsetDateTime ,
15
+ } ;
9
16
10
17
use super :: FungibleToken ;
11
18
use crate :: account:: Account ;
@@ -99,3 +106,54 @@ async fn immutable_token_fails() -> anyhow::Result<()> {
99
106
100
107
Ok ( ( ) )
101
108
}
109
+
110
+ #[ tokio:: test]
111
+
112
+ async fn update_immutable_token_metadata ( ) -> anyhow:: Result < ( ) > {
113
+ let Some ( TestEnvironment { config : _, client } ) = setup_nonfree ( ) else {
114
+ return Ok ( ( ) ) ;
115
+ } ;
116
+ let initial_metadata = vec ! [ 1 ] ;
117
+ let updated_metadata = vec ! [ 1 , 2 ] ;
118
+ let metadata_key = PrivateKey :: generate_ed25519 ( ) ;
119
+
120
+ // Create the Fungible Token with metadata key.
121
+ let token_id = TokenCreateTransaction :: new ( )
122
+ . name ( "ffff" )
123
+ . symbol ( "F" )
124
+ . token_type ( TokenType :: FungibleCommon )
125
+ . decimals ( 3 )
126
+ . initial_supply ( 1000000 )
127
+ . metadata ( initial_metadata. clone ( ) )
128
+ . treasury_account_id ( client. get_operator_account_id ( ) . unwrap ( ) )
129
+ . expiration_time ( OffsetDateTime :: now_utc ( ) + Duration :: minutes ( 5 ) )
130
+ . metadata_key ( metadata_key. public_key ( ) )
131
+ . execute ( & client)
132
+ . await ?
133
+ . get_receipt ( & client)
134
+ . await ?
135
+ . token_id
136
+ . unwrap ( ) ;
137
+
138
+ let token_info = TokenInfoQuery :: new ( ) . token_id ( token_id) . execute ( & client) . await ?;
139
+
140
+ assert_eq ! ( & token_info. metadata, & initial_metadata) ;
141
+ assert_eq ! ( token_info. metadata_key, Some ( Key :: Single ( metadata_key. public_key( ) ) ) ) ;
142
+
143
+ // Update token with metadata key
144
+ _ = TokenUpdateTransaction :: new ( )
145
+ . token_id ( token_id)
146
+ . metadata ( updated_metadata. clone ( ) )
147
+ . freeze_with ( & client) ?
148
+ . sign ( metadata_key)
149
+ . execute ( & client)
150
+ . await ?
151
+ . get_receipt ( & client)
152
+ . await ;
153
+
154
+ let token_info = TokenInfoQuery :: new ( ) . token_id ( token_id) . execute ( & client) . await ?;
155
+
156
+ assert_eq ! ( token_info. metadata, updated_metadata) ;
157
+
158
+ Ok ( ( ) )
159
+ }
0 commit comments