Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

runtime API: Substitute UncheckedExtrinsic with custom encoding #1076

Merged
merged 20 commits into from
Jul 21, 2023
Merged
Changes from 2 commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions subxt/src/utils/unchecked_extrinsic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,3 +107,29 @@ impl<Address, Call, Signature, Extra> IntoVisitor
UncheckedExtrinsicDecodeAsTypeVisitor(PhantomData)
}
}

#[cfg(test)]
pub mod tests {
use super::*;

#[test]
fn unchecked_extrinsic_encoding() {
let tx_bytes = vec![1, 2, 3];

let unchecked_extrinsic = UncheckedExtrinsic::<(), (), (), ()>::new(tx_bytes.clone());
let encoded_tx_bytes = unchecked_extrinsic.encode();

// The encoded representation must not alter the provided bytes.
assert_eq!(tx_bytes, encoded_tx_bytes);

// However, for decoding we expect to be able to read the extrinsic from the wire
// which would be length prefixed.
let wire_bytes = tx_bytes.encode();
let decoded_tx =
UncheckedExtrinsic::<(), (), (), ()>::decode(&mut &wire_bytes[..]).unwrap();
let encoded_tx_bytes = decoded_tx.encode();

assert_eq!(decoded_tx.bytes(), encoded_tx_bytes);
assert_eq!(tx_bytes, encoded_tx_bytes);
lexnv marked this conversation as resolved.
Show resolved Hide resolved
}
}