@@ -2,6 +2,7 @@ use crate::utils::{
2
2
crypto:: { sha256hash, sign_bytes_recoverable} ,
3
3
get_current_time_nanos,
4
4
} ;
5
+ use crate :: DRIA_COMPUTE_NODE_VERSION ;
5
6
use base64:: { prelude:: BASE64_STANDARD , Engine } ;
6
7
use core:: fmt;
7
8
use ecies:: PublicKey ;
@@ -12,7 +13,7 @@ use serde::{Deserialize, Serialize};
12
13
/// A message within Dria Knowledge Network.
13
14
#[ derive( Serialize , Deserialize , Debug , Clone ) ]
14
15
pub struct DKNMessage {
15
- /// Base64 encoded data
16
+ /// Base64 encoded payload, stores the main result.
16
17
pub ( crate ) payload : String ,
17
18
/// The topic of the message, derived from `TopicHash`
18
19
///
@@ -44,7 +45,7 @@ impl DKNMessage {
44
45
Self {
45
46
payload : BASE64_STANDARD . encode ( payload) ,
46
47
topic : topic. to_string ( ) ,
47
- version : crate :: DRIA_COMPUTE_NODE_VERSION . to_string ( ) ,
48
+ version : DRIA_COMPUTE_NODE_VERSION . to_string ( ) ,
48
49
timestamp : get_current_time_nanos ( ) ,
49
50
}
50
51
}
@@ -133,8 +134,7 @@ mod tests {
133
134
use crate :: payloads:: TaskResponsePayload ;
134
135
use crate :: { utils:: crypto:: sha256hash, DriaComputeNodeConfig } ;
135
136
use ecies:: decrypt;
136
- use libsecp256k1:: SecretKey ;
137
- use libsecp256k1:: { verify, Message , PublicKey , RecoveryId , Signature } ;
137
+ use libsecp256k1:: { verify, Message , PublicKey , RecoveryId , SecretKey , Signature } ;
138
138
use rand:: thread_rng;
139
139
use serde_json:: json;
140
140
@@ -155,7 +155,7 @@ mod tests {
155
155
156
156
#[ test]
157
157
fn test_display_message ( ) {
158
- let message = DKNMessage :: new ( b"hello world" , "test-topic" ) ;
158
+ let message = DKNMessage :: new ( b"hello world" , TOPIC ) ;
159
159
println ! ( "{}" , message) ;
160
160
}
161
161
@@ -173,10 +173,11 @@ mod tests {
173
173
serde_json:: to_string( & body) . expect( "Should stringify" ) ,
174
174
"{\" hello\" :\" world\" }"
175
175
) ;
176
- assert_eq ! ( message. topic, "test-topic" ) ;
177
- assert_eq ! ( message. version, crate :: DRIA_COMPUTE_NODE_VERSION ) ;
176
+ assert_eq ! ( message. topic, TOPIC ) ;
177
+ assert_eq ! ( message. version, DRIA_COMPUTE_NODE_VERSION ) ;
178
178
assert ! ( message. timestamp > 0 ) ;
179
179
180
+ // decode payload without signature
180
181
let parsed_body = message. parse_payload ( false ) . expect ( "Should decode" ) ;
181
182
assert_eq ! ( body, parsed_body) ;
182
183
}
@@ -200,8 +201,8 @@ mod tests {
200
201
serde_json:: to_string( & body) . expect( "Should stringify" ) ,
201
202
"{\" hello\" :\" world\" }"
202
203
) ;
203
- assert_eq ! ( message. topic, "test-topic" ) ;
204
- assert_eq ! ( message. version, crate :: DRIA_COMPUTE_NODE_VERSION ) ;
204
+ assert_eq ! ( message. topic, TOPIC ) ;
205
+ assert_eq ! ( message. version, DRIA_COMPUTE_NODE_VERSION ) ;
205
206
assert ! ( message. timestamp > 0 ) ;
206
207
207
208
assert ! ( message. is_signed( & pk) . expect( "Should check signature" ) ) ;
0 commit comments