Skip to content

Commit

Permalink
Use right discriminant for the Upgrade transaction
Browse files Browse the repository at this point in the history
  • Loading branch information
xgreenx committed Apr 7, 2024
1 parent 71c026c commit 4771d5a
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
2 changes: 1 addition & 1 deletion fuel-tx/src/transaction/types/upgrade.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ pub enum UpgradePurpose {
#[derive(Clone, Derivative)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[derive(fuel_types::canonical::Deserialize, fuel_types::canonical::Serialize)]
#[canonical(prefix = TransactionRepr::Script)]
#[canonical(prefix = TransactionRepr::Upgrade)]
#[derivative(Eq, PartialEq, Hash, Debug)]
pub struct UpgradeBody {
/// The purpose of the upgrade.
Expand Down
21 changes: 18 additions & 3 deletions fuel-vm/src/tests/encoding.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,21 @@ where
}
}

/// The function tests that the encoding of the `Transaction` and the specific `T` variant
/// of the transaction are correct.
pub fn assert_transactions_encoding_correct<T>(data: &[T])
where
T: Serialize + Deserialize + Into<Transaction> + fmt::Debug + Clone + PartialEq,
{
assert_encoding_correct(data);

let txs = data
.iter()
.map(|d| d.clone().into())
.collect::<Vec<Transaction>>();
assert_encoding_correct(&txs);
}

#[test]
fn call() {
let rng = &mut StdRng::seed_from_u64(2322u64);
Expand Down Expand Up @@ -208,7 +223,7 @@ fn transaction_canonical_serialization_deserialization() {
let o = Output::coin([0xaa; 32].into(), Word::MAX >> 1, [0xbb; 32].into());
let w = Witness::from(vec![0xbf]);

assert_encoding_correct(&[
assert_transactions_encoding_correct(&[
Transaction::script(
Word::MAX >> 2,
vec![0xfa],
Expand Down Expand Up @@ -321,7 +336,7 @@ fn transaction_canonical_serialization_deserialization() {
vec![],
),
]);
assert_encoding_correct(&[
assert_transactions_encoding_correct(&[
Transaction::create(
0xba,
Policies::new()
Expand Down Expand Up @@ -395,7 +410,7 @@ fn transaction_canonical_serialization_deserialization() {
vec![],
),
]);
assert_encoding_correct(&[
assert_transactions_encoding_correct(&[
Transaction::upgrade(
UpgradePurpose::ConsensusParameters {
witness_index: 0,
Expand Down

0 comments on commit 4771d5a

Please sign in to comment.