Skip to content

Commit

Permalink
web-client: Fix proofs being always set to empty string in Transactio…
Browse files Browse the repository at this point in the history
…n.fromPlain

#3134 (released in v1.0.2) forced plain transaction proof deserialization to always deserialize a `PlainTransactionProof::Raw` variant to be compatible with PoW plain transactions, which didn't have a `proof.type` field.

Unfortunately I forgot to remove the empty string default for `PlainTransactionProof::Raw` when I renamed it from `PlainTransactionProof::Empty`.
  • Loading branch information
sisou authored and jsdanielh committed Dec 13, 2024
1 parent a9c1ac4 commit 89d2049
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
17 changes: 15 additions & 2 deletions web-client/extras/tests/Transaction.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,13 @@ describe('Transaction', () => {
},
};

expect(() => Transaction.fromPlain(plain as PlainTransactionDetails)).not.toThrow();
let tx: Transaction | undefined;
expect(() => tx = Transaction.fromPlain(plain as PlainTransactionDetails)).not.toThrow();
if (!tx) throw new Error('Transaction.fromPlain returned undefined');
const plain2 = tx.toPlain();
expect(plain2.proof).toEqual(plain.proof);
expect(plain2.size).toEqual(plain.size);
expect(plain2.valid).toEqual(plain.valid);
});

it('can deserialize PoW style plain transaction details', () => {
Expand Down Expand Up @@ -129,6 +135,13 @@ describe('Transaction', () => {
},
};

expect(() => Transaction.fromPlain(plain as unknown as PlainTransactionDetails)).not.toThrow();
let tx: Transaction | undefined;
expect(() => tx = Transaction.fromPlain(plain as unknown as PlainTransactionDetails)).not.toThrow();
if (!tx) throw new Error('Transaction.fromPlain returned undefined');

const plain2 = tx.toPlain();
expect(plain2.proof).toEqual(plain.proof);

Check failure on line 143 in web-client/extras/tests/Transaction.test.ts

View workflow job for this annotation

GitHub Actions / web-client-lib

tests/Transaction.test.ts > Transaction > can deserialize PoW style plain transaction details

AssertionError: expected { type: 'standard', …(5) } to deeply equal { …(5) } - Expected + Received Object { "pathLength": 0, "publicKey": "4490c883a95fc7c44e45043108436973b071851ed2a203111ddb2f088056f0fc", - "raw": "4490c883a95fc7c44e45043108436973b071851ed2a203111ddb2f088056f0fc0098be457841e99d998cc54e96306a82e106bc5306271cd2194eba1d8e7653baff6e5e3b3344c11da401d4f42ab5763e4f3147662f07ac4c32addd3e15da469707", + "raw": "004490c883a95fc7c44e45043108436973b071851ed2a203111ddb2f088056f0fc0098be457841e99d998cc54e96306a82e106bc5306271cd2194eba1d8e7653baff6e5e3b3344c11da401d4f42ab5763e4f3147662f07ac4c32addd3e15da469707", "signature": "98be457841e99d998cc54e96306a82e106bc5306271cd2194eba1d8e7653baff6e5e3b3344c11da401d4f42ab5763e4f3147662f07ac4c32addd3e15da469707", "signer": "NQ71 4NP1 51M7 3M05 BGAS VPTH JRY3 RADA ALVQ", + "type": "standard", } ❯ tests/Transaction.test.ts:143:30
expect(plain2.size).toEqual(plain.size);
expect(plain2.valid).toEqual(plain.valid);
});
});
2 changes: 1 addition & 1 deletion web-client/src/common/transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -567,7 +567,7 @@ impl Transaction {
from_network_id(NetworkId::from_str(&plain.network)?),
)?;
tx.set_proof(hex::decode(match plain.proof {
PlainTransactionProof::Raw(_) => "",
PlainTransactionProof::Raw(ref data) => &data.raw,
PlainTransactionProof::Standard(ref data) => &data.raw,
PlainTransactionProof::RegularTransfer(ref data) => &data.raw,
PlainTransactionProof::TimeoutResolve(ref data) => &data.raw,
Expand Down

0 comments on commit 89d2049

Please sign in to comment.