From 1652f333a1ba101398c9e51f0cad4fb3654412ea Mon Sep 17 00:00:00 2001 From: Luis Covarrubias Date: Thu, 24 Sep 2026 00:24:30 +0000 Subject: [PATCH 1/9] fix(ton): decode send-all semantics [skip ci] Expose message grams as nominalAmount, decode send-mode flags, and\nreject unsupported or conflicting modes. Classify carry-value and\ndestructive sends as Unknown to prevent fixed-transfer approval.\n\nThis prevents a nominal TON amount from hiding mode 128/160 balance\nsemantics while preserving explicit flags for downstream policy.\n\nTicket: WCN-1888 Session-Id: 6a1a1c1b-45e9-4804-9582-27026f894f07 Task-Id: d22e36b7-5e2e-4dfc-a508-91dea479e53b --- packages/wasm-ton/js/index.ts | 8 +- packages/wasm-ton/js/parser.ts | 37 +++- packages/wasm-ton/src/parser.rs | 203 +++++++++++++++++- .../wasm-ton/src/wasm/try_into_js_value.rs | 66 +++++- packages/wasm-ton/test/builder.ts | 6 +- packages/wasm-ton/test/transaction.ts | 11 +- 6 files changed, 315 insertions(+), 16 deletions(-) diff --git a/packages/wasm-ton/js/index.ts b/packages/wasm-ton/js/index.ts index 5c274bc3ebd..29866cd434d 100644 --- a/packages/wasm-ton/js/index.ts +++ b/packages/wasm-ton/js/index.ts @@ -17,7 +17,13 @@ export { buildTransaction } from "./builder.js"; // Type exports export type { DecodedAddress } from "./address.js"; -export type { ParsedTransaction, ParsedSendAction, JettonTransferFields } from "./parser.js"; +export { EffectiveAmountKinds } from "./parser.js"; +export type { + EffectiveAmountKind, + ParsedTransaction, + ParsedSendAction, + JettonTransferFields, +} from "./parser.js"; export type { BuildContext, PaymentIntent, diff --git a/packages/wasm-ton/js/parser.ts b/packages/wasm-ton/js/parser.ts index 936c4672d74..8075c4f6df6 100644 --- a/packages/wasm-ton/js/parser.ts +++ b/packages/wasm-ton/js/parser.ts @@ -16,12 +16,23 @@ export interface JettonTransferFields { forwardTonAmount: bigint; } -/** A single send action from the transaction */ -export interface ParsedSendAction { +export const EffectiveAmountKinds = [ + "Exact", + "CarryInboundValue", + "AllRemainingBalance", +] as const; +export type EffectiveAmountKind = (typeof EffectiveAmountKinds)[number]; + +interface ParsedSendActionFields { mode: number; + /** Grams encoded in the message; the send mode can change the outgoing value. */ + nominalAmount: bigint; + payFeesSeparately: boolean; + ignoreActionErrors: boolean; + bounceOnActionFail: boolean; + destroyAccountIfZero: boolean; destination: string; destinationBounceable: string; - amount: bigint; bounce: boolean; stateInit: boolean; bodyOpcode?: number; @@ -31,6 +42,26 @@ export interface ParsedSendAction { withdrawAmount?: bigint; } +/** A send action with its TON send-mode value semantics decoded. */ +export type ParsedSendAction = ParsedSendActionFields & + ( + | { + effectiveAmountKind: "Exact"; + carriesInboundValue: false; + carriesAllBalance: false; + } + | { + effectiveAmountKind: "CarryInboundValue"; + carriesInboundValue: true; + carriesAllBalance: false; + } + | { + effectiveAmountKind: "AllRemainingBalance"; + carriesInboundValue: false; + carriesAllBalance: true; + } + ); + /** A fully parsed TON transaction */ export interface ParsedTransaction { transactionType: string; diff --git a/packages/wasm-ton/src/parser.rs b/packages/wasm-ton/src/parser.rs index a76f4077e63..72ba4c39da3 100644 --- a/packages/wasm-ton/src/parser.rs +++ b/packages/wasm-ton/src/parser.rs @@ -58,13 +58,39 @@ pub struct JettonTransferFields { pub forward_ton_amount: u64, } -/// A single send action parsed from the transaction +/// How the send mode determines the outgoing message value. +#[derive(Debug, Clone, Copy, PartialEq, Eq)] +pub enum EffectiveAmountKind { + Exact, + CarryInboundValue, + AllRemainingBalance, +} + +impl EffectiveAmountKind { + pub fn as_str(&self) -> &'static str { + match self { + Self::Exact => "Exact", + Self::CarryInboundValue => "CarryInboundValue", + Self::AllRemainingBalance => "AllRemainingBalance", + } + } +} + +/// A single send action parsed from the transaction. #[derive(Debug, Clone)] pub struct ParsedSendAction { pub mode: u8, + /// Grams encoded in the message; the send mode can change the outgoing value. + pub nominal_amount: u64, + pub effective_amount_kind: EffectiveAmountKind, + pub pay_fees_separately: bool, + pub ignore_action_errors: bool, + pub bounce_on_action_fail: bool, + pub carries_inbound_value: bool, + pub carries_all_balance: bool, + pub destroy_account_if_zero: bool, pub destination: String, pub destination_bounceable: String, - pub amount: u64, pub bounce: bool, pub body_opcode: Option, pub state_init: bool, @@ -123,6 +149,58 @@ pub fn parse_from_transaction(tx: &Transaction) -> Result Result { + let unsupported_flags = mode & !SUPPORTED_SEND_MODE_FLAGS; + if unsupported_flags != 0 { + return Err(WasmTonError::new(&format!( + "unsupported send mode flags: 0x{unsupported_flags:02x}" + ))); + } + + let carries_inbound_value = mode & SEND_MODE_CARRY_INBOUND_VALUE != 0; + let carries_all_balance = mode & SEND_MODE_CARRY_ALL_BALANCE != 0; + if carries_inbound_value && carries_all_balance { + return Err(WasmTonError::new( + "send mode cannot carry inbound value and all balance", + )); + } + + Ok(DecodedSendMode { + effective_amount_kind: if carries_all_balance { + EffectiveAmountKind::AllRemainingBalance + } else if carries_inbound_value { + EffectiveAmountKind::CarryInboundValue + } else { + EffectiveAmountKind::Exact + }, + pay_fees_separately: mode & SEND_MODE_PAY_FEES_SEPARATELY != 0, + ignore_action_errors: mode & SEND_MODE_IGNORE_ACTION_ERRORS != 0, + bounce_on_action_fail: mode & SEND_MODE_BOUNCE_ON_ACTION_FAIL != 0, + carries_inbound_value, + carries_all_balance, + destroy_account_if_zero: mode & SEND_MODE_DESTROY_ACCOUNT_IF_ZERO != 0, + }) +} + fn parse_sign_body_actions( sign_body: &WalletV4R2SignBody, ) -> Result, WasmTonError> { @@ -130,6 +208,7 @@ fn parse_sign_body_actions( WalletV4R2Op::Send(actions) => { let mut parsed = Vec::new(); for action in actions { + let decoded_mode = decode_send_mode(action.mode)?; let msg = &action.message; let (destination_addr, amount, bounce) = match &msg.info { @@ -154,13 +233,20 @@ fn parse_sign_body_actions( parsed.push(ParsedSendAction { mode: action.mode, + nominal_amount: amount, + effective_amount_kind: decoded_mode.effective_amount_kind, + pay_fees_separately: decoded_mode.pay_fees_separately, + ignore_action_errors: decoded_mode.ignore_action_errors, + bounce_on_action_fail: decoded_mode.bounce_on_action_fail, + carries_inbound_value: decoded_mode.carries_inbound_value, + carries_all_balance: decoded_mode.carries_all_balance, + destroy_account_if_zero: decoded_mode.destroy_account_if_zero, destination: if bounce { bounceable_str.clone() } else { non_bounceable_str }, destination_bounceable: bounceable_str, - amount, bounce, body_opcode: body.opcode, state_init, @@ -363,7 +449,12 @@ fn read_text_comment(parser: &mut tlb_ton::de::CellParser<'_>) -> Option } fn determine_transaction_type(actions: &[ParsedSendAction]) -> TransactionType { - if actions.is_empty() { + if actions.is_empty() + || actions.iter().any(|action| { + action.effective_amount_kind != EffectiveAmountKind::Exact + || action.destroy_account_if_zero + }) + { return TransactionType::Unknown; } @@ -421,7 +512,8 @@ mod parser_tests { use crate::transaction::Transaction; use base64::{engine::general_purpose::STANDARD, Engine}; use tlb_ton::de::CellDeserialize; - use tlb_ton::Cell; + use tlb_ton::ser::CellSerializeExt; + use tlb_ton::{BagOfCells, BagOfCellsArgs, Cell}; use ton_contracts::jetton::JettonTransfer; use ton_contracts::wallet::v4r2::WalletV4R2Op; @@ -429,6 +521,107 @@ mod parser_tests { /// forward_payload is stored as a ref cell (Either bit=1) with memo "jetton testing". const TOKEN_TX: &str = "te6cckECGgEABB0AAuGIAVSGb+UGjjP3lvt+zFA8wouI3McEd6CKbO2TwcZ3OfLKGAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACmpoxdJlgLSAAAAAAADgEXAgE0AhYBFP8A9KQT9LzyyAsDAgEgBBECAUgFCALm0AHQ0wMhcbCSXwTgItdJwSCSXwTgAtMfIYIQcGx1Z70ighBkc3RyvbCSXwXgA/pAMCD6RAHIygfL/8nQ7UTQgQFA1yH0BDBcgQEI9ApvoTGzkl8H4AXTP8glghBwbHVnupI4MOMNA4IQZHN0crqSXwbjDQYHAHgB+gD0BDD4J28iMFAKoSG+8uBQghBwbHVngx6xcIAYUATLBSbPFlj6Ahn0AMtpF8sfUmDLPyDJgED7AAYAilAEgQEI9Fkw7UTQgQFA1yDIAc8W9ADJ7VQBcrCOI4IQZHN0coMesXCAGFAFywVQA88WI/oCE8tqyx/LP8mAQPsAkl8D4gIBIAkQAgEgCg8CAVgLDAA9sp37UTQgQFA1yH0BDACyMoHy//J0AGBAQj0Cm+hMYAIBIA0OABmtznaiaEAga5Drhf/AABmvHfaiaEAQa5DrhY/AABG4yX7UTQ1wsfgAWb0kK29qJoQICga5D6AhhHDUCAhHpJN9KZEM5pA+n/mDeBKAG3gQFImHFZ8xhAT48oMI1xgg0x/TH9MfAvgju/Jk7UTQ0x/TH9P/9ATRUUO68qFRUbryogX5AVQQZPkQ8qP4ACSkyMsfUkDLH1Iwy/9SEPQAye1U+A8B0wchwACfbFGTINdKltMH1AL7AOgw4CHAAeMAIcAC4wABwAORMOMNA6TIyx8Syx/L/xITFBUAbtIH+gDU1CL5AAXIygcVy//J0Hd0gBjIywXLAiLPFlAF+gIUy2sSzMzJc/sAyEAUgQEI9FHypwIAcIEBCNcY+gDTP8hUIEeBAQj0UfKnghBub3RlcHSAGMjLBcsCUAbPFlAE+gIUy2oSyx/LP8lz+wACAGyBAQjXGPoA0z8wUiSBAQj0WfKnghBkc3RycHSAGMjLBcsCUAXPFlAD+gITy2rLHxLLP8lz+wAACvQAye1UAFEAAAAAKamjF9NTAQHUHhbX00VGZ3d2r8hbJxuz7PaxmuCOJ6kgckppQAFmQgABT9LR3Iqffskp0J9gWYO8Azlnb33BCMj8FqIUIGxGOZpiWgAAAAAAAAAAAAAAAAABGAGuD4p+pQAAAAAAAAAAQ7msoAgA/BGdBi/R01erquxJOvPgGKclBawUs3MAi0/IdctKQz8AKpDN/KDRxn7y32/ZigeYUXEbmOCO9BFNnbJ4OM7nPllGHoSBGQAkAAAAAGpldHRvbiB0ZXN0aW5nwHtw7A=="; + /// Simple send BOC used to exercise imported send modes. + const SIMPLE_SEND_BOC: &str = "te6cckEBAgEAqQAB4YgBJAxo7vqHF++LJ4bC/kJ8A1uVRskrKlrKJZ8rIB0tF+gCadlSX+hPo2mmhZyi0p3zTVUYVRkcmrCm97cSUFSa2vzvCArM3APg+ww92r3IcklNjnzfKOgysJVQXiCvj9SAaU1NGLsotvRwAAAAMAAcAQBmQgAaRefBOjTi/hwqDjv+7I6nGj9WEAe3ls/rFuBEQvggr5zEtAAAAAAAAAAAAAAAAAAAdfZO7w=="; + + fn transaction_with_send_mode(mode: u8) -> Transaction { + let mut tx = Transaction::from_base64(SIMPLE_SEND_BOC).unwrap(); + match &mut tx.message.body.body.op { + WalletV4R2Op::Send(actions) => actions[0].mode = mode, + _ => panic!("expected Send op"), + } + let cell = tx.message.to_cell(()).unwrap(); + let boc = BagOfCells::from_root(cell) + .serialize(BagOfCellsArgs { + has_idx: false, + has_crc32c: true, + }) + .unwrap(); + Transaction::from_bytes(&boc).unwrap() + } + + #[test] + fn test_imported_send_modes_preserve_effective_amount_semantics() { + let parsed_mode_3 = parse_from_transaction(&transaction_with_send_mode(3)).unwrap(); + let mode_3_action = &parsed_mode_3.send_actions[0]; + assert_eq!(parsed_mode_3.transaction_type, TransactionType::Transfer); + assert!(mode_3_action.nominal_amount > 0); + assert_eq!(mode_3_action.effective_amount_kind, EffectiveAmountKind::Exact); + assert!(mode_3_action.pay_fees_separately); + assert!(mode_3_action.ignore_action_errors); + assert!(!mode_3_action.carries_all_balance); + assert!(!mode_3_action.destroy_account_if_zero); + + for (mode, destroys_account) in [(128, false), (160, true)] { + let parsed = parse_from_transaction(&transaction_with_send_mode(mode)).unwrap(); + let action = &parsed.send_actions[0]; + assert_eq!(parsed.transaction_type, TransactionType::Unknown); + assert_eq!(action.mode, mode); + assert_eq!(action.nominal_amount, mode_3_action.nominal_amount); + assert_eq!( + action.effective_amount_kind, + EffectiveAmountKind::AllRemainingBalance + ); + assert!(action.carries_all_balance); + assert_eq!(action.destroy_account_if_zero, destroys_account); + } + } + + #[test] + fn test_send_mode_flags_and_internal_bounce_are_distinct() { + let without_ignore_errors = + parse_from_transaction(&transaction_with_send_mode(0)).unwrap(); + let with_ignore_errors = parse_from_transaction(&transaction_with_send_mode(2)).unwrap(); + assert!(!without_ignore_errors.send_actions[0].ignore_action_errors); + assert!(with_ignore_errors.send_actions[0].ignore_action_errors); + + let normal = parse_from_transaction(&transaction_with_send_mode(3)).unwrap(); + let bounce_on_action_fail = + parse_from_transaction(&transaction_with_send_mode(19)).unwrap(); + assert!(bounce_on_action_fail.send_actions[0].bounce_on_action_fail); + assert_eq!( + bounce_on_action_fail.send_actions[0].bounce, + normal.send_actions[0].bounce + ); + + let carries_inbound = parse_from_transaction(&transaction_with_send_mode(64)).unwrap(); + assert_eq!( + carries_inbound.send_actions[0].effective_amount_kind, + EffectiveAmountKind::CarryInboundValue + ); + assert!(carries_inbound.send_actions[0].carries_inbound_value); + } + + #[test] + fn test_rejects_unsupported_and_conflicting_send_modes() { + for (mode, error) in [(4, "unsupported send mode flags"), (192, "cannot carry")] { + let tx = transaction_with_send_mode(mode); + let err = parse_from_transaction(&tx).unwrap_err(); + assert!(err.to_string().contains(error)); + } + } + + #[test] + fn test_send_all_classification_is_independent_of_action_order() { + let regular = parse_from_transaction(&transaction_with_send_mode(3)) + .unwrap() + .send_actions[0] + .clone(); + let send_all = parse_from_transaction(&transaction_with_send_mode(128)) + .unwrap() + .send_actions[0] + .clone(); + + assert_eq!( + determine_transaction_type(&[regular.clone(), send_all.clone()]), + TransactionType::Unknown + ); + assert_eq!( + determine_transaction_type(&[send_all, regular]), + TransactionType::Unknown + ); + } + /// Demonstrates a bug in `tlbits` 0.7.3 `Remainder` adapter that prevents /// `JettonTransfer::::parse` from working on messages with text comments. /// diff --git a/packages/wasm-ton/src/wasm/try_into_js_value.rs b/packages/wasm-ton/src/wasm/try_into_js_value.rs index c1577767066..743dcc5ccf2 100644 --- a/packages/wasm-ton/src/wasm/try_into_js_value.rs +++ b/packages/wasm-ton/src/wasm/try_into_js_value.rs @@ -116,7 +116,16 @@ pub use js_obj; // TryIntoJsValue implementations for parser types // ============================================================================ -use crate::parser::{JettonTransferFields, ParsedSendAction, ParsedTransaction, TransactionType}; +use crate::parser::{ + EffectiveAmountKind, JettonTransferFields, ParsedSendAction, ParsedTransaction, + TransactionType, +}; + +impl TryIntoJsValue for EffectiveAmountKind { + fn try_to_js_value(&self) -> Result { + Ok(JsValue::from_str(self.as_str())) + } +} impl TryIntoJsValue for TransactionType { fn try_to_js_value(&self) -> Result { @@ -163,10 +172,59 @@ impl TryIntoJsValue for ParsedSendAction { js_sys::Reflect::set( &obj, - &JsValue::from_str("amount"), - &TryIntoJsValue::try_to_js_value(&self.amount)?, + &JsValue::from_str("nominalAmount"), + &TryIntoJsValue::try_to_js_value(&self.nominal_amount)?, + ) + .map_err(|_| JsConversionError::new("Failed to set nominalAmount"))?; + + js_sys::Reflect::set( + &obj, + &JsValue::from_str("effectiveAmountKind"), + &TryIntoJsValue::try_to_js_value(&self.effective_amount_kind)?, + ) + .map_err(|_| JsConversionError::new("Failed to set effectiveAmountKind"))?; + + js_sys::Reflect::set( + &obj, + &JsValue::from_str("payFeesSeparately"), + &TryIntoJsValue::try_to_js_value(&self.pay_fees_separately)?, + ) + .map_err(|_| JsConversionError::new("Failed to set payFeesSeparately"))?; + + js_sys::Reflect::set( + &obj, + &JsValue::from_str("ignoreActionErrors"), + &TryIntoJsValue::try_to_js_value(&self.ignore_action_errors)?, + ) + .map_err(|_| JsConversionError::new("Failed to set ignoreActionErrors"))?; + + js_sys::Reflect::set( + &obj, + &JsValue::from_str("bounceOnActionFail"), + &TryIntoJsValue::try_to_js_value(&self.bounce_on_action_fail)?, + ) + .map_err(|_| JsConversionError::new("Failed to set bounceOnActionFail"))?; + + js_sys::Reflect::set( + &obj, + &JsValue::from_str("carriesInboundValue"), + &TryIntoJsValue::try_to_js_value(&self.carries_inbound_value)?, + ) + .map_err(|_| JsConversionError::new("Failed to set carriesInboundValue"))?; + + js_sys::Reflect::set( + &obj, + &JsValue::from_str("carriesAllBalance"), + &TryIntoJsValue::try_to_js_value(&self.carries_all_balance)?, + ) + .map_err(|_| JsConversionError::new("Failed to set carriesAllBalance"))?; + + js_sys::Reflect::set( + &obj, + &JsValue::from_str("destroyAccountIfZero"), + &TryIntoJsValue::try_to_js_value(&self.destroy_account_if_zero)?, ) - .map_err(|_| JsConversionError::new("Failed to set amount"))?; + .map_err(|_| JsConversionError::new("Failed to set destroyAccountIfZero"))?; js_sys::Reflect::set( &obj, diff --git a/packages/wasm-ton/test/builder.ts b/packages/wasm-ton/test/builder.ts index 74f8c4e4ef5..77bc2e732b7 100644 --- a/packages/wasm-ton/test/builder.ts +++ b/packages/wasm-ton/test/builder.ts @@ -36,7 +36,9 @@ describe("Builder", () => { assert.equal(parsed.transactionType, "Transfer"); assert.equal(parsed.sendActions.length, 1); - assert.equal(parsed.sendActions[0].amount, 10_000_000n); + assert.equal(parsed.sendActions[0].nominalAmount, 10_000_000n); + assert.equal(parsed.sendActions[0].effectiveAmountKind, "Exact"); + assert.equal(parsed.sendActions[0].carriesAllBalance, false); }); it("should build a transfer with memo", () => { @@ -83,7 +85,7 @@ describe("Builder", () => { const parsed = parseTransaction(tx); assert.equal(parsed.transactionType, "Transfer"); - assert.equal(parsed.sendActions[0].amount, 1n); + assert.equal(parsed.sendActions[0].nominalAmount, 1n); }); it("should build a token fill nonce", () => { diff --git a/packages/wasm-ton/test/transaction.ts b/packages/wasm-ton/test/transaction.ts index 38a28a4ad40..f76ef5108d6 100644 --- a/packages/wasm-ton/test/transaction.ts +++ b/packages/wasm-ton/test/transaction.ts @@ -56,7 +56,16 @@ describe("Transaction", () => { assert.ok(parsed.sendActions.length > 0); assert.ok(parsed.sender); assert.ok(parsed.signature); - assert.equal(parsed.sendActions[0].withdrawAmount, undefined); + const action = parsed.sendActions[0]; + assert.equal(action.withdrawAmount, undefined); + assert.equal(action.mode, 3); + assert.equal(typeof action.nominalAmount, "bigint"); + assert.equal(action.effectiveAmountKind, "Exact"); + assert.equal(action.payFeesSeparately, true); + assert.equal(action.ignoreActionErrors, true); + assert.equal(action.carriesAllBalance, false); + assert.equal(action.destroyAccountIfZero, false); + assert.equal("amount" in action, false); }); it("should parse a whales deposit transaction", () => { From 7da92888b2949e9305980ad2f72d7334f4d5fb79 Mon Sep 17 00:00:00 2001 From: Luis Covarrubias Date: Thu, 24 Sep 2026 01:51:03 +0000 Subject: [PATCH 2/9] test(wasm-ton): verify send-mode conversion semantics Exercise JavaScript conversion for send-all modes 128 and 160,\nincluding nominal BigInt and zero-balance destruction flags.\n\nKeep all-balance intent visible after conversion so consumers\ncannot mistake nominal grams for a fixed transfer amount.\n\nTicket: WCN-1888 Session-Id: c3c1a2b6-ca94-47c4-81d9-b16cf4920171 Task-Id: aec26d89-87b2-4383-8624-e3f7972c32e7 --- .../wasm-ton/src/wasm/try_into_js_value.rs | 96 +++++++++++++++++++ 1 file changed, 96 insertions(+) diff --git a/packages/wasm-ton/src/wasm/try_into_js_value.rs b/packages/wasm-ton/src/wasm/try_into_js_value.rs index 743dcc5ccf2..dbaf98e18ae 100644 --- a/packages/wasm-ton/src/wasm/try_into_js_value.rs +++ b/packages/wasm-ton/src/wasm/try_into_js_value.rs @@ -280,6 +280,102 @@ impl TryIntoJsValue for ParsedSendAction { } } +#[cfg(all(test, target_arch = "wasm32"))] +mod tests { + use super::*; + use wasm_bindgen_test::wasm_bindgen_test; + + fn send_action(mode: u8) -> ParsedSendAction { + ParsedSendAction { + mode, + nominal_amount: 7, + effective_amount_kind: EffectiveAmountKind::AllRemainingBalance, + pay_fees_separately: mode & 1 != 0, + ignore_action_errors: mode & 2 != 0, + bounce_on_action_fail: mode & 16 != 0, + carries_inbound_value: false, + carries_all_balance: true, + destroy_account_if_zero: mode & 32 != 0, + destination: "destination".to_string(), + destination_bounceable: "destination".to_string(), + bounce: true, + body_opcode: None, + state_init: false, + memo: None, + jetton_transfer: None, + withdraw_amount: None, + } + } + + #[wasm_bindgen_test] + fn send_mode_semantics_survive_javascript_conversion() { + for (mode, destroy_account_if_zero) in [(128, false), (160, true)] { + let value = send_action(mode).try_to_js_value().unwrap(); + + assert_eq!( + js_sys::Reflect::get(&value, &JsValue::from_str("mode")) + .unwrap() + .as_f64(), + Some(mode as f64) + ); + let actual_amount = + js_sys::Reflect::get(&value, &JsValue::from_str("nominalAmount")).unwrap(); + let expected_amount: JsValue = js_sys::BigInt::from(7u64).into(); + assert!(js_sys::Object::is(&actual_amount, &expected_amount)); + assert_eq!( + js_sys::Reflect::get(&value, &JsValue::from_str("effectiveAmountKind")) + .unwrap() + .as_string() + .as_deref(), + Some("AllRemainingBalance") + ); + assert_eq!( + js_sys::Reflect::get(&value, &JsValue::from_str("payFeesSeparately")) + .unwrap() + .as_bool(), + Some(false) + ); + assert_eq!( + js_sys::Reflect::get(&value, &JsValue::from_str("ignoreActionErrors")) + .unwrap() + .as_bool(), + Some(false) + ); + assert_eq!( + js_sys::Reflect::get(&value, &JsValue::from_str("bounceOnActionFail")) + .unwrap() + .as_bool(), + Some(false) + ); + assert_eq!( + js_sys::Reflect::get(&value, &JsValue::from_str("carriesInboundValue")) + .unwrap() + .as_bool(), + Some(false) + ); + assert_eq!( + js_sys::Reflect::get(&value, &JsValue::from_str("carriesAllBalance")) + .unwrap() + .as_bool(), + Some(true) + ); + assert_eq!( + js_sys::Reflect::get(&value, &JsValue::from_str("destroyAccountIfZero")) + .unwrap() + .as_bool(), + Some(destroy_account_if_zero) + ); + assert_eq!( + js_sys::Reflect::get(&value, &JsValue::from_str("bounce")) + .unwrap() + .as_bool(), + Some(true) + ); + assert!(!js_sys::Reflect::has(&value, &JsValue::from_str("amount")).unwrap()); + } + } +} + impl TryIntoJsValue for ParsedTransaction { fn try_to_js_value(&self) -> Result { js_obj!( From 5b44a9870786e743877a7594e1707e58da7d2a28 Mon Sep 17 00:00:00 2001 From: Luis Covarrubias Date: Thu, 24 Sep 2026 01:51:50 +0000 Subject: [PATCH 3/9] refactor(wasm-ton): simplify mode conversion regression Use a shared property reader to keep the WASM boundary assertions\ncompact without dropping send-all or destruction coverage.\n\nTicket: WCN-1888 Session-Id: c3c1a2b6-ca94-47c4-81d9-b16cf4920171 Task-Id: aec26d89-87b2-4383-8624-e3f7972c32e7 --- .../wasm-ton/src/wasm/try_into_js_value.rs | 75 +++++-------------- 1 file changed, 18 insertions(+), 57 deletions(-) diff --git a/packages/wasm-ton/src/wasm/try_into_js_value.rs b/packages/wasm-ton/src/wasm/try_into_js_value.rs index dbaf98e18ae..9e1fd033f14 100644 --- a/packages/wasm-ton/src/wasm/try_into_js_value.rs +++ b/packages/wasm-ton/src/wasm/try_into_js_value.rs @@ -290,9 +290,9 @@ mod tests { mode, nominal_amount: 7, effective_amount_kind: EffectiveAmountKind::AllRemainingBalance, - pay_fees_separately: mode & 1 != 0, - ignore_action_errors: mode & 2 != 0, - bounce_on_action_fail: mode & 16 != 0, + pay_fees_separately: false, + ignore_action_errors: false, + bounce_on_action_fail: false, carries_inbound_value: false, carries_all_balance: true, destroy_account_if_zero: mode & 32 != 0, @@ -307,70 +307,31 @@ mod tests { } } + fn property(value: &JsValue, name: &str) -> JsValue { + js_sys::Reflect::get(value, &JsValue::from_str(name)).unwrap() + } + #[wasm_bindgen_test] fn send_mode_semantics_survive_javascript_conversion() { for (mode, destroy_account_if_zero) in [(128, false), (160, true)] { let value = send_action(mode).try_to_js_value().unwrap(); - - assert_eq!( - js_sys::Reflect::get(&value, &JsValue::from_str("mode")) - .unwrap() - .as_f64(), - Some(mode as f64) - ); - let actual_amount = - js_sys::Reflect::get(&value, &JsValue::from_str("nominalAmount")).unwrap(); - let expected_amount: JsValue = js_sys::BigInt::from(7u64).into(); - assert!(js_sys::Object::is(&actual_amount, &expected_amount)); + assert_eq!(property(&value, "mode").as_f64(), Some(mode as f64)); + let amount: JsValue = js_sys::BigInt::from(7u64).into(); + assert!(js_sys::Object::is(&property(&value, "nominalAmount"), &amount)); assert_eq!( - js_sys::Reflect::get(&value, &JsValue::from_str("effectiveAmountKind")) - .unwrap() - .as_string() - .as_deref(), + property(&value, "effectiveAmountKind").as_string().as_deref(), Some("AllRemainingBalance") ); + assert_eq!(property(&value, "payFeesSeparately").as_bool(), Some(false)); + assert_eq!(property(&value, "ignoreActionErrors").as_bool(), Some(false)); + assert_eq!(property(&value, "bounceOnActionFail").as_bool(), Some(false)); + assert_eq!(property(&value, "carriesInboundValue").as_bool(), Some(false)); + assert_eq!(property(&value, "carriesAllBalance").as_bool(), Some(true)); assert_eq!( - js_sys::Reflect::get(&value, &JsValue::from_str("payFeesSeparately")) - .unwrap() - .as_bool(), - Some(false) - ); - assert_eq!( - js_sys::Reflect::get(&value, &JsValue::from_str("ignoreActionErrors")) - .unwrap() - .as_bool(), - Some(false) - ); - assert_eq!( - js_sys::Reflect::get(&value, &JsValue::from_str("bounceOnActionFail")) - .unwrap() - .as_bool(), - Some(false) - ); - assert_eq!( - js_sys::Reflect::get(&value, &JsValue::from_str("carriesInboundValue")) - .unwrap() - .as_bool(), - Some(false) - ); - assert_eq!( - js_sys::Reflect::get(&value, &JsValue::from_str("carriesAllBalance")) - .unwrap() - .as_bool(), - Some(true) - ); - assert_eq!( - js_sys::Reflect::get(&value, &JsValue::from_str("destroyAccountIfZero")) - .unwrap() - .as_bool(), + property(&value, "destroyAccountIfZero").as_bool(), Some(destroy_account_if_zero) ); - assert_eq!( - js_sys::Reflect::get(&value, &JsValue::from_str("bounce")) - .unwrap() - .as_bool(), - Some(true) - ); + assert_eq!(property(&value, "bounce").as_bool(), Some(true)); assert!(!js_sys::Reflect::has(&value, &JsValue::from_str("amount")).unwrap()); } } From 501ffc1c528abb3c629544f516e3a89af52284ee Mon Sep 17 00:00:00 2001 From: Luis Covarrubias Date: Thu, 24 Sep 2026 02:01:20 +0000 Subject: [PATCH 4/9] style(wasm-ton): format parsed send-mode union Format the discriminated amount-kind union to match repository\nPrettier output so the source-format check passes.\n\nTicket: WCN-1888 Session-Id: c3c1a2b6-ca94-47c4-81d9-b16cf4920171 Task-Id: aec26d89-87b2-4383-8624-e3f7972c32e7 --- packages/wasm-ton/js/parser.ts | 35 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 18 deletions(-) diff --git a/packages/wasm-ton/js/parser.ts b/packages/wasm-ton/js/parser.ts index 8075c4f6df6..e6d6817eac0 100644 --- a/packages/wasm-ton/js/parser.ts +++ b/packages/wasm-ton/js/parser.ts @@ -43,24 +43,23 @@ interface ParsedSendActionFields { } /** A send action with its TON send-mode value semantics decoded. */ -export type ParsedSendAction = ParsedSendActionFields & - ( - | { - effectiveAmountKind: "Exact"; - carriesInboundValue: false; - carriesAllBalance: false; - } - | { - effectiveAmountKind: "CarryInboundValue"; - carriesInboundValue: true; - carriesAllBalance: false; - } - | { - effectiveAmountKind: "AllRemainingBalance"; - carriesInboundValue: false; - carriesAllBalance: true; - } - ); +export type ParsedSendAction = ParsedSendActionFields & ( + | { + effectiveAmountKind: "Exact"; + carriesInboundValue: false; + carriesAllBalance: false; + } + | { + effectiveAmountKind: "CarryInboundValue"; + carriesInboundValue: true; + carriesAllBalance: false; + } + | { + effectiveAmountKind: "AllRemainingBalance"; + carriesInboundValue: false; + carriesAllBalance: true; + } +); /** A fully parsed TON transaction */ export interface ParsedTransaction { From 948d88c52d677918bb68eed1532f943ee165d8c0 Mon Sep 17 00:00:00 2001 From: Luis Covarrubias Date: Thu, 24 Sep 2026 02:07:08 +0000 Subject: [PATCH 5/9] style(wasm-ton): simplify send-action type layout Name the effective-amount union separately to follow the repository's\nstandard multiline union formatting.\n\nTicket: WCN-1888 Session-Id: c3c1a2b6-ca94-47c4-81d9-b16cf4920171 Task-Id: aec26d89-87b2-4383-8624-e3f7972c32e7 --- packages/wasm-ton/js/parser.ts | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/packages/wasm-ton/js/parser.ts b/packages/wasm-ton/js/parser.ts index e6d6817eac0..b7da92b0314 100644 --- a/packages/wasm-ton/js/parser.ts +++ b/packages/wasm-ton/js/parser.ts @@ -43,7 +43,7 @@ interface ParsedSendActionFields { } /** A send action with its TON send-mode value semantics decoded. */ -export type ParsedSendAction = ParsedSendActionFields & ( +type EffectiveAmountSemantics = | { effectiveAmountKind: "Exact"; carriesInboundValue: false; @@ -58,8 +58,9 @@ export type ParsedSendAction = ParsedSendActionFields & ( effectiveAmountKind: "AllRemainingBalance"; carriesInboundValue: false; carriesAllBalance: true; - } -); + }; + +export type ParsedSendAction = ParsedSendActionFields & EffectiveAmountSemantics; /** A fully parsed TON transaction */ export interface ParsedTransaction { From 6fe231194b4c13645ef9e7380158e0e01e921abc Mon Sep 17 00:00:00 2001 From: Luis Covarrubias Date: Thu, 24 Sep 2026 02:13:31 +0000 Subject: [PATCH 6/9] style(wasm-ton): format effective amount kinds Keep the short constant list on one line to match the configured\nPrettier width and unblock CI source formatting.\n\nTicket: WCN-1888 Session-Id: c3c1a2b6-ca94-47c4-81d9-b16cf4920171 Task-Id: aec26d89-87b2-4383-8624-e3f7972c32e7 --- packages/wasm-ton/js/parser.ts | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/packages/wasm-ton/js/parser.ts b/packages/wasm-ton/js/parser.ts index b7da92b0314..2e256946fe8 100644 --- a/packages/wasm-ton/js/parser.ts +++ b/packages/wasm-ton/js/parser.ts @@ -16,11 +16,7 @@ export interface JettonTransferFields { forwardTonAmount: bigint; } -export const EffectiveAmountKinds = [ - "Exact", - "CarryInboundValue", - "AllRemainingBalance", -] as const; +export const EffectiveAmountKinds = ["Exact", "CarryInboundValue", "AllRemainingBalance"] as const; export type EffectiveAmountKind = (typeof EffectiveAmountKinds)[number]; interface ParsedSendActionFields { From 8f3ff0a30fb51459bccaa5bb654a598220d7ee6d Mon Sep 17 00:00:00 2001 From: Luis Covarrubias Date: Thu, 24 Sep 2026 02:25:08 +0000 Subject: [PATCH 7/9] refactor(wasm-ton): clarify send-action type variants Represent each effective-amount case as a named type and union the\nvariants explicitly for a clear public discriminant.\n\nTicket: WCN-1888 Session-Id: c3c1a2b6-ca94-47c4-81d9-b16cf4920171 Task-Id: aec26d89-87b2-4383-8624-e3f7972c32e7 --- packages/wasm-ton/js/parser.ts | 40 +++++++++++++++++++--------------- 1 file changed, 22 insertions(+), 18 deletions(-) diff --git a/packages/wasm-ton/js/parser.ts b/packages/wasm-ton/js/parser.ts index 2e256946fe8..0f263d82b51 100644 --- a/packages/wasm-ton/js/parser.ts +++ b/packages/wasm-ton/js/parser.ts @@ -38,25 +38,29 @@ interface ParsedSendActionFields { withdrawAmount?: bigint; } -/** A send action with its TON send-mode value semantics decoded. */ -type EffectiveAmountSemantics = - | { - effectiveAmountKind: "Exact"; - carriesInboundValue: false; - carriesAllBalance: false; - } - | { - effectiveAmountKind: "CarryInboundValue"; - carriesInboundValue: true; - carriesAllBalance: false; - } - | { - effectiveAmountKind: "AllRemainingBalance"; - carriesInboundValue: false; - carriesAllBalance: true; - }; +interface ExactAmountSemantics { + effectiveAmountKind: "Exact"; + carriesInboundValue: false; + carriesAllBalance: false; +} + +interface CarryInboundValueSemantics { + effectiveAmountKind: "CarryInboundValue"; + carriesInboundValue: true; + carriesAllBalance: false; +} -export type ParsedSendAction = ParsedSendActionFields & EffectiveAmountSemantics; +interface AllRemainingBalanceSemantics { + effectiveAmountKind: "AllRemainingBalance"; + carriesInboundValue: false; + carriesAllBalance: true; +} + +/** A send action with its TON send-mode value semantics decoded. */ +export type ParsedSendAction = + | (ParsedSendActionFields & ExactAmountSemantics) + | (ParsedSendActionFields & CarryInboundValueSemantics) + | (ParsedSendActionFields & AllRemainingBalanceSemantics); /** A fully parsed TON transaction */ export interface ParsedTransaction { From cb328afddd1dfd473d339f7ea2562263db3e393c Mon Sep 17 00:00:00 2001 From: Luis Covarrubias Date: Thu, 24 Sep 2026 02:26:27 +0000 Subject: [PATCH 8/9] style(wasm-ton): apply CI rustfmt suggestions Apply the precise formatting emitted by rustfmt in the CI check.\nThe parser and WASM conversion tests retain their behavior while the\nformat gate can proceed to executable tests.\n\nTicket: WCN-1888 Session-Id: c3c1a2b6-ca94-47c4-81d9-b16cf4920171 Task-Id: aec26d89-87b2-4383-8624-e3f7972c32e7 --- packages/wasm-ton/src/parser.rs | 8 +++--- .../wasm-ton/src/wasm/try_into_js_value.rs | 27 ++++++++++++++----- 2 files changed, 25 insertions(+), 10 deletions(-) diff --git a/packages/wasm-ton/src/parser.rs b/packages/wasm-ton/src/parser.rs index 72ba4c39da3..0d082fb23db 100644 --- a/packages/wasm-ton/src/parser.rs +++ b/packages/wasm-ton/src/parser.rs @@ -546,7 +546,10 @@ mod parser_tests { let mode_3_action = &parsed_mode_3.send_actions[0]; assert_eq!(parsed_mode_3.transaction_type, TransactionType::Transfer); assert!(mode_3_action.nominal_amount > 0); - assert_eq!(mode_3_action.effective_amount_kind, EffectiveAmountKind::Exact); + assert_eq!( + mode_3_action.effective_amount_kind, + EffectiveAmountKind::Exact + ); assert!(mode_3_action.pay_fees_separately); assert!(mode_3_action.ignore_action_errors); assert!(!mode_3_action.carries_all_balance); @@ -569,8 +572,7 @@ mod parser_tests { #[test] fn test_send_mode_flags_and_internal_bounce_are_distinct() { - let without_ignore_errors = - parse_from_transaction(&transaction_with_send_mode(0)).unwrap(); + let without_ignore_errors = parse_from_transaction(&transaction_with_send_mode(0)).unwrap(); let with_ignore_errors = parse_from_transaction(&transaction_with_send_mode(2)).unwrap(); assert!(!without_ignore_errors.send_actions[0].ignore_action_errors); assert!(with_ignore_errors.send_actions[0].ignore_action_errors); diff --git a/packages/wasm-ton/src/wasm/try_into_js_value.rs b/packages/wasm-ton/src/wasm/try_into_js_value.rs index 9e1fd033f14..9787a633520 100644 --- a/packages/wasm-ton/src/wasm/try_into_js_value.rs +++ b/packages/wasm-ton/src/wasm/try_into_js_value.rs @@ -117,8 +117,7 @@ pub use js_obj; // ============================================================================ use crate::parser::{ - EffectiveAmountKind, JettonTransferFields, ParsedSendAction, ParsedTransaction, - TransactionType, + EffectiveAmountKind, JettonTransferFields, ParsedSendAction, ParsedTransaction, TransactionType, }; impl TryIntoJsValue for EffectiveAmountKind { @@ -317,15 +316,29 @@ mod tests { let value = send_action(mode).try_to_js_value().unwrap(); assert_eq!(property(&value, "mode").as_f64(), Some(mode as f64)); let amount: JsValue = js_sys::BigInt::from(7u64).into(); - assert!(js_sys::Object::is(&property(&value, "nominalAmount"), &amount)); + assert!(js_sys::Object::is( + &property(&value, "nominalAmount"), + &amount + )); assert_eq!( - property(&value, "effectiveAmountKind").as_string().as_deref(), + property(&value, "effectiveAmountKind") + .as_string() + .as_deref(), Some("AllRemainingBalance") ); assert_eq!(property(&value, "payFeesSeparately").as_bool(), Some(false)); - assert_eq!(property(&value, "ignoreActionErrors").as_bool(), Some(false)); - assert_eq!(property(&value, "bounceOnActionFail").as_bool(), Some(false)); - assert_eq!(property(&value, "carriesInboundValue").as_bool(), Some(false)); + assert_eq!( + property(&value, "ignoreActionErrors").as_bool(), + Some(false) + ); + assert_eq!( + property(&value, "bounceOnActionFail").as_bool(), + Some(false) + ); + assert_eq!( + property(&value, "carriesInboundValue").as_bool(), + Some(false) + ); assert_eq!(property(&value, "carriesAllBalance").as_bool(), Some(true)); assert_eq!( property(&value, "destroyAccountIfZero").as_bool(), From 7f38cbee376ca43aac57e1af1e810908a6975173 Mon Sep 17 00:00:00 2001 From: Luis Covarrubias Date: Thu, 24 Sep 2026 02:42:22 +0000 Subject: [PATCH 9/9] test(wasm-ton): run mode semantics checks in CI Add wasm-pack Node and Chrome test commands and select them for\nwasm-ton in the package test matrix.\n\nThis ensures the carry-all and destroy-if-zero JS conversion\nregressions run instead of remaining skipped in CI.\n\nTicket: WCN-1888 Session-Id: c3c1a2b6-ca94-47c4-81d9-b16cf4920171 Task-Id: aec26d89-87b2-4383-8624-e3f7972c32e7 --- .github/scripts/detect-changes.mjs | 2 +- packages/wasm-ton/package.json | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/scripts/detect-changes.mjs b/.github/scripts/detect-changes.mjs index db9d0e358d4..92e63acbd33 100644 --- a/.github/scripts/detect-changes.mjs +++ b/.github/scripts/detect-changes.mjs @@ -17,7 +17,7 @@ const PACKAGE_CONFIG = [ { package: "wasm-mps", "needs-wasm-pack": false, "has-wasm-pack-tests": false }, { package: "wasm-solana", "needs-wasm-pack": false, "has-wasm-pack-tests": false }, { package: "wasm-dot", "needs-wasm-pack": false, "has-wasm-pack-tests": false }, - { package: "wasm-ton", "needs-wasm-pack": false, "has-wasm-pack-tests": false }, + { package: "wasm-ton", "needs-wasm-pack": true, "has-wasm-pack-tests": true }, { package: "wasm-privacy-coin", "needs-wasm-pack": false, "has-wasm-pack-tests": false }, ]; diff --git a/packages/wasm-ton/package.json b/packages/wasm-ton/package.json index 5fca6ff63f5..d960034b444 100644 --- a/packages/wasm-ton/package.json +++ b/packages/wasm-ton/package.json @@ -35,6 +35,8 @@ "scripts": { "test": "npm run test:mocha", "test:mocha": "mocha --recursive test", + "test:wasm-pack-node": "wasm-pack test --node", + "test:wasm-pack-chrome": "wasm-pack test --headless --chrome", "build:wasm": "make js/wasm && make dist/esm/js/wasm && make dist/cjs/js/wasm", "build:ts-esm": "tsc", "build:ts-cjs": "tsc --project tsconfig.cjs.json",