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

fix: deserialize of enhanced transaction when transactionError contains different error than instructionError #71

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
5 changes: 4 additions & 1 deletion src/types/enhanced_transaction_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,11 @@ pub struct TokenTransfer {
#[derive(Serialize, Deserialize, Debug)]
#[serde(rename_all = "camelCase")]
pub struct TransactionError {
#[serde(rename = "InstructionError")]
#[serde(default, rename = "InstructionError")]
pub instruciton_error: serde_json::Value,
// TODO adding below allow to handle other errors too but adding this field is breaking change as all other fields are pub
// #[serde(flatten)]
// other: serde_json::Value,
}

#[derive(Serialize, Deserialize, Debug)]
Expand Down
4 changes: 4 additions & 0 deletions tests/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ mod utils {
mod test_make_keypairs;
}

mod types {
mod deserialize_enhanced_tx;
}

mod rpc {
mod test_get_asset;
mod test_get_asset_batch;
Expand Down
24 changes: 24 additions & 0 deletions tests/types/deserialize_enhanced_tx.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
use helius::types::EnhancedTransaction;

#[test]
fn dese_enhanced_tx_with_transaction_error_insufficient_founds() {
let raw_json = include_str!("./enhanced_tx__transaction_error_insufficient_founds.json");
let enhanced_tx: EnhancedTransaction = serde_json::from_str(raw_json).unwrap();

// There was different error that can be handled because of backward compatibility
assert_eq!(
enhanced_tx.transaction_error.unwrap().instruciton_error,
serde_json::Value::Null
);
}

#[test]
fn dese_enhanced_tx_with_instruction_error() {
let raw_json = include_str!("./enhanced_tx__transaction_error_instruction_error.json");
let enhanced_tx: EnhancedTransaction = serde_json::from_str(raw_json).unwrap();

assert_ne!(
enhanced_tx.transaction_error.unwrap().instruciton_error,
serde_json::Value::Null
);
}
162 changes: 162 additions & 0 deletions tests/types/enhanced_tx__transaction_error_instruction_error.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,162 @@
{
"description": "",
"type": "SWAP",
"source": "RAYDIUM",
"fee": 31563,
"feePayer": "22WLnDCeMvcoboRgVt8a4ztkd4yA1ptSv9JpnE2gx95R",
"signature": "3VvunzA4uPRjGeZcE8GjDUbPPPs2oQKR3AEDqw87vKiSYKr5SMH9uAWjigsTt5fEcqeC5NCt5DvZV8gkTnrU4piM",
"slot": 292070637,
"timestamp": 1727334237,
"tokenTransfers": [],
"nativeTransfers": [],
"accountData": [
{
"account": "22WLnDCeMvcoboRgVt8a4ztkd4yA1ptSv9JpnE2gx95R",
"nativeBalanceChange": -31563,
"tokenBalanceChanges": []
},
{
"account": "9PG9Y6X27hZWzU6b1jJFv1PsvGU1o2xUzVZjcQMgbirC",
"nativeBalanceChange": 0,
"tokenBalanceChanges": []
},
{
"account": "AbcBkTe7AjStTBNiHb54ayfhFk69YBW2s6hSFrCfWDpu",
"nativeBalanceChange": 0,
"tokenBalanceChanges": []
},
{
"account": "9DCxsMizn3H1hprZ7xWe6LDzeUeZBksYFpBWBtSf1PQX",
"nativeBalanceChange": 0,
"tokenBalanceChanges": []
},
{
"account": "DBnvPrA6AekVqb6SLpGBY9QVaufvgvSmQ7PbztekWLoe",
"nativeBalanceChange": 0,
"tokenBalanceChanges": []
},
{
"account": "CnHbayYtvaXGyX9te1yCPVpiZysFTSPJ9H78CMHmoRKu",
"nativeBalanceChange": 0,
"tokenBalanceChanges": []
},
{
"account": "AEdY78voJWRRqcB4cARvAtgsmakdvKwWW5i9VHe3AxyA",
"nativeBalanceChange": 0,
"tokenBalanceChanges": []
},
{
"account": "H6cj3ZBQ4kf81mySHu4WTZhJmDEU5Duy5BvDLhRcZ8cy",
"nativeBalanceChange": 0,
"tokenBalanceChanges": []
},
{
"account": "83PT4anismqyBaXsjSnpWN7YbkxK6eGFykV9koqoCZ87",
"nativeBalanceChange": 0,
"tokenBalanceChanges": []
},
{
"account": "526LzAE23TE8cCCQmJw4bD8BM6N7JXV8Hm1CSJeCULiC",
"nativeBalanceChange": 0,
"tokenBalanceChanges": []
},
{
"account": "B8QYVSiaNnYzYe3mNaAPjrWAwnJFxRcTLr68TfCEyxBj",
"nativeBalanceChange": 0,
"tokenBalanceChanges": []
},
{
"account": "HCZiweAwvyGgAN3AXj5y7vzreozAY68PCqCm6PNHjS7R",
"nativeBalanceChange": 0,
"tokenBalanceChanges": []
},
{
"account": "1o6ECsnK5vzSkNVvSWNixEYSfr9tE2ota7ZdmU9j4TZ",
"nativeBalanceChange": 0,
"tokenBalanceChanges": []
},
{
"account": "6aXrakfEbmHv3BDRudMHvT5orGH7N36tjGh1RRgoFQDy",
"nativeBalanceChange": 0,
"tokenBalanceChanges": []
},
{
"account": "ComputeBudget111111111111111111111111111111",
"nativeBalanceChange": 0,
"tokenBalanceChanges": []
},
{
"account": "675kPX9MHTjS2zt1qfr1NYHuzeLXfQM9H24wFSUt1Mp8",
"nativeBalanceChange": 0,
"tokenBalanceChanges": []
},
{
"account": "EyxQ6UceYeAqN4tie9tBFSE1XorN7fWxSfX11WUxT1TX",
"nativeBalanceChange": 0,
"tokenBalanceChanges": []
},
{
"account": "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA",
"nativeBalanceChange": 0,
"tokenBalanceChanges": []
},
{
"account": "5Q544fKrFoe6tsEbD7S8EmxGTJYAKtTVhAW5Q5pge4j1",
"nativeBalanceChange": 0,
"tokenBalanceChanges": []
},
{
"account": "srmqPvymJeFKQ4zGQed1GFppgkRHL9kaELCbyksJtPX",
"nativeBalanceChange": 0,
"tokenBalanceChanges": []
}
],
"transactionError": {
"InstructionError": [
2,
{
"Custom": 30
}
]
},
"instructions": [
{
"accounts": [],
"data": "3kw4sRb1pXrP",
"programId": "ComputeBudget111111111111111111111111111111",
"innerInstructions": []
},
{
"accounts": [],
"data": "EP8BzP",
"programId": "ComputeBudget111111111111111111111111111111",
"innerInstructions": []
},
{
"accounts": [
"TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA",
"9PG9Y6X27hZWzU6b1jJFv1PsvGU1o2xUzVZjcQMgbirC",
"5Q544fKrFoe6tsEbD7S8EmxGTJYAKtTVhAW5Q5pge4j1",
"AbcBkTe7AjStTBNiHb54ayfhFk69YBW2s6hSFrCfWDpu",
"9DCxsMizn3H1hprZ7xWe6LDzeUeZBksYFpBWBtSf1PQX",
"DBnvPrA6AekVqb6SLpGBY9QVaufvgvSmQ7PbztekWLoe",
"CnHbayYtvaXGyX9te1yCPVpiZysFTSPJ9H78CMHmoRKu",
"srmqPvymJeFKQ4zGQed1GFppgkRHL9kaELCbyksJtPX",
"AEdY78voJWRRqcB4cARvAtgsmakdvKwWW5i9VHe3AxyA",
"H6cj3ZBQ4kf81mySHu4WTZhJmDEU5Duy5BvDLhRcZ8cy",
"83PT4anismqyBaXsjSnpWN7YbkxK6eGFykV9koqoCZ87",
"526LzAE23TE8cCCQmJw4bD8BM6N7JXV8Hm1CSJeCULiC",
"B8QYVSiaNnYzYe3mNaAPjrWAwnJFxRcTLr68TfCEyxBj",
"HCZiweAwvyGgAN3AXj5y7vzreozAY68PCqCm6PNHjS7R",
"EyxQ6UceYeAqN4tie9tBFSE1XorN7fWxSfX11WUxT1TX",
"1o6ECsnK5vzSkNVvSWNixEYSfr9tE2ota7ZdmU9j4TZ",
"6aXrakfEbmHv3BDRudMHvT5orGH7N36tjGh1RRgoFQDy",
"22WLnDCeMvcoboRgVt8a4ztkd4yA1ptSv9JpnE2gx95R"
],
"data": "676XSqJuLojyTjc1qzZmEfH",
"programId": "675kPX9MHTjS2zt1qfr1NYHuzeLXfQM9H24wFSUt1Mp8",
"innerInstructions": []
}
],
"events": {}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
{
"description": "7mHVPmoTJQZUGDHpWHRr2dV2e9UBaGknopjh3AdJpj89 transferred 0.05008025 SOL to BZkAJnd9QaNWgAXkTjNmKvYiAGXVAzhWZHJpJgo6RsAt.",
"type": "TRANSFER",
"source": "SYSTEM_PROGRAM",
"fee": 5000,
"feePayer": "7mHVPmoTJQZUGDHpWHRr2dV2e9UBaGknopjh3AdJpj89",
"signature": "ArRXvQdphogFmmuULMjHhk1nBV7vhjHwQxUbKAEkexPJYWmeFQXt5ycoyA2wKMTN9STdtHJ1Nm7d9csjC1oDd32",
"slot": 289356858,
"timestamp": 1726146439,
"tokenTransfers": [],
"nativeTransfers": [
{
"fromUserAccount": "7mHVPmoTJQZUGDHpWHRr2dV2e9UBaGknopjh3AdJpj89",
"toUserAccount": "BZkAJnd9QaNWgAXkTjNmKvYiAGXVAzhWZHJpJgo6RsAt",
"amount": 50080250
}
],
"accountData": [
{
"account": "7mHVPmoTJQZUGDHpWHRr2dV2e9UBaGknopjh3AdJpj89",
"nativeBalanceChange": -5000,
"tokenBalanceChanges": []
},
{
"account": "BZkAJnd9QaNWgAXkTjNmKvYiAGXVAzhWZHJpJgo6RsAt",
"nativeBalanceChange": 0,
"tokenBalanceChanges": []
},
{
"account": "11111111111111111111111111111111",
"nativeBalanceChange": 0,
"tokenBalanceChanges": []
}
],
"transactionError": {
"InsufficientFundsForRent": {
"account_index": 0
}
},
"instructions": [
{
"accounts": [
"7mHVPmoTJQZUGDHpWHRr2dV2e9UBaGknopjh3AdJpj89",
"BZkAJnd9QaNWgAXkTjNmKvYiAGXVAzhWZHJpJgo6RsAt"
],
"data": "3Bxs4ihZh9cqzbLb",
"programId": "11111111111111111111111111111111",
"innerInstructions": []
}
],
"events": {}
}
Loading