-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(api): query all possible ibc seq numbers instead of hardcoding th…
…e JSON path (#52) * fix(api): query all possible ibc seq numbers instead of hardcoding the JSON path See comment on line 137. * chore(tx): refactor ibc sequence number function to be more testable Added unit tests around the gjson query, so that we can detect and easily fix when/if Tendermint/Cosmos SDK change anything in the IBC send structure.
- Loading branch information
Showing
2 changed files
with
158 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
package tx | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func Test_getIBCSeqFromTx(t *testing.T) { | ||
// This test assumes tx_response.logs.events is always present, | ||
// because Tendermint events are formatted this way. | ||
tests := []struct { | ||
name string | ||
payload string | ||
want []string | ||
}{ | ||
{ | ||
"ibc send payload with a single transfer", | ||
`{ | ||
"tx_response":{ | ||
"logs":[ | ||
{ | ||
"events":[ | ||
{ | ||
"type":"send_packet", | ||
"attributes":[ | ||
{ | ||
"key":"packet_sequence", | ||
"value":"42" | ||
} | ||
] | ||
} | ||
] | ||
} | ||
] | ||
} | ||
}`, | ||
[]string{"42"}, | ||
}, | ||
{ | ||
"ibc send payload with multiple transfer", | ||
`{ | ||
"tx_response":{ | ||
"logs":[ | ||
{ | ||
"events":[ | ||
{ | ||
"type":"send_packet", | ||
"attributes":[ | ||
{ | ||
"key":"packet_sequence", | ||
"value":"42" | ||
} | ||
] | ||
} | ||
] | ||
}, | ||
{ | ||
"events":[ | ||
{ | ||
"type":"send_packet", | ||
"attributes":[ | ||
{ | ||
"key":"packet_sequence", | ||
"value":"44" | ||
} | ||
] | ||
} | ||
] | ||
} | ||
] | ||
} | ||
}`, | ||
[]string{"42", "44"}, | ||
}, | ||
{ | ||
"transaction with no IBC-related tx's", | ||
`{ | ||
"tx_response":{ | ||
"logs":[ | ||
{ | ||
"events":[ | ||
{ | ||
"type":"fake_event", | ||
"attributes":[ | ||
{ | ||
"key":"packet_sequence", | ||
"value":"42" | ||
} | ||
] | ||
} | ||
] | ||
} | ||
] | ||
} | ||
}`, | ||
[]string{}, | ||
}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
res := getIBCSeqFromTx([]byte(tt.payload)) | ||
require.ElementsMatch(t, res, tt.want) | ||
}) | ||
} | ||
} |