Skip to content
This repository was archived by the owner on Jun 1, 2026. It is now read-only.

Commit c75a087

Browse files
committed
fix(cosmos): ignore reverted parsed transactions
1 parent 7855fc2 commit c75a087

3 files changed

Lines changed: 184 additions & 6 deletions

File tree

‎crates/gem_cosmos/src/provider/testkit.rs‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#[cfg(test)]
2+
use crate::models::TransactionResponse;
13
#[cfg(all(test, feature = "chain_integration_tests"))]
24
use crate::rpc::client::CosmosClient;
35
#[cfg(all(test, feature = "chain_integration_tests"))]
@@ -13,6 +15,17 @@ pub const TEST_EMPTY_ADDRESS: &str = "cosmos19xv76hwfjzf286we9q8ssce4v67h378vfnx
1315
#[cfg(test)]
1416
pub const TEST_TRANSACTION_ID: &str = "BC5E330F0AFA34489B9796E8101A2B027CC8AE8E820AFC7901C3C1E75C2895DD";
1517

18+
#[cfg(test)]
19+
impl TransactionResponse {
20+
pub fn mock_delegate() -> Self {
21+
serde_json::from_str(include_str!("../../testdata/delegate.json")).unwrap()
22+
}
23+
24+
pub fn mock_reverted_transfer_spam() -> Self {
25+
serde_json::from_str(include_str!("../../testdata/reverted_transfer_spam.json")).unwrap()
26+
}
27+
}
28+
1629
#[cfg(all(test, feature = "chain_integration_tests"))]
1730
pub fn create_osmosis_test_client() -> CosmosClient<ReqwestClient> {
1831
let settings = get_test_settings();

‎crates/gem_cosmos/src/provider/transactions_mapper.rs‎

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,10 @@ fn asset_id_from_denom(chain: primitives::Chain, denom: &str, default_denom: &st
5050
}
5151

5252
pub fn map_transaction(cosmos_chain: CosmosChain, body: TransactionBody, auth_info: Option<AuthInfo>, transaction: TransactionResponse) -> Option<Transaction> {
53+
if transaction.tx_response.code != 0 {
54+
return None;
55+
}
56+
5357
let hash = transaction.tx_response.txhash.clone();
5458
let chain = cosmos_chain.as_chain();
5559
let default_denom = chain.as_denom()?.to_string();
@@ -64,11 +68,6 @@ pub fn map_transaction(cosmos_chain: CosmosChain, body: TransactionBody, auth_in
6468

6569
let memo = if body.memo.is_empty() { None } else { Some(body.memo.clone()) };
6670

67-
let state = if transaction.tx_response.code == 0 {
68-
TransactionState::Confirmed
69-
} else {
70-
TransactionState::Reverted
71-
};
7271
let created_at = DateTime::parse_from_rfc3339(&transaction.tx_response.timestamp).ok()?.into();
7372

7473
if body.messages.len() != 1 {
@@ -129,7 +128,7 @@ pub fn map_transaction(cosmos_chain: CosmosChain, body: TransactionBody, auth_in
129128
to_address,
130129
None,
131130
transaction_type,
132-
state,
131+
TransactionState::Confirmed,
133132
fee,
134133
fee_asset_id,
135134
value,
@@ -209,6 +208,24 @@ mod tests {
209208
);
210209
}
211210

211+
#[test]
212+
fn test_map_reverted_transfer_is_ignored() {
213+
let result = TransactionResponse::mock_reverted_transfer_spam();
214+
let transactions = map_transactions(CosmosChain::Cosmos, vec![result]);
215+
216+
assert_eq!(transactions, vec![]);
217+
}
218+
219+
#[test]
220+
fn test_map_reverted_staking_is_ignored() {
221+
let mut result = TransactionResponse::mock_delegate();
222+
result.tx_response.code = 1;
223+
224+
let transactions = map_transactions(CosmosChain::Cosmos, vec![result]);
225+
226+
assert_eq!(transactions, vec![]);
227+
}
228+
212229
#[test]
213230
fn test_transfer_ibc() {
214231
let result: TransactionResponse = serde_json::from_str(include_str!("../../testdata/transfer_ibc.json")).unwrap();
Lines changed: 148 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,148 @@
1+
{
2+
"tx": {
3+
"body": {
4+
"messages": [
5+
{
6+
"@type": "/cosmos.bank.v1beta1.MsgSend",
7+
"from_address": "cosmos1spam28rxfh39axghzlcusd98qhpkdarcq6umev2",
8+
"to_address": "cosmos1hgp84me0lze8t4jfrwsr05aep2kr57zrk4gecx",
9+
"amount": [
10+
{
11+
"denom": "uatom",
12+
"amount": "99999999999999999999999999999999"
13+
}
14+
]
15+
}
16+
],
17+
"memo": "reverted spam transfer",
18+
"timeout_height": "0",
19+
"extension_options": [],
20+
"non_critical_extension_options": []
21+
},
22+
"auth_info": {
23+
"signer_infos": [
24+
{
25+
"public_key": {
26+
"@type": "/cosmos.crypto.secp256k1.PubKey",
27+
"key": "A7Y9+R2a6pVf07i5P0dYqv5vLAkUn1d2P7YwW1Q4hH9S"
28+
},
29+
"mode_info": {
30+
"single": {
31+
"mode": "SIGN_MODE_DIRECT"
32+
}
33+
},
34+
"sequence": "42"
35+
}
36+
],
37+
"fee": {
38+
"amount": [
39+
{
40+
"denom": "uatom",
41+
"amount": "2500"
42+
}
43+
],
44+
"gas_limit": "200000",
45+
"payer": "",
46+
"granter": ""
47+
},
48+
"tip": null
49+
},
50+
"signatures": [
51+
"Q2xpZW50U2lnbmF0dXJlRG9lc05vdE1hdHRlckZvclBhcnNpbmdUZXN0cw=="
52+
]
53+
},
54+
"tx_response": {
55+
"height": "26260000",
56+
"txhash": "F8D05E52F23159D4545E516775E87DE6678AD2AA0B01BB8911C61861B8A60D10",
57+
"codespace": "bank",
58+
"code": 5,
59+
"data": "",
60+
"raw_log": "failed to execute message; message index: 0: 99999999999999999999999999999999uatom is larger than available balance: insufficient funds",
61+
"logs": [],
62+
"info": "",
63+
"gas_wanted": "200000",
64+
"gas_used": "81234",
65+
"tx": {
66+
"@type": "/cosmos.tx.v1beta1.Tx",
67+
"body": {
68+
"messages": [
69+
{
70+
"@type": "/cosmos.bank.v1beta1.MsgSend",
71+
"from_address": "cosmos1spam28rxfh39axghzlcusd98qhpkdarcq6umev2",
72+
"to_address": "cosmos1hgp84me0lze8t4jfrwsr05aep2kr57zrk4gecx",
73+
"amount": [
74+
{
75+
"denom": "uatom",
76+
"amount": "99999999999999999999999999999999"
77+
}
78+
]
79+
}
80+
],
81+
"memo": "reverted spam transfer",
82+
"timeout_height": "0",
83+
"extension_options": [],
84+
"non_critical_extension_options": []
85+
},
86+
"auth_info": {
87+
"signer_infos": [
88+
{
89+
"public_key": {
90+
"@type": "/cosmos.crypto.secp256k1.PubKey",
91+
"key": "A7Y9+R2a6pVf07i5P0dYqv5vLAkUn1d2P7YwW1Q4hH9S"
92+
},
93+
"mode_info": {
94+
"single": {
95+
"mode": "SIGN_MODE_DIRECT"
96+
}
97+
},
98+
"sequence": "42"
99+
}
100+
],
101+
"fee": {
102+
"amount": [
103+
{
104+
"denom": "uatom",
105+
"amount": "2500"
106+
}
107+
],
108+
"gas_limit": "200000",
109+
"payer": "",
110+
"granter": ""
111+
},
112+
"tip": null
113+
},
114+
"signatures": [
115+
"Q2xpZW50U2lnbmF0dXJlRG9lc05vdE1hdHRlckZvclBhcnNpbmdUZXN0cw=="
116+
]
117+
},
118+
"timestamp": "2026-05-19T19:05:46Z",
119+
"events": [
120+
{
121+
"type": "tx",
122+
"attributes": [
123+
{
124+
"key": "fee",
125+
"value": "2500uatom"
126+
},
127+
{
128+
"key": "acc_seq",
129+
"value": "cosmos1spam28rxfh39axghzlcusd98qhpkdarcq6umev2/42"
130+
}
131+
]
132+
},
133+
{
134+
"type": "message",
135+
"attributes": [
136+
{
137+
"key": "action",
138+
"value": "/cosmos.bank.v1beta1.MsgSend"
139+
},
140+
{
141+
"key": "sender",
142+
"value": "cosmos1spam28rxfh39axghzlcusd98qhpkdarcq6umev2"
143+
}
144+
]
145+
}
146+
]
147+
}
148+
}

0 commit comments

Comments
 (0)