Skip to content

Commit 133934d

Browse files
svyatonikbkchr
authored andcommitted
fix parse_transaction on Rialto+Millau (#1360)
1 parent c29bfcc commit 133934d

File tree

4 files changed

+66
-8
lines changed

4 files changed

+66
-8
lines changed

bridges/primitives/runtime/src/chain.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ use sp_runtime::{
2727
use sp_std::{convert::TryFrom, fmt::Debug, hash::Hash, str::FromStr, vec, vec::Vec};
2828

2929
/// Chain call, that is either SCALE-encoded, or decoded.
30-
#[derive(Debug, Clone)]
30+
#[derive(Debug, Clone, PartialEq)]
3131
pub enum EncodedOrDecodedCall<ChainCall> {
3232
/// The call that is SCALE-encoded.
3333
///

bridges/relays/client-millau/src/lib.rs

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ use std::time::Duration;
3131
pub type HeaderId = relay_utils::HeaderId<millau_runtime::Hash, millau_runtime::BlockNumber>;
3232

3333
/// Millau chain definition.
34-
#[derive(Debug, Clone, Copy)]
34+
#[derive(Debug, Clone, Copy, PartialEq)]
3535
pub struct Millau;
3636

3737
impl ChainBase for Millau {
@@ -154,8 +154,8 @@ impl TransactionSignScheme for Millau {
154154
let extra = &tx.signature.as_ref()?.2;
155155
Some(UnsignedTransaction {
156156
call: tx.function.into(),
157-
nonce: Compact::<IndexOf<Self::Chain>>::decode(&mut &extra.4.encode()[..]).ok()?.into(),
158-
tip: Compact::<BalanceOf<Self::Chain>>::decode(&mut &extra.6.encode()[..])
157+
nonce: Compact::<IndexOf<Self::Chain>>::decode(&mut &extra.5.encode()[..]).ok()?.into(),
158+
tip: Compact::<BalanceOf<Self::Chain>>::decode(&mut &extra.7.encode()[..])
159159
.ok()?
160160
.into(),
161161
})
@@ -167,3 +167,32 @@ pub type SigningParams = sp_core::sr25519::Pair;
167167

168168
/// Millau header type used in headers sync.
169169
pub type SyncHeader = relay_substrate_client::SyncHeader<millau_runtime::Header>;
170+
171+
#[cfg(test)]
172+
mod tests {
173+
use super::*;
174+
use relay_substrate_client::TransactionEra;
175+
176+
#[test]
177+
fn parse_transaction_works() {
178+
let unsigned = UnsignedTransaction {
179+
call: millau_runtime::Call::System(millau_runtime::SystemCall::remark {
180+
remark: b"Hello world!".to_vec(),
181+
})
182+
.into(),
183+
nonce: 777,
184+
tip: 888,
185+
};
186+
let signed_transaction = Millau::sign_transaction(SignParam {
187+
spec_version: 42,
188+
transaction_version: 50000,
189+
genesis_hash: [42u8; 64].into(),
190+
signer: sp_core::sr25519::Pair::from_seed_slice(&[1u8; 32]).unwrap(),
191+
era: TransactionEra::immortal(),
192+
unsigned: unsigned.clone(),
193+
})
194+
.unwrap();
195+
let parsed_transaction = Millau::parse_transaction(signed_transaction).unwrap();
196+
assert_eq!(parsed_transaction, unsigned);
197+
}
198+
}

bridges/relays/client-rialto/src/lib.rs

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ use std::time::Duration;
3131
pub type HeaderId = relay_utils::HeaderId<rialto_runtime::Hash, rialto_runtime::BlockNumber>;
3232

3333
/// Rialto chain definition
34-
#[derive(Debug, Clone, Copy)]
34+
#[derive(Debug, Clone, Copy, PartialEq)]
3535
pub struct Rialto;
3636

3737
impl ChainBase for Rialto {
@@ -152,8 +152,8 @@ impl TransactionSignScheme for Rialto {
152152
let extra = &tx.signature.as_ref()?.2;
153153
Some(UnsignedTransaction {
154154
call: tx.function.into(),
155-
nonce: Compact::<IndexOf<Self::Chain>>::decode(&mut &extra.4.encode()[..]).ok()?.into(),
156-
tip: Compact::<BalanceOf<Self::Chain>>::decode(&mut &extra.6.encode()[..])
155+
nonce: Compact::<IndexOf<Self::Chain>>::decode(&mut &extra.5.encode()[..]).ok()?.into(),
156+
tip: Compact::<BalanceOf<Self::Chain>>::decode(&mut &extra.7.encode()[..])
157157
.ok()?
158158
.into(),
159159
})
@@ -165,3 +165,32 @@ pub type SigningParams = sp_core::sr25519::Pair;
165165

166166
/// Rialto header type used in headers sync.
167167
pub type SyncHeader = relay_substrate_client::SyncHeader<rialto_runtime::Header>;
168+
169+
#[cfg(test)]
170+
mod tests {
171+
use super::*;
172+
use relay_substrate_client::TransactionEra;
173+
174+
#[test]
175+
fn parse_transaction_works() {
176+
let unsigned = UnsignedTransaction {
177+
call: rialto_runtime::Call::System(rialto_runtime::SystemCall::remark {
178+
remark: b"Hello world!".to_vec(),
179+
})
180+
.into(),
181+
nonce: 777,
182+
tip: 888,
183+
};
184+
let signed_transaction = Rialto::sign_transaction(SignParam {
185+
spec_version: 42,
186+
transaction_version: 50000,
187+
genesis_hash: [42u8; 32].into(),
188+
signer: sp_core::sr25519::Pair::from_seed_slice(&[1u8; 32]).unwrap(),
189+
era: TransactionEra::immortal(),
190+
unsigned: unsigned.clone(),
191+
})
192+
.unwrap();
193+
let parsed_transaction = Rialto::parse_transaction(signed_transaction).unwrap();
194+
assert_eq!(parsed_transaction, unsigned);
195+
}
196+
}

bridges/relays/client-substrate/src/chain.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ pub trait BlockWithJustification<Header> {
134134
}
135135

136136
/// Transaction before it is signed.
137-
#[derive(Clone, Debug)]
137+
#[derive(Clone, Debug, PartialEq)]
138138
pub struct UnsignedTransaction<C: Chain> {
139139
/// Runtime call of this transaction.
140140
pub call: EncodedOrDecodedCall<C::Call>,

0 commit comments

Comments
 (0)